diff --git a/.bzrignore b/.bzrignore index 6939ce594c5..2e0e5acabb5 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1071,6 +1071,7 @@ vio/viotest.cpp ylwrap zlib/*.ds? sql-bench/test-table-elimination +sql/share/bulgarian sql/share/czech sql/share/danish sql/share/dutch @@ -1134,6 +1135,7 @@ cmd-line-utils/libedit/emacs.h mysql-test/collections/default.release support-files/plugins.files client/mysql_plugin +*.resource.txt plugin/handler_socket/perl-Net-HandlerSocket/HandlerSocket.c plugin/handler_socket/perl-Net-HandlerSocket/blib plugin/handler_socket/perl-Net-HandlerSocket/pm_to_blib @@ -1155,3 +1157,4 @@ storage/perfschema/pfs_lex_token.h *.bak *.OLD mysql-test/collections/default.release.done +sql/sql_yacc.hh diff --git a/BUILD/compile-amd64-debug-max b/BUILD/compile-amd64-debug-max index 273942df5f8..ebdf278b7d2 100755 --- a/BUILD/compile-amd64-debug-max +++ b/BUILD/compile-amd64-debug-max @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2005 MySQL AB +# Copyright (c) 2005, 2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-amd64-max b/BUILD/compile-amd64-max index c14f0d7104c..915129e1863 100755 --- a/BUILD/compile-amd64-max +++ b/BUILD/compile-amd64-max @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2005 MySQL AB +# Copyright (c) 2005, 2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-darwin-mwcc b/BUILD/compile-darwin-mwcc index 88747de77af..ad2990f2de1 100755 --- a/BUILD/compile-darwin-mwcc +++ b/BUILD/compile-darwin-mwcc @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2005 MySQL AB +# Copyright (c) 2005, 2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-hpux11-parisc2-aCC b/BUILD/compile-hpux11-parisc2-aCC index 5d0df465bc9..a4c9eb7abfa 100755 --- a/BUILD/compile-hpux11-parisc2-aCC +++ b/BUILD/compile-hpux11-parisc2-aCC @@ -1,6 +1,7 @@ #!/bin/sh -# Copyright (C) 2004, 2005 MySQL AB +# Copyright (c) 2004, 2005, 2007 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-irix-mips64-mipspro b/BUILD/compile-irix-mips64-mipspro index a8433c715ab..13df7ea2028 100755 --- a/BUILD/compile-irix-mips64-mipspro +++ b/BUILD/compile-irix-mips64-mipspro @@ -1,6 +1,7 @@ #!/bin/sh -# Copyright (C) 2004, 2005 MySQL AB +# Copyright (c) 2004, 2005, 2007 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-ndb-autotest b/BUILD/compile-ndb-autotest index e14855f1489..8002b4c5fad 100755 --- a/BUILD/compile-ndb-autotest +++ b/BUILD/compile-ndb-autotest @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (C) 2006 MySQL AB +# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # 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/BUILD/compile-pentium b/BUILD/compile-pentium index 1da117541a4..fc3d070393d 100755 --- a/BUILD/compile-pentium +++ b/BUILD/compile-pentium @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2000, 2002 MySQL AB +# Copyright (c) 2000-2002, 2007 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-pentium-debug-max-no-embedded b/BUILD/compile-pentium-debug-max-no-embedded index 55aede7536f..e88542f5d24 100755 --- a/BUILD/compile-pentium-debug-max-no-embedded +++ b/BUILD/compile-pentium-debug-max-no-embedded @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2004, 2005 MySQL AB +# Copyright (c) 2004-2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-pentium-debug-max-no-ndb b/BUILD/compile-pentium-debug-max-no-ndb index cb8dbc7e364..3319307fc32 100755 --- a/BUILD/compile-pentium-debug-max-no-ndb +++ b/BUILD/compile-pentium-debug-max-no-ndb @@ -1,6 +1,6 @@ #! /bin/sh -# Copyright (C) 2005, 2007 MySQL AB +# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. # # 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/BUILD/compile-pentium-max b/BUILD/compile-pentium-max index 7bd063cd24a..77726735c79 100755 --- a/BUILD/compile-pentium-max +++ b/BUILD/compile-pentium-max @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2001, 2005 MySQL AB +# Copyright (c) 2001-2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-ppc-debug b/BUILD/compile-ppc-debug index 76b6bf65ce4..2ee49a9fda3 100755 --- a/BUILD/compile-ppc-debug +++ b/BUILD/compile-ppc-debug @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2004 MySQL AB +# Copyright (c) 2004, 2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-ppc-debug-max b/BUILD/compile-ppc-debug-max index b2c7ec18b3e..408f85f64e6 100755 --- a/BUILD/compile-ppc-debug-max +++ b/BUILD/compile-ppc-debug-max @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2004, 2005 MySQL AB +# Copyright (c) 2004-2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-ppc-debug-max-no-ndb b/BUILD/compile-ppc-debug-max-no-ndb index e77c517b302..958f6b09a11 100755 --- a/BUILD/compile-ppc-debug-max-no-ndb +++ b/BUILD/compile-ppc-debug-max-no-ndb @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2005 MySQL AB +# Copyright (c) 2005, 2006 MySQL AB +# Use is subject to license terms # # 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/BUILD/compile-ppc-max b/BUILD/compile-ppc-max index cd2ada87dd8..5aac6af60e9 100755 --- a/BUILD/compile-ppc-max +++ b/BUILD/compile-ppc-max @@ -1,6 +1,7 @@ #! /bin/sh -# Copyright (C) 2004, 2005 MySQL AB +# Copyright (c) 2004-2006 MySQL AB +# Use is subject to license terms # # 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/CMakeLists.txt b/CMakeLists.txt index e8a48cbb5e4..3bf630209b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,8 +342,8 @@ INCLUDE(cmake/abi_check.cmake) INCLUDE(cmake/tags.cmake) IF(WIN32) - ADD_SUBDIRECTORY(win/packaging) ADD_SUBDIRECTORY(win/upgrade_wizard) + ADD_SUBDIRECTORY(win/packaging) ENDIF() CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/my_config.h) diff --git a/VERSION b/VERSION index 2301e3f8ba3..45cfb298590 100644 --- a/VERSION +++ b/VERSION @@ -4,5 +4,5 @@ # MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=0 -MYSQL_VERSION_PATCH=2 +MYSQL_VERSION_PATCH=3 MYSQL_VERSION_EXTRA= diff --git a/client/client_priv.h b/client/client_priv.h index 8c713d73200..e2afbad89a5 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 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/client/completion_hash.h b/client/completion_hash.h index 8e1b2d6e453..50098e436b9 100644 --- a/client/completion_hash.h +++ b/client/completion_hash.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2000-2002 MySQL AB +/* Copyright (c) 2000-2002, 2006 MySQL AB + Use is subject to license terms This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/client/echo.c b/client/echo.c index e3d22edb3ae..cd61b23a826 100644 --- a/client/echo.c +++ b/client/echo.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2007 MySQL AB + Use is subject to license terms 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/client/get_password.c b/client/get_password.c index 09d307b5553..a73771b00d4 100644 --- a/client/get_password.c +++ b/client/get_password.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2001, 2003, 2006, 2008 MySQL AB + Use is subject to license terms 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/client/mysql.cc b/client/mysql.cc index 39fe52f4a1b..a4cba59d235 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1635,7 +1635,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), { switch(optid) { case OPT_CHARSETS_DIR: - strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1); + strmake_buf(mysql_charsets_dir, argument); charsets_dir = mysql_charsets_dir; break; case OPT_DELIMITER: @@ -1648,7 +1648,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), /* Check that delimiter does not contain a backslash */ if (!strstr(argument, "\\")) { - strmake(delimiter, argument, sizeof(delimiter) - 1); + strmake_buf(delimiter, argument); } else { @@ -1680,7 +1680,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), if (argument && strlen(argument)) { default_pager_set= 1; - strmake(pager, argument, sizeof(pager) - 1); + strmake_buf(pager, argument); strmov(default_pager, pager); } else if (default_pager_set) @@ -2961,7 +2961,7 @@ com_charset(String *buffer __attribute__((unused)), char *line) { char buff[256], *param; CHARSET_INFO * new_cs; - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); param= get_arg(buff, 0); if (!param || !*param) { @@ -3198,7 +3198,7 @@ static void init_tee(const char *file_name) return; } OUTFILE = new_outfile; - strmake(outfile, file_name, FN_REFLEN-1); + strmake_buf(outfile, file_name); tee_fprintf(stdout, "Logging to file '%s'\n", file_name); opt_outfile= 1; return; @@ -3827,7 +3827,7 @@ com_tee(String *buffer __attribute__((unused)), /* eliminate the spaces before the parameters */ while (my_isspace(charset_info,*param)) param++; - end= strmake(file_name, param, sizeof(file_name) - 1); + end= strmake_buf(file_name, param); /* remove end space from command line */ while (end > file_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) @@ -3888,7 +3888,7 @@ com_pager(String *buffer __attribute__((unused)), } else { - end= strmake(pager_name, param, sizeof(pager_name)-1); + end= strmake_buf(pager_name, param); while (end > pager_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) end--; @@ -4101,7 +4101,7 @@ static int com_source(String *buffer __attribute__((unused)), INFO_ERROR, 0); while (my_isspace(charset_info,*param)) param++; - end=strmake(source_name,param,sizeof(source_name)-1); + end=strmake_buf(source_name, param); while (end > source_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) end--; @@ -4154,7 +4154,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line) { char buff[256], *tmp; - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); tmp= get_arg(buff, 0); if (!tmp || !*tmp) @@ -4171,7 +4171,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line) return 0; } } - strmake(delimiter, tmp, sizeof(delimiter) - 1); + strmake_buf(delimiter, tmp); delimiter_length= (int)strlen(delimiter); delimiter_str= delimiter; return 0; @@ -4185,7 +4185,7 @@ com_use(String *buffer __attribute__((unused)), char *line) int select_db; bzero(buff, sizeof(buff)); - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); tmp= get_arg(buff, 0); if (!tmp || !*tmp) { diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index c099459f61e..9ad284646e0 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -37,6 +37,7 @@ /* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */ #include "sql_priv.h" #include "log_event.h" +#include "compat56.h" #include "sql_common.h" #include "my_dir.h" #include // ORACLE_WELCOME_COPYRIGHT_NOTICE @@ -1541,13 +1542,14 @@ the mysql command line client.\n\n"); static my_time_t convert_str_to_timestamp(const char* str) { - int was_cut; + MYSQL_TIME_STATUS status; MYSQL_TIME l_time; long dummy_my_timezone; uint dummy_in_dst_time_gap; + /* We require a total specification (date AND time) */ - if (str_to_datetime(str, (uint) strlen(str), &l_time, 0, &was_cut) != - MYSQL_TIMESTAMP_DATETIME || was_cut) + if (str_to_datetime(str, (uint) strlen(str), &l_time, 0, &status) || + l_time.time_type != MYSQL_TIMESTAMP_DATETIME || status.warnings) { error("Incorrect date and time argument: %s", str); exit(1); @@ -2562,3 +2564,4 @@ void *sql_alloc(size_t size) #include "sql_string.cc" #include "sql_list.cc" #include "rpl_filter.cc" +#include "compat56.cc" diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 60778e12f06..e96f855719e 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -18,7 +18,7 @@ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */ -#define CHECK_VERSION "2.7.0" +#define CHECK_VERSION "2.7.1" #include "client_priv.h" #include @@ -32,6 +32,10 @@ #define EX_USAGE 1 #define EX_MYSQLERR 2 +/* ALTER instead of repair. */ +#define MAX_ALTER_STR_SIZE 128 * 1024 +#define KEY_PARTITIONING_CHANGED_STR "KEY () partitioning changed" + static MYSQL mysql_connection, *sock = 0; static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0, opt_compress = 0, opt_databases = 0, opt_fast = 0, @@ -47,7 +51,7 @@ static char *opt_password = 0, *current_user = 0, *default_charset= 0, *current_host= 0; static char *opt_plugin_dir= 0, *opt_default_auth= 0; static int first_error = 0; -DYNAMIC_ARRAY tables4repair, tables4rebuild; +DYNAMIC_ARRAY tables4repair, tables4rebuild, alter_table_cmds; static char *shared_memory_base_name=0; static uint opt_protocol=0; @@ -620,6 +624,17 @@ static int process_all_tables_in_db(char *database) } /* process_all_tables_in_db */ +static int run_query(const char *query) +{ + if (mysql_query(sock, query)) + { + fprintf(stderr, "Failed to %s\n", query); + fprintf(stderr, "Error: %s\n", mysql_error(sock)); + return 1; + } + return 0; +} + static int fix_table_storage_name(const char *name) { @@ -630,12 +645,7 @@ static int fix_table_storage_name(const char *name) if (strncmp(name, "#mysql50#", 9)) DBUG_RETURN(1); sprintf(qbuf, "RENAME TABLE `%s` TO `%s`", name, name + 9); - if (mysql_query(sock, qbuf)) - { - fprintf(stderr, "Failed to %s\n", qbuf); - fprintf(stderr, "Error: %s\n", mysql_error(sock)); - rc= 1; - } + rc= run_query(qbuf); if (verbose) printf("%-50s %s\n", name, rc ? "FAILED" : "OK"); DBUG_RETURN(rc); @@ -650,12 +660,7 @@ static int fix_database_storage_name(const char *name) if (strncmp(name, "#mysql50#", 9)) DBUG_RETURN(1); sprintf(qbuf, "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME", name); - if (mysql_query(sock, qbuf)) - { - fprintf(stderr, "Failed to %s\n", qbuf); - fprintf(stderr, "Error: %s\n", mysql_error(sock)); - rc= 1; - } + rc= run_query(qbuf); if (verbose) printf("%-50s %s\n", name, rc ? "FAILED" : "OK"); DBUG_RETURN(rc); @@ -726,15 +731,7 @@ static int use_db(char *database) static int disable_binlog() { const char *stmt= "SET SQL_LOG_BIN=0"; - DBUG_ENTER("disable_binlog"); - - if (mysql_query(sock, stmt)) - { - fprintf(stderr, "Failed to %s\n", stmt); - fprintf(stderr, "Error: %s\n", mysql_error(sock)); - DBUG_RETURN(1); - } - DBUG_RETURN(0); + return run_query(stmt); } static int handle_request_for_tables(char *tables, uint length) @@ -821,6 +818,7 @@ static void print_result() MYSQL_RES *res; MYSQL_ROW row; char prev[(NAME_LEN+9)*2+2]; + char prev_alter[MAX_ALTER_STR_SIZE]; uint i; my_bool found_error=0, table_rebuild=0; DBUG_ENTER("print_result"); @@ -828,6 +826,7 @@ static void print_result() res = mysql_use_result(sock); prev[0] = '\0'; + prev_alter[0]= 0; for (i = 0; (row = mysql_fetch_row(res)); i++) { int changed = strcmp(prev, row[0]); @@ -844,12 +843,18 @@ static void print_result() strcmp(row[3],"OK")) { if (table_rebuild) - insert_dynamic(&tables4rebuild, (uchar*) prev); + { + if (prev_alter[0]) + insert_dynamic(&alter_table_cmds, (uchar*) prev_alter); + else + insert_dynamic(&tables4rebuild, (uchar*) prev); + } else insert_dynamic(&tables4repair, (uchar*) prev); } found_error=0; table_rebuild=0; + prev_alter[0]= 0; if (opt_silent) continue; } @@ -866,11 +871,30 @@ static void print_result() printf("%-50s %s", row[0], "Needs upgrade"); else printf("%s\n%-9s: %s", row[0], row[2], row[3]); - if (strcmp(row[2],"note")) + if (opt_auto_repair && strcmp(row[2],"note")) { - found_error=1; - if (opt_auto_repair && strstr(row[3], "ALTER TABLE") != NULL) + const char *alter_txt= strstr(row[3], "ALTER TABLE"); + found_error=1; + if (alter_txt) + { table_rebuild=1; + if (!strncmp(row[3], KEY_PARTITIONING_CHANGED_STR, + strlen(KEY_PARTITIONING_CHANGED_STR)) && + strstr(alter_txt, "PARTITION BY")) + { + if (strlen(alter_txt) >= MAX_ALTER_STR_SIZE) + { + printf("Error: Alter command too long (>= %d)," + " please do \"%s\" or dump/reload to fix it!\n", + MAX_ALTER_STR_SIZE, + alter_txt); + table_rebuild= 0; + prev_alter[0]= 0; + } + else + strcpy(prev_alter, alter_txt); + } + } } } else @@ -882,7 +906,12 @@ static void print_result() if (found_error && opt_auto_repair && what_to_do != DO_REPAIR) { if (table_rebuild) - insert_dynamic(&tables4rebuild, (uchar*) prev); + { + if (prev_alter[0]) + insert_dynamic(&alter_table_cmds, (uchar*) prev_alter); + else + insert_dynamic(&tables4rebuild, (uchar*) prev); + } else insert_dynamic(&tables4repair, (uchar*) prev); } @@ -1001,7 +1030,9 @@ int main(int argc, char **argv) (my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16, 64, MYF(0)) || my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16, - 64, MYF(0)))) + 64, MYF(0)) || + my_init_dynamic_array(&alter_table_cmds, MAX_ALTER_STR_SIZE, 0, + 1, MYF(0)))) goto end; if (opt_alldbs) @@ -1026,6 +1057,8 @@ int main(int argc, char **argv) } for (i = 0; i < tables4rebuild.elements ; i++) rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i)); + for (i = 0; i < alter_table_cmds.elements ; i++) + run_query((char*) dynamic_array_ptr(&alter_table_cmds, i)); } ret= test(first_error); diff --git a/client/mysqldump.c b/client/mysqldump.c index c1e848b1752..b810973f9c2 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2010, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 708f9077cb2..1fb898bd129 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6355,8 +6355,7 @@ void do_delimiter(struct st_command* command) if (!(*p)) die("Can't set empty delimiter"); - strmake(delimiter, p, sizeof(delimiter) - 1); - delimiter_length= strlen(delimiter); + delimiter_length= strmake_buf(delimiter, p) - delimiter; DBUG_PRINT("exit", ("delimiter: %s", delimiter)); command->last_argument= p + delimiter_length; diff --git a/client/sql_string.cc.dontuse b/client/sql_string.cc.dontuse index 64219886dd0..9679197b207 100644 --- a/client/sql_string.cc.dontuse +++ b/client/sql_string.cc.dontuse @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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 @@ -691,7 +691,7 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length) { if (from->Alloced_length >= from_length) return from; - if (from->alloced || !to || from == to) + if ((from->alloced && (from->Alloced_length != 0)) || !to || from == to) { (void) from->realloc(from_length); return from; diff --git a/cmake/configure.pl b/cmake/configure.pl index d39071b13bb..9f46a5668c9 100644 --- a/cmake/configure.pl +++ b/cmake/configure.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/cpack_rpm.cmake b/cmake/cpack_rpm.cmake index e7da4e984e0..5da00f9cecc 100644 --- a/cmake/cpack_rpm.cmake +++ b/cmake/cpack_rpm.cmake @@ -93,7 +93,7 @@ SET(CPACK_RPM_devel_USER_FILELIST ${ignored}) SET(CPACK_RPM_test_USER_FILELIST ${ignored}) SET(CPACK_RPM_client_PACKAGE_OBSOLETES "mysql-client MySQL-client MySQL-OurDelta-client") -SET(CPACK_RPM_client_PACKAGE_PROVIDES "MariaDB-client MySQL-client mysql-client") +SET(CPACK_RPM_client_PACKAGE_PROVIDES "MySQL-client mysql-client") # this is a workaround for CPackRPM.cmake (as of 2.8.8) bug. # If a package group does not specify OBSOLETES/REQUIRES the values of the @@ -102,22 +102,40 @@ SET(CPACK_RPM_common_PACKAGE_OBSOLETES "MySQL-common") SET(CPACK_RPM_common_PACKAGE_PROVIDES "MariaDB-common") SET(CPACK_RPM_devel_PACKAGE_OBSOLETES "mysql-devel MySQL-devel MySQL-OurDelta-devel") -SET(CPACK_RPM_devel_PACKAGE_PROVIDES "MariaDB-devel MySQL-devel mysql-devel") +SET(CPACK_RPM_devel_PACKAGE_PROVIDES "MySQL-devel mysql-devel") -SET(CPACK_RPM_server_PACKAGE_OBSOLETES "MariaDB mysql mysql-server MySQL-server MySQL-OurDelta-server") -SET(CPACK_RPM_server_PACKAGE_PROVIDES "MariaDB MariaDB-server MySQL-server config(MariaDB-server) msqlormysql mysql mysql(x86-32) mysql(x86-64) mysql-server") +SET(CPACK_RPM_server_PACKAGE_OBSOLETES "MariaDB MySQL mysql-server MySQL-server MySQL-OurDelta-server") +SET(CPACK_RPM_server_PACKAGE_PROVIDES "MariaDB MySQL MySQL-server msqlormysql mysql-server") SET(CPACK_RPM_server_PRE_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/server-prein.sh) SET(CPACK_RPM_server_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/server-preun.sh) SET(CPACK_RPM_server_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/server-postin.sh) SET(CPACK_RPM_server_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/server-postun.sh) SET(CPACK_RPM_shared_PACKAGE_OBSOLETES "mysql-shared MySQL-shared-standard MySQL-shared-pro MySQL-shared-pro-cert MySQL-shared-pro-gpl MySQL-shared-pro-gpl-cert MySQL-shared MySQL-OurDelta-shared mysql-libs") -SET(CPACK_RPM_shared_PACKAGE_PROVIDES "MariaDB-shared MySQL-shared mysql-shared libmysqlclient.so.18 libmysqlclient.so.18(libmysqlclient_16) libmysqlclient.so.18(libmysqlclient_18) libmysqlclient_r.so.18 libmysqlclient_r.so.18(libmysqlclient_18) mysql-libs") +SET(CPACK_RPM_shared_PACKAGE_PROVIDES "MySQL-shared mysql-shared") + SET(CPACK_RPM_shared_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/shared-post.sh) SET(CPACK_RPM_shared_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/shared-post.sh) SET(CPACK_RPM_test_PACKAGE_OBSOLETES "mysql-test MySQL-test MySQL-OurDelta-test") -SET(CPACK_RPM_test_PACKAGE_PROVIDES "MariaDB-test MySQL-test mysql-test") +SET(CPACK_RPM_test_PACKAGE_PROVIDES "MySQL-test mysql-test") + +# Argh! Different distributions call packages differently, to be a drop-in replacement +# we have to fake distribution-speficic dependencies +MACRO(ALTERNATIVE_NAME real alt) + SET(p "CPACK_RPM_${real}_PACKAGE_PROVIDES") + SET(${p} "${${p}} ${alt} ${alt}(x86-32) ${alt}(x86-64) config(${alt})") +ENDMACRO(ALTERNATIVE_NAME) + +IF(RPM MATCHES "(rhel|centos)5") + ALTERNATIVE_NAME("shared" "mysql") +ELSEIF(RPM MATCHES "(rhel|centos)6") + ALTERNATIVE_NAME("client" "mysql") + ALTERNATIVE_NAME("shared" "mysql-libs") +ELSEIF(RPM MATCHES "fedora") + ALTERNATIVE_NAME("client" "mysql") + ALTERNATIVE_NAME("shared" "mysql-libs") +ENDIF() # workaround for lots of perl dependencies added by rpmbuild SET(CPACK_RPM_test_PACKAGE_PROVIDES "${CPACK_RPM_test_PACKAGE_PROVIDES} perl(lib::mtr_gcov.pl) perl(lib::mtr_gprof.pl) perl(lib::mtr_io.pl) perl(lib::mtr_misc.pl) perl(lib::mtr_process.pl) perl(lib::v1/mtr_cases.pl) perl(lib::v1/mtr_gcov.pl) perl(lib::v1/mtr_gprof.pl) perl(lib::v1/mtr_im.pl) perl(lib::v1/mtr_io.pl) perl(lib::v1/mtr_match.pl) perl(lib::v1/mtr_misc.pl) perl(lib::v1/mtr_process.pl) perl(lib::v1/mtr_report.pl) perl(lib::v1/mtr_stress.pl) perl(lib::v1/mtr_timer.pl) perl(lib::v1/mtr_unique.pl) perl(mtr_cases) perl(mtr_io.pl) perl(mtr_match) perl(mtr_misc.pl) perl(mtr_report) perl(mtr_results) perl(mtr_unique)") diff --git a/cmake/create_initial_db.cmake.in b/cmake/create_initial_db.cmake.in index f330c13b09d..c77e28d882c 100644 --- a/cmake/create_initial_db.cmake.in +++ b/cmake/create_initial_db.cmake.in @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/make_dist.cmake.in b/cmake/make_dist.cmake.in index 1b347e41836..ada27c36926 100644 --- a/cmake/make_dist.cmake.in +++ b/cmake/make_dist.cmake.in @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/mysql_version.cmake b/cmake/mysql_version.cmake index 9dd2dfed1e6..2abff3dc63d 100644 --- a/cmake/mysql_version.cmake +++ b/cmake/mysql_version.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/os/FreeBSD.cmake b/cmake/os/FreeBSD.cmake index 27afe679f25..3a5a29f6de6 100644 --- a/cmake/os/FreeBSD.cmake +++ b/cmake/os/FreeBSD.cmake @@ -32,9 +32,3 @@ IF(EXECINFO) SET(LIBEXECINFO ${EXECINFO}) ENDIF() -# Use atomic builtins -IF(CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686") - SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=i686") -ENDIF() diff --git a/cmake/os/Linux.cmake b/cmake/os/Linux.cmake index 108e06cf7b0..36d7ade66a7 100644 --- a/cmake/os/Linux.cmake +++ b/cmake/os/Linux.cmake @@ -47,9 +47,3 @@ IF(HAVE_DECL_SHM_HUGETLB) SET(HAVE_LARGE_PAGE_OPTION 1) ENDIF() -IF(CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR MATCHES "86") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686") - SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=i686") -ENDIF() - diff --git a/cmake/package_name.cmake b/cmake/package_name.cmake index df6822493cb..b4125e873d6 100644 --- a/cmake/package_name.cmake +++ b/cmake/package_name.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/plugin.cmake b/cmake/plugin.cmake index f016d8eab4f..2f1ebc8f428 100644 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/readline.cmake b/cmake/readline.cmake index 285b436921e..c99557683a6 100644 --- a/cmake/readline.cmake +++ b/cmake/readline.cmake @@ -115,7 +115,7 @@ ENDMACRO() MACRO (MYSQL_USE_BUNDLED_READLINE) SET(USE_NEW_READLINE_INTERFACE 1) - SET(HAVE_HIST_ENTRY) + SET(HAVE_HIST_ENTRY 0 CACHE INTERNAL "" FORCE) SET(READLINE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/cmd-line-utils) SET(READLINE_LIBRARY readline) ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/cmd-line-utils/readline) diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index cabff530b47..ca950229129 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/cmake/zlib.cmake b/cmake/zlib.cmake index a3960c2a9da..d2e78dd7049 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -56,12 +56,16 @@ MACRO (MYSQL_CHECK_ZLIB_WITH_COMPRESS) INCLUDE(CheckFunctionExists) SET(CMAKE_REQUIRED_LIBRARIES z) CHECK_FUNCTION_EXISTS(crc32 HAVE_CRC32) + CHECK_FUNCTION_EXISTS(compressBound HAVE_COMPRESSBOUND) + CHECK_FUNCTION_EXISTS(deflateBound HAVE_DEFLATEBOUND) SET(CMAKE_REQUIRED_LIBRARIES) - IF(HAVE_CRC32) - SET(WITH_ZLIB "system" CACHE STRING "Which zlib to use (possible values are 'bundled' or 'system')") + IF(HAVE_CRC32 AND HAVE_COMPRESSBOUND AND HAVE_DEFLATEBOUND) + SET(WITH_ZLIB "system" CACHE STRING + "Which zlib to use (possible values are 'bundled' or 'system')") SET(ZLIB_SOURCES "") ELSE() SET(ZLIB_FOUND FALSE CACHE INTERNAL "Zlib found but not usable") + MESSAGE(STATUS "system zlib found but not usable") ENDIF() ENDIF() IF(NOT ZLIB_FOUND) diff --git a/configure.cmake b/configure.cmake index 66a7e78f3ff..755a0402215 100644 --- a/configure.cmake +++ b/configure.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/debian/dist/Debian/control b/debian/dist/Debian/control index c1e085bcc5c..998c9d710eb 100644 --- a/debian/dist/Debian/control +++ b/debian/dist/Debian/control @@ -204,7 +204,7 @@ Description: MariaDB database server binaries Package: mariadb-server Section: database Architecture: all -Depends: mariadb-server-10.0, ${misc:Depends} +Depends: mariadb-server-10.0 (= ${source:Version}), ${misc:Depends} Description: MariaDB database server (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-server (currently mariadb-server-10.0), as determined by the MariaDB @@ -220,7 +220,7 @@ Description: MariaDB database server (metapackage depending on the latest versio Package: mariadb-client Section: database Architecture: all -Depends: mariadb-client-10.0, ${misc:Depends} +Depends: mariadb-client-10.0 (= ${source:Version}), ${misc:Depends} Description: MariaDB database client (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-client (currently mariadb-client-10.0), as determined by the MariaDB @@ -230,7 +230,7 @@ Description: MariaDB database client (metapackage depending on the latest versio Package: mariadb-test Section: database Architecture: all -Depends: mariadb-test-10.0 +Depends: mariadb-test-10.0 (= ${source:Version}) Description: MariaDB database regression test suite (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-test (currently mariadb-test-10.0), as determined by the MariaDB diff --git a/debian/dist/Debian/mariadb-server-10.0.files.in b/debian/dist/Debian/mariadb-server-10.0.files.in index 1f1132ea4fa..e56a5894b3f 100644 --- a/debian/dist/Debian/mariadb-server-10.0.files.in +++ b/debian/dist/Debian/mariadb-server-10.0.files.in @@ -81,3 +81,4 @@ usr/share/mysql/mysql_performance_tables.sql usr/share/mysql/mysql_test_data_timezone.sql @CASSANDRA_DEB_FILES@ @OQGRAPH_DEB_FILES@ +@SPIDER_DEB_FILES@ diff --git a/debian/dist/Ubuntu/control b/debian/dist/Ubuntu/control index 093e2577299..228498c1015 100644 --- a/debian/dist/Ubuntu/control +++ b/debian/dist/Ubuntu/control @@ -198,7 +198,7 @@ Description: MariaDB database server binaries Package: mariadb-server Section: database Architecture: all -Depends: mariadb-server-10.0, ${misc:Depends} +Depends: mariadb-server-10.0 (= ${source:Version}), ${misc:Depends} Description: MariaDB database server (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-server (currently mariadb-server-10.0), as determined by the MariaDB @@ -214,7 +214,7 @@ Description: MariaDB database server (metapackage depending on the latest versio Package: mariadb-client Section: database Architecture: all -Depends: mariadb-client-10.0, ${misc:Depends} +Depends: mariadb-client-10.0 (= ${source:Version}), ${misc:Depends} Description: MariaDB database client (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-client (currently mariadb-client-10.0), as determined by the MariaDB @@ -224,7 +224,7 @@ Description: MariaDB database client (metapackage depending on the latest versio Package: mariadb-test Section: database Architecture: all -Depends: mariadb-test-10.0 +Depends: mariadb-test-10.0 (= ${source:Version}) Description: MariaDB database regression test suite (metapackage depending on the latest version) This is an empty package that depends on the current "best" version of mariadb-test (currently mariadb-test-10.0), as determined by the MariaDB diff --git a/debian/dist/Ubuntu/mariadb-server-10.0.files.in b/debian/dist/Ubuntu/mariadb-server-10.0.files.in index 565405adb6f..c0e67d617d9 100644 --- a/debian/dist/Ubuntu/mariadb-server-10.0.files.in +++ b/debian/dist/Ubuntu/mariadb-server-10.0.files.in @@ -83,3 +83,4 @@ usr/share/mysql/mysql_performance_tables.sql usr/share/mysql/mysql_test_data_timezone.sql @CASSANDRA_DEB_FILES@ @OQGRAPH_DEB_FILES@ +@SPIDER_DEB_FILES@ diff --git a/extra/charset2html.c b/extra/charset2html.c index 8dcfa0c8990..834f54f125b 100644 --- a/extra/charset2html.c +++ b/extra/charset2html.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2002-2004, 2007, 2008 MySQL AB + Use is subject to license terms 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/extra/yassl/CMakeLists.txt b/extra/yassl/CMakeLists.txt index 5f2f1956803..26ea7e23e33 100644 --- a/extra/yassl/CMakeLists.txt +++ b/extra/yassl/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. # # 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/extra/yassl/examples/client/client.cpp b/extra/yassl/examples/client/client.cpp index d05c31d4d63..fc05b66aaf7 100644 --- a/extra/yassl/examples/client/client.cpp +++ b/extra/yassl/examples/client/client.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 MySQL AB + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/examples/echoclient/echoclient.cpp b/extra/yassl/examples/echoclient/echoclient.cpp index c2b8ff66ac9..fabcfbec29e 100644 --- a/extra/yassl/examples/echoclient/echoclient.cpp +++ b/extra/yassl/examples/echoclient/echoclient.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 MySQL AB + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/examples/echoserver/echoserver.cpp b/extra/yassl/examples/echoserver/echoserver.cpp index bd044e70e8b..82696568ace 100644 --- a/extra/yassl/examples/echoserver/echoserver.cpp +++ b/extra/yassl/examples/echoserver/echoserver.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 MySQL AB + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/examples/server/server.cpp b/extra/yassl/examples/server/server.cpp index 3fac40e88c4..173ce8fb548 100644 --- a/extra/yassl/examples/server/server.cpp +++ b/extra/yassl/examples/server/server.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 MySQL AB + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/buffer.hpp b/extra/yassl/include/buffer.hpp index 2d7817a7ca2..27f71199093 100644 --- a/extra/yassl/include/buffer.hpp +++ b/extra/yassl/include/buffer.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/cert_wrapper.hpp b/extra/yassl/include/cert_wrapper.hpp index 10634692713..cc687e24f6a 100644 --- a/extra/yassl/include/cert_wrapper.hpp +++ b/extra/yassl/include/cert_wrapper.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2008 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/lock.hpp b/extra/yassl/include/lock.hpp index 487bedfcc70..5273f92f151 100644 --- a/extra/yassl/include/lock.hpp +++ b/extra/yassl/include/lock.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/openssl/prefix_ssl.h b/extra/yassl/include/openssl/prefix_ssl.h index dbe8ac27ad0..19725206cf8 100644 --- a/extra/yassl/include/openssl/prefix_ssl.h +++ b/extra/yassl/include/openssl/prefix_ssl.h @@ -1,6 +1,5 @@ /* - Copyright (c) 2006, 2007 MySQL AB, 2008 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp index 4c61698e7e3..ee4c1fbc79a 100644 --- a/extra/yassl/include/socket_wrapper.hpp +++ b/extra/yassl/include/socket_wrapper.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2011, Oracle and/or its affiliates. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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/extra/yassl/include/yassl_error.hpp b/extra/yassl/include/yassl_error.hpp index 8efc7f72e87..a4b29ae2e8c 100644 --- a/extra/yassl/include/yassl_error.hpp +++ b/extra/yassl/include/yassl_error.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2010 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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 @@ -53,7 +52,8 @@ enum YasslError { badVersion_error = 117, compress_error = 118, decompress_error = 119, - pms_version_error = 120 + pms_version_error = 120, + sanityCipher_error = 121 // !!!! add error message to .cpp !!!! diff --git a/extra/yassl/include/yassl_imp.hpp b/extra/yassl/include/yassl_imp.hpp index 04e85c16a04..a952da0d3d9 100644 --- a/extra/yassl/include/yassl_imp.hpp +++ b/extra/yassl/include/yassl_imp.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2008 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index 82cadb37c30..d04e0d56bf8 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp index a9e22833eb1..6a8c3f6c075 100644 --- a/extra/yassl/include/yassl_types.hpp +++ b/extra/yassl/include/yassl_types.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2008 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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 @@ -220,7 +219,11 @@ const int DEFAULT_TIMEOUT = 500; // Default Session timeout in seconds const int MAX_RECORD_SIZE = 16384; // 2^14, max size by standard const int COMPRESS_EXTRA = 1024; // extra compression possible addition const int SESSION_FLUSH_COUNT = 256; // when to flush session cache - +const int MAX_PAD_SIZE = 256; // max TLS padding size +const int COMPRESS_CONSTANT = 13; // compression calculation constant +const int COMPRESS_UPPER = 55; // compression calculation numerator +const int COMPRESS_LOWER = 64; // compression calculation denominator +const int COMPRESS_DUMMY_SIZE = 64; // compression dummy round size typedef uint8 Cipher; // first byte is always 0x00 for SSLv3 & TLS diff --git a/extra/yassl/src/buffer.cpp b/extra/yassl/src/buffer.cpp index d885c953207..ec35f1760e7 100644 --- a/extra/yassl/src/buffer.cpp +++ b/extra/yassl/src/buffer.cpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp index a89490e9701..752e9cf5f0f 100644 --- a/extra/yassl/src/cert_wrapper.cpp +++ b/extra/yassl/src/cert_wrapper.cpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2008, 2009 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/src/crypto_wrapper.cpp b/extra/yassl/src/crypto_wrapper.cpp index 42a43627760..d85cc6ba6a0 100644 --- a/extra/yassl/src/crypto_wrapper.cpp +++ b/extra/yassl/src/crypto_wrapper.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp index 97db6264dbb..d4c45ae8a3d 100644 --- a/extra/yassl/src/handshake.cpp +++ b/extra/yassl/src/handshake.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 @@ -220,12 +220,45 @@ void buildSHA(SSL& ssl, Finished& fin, const opaque* sender) } +// sanity checks on encrypted message size +static int sanity_check_message(SSL& ssl, uint msgSz) +{ + uint minSz = 0; + + if (ssl.getSecurity().get_parms().cipher_type_ == block) { + uint blockSz = ssl.getCrypto().get_cipher().get_blockSize(); + if (msgSz % blockSz) + return -1; + + minSz = ssl.getSecurity().get_parms().hash_size_ + 1; // pad byte too + if (blockSz > minSz) + minSz = blockSz; + + if (ssl.isTLSv1_1()) + minSz += blockSz; // explicit IV + } + else { // stream + minSz = ssl.getSecurity().get_parms().hash_size_; + } + + if (msgSz < minSz) + return -1; + + return 0; +} + + // decrypt input message in place, store size in case needed later void decrypt_message(SSL& ssl, input_buffer& input, uint sz) { input_buffer plain(sz); opaque* cipher = input.get_buffer() + input.get_current(); + if (sanity_check_message(ssl, sz) != 0) { + ssl.SetError(sanityCipher_error); + return; + } + ssl.useCrypto().use_cipher().decrypt(plain.get_buffer(), cipher, sz); memcpy(cipher, plain.get_buffer(), sz); ssl.useSecurity().use_parms().encrypt_size_ = sz; @@ -774,6 +807,8 @@ int DoProcessReply(SSL& ssl) return 0; } decrypt_message(ssl, buffer, hdr.length_); + if (ssl.GetError()) + return 0; } mySTL::auto_ptr msg(mf.CreateObject(hdr.type_)); diff --git a/extra/yassl/src/lock.cpp b/extra/yassl/src/lock.cpp index d603440757f..c74ea1c6b76 100644 --- a/extra/yassl/src/lock.cpp +++ b/extra/yassl/src/lock.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/src/make.bat b/extra/yassl/src/make.bat index cccd11dbd17..42f49ee4c0a 100755 --- a/extra/yassl/src/make.bat +++ b/extra/yassl/src/make.bat @@ -1,4 +1,4 @@ -REM Copyright (C) 2006, 2007 MySQL AB +REM Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. REM REM This program is free software; you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp index 4d41c4f8442..9b099973578 100644 --- a/extra/yassl/src/socket_wrapper.cpp +++ b/extra/yassl/src/socket_wrapper.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index 5e4e8197ff2..9352423de2a 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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/extra/yassl/src/yassl.cpp b/extra/yassl/src/yassl.cpp index 99a1da5371b..b6b9a87e09a 100644 --- a/extra/yassl/src/yassl.cpp +++ b/extra/yassl/src/yassl.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp index f48fbdc925e..2d42e82ab4a 100644 --- a/extra/yassl/src/yassl_error.cpp +++ b/extra/yassl/src/yassl_error.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2011, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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 @@ -144,6 +144,10 @@ void SetErrorString(YasslError error, char* buffer) strncpy(buffer, "bad PreMasterSecret version error", max); break; + case sanityCipher_error : + strncpy(buffer, "sanity check on cipher text size error", max); + break; + // openssl errors case SSL_ERROR_WANT_READ : strncpy(buffer, "the read operation would block", max); diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp index c0ef23a4e94..d943775101b 100644 --- a/extra/yassl/src/yassl_imp.cpp +++ b/extra/yassl/src/yassl_imp.cpp @@ -972,30 +972,193 @@ output_buffer& operator<<(output_buffer& output, const Data& data) } +// check all bytes for equality +static int constant_compare(const byte* a, const byte* b, int len) +{ + int good = 0; + int bad = 0; + + for (int i = 0; i < len; i++) { + if (a[i] == b[i]) + good++; + else + bad++; + } + + if (good == len) + return 0; + else + return 0 - bad; // failure +} + + +// check bytes for pad value +static int pad_check(const byte* input, byte pad, int len) +{ + int good = 0; + int bad = 0; + + for (int i = 0; i < len; i++) { + if (input[i] == pad) + good++; + else + bad++; + } + + if (good == len) + return 0; + else + return 0 - bad; // failure +} + + +// get number of compression rounds +static inline int get_rounds(int pLen, int padLen, int t) +{ + int roundL1 = 1; // round ups + int roundL2 = 1; + + int L1 = COMPRESS_CONSTANT + pLen - t; + int L2 = COMPRESS_CONSTANT + pLen - padLen - 1 - t; + + L1 -= COMPRESS_UPPER; + L2 -= COMPRESS_UPPER; + + if ( (L1 % COMPRESS_LOWER) == 0) + roundL1 = 0; + if ( (L2 % COMPRESS_LOWER) == 0) + roundL2 = 0; + + L1 /= COMPRESS_LOWER; + L2 /= COMPRESS_LOWER; + + L1 += roundL1; + L2 += roundL2; + + return L1 - L2; +} + + +// do compression rounds on dummy data +static inline void compress_rounds(SSL& ssl, int rounds, const byte* dummy) +{ + if (rounds) { + Digest* digest = NULL; + + MACAlgorithm ma = ssl.getSecurity().get_parms().mac_algorithm_; + if (ma == sha) + digest = NEW_YS SHA; + else if (ma == md5) + digest = NEW_YS MD5; + else if (ma == rmd) + digest = NEW_YS RMD; + else + return; + + for (int i = 0; i < rounds; i++) + digest->update(dummy, COMPRESS_LOWER); + + ysDelete(digest); + } +} + + +// timing resistant pad verification +static int timing_verify(SSL& ssl, const byte* input, int padLen, int t, + int pLen) +{ + byte verify[SHA_LEN]; + byte dummy[MAX_PAD_SIZE]; + + memset(dummy, 1, sizeof(dummy)); + + if ( (t + padLen + 1) > pLen) { + pad_check(dummy, (byte)padLen, MAX_PAD_SIZE); + if (ssl.isTLS()) + TLS_hmac(ssl, verify, input, pLen - t, application_data, 1); + else + hmac(ssl, verify, input, pLen - t, application_data, 1); + constant_compare(verify, input + pLen - t, t); + + return -1; + } + + if (pad_check(input + pLen - (padLen + 1), (byte)padLen, padLen + 1) != 0) { + pad_check(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); + if (ssl.isTLS()) + TLS_hmac(ssl, verify, input, pLen - t, application_data, 1); + else + hmac(ssl, verify, input, pLen - t, application_data, 1); + constant_compare(verify, input + pLen - t, t); + + return -1; + } + + pad_check(dummy, (byte)padLen, MAX_PAD_SIZE - padLen - 1); + if (ssl.isTLS()) + TLS_hmac(ssl, verify, input, pLen - padLen - 1 - t, application_data,1); + else + hmac(ssl, verify, input, pLen - padLen - 1 - t, application_data, 1); + + compress_rounds(ssl, get_rounds(pLen, padLen, t), dummy); + + if (constant_compare(verify, input + (pLen - padLen - 1 - t), t) != 0) + return -1; + + return 0; +} + + // Process handler for Data void Data::Process(input_buffer& input, SSL& ssl) { int msgSz = ssl.getSecurity().get_parms().encrypt_size_; int pad = 0, padSz = 0; int ivExtra = 0; + int digestSz = ssl.getCrypto().get_digest().get_digestSize(); + const byte* rawData = input.get_buffer() + input.get_current(); + opaque verify[SHA_LEN]; if (ssl.getSecurity().get_parms().cipher_type_ == block) { if (ssl.isTLSv1_1()) // IV ivExtra = ssl.getCrypto().get_cipher().get_blockSize(); pad = *(input.get_buffer() + input.get_current() + msgSz -ivExtra - 1); padSz = 1; + + if (ssl.isTLS()) { + if (timing_verify(ssl, rawData, pad,digestSz, msgSz-ivExtra) != 0) { + ssl.SetError(verify_error); + return; + } + } + else { // SSLv3, some don't do this padding right + int sz3 = msgSz - digestSz - pad - 1; + hmac(ssl, verify, rawData, sz3, application_data, true); + if (constant_compare(verify, rawData + sz3, digestSz) != 0) { + ssl.SetError(verify_error); + return; + } + } } - int digestSz = ssl.getCrypto().get_digest().get_digestSize(); + else { // stream + int streamSz = msgSz - digestSz; + if (ssl.isTLS()) + TLS_hmac(ssl, verify, rawData, streamSz, application_data, true); + else + hmac(ssl, verify, rawData, streamSz, application_data, true); + if (constant_compare(verify, rawData + streamSz, digestSz) != 0) { + ssl.SetError(verify_error); + return; + } + } + int dataSz = msgSz - ivExtra - digestSz - pad - padSz; - opaque verify[SHA_LEN]; if (dataSz < 0) { ssl.SetError(bad_input); return; } - const byte* rawData = input.get_buffer() + input.get_current(); - // read data if (dataSz) { // could be compressed if (ssl.CompressionOn()) { @@ -1013,27 +1176,10 @@ void Data::Process(input_buffer& input, SSL& ssl) input.read(data->get_buffer(), dataSz); data->add_size(dataSz); } - - if (ssl.isTLS()) - TLS_hmac(ssl, verify, rawData, dataSz, application_data, true); - else - hmac(ssl, verify, rawData, dataSz, application_data, true); } - // read mac and skip fill - opaque mac[SHA_LEN]; - input.read(mac, digestSz); - input.set_current(input.get_current() + pad + padSz); - - // verify - if (dataSz) { - if (memcmp(mac, verify, digestSz)) { - ssl.SetError(verify_error); - return; - } - } - else - ssl.get_SEQIncrement(true); // even though no data, increment verify + // advance past mac and fill + input.set_current(input.get_current() + digestSz + pad + padSz); } diff --git a/extra/yassl/taocrypt/benchmark/benchmark.cpp b/extra/yassl/taocrypt/benchmark/benchmark.cpp index 6ed7351a56b..834f340b651 100644 --- a/extra/yassl/taocrypt/benchmark/benchmark.cpp +++ b/extra/yassl/taocrypt/benchmark/benchmark.cpp @@ -1,3 +1,21 @@ +/* + Copyright (c) 2006, 2012, Oracle and/or its affiliates. + + 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; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA. +*/ + // benchmark.cpp // TaoCrypt benchmark diff --git a/extra/yassl/taocrypt/benchmark/make.bat b/extra/yassl/taocrypt/benchmark/make.bat index 1457521bce9..e9156e0c8af 100755 --- a/extra/yassl/taocrypt/benchmark/make.bat +++ b/extra/yassl/taocrypt/benchmark/make.bat @@ -1,4 +1,4 @@ -REM Copyright (C) 2006, 2007 MySQL AB +REM Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. REM REM This program is free software; you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by diff --git a/extra/yassl/taocrypt/include/aes.hpp b/extra/yassl/taocrypt/include/aes.hpp index e2041fc9350..01763033156 100644 --- a/extra/yassl/taocrypt/include/aes.hpp +++ b/extra/yassl/taocrypt/include/aes.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp index d52413b504c..c58c7579ccf 100644 --- a/extra/yassl/taocrypt/include/asn.hpp +++ b/extra/yassl/taocrypt/include/asn.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2010 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp index 77017e9d5e4..601d9dbce57 100644 --- a/extra/yassl/taocrypt/include/block.hpp +++ b/extra/yassl/taocrypt/include/block.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/blowfish.hpp b/extra/yassl/taocrypt/include/blowfish.hpp index e868872d3cf..347cf05de4b 100644 --- a/extra/yassl/taocrypt/include/blowfish.hpp +++ b/extra/yassl/taocrypt/include/blowfish.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2010, Oracle and/or its affiliates + Copyright (c) 2006, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/include/des.hpp b/extra/yassl/taocrypt/include/des.hpp index 2bc41fc2628..d88e9ef2f46 100644 --- a/extra/yassl/taocrypt/include/des.hpp +++ b/extra/yassl/taocrypt/include/des.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/hash.hpp b/extra/yassl/taocrypt/include/hash.hpp index 4ebc82e073d..4d2f7dd35a1 100644 --- a/extra/yassl/taocrypt/include/hash.hpp +++ b/extra/yassl/taocrypt/include/hash.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/hc128.hpp b/extra/yassl/taocrypt/include/hc128.hpp index d1cf5f075f2..0449b28d8c7 100644 --- a/extra/yassl/taocrypt/include/hc128.hpp +++ b/extra/yassl/taocrypt/include/hc128.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp index 256573cf622..e1a2ed5f426 100644 --- a/extra/yassl/taocrypt/include/integer.hpp +++ b/extra/yassl/taocrypt/include/integer.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/kernelc.hpp b/extra/yassl/taocrypt/include/kernelc.hpp index 5bdf1cffa3f..0840b3f2740 100644 --- a/extra/yassl/taocrypt/include/kernelc.hpp +++ b/extra/yassl/taocrypt/include/kernelc.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp index afa49d5e8a0..ce9e3e371ad 100644 --- a/extra/yassl/taocrypt/include/misc.hpp +++ b/extra/yassl/taocrypt/include/misc.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp index 5fd36b80d3e..bfe8c6ec5d4 100644 --- a/extra/yassl/taocrypt/include/modes.hpp +++ b/extra/yassl/taocrypt/include/modes.hpp @@ -1,6 +1,5 @@ /* - Copyright (c) 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/pwdbased.hpp b/extra/yassl/taocrypt/include/pwdbased.hpp index 58bd5902a58..9b1b62fea45 100644 --- a/extra/yassl/taocrypt/include/pwdbased.hpp +++ b/extra/yassl/taocrypt/include/pwdbased.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/rabbit.hpp b/extra/yassl/taocrypt/include/rabbit.hpp index 1e7276dd8ec..fb4e12c66bc 100644 --- a/extra/yassl/taocrypt/include/rabbit.hpp +++ b/extra/yassl/taocrypt/include/rabbit.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/rsa.hpp b/extra/yassl/taocrypt/include/rsa.hpp index 11a4ccfd039..ee3e378a69f 100644 --- a/extra/yassl/taocrypt/include/rsa.hpp +++ b/extra/yassl/taocrypt/include/rsa.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/include/runtime.hpp b/extra/yassl/taocrypt/include/runtime.hpp index 328c8e9e978..29c4d2db236 100644 --- a/extra/yassl/taocrypt/include/runtime.hpp +++ b/extra/yassl/taocrypt/include/runtime.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/include/types.hpp b/extra/yassl/taocrypt/include/types.hpp index 5d8bc9f0683..973e1d19893 100644 --- a/extra/yassl/taocrypt/include/types.hpp +++ b/extra/yassl/taocrypt/include/types.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/mySTL/stdexcept.hpp b/extra/yassl/taocrypt/mySTL/stdexcept.hpp index 15533eebc02..79ae6de3380 100644 --- a/extra/yassl/taocrypt/mySTL/stdexcept.hpp +++ b/extra/yassl/taocrypt/mySTL/stdexcept.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/mySTL/vector.hpp b/extra/yassl/taocrypt/mySTL/vector.hpp index 35b92610942..f3702b75125 100644 --- a/extra/yassl/taocrypt/mySTL/vector.hpp +++ b/extra/yassl/taocrypt/mySTL/vector.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/aes.cpp b/extra/yassl/taocrypt/src/aes.cpp index 3b09c5280bf..f976650e028 100644 --- a/extra/yassl/taocrypt/src/aes.cpp +++ b/extra/yassl/taocrypt/src/aes.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/src/aestables.cpp b/extra/yassl/taocrypt/src/aestables.cpp index 05c2c3b8e62..60795a549e4 100644 --- a/extra/yassl/taocrypt/src/aestables.cpp +++ b/extra/yassl/taocrypt/src/aestables.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp index b2bebfe8b94..a28d8915330 100644 --- a/extra/yassl/taocrypt/src/algebra.cpp +++ b/extra/yassl/taocrypt/src/algebra.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/src/arc4.cpp b/extra/yassl/taocrypt/src/arc4.cpp index 4630adcb11a..a76a37904f9 100644 --- a/extra/yassl/taocrypt/src/arc4.cpp +++ b/extra/yassl/taocrypt/src/arc4.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/blowfish.cpp b/extra/yassl/taocrypt/src/blowfish.cpp index e1c7c852d19..864f8bac260 100644 --- a/extra/yassl/taocrypt/src/blowfish.cpp +++ b/extra/yassl/taocrypt/src/blowfish.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2010, Oracle and/or its affiliates + Copyright (c) 2006, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/src/coding.cpp b/extra/yassl/taocrypt/src/coding.cpp index 0512ea9c889..8f317a484d8 100644 --- a/extra/yassl/taocrypt/src/coding.cpp +++ b/extra/yassl/taocrypt/src/coding.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/src/dsa.cpp b/extra/yassl/taocrypt/src/dsa.cpp index 7b882b10cd1..72221441b2b 100644 --- a/extra/yassl/taocrypt/src/dsa.cpp +++ b/extra/yassl/taocrypt/src/dsa.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/hash.cpp b/extra/yassl/taocrypt/src/hash.cpp index b36a486368c..c176e6a68d0 100644 --- a/extra/yassl/taocrypt/src/hash.cpp +++ b/extra/yassl/taocrypt/src/hash.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/hc128.cpp b/extra/yassl/taocrypt/src/hc128.cpp index aac92f0abb4..8934c318781 100644 --- a/extra/yassl/taocrypt/src/hc128.cpp +++ b/extra/yassl/taocrypt/src/hc128.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/make.bat b/extra/yassl/taocrypt/src/make.bat index ecd3023f5ab..a8c00f8ee0d 100755 --- a/extra/yassl/taocrypt/src/make.bat +++ b/extra/yassl/taocrypt/src/make.bat @@ -1,4 +1,4 @@ -REM Copyright (C) 2006, 2007 MySQL AB +REM Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. REM REM This program is free software; you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by diff --git a/extra/yassl/taocrypt/src/md4.cpp b/extra/yassl/taocrypt/src/md4.cpp index 54820f4c944..9364a1c23b1 100644 --- a/extra/yassl/taocrypt/src/md4.cpp +++ b/extra/yassl/taocrypt/src/md4.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/md5.cpp b/extra/yassl/taocrypt/src/md5.cpp index 4d0a8bd03be..ee0d64acc17 100644 --- a/extra/yassl/taocrypt/src/md5.cpp +++ b/extra/yassl/taocrypt/src/md5.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp index 1a4dd4a52d3..e410cfe1946 100644 --- a/extra/yassl/taocrypt/src/misc.cpp +++ b/extra/yassl/taocrypt/src/misc.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates + Copyright (c) 2005, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/src/rabbit.cpp b/extra/yassl/taocrypt/src/rabbit.cpp index 0ea4146618a..071a25191f8 100644 --- a/extra/yassl/taocrypt/src/rabbit.cpp +++ b/extra/yassl/taocrypt/src/rabbit.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp index aa9be7f1985..084871c5447 100644 --- a/extra/yassl/taocrypt/src/random.cpp +++ b/extra/yassl/taocrypt/src/random.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/ripemd.cpp b/extra/yassl/taocrypt/src/ripemd.cpp index e012db43de5..f77010ca94d 100644 --- a/extra/yassl/taocrypt/src/ripemd.cpp +++ b/extra/yassl/taocrypt/src/ripemd.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/rsa.cpp b/extra/yassl/taocrypt/src/rsa.cpp index 576146377a3..69c59402e48 100644 --- a/extra/yassl/taocrypt/src/rsa.cpp +++ b/extra/yassl/taocrypt/src/rsa.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/sha.cpp b/extra/yassl/taocrypt/src/sha.cpp index 1ae42d94e4c..f67a4f55067 100644 --- a/extra/yassl/taocrypt/src/sha.cpp +++ b/extra/yassl/taocrypt/src/sha.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 MySQL AB + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/src/twofish.cpp b/extra/yassl/taocrypt/src/twofish.cpp index 4ae493624dc..bf57f5dde44 100644 --- a/extra/yassl/taocrypt/src/twofish.cpp +++ b/extra/yassl/taocrypt/src/twofish.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2010, Oracle and/or its affiliates + Copyright (c) 2006, 2012, Oracle and/or its affiliates 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/extra/yassl/taocrypt/test/make.bat b/extra/yassl/taocrypt/test/make.bat index d6d62b984a8..51f266a1ee6 100755 --- a/extra/yassl/taocrypt/test/make.bat +++ b/extra/yassl/taocrypt/test/make.bat @@ -1,4 +1,4 @@ -REM Copyright (C) 2006, 2007 MySQL AB +REM Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. REM REM This program is free software; you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by diff --git a/extra/yassl/taocrypt/test/memory.cpp b/extra/yassl/taocrypt/test/memory.cpp index a9b21f94902..053d79688a2 100644 --- a/extra/yassl/taocrypt/test/memory.cpp +++ b/extra/yassl/taocrypt/test/memory.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/extra/yassl/taocrypt/test/test.cpp b/extra/yassl/taocrypt/test/test.cpp index 807f91f32ae..00547d0f963 100644 --- a/extra/yassl/taocrypt/test/test.cpp +++ b/extra/yassl/taocrypt/test/test.cpp @@ -1,3 +1,21 @@ +/* + Copyright (c) 2006, 2012, Oracle and/or its affiliates. + + 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; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA. +*/ + // test.cpp // test taocrypt functionality diff --git a/extra/yassl/testsuite/make.bat b/extra/yassl/testsuite/make.bat index 941e499d7e6..e056f3fed53 100755 --- a/extra/yassl/testsuite/make.bat +++ b/extra/yassl/testsuite/make.bat @@ -1,4 +1,4 @@ -REM Copyright (C) 2006, 2007 MySQL AB +REM Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. REM REM This program is free software; you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp index 559ebe54f1b..33f398ae269 100644 --- a/extra/yassl/testsuite/test.hpp +++ b/extra/yassl/testsuite/test.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. + Copyright (c) 2006, 2012, Oracle and/or its affiliates. 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/extra/yassl/testsuite/testsuite.cpp b/extra/yassl/testsuite/testsuite.cpp index fa8c997e7c2..7973a3704e1 100644 --- a/extra/yassl/testsuite/testsuite.cpp +++ b/extra/yassl/testsuite/testsuite.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2006, 2007 MySQL AB + Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 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/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h index 2238347d419..173e32e790c 100644 --- a/include/atomic/x86-gcc.h +++ b/include/atomic/x86-gcc.h @@ -124,10 +124,10 @@ asm volatile ("push %%ebx;" \ "movl (%%ecx), %%ebx;" \ "movl 4(%%ecx), %%ecx;" \ - LOCK_prefix "; cmpxchg8b %0;" \ + LOCK_prefix "; cmpxchg8b (%%esi);" \ "setz %2; pop %%ebx" \ - : "=m" (*a), "+A" (*cmp), "=c" (ret) \ - : "c" (&set), "m" (*a) \ + : "+S" (a), "+A" (*cmp), "=c" (ret) \ + : "c" (&set) \ : "memory", "esp") #endif diff --git a/include/base64.h b/include/base64.h index 4ac0aa72ad8..e19da8762cb 100644 --- a/include/base64.h +++ b/include/base64.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2003 MySQL AB +/* Copyright (c) 2003-2006 MySQL AB + Use is subject to license terms 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/include/ft_global.h b/include/ft_global.h index 8a1069d6e62..73726018d0a 100644 --- a/include/ft_global.h +++ b/include/ft_global.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2000-2005, 2007 MySQL AB, 2009 Sun Microsystems, Inc. Use is subject to license terms. This program is free software; you can redistribute it and/or modify diff --git a/include/m_ctype.h b/include/m_ctype.h index 7ffa8022c85..95b520e4ee9 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -1,5 +1,4 @@ -/* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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 @@ -172,6 +171,8 @@ enum my_lex_states struct charset_info_st; +extern int (*my_string_stack_guard)(int); + /* See strings/CHARSET_INFO.txt for information about this structure */ struct my_collation_handler_st { diff --git a/include/m_string.h b/include/m_string.h index 9efa0376942..1f59fd06084 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 @@ -108,6 +108,15 @@ extern char *strcend(const char *, pchar); extern char *strfill(char * s,size_t len,pchar fill); extern char *strmake(char *dst,const char *src,size_t length); +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define strmake_buf(D,S) strmake(D, S, sizeof(D) - 1) +#else +#define strmake_buf(D,S) ({ \ + compile_time_assert(sizeof(D) != sizeof(char*)); \ + strmake(D, S, sizeof(D) - 1); \ + }) +#endif + #ifndef strmov extern char *strmov(char *dst,const char *src); #endif diff --git a/include/my_global.h b/include/my_global.h index 83e796f107f..7f20cdc7632 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1003,8 +1003,9 @@ typedef struct st_mysql_lex_string LEX_STRING; #define SOCKET_EMFILE EMFILE #endif +#include /* my_bool */ + typedef ulong myf; /* Type of MyFlags in my_funcs */ -typedef char my_bool; /* Small bool */ #define MYF(v) (myf) (v) @@ -1420,6 +1421,7 @@ static inline char *dlerror(void) #endif /* Provide __func__ macro definition for platforms that miss it. */ +#if !defined (__func__) #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 # define __func__ __FUNCTION__ @@ -1437,6 +1439,7 @@ static inline char *dlerror(void) #else # define __func__ "" #endif +#endif /* !defined(__func__) */ #ifndef HAVE_RINT /** diff --git a/include/my_md5.h b/include/my_md5.h index 4f90541067b..b8633b7b1ab 100644 --- a/include/my_md5.h +++ b/include/my_md5.h @@ -1,7 +1,8 @@ #ifndef MY_MD5_INCLUDED #define MY_MD5_INCLUDED -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2001, 2007 MySQL AB, 2009 Sun Microsystems, Inc. + Use is subject to license terms 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/include/my_pthread.h b/include/my_pthread.h index 8c16a112eac..9e39c6565dc 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -119,7 +119,6 @@ int pthread_cancel(pthread_t thread); #define HAVE_LOCALTIME_R 1 #define _REENTRANT 1 #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 -#define PTHREAD_STACK_MIN 65536 #undef SAFE_MUTEX /* This will cause conflicts */ #define pthread_key(T,V) DWORD V @@ -830,6 +829,11 @@ extern uint thd_lib_detected; #define mysql_mutex_record_order(A,B) do { } while(0) #endif +/* At least Windows and NetBSD do not have this definition */ +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 65536 +#endif + #ifdef __cplusplus } #endif diff --git a/include/my_sys.h b/include/my_sys.h index e2132815cdd..24a38656161 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2000-2003 MySQL AB +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2010, 2013, 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/include/my_time.h b/include/my_time.h index 9bd545bb850..b0539939d8d 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -29,16 +29,6 @@ C_MODE_START extern ulonglong log_10_int[20]; extern uchar days_in_month[]; -/* - Portable time_t replacement. - Should be signed and hold seconds for 1902 -- 2038-01-19 range - i.e at least a 32bit variable - - Using the system built in time_t is not an option as - we rely on the above requirements in the time functions -*/ -typedef long my_time_t; - #define MY_TIME_T_MAX LONG_MAX #define MY_TIME_T_MIN LONG_MIN @@ -88,14 +78,27 @@ typedef long my_time_t; #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) +/* + Structure to return status from + str_to_datetime(), str_to_time(). +*/ +typedef struct st_mysql_time_status +{ + int warnings; + uint precision; +} MYSQL_TIME_STATUS; + +static inline void my_time_status_init(MYSQL_TIME_STATUS *status) +{ + status->warnings= status->precision= 0; +} + my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulonglong flags, int *was_cut); -enum enum_mysql_timestamp_type -str_to_time(const char *str, uint length, MYSQL_TIME *l_time, - ulonglong flag, int *warning); -enum enum_mysql_timestamp_type -str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, - ulonglong flags, int *was_cut); +my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time, + ulonglong flag, MYSQL_TIME_STATUS *status); +my_bool str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, + ulonglong flags, MYSQL_TIME_STATUS *status); longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, ulonglong flags, int *was_cut); @@ -117,10 +120,12 @@ ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); ulonglong TIME_to_ulonglong(const MYSQL_TIME *); double TIME_to_double(const MYSQL_TIME *my_time); -longlong pack_time(MYSQL_TIME *my_time); +longlong pack_time(const MYSQL_TIME *my_time); MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time); int check_time_range(struct st_mysql_time *my_time, uint dec, int *warning); +my_bool check_datetime_range(const MYSQL_TIME *ltime); + long calc_daynr(uint year,uint month,uint day); uint calc_days_in_year(uint year); @@ -173,6 +178,8 @@ int my_date_to_str(const MYSQL_TIME *l_time, char *to); int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint digits); int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, uint digits); +int my_timeval_to_str(const struct timeval *tm, char *to, uint dec); + static inline longlong sec_part_shift(longlong second_part, uint digits) { return second_part / (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; @@ -181,11 +188,22 @@ static inline longlong sec_part_unshift(longlong second_part, uint digits) { return second_part * (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; } -static inline ulong sec_part_truncate(ulong second_part, uint digits) + +/* Date/time rounding and truncation functions */ +static inline long my_time_fraction_remainder(long nr, uint decimals) { - /* the cast here should be unnecessary! */ - return second_part - second_part % (ulong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; + DBUG_ASSERT(decimals <= TIME_SECOND_PART_DIGITS); + return nr % (long) log_10_int[TIME_SECOND_PART_DIGITS - decimals]; } +static inline void my_time_trunc(MYSQL_TIME *ltime, uint decimals) +{ + ltime->second_part-= my_time_fraction_remainder(ltime->second_part, decimals); +} +static inline void my_timeval_trunc(struct timeval *tv, uint decimals) +{ + tv->tv_usec-= my_time_fraction_remainder(tv->tv_usec, decimals); +} + #define hrtime_to_my_time(X) ((my_time_t)hrtime_to_time(X)) diff --git a/include/my_user.h b/include/my_user.h index 44eebf1551d..067425a2b47 100644 --- a/include/my_user.h +++ b/include/my_user.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2005 MySQL AB +/* Copyright (c) 2005-2007 MySQL AB + Use is subject to license terms 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/include/my_xml.h b/include/my_xml.h index 6a453ee90be..e97232c7039 100644 --- a/include/my_xml.h +++ b/include/my_xml.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2002, 2003, 2005, 2007 MySQL AB + Use is subject to license terms 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/include/myisamchk.h b/include/myisamchk.h index 152467db547..0a30615c629 100644 --- a/include/myisamchk.h +++ b/include/myisamchk.h @@ -31,27 +31,27 @@ #define T_AUTO_REPAIR 2 /* QQ to be removed */ #define T_BACKUP_DATA 4 #define T_CALC_CHECKSUM 8 -#define T_CHECK 16 /* QQ to be removed */ -#define T_CHECK_ONLY_CHANGED 32 /* QQ to be removed */ +#define T_CHECK 16 +#define T_CHECK_ONLY_CHANGED 32 #define T_CREATE_MISSING_KEYS 64 #define T_DESCRIPT 128 #define T_DONT_CHECK_CHECKSUM 256 #define T_EXTEND 512 -#define T_FAST (1L << 10) /* QQ to be removed */ -#define T_FORCE_CREATE (1L << 11) /* QQ to be removed */ +#define T_FAST (1L << 10) +#define T_FORCE_CREATE (1L << 11) #define T_FORCE_UNIQUENESS (1L << 12) #define T_INFO (1L << 13) #define T_MEDIUM (1L << 14) -#define T_QUICK (1L << 15) /* QQ to be removed */ -#define T_READONLY (1L << 16) /* QQ to be removed */ +#define T_QUICK (1L << 15) +#define T_READONLY (1L << 16) #define T_REP (1L << 17) -#define T_REP_BY_SORT (1L << 18) /* QQ to be removed */ -#define T_REP_PARALLEL (1L << 19) /* QQ to be removed */ +#define T_REP_BY_SORT (1L << 18) +#define T_REP_PARALLEL (1L << 19) #define T_RETRY_WITHOUT_QUICK (1L << 20) #define T_SAFE_REPAIR (1L << 21) #define T_SILENT (1L << 22) -#define T_SORT_INDEX (1L << 23) /* QQ to be removed */ -#define T_SORT_RECORDS (1L << 24) /* QQ to be removed */ +#define T_SORT_INDEX (1L << 23) +#define T_SORT_RECORDS (1L << 24) #define T_STATISTICS (1L << 25) #define T_UNPACK (1L << 26) #define T_UPDATE_STATE (1L << 27) diff --git a/include/myisampack.h b/include/myisampack.h index a065de378d8..0795455dc3e 100644 --- a/include/myisampack.h +++ b/include/myisampack.h @@ -1,7 +1,7 @@ #ifndef MYISAMPACK_INCLUDED #define MYISAMPACK_INCLUDED -/* Copyright (c) 2000-2002, 2004, 2006 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2000-2002, 2004 MySQL AB, 2009 Sun Microsystems, Inc. Use is subject to license terms. This program is free software; you can redistribute it and/or modify diff --git a/include/mysql.h b/include/mysql.h index 69fc8005d61..b070d50e966 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -1,5 +1,6 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 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 diff --git a/include/mysql.h.pp b/include/mysql.h.pp index d33822b2021..4b0edf56a72 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -49,6 +49,9 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT, + MYSQL_TYPE_TIMESTAMP2, + MYSQL_TYPE_DATETIME2, + MYSQL_TYPE_TIME2, MYSQL_TYPE_NEWDECIMAL=246, MYSQL_TYPE_ENUM=247, MYSQL_TYPE_SET=248, @@ -143,6 +146,7 @@ const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); my_bool my_thread_init(void); void my_thread_end(void); #include "mysql_time.h" +typedef long my_time_t; enum enum_mysql_timestamp_type { MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 38573180232..a96e3e72b7b 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -45,6 +45,8 @@ class Item; #define MYSQL_THD void* #endif +typedef char my_bool; + #include #define MYSQL_XIDDATASIZE 128 @@ -72,7 +74,7 @@ typedef struct st_mysql_xid MYSQL_XID; #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0103 /* MariaDB plugin interface version */ -#define MARIA_PLUGIN_INTERFACE_VERSION 0x0104 +#define MARIA_PLUGIN_INTERFACE_VERSION 0x0105 /* The allowable types of plugins diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index eee32a9e523..86b6dea5668 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -25,7 +25,7 @@ #define MYSQL_AUDIT_CLASS_MASK_SIZE 1 -#define MYSQL_AUDIT_INTERFACE_VERSION 0x0300 +#define MYSQL_AUDIT_INTERFACE_VERSION 0x0301 /************************************************************************* @@ -97,6 +97,50 @@ struct mysql_event_connection unsigned int database_length; }; +/* + AUDIT CLASS : TABLE + + LOCK occurs when a connection "locks" (this does not necessarily mean a table + lock and also happens for row-locking engines) the table at the beginning of + a statement. This event is generated at the beginning of every statement for + every affected table, unless there's a LOCK TABLES statement in effect (in + which case it is generated once for LOCK TABLES and then is suppressed until + the tables are unlocked). + + CREATE/DROP/RENAME occur when a table is created, dropped, or renamed. +*/ + +#define MYSQL_AUDIT_TABLE_CLASS 15 +#define MYSQL_AUDIT_TABLE_CLASSMASK (1 << MYSQL_AUDIT_TABLE_CLASS) +#define MYSQL_AUDIT_TABLE_LOCK 0 +#define MYSQL_AUDIT_TABLE_CREATE 1 +#define MYSQL_AUDIT_TABLE_DROP 2 +#define MYSQL_AUDIT_TABLE_RENAME 3 +#define MYSQL_AUDIT_TABLE_ALTER 4 + +struct mysql_event_table +{ + unsigned int event_subclass; + unsigned long thread_id; + const char *user; + const char *priv_user; + const char *priv_host; + const char *external_user; + const char *proxy_user; + const char *host; + const char *ip; + const char *database; + unsigned int database_length; + const char *table; + unsigned int table_length; + /* for MYSQL_AUDIT_TABLE_LOCK, true if read-only, false if read/write */ + int read_only; + /* for MYSQL_AUDIT_TABLE_RENAME */ + const char *new_database; + unsigned int new_database_length; + const char *new_table; + unsigned int new_table_length; +}; /************************************************************************* Here we define the descriptor structure, that is referred from diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 1c4b46c2a01..a3fabf011ab 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -1,4 +1,5 @@ #include "plugin.h" +typedef char my_bool; #include #include extern struct my_snprintf_service_st { @@ -85,6 +86,27 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); +#include +#include "mysql_time.h" +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); struct st_mysql_xid { long formatID; long gtrid_length; @@ -272,6 +294,27 @@ struct mysql_event_connection const char *database; unsigned int database_length; }; +struct mysql_event_table +{ + unsigned int event_subclass; + unsigned long thread_id; + const char *user; + const char *priv_user; + const char *priv_host; + const char *external_user; + const char *proxy_user; + const char *host; + const char *ip; + const char *database; + unsigned int database_length; + const char *table; + unsigned int table_length; + int read_only; + const char *new_database; + unsigned int new_database_length; + const char *new_table; + unsigned int new_table_length; +}; struct st_mysql_audit { int interface_version; diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index ac6e5e3b13d..28172286fb3 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -1,4 +1,5 @@ #include +typedef char my_bool; #include #include extern struct my_snprintf_service_st { @@ -85,6 +86,27 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); +#include +#include "mysql_time.h" +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index f5d6ac3b849..532e049cf53 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -1,4 +1,5 @@ #include "plugin.h" +typedef char my_bool; #include #include extern struct my_snprintf_service_st { @@ -85,6 +86,27 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); +#include +#include "mysql_time.h" +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h index a7fd3e8a2c6..d4ce97076e6 100644 --- a/include/mysql/service_my_snprintf.h +++ b/include/mysql/service_my_snprintf.h @@ -1,5 +1,5 @@ #ifndef MYSQL_SERVICE_MY_SNPRINTF_INCLUDED -/* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 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/include/mysql/service_thd_timezone.h b/include/mysql/service_thd_timezone.h new file mode 100644 index 00000000000..f44f011b891 --- /dev/null +++ b/include/mysql/service_thd_timezone.h @@ -0,0 +1,73 @@ +#ifndef MYSQL_SERVICE_THD_TIMEZONE_INCLUDED +/* Copyright (C) 2013 MariaDB Foundation. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/** + @file + This service provdes functions to convert between my_time_t and + MYSQL_TIME taking into account the current value of the time_zone + session variable. + + The values of the my_time_t type are in Unix timestamp format, + i.e. the number of seconds since "1970-01-01 00:00:00 UTC". + + The values of the MYSQL_TIME type are in the current time zone, + according to thd->variables.time_zone. + + If the MYSQL_THD parameter is NULL, then global_system_variables.time_zone + is used for conversion. +*/ + +#ifndef MYSQL_ABI_CHECK +/* + This service currently does not depend on any system headers. + If it needs system headers in the future, make sure to put + them inside this ifndef. +*/ +#endif + +#include "mysql_time.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(MYSQL_THD thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(MYSQL_THD thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define thd_TIME_to_gmt_sec(thd, ltime, errcode) \ + (thd_timezone_service->thd_TIME_to_gmt_sec((thd), (ltime), (errcode))) + +#define thd_gmt_sec_to_TIME(thd, ltime, t) \ + (thd_timezone_service->thd_gmt_sec_to_TIME((thd), (ltime), (t))) + +#else + +my_time_t thd_TIME_to_gmt_sec(MYSQL_THD thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(MYSQL_THD thd, MYSQL_TIME *ltime, my_time_t t); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_THD_TIMEZONE_INCLUDED +#endif diff --git a/include/mysql/services.h b/include/mysql/services.h index e14523f4fa1..1145d19872b 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -25,6 +25,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/include/mysql_com.h b/include/mysql_com.h index 229f54f68e1..6e8350b0d75 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -24,7 +24,7 @@ #define HOSTNAME_LENGTH 60 #define SYSTEM_CHARSET_MBMAXLEN 3 #define NAME_CHAR_LEN 64 /* Field/table name length */ -#define USERNAME_CHAR_LENGTH 16 +#define USERNAME_CHAR_LENGTH 128 #define NAME_LEN (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN) #define USERNAME_LENGTH (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN) @@ -400,6 +400,16 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT, + /* + mysql-5.6 compatibility temporal types. + They're only used internally for reading RBR + mysql-5.6 binary log events and mysql-5.6 frm files. + They're never sent to the client. + */ + MYSQL_TYPE_TIMESTAMP2, + MYSQL_TYPE_DATETIME2, + MYSQL_TYPE_TIME2, + MYSQL_TYPE_NEWDECIMAL=246, MYSQL_TYPE_ENUM=247, MYSQL_TYPE_SET=248, diff --git a/include/mysql_time.h b/include/mysql_time.h index 0a3f17a81fb..a1b7bdb9bec 100644 --- a/include/mysql_time.h +++ b/include/mysql_time.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2004 MySQL AB +/* Copyright (c) 2004, 2006 MySQL AB + Use is subject to license terms 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 @@ -16,6 +17,17 @@ #ifndef _mysql_time_h_ #define _mysql_time_h_ +/* + Portable time_t replacement. + Should be signed and hold seconds for 1902 -- 2038-01-19 range + i.e at least a 32bit variable + + Using the system built in time_t is not an option as + we rely on the above requirements in the time functions +*/ +typedef long my_time_t; + + /* Time declarations shared between the server and client API: you should not add anything to this header unless it's used diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index 18c61040c22..56b2fe50ec0 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -1,4 +1,5 @@ -/* Copyright Abandoned 1996, 1999, 2001 MySQL AB +/* Copyright (c) 1996, 1999-2004, 2007 MySQL AB + Use is subject to license terms This file is public domain and comes with NO WARRANTY of any kind */ /* Version numbers for protocol & mysqld */ diff --git a/include/probes_mysql_nodtrace.h b/include/probes_mysql_nodtrace.h index a84bf7726c3..bc3b65a00e5 100644 --- a/include/probes_mysql_nodtrace.h +++ b/include/probes_mysql_nodtrace.h @@ -6,124 +6,121 @@ #define _PROBES_MYSQL_D #ifdef __cplusplus -#define MYSQL_PROBES_FALSE false extern "C" { -#else -#define MYSQL_PROBES_FALSE 0 #endif #define MYSQL_CONNECTION_START(arg0, arg1, arg2) -#define MYSQL_CONNECTION_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_CONNECTION_START_ENABLED() (0) #define MYSQL_CONNECTION_DONE(arg0, arg1) -#define MYSQL_CONNECTION_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_CONNECTION_DONE_ENABLED() (0) #define MYSQL_COMMAND_START(arg0, arg1, arg2, arg3) -#define MYSQL_COMMAND_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_COMMAND_START_ENABLED() (0) #define MYSQL_COMMAND_DONE(arg0) -#define MYSQL_COMMAND_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_COMMAND_DONE_ENABLED() (0) #define MYSQL_QUERY_START(arg0, arg1, arg2, arg3, arg4) -#define MYSQL_QUERY_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_START_ENABLED() (0) #define MYSQL_QUERY_DONE(arg0) -#define MYSQL_QUERY_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_DONE_ENABLED() (0) #define MYSQL_QUERY_PARSE_START(arg0) -#define MYSQL_QUERY_PARSE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_PARSE_START_ENABLED() (0) #define MYSQL_QUERY_PARSE_DONE(arg0) -#define MYSQL_QUERY_PARSE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_PARSE_DONE_ENABLED() (0) #define MYSQL_QUERY_CACHE_HIT(arg0, arg1) -#define MYSQL_QUERY_CACHE_HIT_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_CACHE_HIT_ENABLED() (0) #define MYSQL_QUERY_CACHE_MISS(arg0) -#define MYSQL_QUERY_CACHE_MISS_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_CACHE_MISS_ENABLED() (0) #define MYSQL_QUERY_EXEC_START(arg0, arg1, arg2, arg3, arg4, arg5) -#define MYSQL_QUERY_EXEC_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_EXEC_START_ENABLED() (0) #define MYSQL_QUERY_EXEC_DONE(arg0) -#define MYSQL_QUERY_EXEC_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_EXEC_DONE_ENABLED() (0) #define MYSQL_INSERT_ROW_START(arg0, arg1) -#define MYSQL_INSERT_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_ROW_START_ENABLED() (0) #define MYSQL_INSERT_ROW_DONE(arg0) -#define MYSQL_INSERT_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_ROW_DONE_ENABLED() (0) #define MYSQL_UPDATE_ROW_START(arg0, arg1) -#define MYSQL_UPDATE_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_ROW_START_ENABLED() (0) #define MYSQL_UPDATE_ROW_DONE(arg0) -#define MYSQL_UPDATE_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_ROW_DONE_ENABLED() (0) #define MYSQL_DELETE_ROW_START(arg0, arg1) -#define MYSQL_DELETE_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_ROW_START_ENABLED() (0) #define MYSQL_DELETE_ROW_DONE(arg0) -#define MYSQL_DELETE_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_ROW_DONE_ENABLED() (0) #define MYSQL_READ_ROW_START(arg0, arg1, arg2) -#define MYSQL_READ_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_READ_ROW_START_ENABLED() (0) #define MYSQL_READ_ROW_DONE(arg0) -#define MYSQL_READ_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_READ_ROW_DONE_ENABLED() (0) #define MYSQL_INDEX_READ_ROW_START(arg0, arg1) -#define MYSQL_INDEX_READ_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INDEX_READ_ROW_START_ENABLED() (0) #define MYSQL_INDEX_READ_ROW_DONE(arg0) -#define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (0) #define MYSQL_HANDLER_RDLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_RDLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_RDLOCK_START_ENABLED() (0) #define MYSQL_HANDLER_WRLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_WRLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_WRLOCK_START_ENABLED() (0) #define MYSQL_HANDLER_UNLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_UNLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_UNLOCK_START_ENABLED() (0) #define MYSQL_HANDLER_RDLOCK_DONE(arg0) -#define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (0) #define MYSQL_HANDLER_WRLOCK_DONE(arg0) -#define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (0) #define MYSQL_HANDLER_UNLOCK_DONE(arg0) -#define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (0) #define MYSQL_FILESORT_START(arg0, arg1) -#define MYSQL_FILESORT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_FILESORT_START_ENABLED() (0) #define MYSQL_FILESORT_DONE(arg0, arg1) -#define MYSQL_FILESORT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_FILESORT_DONE_ENABLED() (0) #define MYSQL_SELECT_START(arg0) -#define MYSQL_SELECT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_SELECT_START_ENABLED() (0) #define MYSQL_SELECT_DONE(arg0, arg1) -#define MYSQL_SELECT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_SELECT_DONE_ENABLED() (0) #define MYSQL_INSERT_START(arg0) -#define MYSQL_INSERT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_START_ENABLED() (0) #define MYSQL_INSERT_DONE(arg0, arg1) -#define MYSQL_INSERT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_DONE_ENABLED() (0) #define MYSQL_INSERT_SELECT_START(arg0) -#define MYSQL_INSERT_SELECT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_SELECT_START_ENABLED() (0) #define MYSQL_INSERT_SELECT_DONE(arg0, arg1) -#define MYSQL_INSERT_SELECT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_SELECT_DONE_ENABLED() (0) #define MYSQL_UPDATE_START(arg0) -#define MYSQL_UPDATE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_START_ENABLED() (0) #define MYSQL_UPDATE_DONE(arg0, arg1, arg2) -#define MYSQL_UPDATE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_DONE_ENABLED() (0) #define MYSQL_MULTI_UPDATE_START(arg0) -#define MYSQL_MULTI_UPDATE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_UPDATE_START_ENABLED() (0) #define MYSQL_MULTI_UPDATE_DONE(arg0, arg1, arg2) -#define MYSQL_MULTI_UPDATE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_UPDATE_DONE_ENABLED() (0) #define MYSQL_DELETE_START(arg0) -#define MYSQL_DELETE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_START_ENABLED() (0) #define MYSQL_DELETE_DONE(arg0, arg1) -#define MYSQL_DELETE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_DONE_ENABLED() (0) #define MYSQL_MULTI_DELETE_START(arg0) -#define MYSQL_MULTI_DELETE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_DELETE_START_ENABLED() (0) #define MYSQL_MULTI_DELETE_DONE(arg0, arg1) -#define MYSQL_MULTI_DELETE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_DELETE_DONE_ENABLED() (0) #define MYSQL_NET_READ_START() -#define MYSQL_NET_READ_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_READ_START_ENABLED() (0) #define MYSQL_NET_READ_DONE(arg0, arg1) -#define MYSQL_NET_READ_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_READ_DONE_ENABLED() (0) #define MYSQL_NET_WRITE_START(arg0) -#define MYSQL_NET_WRITE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_WRITE_START_ENABLED() (0) #define MYSQL_NET_WRITE_DONE(arg0) -#define MYSQL_NET_WRITE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_WRITE_DONE_ENABLED() (0) #define MYSQL_KEYCACHE_READ_START(arg0, arg1, arg2, arg3) -#define MYSQL_KEYCACHE_READ_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_START_ENABLED() (0) #define MYSQL_KEYCACHE_READ_BLOCK(arg0) -#define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (0) #define MYSQL_KEYCACHE_READ_HIT() -#define MYSQL_KEYCACHE_READ_HIT_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_HIT_ENABLED() (0) #define MYSQL_KEYCACHE_READ_MISS() -#define MYSQL_KEYCACHE_READ_MISS_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_MISS_ENABLED() (0) #define MYSQL_KEYCACHE_READ_DONE(arg0, arg1) -#define MYSQL_KEYCACHE_READ_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_DONE_ENABLED() (0) #define MYSQL_KEYCACHE_WRITE_START(arg0, arg1, arg2, arg3) -#define MYSQL_KEYCACHE_WRITE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_START_ENABLED() (0) #define MYSQL_KEYCACHE_WRITE_BLOCK(arg0) -#define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (0) #define MYSQL_KEYCACHE_WRITE_DONE(arg0, arg1) -#define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (0) #ifdef __cplusplus } diff --git a/include/service_versions.h b/include/service_versions.h index e0a717fea9e..2dffa7cf863 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -26,4 +26,4 @@ #define VERSION_progress_report 0x0100 #define VERSION_debug_sync 0x1000 #define VERSION_kill_statement 0x1000 - +#define VERSION_thd_timezone 0x0100 diff --git a/include/thread_pool_priv.h b/include/thread_pool_priv.h index 84c7faa2e2b..9a9c65af6da 100644 --- a/include/thread_pool_priv.h +++ b/include/thread_pool_priv.h @@ -1,6 +1,6 @@ #error don't use /* - Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 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/include/welcome_copyright_notice.h b/include/welcome_copyright_notice.h index 9878ab1c07d..302f623e377 100644 --- a/include/welcome_copyright_notice.h +++ b/include/welcome_copyright_notice.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. +/* Copyright (c) 2011, 2012, Oracle and/or its affiliates. Copyright (c) 2011, 2012, Monty Program Ab This program is free software; you can redistribute it and/or modify diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 69fce429ab9..2be7c00b4a4 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2131,7 +2131,14 @@ int cli_stmt_execute(MYSQL_STMT *stmt) DBUG_RETURN(1); } - net_clear(net, 1); /* Sets net->write_pos */ + if (net->vio) + net_clear(net, 1); /* Sets net->write_pos */ + else + { + set_stmt_errmsg(stmt, net); + DBUG_RETURN(1); + } + /* Reserve place for null-marker bytes */ null_count= (stmt->param_count+7) /8; if (my_realloc_str(net, null_count + 1)) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index c33f08abeee..7450dc22184 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -90,7 +90,7 @@ void embedded_get_error(MYSQL *mysql, MYSQL_DATA *data) NET *net= &mysql->net; struct embedded_query_result *ei= data->embedded_info; net->last_errno= ei->last_errno; - strmake(net->last_error, ei->info, sizeof(net->last_error)-1); + strmake_buf(net->last_error, ei->info); memcpy(net->sqlstate, ei->sqlstate, sizeof(net->sqlstate)); mysql->server_status= ei->server_status; my_free(data); @@ -704,8 +704,8 @@ int check_embedded_connection(MYSQL *mysql, const char *db) thd->update_charset(); Security_context *sctx= thd->security_ctx; sctx->host_or_ip= sctx->host= (char*) my_localhost; - strmake(sctx->priv_host, (char*) my_localhost, MAX_HOSTNAME-1); - strmake(sctx->priv_user, mysql->user, USERNAME_LENGTH-1); + strmake_buf(sctx->priv_host, (char*) my_localhost); + strmake_buf(sctx->priv_user, mysql->user); sctx->user= my_strdup(mysql->user, MYF(0)); sctx->proxy_user[0]= 0; sctx->master_access= GLOBAL_ACLS; // Full rights @@ -773,7 +773,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db) return 0; err: - strmake(net->last_error, thd->main_da.message(), sizeof(net->last_error)-1); + strmake_buf(net->last_error, thd->main_da.message()); memcpy(net->sqlstate, mysql_errno_to_sqlstate(thd->main_da.sql_errno()), sizeof(net->sqlstate)-1); @@ -1121,8 +1121,7 @@ net_send_ok(THD *thd, data->embedded_info->affected_rows= affected_rows; data->embedded_info->insert_id= id; if (message) - strmake(data->embedded_info->info, message, - sizeof(data->embedded_info->info)-1); + strmake_buf(data->embedded_info->info, message); bool error= write_eof_packet(thd, server_status, statement_warn_count); thd->cur_data= 0; @@ -1173,7 +1172,7 @@ bool net_send_error_packet(THD *thd, uint sql_errno, const char *err, err, strlen(err), system_charset_info, &error); /* Converted error message is always null-terminated. */ - strmake(ei->info, converted_err, sizeof(ei->info)-1); + strmake_buf(ei->info, converted_err); strmov(ei->sqlstate, sqlstate); ei->server_status= thd->server_status; thd->cur_data= 0; diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index 86ed3493993..e7dcf20e547 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -19,6 +19,7 @@ SET(MYSQLSERVICES_SOURCES my_snprintf_service.c thd_alloc_service.c thd_wait_service.c + thd_timezone_service.c progress_report_service.c debug_sync_service.c kill_statement_service.c) diff --git a/libservices/thd_timezone_service.c b/libservices/thd_timezone_service.c new file mode 100644 index 00000000000..2c93453f8ca --- /dev/null +++ b/libservices/thd_timezone_service.c @@ -0,0 +1,18 @@ +/* Copyright (C) 2013 MariaDB Foundation + Use is subject to license terms. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include +SERVICE_VERSION thd_timezone_service= (void *) VERSION_thd_timezone; diff --git a/mysql-test/collections/default.experimental b/mysql-test/collections/default.experimental index 56b8feb6739..dca07e1a388 100644 --- a/mysql-test/collections/default.experimental +++ b/mysql-test/collections/default.experimental @@ -6,6 +6,7 @@ binlog.binlog_multi_engine # joro : NDB tests marked as experiment funcs_1.charset_collation_1 # depends on compile-time decisions main.func_math @freebsd # Bug#11751977 2010-05-04 alik main.func_math fails on FreeBSD in PB2 +main.kill @solaris # Bug#16064876 2013-01-02 prthirum main.kill fails on sol10 sparc64 main.lock_multi_bug38499 # Bug#11755645 2009-09-19 alik main.lock_multi_bug38499 times out sporadically main.outfile_loaddata @solaris # Bug#11755168 2010-01-20 alik Test "outfile_loaddata" fails (reproducible) main.signal_demo3 @solaris # Bug#11753919 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun diff --git a/mysql-test/include/get_relay_log_pos.inc b/mysql-test/include/get_relay_log_pos.inc index 61ee07fc655..47a74c9bd41 100644 --- a/mysql-test/include/get_relay_log_pos.inc +++ b/mysql-test/include/get_relay_log_pos.inc @@ -40,7 +40,6 @@ CREATE TEMPORARY TABLE mysqlbinlog_events(c1 INT AUTO_INCREMENT KEY, c2 varchar( # '# .... end_log_pos 46' eval LOAD DATA LOCAL INFILE '$_tmp_file' INTO TABLE mysqlbinlog_events LINES STARTING BY '#' (c2) SET c1 = NULL; ---enable_warnings # Event pos in relay log file is inserted into table events_at CREATE TEMPORARY TABLE events_at(c1 INT AUTO_INCREMENT KEY, c2 varchar(256)) @@ -49,6 +48,7 @@ CREATE TEMPORARY TABLE events_at(c1 INT AUTO_INCREMENT KEY, c2 varchar(256)) # Event pos in master log file is inserted into table events_pos CREATE TEMPORARY TABLE events_pos(c1 INT AUTO_INCREMENT KEY, c2 varchar(256)) SELECT c2 FROM mysqlbinlog_events WHERE c2 LIKE '% end_log_pos %' ORDER BY c1; +--enable_warnings # events_at events_pos # c1------c2-------------------------- c1------c2------------------------ diff --git a/mysql-test/include/kill_binlog_dump_threads.inc b/mysql-test/include/kill_binlog_dump_threads.inc new file mode 100644 index 00000000000..38e3e2a7c98 --- /dev/null +++ b/mysql-test/include/kill_binlog_dump_threads.inc @@ -0,0 +1,62 @@ +# ==== Purpose ==== +# +# Terminate all binlog dump threads on a master. +# +# This is sometimes useful, as normally such dump threads can hang +# around for some time before they notice that the slave has disconnected. +# +# Note that if there are active slave connections, they might try to +# reconnect as their dump threads are killed, which may not lead to the +# desired results. +# +# +# ==== Usage ==== +# +# [--let $kill_timeout= NUMBER] +# --source include/stop_slavekill_binlog_dump_threads.inc +# +# Parameters: +# $kill_timeout +# Maximum number of seconds to wait for dump threads to disappear. + + +--let $include_filename= kill_binlog_dump_threads.inc +--source include/begin_include_file.inc + +--disable_query_log + +let $wait_counter= 300; +if ($kill_timeout) +{ + let $wait_counter= `SELECT $kill_timeout * 10`; +} + +let $success= 0; +while ($wait_counter) +{ + dec $wait_counter; + let $_tid= `SELECT id FROM information_schema.processlist WHERE command = 'Binlog Dump' LIMIT 1`; + if ($_tid) + { + eval KILL QUERY $_tid; + } + if (!$_tid) + { + let $wait_counter= 0; + let $success= 1; + } + if (!$success) + { + real_sleep 0.1; + } +} +if (!$success) +{ + SHOW FULL PROCESSLIST; + --die Timeout while waiting for binlog dump threads to disappear. +} + +--enable_query_log + +--let $include_filename= kill_binlog_dump_threads.inc +--source include/end_include_file.inc diff --git a/mysql-test/include/rpl_init.inc b/mysql-test/include/rpl_init.inc index dbe93adbec3..09569fc2b57 100644 --- a/mysql-test/include/rpl_init.inc +++ b/mysql-test/include/rpl_init.inc @@ -7,7 +7,6 @@ # well as extra connections server_1_1, server_2_1, ..., # server_N_1. server_I and server_I_1 are connections to the same # server. -# - Sets up @@auto_increment_increment and @@auto_increment_increment. # - Verifies that @@server_id of all servers are different. # - Calls RESET MASTER, RESET SLAVE, USE test, CHANGE MASTER, START SLAVE. # - Sets the connection to server_1 before exiting. @@ -180,8 +179,6 @@ while ($_rpl_server) SET GLOBAL gtid_slave_pos= ""; RESET SLAVE; } - eval SET auto_increment_increment= $rpl_server_count; - eval SET auto_increment_offset= $_rpl_server; --dec $_rpl_server } diff --git a/mysql-test/include/wait_show_condition.inc b/mysql-test/include/wait_show_condition.inc index ae1600a7e30..b8dd9bdf971 100644 --- a/mysql-test/include/wait_show_condition.inc +++ b/mysql-test/include/wait_show_condition.inc @@ -127,5 +127,6 @@ if (!$found) echo # field : $field; echo # condition : $condition; echo # max_run_time : $max_run_time; + eval $show_statement; } diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index fe9777fcecd..90988c73c66 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -377,7 +377,7 @@ sub main { # directly before it executes them, like "make test-force-pl" in RPM builds. mtr_report("Logging: $0 ", join(" ", @ARGV)); - $DEFAULT_SUITES.=",sequence,sql_discovery" if $source_dist; + $DEFAULT_SUITES.=",sequence,sql_discovery,spider,spider/bg" if $source_dist; command_line_setup(); @@ -749,9 +749,11 @@ sub run_test_server ($$$) { mtr_report("\nRetrying test $tname, ". "attempt($retries/$opt_retry)...\n"); #saving the log file as filename.failed in case of retry - my $worker_logdir= $result->{savedir}; - my $log_file_name=dirname($worker_logdir)."/".$result->{shortname}.".log"; - rename $log_file_name,$log_file_name.".failed"; + if ( $result->is_failed() ) { + my $worker_logdir= $result->{savedir}; + my $log_file_name=dirname($worker_logdir)."/".$result->{shortname}.".log"; + rename $log_file_name,$log_file_name.".failed"; + } delete($result->{result}); $result->{retries}= $retries+1; $result->write_test($sock, 'TESTCASE'); @@ -4152,6 +4154,7 @@ sub resfile_report_test ($) { sub run_testcase ($$) { my ($tinfo, $server_socket)= @_; + my $print_freq=20; mtr_verbose("Running test:", $tinfo->{name}); resfile_report_test($tinfo) if $opt_resfile; @@ -4335,6 +4338,7 @@ sub run_testcase ($$) { my $test= $tinfo->{suite}->start_test($tinfo); # Set only when we have to keep waiting after expectedly died server my $keep_waiting_proc = 0; + my $print_timeout= start_timer($print_freq * 60); while (1) { @@ -4359,7 +4363,22 @@ sub run_testcase ($$) { } if (! $keep_waiting_proc) { - $proc= My::SafeProcess->wait_any_timeout($test_timeout); + if($test_timeout > $print_timeout) + { + $proc= My::SafeProcess->wait_any_timeout($print_timeout); + if ( $proc->{timeout} ) + { + #print out that the test is still on + mtr_print("Test still running: $tinfo->{name}"); + #reset the timer + $print_timeout= start_timer($print_freq * 60); + next; + } + } + else + { + $proc= My::SafeProcess->wait_any_timeout($test_timeout); + } } # Will be restored if we need to keep waiting diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 31f1d57f916..ac7be28d736 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -180,24 +180,24 @@ select 10.0+'10'; select 10E+0+'10'; 10E+0+'10' 20 -select CONVERT(DATE "2004-01-22 21:45:33" USING latin1); -CONVERT(DATE "2004-01-22 21:45:33" USING latin1) +select CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1); +CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1) 2004-01-22 21:45:33 -select CONVERT(DATE "2004-01-22 21:45:33",CHAR); -CONVERT(DATE "2004-01-22 21:45:33",CHAR) +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR); +CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR) 2004-01-22 21:45:33 -select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4)); -CONVERT(DATE "2004-01-22 21:45:33",CHAR(4)) +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR(4)); +CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR(4)) 2004 Warnings: Warning 1292 Truncated incorrect CHAR(4) value: '2004-01-22 21:45:33' -select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4)); -CONVERT(DATE "2004-01-22 21:45:33",BINARY(4)) +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",BINARY(4)); +CONVERT(TIMESTAMP "2004-01-22 21:45:33",BINARY(4)) 2004 Warnings: Warning 1292 Truncated incorrect BINARY(4) value: '2004-01-22 21:45:33' -select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4)); -CAST(DATE "2004-01-22 21:45:33" AS BINARY(4)) +select CAST(TIMESTAMP "2004-01-22 21:45:33" AS BINARY(4)); +CAST(TIMESTAMP "2004-01-22 21:45:33" AS BINARY(4)) 2004 Warnings: Warning 1292 Truncated incorrect BINARY(4) value: '2004-01-22 21:45:33' @@ -737,6 +737,24 @@ WHERE CAST(a as BINARY)=x'62736D697468' AND CAST(a AS BINARY)=x'65736D697468'; a DROP TABLE t1; +# +# Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH +# LONGTEXT, UNION, USER VARIABLE +# Bug#14096619 UNABLE TO RESTORE DATABASE DUMP +# +CREATE TABLE t1 AS SELECT CONCAT(CAST(REPEAT('9', 1000) AS SIGNED)), +CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED)); +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999' +Warning 1292 Truncated incorrect INTEGER value: '99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `CONCAT(CAST(REPEAT('9', 1000) AS SIGNED))` varchar(21) NOT NULL DEFAULT '', + `CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED))` varchar(21) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# End of test for Bug#13581962, Bug#14096619 End of 5.1 tests select cast("2101-00-01 02:03:04" as datetime); cast("2101-00-01 02:03:04" as datetime) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 7e814283d32..d0d953f4e38 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1752,7 +1752,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', @@ -1772,7 +1772,7 @@ show create table t1; Table Create Table t1 CREATE TEMPORARY TABLE `t1` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result index b70f3f91bd6..413b96da16b 100644 --- a/mysql-test/r/ctype_cp932_binlog_stm.result +++ b/mysql-test/r/ctype_cp932_binlog_stm.result @@ -11,7 +11,7 @@ Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE TABLE t1(f1 blob) master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES(0x8300) +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES(X'8300') master-bin.000001 # Query # # COMMIT SELECT HEX(f1) FROM t1; HEX(f1) @@ -47,7 +47,7 @@ BEGIN INSERT INTO t4 VALUES (ins1, ins2, ind); END master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # Query # # use `test`; INSERT INTO t4 VALUES ( NAME_CONST('ins1',_latin1 0x466F6F2773206120426172 COLLATE 'latin1_swedish_ci'), NAME_CONST('ins2',_cp932 0xED40ED41ED42 COLLATE 'cp932_japanese_ci'), NAME_CONST('ind',47.93)) +master-bin.000001 # Query # # use `test`; INSERT INTO t4 VALUES ( NAME_CONST('ins1',_latin1 X'466F6F2773206120426172' COLLATE 'latin1_swedish_ci'), NAME_CONST('ins2',_cp932 X'ED40ED41ED42' COLLATE 'cp932_japanese_ci'), NAME_CONST('ind',47.93)) master-bin.000001 # Query # # COMMIT master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP PROCEDURE bug18293 @@ -19496,5 +19496,40 @@ EFBFA4 FA55 EFBFA5 818F DROP TABLE t1; # +# Bug#MDEV-4489 Replication of big5, cp932, gbk, sjis strings makes wrong values on slave +# +SET NAMES cp932; +CREATE TABLE t1 (a INT); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES (0x31); +INSERT INTO t1 VALUES (X'31'); +PREPARE stmt FROM 'INSERT INTO t1 (a) VALUES (?)'; +SET @a='1'; +SELECT charset(@a); +charset(@a) +cp932 +EXECUTE stmt USING @a; +DROP PREPARE stmt; +DROP TABLE t1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (0x31) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (X'31') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 (a) VALUES (X'31') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ +# # End of 5.5 tests # diff --git a/mysql-test/r/ctype_ucs2_query_cache.result b/mysql-test/r/ctype_ucs2_query_cache.result new file mode 100644 index 00000000000..c5f1ef5918d --- /dev/null +++ b/mysql-test/r/ctype_ucs2_query_cache.result @@ -0,0 +1,19 @@ +# +# Start of 5.5 tests +# +# +# Bug#MDEV-4518 Server crashes in is_white_space when it's run +# with query cache, charset ucs2 and collation ucs2_unicode_ci +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3),(4); +SELECT * FROM t1; +a +1 +2 +3 +4 +DROP TABLE t1; +# +# End of 5.5 tests +# diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result index a956a474ef7..d8642955b89 100644 --- a/mysql-test/r/ctype_utf8mb4.result +++ b/mysql-test/r/ctype_utf8mb4.result @@ -2539,6 +2539,24 @@ t2 CREATE TABLE `t2` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1, t2; # +# Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH +# LONGTEXT, UNION, USER VARIABLE +# Bug#14096619 UNABLE TO RESTORE DATABASE DUMP +# +CREATE TABLE t1(f1 LONGTEXT CHARACTER SET utf8mb4); +INSERT INTO t1 VALUES ('a'); +SELECT @a:= CAST(f1 AS SIGNED) FROM t1 +UNION ALL +SELECT CAST(f1 AS SIGNED) FROM t1; +@a:= CAST(f1 AS SIGNED) +0 +0 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'a' +Warning 1292 Truncated incorrect INTEGER value: 'a' +DROP TABLE t1; +# End of test for Bug#13581962,Bug#14096619 +# # End of 5.5 tests # # diff --git a/mysql-test/r/empty_user_table.result b/mysql-test/r/empty_user_table.result new file mode 100644 index 00000000000..b93596ab59a --- /dev/null +++ b/mysql-test/r/empty_user_table.result @@ -0,0 +1,8 @@ +create table t1 as select * from mysql.user; +truncate table mysql.user; +flush privileges; +connect(localhost,u1,,test,MASTER_PORT,MASTER_SOCKET); +Got one of the listed errors +insert mysql.user select * from t1; +drop table t1; +flush privileges; diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index 02284186c76..c2f1e5bf273 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -11,7 +11,7 @@ explain extended select uncompress(compress(@test_compress_string)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select uncompress(compress((@test_compress_string))) AS `uncompress(compress(@test_compress_string))` +Note 1003 select uncompress(compress((@`test_compress_string`))) AS `uncompress(compress(@test_compress_string))` select uncompressed_length(compress(@test_compress_string))=length(@test_compress_string); uncompressed_length(compress(@test_compress_string))=length(@test_compress_string) 1 @@ -19,7 +19,7 @@ explain extended select uncompressed_length(compress(@test_compress_string))=len id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select (uncompressed_length(compress((@test_compress_string))) = length((@test_compress_string))) AS `uncompressed_length(compress(@test_compress_string))=length(@test_compress_string)` +Note 1003 select (uncompressed_length(compress((@`test_compress_string`))) = length((@`test_compress_string`))) AS `uncompressed_length(compress(@test_compress_string))=length(@test_compress_string)` select uncompressed_length(compress(@test_compress_string)); uncompressed_length(compress(@test_compress_string)) 117 diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index c6fa040246a..38aa3f49c4d 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -2098,6 +2098,34 @@ avg(export_set( 3, 'y', sha(i))) group_concat(d) 0 2010-12-12 drop table t1; # +# MDEV-4290: crash in st_select_lex::mark_as_dependent +# +create table `t1`(`a` int); +select 1 from t1 v1 right join t1 on count(*); +ERROR HY000: Invalid use of group function +select 1 from t1 order by +( +select 1 from +( +select 1 from t1 v1 right join t1 on count(*) +) v +); +ERROR HY000: Invalid use of group function +insert into t1 values (1),(1),(2),(2); +select count(*) from t1; +count(*) +4 +select z from (select count(*) as z from t1) v; +z +4 +# next is how it implemented now (may be changed in case of dependent +# derived tables) +select z from (select count(*) as z from t1) v group by 1; +z +4 +drop table t1; +# end of 5.3 tests +# # Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(), # file .\item_sum.cc, line 587 # diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 67f3f664ad8..04e71a715ce 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -666,13 +666,13 @@ ERROR 22003: BIGINT value is out of range in '-(9223372036854775809)' DROP TABLE t1; SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999; SELECT @a + @a; -ERROR 22003: DECIMAL value is out of range in '((@a) + (@a))' +ERROR 22003: DECIMAL value is out of range in '((@`a`) + (@`a`))' SELECT @a * @a; -ERROR 22003: DECIMAL value is out of range in '((@a) * (@a))' +ERROR 22003: DECIMAL value is out of range in '((@`a`) * (@`a`))' SELECT -@a - @a; -ERROR 22003: DECIMAL value is out of range in '(-((@a)) - (@a))' +ERROR 22003: DECIMAL value is out of range in '(-((@`a`)) - (@`a`))' SELECT @a / 0.5; -ERROR 22003: DECIMAL value is out of range in '((@a) / 0.5)' +ERROR 22003: DECIMAL value is out of range in '((@`a`) / 0.5)' SELECT COT(1/0); COT(1/0) NULL diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 16c0854241f..ad5d640b402 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2911,6 +2911,17 @@ select 1 div convert(a using utf8) from t1; 1 div convert(a using utf8) NULL drop table t1; +create table t1 (a int); +create table t2 (a int); +create procedure foo (var char(100)) +select replace(var, '00000000', table_name) +from information_schema.tables where table_schema='test'; +call foo('(( 00000000 ++ 00000000 ))'); +replace(var, '00000000', table_name) +(( t1 ++ t1 )) +(( t2 ++ t2 )) +drop procedure foo; +drop table t1,t2; # # End of 5.5 tests # diff --git a/mysql-test/r/func_time_hires.result b/mysql-test/r/func_time_hires.result index 73b82a6ac1f..4aa0333c4b4 100644 --- a/mysql-test/r/func_time_hires.result +++ b/mysql-test/r/func_time_hires.result @@ -156,12 +156,12 @@ explain extended select cast(cast(@a as datetime(4)) as time(0)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select cast(cast((@a) as datetime(4)) as time) AS `cast(cast(@a as datetime(4)) as time(0))` +Note 1003 select cast(cast((@`a`) as datetime(4)) as time) AS `cast(cast(@a as datetime(4)) as time(0))` select cast(cast(@a as time(2)) as time(6)); cast(cast(@a as time(2)) as time(6)) 12:13:14.120000 select CAST(@a AS DATETIME(7)); -ERROR 42000: Too big precision 7 specified for '(@a)'. Maximum is 6. +ERROR 42000: Too big precision 7 specified for '(@`a`)'. Maximum is 6. SELECT CONVERT_TZ('2011-01-02 12:00:00', '+00:00', '+03:00'); CONVERT_TZ('2011-01-02 12:00:00', '+00:00', '+03:00') 2011-01-02 15:00:00 diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index c394aec8851..22c30479125 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -1576,3 +1576,23 @@ a ASTEXT(b) 0 POINT(1 1) DROP TABLE t1; End of 5.1 tests +CREATE TABLE t1 ( +l LINESTRING NOT NULL, +SPATIAL KEY(l) +) ENGINE = myisam; +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(0 0, 1 1)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(1 1, 2 2)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(2 2, 3 3)')); +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); +COUNT(*) +1 +DROP TABLE t1; diff --git a/mysql-test/r/grant_4332.result b/mysql-test/r/grant_4332.result new file mode 100644 index 00000000000..ef92b62ab32 --- /dev/null +++ b/mysql-test/r/grant_4332.result @@ -0,0 +1,96 @@ +select user(); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def user() 253 77 14 N 1 31 8 +user() +root@localhost +create user a17aaaaaaaaaaaaa0@localhost; +ERROR HY000: String 'a17aaaaaaaaaaaaa0' is too long for user name (should be no longer than 16) +alter table mysql.user modify User char(80) binary not null default ''; +alter table mysql.db modify User char(80) binary not null default ''; +alter table mysql.tables_priv modify User char(80) binary not null default ''; +alter table mysql.columns_priv modify User char(80) binary not null default ''; +alter table mysql.procs_priv modify User char(80) binary not null default ''; +alter table mysql.proc modify definer char(141) collate utf8_bin not null default ''; +alter table mysql.event modify definer char(141) collate utf8_bin not null default ''; +set global event_scheduler = on; +select user(); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def user() 253 141 14 N 1 31 8 +user() +root@localhost +create user a17aaaaaaaaaaaaa0@localhost; +grant usage on *.* to a17aaaaaaaaaaaaa0@localhost; +grant select on mysql.user to b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; +grant select(User) on mysql.tables_priv to c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; +select user(), current_user(); +user() current_user() +a17aaaaaaaaaaaaa0@localhost a17aaaaaaaaaaaaa0@localhost +show grants; +Grants for a17aaaaaaaaaaaaa0@localhost +GRANT USAGE ON *.* TO 'a17aaaaaaaaaaaaa0'@'localhost' +select user(), current_user(); +user() current_user() +b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost +show grants; +Grants for b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost +GRANT USAGE ON *.* TO 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0'@'localhost' +GRANT SELECT ON `mysql`.`user` TO 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0'@'localhost' +select user,host from mysql.user where user like '%0'; +user host +a17aaaaaaaaaaaaa0 localhost +b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 localhost +c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 localhost +select user,host from mysql.db; +ERROR 42000: SELECT command denied to user 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'@'localhost' for table 'db' +select user(), current_user(); +user() current_user() +c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost +show grants; +Grants for c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost +GRANT USAGE ON *.* TO 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' +GRANT SELECT (User) ON `mysql`.`tables_priv` TO 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' +select user from mysql.tables_priv; +user +b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 +c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 +select user,host from mysql.tables_priv; +ERROR 42000: SELECT command denied to user 'c80ccccccccccccccccccccccccccccccccccccccccccccc'@'localhost' for column 'host' in table 'tables_priv' +create procedure test.p1() select user(), current_user(), user from mysql.tables_priv; +show create procedure test.p1; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +p1 CREATE DEFINER=`c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0`@`localhost` PROCEDURE `p1`() +select user(), current_user(), user from mysql.tables_priv latin1 latin1_swedish_ci latin1_swedish_ci +create table test.t1 (a text); +create event e1 on schedule every 1 second +do insert test.t1 values (concat(user(), ' ', current_user())); +call test.p1(); +user() current_user() user +root@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 +root@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 +select * from t1 limit 1; +a +event_scheduler@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost +grant usage on *.* to d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; +ERROR HY000: String 'd81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long for user name (should be no longer than 80) +drop user d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; +ERROR HY000: String 'd81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long for user name (should be no longer than 80) +drop user c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; +drop user b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; +drop user a17aaaaaaaaaaaaa0@localhost; +set global event_scheduler = off; +drop event e1; +drop procedure test.p1; +drop table t1; +alter table mysql.user modify User char(16) binary not null default ''; +alter table mysql.db modify User char(16) binary not null default ''; +alter table mysql.tables_priv modify User char(16) binary not null default ''; +alter table mysql.columns_priv modify User char(16) binary not null default ''; +alter table mysql.procs_priv modify User char(16) binary not null default ''; +alter table mysql.proc modify definer char(77) collate utf8_bin not null default ''; +alter table mysql.event modify definer char(77) collate utf8_bin not null default ''; +flush privileges; +select user(); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def user() 253 77 14 N 1 31 8 +user() +root@localhost diff --git a/mysql-test/r/handlersocket.result b/mysql-test/r/handlersocket.result index 9e5d273cbb6..765d954d3dc 100644 --- a/mysql-test/r/handlersocket.result +++ b/mysql-test/r/handlersocket.result @@ -5,7 +5,7 @@ plugin_version 1.0 plugin_status ACTIVE plugin_type DAEMON plugin_library handlersocket.so -plugin_library_version 1.4 +plugin_library_version 1.5 plugin_author higuchi dot akira at dena dot jp plugin_description Direct access into InnoDB plugin_license BSD diff --git a/mysql-test/r/init_connection_query_cache.result b/mysql-test/r/init_connection_query_cache.result new file mode 100644 index 00000000000..5a1e5c5244f --- /dev/null +++ b/mysql-test/r/init_connection_query_cache.result @@ -0,0 +1,19 @@ +# +# MDEV-4520: Assertion `0' fails in Query_cache::end_of_result on +# concurrent drop event and event execution +# +set GLOBAL query_cache_size=1355776; +create user mysqltest1@localhost; +grant SELECT on test.* to mysqltest1@localhost; +create table t1 (a int); +# This explain put here to be sure that init connection query +# has 'Impossible WHERE'. +explain extended select * from test.t1 where 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +revoke all privileges, grant option from mysqltest1@localhost; +drop user mysqltest1@localhost; +drop table t1; +set GLOBAL query_cache_size=default; diff --git a/mysql-test/r/innodb_ext_key.result b/mysql-test/r/innodb_ext_key.result index 0da4feaf26f..4a6b902e869 100644 --- a/mysql-test/r/innodb_ext_key.result +++ b/mysql-test/r/innodb_ext_key.result @@ -865,6 +865,128 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where 1 SIMPLE t3 ref PRIMARY,col1 col1 12 test.t1.a,test.t1.a,test.t1.a # Using index drop table t1,t2,t3; +# +# Bug mdev-4340: performance regression with extended_keys=on +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +page_id int(8) unsigned NOT NULL AUTO_INCREMENT, +page_namespace int(11) NOT NULL DEFAULT '0', +page_title varbinary(255) NOT NULL DEFAULT '', +page_restrictions tinyblob NOT NULL, +page_counter bigint(20) unsigned NOT NULL DEFAULT '0', +page_is_redirect tinyint(1) unsigned NOT NULL DEFAULT '0', +page_is_new tinyint(1) unsigned NOT NULL DEFAULT '0', +page_random double unsigned NOT NULL DEFAULT '0', +page_touched varbinary(14) NOT NULL DEFAULT '', +page_latest int(8) unsigned NOT NULL DEFAULT '0', +page_len int(8) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (page_id), +UNIQUE KEY name_title (page_namespace,page_title), +KEY page_random (page_random), +KEY page_len (page_len), +KEY page_redirect_namespace_len (page_is_redirect,page_namespace,page_len) +) ENGINE=InnoDB AUTO_INCREMENT=38929100 DEFAULT CHARSET=binary; +INSERT INTO t1 VALUES +(38928077,0,'Sandbox','',0,0,0,0,'',0,0),(38928078,1,'Sandbox','',0,0,0,1,'',0,0), +(38928079,2,'Sandbox','',0,0,0,2,'',0,0),(38928080,3,'Sandbox','',0,0,0,3,'',0,0), +(38928081,4,'Sandbox','',0,0,0,4,'',0,0),(38928082,5,'Sandbox','',0,0,0,5,'',0,0); +CREATE TABLE t2 ( +rev_id int(8) unsigned NOT NULL AUTO_INCREMENT, +rev_page int(8) unsigned NOT NULL DEFAULT '0', +rev_text_id int(8) unsigned NOT NULL DEFAULT '0', +rev_comment varbinary(255) DEFAULT NULL, +rev_user int(5) unsigned NOT NULL DEFAULT '0', +rev_user_text varbinary(255) NOT NULL DEFAULT '', +rev_timestamp varbinary(14) NOT NULL DEFAULT '', +rev_minor_edit tinyint(1) unsigned NOT NULL DEFAULT '0', +rev_deleted tinyint(1) unsigned NOT NULL DEFAULT '0', +rev_len int(8) unsigned DEFAULT NULL, +rev_parent_id int(8) unsigned DEFAULT NULL, +rev_sha1 varbinary(32) NOT NULL DEFAULT '', +PRIMARY KEY (rev_page,rev_id), +UNIQUE KEY rev_id (rev_id), +KEY rev_timestamp (rev_timestamp), +KEY page_timestamp (rev_page,rev_timestamp), +KEY user_timestamp (rev_user,rev_timestamp), +KEY usertext_timestamp (rev_user_text,rev_timestamp,rev_user,rev_deleted,rev_minor_edit,rev_text_id,rev_comment) +) ENGINE=InnoDB DEFAULT CHARSET=binary; +INSERT INTO t2 VALUES +(547116222,20,0,NULL,3,'','',0,0,NULL,NULL,''),(547117245,20,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118268,20,0,NULL,5,'','',0,0,NULL,NULL,''),(547114177,21,0,NULL,1,'','',0,0,NULL,NULL,''), +(547115200,21,0,NULL,2,'','',0,0,NULL,NULL,''),(547116223,21,0,NULL,3,'','',0,0,NULL,NULL,''), +(547117246,21,0,NULL,4,'','',0,0,NULL,NULL,''),(547118269,21,0,NULL,5,'','',0,0,NULL,NULL,''), +(547114178,22,0,NULL,1,'','',0,0,NULL,NULL,''),(547115201,22,0,NULL,2,'','',0,0,NULL,NULL,''), +(547116224,22,0,NULL,3,'','',0,0,NULL,NULL,''),(547117247,22,0,NULL,4,'','',0,0,NULL,NULL,''), +(547116226,24,0,NULL,3,'','',0,0,NULL,NULL,''),(547117249,24,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118272,24,0,NULL,5,'','',0,0,NULL,NULL,''),(547114181,25,0,NULL,1,'','',0,0,NULL,NULL,''), +(547115204,25,0,NULL,2,'','',0,0,NULL,NULL,''),(547116227,25,0,NULL,3,'','',0,0,NULL,NULL,''), +(547116157,978,0,NULL,2,'','',0,0,NULL,NULL,''),(547117180,978,0,NULL,3,'','',0,0,NULL,NULL,''), +(547118203,978,0,NULL,4,'','',0,0,NULL,NULL,''),(547119226,978,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115135,979,0,NULL,1,'','',0,0,NULL,NULL,''),(547116158,979,0,NULL,2,'','',0,0,NULL,NULL,''), +(547116173,994,0,NULL,2,'','',0,0,NULL,NULL,''),(547117196,994,0,NULL,3,'','',0,0,NULL,NULL,''), +(547118219,994,0,NULL,4,'','',0,0,NULL,NULL,''),(547119242,994,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115151,995,0,NULL,1,'','',0,0,NULL,NULL,''),(547116174,995,0,NULL,2,'','',0,0,NULL,NULL,''), +(547117197,995,0,NULL,3,'','',0,0,NULL,NULL,''),(547118220,995,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118223,998,0,NULL,4,'','',0,0,NULL,NULL,''),(547119246,998,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115155,999,0,NULL,1,'','',0,0,NULL,NULL,''),(547116178,999,0,NULL,2,'','',0,0,NULL,NULL,''), +(547117201,999,0,NULL,3,'','',0,0,NULL,NULL,''),(547118224,999,0,NULL,4,'','',0,0,NULL,NULL,''), +(547119271,38928081,0,NULL,10,'','',0,0,NULL,NULL,''),(547119272,38928081,0,NULL,11,'','',0,0,NULL,NULL,''), +(547119273,38928081,0,NULL,12,'','',0,0,NULL,NULL,''),(547119274,38928081,0,NULL,13,'','',0,0,NULL,NULL,''), +(547119275,38928081,0,NULL,14,'','',0,0,NULL,NULL,''),(547119276,38928081,0,NULL,15,'','',0,0,NULL,NULL,''), +(547119277,38928081,0,NULL,16,'','',0,0,NULL,NULL,''),(547119278,38928081,0,NULL,17,'','',0,0,NULL,NULL,''), +(547119279,38928081,0,NULL,18,'','',0,0,NULL,NULL,''),(547119280,38928081,0,NULL,19,'','',0,0,NULL,NULL,''); +CREATE TABLE t3 ( +old_id int(10) unsigned NOT NULL AUTO_INCREMENT, +old_text mediumblob NOT NULL, +old_flags tinyblob NOT NULL, +PRIMARY KEY (old_id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +INSERT INTO t3 VALUES +(1,'text-0',''),(2,'text-1000',''),(3,'text-2000',''),(4,'text-3000',''), +(5,'text-4000',''),(6,'text-5000',''),(7,'text-6000',''),(8,'text-7000',''), +(9,'text-8000',''),(10,'text-9000',''),(11,'text-1',''),(12,'text-1001',''), +(13,'text-2001',''),(14,'text-3001',''),(15,'text-4001',''),(16,'text-5001',''), +(17,'text-6001',''),(18,'text-7001',''),(19,'text-8001',''),(20,'text-9001',''), +(21,'text-2',''),(22,'text-1002',''),(23,'text-2002',''),(24,'text-3002',''), +(25,'text-4002',''),(26,'text-5002',''),(27,'text-6002',''),(28,'text-7002',''), +(29,'text-8002',''),(30,'text-9002',''),(31,'text-3',''),(32,'text-1003',''), +(33,'text-2003',''),(34,'text-3003',''),(35,'text-4003',''),(36,'text-5003',''), +(37,'text-6003',''),(38,'text-7003',''),(39,'text-8003',''),(40,'text-9003',''), +(41,'text-4',''),(42,'text-1004',''),(43,'text-2004',''),(44,'text-3004',''), +(45,'text-4004',''),(46,'text-5004',''),(47,'text-6004',''),(48,'text-7004',''), +(49,'text-8004',''),(50,'text-9004',''),(51,'text-5',''),(52,'text-1005',''), +(53,'text-2005',''),(54,'text-3005',''),(55,'text-4005',''),(56,'text-5005',''), +(57,'text-6005',''),(58,'text-7005',''),(59,'text-8005',''),(60,'text-9005',''), +(61,'text-6',''),(62,'text-1006',''),(63,'text-2006',''),(64,'text-3006',''), +(65,'text-4006',''),(66,'text-5006',''),(67,'text-6006',''),(68,'text-7006',''), +(69,'text-8006',''),(70,'text-9006',''),(71,'text-7',''),(72,'text-1007',''), +(73,'text-2007',''),(74,'text-3007',''),(75,'text-4007',''),(76,'text-5007',''), +(77,'text-6007',''),(78,'text-7007',''),(79,'text-8007',''),(80,'text-9007',''), +(81,'text-8',''),(82,'text-1008',''),(83,'text-2008',''),(84,'text-3008',''), +(85,'text-4008',''),(86,'text-5008',''),(87,'text-6008',''),(88,'text-7008',''), +(89,'text-8008',''),(90,'text-9008',''),(91,'text-9',''),(92,'text-1009',''), +(93,'text-2009',''),(94,'text-3009',''),(95,'text-4009',''),(96,'text-5009',''), +(97,'text-6009',''),(98,'text-7009',''),(99,'text-8009',''),(100,'text-9009',''); +set optimizer_switch='extended_keys=off'; +EXPLAIN +SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 +WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' +ORDER BY rev_timestamp ASC LIMIT 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY,name_title name_title 261 const,const 1 +1 SIMPLE t2 ref page_timestamp page_timestamp 4 const 10 Using where +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.rev_text_id 1 +set optimizer_switch='extended_keys=on'; +EXPLAIN +SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 +WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' +ORDER BY rev_timestamp ASC LIMIT 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY,name_title name_title 261 const,const 1 +1 SIMPLE t2 ref page_timestamp page_timestamp 4 const 10 Using where +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.rev_text_id 1 +DROP TABLE t1,t2,t3; set optimizer_switch=@save_optimizer_switch; set optimizer_switch=@save_ext_key_optimizer_switch; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/join_nested.result b/mysql-test/r/join_nested.result index 255714a7236..84b6ff640e9 100644 --- a/mysql-test/r/join_nested.result +++ b/mysql-test/r/join_nested.result @@ -1847,3 +1847,27 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` A DROP TABLE t1,t2,t3,t4; SET optimizer_switch=@save_optimizer_switch; End of 5.0 tests +# +# MDEV-621: LP:693329 - Assertion `!is_interleave_error' failed on low optimizer_search_depth +# +set @tmp_mdev621= @@optimizer_search_depth; +SET SESSION optimizer_search_depth = 4; +CREATE TABLE t1 (f1 int,f2 int,f3 int,f4 int) ; +INSERT IGNORE INTO t1 VALUES (0,0,2,0),(NULL,0,2,0); +CREATE TABLE t2 (f1 int) ; +CREATE TABLE t3 (f3 int,PRIMARY KEY (f3)) ; +CREATE TABLE t4 (f5 int) ; +CREATE TABLE t5 (f2 int) ; +SELECT alias2.f4 FROM t1 AS alias1 +LEFT JOIN t1 AS alias2 +LEFT JOIN t2 AS alias3 +LEFT JOIN t3 AS alias4 ON alias3.f1 = alias4.f3 +ON alias2.f1 +LEFT JOIN t4 AS alias5 +JOIN t5 ON alias5.f5 +ON alias2.f3 ON alias1.f2; +f4 +NULL +NULL +DROP TABLE t1,t2,t3,t4,t5; +set optimizer_search_depth= @tmp_mdev621; diff --git a/mysql-test/r/join_nested_jcl6.result b/mysql-test/r/join_nested_jcl6.result index c744df9e2fe..6b5a50ba978 100644 --- a/mysql-test/r/join_nested_jcl6.result +++ b/mysql-test/r/join_nested_jcl6.result @@ -1858,6 +1858,30 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` A DROP TABLE t1,t2,t3,t4; SET optimizer_switch=@save_optimizer_switch; End of 5.0 tests +# +# MDEV-621: LP:693329 - Assertion `!is_interleave_error' failed on low optimizer_search_depth +# +set @tmp_mdev621= @@optimizer_search_depth; +SET SESSION optimizer_search_depth = 4; +CREATE TABLE t1 (f1 int,f2 int,f3 int,f4 int) ; +INSERT IGNORE INTO t1 VALUES (0,0,2,0),(NULL,0,2,0); +CREATE TABLE t2 (f1 int) ; +CREATE TABLE t3 (f3 int,PRIMARY KEY (f3)) ; +CREATE TABLE t4 (f5 int) ; +CREATE TABLE t5 (f2 int) ; +SELECT alias2.f4 FROM t1 AS alias1 +LEFT JOIN t1 AS alias2 +LEFT JOIN t2 AS alias3 +LEFT JOIN t3 AS alias4 ON alias3.f1 = alias4.f3 +ON alias2.f1 +LEFT JOIN t4 AS alias5 +JOIN t5 ON alias5.f5 +ON alias2.f3 ON alias1.f2; +f4 +NULL +NULL +DROP TABLE t1,t2,t3,t4,t5; +set optimizer_search_depth= @tmp_mdev621; CREATE TABLE t5 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); CREATE TABLE t6 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); CREATE TABLE t7 (a int, b int, c int, PRIMARY KEY(a), KEY b_i (b)); diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index c28887d4ff2..8920539ef2e 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1853,6 +1853,38 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; f1 f1 f2 DROP TABLE t1,t2; +# +# Bug#13068506 - QUERY WITH GROUP BY ON NON-AGGR COLUMN RETURNS +# WRONG RESULT +# +CREATE TABLE t1 (i1 int); +INSERT INTO t1 VALUES (100), (101); +CREATE TABLE t2 (i2 int, i3 int); +INSERT INTO t2 VALUES (20,1),(10,2); +CREATE TABLE t3 (i4 int(11)); +INSERT INTO t3 VALUES (1),(2); + +SELECT ( +SELECT MAX( t2.i2 ) +FROM t3 RIGHT JOIN t2 ON ( t2.i3 = 2 ) +WHERE t2.i3 <> t1.i1 +) AS field1 +FROM t1;; +field1 +20 +20 + +SELECT ( +SELECT MAX( t2.i2 ) +FROM t3 RIGHT JOIN t2 ON ( t2.i3 = 2 ) +WHERE t2.i3 <> t1.i1 +) AS field1 +FROM t1 GROUP BY field1;; +field1 +20 + +drop table t1,t2,t3; +# End of test for Bug#13068506 End of 5.1 tests # # LP BUG#994392: Wrong result with RIGHT/LEFT JOIN and ALL subquery @@ -2071,4 +2103,18 @@ b c d 5 8 88 5 8 81 DROP TABLE t1,t2; +# +# Bug mdev-4336: LEFT JOIN with disjunctive +# IS NULL in WHERE +# causes a hang and eventual crash +# +CREATE TABLE t1 ( +id int(11) NOT NULL, +modified datetime NOT NULL, +PRIMARY KEY (id) +); +SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id +WHERE a.modified > b.modified or b.modified IS NULL; +id modified +DROP TABLE t1; SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/join_outer_innodb.result b/mysql-test/r/join_outer_innodb.result index 0184e236d14..1081fc0eed3 100644 --- a/mysql-test/r/join_outer_innodb.result +++ b/mysql-test/r/join_outer_innodb.result @@ -476,3 +476,25 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t10 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) drop view v1; drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; +# +# MDEV-4270: crash in fix_semijoin_strategies_for_picked_join_order +# +drop table if exists t1,t2,t3; +Warnings: +Note 1051 Unknown table 't1' +Note 1051 Unknown table 't2' +Note 1051 Unknown table 't3' +create table t2(a int,unique key (a)) engine=innodb; +create table t3(b int) engine=innodb; +create table t1(a int,b int)engine=innodb; +set @mdev4270_opl= @@optimizer_prune_level; +set @mdev4270_osd= @@optimizer_search_depth; +set optimizer_prune_level=0; +set optimizer_search_depth=2; +select 1 from t1 join t2 a +natural left join t2 b +natural right outer join t3; +1 +drop table t1,t2,t3; +set optimizer_prune_level=@mdev4270_opl; +set optimizer_search_depth=@mdev4270_osd; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 4efb6126cba..43443aa2fef 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1864,6 +1864,38 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; f1 f1 f2 DROP TABLE t1,t2; +# +# Bug#13068506 - QUERY WITH GROUP BY ON NON-AGGR COLUMN RETURNS +# WRONG RESULT +# +CREATE TABLE t1 (i1 int); +INSERT INTO t1 VALUES (100), (101); +CREATE TABLE t2 (i2 int, i3 int); +INSERT INTO t2 VALUES (20,1),(10,2); +CREATE TABLE t3 (i4 int(11)); +INSERT INTO t3 VALUES (1),(2); + +SELECT ( +SELECT MAX( t2.i2 ) +FROM t3 RIGHT JOIN t2 ON ( t2.i3 = 2 ) +WHERE t2.i3 <> t1.i1 +) AS field1 +FROM t1;; +field1 +20 +20 + +SELECT ( +SELECT MAX( t2.i2 ) +FROM t3 RIGHT JOIN t2 ON ( t2.i3 = 2 ) +WHERE t2.i3 <> t1.i1 +) AS field1 +FROM t1 GROUP BY field1;; +field1 +20 + +drop table t1,t2,t3; +# End of test for Bug#13068506 End of 5.1 tests # # LP BUG#994392: Wrong result with RIGHT/LEFT JOIN and ALL subquery @@ -2082,6 +2114,20 @@ b c d 5 8 88 5 8 81 DROP TABLE t1,t2; +# +# Bug mdev-4336: LEFT JOIN with disjunctive +# IS NULL in WHERE +# causes a hang and eventual crash +# +CREATE TABLE t1 ( +id int(11) NOT NULL, +modified datetime NOT NULL, +PRIMARY KEY (id) +); +SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id +WHERE a.modified > b.modified or b.modified IS NULL; +id modified +DROP TABLE t1; SET optimizer_switch=@save_optimizer_switch; set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/r/log_slow.result b/mysql-test/r/log_slow.result index 76cf45631bd..6500ba3ca53 100644 --- a/mysql-test/r/log_slow.result +++ b/mysql-test/r/log_slow.result @@ -13,6 +13,7 @@ log_slow_filter admin,filesort,filesort_on_disk,full_join,full_scan,query_cache, log_slow_queries ON log_slow_rate_limit 1 log_slow_verbosity +set @org_slow_query_log= @@global.slow_query_log; set @@log_slow_filter= "filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk,admin"; select @@log_slow_filter; @@log_slow_filter @@ -56,5 +57,19 @@ insert_id int(11) NO NULL server_id int(10) unsigned NO NULL sql_text mediumtext NO NULL flush slow logs; +set long_query_time=0.1; +set log_slow_filter=''; +set global slow_query_log=1; +set global log_output='TABLE'; +select sleep(0.5); +sleep(0.5) +0 +select count(*) FROM mysql.slow_log; +count(*) +1 +truncate mysql.slow_log; +set @@long_query_time=default; +set global slow_query_log= @org_slow_query_log; set @@log_slow_filter=default; set @@log_slow_verbosity=default; +set global log_output= default; diff --git a/mysql-test/r/myisam-metadata.result b/mysql-test/r/myisam-metadata.result index 4d49bac9436..f13e4ac8b60 100644 --- a/mysql-test/r/myisam-metadata.result +++ b/mysql-test/r/myisam-metadata.result @@ -5,7 +5,7 @@ a VARCHAR(100), INDEX(a) ) ENGINE=MyISAM; ALTER TABLE t1 DISABLE KEYS; -SET debug_sync= 'myisam_after_repair_by_sort SIGNAL waiting WAIT_FOR go'; +SET debug_sync= 'myisam_before_repair_by_sort SIGNAL waiting WAIT_FOR go'; ALTER TABLE t1 ENABLE KEYS; SET debug_sync= 'now WAIT_FOR waiting'; SET debug_sync= 'now SIGNAL go'; diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index c6a806bec80..c68d43831ad 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1764,13 +1764,13 @@ engine=MEMORY partition by key (a); REPAIR TABLE t1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK OPTIMIZE TABLE t1; Table Op Msg_type Msg_text test.t1 optimize note The storage engine for the table doesn't support optimize CHECK TABLE t1; Table Op Msg_type Msg_text -test.t1 check note The storage engine for the table doesn't support check +test.t1 check status OK ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze note The storage engine for the table doesn't support analyze diff --git a/mysql-test/r/partition_innodb.result b/mysql-test/r/partition_innodb.result index adfe3287459..a1accfa8e3d 100644 --- a/mysql-test/r/partition_innodb.result +++ b/mysql-test/r/partition_innodb.result @@ -51,8 +51,8 @@ p200912 0 p201103 1 p201912 0 SELECT count(*) FROM t1 p where c3 in -(select c3 from t1 t where t.c3 < date '2011-04-26 19:19:44' - and t.c3 > date '2011-04-26 19:18:44') ; +(select c3 from t1 t where t.c3 < timestamp '2011-04-26 19:19:44' + and t.c3 > timestamp '2011-04-26 19:18:44') ; count(*) 0 DROP TABLE t1; diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result index 0eb49584c4a..e175d59cbac 100644 --- a/mysql-test/r/plugin.result +++ b/mysql-test/r/plugin.result @@ -15,7 +15,7 @@ PLUGIN_STATUS ACTIVE PLUGIN_TYPE STORAGE ENGINE PLUGIN_TYPE_VERSION # PLUGIN_LIBRARY ha_example.so -PLUGIN_LIBRARY_VERSION 1.4 +PLUGIN_LIBRARY_VERSION 1.5 PLUGIN_AUTHOR Brian Aker, MySQL AB PLUGIN_DESCRIPTION Example storage engine PLUGIN_LICENSE GPL @@ -28,7 +28,7 @@ PLUGIN_STATUS ACTIVE PLUGIN_TYPE DAEMON PLUGIN_TYPE_VERSION # PLUGIN_LIBRARY ha_example.so -PLUGIN_LIBRARY_VERSION 1.4 +PLUGIN_LIBRARY_VERSION 1.5 PLUGIN_AUTHOR Sergei Golubchik PLUGIN_DESCRIPTION Unusable Daemon PLUGIN_LICENSE GPL @@ -60,7 +60,7 @@ PLUGIN_STATUS DELETED PLUGIN_TYPE STORAGE ENGINE PLUGIN_TYPE_VERSION # PLUGIN_LIBRARY ha_example.so -PLUGIN_LIBRARY_VERSION 1.4 +PLUGIN_LIBRARY_VERSION 1.5 PLUGIN_AUTHOR Brian Aker, MySQL AB PLUGIN_DESCRIPTION Example storage engine PLUGIN_LICENSE GPL diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 3d16d37c5f1..c086a62275a 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2921,8 +2921,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) DROP TABLE t1,t2; -select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; -x'10' + 0 X'10' + 0 b'10' + 0 B'10' + 0 +select x'3136' + 0, X'3136' + 0, b'10' + 0, B'10' + 0; +x'3136' + 0 X'3136' + 0 b'10' + 0 B'10' + 0 16 16 2 2 create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null); create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4)); @@ -5119,6 +5119,7 @@ SELECT 1 FROM t1 GROUP BY 1; 1 1 drop table t1; +set sql_buffer_result= 0; # # Bug #58422: Incorrect result when OUTER JOIN'ing # with an empty table @@ -5322,4 +5323,38 @@ AND Time_zone_id = Time_zone_id OR Time_zone_id <> Time_zone_id ) AND Use_leap_seconds <> 'N'; Time_zone_id Use_leap_seconds +# +# Bug mdev-4274: result of simplification of OR badly merged +# into embedding AND +# +CREATE TABLE t1 (a int, b int, INDEX idx(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8,8); +CREATE TABLE t2 (c int, INDEX idx(c)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8), (9); +EXPLAIN EXTENDED +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system idx NULL NULL NULL 1 100.00 +1 SIMPLE t2 ref idx idx 5 const 1 100.00 Using index +Warnings: +Note 1003 select 8 AS `a`,8 AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`c` = 8) and 1) +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +a b c +8 8 8 +DROP TABLE t1,t2; +# +# Bug mdev-4413: another manifestations of bug mdev-2474 +# (valgrind complains) +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,1); +CREATE TABLE t2 (c int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0), (8); +SELECT * FROM t1, t2 +WHERE c = a AND +( 0 OR ( b BETWEEN 45 AND 300 OR a > 45 AND a < 100 ) AND b = c ); +a b c +DROP TABLE t1, t2; End of 5.3 tests diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index 467f940c85d..00b356fc1c0 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -2932,8 +2932,8 @@ 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 hash_ALL NULL #hash#$hj 5 test.t2.a 5 Using where; Using join buffer (flat, BNLH join) DROP TABLE t1,t2; -select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; -x'10' + 0 X'10' + 0 b'10' + 0 B'10' + 0 +select x'3136' + 0, X'3136' + 0, b'10' + 0, B'10' + 0; +x'3136' + 0 X'3136' + 0 b'10' + 0 B'10' + 0 16 16 2 2 create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null); create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4)); @@ -5130,6 +5130,7 @@ SELECT 1 FROM t1 GROUP BY 1; 1 1 drop table t1; +set sql_buffer_result= 0; # # Bug #58422: Incorrect result when OUTER JOIN'ing # with an empty table @@ -5333,6 +5334,40 @@ AND Time_zone_id = Time_zone_id OR Time_zone_id <> Time_zone_id ) AND Use_leap_seconds <> 'N'; Time_zone_id Use_leap_seconds +# +# Bug mdev-4274: result of simplification of OR badly merged +# into embedding AND +# +CREATE TABLE t1 (a int, b int, INDEX idx(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8,8); +CREATE TABLE t2 (c int, INDEX idx(c)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8), (9); +EXPLAIN EXTENDED +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system idx NULL NULL NULL 1 100.00 +1 SIMPLE t2 ref idx idx 5 const 1 100.00 Using index +Warnings: +Note 1003 select 8 AS `a`,8 AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`c` = 8) and 1) +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +a b c +8 8 8 +DROP TABLE t1,t2; +# +# Bug mdev-4413: another manifestations of bug mdev-2474 +# (valgrind complains) +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,1); +CREATE TABLE t2 (c int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0), (8); +SELECT * FROM t1, t2 +WHERE c = a AND +( 0 OR ( b BETWEEN 45 AND 300 OR a > 45 AND a < 100 ) AND b = c ); +a b c +DROP TABLE t1, t2; End of 5.3 tests set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index 3d16d37c5f1..c086a62275a 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -2921,8 +2921,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) DROP TABLE t1,t2; -select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; -x'10' + 0 X'10' + 0 b'10' + 0 B'10' + 0 +select x'3136' + 0, X'3136' + 0, b'10' + 0, B'10' + 0; +x'3136' + 0 X'3136' + 0 b'10' + 0 B'10' + 0 16 16 2 2 create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null); create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4)); @@ -5119,6 +5119,7 @@ SELECT 1 FROM t1 GROUP BY 1; 1 1 drop table t1; +set sql_buffer_result= 0; # # Bug #58422: Incorrect result when OUTER JOIN'ing # with an empty table @@ -5322,4 +5323,38 @@ AND Time_zone_id = Time_zone_id OR Time_zone_id <> Time_zone_id ) AND Use_leap_seconds <> 'N'; Time_zone_id Use_leap_seconds +# +# Bug mdev-4274: result of simplification of OR badly merged +# into embedding AND +# +CREATE TABLE t1 (a int, b int, INDEX idx(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8,8); +CREATE TABLE t2 (c int, INDEX idx(c)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8), (9); +EXPLAIN EXTENDED +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system idx NULL NULL NULL 1 100.00 +1 SIMPLE t2 ref idx idx 5 const 1 100.00 Using index +Warnings: +Note 1003 select 8 AS `a`,8 AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`c` = 8) and 1) +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) +WHERE 1 IS NULL OR b < 33 AND b = c; +a b c +8 8 8 +DROP TABLE t1,t2; +# +# Bug mdev-4413: another manifestations of bug mdev-2474 +# (valgrind complains) +# +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,1); +CREATE TABLE t2 (c int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0), (8); +SELECT * FROM t1, t2 +WHERE c = a AND +( 0 OR ( b BETWEEN 45 AND 300 OR a > 45 AND a < 100 ) AND b = c ); +a b c +DROP TABLE t1, t2; End of 5.3 tests diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 567e878edda..4524a4def83 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -15,7 +15,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 27 Y 0 31 8 +def Msg_text 250 393216 27 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status Table is already up to date check table t1 fast; @@ -23,7 +23,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 27 Y 0 31 8 +def Msg_text 250 393216 27 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status Table is already up to date check table t1 changed; @@ -31,7 +31,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status OK insert into t1 values (5,5,5); @@ -40,7 +40,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status OK check table t1 medium; @@ -48,7 +48,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status OK check table t1 extended; @@ -56,7 +56,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 5 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 check status OK show index from t1; @@ -88,7 +88,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 8 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 optimize status OK optimize table t1; @@ -160,7 +160,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 7 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 analyze status OK show index from t1; @@ -177,7 +177,7 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def Table 253 128 7 Y 0 31 8 def Op 253 10 6 Y 0 31 8 def Msg_type 253 10 6 Y 0 31 8 -def Msg_text 253 255 2 Y 0 31 8 +def Msg_text 250 393216 2 Y 0 31 8 Table Op Msg_type Msg_text test.t1 repair status OK show index from t1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index c297ceda572..6e6f05667ed 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -7916,4 +7916,65 @@ DROP FUNCTION f1; DROP FUNCTION f2; DROP FUNCTION f3; DROP FUNCTION f4; + +Stored procedures and a condition handler in a nested procedure call +doesn't suppress the condition from being passed on to the calling +procedure + +drop procedure if exists p1; +drop procedure if exists p0; +create table t1 (id int); +create procedure p1 () begin +declare i int default 0; +declare continue handler for not found begin +select "You should see this message and the warning that generated this" as "message"; +show warnings; +end; +select id into i from t1; +end$$ +create procedure p0 () begin +declare continue handler for not found begin +select "You should NOT see this message" as "message"; +end; +call p1(); +end$$ +call p0(); +message +You should see this message and the warning that generated this +Level Code Message +Warning 1329 No data - zero rows fetched, selected, or processed +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +drop procedure p1; +drop procedure p0; +drop table t1; + +Test if stored procedures propagates errors + +create table t1 (id int primary key); +create procedure p1 () begin +insert into t1 values(1); +insert into t1 values(2); +insert into t1 values(2); +insert into t1 values(3); +end$$ +create procedure p2 () begin +declare x int; +select id into x from t1 where id=5; +end$$ +call p1(); +ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +show warnings; +Level Code Message +Error 1062 Duplicate entry '2' for key 'PRIMARY' +select * from t1; +id +1 +2 +call p2(); +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +drop procedure p1; +drop procedure p2; +drop table t1; # End of 5.5 test diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index 640a2f649d6..ad12c60cce5 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -220,7 +220,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_frequency his test t1 a 0 49 0.0000 1.0000 4 SINGLE_PREC_HB 2E62A1D0 test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 4 SINGLE_PREC_HB 003FBFFF test t1 c aaaa dddddddd 0.1250 7.0000 4 SINGLE_PREC_HB 0055AAFF -test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 4 SINGLE_PREC_HB 009393FF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 4 SINGLE_PREC_HB 001919FF test t1 e 0.01 0.112 0.2250 6.2000 4 SINGLE_PREC_HB 000564E1 test t1 f 1 5 0.2000 6.4000 4 SINGLE_PREC_HB 3F7FBFBF DELETE FROM mysql.column_stats; @@ -238,7 +238,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_frequency his test t1 a 0 49 0.0000 1.0000 8 DOUBLE_PREC_HB 052F4363F4A1F9D0 test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 8 DOUBLE_PREC_HB 0000FF3FFFBFFFFF test t1 c aaaa dddddddd 0.1250 7.0000 8 DOUBLE_PREC_HB 00005555AAAAFFFF -test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 8 DOUBLE_PREC_HB 000026942694FFFF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 8 DOUBLE_PREC_HB 0000031A031AFFFF test t1 e 0.01 0.112 0.2250 6.2000 8 DOUBLE_PREC_HB 000005056464E1E1 test t1 f 1 5 0.2000 6.4000 8 DOUBLE_PREC_HB FF3FFF7FFFBFFFBF DELETE FROM mysql.column_stats; diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index e368fe2c8b2..829c8abb634 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -27,7 +27,7 @@ ACCESS_DENIED bigint(21) NO 0 EMPTY_QUERIES bigint(21) NO 0 show columns from information_schema.user_statistics; Field Type Null Key Default Extra -USER varchar(48) NO +USER varchar(128) NO TOTAL_CONNECTIONS int(11) NO 0 CONCURRENT_CONNECTIONS int(11) NO 0 CONNECTED_TIME int(11) NO 0 diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result index b1e4cb669ed..139994445f9 100644 --- a/mysql-test/r/strict.result +++ b/mysql-test/r/strict.result @@ -1135,7 +1135,7 @@ create table t1 (col1 date, col2 datetime, col3 timestamp); insert into t1 values (0,0,0); ERROR 22007: Incorrect date value: '0' for column 'col1' at row 1 insert into t1 values (0.0,0.0,0.0); -ERROR 22007: Incorrect date value: '0' for column 'col1' at row 1 +ERROR 22007: Incorrect date value: '0.0' for column 'col1' at row 1 insert into t1 (col1) values (convert('0000-00-00',date)); ERROR 22007: Incorrect datetime value: '0000-00-00' insert into t1 (col1) values (cast('0000-00-00' as date)); diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 53334dbc32b..0a98efb5c0e 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -1999,6 +1999,20 @@ b b v v b b s s b b y y DROP TABLE t1,t2; +# +# MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +# +CREATE TABLE t1 ( +id int(11) NOT NULL +); +CREATE TABLE t2 ( +id int(11) NOT NULL, +a_id int(11) DEFAULT NULL +); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); +drop table t1,t2; # 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.result b/mysql-test/r/subselect_sj.result index 92c626eca61..56c3044c4e4 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -2852,4 +2852,36 @@ field1 o o DROP TABLE t1, t2; +# +# MDEV-389: Wrong result (missing row) with semijoin, join_cache_level>4, LEFT JOIN... +# (testcase only) +# +SET join_cache_level = 5; +SET optimizer_switch = 'semijoin=on'; +CREATE TABLE t1 (a INT NOT NULL, b CHAR(1), KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4,'p'),(1,'q'),(8,'e'); +CREATE TABLE t2 (c INT, d CHAR(1), KEY(c), KEY(d)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,'f'),(2,'i'),(5,'h'),(3,'q'),(1,'g'); +SELECT a, COUNT(*) AS cnt +FROM t1 LEFT JOIN t2 ON (d = b) +WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' ) +GROUP BY a ORDER BY a, cnt LIMIT 2; +a cnt +1 1 +4 1 +drop table t1, t2; +# +# MDEV-4071: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with ... +# +CREATE TABLE t1 (b INT, c VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,'v'),(0,'s'); +CREATE TABLE t2 (a INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0),(8); +SELECT c, SUM( DISTINCT b ) AS sm FROM t1 +WHERE ( 5, 108 ) IN ( SELECT MIN(a), MAX(a) FROM t2 ) +GROUP BY b +HAVING c <> ( SELECT MAX( c ) FROM t1 ) +ORDER BY sm; +c sm +DROP TABLE t1,t2; set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result index c91ee67a717..1af507668da 100644 --- a/mysql-test/r/subselect_sj2_mat.result +++ b/mysql-test/r/subselect_sj2_mat.result @@ -1377,7 +1377,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Using where 2 MATERIALIZED t3 hash_ALL NULL #hash#$hj 5 test.t2.i2 3 100.00 Using where; Using join buffer (flat, BNLH join) Warnings: -Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where ((`test`.`t3`.`i3` = `test`.`t2`.`i2`) and (`test`.`t1`.`i1` = `test`.`t2`.`i2`) and (`test`.`t3`.`i3` > 0)) +Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` join `test`.`t3`) where ((`test`.`t3`.`i3` = `test`.`t2`.`i2`) and (`test`.`t1`.`i1` = `test`.`t2`.`i2`) and (`test`.`t2`.`i2` > 0)) SELECT * FROM t1 WHERE i1 IN (SELECT i3 FROM t2, t3 WHERE i3 > 0 AND i3 = i2 OR 1=2); i1 diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index 04a54c9a371..7be29201c63 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -2866,6 +2866,38 @@ field1 o o DROP TABLE t1, t2; +# +# MDEV-389: Wrong result (missing row) with semijoin, join_cache_level>4, LEFT JOIN... +# (testcase only) +# +SET join_cache_level = 5; +SET optimizer_switch = 'semijoin=on'; +CREATE TABLE t1 (a INT NOT NULL, b CHAR(1), KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4,'p'),(1,'q'),(8,'e'); +CREATE TABLE t2 (c INT, d CHAR(1), KEY(c), KEY(d)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,'f'),(2,'i'),(5,'h'),(3,'q'),(1,'g'); +SELECT a, COUNT(*) AS cnt +FROM t1 LEFT JOIN t2 ON (d = b) +WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' ) +GROUP BY a ORDER BY a, cnt LIMIT 2; +a cnt +1 1 +4 1 +drop table t1, t2; +# +# MDEV-4071: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with ... +# +CREATE TABLE t1 (b INT, c VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,'v'),(0,'s'); +CREATE TABLE t2 (a INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0),(8); +SELECT c, SUM( DISTINCT b ) AS sm FROM t1 +WHERE ( 5, 108 ) IN ( SELECT MIN(a), MAX(a) FROM t2 ) +GROUP BY b +HAVING c <> ( SELECT MAX( c ) FROM t1 ) +ORDER BY sm; +c sm +DROP TABLE t1,t2; set optimizer_switch=@subselect_sj_tmp; # # BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index 549282c9dbe..4e8d1697b83 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -2039,6 +2039,20 @@ b b v v b b s s b b y y DROP TABLE t1,t2; +# +# MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +# +CREATE TABLE t1 ( +id int(11) NOT NULL +); +CREATE TABLE t2 ( +id int(11) NOT NULL, +a_id int(11) DEFAULT NULL +); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); +drop table t1,t2; # 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/temporal_literal.result b/mysql-test/r/temporal_literal.result new file mode 100644 index 00000000000..c79ed311d16 --- /dev/null +++ b/mysql-test/r/temporal_literal.result @@ -0,0 +1,418 @@ +DROP TABLE IF EXISTS t1, t2; +SET NAMES latin1; +# +# Testing DATE literals +# +SELECT DATE'xxxx'; +ERROR HY000: Incorrect DATE value: 'xxxx' +SELECT DATE'01'; +ERROR HY000: Incorrect DATE value: '01' +SELECT DATE'01-01'; +ERROR HY000: Incorrect DATE value: '01-01' +SELECT DATE'2001'; +ERROR HY000: Incorrect DATE value: '2001' +SELECT DATE'2001-01'; +ERROR HY000: Incorrect DATE value: '2001-01' +SELECT DATE'2001-00-00'; +DATE'2001-00-00' +2001-00-00 +SELECT DATE'2001-01-00'; +DATE'2001-01-00' +2001-01-00 +SELECT DATE'0000-00-00'; +DATE'0000-00-00' +0000-00-00 +SELECT DATE'2001-01-01 00:00:00'; +ERROR HY000: Incorrect DATE value: '2001-01-01 00:00:00' +SELECT DATE'01:01:01'; +DATE'01:01:01' +2001-01-01 +SELECT DATE'01-01-01'; +DATE'01-01-01' +2001-01-01 +SELECT DATE'2010-01-01'; +DATE'2010-01-01' +2010-01-01 +SELECT DATE '2010-01-01'; +DATE '2010-01-01' +2010-01-01 +CREATE TABLE t1 AS SELECT DATE'2010-01-01'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `DATE'2010-01-01'` date NOT NULL DEFAULT '0000-00-00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT +{d'2001-01-01'}, +{ d '2001-01-01' }, +{d'2001-01-01 10:10:10'}; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `{d'2001-01-01'}` date NOT NULL DEFAULT '0000-00-00', + `{ d '2001-01-01' }` date NOT NULL DEFAULT '0000-00-00', + `2001-01-01 10:10:10` varchar(19) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {d'2010-01-01'}; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select DATE'2010-01-01' AS `{d'2010-01-01'}` +EXPLAIN EXTENDED SELECT DATE'2010-01-01'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select DATE'2010-01-01' AS `DATE'2010-01-01'` +# +# Testing DATE literals in non-default sql_mode +# +SET sql_mode=no_zero_in_date; +SELECT DATE'2001-00-00'; +ERROR HY000: Incorrect DATE value: '2001-00-00' +SELECT DATE'2001-01-00'; +ERROR HY000: Incorrect DATE value: '2001-01-00' +SELECT DATE'0000-00-00'; +DATE'0000-00-00' +0000-00-00 +SET sql_mode=no_zero_date; +SELECT DATE'0000-00-00'; +ERROR HY000: Incorrect DATE value: '0000-00-00' +SET sql_mode=default; +# +# Testing TIME literals +# +SELECT TIME'xxxx'; +ERROR HY000: Incorrect TIME value: 'xxxx' +SELECT TIME'900:00:00'; +ERROR HY000: Incorrect TIME value: '900:00:00' +SELECT TIME'-900:00:00'; +ERROR HY000: Incorrect TIME value: '-900:00:00' +SELECT TIME'1 24:00:00'; +TIME'1 24:00:00' +48:00:00 +SELECT TIME'30 24:00:00'; +TIME'30 24:00:00' +744:00:00 +SELECT TIME'0000-00-00 00:00:00'; +ERROR HY000: Incorrect TIME value: '0000-00-00 00:00:00' +SELECT TIME'40 24:00:00'; +ERROR HY000: Incorrect TIME value: '40 24:00:00' +SELECT TIME'10'; +TIME'10' +00:00:10 +SELECT TIME'10:10'; +TIME'10:10' +10:10:00 +SELECT TIME'10:11.12'; +TIME'10:11.12' +10:11:00.12 +SELECT TIME'10:10:10'; +TIME'10:10:10' +10:10:10 +SELECT TIME'10:10:10.'; +TIME'10:10:10.' +10:10:10 +SELECT TIME'10:10:10.1'; +TIME'10:10:10.1' +10:10:10.1 +SELECT TIME'10:10:10.12'; +TIME'10:10:10.12' +10:10:10.12 +SELECT TIME'10:10:10.123'; +TIME'10:10:10.123' +10:10:10.123 +SELECT TIME'10:10:10.1234'; +TIME'10:10:10.1234' +10:10:10.1234 +SELECT TIME'10:10:10.12345'; +TIME'10:10:10.12345' +10:10:10.12345 +SELECT TIME'10:10:10.123456'; +TIME'10:10:10.123456' +10:10:10.123456 +SELECT TIME'-10:00:00'; +TIME'-10:00:00' +-10:00:00 +SELECT TIME '10:11:12'; +TIME '10:11:12' +10:11:12 +CREATE TABLE t1 AS SELECT +TIME'10:10:10', +TIME'10:10:10.', +TIME'10:10:10.1', +TIME'10:10:10.12', +TIME'10:10:10.123', +TIME'10:10:10.1234', +TIME'10:10:10.12345', +TIME'10:10:10.123456'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `TIME'10:10:10'` time NOT NULL DEFAULT '00:00:00', + `TIME'10:10:10.'` time NOT NULL DEFAULT '00:00:00', + `TIME'10:10:10.1'` time(1) NOT NULL DEFAULT '00:00:00.0', + `TIME'10:10:10.12'` time(2) NOT NULL DEFAULT '00:00:00.00', + `TIME'10:10:10.123'` time(3) NOT NULL DEFAULT '00:00:00.000', + `TIME'10:10:10.1234'` time(4) NOT NULL DEFAULT '00:00:00.0000', + `TIME'10:10:10.12345'` time(5) NOT NULL DEFAULT '00:00:00.00000', + `TIME'10:10:10.123456'` time(6) NOT NULL DEFAULT '00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT +{t'10:10:10'}, +{ t '10:10:10' }, +{t'10:10:10.'}, +{t'10:10:10.123456'}, +{t'2001-01-01'}; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `{t'10:10:10'}` time NOT NULL DEFAULT '00:00:00', + `{ t '10:10:10' }` time NOT NULL DEFAULT '00:00:00', + `{t'10:10:10.'}` time NOT NULL DEFAULT '00:00:00', + `{t'10:10:10.123456'}` time(6) NOT NULL DEFAULT '00:00:00.000000', + `2001-01-01` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {t'10:01:01'}; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIME'10:01:01' AS `{t'10:01:01'}` +EXPLAIN EXTENDED SELECT TIME'10:01:01'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIME'10:01:01' AS `TIME'10:01:01'` +# +# Testing TIMESTAMP literals +# +SELECT TIMESTAMP'xxxx'; +ERROR HY000: Incorrect DATETIME value: 'xxxx' +SELECT TIMESTAMP'2010'; +ERROR HY000: Incorrect DATETIME value: '2010' +SELECT TIMESTAMP'2010-01'; +ERROR HY000: Incorrect DATETIME value: '2010-01' +SELECT TIMESTAMP'2010-01-01'; +ERROR HY000: Incorrect DATETIME value: '2010-01-01' +SELECT TIMESTAMP'2010-01-01 00'; +TIMESTAMP'2010-01-01 00' +2010-01-01 00:00:00 +SELECT TIMESTAMP'2010-01-01 00:01'; +TIMESTAMP'2010-01-01 00:01' +2010-01-01 00:01:00 +SELECT TIMESTAMP'2010-01-01 10:10:10'; +TIMESTAMP'2010-01-01 10:10:10' +2010-01-01 10:10:10 +SELECT TIMESTAMP'2010-01-01 10:10:10.'; +TIMESTAMP'2010-01-01 10:10:10.' +2010-01-01 10:10:10 +SELECT TIMESTAMP'2010-01-01 10:10:10.1'; +TIMESTAMP'2010-01-01 10:10:10.1' +2010-01-01 10:10:10.1 +SELECT TIMESTAMP'2010-01-01 10:10:10.12'; +TIMESTAMP'2010-01-01 10:10:10.12' +2010-01-01 10:10:10.12 +SELECT TIMESTAMP'2010-01-01 10:10:10.123'; +TIMESTAMP'2010-01-01 10:10:10.123' +2010-01-01 10:10:10.123 +SELECT TIMESTAMP'2010-01-01 10:10:10.1234'; +TIMESTAMP'2010-01-01 10:10:10.1234' +2010-01-01 10:10:10.1234 +SELECT TIMESTAMP'2010-01-01 10:10:10.12345'; +TIMESTAMP'2010-01-01 10:10:10.12345' +2010-01-01 10:10:10.12345 +SELECT TIMESTAMP'2010-01-01 10:10:10.123456'; +TIMESTAMP'2010-01-01 10:10:10.123456' +2010-01-01 10:10:10.123456 +SELECT TIMESTAMP '2010-01-01 10:20:30'; +TIMESTAMP '2010-01-01 10:20:30' +2010-01-01 10:20:30 +CREATE TABLE t1 AS SELECT +TIMESTAMP'2010-01-01 10:10:10', +TIMESTAMP'2010-01-01 10:10:10.', +TIMESTAMP'2010-01-01 10:10:10.1', +TIMESTAMP'2010-01-01 10:10:10.12', +TIMESTAMP'2010-01-01 10:10:10.123', +TIMESTAMP'2010-01-01 10:10:10.1234', +TIMESTAMP'2010-01-01 10:10:10.12345', +TIMESTAMP'2010-01-01 10:10:10.123456'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `TIMESTAMP'2010-01-01 10:10:10'` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `TIMESTAMP'2010-01-01 10:10:10.'` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `TIMESTAMP'2010-01-01 10:10:10.1'` datetime(1) NOT NULL DEFAULT '0000-00-00 00:00:00.0', + `TIMESTAMP'2010-01-01 10:10:10.12'` datetime(2) NOT NULL DEFAULT '0000-00-00 00:00:00.00', + `TIMESTAMP'2010-01-01 10:10:10.123'` datetime(3) NOT NULL DEFAULT '0000-00-00 00:00:00.000', + `TIMESTAMP'2010-01-01 10:10:10.1234'` datetime(4) NOT NULL DEFAULT '0000-00-00 00:00:00.0000', + `TIMESTAMP'2010-01-01 10:10:10.12345'` datetime(5) NOT NULL DEFAULT '0000-00-00 00:00:00.00000', + `TIMESTAMP'2010-01-01 10:10:10.123456'` datetime(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT +{ts'2001-01-01 10:10:10'}, +{ ts '2001-01-01 10:10:10' }, +{ts'2001-01-01 10:10:10.'}, +{ts'2001-01-01 10:10:10.123456'}, +{ts'2001-01-01'}; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `{ts'2001-01-01 10:10:10'}` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `{ ts '2001-01-01 10:10:10' }` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `{ts'2001-01-01 10:10:10.'}` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `{ts'2001-01-01 10:10:10.123456'}` datetime(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `2001-01-01` varchar(10) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {ts'2010-01-01 10:10:10'}; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIMESTAMP'2010-01-01 10:10:10' AS `{ts'2010-01-01 10:10:10'}` +EXPLAIN EXTENDED SELECT TIMESTAMP'2010-01-01 10:10:10'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select TIMESTAMP'2010-01-01 10:10:10' AS `TIMESTAMP'2010-01-01 10:10:10'` +# +# Testing nanosecond rounding for TIMESTAMP literals with bad dates +# +SELECT TIMESTAMP'2001-00-00 00:00:00.999999'; +TIMESTAMP'2001-00-00 00:00:00.999999' +2001-00-00 00:00:00.999999 +SELECT TIMESTAMP'2001-00-01 00:00:00.999999'; +TIMESTAMP'2001-00-01 00:00:00.999999' +2001-00-01 00:00:00.999999 +SELECT TIMESTAMP'2001-01-00 00:00:00.999999'; +TIMESTAMP'2001-01-00 00:00:00.999999' +2001-01-00 00:00:00.999999 +SELECT TIMESTAMP'2001-00-00 00:00:00.9999999'; +ERROR HY000: Incorrect DATETIME value: '2001-00-00 00:00:00.9999999' +SELECT TIMESTAMP'2001-00-01 00:00:00.9999999'; +ERROR HY000: Incorrect DATETIME value: '2001-00-01 00:00:00.9999999' +SELECT TIMESTAMP'2001-01-00 00:00:00.9999999'; +ERROR HY000: Incorrect DATETIME value: '2001-01-00 00:00:00.9999999' +# +# String literal with bad dates and nanoseconds to DATETIME(N) +# +CREATE TABLE t1 (a DATETIME(6)); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +SELECT * FROM t1; +a +2001-00-00 00:00:00.999999 +2001-00-01 00:00:00.999999 +2001-01-00 00:00:00.999999 +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME(5)); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +SELECT * FROM t1; +a +2001-00-00 00:00:00.99999 +2001-00-01 00:00:00.99999 +2001-01-00 00:00:00.99999 +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +SELECT * FROM t1; +a +2001-00-00 00:00:00 +2001-00-01 00:00:00 +2001-01-00 00:00:00 +DROP TABLE t1; +# +# Testing Item_date_literal::eq +# +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2001-01-01'),('2003-01-01'); +SELECT * FROM t1 WHERE a BETWEEN DATE'2001-01-01' AND DATE'2002-01-01'; +a +2001-01-01 +SELECT DATE'2001-01-01' FROM t1 GROUP BY DATE'2001-01-01'; +DATE'2001-01-01' +2001-01-01 +DROP TABLE t1; +# +# TIME literals in no-zero date context +# +SELECT TO_DAYS(TIME'00:00:00'); +TO_DAYS(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT TO_SECONDS(TIME'00:00:00'); +TO_SECONDS(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT DAYOFYEAR(TIME'00:00:00'); +DAYOFYEAR(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT WEEK(TIME'00:00:00'); +WEEK(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT YEARWEEK(TIME'00:00:00'); +YEARWEEK(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT WEEKDAY(TIME'00:00:00'); +WEEKDAY(TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT CONVERT_TZ(TIME'00:00:00','+00:00','+01:00'); +CONVERT_TZ(TIME'00:00:00','+00:00','+01:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT DATE_ADD(TIME'00:00:00', INTERVAL 1 HOUR); +DATE_ADD(TIME'00:00:00', INTERVAL 1 HOUR) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +SELECT TIMESTAMPDIFF(SECOND,TIME'00:00:00', TIME'00:00:00'); +TIMESTAMPDIFF(SECOND,TIME'00:00:00', TIME'00:00:00') +NULL +Warnings: +Warning 1292 Incorrect datetime value: '00:00:00' +# +# Testing Item_func::fix_fields() +# +SELECT 'a' LIKE 'a' ESCAPE DATE'2001-01-01'; +ERROR HY000: Incorrect arguments to ESCAPE +SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00'; +ERROR HY000: Incorrect arguments to ESCAPE +SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00'; +ERROR HY000: Incorrect arguments to ESCAPE diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 05cdcf7e256..d6676bbf16b 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -665,6 +665,22 @@ Warning 1292 Incorrect datetime value: '10:19:31' Warning 1292 Incorrect datetime value: '22:55:23' Warning 1292 Incorrect datetime value: '10:19:31' drop table t1; +# +# Semantics of the condition IS NULL +# when the field belongs to an inner table of an outer join +# +create table t1 (a int, b date not null); +insert t1 values (1, 0), (2, '1999-01-02'); +create table t2 (c int); +insert t2 values (1),(3); +select * from t2 left join t1 on t1.a=t2.c where t1.a is null; +c a b +3 NULL NULL +select * from t2 left join t1 on t1.a=t2.c where t1.b is null; +c a b +1 1 0000-00-00 +3 NULL NULL +drop table t1,t2; End of 5.3 tests # # Start of 5.5 tests diff --git a/mysql-test/r/type_temporal_mysql56.result b/mysql-test/r/type_temporal_mysql56.result new file mode 100644 index 00000000000..b0c81844781 --- /dev/null +++ b/mysql-test/r/type_temporal_mysql56.result @@ -0,0 +1,89 @@ +SHOW CREATE TABLE mysql56time; +Table Create Table +mysql56time CREATE TABLE `mysql56time` ( + `t0` time DEFAULT NULL, + `t1` time(1) DEFAULT NULL, + `t2` time(2) DEFAULT NULL, + `t3` time(3) DEFAULT NULL, + `t4` time(4) DEFAULT NULL, + `t5` time(5) DEFAULT NULL, + `t6` time(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql56time; +t0 838:59:59 +t1 838:59:59.0 +t2 838:59:59.00 +t3 838:59:59.000 +t4 838:59:59.0000 +t5 838:59:59.00000 +t6 838:59:59.000000 +t0 00:00:00 +t1 00:00:00.0 +t2 00:00:00.00 +t3 00:00:00.000 +t4 00:00:00.0000 +t5 00:00:00.00000 +t6 00:00:00.000000 +t0 -838:59:59 +t1 -838:59:59.0 +t2 -838:59:59.00 +t3 -838:59:59.000 +t4 -838:59:59.0000 +t5 -838:59:59.00000 +t6 -838:59:59.000000 +DROP TABLE mysql56time; +SHOW CREATE TABLE mysql56datetime; +Table Create Table +mysql56datetime CREATE TABLE `mysql56datetime` ( + `dt0` datetime DEFAULT NULL, + `dt1` datetime(1) DEFAULT NULL, + `dt2` datetime(2) DEFAULT NULL, + `dt3` datetime(3) DEFAULT NULL, + `dt4` datetime(4) DEFAULT NULL, + `dt5` datetime(5) DEFAULT NULL, + `dt6` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql56datetime; +dt0 0000-00-00 00:00:00 +dt1 0000-00-00 00:00:00.0 +dt2 0000-00-00 00:00:00.00 +dt3 0000-00-00 00:00:00.000 +dt4 0000-00-00 00:00:00.0000 +dt5 0000-00-00 00:00:00.00000 +dt6 0000-00-00 00:00:00.000000 +dt0 9999-12-31 23:59:59 +dt1 9999-12-31 23:59:59.9 +dt2 9999-12-31 23:59:59.99 +dt3 9999-12-31 23:59:59.999 +dt4 9999-12-31 23:59:59.9999 +dt5 9999-12-31 23:59:59.99999 +dt6 9999-12-31 23:59:59.999999 +DROP TABLE mysql56datetime; +SET TIME_ZONE='+00:00'; +SHOW CREATE TABLE mysql56timestamp; +Table Create Table +mysql56timestamp CREATE TABLE `mysql56timestamp` ( + `ts0` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `ts1` timestamp(1) NOT NULL DEFAULT '0000-00-00 00:00:00.0', + `ts2` timestamp(2) NOT NULL DEFAULT '0000-00-00 00:00:00.00', + `ts3` timestamp(3) NOT NULL DEFAULT '0000-00-00 00:00:00.000', + `ts4` timestamp(4) NOT NULL DEFAULT '0000-00-00 00:00:00.0000', + `ts5` timestamp(5) NOT NULL DEFAULT '0000-00-00 00:00:00.00000', + `ts6` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql56timestamp; +ts0 1970-01-01 00:00:01 +ts1 1970-01-01 00:00:01.0 +ts2 1970-01-01 00:00:01.00 +ts3 1970-01-01 00:00:01.000 +ts4 1970-01-01 00:00:01.0000 +ts5 1970-01-01 00:00:01.00000 +ts6 1970-01-01 00:00:01.000000 +ts0 2038-01-19 03:14:07 +ts1 2038-01-19 03:14:07.9 +ts2 2038-01-19 03:14:07.99 +ts3 2038-01-19 03:14:07.999 +ts4 2038-01-19 03:14:07.9999 +ts5 2038-01-19 03:14:07.99999 +ts6 2038-01-19 03:14:07.999999 +DROP TABLE mysql56timestamp; diff --git a/mysql-test/r/user_var-binlog.result b/mysql-test/r/user_var-binlog.result index 27014aab576..e6e9ddf9545 100644 --- a/mysql-test/r/user_var-binlog.result +++ b/mysql-test/r/user_var-binlog.result @@ -9,12 +9,12 @@ insert into t1 values (@var1),(@var2); include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # User var # # @`a b`=_latin1 0x68656C6C6F COLLATE latin1_swedish_ci +master-bin.000001 # User var # # @`a b`=_latin1 X'68656C6C6F' COLLATE latin1_swedish_ci master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES(@`a b`) master-bin.000001 # Query # # COMMIT master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # User var # # @`var1`=_latin1 0x273B616161 COLLATE latin1_swedish_ci -master-bin.000001 # User var # # @`var2`=_binary 0x61 COLLATE binary +master-bin.000001 # User var # # @`var1`=_latin1 X'273B616161' COLLATE latin1_swedish_ci +master-bin.000001 # User var # # @`var2`=_binary X'61' COLLATE binary master-bin.000001 # Query # # use `test`; insert into t1 values (@var1),(@var2) master-bin.000001 # Query # # COMMIT flush logs; @@ -25,7 +25,7 @@ DELIMITER /*!*/; ROLLBACK/*!*/; BEGIN /*!*/; -SET @`a b`:=_latin1 0x68656C6C6F COLLATE `latin1_swedish_ci`/*!*/; +SET @`a b`:=_latin1 X'68656C6C6F' COLLATE `latin1_swedish_ci`/*!*/; use `test`/*!*/; SET TIMESTAMP=10000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; @@ -43,8 +43,8 @@ COMMIT /*!*/; BEGIN /*!*/; -SET @`var1`:=_latin1 0x273B616161 COLLATE `latin1_swedish_ci`/*!*/; -SET @`var2`:=_binary 0x61 COLLATE `binary`/*!*/; +SET @`var1`:=_latin1 X'273B616161' COLLATE `latin1_swedish_ci`/*!*/; +SET @`var2`:=_binary X'61' COLLATE `binary`/*!*/; SET TIMESTAMP=10000/*!*/; insert into t1 values (@var1),(@var2) /*!*/; diff --git a/mysql-test/r/varbinary.result b/mysql-test/r/varbinary.result index 065abbb9c00..689db16b5d4 100644 --- a/mysql-test/r/varbinary.result +++ b/mysql-test/r/varbinary.result @@ -5,9 +5,62 @@ A 65 9223372036854775807 18446744073709551615 select 0x31+1,concat(0x31)+1,-0xf; 0x31+1 concat(0x31)+1 -0xf 50 2 -15 -select x'31',X'ffff'+0; -x'31' X'ffff'+0 +select x'31',0xffff+0; +x'31' 0xffff+0 1 65535 +select X'FFFF'+0; +X'FFFF'+0 +0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '\xFF\xFF' +SELECT x'31'+0, 0x31+0; +x'31'+0 0x31+0 +1 49 +SELECT x'31'+0.1e0, 0x31+0.1e0; +x'31'+0.1e0 0x31+0.1e0 +1.1 49.1 +SELECT x'312E39'+0e0, 0x312E39+0e0; +x'312E39'+0e0 0x312E39+0e0 +1.9 3223097 +SELECT CAST(x'31' AS SIGNED), CAST(0x31 AS SIGNED); +CAST(x'31' AS SIGNED) CAST(0x31 AS SIGNED) +1 49 +SELECT CAST(x'31' AS DECIMAL(10,1)), CAST(0x31 AS DECIMAL(10,1)); +CAST(x'31' AS DECIMAL(10,1)) CAST(0x31 AS DECIMAL(10,1)) +1.0 49.0 +SELECT CAST(x'312E39' AS SIGNED), CAST(0x312E39 AS SIGNED); +CAST(x'312E39' AS SIGNED) CAST(0x312E39 AS SIGNED) +1 3223097 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: '1.9' +SELECT CAST(x'312E39' AS DECIMAL(10,1)), CAST(0x312E39 AS DECIMAL(10,1)); +CAST(x'312E39' AS DECIMAL(10,1)) CAST(0x312E39 AS DECIMAL(10,1)) +1.9 3223097.0 +EXPLAIN EXTENDED SELECT X'FFFF', 0xFFFF; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select X'ffff' AS `X'FFFF'`,0xffff AS `0xFFFF` +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (X'31'),(0x31); +INSERT INTO t1 VALUES (X'312E39'),(0x312E39); +SELECT * FROM t1; +a +1 +49 +2 +3223097 +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL(10,1)); +INSERT INTO t1 VALUES (X'31'),(0x31); +INSERT INTO t1 VALUES (X'312E39'),(0x312E39); +SELECT * FROM t1; +a +1.0 +49.0 +1.9 +3223097.0 +DROP TABLE t1; create table t1 (ID int(8) unsigned zerofill not null auto_increment,UNIQ bigint(21) unsigned zerofill not null,primary key (ID),unique (UNIQ) ); insert into t1 set UNIQ=0x38afba1d73e6a18a; insert into t1 set UNIQ=123; @@ -104,8 +157,8 @@ A select b'01000001'; b'01000001' A -select x'41', 0+x'41'; -x'41' 0+x'41' +select x'41', 0+x'3635'; +x'41' 0+x'3635' A 65 select N'abc', length(N'abc'); abc length(N'abc') diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index bba63e73c56..0db68c4934f 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -78,7 +78,7 @@ explain extended select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select (@t1:=((@t2:=1) + (@t3:=4))) AS `@t1:=(@t2:=1)+@t3:=4`,(@t1) AS `@t1`,(@t2) AS `@t2`,(@t3) AS `@t3` +Note 1003 select (@t1:=((@t2:=1) + (@t3:=4))) AS `@t1:=(@t2:=1)+@t3:=4`,(@`t1`) AS `@t1`,(@`t2`) AS `@t2`,(@`t3`) AS `@t3` select @t5; @t5 1.23456 @@ -1790,4 +1790,8 @@ set session collation_connection=2048; ERROR HY000: Unknown collation: '2048' set session collation_database=2048; ERROR HY000: Unknown collation: '2048' +set session rand_seed1=DEFAULT; +ERROR 42000: Variable 'rand_seed1' doesn't have a default value +set autocommit = values(v); +ERROR 42S22: Unknown column 'v' in 'field list' End of 5.5 tests diff --git a/mysql-test/std_data/mysql56datetime.MYD b/mysql-test/std_data/mysql56datetime.MYD new file mode 100644 index 00000000000..5c398fe9f7a Binary files /dev/null and b/mysql-test/std_data/mysql56datetime.MYD differ diff --git a/mysql-test/std_data/mysql56datetime.MYI b/mysql-test/std_data/mysql56datetime.MYI new file mode 100644 index 00000000000..d1b19d18093 Binary files /dev/null and b/mysql-test/std_data/mysql56datetime.MYI differ diff --git a/mysql-test/std_data/mysql56datetime.frm b/mysql-test/std_data/mysql56datetime.frm new file mode 100644 index 00000000000..5b215ae3400 Binary files /dev/null and b/mysql-test/std_data/mysql56datetime.frm differ diff --git a/mysql-test/std_data/mysql56time.MYD b/mysql-test/std_data/mysql56time.MYD new file mode 100644 index 00000000000..29ac794e9db Binary files /dev/null and b/mysql-test/std_data/mysql56time.MYD differ diff --git a/mysql-test/std_data/mysql56time.MYI b/mysql-test/std_data/mysql56time.MYI new file mode 100644 index 00000000000..0cdac671d93 Binary files /dev/null and b/mysql-test/std_data/mysql56time.MYI differ diff --git a/mysql-test/std_data/mysql56time.frm b/mysql-test/std_data/mysql56time.frm new file mode 100644 index 00000000000..318f2080b5e Binary files /dev/null and b/mysql-test/std_data/mysql56time.frm differ diff --git a/mysql-test/std_data/mysql56timestamp.MYD b/mysql-test/std_data/mysql56timestamp.MYD new file mode 100644 index 00000000000..9d0cb49737c Binary files /dev/null and b/mysql-test/std_data/mysql56timestamp.MYD differ diff --git a/mysql-test/std_data/mysql56timestamp.MYI b/mysql-test/std_data/mysql56timestamp.MYI new file mode 100644 index 00000000000..fb47f4a5c6a Binary files /dev/null and b/mysql-test/std_data/mysql56timestamp.MYI differ diff --git a/mysql-test/std_data/mysql56timestamp.frm b/mysql-test/std_data/mysql56timestamp.frm new file mode 100644 index 00000000000..104fae4e4bd Binary files /dev/null and b/mysql-test/std_data/mysql56timestamp.frm differ diff --git a/mysql-test/suite/binlog/disabled.def b/mysql-test/suite/binlog/disabled.def index 1abc9951322..424e5549541 100644 --- a/mysql-test/suite/binlog/disabled.def +++ b/mysql-test/suite/binlog/disabled.def @@ -10,4 +10,4 @@ # ############################################################################## binlog_truncate_innodb : BUG#11764459 2010-10-20 anitha Originally disabled due to BUG#42643. Product bug fixed, but test changes needed -binlog_spurious_ddl_errors : BUG#11761680 2010-06-03 alik binlog_spurious_ddl_errors.test fails, thus disabled +binlog_spurious_ddl_errors : BUG#11761680 2013-01-18 astha Fixed on mysql-5.6 and trunk diff --git a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_innodb.result b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_innodb.result index a209ec141fe..0c44061c4e9 100644 --- a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_innodb.result +++ b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_innodb.result @@ -2404,7 +2404,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -2766,7 +2766,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -3019,7 +3019,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -3551,7 +3551,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ diff --git a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_myisam.result b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_myisam.result index ff4f26b93e5..e54e33283fd 100644 --- a/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_mysqlbinlog_row_myisam.result @@ -2404,7 +2404,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -2773,7 +2773,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -3028,7 +3028,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ @@ -3568,7 +3568,7 @@ BEGIN ### @28='1000:01:01' /* DATE meta=0 nullable=1 is_null=0 */ ### @29=1000-01-01 00:00:00 /* DATETIME meta=0 nullable=1 is_null=0 */ ### @30=75601 /* TIMESTAMP meta=0 nullable=0 is_null=0 */ -### @31='839:12:57' /* TIME meta=0 nullable=1 is_null=0 */ +### @31='-838:59:59' /* TIME meta=0 nullable=1 is_null=0 */ ### @32=1901 /* YEAR meta=0 nullable=1 is_null=0 */ ### @33='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ ### @34='' /* STRING(0) meta=65024 nullable=1 is_null=0 */ diff --git a/mysql-test/suite/binlog/r/binlog_spurious_ddl_errors.result b/mysql-test/suite/binlog/r/binlog_spurious_ddl_errors.result index 17a473ff062..1a81eee1a58 100644 --- a/mysql-test/suite/binlog/r/binlog_spurious_ddl_errors.result +++ b/mysql-test/suite/binlog/r/binlog_spurious_ddl_errors.result @@ -48,6 +48,7 @@ DROP TABLE t_stmt; ################################################################################ # CLEAN UP # ################################################################################ +flush tables; UNINSTALL PLUGIN example; SET @@global.binlog_format = @old_binlog_format; SET @@session.binlog_format = @old_binlog_format; diff --git a/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result b/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result index 2cabda0b88e..55db2de4b52 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result +++ b/mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result @@ -6,7 +6,7 @@ insert into t2 values (@v); include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # BEGIN GTID #-#-# -master-bin.000001 # User var # # @`v`=_ucs2 0x006100620063 COLLATE ucs2_general_ci +master-bin.000001 # User var # # @`v`=_ucs2 X'006100620063' COLLATE ucs2_general_ci master-bin.000001 # Query # # use `test`; insert into t2 values (@v) master-bin.000001 # Query # # COMMIT flush logs; @@ -17,7 +17,7 @@ DELIMITER /*!*/; ROLLBACK/*!*/; BEGIN /*!*/; -SET @`v`:=_ucs2 0x006100620063 COLLATE `ucs2_general_ci`/*!*/; +SET @`v`:=_ucs2 X'006100620063' COLLATE `ucs2_general_ci`/*!*/; use `test`/*!*/; SET TIMESTAMP=10000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; diff --git a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result index e290587cb01..03fcb481245 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result @@ -961,10 +961,10 @@ include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Intvar # # INSERT_ID=10 -master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci +master-bin.000001 # User var # # @`b`=_latin1 X'3135' COLLATE latin1_swedish_ci master-bin.000001 # Begin_load_query # # ;file_id=#;block_len=# master-bin.000001 # Intvar # # INSERT_ID=10 -master-bin.000001 # User var # # @`b`=_latin1 0x3135 COLLATE latin1_swedish_ci +master-bin.000001 # User var # # @`b`=_latin1 X'3135' COLLATE latin1_swedish_ci master-bin.000001 # Execute_load_query # # use `test`; LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE `t4` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`, @`b`) SET `b`= @b + bug27417(2) ;file_id=# master-bin.000001 # Query # # ROLLBACK drop trigger trg_del_t2; diff --git a/mysql-test/suite/binlog/t/binlog_spurious_ddl_errors.test b/mysql-test/suite/binlog/t/binlog_spurious_ddl_errors.test index 6514ff1f712..e64e7838a31 100644 --- a/mysql-test/suite/binlog/t/binlog_spurious_ddl_errors.test +++ b/mysql-test/suite/binlog/t/binlog_spurious_ddl_errors.test @@ -26,7 +26,7 @@ --source include/have_log_bin.inc SET @old_binlog_format= @@global.binlog_format; -INSTALL PLUGIN example SONAME 'ha_example.so'; +INSTALL PLUGIN example SONAME 'ha_example'; --echo ################################################################################ --echo # Verifies if ER_BINLOG_STMT_MODE_AND_ROW_ENGINE happens by setting the binlog @@ -90,6 +90,7 @@ DROP TABLE t_stmt; --echo ################################################################################ --echo # CLEAN UP # --echo ################################################################################ +flush tables; UNINSTALL PLUGIN example; SET @@global.binlog_format = @old_binlog_format; SET @@session.binlog_format = @old_binlog_format; diff --git a/mysql-test/suite/federated/federated.result b/mysql-test/suite/federated/federated.result new file mode 100644 index 00000000000..49f9d338c6a --- /dev/null +++ b/mysql-test/suite/federated/federated.result @@ -0,0 +1,13 @@ +CREATE DATABASE federated; +CREATE DATABASE federated; +CREATE TABLE t1 (a INT) ENGINE=FEDERATED CONNECTION='non_existing'; +ERROR HY000: server name: 'non_existing' doesn't exist! +SHOW WARNINGS; +Level Code Message +Error 1 server name: 'non_existing' doesn't exist! +Error 1 Can't create/write to file 'non_existing' (Errcode: 14 "Bad address") +Error 1005 Can't create table `test`.`t1` (errno: 1 "Operation not permitted") +DROP TABLE IF EXISTS federated.t1; +DROP DATABASE IF EXISTS federated; +DROP TABLE IF EXISTS federated.t1; +DROP DATABASE IF EXISTS federated; diff --git a/mysql-test/suite/federated/federated.test b/mysql-test/suite/federated/federated.test new file mode 100644 index 00000000000..88d20817996 --- /dev/null +++ b/mysql-test/suite/federated/federated.test @@ -0,0 +1,12 @@ +source include/federated.inc; + +connection master; +# +# MDEV-388 Creating a federated table with a non-existing server returns a random error code +# +--error 1 +CREATE TABLE t1 (a INT) ENGINE=FEDERATED CONNECTION='non_existing'; +SHOW WARNINGS; + +source include/federated_cleanup.inc; + diff --git a/mysql-test/suite/federated/federatedx.test b/mysql-test/suite/federated/federatedx.test index 15fdd47c4da..cfe6a425944 100644 --- a/mysql-test/suite/federated/federatedx.test +++ b/mysql-test/suite/federated/federatedx.test @@ -1999,4 +1999,5 @@ connection slave; SET @@GLOBAL.CONCURRENT_INSERT= @OLD_SLAVE_CONCURRENT_INSERT; connection default; + source include/federated_cleanup.inc; diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index 75b87daa86c..b3bff85d95c 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -245,7 +245,7 @@ def information_schema PROCESSLIST STAGE 10 0 NO tinyint NULL NULL 3 0 NULL NULL def information_schema PROCESSLIST STATE 7 NULL YES varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select def information_schema PROCESSLIST TIME 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(7) select def information_schema PROCESSLIST TIME_MS 9 0.000 NO decimal NULL NULL 22 3 NULL NULL NULL decimal(22,3) select -def information_schema PROCESSLIST USER 2 NO varchar 16 48 NULL NULL NULL utf8 utf8_general_ci varchar(16) select +def information_schema PROCESSLIST USER 2 NO varchar 128 384 NULL NULL NULL utf8 utf8_general_ci varchar(128) select def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_CATALOG 1 NO varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) select def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_NAME 3 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_SCHEMA 2 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select @@ -413,7 +413,7 @@ def information_schema USER_STATISTICS ROWS_UPDATED 14 0 NO bigint NULL NULL 19 def information_schema USER_STATISTICS SELECT_COMMANDS 15 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select def information_schema USER_STATISTICS TOTAL_CONNECTIONS 2 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) select def information_schema USER_STATISTICS UPDATE_COMMANDS 16 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select -def information_schema USER_STATISTICS USER 1 NO varchar 48 144 NULL NULL NULL utf8 utf8_general_ci varchar(48) select +def information_schema USER_STATISTICS USER 1 NO varchar 128 384 NULL NULL NULL utf8 utf8_general_ci varchar(128) select def information_schema VIEWS CHARACTER_SET_CLIENT 9 NO varchar 32 96 NULL NULL NULL utf8 utf8_general_ci varchar(32) select def information_schema VIEWS CHECK_OPTION 5 NO varchar 8 24 NULL NULL NULL utf8 utf8_general_ci varchar(8) select def information_schema VIEWS COLLATION_CONNECTION 10 NO varchar 32 96 NULL NULL NULL utf8 utf8_general_ci varchar(32) select @@ -716,7 +716,7 @@ NULL information_schema PARTITIONS CHECKSUM bigint NULL NULL NULL NULL bigint(21 3.0000 information_schema PLUGINS PLUGIN_MATURITY varchar 12 36 utf8 utf8_general_ci varchar(12) 3.0000 information_schema PLUGINS PLUGIN_AUTH_VERSION varchar 80 240 utf8 utf8_general_ci varchar(80) NULL information_schema PROCESSLIST ID bigint NULL NULL NULL NULL bigint(4) -3.0000 information_schema PROCESSLIST USER varchar 16 48 utf8 utf8_general_ci varchar(16) +3.0000 information_schema PROCESSLIST USER varchar 128 384 utf8 utf8_general_ci varchar(128) 3.0000 information_schema PROCESSLIST HOST varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST DB varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST COMMAND varchar 16 48 utf8 utf8_general_ci varchar(16) @@ -874,7 +874,7 @@ NULL information_schema TRIGGERS CREATED datetime NULL NULL NULL NULL datetime 3.0000 information_schema USER_PRIVILEGES TABLE_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512) 3.0000 information_schema USER_PRIVILEGES PRIVILEGE_TYPE varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema USER_PRIVILEGES IS_GRANTABLE varchar 3 9 utf8 utf8_general_ci varchar(3) -3.0000 information_schema USER_STATISTICS USER varchar 48 144 utf8 utf8_general_ci varchar(48) +3.0000 information_schema USER_STATISTICS USER varchar 128 384 utf8 utf8_general_ci varchar(128) NULL information_schema USER_STATISTICS TOTAL_CONNECTIONS int NULL NULL NULL NULL int(11) NULL information_schema USER_STATISTICS CONCURRENT_CONNECTIONS int NULL NULL NULL NULL int(11) NULL information_schema USER_STATISTICS CONNECTED_TIME int NULL NULL NULL NULL int(11) diff --git a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result index ba5166691c1..1fe4e2ebeb6 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result @@ -246,7 +246,7 @@ def information_schema PROCESSLIST STAGE 10 0 NO tinyint NULL NULL 3 0 NULL NULL def information_schema PROCESSLIST STATE 7 NULL YES varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) def information_schema PROCESSLIST TIME 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(7) def information_schema PROCESSLIST TIME_MS 9 0.000 NO decimal NULL NULL 22 3 NULL NULL NULL decimal(22,3) -def information_schema PROCESSLIST USER 2 NO varchar 16 48 NULL NULL NULL utf8 utf8_general_ci varchar(16) +def information_schema PROCESSLIST USER 2 NO varchar 128 384 NULL NULL NULL utf8 utf8_general_ci varchar(128) def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_CATALOG 1 NO varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_NAME 3 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) def information_schema REFERENTIAL_CONSTRAINTS CONSTRAINT_SCHEMA 2 NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) @@ -414,7 +414,7 @@ def information_schema USER_STATISTICS ROWS_UPDATED 14 0 NO bigint NULL NULL 19 def information_schema USER_STATISTICS SELECT_COMMANDS 15 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) def information_schema USER_STATISTICS TOTAL_CONNECTIONS 2 0 NO int NULL NULL 10 0 NULL NULL NULL int(11) def information_schema USER_STATISTICS UPDATE_COMMANDS 16 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) -def information_schema USER_STATISTICS USER 1 NO varchar 48 144 NULL NULL NULL utf8 utf8_general_ci varchar(48) +def information_schema USER_STATISTICS USER 1 NO varchar 128 384 NULL NULL NULL utf8 utf8_general_ci varchar(128) def information_schema VIEWS CHARACTER_SET_CLIENT 9 NO varchar 32 96 NULL NULL NULL utf8 utf8_general_ci varchar(32) def information_schema VIEWS CHECK_OPTION 5 NO varchar 8 24 NULL NULL NULL utf8 utf8_general_ci varchar(8) def information_schema VIEWS COLLATION_CONNECTION 10 NO varchar 32 96 NULL NULL NULL utf8 utf8_general_ci varchar(32) @@ -721,7 +721,7 @@ NULL information_schema PARTITIONS CHECKSUM bigint NULL NULL NULL NULL bigint(21 3.0000 information_schema PLUGINS PLUGIN_MATURITY varchar 12 36 utf8 utf8_general_ci varchar(12) 3.0000 information_schema PLUGINS PLUGIN_AUTH_VERSION varchar 80 240 utf8 utf8_general_ci varchar(80) NULL information_schema PROCESSLIST ID bigint NULL NULL NULL NULL bigint(4) -3.0000 information_schema PROCESSLIST USER varchar 16 48 utf8 utf8_general_ci varchar(16) +3.0000 information_schema PROCESSLIST USER varchar 128 384 utf8 utf8_general_ci varchar(128) 3.0000 information_schema PROCESSLIST HOST varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST DB varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema PROCESSLIST COMMAND varchar 16 48 utf8 utf8_general_ci varchar(16) @@ -879,7 +879,7 @@ NULL information_schema TRIGGERS CREATED datetime NULL NULL NULL NULL datetime 3.0000 information_schema USER_PRIVILEGES TABLE_CATALOG varchar 512 1536 utf8 utf8_general_ci varchar(512) 3.0000 information_schema USER_PRIVILEGES PRIVILEGE_TYPE varchar 64 192 utf8 utf8_general_ci varchar(64) 3.0000 information_schema USER_PRIVILEGES IS_GRANTABLE varchar 3 9 utf8 utf8_general_ci varchar(3) -3.0000 information_schema USER_STATISTICS USER varchar 48 144 utf8 utf8_general_ci varchar(48) +3.0000 information_schema USER_STATISTICS USER varchar 128 384 utf8 utf8_general_ci varchar(128) NULL information_schema USER_STATISTICS TOTAL_CONNECTIONS int NULL NULL NULL NULL int(11) NULL information_schema USER_STATISTICS CONCURRENT_CONNECTIONS int NULL NULL NULL NULL int(11) NULL information_schema USER_STATISTICS CONNECTED_TIME int NULL NULL NULL NULL int(11) diff --git a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result index 7bd5f9adb54..7c8563a400d 100644 --- a/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result +++ b/mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result @@ -23,7 +23,7 @@ SHOW CREATE TABLE processlist; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', @@ -98,7 +98,7 @@ SHOW CREATE TABLE processlist; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', diff --git a/mysql-test/suite/funcs_1/r/processlist_priv_ps.result b/mysql-test/suite/funcs_1/r/processlist_priv_ps.result index 8181901bde7..8985cc4ff73 100644 --- a/mysql-test/suite/funcs_1/r/processlist_priv_ps.result +++ b/mysql-test/suite/funcs_1/r/processlist_priv_ps.result @@ -23,7 +23,7 @@ SHOW CREATE TABLE processlist; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', @@ -98,7 +98,7 @@ SHOW CREATE TABLE processlist; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', diff --git a/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result b/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result index 321936cdc1b..57c84da36c7 100644 --- a/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result +++ b/mysql-test/suite/funcs_1/r/processlist_val_no_prot.result @@ -13,7 +13,7 @@ SHOW CREATE TABLE INFORMATION_SCHEMA.PROCESSLIST; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', diff --git a/mysql-test/suite/funcs_1/r/processlist_val_ps.result b/mysql-test/suite/funcs_1/r/processlist_val_ps.result index 5b7e05c6e1b..0995c7a63ec 100644 --- a/mysql-test/suite/funcs_1/r/processlist_val_ps.result +++ b/mysql-test/suite/funcs_1/r/processlist_val_ps.result @@ -13,7 +13,7 @@ SHOW CREATE TABLE INFORMATION_SCHEMA.PROCESSLIST; Table Create Table PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` ( `ID` bigint(4) NOT NULL DEFAULT '0', - `USER` varchar(16) NOT NULL DEFAULT '', + `USER` varchar(128) NOT NULL DEFAULT '', `HOST` varchar(64) NOT NULL DEFAULT '', `DB` varchar(64) DEFAULT NULL, `COMMAND` varchar(16) NOT NULL DEFAULT '', diff --git a/mysql-test/suite/handler/interface.result b/mysql-test/suite/handler/interface.result index cebbc2784df..89dec29f412 100644 --- a/mysql-test/suite/handler/interface.result +++ b/mysql-test/suite/handler/interface.result @@ -294,3 +294,13 @@ ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema USE test; PREPARE h_r FROM 'HANDLER t1 READ `PRIMARY` LAST'; ERROR 42S02: Unknown table 't1' in HANDLER +create view v as select 1; +create temporary table v as select 2; +handler v open; +prepare stmt from 'create table if not exists v as select 3'; +execute stmt; +Warnings: +Note 1050 Table 'v' already exists +handler v read next; +ERROR 42S02: Unknown table 'v' in HANDLER +drop view v; diff --git a/mysql-test/suite/handler/interface.test b/mysql-test/suite/handler/interface.test index e4e854b2515..2ef617c3ce7 100644 --- a/mysql-test/suite/handler/interface.test +++ b/mysql-test/suite/handler/interface.test @@ -377,3 +377,16 @@ USE test; # --error ER_UNKNOWN_TABLE PREPARE h_r FROM 'HANDLER t1 READ `PRIMARY` LAST'; + +# +# MySQL Bug#16385711: HANDLER, CREATE TABLE IF NOT EXISTS, PROBLEM AFTER MYSQL_HA_FIND +# +create view v as select 1; +create temporary table v as select 2; +handler v open; +prepare stmt from 'create table if not exists v as select 3'; +execute stmt; +--error ER_UNKNOWN_TABLE +handler v read next; +drop view v; + diff --git a/mysql-test/suite/innodb/r/innodb_bug14147491.result b/mysql-test/suite/innodb/r/innodb_bug14147491.result index 6279f85f676..faf922ca5f8 100644 --- a/mysql-test/suite/innodb/r/innodb_bug14147491.result +++ b/mysql-test/suite/innodb/r/innodb_bug14147491.result @@ -4,14 +4,25 @@ CALL mtr.add_suppression("InnoDB: Warning: database page corruption or a failed" CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b TEXT) ENGINE=InnoDB; INSERT INTO t1 (b) VALUES ('corrupt me'); INSERT INTO t1 (b) VALUES ('corrupt me'); -# Restart server to flush buffers +# Write file to make mysql-test-run.pl expect the "crash", but don't +# start it until it's told to +# We give 30 seconds to do a clean shutdown because we do not want +# to redo apply the pages of t1.ibd at the time of recovery. +# We want SQL to initiate the first access to t1.ibd. +# Wait until disconnected. +# Backup the t1.ibd before corrupting # Corrupt the table Munged a string. Munged a string. -# Write file to make mysql-test-run.pl expect crash and restart +# Write file to make mysql-test-run.pl start up the server again +SET DEBUG_DBUG = '+d,innodb_page_corruption_retries'; +# Write file to make mysql-test-run.pl expect the "crash", but don't +# start it until it's told to +# The below SELECT query will crash the server because some pages +# on the disk are corrupted SELECT * FROM t1; ERROR HY000: Lost connection to MySQL server during query -# Turn on reconnect -# Wait for server to fully start +# Restore the original t1.ibd +# Write file to make mysql-test-run.pl start up the server again # Cleanup DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb_bug12400341.test b/mysql-test/suite/innodb/t/innodb_bug12400341.test index b9f8c503dc5..173d42665be 100644 --- a/mysql-test/suite/innodb/t/innodb_bug12400341.test +++ b/mysql-test/suite/innodb/t/innodb_bug12400341.test @@ -7,6 +7,10 @@ if (`select count(*)=0 from information_schema.global_variables where variable_n --skip Test requires InnoDB built with UNIV_DEBUG definition. } +# Don't test under valgrind, undo slots of the previous test might exist still +# and cause unstable result. +--source include/not_valgrind.inc + call mtr.add_suppression("InnoDB: Warning: cannot find a free slot for an undo log. Do you have too"); --disable_query_log diff --git a/mysql-test/suite/innodb/t/innodb_bug14147491.test b/mysql-test/suite/innodb/t/innodb_bug14147491.test index ee3519c53fc..050f7fbdd73 100644 --- a/mysql-test/suite/innodb/t/innodb_bug14147491.test +++ b/mysql-test/suite/innodb/t/innodb_bug14147491.test @@ -10,6 +10,8 @@ source include/not_crashrep.inc; source include/not_embedded.inc; # Require InnoDB source include/have_innodb.inc; +# Require Debug for SET DEBUG +source include/have_debug.inc; CALL mtr.add_suppression("InnoDB: Error: Unable to read tablespace .* page no .* into the buffer pool after 100 attempts"); CALL mtr.add_suppression("InnoDB: Warning: database page corruption or a failed"); @@ -27,13 +29,26 @@ while ($i) --enable_query_log INSERT INTO t1 (b) VALUES ('corrupt me'); ---echo # Restart server to flush buffers -source include/restart_mysqld.inc; - ---echo # Corrupt the table let $MYSQLD_DATADIR=`select @@datadir`; let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd; +--echo # Write file to make mysql-test-run.pl expect the "crash", but don't +--echo # start it until it's told to +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + +--echo # We give 30 seconds to do a clean shutdown because we do not want +--echo # to redo apply the pages of t1.ibd at the time of recovery. +--echo # We want SQL to initiate the first access to t1.ibd. +shutdown_server 30; + +--echo # Wait until disconnected. +--source include/wait_until_disconnected.inc + +--echo # Backup the t1.ibd before corrupting +--copy_file $t1_IBD $MYSQLD_DATADIR/test/t1.ibd.backup + +--echo # Corrupt the table + perl; use strict; use warnings; @@ -59,17 +74,38 @@ while ($len = sysread IBD_FILE, $chunk, 1024) close IBD_FILE; EOF ---echo # Write file to make mysql-test-run.pl expect crash and restart +--echo # Write file to make mysql-test-run.pl start up the server again --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--enable_reconnect +--source include/wait_until_connected_again.inc +SET DEBUG_DBUG = '+d,innodb_page_corruption_retries'; + +--echo # Write file to make mysql-test-run.pl expect the "crash", but don't +--echo # start it until it's told to +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect + +--echo # The below SELECT query will crash the server because some pages +--echo # on the disk are corrupted --error 2013 SELECT * FROM t1; ---echo # Turn on reconnect ---enable_reconnect +# The below mtr command --remove_file fails randomly on windows with +# error number 13 which is permission denied on nix systems. We sleep +# 1 second hoping that any process holding lock on t1.ibd is released. +SLEEP 1; ---echo # Wait for server to fully start +--echo # Restore the original t1.ibd +--remove_file $MYSQLD_DATADIR/test/t1.ibd +--move_file $MYSQLD_DATADIR/test/t1.ibd.backup $MYSQLD_DATADIR/test/t1.ibd + +--echo # Write file to make mysql-test-run.pl start up the server again +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--enable_reconnect --source include/wait_until_connected_again.inc +# Note SET DEBUG = '-d,innodb_page_corruption_retries' is not required +# because the session information is lost after server restart + --echo # Cleanup DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb_bug14676111-master.opt b/mysql-test/suite/innodb/t/innodb_bug14676111-master.opt new file mode 100644 index 00000000000..e16b9b0b895 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb_bug14676111-master.opt @@ -0,0 +1 @@ +--loose-innodb-purge-threads=0 diff --git a/mysql-test/suite/innodb/t/innodb_bug14676111.test b/mysql-test/suite/innodb/t/innodb_bug14676111.test index fadd111fdc9..41862b8105e 100644 --- a/mysql-test/suite/innodb/t/innodb_bug14676111.test +++ b/mysql-test/suite/innodb/t/innodb_bug14676111.test @@ -3,6 +3,11 @@ -- source include/have_innodb.inc -- source include/have_debug.inc +# Note that this test needs to be able to manipulate how/when purge is done +# using @@innodb_limit_optimistic_insert_debug. This does not work with +# background purge threads, so we disabled them in the -master.opt (they are +# off by default in normal 5.5 innodb but on by default in xtradb) + if (`select count(*)=0 from information_schema.global_variables where variable_name = 'INNODB_LIMIT_OPTIMISTIC_INSERT_DEBUG'`) { --skip Test requires InnoDB built with UNIV_DEBUG definition. diff --git a/mysql-test/suite/maria/distinct.result b/mysql-test/suite/maria/distinct.result new file mode 100644 index 00000000000..7963e7b72ff --- /dev/null +++ b/mysql-test/suite/maria/distinct.result @@ -0,0 +1,25 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a INT, b INT) ENGINE=Aria; +INSERT t1 VALUES (3,2004),(2,2006),(1,2007),(3,2008),(2,2005),(2,2001); +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY b; +GROUP_CONCAT(a) +2 +3 +2 +2 +1 +3 +SELECT DISTINCT GROUP_CONCAT(a) FROM t1 GROUP BY b; +GROUP_CONCAT(a) +2 +3 +1 +DROP TABLE t1; +CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,'q'),(2,NULL),(7,'g'),(6,'x'); +SELECT DISTINCT MAX( a ) FROM t1 GROUP BY b ORDER BY MD5( b ); +MAX( a ) +2 +7 +6 +DROP TABLE t1; diff --git a/mysql-test/suite/maria/distinct.test b/mysql-test/suite/maria/distinct.test new file mode 100644 index 00000000000..c71a172597c --- /dev/null +++ b/mysql-test/suite/maria/distinct.test @@ -0,0 +1,25 @@ +# +# MDEV-4280: +# Assertion `empty_size == empty_size_on_page' failure in ma_blockrec.c or +# ER_NOT_KEYFILE on query with DISTINCT and GROUP BY +# +# This issue was a bug in how we delete row during duplicate removal when +# we use Aria for internal temporary table. +# + +-- source include/have_maria.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (a INT, b INT) ENGINE=Aria; +INSERT t1 VALUES (3,2004),(2,2006),(1,2007),(3,2008),(2,2005),(2,2001); +SELECT GROUP_CONCAT(a) FROM t1 GROUP BY b; +SELECT DISTINCT GROUP_CONCAT(a) FROM t1 GROUP BY b; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,'q'),(2,NULL),(7,'g'),(6,'x'); +SELECT DISTINCT MAX( a ) FROM t1 GROUP BY b ORDER BY MD5( b ); +DROP TABLE t1; diff --git a/mysql-test/suite/maria/maria-autozerofill.result b/mysql-test/suite/maria/maria-autozerofill.result index 22856fe54b0..ef9e2f77345 100644 --- a/mysql-test/suite/maria/maria-autozerofill.result +++ b/mysql-test/suite/maria/maria-autozerofill.result @@ -12,6 +12,8 @@ create table t4 (a int) engine=aria; INSERT INTO t4 VALUES (1),(2); create table t5 (a int) engine=aria; INSERT INTO t5 VALUES (1),(2); +create table t6 (a int) engine=aria; +INSERT INTO t6 VALUES (1),(2); flush tables; create_rename_lsn has non-magic value * shut down mysqld, removed logs, restarted it @@ -25,6 +27,10 @@ Status: changed,sorted index pages,zerofilled insert into t1 values(2); flush table t1; create_rename_lsn has non-magic value +# +# BUG#44422 "mysql_upgrade destroys Maria tables?" +# Check repair and optimize of moved table +# check table t2; Table Op Msg_type Msg_text mysqltest.t2 check error Table is from another system and must be zerofilled or repaired to be usable on this system @@ -59,4 +65,11 @@ mysqltest.t5 repair status OK check table t5; Table Op Msg_type Msg_text mysqltest.t5 check status OK +select * from t6; +a +1 +2 +check table t6; +Table Op Msg_type Msg_text +mysqltest.t6 check status OK drop database mysqltest; diff --git a/mysql-test/suite/maria/maria-autozerofill.test b/mysql-test/suite/maria/maria-autozerofill.test index 9bb2782105a..e56f71d2c5f 100644 --- a/mysql-test/suite/maria/maria-autozerofill.test +++ b/mysql-test/suite/maria/maria-autozerofill.test @@ -33,11 +33,13 @@ create table t4 (a int) engine=aria; INSERT INTO t4 VALUES (1),(2); create table t5 (a int) engine=aria; INSERT INTO t5 VALUES (1),(2); +create table t6 (a int) engine=aria; +INSERT INTO t6 VALUES (1),(2); flush tables; # Check that table is not zerofilled, not movable let $MYSQLD_DATADIR= `select @@datadir`; ---exec $MARIA_CHK -dv $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt +--exec $MARIA_CHK -dv --ignore-control-file $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt perl; use strict; use warnings; @@ -62,7 +64,7 @@ enable_ps_protocol; flush table t1; # Check that table is auto-zerofilled, movable ---exec $MARIA_CHK -dv $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt +--exec $MARIA_CHK -dv --ignore-control-file $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt perl; use strict; use warnings; @@ -79,7 +81,7 @@ insert into t1 values(2); flush table t1; # Check that table is not zerofilled, not movable ---exec $MARIA_CHK -dv $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt +--exec $MARIA_CHK -dv --ignore-control-file $MYSQLD_DATADIR/mysqltest/t1 >$MYSQLTEST_VARDIR/tmp/ariachk.txt perl; use strict; use warnings; @@ -91,10 +93,13 @@ perl; close FILE; EOF -# -# BUG#44422 "mysql_upgrade destroys Maria tables?" -# Check repair and optimize of moved table -# +--echo # +--echo # BUG#44422 "mysql_upgrade destroys Maria tables?" +--echo # Check repair and optimize of moved table +--echo # + +# Table t2 is regarded as it would be from another server as we removed +# the aria control file earlier check table t2; check table t2; repair table t2; @@ -108,4 +113,10 @@ check table t5; repair table t5; check table t5; +# Check that if we zerofill with aria_chk, we should not get any warnings when +# accessing the table +--exec $MARIA_CHK --zerofill $MYSQLD_DATADIR/mysqltest/t6 >$MYSQLTEST_VARDIR/tmp/ariachk.txt +select * from t6; +check table t6; + drop database mysqltest; diff --git a/mysql-test/suite/maria/maria-recovery2.result b/mysql-test/suite/maria/maria-recovery2.result index 6e4daa64615..054e86d079c 100644 --- a/mysql-test/suite/maria/maria-recovery2.result +++ b/mysql-test/suite/maria/maria-recovery2.result @@ -107,6 +107,9 @@ flush table t1; * copied t1 for comparison lock tables t1 write, t2 read; delete from t1 limit 1; +select count(*) from t1; +count(*) +0 insert into t1 select * from t2; SET SESSION debug_dbug="+d,maria_flush_whole_log,maria_flush_whole_page_cache,maria_crash"; * crashing mysqld intentionally @@ -123,6 +126,9 @@ use mysqltest; show keys from t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment t1 1 a 1 a A 1 NULL NULL YES BTREE +select count(*) from t1; +count(*) +1 drop table t1; * TEST of recovery when OPTIMIZE has replaced the index file and crash create table t_corrupted1 (a varchar(100), key(a)) engine=aria; diff --git a/mysql-test/suite/maria/maria-recovery2.test b/mysql-test/suite/maria/maria-recovery2.test index 3c0ad75f8a8..3551d873ca4 100644 --- a/mysql-test/suite/maria/maria-recovery2.test +++ b/mysql-test/suite/maria/maria-recovery2.test @@ -130,9 +130,11 @@ insert into t1 values(30); lock tables t1 write, t2 read; delete from t1 limit 1; # 127 rows in t2, >100, so this will use repair-at-end +select count(*) from t1; insert into t1 select * from t2; -- source include/maria_verify_recovery.inc show keys from t1; # should be enabled +select count(*) from t1; drop table t1; --echo * TEST of recovery when OPTIMIZE has replaced the index file and crash diff --git a/mysql-test/suite/parts/r/partition_alter1_1_2_innodb.result b/mysql-test/suite/parts/r/partition_alter1_1_2_innodb.result index 8dbb9b44e2f..3ef62f2b050 100644 --- a/mysql-test/suite/parts/r/partition_alter1_1_2_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter1_1_2_innodb.result @@ -531,7 +531,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1023,7 +1023,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1530,7 +1530,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2031,7 +2031,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2530,7 +2530,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3040,7 +3040,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3552,7 +3552,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4052,7 +4052,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4545,7 +4545,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5037,7 +5037,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5544,7 +5544,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6045,7 +6045,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6544,7 +6544,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7054,7 +7054,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7566,7 +7566,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8066,7 +8066,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8576,7 +8576,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9084,7 +9084,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9607,7 +9607,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10124,7 +10124,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10639,7 +10639,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11165,7 +11165,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11693,7 +11693,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12209,7 +12209,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12718,7 +12718,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13226,7 +13226,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13749,7 +13749,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14266,7 +14266,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14781,7 +14781,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15307,7 +15307,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15835,7 +15835,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16351,7 +16351,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16846,7 +16846,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17339,7 +17339,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17847,7 +17847,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18349,7 +18349,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18849,7 +18849,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19360,7 +19360,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19873,7 +19873,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20374,7 +20374,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20868,7 +20868,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21361,7 +21361,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21869,7 +21869,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22371,7 +22371,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22871,7 +22871,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23382,7 +23382,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23895,7 +23895,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24396,7 +24396,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24890,7 +24890,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25383,7 +25383,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25891,7 +25891,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26393,7 +26393,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26893,7 +26893,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27404,7 +27404,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27917,7 +27917,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28418,7 +28418,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter1_1_innodb.result b/mysql-test/suite/parts/r/partition_alter1_1_innodb.result index 075346cfe94..66d84768b5e 100644 --- a/mysql-test/suite/parts/r/partition_alter1_1_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter1_1_innodb.result @@ -849,7 +849,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1341,7 +1341,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1848,7 +1848,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2349,7 +2349,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2850,7 +2850,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3360,7 +3360,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3872,7 +3872,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4372,7 +4372,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4865,7 +4865,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5357,7 +5357,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5864,7 +5864,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6365,7 +6365,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6866,7 +6866,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7376,7 +7376,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7888,7 +7888,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8388,7 +8388,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8898,7 +8898,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9406,7 +9406,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9929,7 +9929,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10446,7 +10446,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10963,7 +10963,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11489,7 +11489,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12017,7 +12017,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12533,7 +12533,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13042,7 +13042,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13550,7 +13550,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14073,7 +14073,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14590,7 +14590,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15107,7 +15107,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15633,7 +15633,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16161,7 +16161,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16677,7 +16677,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter1_2_innodb.result b/mysql-test/suite/parts/r/partition_alter1_2_innodb.result index b25ed98c355..f1a1aeecb66 100644 --- a/mysql-test/suite/parts/r/partition_alter1_2_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter1_2_innodb.result @@ -478,7 +478,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -918,7 +918,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1373,7 +1373,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1822,7 +1822,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2271,7 +2271,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2729,7 +2729,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3189,7 +3189,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3637,7 +3637,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4078,7 +4078,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4518,7 +4518,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4973,7 +4973,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5422,7 +5422,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5871,7 +5871,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6329,7 +6329,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6789,7 +6789,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7237,7 +7237,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7694,7 +7694,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8150,7 +8150,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8621,7 +8621,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9086,7 +9086,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9551,7 +9551,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10025,7 +10025,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10501,7 +10501,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10965,7 +10965,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11410,7 +11410,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11850,7 +11850,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12305,7 +12305,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12754,7 +12754,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13201,7 +13201,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13659,7 +13659,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14119,7 +14119,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14567,7 +14567,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15008,7 +15008,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15448,7 +15448,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15903,7 +15903,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16352,7 +16352,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16799,7 +16799,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17257,7 +17257,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17717,7 +17717,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18165,7 +18165,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18623,7 +18623,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19079,7 +19079,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19550,7 +19550,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20015,7 +20015,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20478,7 +20478,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20952,7 +20952,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21428,7 +21428,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21892,7 +21892,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22349,7 +22349,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22805,7 +22805,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23276,7 +23276,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23741,7 +23741,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24204,7 +24204,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24678,7 +24678,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25154,7 +25154,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25618,7 +25618,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26060,7 +26060,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26500,7 +26500,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26955,7 +26955,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27404,7 +27404,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27851,7 +27851,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28309,7 +28309,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28769,7 +28769,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29217,7 +29217,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29658,7 +29658,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30098,7 +30098,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30553,7 +30553,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31002,7 +31002,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31449,7 +31449,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31907,7 +31907,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -32367,7 +32367,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -32815,7 +32815,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -33272,7 +33272,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -33728,7 +33728,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -34199,7 +34199,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -34664,7 +34664,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -35127,7 +35127,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -35601,7 +35601,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -36077,7 +36077,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -36541,7 +36541,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter2_1_1_innodb.result b/mysql-test/suite/parts/r/partition_alter2_1_1_innodb.result index 1b08b2f74fd..314044044bb 100644 --- a/mysql-test/suite/parts/r/partition_alter2_1_1_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter2_1_1_innodb.result @@ -495,7 +495,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -951,7 +951,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1422,7 +1422,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1887,7 +1887,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2352,7 +2352,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2826,7 +2826,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3302,7 +3302,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3766,7 +3766,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4260,7 +4260,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4752,7 +4752,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5259,7 +5259,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5760,7 +5760,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6261,7 +6261,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6771,7 +6771,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7283,7 +7283,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7783,7 +7783,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8276,7 +8276,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8768,7 +8768,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9275,7 +9275,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9776,7 +9776,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10277,7 +10277,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10787,7 +10787,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11299,7 +11299,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11799,7 +11799,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12309,7 +12309,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12817,7 +12817,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13340,7 +13340,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13857,7 +13857,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14374,7 +14374,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14900,7 +14900,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15428,7 +15428,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15944,7 +15944,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16453,7 +16453,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16961,7 +16961,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17484,7 +17484,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18001,7 +18001,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18518,7 +18518,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19044,7 +19044,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19572,7 +19572,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20088,7 +20088,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter2_1_2_innodb.result b/mysql-test/suite/parts/r/partition_alter2_1_2_innodb.result index b69fcee1b1f..e824cf45ce9 100644 --- a/mysql-test/suite/parts/r/partition_alter2_1_2_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter2_1_2_innodb.result @@ -491,7 +491,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -947,7 +947,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1418,7 +1418,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1883,7 +1883,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2346,7 +2346,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2820,7 +2820,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3296,7 +3296,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3760,7 +3760,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4254,7 +4254,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4746,7 +4746,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5253,7 +5253,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5754,7 +5754,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6253,7 +6253,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6763,7 +6763,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7275,7 +7275,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7775,7 +7775,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8268,7 +8268,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8760,7 +8760,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9267,7 +9267,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9768,7 +9768,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10267,7 +10267,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10777,7 +10777,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11289,7 +11289,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11789,7 +11789,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12299,7 +12299,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12807,7 +12807,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13330,7 +13330,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13847,7 +13847,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14362,7 +14362,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14888,7 +14888,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15416,7 +15416,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15932,7 +15932,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16441,7 +16441,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16949,7 +16949,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17472,7 +17472,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17989,7 +17989,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18504,7 +18504,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19030,7 +19030,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19558,7 +19558,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20074,7 +20074,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter2_2_1_innodb.result b/mysql-test/suite/parts/r/partition_alter2_2_1_innodb.result index 1ff53af9111..faba21b41f7 100644 --- a/mysql-test/suite/parts/r/partition_alter2_2_1_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter2_2_1_innodb.result @@ -497,7 +497,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -955,7 +955,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1428,7 +1428,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1893,7 +1893,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2360,7 +2360,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2834,7 +2834,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3312,7 +3312,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3778,7 +3778,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4273,7 +4273,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4767,7 +4767,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5276,7 +5276,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5777,7 +5777,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6280,7 +6280,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6790,7 +6790,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7304,7 +7304,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7806,7 +7806,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8301,7 +8301,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8795,7 +8795,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9304,7 +9304,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9805,7 +9805,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10308,7 +10308,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10818,7 +10818,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11332,7 +11332,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11834,7 +11834,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12346,7 +12346,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12856,7 +12856,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13381,7 +13381,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13898,7 +13898,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14417,7 +14417,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14943,7 +14943,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15473,7 +15473,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15991,7 +15991,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16502,7 +16502,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17012,7 +17012,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17537,7 +17537,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18054,7 +18054,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18573,7 +18573,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19099,7 +19099,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19629,7 +19629,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20147,7 +20147,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter2_2_2_innodb.result b/mysql-test/suite/parts/r/partition_alter2_2_2_innodb.result index 1859859b24f..2557cd5a219 100644 --- a/mysql-test/suite/parts/r/partition_alter2_2_2_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter2_2_2_innodb.result @@ -493,7 +493,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -952,7 +952,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1426,7 +1426,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1896,7 +1896,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2364,7 +2364,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2843,7 +2843,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3322,7 +3322,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3789,7 +3789,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4286,7 +4286,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4781,7 +4781,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5291,7 +5291,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5797,7 +5797,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6301,7 +6301,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6816,7 +6816,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7331,7 +7331,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7834,7 +7834,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8330,7 +8330,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8825,7 +8825,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9335,7 +9335,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9841,7 +9841,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10345,7 +10345,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10860,7 +10860,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11375,7 +11375,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11878,7 +11878,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12391,7 +12391,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12902,7 +12902,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13428,7 +13428,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13950,7 +13950,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14470,7 +14470,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15001,7 +15001,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15532,7 +15532,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16051,7 +16051,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16563,7 +16563,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17074,7 +17074,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17600,7 +17600,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18122,7 +18122,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18642,7 +18642,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19173,7 +19173,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19704,7 +19704,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20223,7 +20223,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_alter4_innodb.result b/mysql-test/suite/parts/r/partition_alter4_innodb.result index b0f340664b7..46f3ed3c974 100644 --- a/mysql-test/suite/parts/r/partition_alter4_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter4_innodb.result @@ -497,7 +497,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -959,7 +959,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1432,7 +1432,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1899,7 +1899,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2366,7 +2366,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2842,7 +2842,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3320,7 +3320,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3786,7 +3786,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4247,7 +4247,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4709,7 +4709,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5182,7 +5182,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5649,7 +5649,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6116,7 +6116,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6592,7 +6592,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7070,7 +7070,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7536,7 +7536,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7997,7 +7997,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8459,7 +8459,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8932,7 +8932,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9399,7 +9399,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9866,7 +9866,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10342,7 +10342,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10820,7 +10820,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11286,7 +11286,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11747,7 +11747,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12209,7 +12209,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12682,7 +12682,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13149,7 +13149,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13616,7 +13616,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14092,7 +14092,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14570,7 +14570,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15036,7 +15036,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15497,7 +15497,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15959,7 +15959,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16432,7 +16432,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16899,7 +16899,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17366,7 +17366,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17842,7 +17842,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18320,7 +18320,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18786,7 +18786,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19250,7 +19250,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19712,7 +19712,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20185,7 +20185,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20652,7 +20652,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21119,7 +21119,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21595,7 +21595,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22073,7 +22073,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22539,7 +22539,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23000,7 +23000,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23462,7 +23462,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23935,7 +23935,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24402,7 +24402,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24869,7 +24869,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25345,7 +25345,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25823,7 +25823,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26289,7 +26289,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26750,7 +26750,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27212,7 +27212,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27685,7 +27685,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28152,7 +28152,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28619,7 +28619,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29095,7 +29095,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29573,7 +29573,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30039,7 +30039,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30500,7 +30500,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30962,7 +30962,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31435,7 +31435,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31902,7 +31902,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -32369,7 +32369,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -32845,7 +32845,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -33323,7 +33323,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -33789,7 +33789,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -34250,7 +34250,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -34712,7 +34712,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -35185,7 +35185,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -35652,7 +35652,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -36119,7 +36119,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -36595,7 +36595,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -37073,7 +37073,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -37539,7 +37539,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -38004,7 +38004,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -38467,7 +38467,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -38941,7 +38941,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -39409,7 +39409,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -39877,7 +39877,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -40354,7 +40354,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -40833,7 +40833,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -41300,7 +41300,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -41762,7 +41762,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -42225,7 +42225,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -42699,7 +42699,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -43167,7 +43167,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -43635,7 +43635,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -44112,7 +44112,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -44591,7 +44591,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -45058,7 +45058,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -45519,7 +45519,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -45981,7 +45981,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -46454,7 +46454,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -46921,7 +46921,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -47388,7 +47388,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -47864,7 +47864,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -48342,7 +48342,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -48808,7 +48808,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -49269,7 +49269,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -49731,7 +49731,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -50204,7 +50204,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -50671,7 +50671,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -51138,7 +51138,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -51614,7 +51614,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -52092,7 +52092,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -52558,7 +52558,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -53020,7 +53020,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -53483,7 +53483,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -53957,7 +53957,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -54425,7 +54425,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -54893,7 +54893,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -55370,7 +55370,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -55849,7 +55849,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -56316,7 +56316,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -56778,7 +56778,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -57238,7 +57238,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -57709,7 +57709,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -58174,7 +58174,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -58639,7 +58639,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -59113,7 +59113,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -59589,7 +59589,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -60053,7 +60053,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -60512,7 +60512,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -60972,7 +60972,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -61443,7 +61443,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -61908,7 +61908,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -62373,7 +62373,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -62847,7 +62847,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -63323,7 +63323,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -63787,7 +63787,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -64566,7 +64566,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -65026,7 +65026,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -65497,7 +65497,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -65962,7 +65962,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -66427,7 +66427,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -66901,7 +66901,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -67377,7 +67377,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -67841,7 +67841,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -67868,7 +67868,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -68305,7 +68305,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -68327,7 +68327,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -68767,7 +68767,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -68797,7 +68797,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -69240,7 +69240,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -69268,7 +69268,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -69707,7 +69707,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -69733,7 +69733,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -70174,7 +70174,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -70204,7 +70204,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -70650,7 +70650,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -70680,7 +70680,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -71128,7 +71128,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -71154,7 +71154,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -71594,7 +71594,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -71618,7 +71618,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -72055,7 +72055,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -72077,7 +72077,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -72517,7 +72517,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -72547,7 +72547,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -72990,7 +72990,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -73018,7 +73018,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -73457,7 +73457,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -73483,7 +73483,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -73924,7 +73924,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -73954,7 +73954,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -74400,7 +74400,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -74430,7 +74430,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -74878,7 +74878,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -74904,7 +74904,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION part_1,part_2; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -75344,7 +75344,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -75805,7 +75805,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -76267,7 +76267,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -76740,7 +76740,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -77207,7 +77207,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -77674,7 +77674,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -78150,7 +78150,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -78628,7 +78628,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -79094,7 +79094,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -79555,7 +79555,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -80017,7 +80017,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -80490,7 +80490,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -80957,7 +80957,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -81424,7 +81424,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -81900,7 +81900,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -82378,7 +82378,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -82844,7 +82844,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -82868,7 +82868,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -83305,7 +83305,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -83327,7 +83327,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -83767,7 +83767,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -83797,7 +83797,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -84240,7 +84240,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -84268,7 +84268,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -84707,7 +84707,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -84733,7 +84733,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -85174,7 +85174,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -85204,7 +85204,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -85650,7 +85650,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -85680,7 +85680,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -86128,7 +86128,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -86154,7 +86154,7 @@ SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; ALTER TABLE t1 REPAIR PARTITION ALL; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; @@ -86594,7 +86594,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_basic_innodb.result b/mysql-test/suite/parts/r/partition_basic_innodb.result index 21c5d70e6e3..ea5a53fc5f4 100644 --- a/mysql-test/suite/parts/r/partition_basic_innodb.result +++ b/mysql-test/suite/parts/r/partition_basic_innodb.result @@ -498,7 +498,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -953,7 +953,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1423,7 +1423,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1887,7 +1887,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2351,7 +2351,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2824,7 +2824,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3303,7 +3303,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3766,7 +3766,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4223,7 +4223,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4678,7 +4678,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5148,7 +5148,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5612,7 +5612,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6074,7 +6074,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -6547,7 +6547,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7022,7 +7022,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7485,7 +7485,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -7983,7 +7983,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8475,7 +8475,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -8982,7 +8982,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9483,7 +9483,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -9984,7 +9984,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -10494,7 +10494,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11010,7 +11010,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -11510,7 +11510,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12003,7 +12003,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -12495,7 +12495,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13002,7 +13002,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -13503,7 +13503,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14004,7 +14004,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -14514,7 +14514,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15030,7 +15030,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -15530,7 +15530,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16039,7 +16039,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -16547,7 +16547,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17070,7 +17070,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -17587,7 +17587,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18104,7 +18104,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -18630,7 +18630,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19162,7 +19162,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -19678,7 +19678,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20176,7 +20176,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -20668,7 +20668,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21175,7 +21175,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -21676,7 +21676,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22175,7 +22175,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -22685,7 +22685,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23197,7 +23197,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -23697,7 +23697,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24190,7 +24190,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -24682,7 +24682,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25189,7 +25189,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -25690,7 +25690,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26189,7 +26189,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -26699,7 +26699,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27211,7 +27211,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -27711,7 +27711,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28220,7 +28220,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -28728,7 +28728,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29251,7 +29251,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -29768,7 +29768,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30283,7 +30283,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -30809,7 +30809,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31337,7 +31337,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -31853,7 +31853,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/r/partition_engine_innodb.result b/mysql-test/suite/parts/r/partition_engine_innodb.result index c033ea36351..5335983b560 100644 --- a/mysql-test/suite/parts/r/partition_engine_innodb.result +++ b/mysql-test/suite/parts/r/partition_engine_innodb.result @@ -489,7 +489,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -947,7 +947,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1409,7 +1409,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -1934,7 +1934,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2435,7 +2435,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -2897,7 +2897,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3356,7 +3356,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -3818,7 +3818,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4283,7 +4283,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -4737,7 +4737,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; @@ -5192,7 +5192,7 @@ test.t1 optimize status OK # check layout success: 1 REPAIR TABLE t1 EXTENDED; Table Op Msg_type Msg_text -test.t1 repair note The storage engine for the table doesn't support repair +test.t1 repair status OK # check layout success: 1 TRUNCATE t1; diff --git a/mysql-test/suite/parts/t/partition_basic_innodb.test b/mysql-test/suite/parts/t/partition_basic_innodb.test index 8240257f087..398f62dab28 100644 --- a/mysql-test/suite/parts/t/partition_basic_innodb.test +++ b/mysql-test/suite/parts/t/partition_basic_innodb.test @@ -22,7 +22,7 @@ # any of the variables. # ---source include/long_test.inc +--source include/big_test.inc #------------------------------------------------------------------------------# # General not engine specific settings and requirements diff --git a/mysql-test/suite/perfschema/r/digest_table_full.result b/mysql-test/suite/perfschema/r/digest_table_full.result index d595d736fa1..695c600842c 100644 --- a/mysql-test/suite/perfschema/r/digest_table_full.result +++ b/mysql-test/suite/perfschema/r/digest_table_full.result @@ -76,7 +76,7 @@ SELECT DIGEST, DIGEST_TEXT, COUNT_STAR, SUM_ROWS_AFFECTED, SUM_WARNINGS, SUM_ERRORS FROM performance_schema.events_statements_summary_by_digest; DIGEST DIGEST_TEXT COUNT_STAR SUM_ROWS_AFFECTED SUM_WARNINGS SUM_ERRORS NULL NULL 29 21 1 2 -3225531460dd440befd77236e5120ed8 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0 +025af09b416617ee444962d35913c0ab TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0 SHOW VARIABLES LIKE "performance_schema_digests_size"; Variable_name Value performance_schema_digests_size 2 diff --git a/mysql-test/suite/perfschema/r/statement_digest.result b/mysql-test/suite/perfschema/r/statement_digest.result index d57c6e065a7..628775781e6 100644 --- a/mysql-test/suite/perfschema/r/statement_digest.result +++ b/mysql-test/suite/perfschema/r/statement_digest.result @@ -75,28 +75,28 @@ Warning 1265 Data truncated for column 'c' at row 1 SELECT DIGEST, DIGEST_TEXT, COUNT_STAR, SUM_ROWS_AFFECTED, SUM_WARNINGS, SUM_ERRORS FROM performance_schema.events_statements_summary_by_digest; DIGEST DIGEST_TEXT COUNT_STAR SUM_ROWS_AFFECTED SUM_WARNINGS SUM_ERRORS -3225531460dd440befd77236e5120ed8 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0 -ee68ed554a5635c7150bf4145bf7b407 SELECT ? FROM t1 1 0 0 0 -df8387c347acdee7c6921a9f4d6dd4c3 SELECT ? FROM `t1` 1 0 0 0 -315c9ba9f900acbd481c410f8682a177 SELECT ?, ... FROM t1 2 0 0 0 -690e9ae778d8139380037b23982a2751 SELECT ? FROM t2 1 0 0 0 -11a7796987200437c70b279b724de1c5 SELECT ?, ... FROM t2 2 0 0 0 -6cf57914c95f7c1b7002add9dfba500a INSERT INTO t1 VALUES (?) 1 1 0 0 -b1d63656e88d49ad8f35cde60ed237ac INSERT INTO t2 VALUES (?) 1 1 0 0 -c9ef4f55c1b2d510c45b06a957b03528 INSERT INTO t3 VALUES (...) 1 1 0 0 -1ca36bb6072d28969691835393f05613 INSERT INTO t4 VALUES (...) 1 1 0 0 -0e34bd5feaa44dcac28546af0b44d483 INSERT INTO t5 VALUES (...) 1 1 0 0 -4b4847b65054d2a7e0bfd628f5c4c1f8 INSERT INTO t1 VALUES (?) /* , ... */ 2 7 0 0 -a3864a3b53830547b589fc1e645ae9e0 INSERT INTO t3 VALUES (...) /* , ... */ 1 3 0 0 -531decf5f8240256654fc7833c79d25d INSERT INTO t5 VALUES (...) /* , ... */ 1 3 0 0 -8f4b0e89ea4a410f4681ea667496292d SELECT ? + ? 3 0 0 0 -2cfaf59d6b5a2bdd331188ed37fd8d91 SELECT ? 1 0 0 0 -85d2000611635c9cbffba908d1fd0ae9 CREATE SCHEMA statements_digest_temp 2 2 0 0 -a33623d6bc003da1a327b8ae10456f84 DROP SCHEMA statements_digest_temp 2 0 0 0 -ff47f3960b7118240c57d8646d016d7f SELECT ? FROM t11 1 0 0 1 -c728d9b6c1b79b9dac451c685899cb59 CREATE TABLE t11 ( c CHARACTER (?) ) 2 0 0 1 -34e7c0331037e3bf580d4a35005fca34 INSERT INTO t11 VALUES (?) 1 1 1 0 -e527c909da8f650bee03c420345342dc SHOW WARNINGS 1 0 0 0 +025af09b416617ee444962d35913c0ab TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0 +2448fef9bf02af329f4379caa8311a29 SELECT ? FROM t1 1 0 0 0 +8ffffc32710da95472a3eae27f5a4138 SELECT ? FROM `t1` 1 0 0 0 +0fb24bb23dd5e0781c8be24d072a4e0d SELECT ?, ... FROM t1 2 0 0 0 +bfb5a2acdbc5fce89461e691841090d8 SELECT ? FROM t2 1 0 0 0 +320290df27bd6c85764c3d9293087f6d SELECT ?, ... FROM t2 2 0 0 0 +e71851702cece9c252fe03e12e065471 INSERT INTO t1 VALUES (?) 1 1 0 0 +2bfe58b981242b825ff30e0a23610c01 INSERT INTO t2 VALUES (?) 1 1 0 0 +7dffbc5052092965f9d2739569afbb89 INSERT INTO t3 VALUES (...) 1 1 0 0 +22d4d66694b4eaffa0b2037d9312aae0 INSERT INTO t4 VALUES (...) 1 1 0 0 +d8b582fde31cf51cd5d0ee4e565c5eee INSERT INTO t5 VALUES (...) 1 1 0 0 +c45c72afb3fbdbec45f98072a4ecf6f5 INSERT INTO t1 VALUES (?) /* , ... */ 2 7 0 0 +9a49ff059861b8b0fac613a205c80fcd INSERT INTO t3 VALUES (...) /* , ... */ 1 3 0 0 +bb9851b80e774365eadd37ae7e6efb7f INSERT INTO t5 VALUES (...) /* , ... */ 1 3 0 0 +f130568315c6ad1d3e9804f1877b5f1e SELECT ? + ? 3 0 0 0 +6de2f55944526286ad0a812d0c546851 SELECT ? 1 0 0 0 +00c7b29a063ecaa8b0986db7fb2226a8 CREATE SCHEMA statements_digest_temp 2 2 0 0 +ab15c731548dc40ff43f9bff0ad94c80 DROP SCHEMA statements_digest_temp 2 0 0 0 +42f722a57efba27876a0124a5be1ab5b SELECT ? FROM t11 1 0 0 1 +d98c529e915c29f2244a14921a990335 CREATE TABLE t11 ( c CHARACTER (?) ) 2 0 0 1 +dc1241f077d462bb4d6d096b0e7b2b1a INSERT INTO t11 VALUES (?) 1 1 1 0 +043fc5cdadb7f0300fc8e9c83d768f13 SHOW WARNINGS 1 0 0 0 #################################### # CLEANUP #################################### diff --git a/mysql-test/suite/perfschema/r/statement_digest_consumers.result b/mysql-test/suite/perfschema/r/statement_digest_consumers.result index 30a72b39f8c..3b96736ba17 100644 --- a/mysql-test/suite/perfschema/r/statement_digest_consumers.result +++ b/mysql-test/suite/perfschema/r/statement_digest_consumers.result @@ -88,28 +88,28 @@ Warning 1265 Data truncated for column 'c' at row 1 #################################### SELECT digest, digest_text, count_star FROM performance_schema.events_statements_summary_by_digest; digest digest_text count_star -3225531460dd440befd77236e5120ed8 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 -ee68ed554a5635c7150bf4145bf7b407 SELECT ? FROM t1 1 -df8387c347acdee7c6921a9f4d6dd4c3 SELECT ? FROM `t1` 1 -315c9ba9f900acbd481c410f8682a177 SELECT ?, ... FROM t1 2 -690e9ae778d8139380037b23982a2751 SELECT ? FROM t2 1 -11a7796987200437c70b279b724de1c5 SELECT ?, ... FROM t2 2 -6cf57914c95f7c1b7002add9dfba500a INSERT INTO t1 VALUES (?) 1 -b1d63656e88d49ad8f35cde60ed237ac INSERT INTO t2 VALUES (?) 1 -c9ef4f55c1b2d510c45b06a957b03528 INSERT INTO t3 VALUES (...) 1 -1ca36bb6072d28969691835393f05613 INSERT INTO t4 VALUES (...) 1 -0e34bd5feaa44dcac28546af0b44d483 INSERT INTO t5 VALUES (...) 1 -4b4847b65054d2a7e0bfd628f5c4c1f8 INSERT INTO t1 VALUES (?) /* , ... */ 2 -a3864a3b53830547b589fc1e645ae9e0 INSERT INTO t3 VALUES (...) /* , ... */ 1 -531decf5f8240256654fc7833c79d25d INSERT INTO t5 VALUES (...) /* , ... */ 1 -8f4b0e89ea4a410f4681ea667496292d SELECT ? + ? 3 -2cfaf59d6b5a2bdd331188ed37fd8d91 SELECT ? 1 -85d2000611635c9cbffba908d1fd0ae9 CREATE SCHEMA statements_digest_temp 2 -a33623d6bc003da1a327b8ae10456f84 DROP SCHEMA statements_digest_temp 2 -ff47f3960b7118240c57d8646d016d7f SELECT ? FROM t11 1 -c728d9b6c1b79b9dac451c685899cb59 CREATE TABLE t11 ( c CHARACTER (?) ) 2 -34e7c0331037e3bf580d4a35005fca34 INSERT INTO t11 VALUES (?) 1 -e527c909da8f650bee03c420345342dc SHOW WARNINGS 1 +025af09b416617ee444962d35913c0ab TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 +2448fef9bf02af329f4379caa8311a29 SELECT ? FROM t1 1 +8ffffc32710da95472a3eae27f5a4138 SELECT ? FROM `t1` 1 +0fb24bb23dd5e0781c8be24d072a4e0d SELECT ?, ... FROM t1 2 +bfb5a2acdbc5fce89461e691841090d8 SELECT ? FROM t2 1 +320290df27bd6c85764c3d9293087f6d SELECT ?, ... FROM t2 2 +e71851702cece9c252fe03e12e065471 INSERT INTO t1 VALUES (?) 1 +2bfe58b981242b825ff30e0a23610c01 INSERT INTO t2 VALUES (?) 1 +7dffbc5052092965f9d2739569afbb89 INSERT INTO t3 VALUES (...) 1 +22d4d66694b4eaffa0b2037d9312aae0 INSERT INTO t4 VALUES (...) 1 +d8b582fde31cf51cd5d0ee4e565c5eee INSERT INTO t5 VALUES (...) 1 +c45c72afb3fbdbec45f98072a4ecf6f5 INSERT INTO t1 VALUES (?) /* , ... */ 2 +9a49ff059861b8b0fac613a205c80fcd INSERT INTO t3 VALUES (...) /* , ... */ 1 +bb9851b80e774365eadd37ae7e6efb7f INSERT INTO t5 VALUES (...) /* , ... */ 1 +f130568315c6ad1d3e9804f1877b5f1e SELECT ? + ? 3 +6de2f55944526286ad0a812d0c546851 SELECT ? 1 +00c7b29a063ecaa8b0986db7fb2226a8 CREATE SCHEMA statements_digest_temp 2 +ab15c731548dc40ff43f9bff0ad94c80 DROP SCHEMA statements_digest_temp 2 +42f722a57efba27876a0124a5be1ab5b SELECT ? FROM t11 1 +d98c529e915c29f2244a14921a990335 CREATE TABLE t11 ( c CHARACTER (?) ) 2 +dc1241f077d462bb4d6d096b0e7b2b1a INSERT INTO t11 VALUES (?) 1 +043fc5cdadb7f0300fc8e9c83d768f13 SHOW WARNINGS 1 SELECT digest, digest_text FROM performance_schema.events_statements_current; digest digest_text #################################### diff --git a/mysql-test/suite/perfschema/r/statement_digest_long_query.result b/mysql-test/suite/perfschema/r/statement_digest_long_query.result index 8e134ef2e6c..a7c28822185 100644 --- a/mysql-test/suite/perfschema/r/statement_digest_long_query.result +++ b/mysql-test/suite/perfschema/r/statement_digest_long_query.result @@ -8,5 +8,5 @@ SELECT 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 #################################### SELECT digest, digest_text, count_star FROM events_statements_summary_by_digest; digest digest_text count_star -0eaad5973ec42fa6663598cbe4db6536 TRUNCATE TABLE events_statements_summary_by_digest 1 -f17895a2b6f270dbd4dc21b313d7f647 SELECT ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... 1 +5c6b2b48a2a39d5dce7ab6ff18ba12d7 TRUNCATE TABLE events_statements_summary_by_digest 1 +3eec87a1ca63856db1629def2300543e SELECT ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... 1 diff --git a/mysql-test/suite/plugins/r/audit_null.result b/mysql-test/suite/plugins/r/audit_null.result index 2b1b64a9d85..81d047c077b 100644 --- a/mysql-test/suite/plugins/r/audit_null.result +++ b/mysql-test/suite/plugins/r/audit_null.result @@ -1,5 +1,6 @@ set @old_global_general_log=@@global.general_log; set global general_log=OFF; +grant select on *.* to testuser@localhost; install plugin audit_null soname 'adt_null'; select 1; 1 @@ -9,8 +10,8 @@ ERROR 42S22: Unknown column 'foobar' in 'field list' show status like 'audit_null%'; Variable_name Value Audit_null_called 9 -Audit_null_general_log 3 Audit_null_general_error 1 +Audit_null_general_log 3 Audit_null_general_result 2 create procedure au1(x char(16)) select concat("test1", x); call au1("-12"); @@ -18,12 +19,88 @@ concat("test1", x) test1-12 show status like 'audit_null%'; Variable_name Value -Audit_null_called 19 -Audit_null_general_log 7 +Audit_null_called 21 Audit_null_general_error 1 +Audit_null_general_log 7 Audit_null_general_result 5 +create table t1 (a int); +insert t1 values (1), (2); +select * from t1; +a +1 +2 +rename table t1 to t2; +alter table t2 add column b int; +create definer=testuser@localhost view v1 as select t2.a+1, t2_copy.a+2 from t2, t2 as t2_copy; +select * from v1; +t2.a+1 t2_copy.a+2 +2 3 +3 3 +2 4 +3 4 +drop view v1; +create temporary table t2 (a date); +insert t2 values ('2020-10-09'); +select * from t2; +a +2020-10-09 +drop table t2; +explain select distinct * from t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using temporary +select distinct * from t2; +a b +1 NULL +2 NULL +drop table t2; uninstall plugin audit_null; Warnings: Warning 1620 Plugin is busy and will be uninstalled on shutdown drop procedure au1; +drop user testuser@localhost; set global general_log=@old_global_general_log; +root[root] @ localhost [] >> select 1 +root[root] @ localhost [] >> select foobar +root[root] @ localhost [] >> show status like 'audit_null%' +root[root] @ localhost [] >> create procedure au1(x char(16)) select concat("test1", x) +root[root] @ localhost [] mysql.proc : write +root[root] @ localhost [] >> call au1("-12") +root[root] @ localhost [] mysql.proc : read +root[root] @ localhost [] >> select concat("test1", NAME_CONST('x',_latin1'-12' COLLATE 'latin1_swedish_ci')) +root[root] @ localhost [] >> show status like 'audit_null%' +root[root] @ localhost [] >> create table t1 (a int) +root[root] @ localhost [] test.t1 : create +root[root] @ localhost [] >> insert t1 values (1), (2) +root[root] @ localhost [] test.t1 : write +root[root] @ localhost [] >> select * from t1 +root[root] @ localhost [] test.t1 : read +root[root] @ localhost [] >> rename table t1 to t2 +root[root] @ localhost [] test.t1 : rename to test.t2 +root[root] @ localhost [] mysql.table_stats : write +root[root] @ localhost [] mysql.column_stats : write +root[root] @ localhost [] mysql.index_stats : write +root[root] @ localhost [] >> alter table t2 add column b int +root[root] @ localhost [] test.t2 : alter +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] >> create definer=testuser@localhost view v1 as select t2.a+1, t2_copy.a+2 from t2, t2 as t2_copy +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] >> select * from v1 +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] >> drop view v1 +root[root] @ localhost [] >> create temporary table t2 (a date) +root[root] @ localhost [] >> insert t2 values ('2020-10-09') +root[root] @ localhost [] >> select * from t2 +root[root] @ localhost [] >> drop table t2 +root[root] @ localhost [] >> explain select distinct * from t2 +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] >> select distinct * from t2 +root[root] @ localhost [] test.t2 : read +root[root] @ localhost [] >> drop table t2 +root[root] @ localhost [] mysql.table_stats : write +root[root] @ localhost [] mysql.column_stats : write +root[root] @ localhost [] mysql.index_stats : write +root[root] @ localhost [] test.t2 : drop +root[root] @ localhost [] >> uninstall plugin audit_null +root[root] @ localhost [] mysql.plugin : write diff --git a/mysql-test/suite/plugins/r/qc_info.result b/mysql-test/suite/plugins/r/qc_info.result index 3e967d55f43..ab646d74511 100644 --- a/mysql-test/suite/plugins/r/qc_info.result +++ b/mysql-test/suite/plugins/r/qc_info.result @@ -12,4 +12,7 @@ test select * from t1 1 512 drop table t1; select statement_schema, statement_text, result_blocks_count, result_blocks_size from information_schema.query_cache_info; statement_schema statement_text result_blocks_count result_blocks_size +set global query_cache_size = 0; +select * from information_schema.query_cache_info; +STATEMENT_SCHEMA STATEMENT_TEXT RESULT_BLOCKS_COUNT RESULT_BLOCKS_SIZE RESULT_BLOCKS_SIZE_USED set global query_cache_size= default; diff --git a/mysql-test/suite/plugins/r/show_all_plugins.result b/mysql-test/suite/plugins/r/show_all_plugins.result index f9cbbd849e2..d61347a06b6 100644 --- a/mysql-test/suite/plugins/r/show_all_plugins.result +++ b/mysql-test/suite/plugins/r/show_all_plugins.result @@ -4,8 +4,8 @@ Variable_name Value Opened_plugin_libraries 0 select * from information_schema.all_plugins where plugin_library='ha_example.so'; PLUGIN_NAME PLUGIN_VERSION PLUGIN_STATUS PLUGIN_TYPE PLUGIN_TYPE_VERSION PLUGIN_LIBRARY PLUGIN_LIBRARY_VERSION PLUGIN_AUTHOR PLUGIN_DESCRIPTION PLUGIN_LICENSE LOAD_OPTION PLUGIN_MATURITY PLUGIN_AUTH_VERSION -EXAMPLE 0.1 NOT INSTALLED STORAGE ENGINE 100002.0 ha_example.so 1.4 Brian Aker, MySQL AB Example storage engine GPL OFF Experimental 0.1 -UNUSABLE 3.14 NOT INSTALLED DAEMON 100002.0 ha_example.so 1.4 Sergei Golubchik Unusable Daemon GPL OFF Experimental 3.14.15.926 +EXAMPLE 0.1 NOT INSTALLED STORAGE ENGINE 100003.0 ha_example.so 1.5 Brian Aker, MySQL AB Example storage engine GPL OFF Experimental 0.1 +UNUSABLE 3.14 NOT INSTALLED DAEMON 100003.0 ha_example.so 1.5 Sergei Golubchik Unusable Daemon GPL OFF Experimental 3.14.15.926 show status like '%libraries%'; Variable_name Value Opened_plugin_libraries 1 diff --git a/mysql-test/suite/plugins/t/audit_null.test b/mysql-test/suite/plugins/t/audit_null.test index 428fd0c276e..60883bbe4f9 100644 --- a/mysql-test/suite/plugins/t/audit_null.test +++ b/mysql-test/suite/plugins/t/audit_null.test @@ -8,6 +8,8 @@ if (!$ADT_NULL_SO) { set @old_global_general_log=@@global.general_log; set global general_log=OFF; +grant select on *.* to testuser@localhost; + --disable_ps_protocol install plugin audit_null soname 'adt_null'; @@ -22,9 +24,36 @@ call au1("-12"); show status like 'audit_null%'; +create table t1 (a int); +insert t1 values (1), (2); +select * from t1; +rename table t1 to t2; +alter table t2 add column b int; + +create definer=testuser@localhost view v1 as select t2.a+1, t2_copy.a+2 from t2, t2 as t2_copy; +select * from v1; +drop view v1; + +# temp table generates no audit events +create temporary table t2 (a date); +insert t2 values ('2020-10-09'); +select * from t2; +drop table t2; + +# internal temp table generates no audit events +explain select distinct * from t2; +select distinct * from t2; + +drop table t2; + uninstall plugin audit_null; --enable_ps_protocol drop procedure au1; +drop user testuser@localhost; set global general_log=@old_global_general_log; +let $MYSQLD_DATADIR= `SELECT @@datadir`; +--replace_regex /#sql-[0-9a-f_]*/#sql-temporary/ /#sql2-[-0-9a-f_]*/#sql2-temporary/ /::1// /127.0.0.1// +cat_file $MYSQLD_DATADIR/audit_null_tables.log; + diff --git a/mysql-test/suite/plugins/t/qc_info.test b/mysql-test/suite/plugins/t/qc_info.test index fc6c9d5af3a..a081617c524 100644 --- a/mysql-test/suite/plugins/t/qc_info.test +++ b/mysql-test/suite/plugins/t/qc_info.test @@ -4,5 +4,8 @@ drop table t1; # the query was invalidated select statement_schema, statement_text, result_blocks_count, result_blocks_size from information_schema.query_cache_info; +set global query_cache_size = 0; +select * from information_schema.query_cache_info; + set global query_cache_size= default; diff --git a/mysql-test/suite/plugins/t/unix_socket.test b/mysql-test/suite/plugins/t/unix_socket.test index fc2e6c5b3c6..72106fab46d 100644 --- a/mysql-test/suite/plugins/t/unix_socket.test +++ b/mysql-test/suite/plugins/t/unix_socket.test @@ -1,4 +1,7 @@ --source include/not_embedded.inc +# If we run this as root, $USER gets authenticated as the `root' user, and we +# get .result differences from CURRENT_USER(). +--source include/not_as_root.inc if (!$AUTH_SOCKET_SO) { skip No auth_socket plugin; diff --git a/mysql-test/suite/rpl/disabled.def b/mysql-test/suite/rpl/disabled.def index 9eb5f57c7be..f9af9c30f5c 100644 --- a/mysql-test/suite/rpl/disabled.def +++ b/mysql-test/suite/rpl/disabled.def @@ -13,4 +13,3 @@ rpl_row_create_table : Bug#11759274 2010-02-27 andrei failed different way than earlier with bug#45576 rpl_spec_variables : BUG#11755836 2009-10-27 jasonh rpl_spec_variables fails on PB2 hpux rpl_get_master_version_and_clock : Bug#11766137 Jan 05 2011 joro Valgrind warnings rpl_get_master_version_and_clock -rpl_stm_until : BUG#59543 Jan 26 2011 alfranio Replication test from eits suite rpl_row_until times out diff --git a/mysql-test/suite/rpl/r/rpl_charset_sjis.result b/mysql-test/suite/rpl/r/rpl_charset_sjis.result index b31bad28a59..ff6296987f8 100644 --- a/mysql-test/suite/rpl/r/rpl_charset_sjis.result +++ b/mysql-test/suite/rpl/r/rpl_charset_sjis.result @@ -20,4 +20,36 @@ hex(a) 965C drop table t1; drop procedure p1; +# +# Start of 5.5 tests +# +# +# Bug#MDEV-4489 Replication of big5, cp932, gbk, sjis strings makes wrong values on slave +# +--- on master --- +SET NAMES sjis; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0x31),(X'31'),('1'); +PREPARE stmt FROM 'INSERT INTO t1 (a) VALUES (?)'; +SET @a='1'; +EXECUTE stmt USING @a; +DROP PREPARE stmt; +SELECT * FROM t1; +a +49 +1 +1 +1 +--- on slave --- +SELECT * FROM t1; +a +49 +1 +1 +1 +--- on master --- +DROP TABLE t1; +# +# End of 5.5 tests +# include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result b/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result index c51279bf8df..c4878fa3f4b 100644 --- a/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result +++ b/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result @@ -1,6 +1,18 @@ *** Set up circular replication on four servers *** include/rpl_init.inc [topology=1->2->3->4->1] +[connection server_4] +SET auto_increment_increment= 4; +SET auto_increment_offset= 4; +[connection server_3] +SET auto_increment_increment= 4; +SET auto_increment_offset= 3; +[connection server_2] +SET auto_increment_increment= 4; +SET auto_increment_offset= 2; +[connection server_1] +SET auto_increment_increment= 4; +SET auto_increment_offset= 1; *** Preparing data *** CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b VARCHAR(100), c INT NOT NULL, PRIMARY KEY(a)) ENGINE=MyISAM; CREATE TABLE t2 (a INT NOT NULL AUTO_INCREMENT, b VARCHAR(100), c INT NOT NULL, PRIMARY KEY(a)) ENGINE=InnoDB; diff --git a/mysql-test/suite/rpl/r/rpl_gtid_mdev4484.result b/mysql-test/suite/rpl/r/rpl_gtid_mdev4484.result new file mode 100644 index 00000000000..1acce9e65ff --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_gtid_mdev4484.result @@ -0,0 +1,34 @@ +include/master-slave.inc +[connection master] +CREATE TABLE t1 (i int) ENGINE=InnoDB; +*** MDEV-4484, incorrect error handling when entries in gtid_slave_pos not found. *** +TRUNCATE TABLE mysql.gtid_slave_pos; +INSERT INTO t1 VALUES (1); +include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,gtid_slave_pos_simulate_failed_delete"; +include/start_slave.inc +SET sql_log_bin= 0; +CALL mtr.add_suppression("Can't find file"); +SET sql_log_bin= 1; +INSERT INTO t1 VALUES (2); +include/wait_for_slave_sql_error.inc [errno=1942] +STOP SLAVE IO_THREAD; +SELECT domain_id, server_id, seq_no FROM mysql.gtid_slave_pos +ORDER BY domain_id, sub_id DESC LIMIT 1; +domain_id server_id seq_no +0 1 3 +SET GLOBAL debug_dbug= @old_dbug; +include/start_slave.inc +INSERT INTO t1 VALUES (3); +SELECT domain_id, server_id, seq_no FROM mysql.gtid_slave_pos +ORDER BY domain_id, sub_id DESC LIMIT 1; +domain_id server_id seq_no +0 1 4 +SELECT * FROM t1 ORDER BY i; +i +1 +2 +3 +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_gtid_mdev4485.result b/mysql-test/suite/rpl/r/rpl_gtid_mdev4485.result new file mode 100644 index 00000000000..34efd43f81b --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_gtid_mdev4485.result @@ -0,0 +1,15 @@ +include/rpl_init.inc [topology=1->3] +*** MDEV-4485. Master did not allow slave to connect from the very start (empty GTID pos) if GTIDs from other multi_source master was present *** +create table t1 (i int); +create table t2 (i int); +set default_master_connection = 'm2'; +change master to master_host='127.0.0.1', master_port=SERVER_MYPORT_2, master_user='root', master_use_gtid=slave_pos; +include/start_slave.inc +insert into t2 values (1); +drop table t1; +drop table t2; +set default_master_connection = 'm2'; +include/stop_slave.inc +RESET SLAVE ALL; +set default_master_connection = ''; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result b/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result new file mode 100644 index 00000000000..e9f64628e12 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_gtid_reconnect.result @@ -0,0 +1,169 @@ +include/rpl_init.inc [topology=1->2] +include/stop_slave.inc +CHANGE MASTER TO master_use_gtid= current_pos; +include/start_slave.inc +CREATE TABLE t1 (a INT); +FLUSH LOGS; +SET gtid_domain_id=10; +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (3); +INSERT INTO t1 VALUES (4); +INSERT INTO t1 VALUES (5); +include/stop_slave.inc +SELECT * FROM t1 ORDER BY a; +a +1 +2 +3 +4 +5 +include/kill_binlog_dump_threads.inc +INSERT INTO t1 VALUES (10); +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; +include/start_slave.inc +SELECT * FROM t1 ORDER BY a; +a +1 +2 +3 +4 +5 +10 +include/stop_slave.inc +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; +SET gtid_domain_id=10; +SET gtid_seq_no=50; +INSERT INTO t1 VALUES (1); +SET gtid_domain_id=11; +INSERT INTO t1 VALUES (11); +SET gtid_domain_id=10; +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (2); +SET gtid_domain_id=11; +INSERT INTO t1 VALUES (12); +SET gtid_domain_id=10; +INSERT INTO t1 VALUES (3); +SET gtid_domain_id=11; +SET gtid_seq_no=200; +INSERT INTO t1 VALUES (13); +START SLAVE UNTIL master_gtid_pos="10-1-50,11-1-200"; +include/wait_for_slave_to_stop.inc +SELECT * FROM t1 ORDER BY a; +a +1 +11 +12 +13 +include/kill_binlog_dump_threads.inc +INSERT INTO t1 VALUES (20); +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; +include/start_slave.inc +SELECT * FROM t1 ORDER BY a; +a +1 +2 +3 +11 +12 +13 +20 +include/stop_slave.inc +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; +include/kill_binlog_dump_threads.inc +SET gtid_domain_id= 9; +SET gtid_seq_no= 50; +INSERT INTO t1 VALUES (1); +SET gtid_domain_id= 10; +INSERT INTO t1 VALUES (11); +SET gtid_domain_id= 9; +INSERT INTO t1 VALUES (2); +SET gtid_domain_id= 10; +SET gtid_seq_no= 100; +INSERT INTO t1 VALUES (12); +SET gtid_domain_id= 9; +INSERT INTO t1 VALUES (3); +SET gtid_domain_id= 10; +SET gtid_seq_no= 200; +INSERT INTO t1 VALUES (13); +SET gtid_domain_id= 10; +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; +START SLAVE UNTIL master_gtid_pos="9-1-50,10-1-200"; +include/wait_for_slave_to_stop.inc +SELECT * FROM t1 ORDER BY a; +a +1 +11 +12 +13 +SET GLOBAL debug_dbug= @old_debug; +INSERT INTO t1 VALUES (20); +include/start_slave.inc +SELECT * FROM t1 ORDER BY a; +a +1 +2 +3 +11 +12 +13 +20 +*** Test when slave IO thread needs to reconnect in the middle of an event group. *** +include/stop_slave.inc +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; +include/kill_binlog_dump_threads.inc +SET GLOBAL debug_dbug="+d,binlog_force_reconnect_after_22_events"; +CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1); +BEGIN; +INSERT INTO t2 VALUES (10); +INSERT INTO t2 VALUES (11); +COMMIT; +BEGIN; +INSERT INTO t2 VALUES (20); +INSERT INTO t2 VALUES (21); +INSERT INTO t2 VALUES (22); +INSERT INTO t2 VALUES (23); +INSERT INTO t2 VALUES (24); +INSERT INTO t2 VALUES (25); +INSERT INTO t2 VALUES (26); +INSERT INTO t2 VALUES (27); +INSERT INTO t2 VALUES (28); +INSERT INTO t2 VALUES (29); +COMMIT; +include/start_slave.inc +SELECT * FROM t2 ORDER BY a; +a +1 +10 +11 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +SET GLOBAL debug_dbug= @old_debug; +DROP TABLE t1, t2; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result b/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result index dcfdc567736..b524ab17c23 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_stop_start.result @@ -50,5 +50,15 @@ a 3 4 5 +*** Test that @@gtid_slave_pos and @@gtid_current_pos are correctly loaded even if slave threads have not started. *** +SET @slave_pos2= @@GLOBAL.gtid_slave_pos; +SET @current_pos2= @@GLOBAL.gtid_current_pos; +SELECT IF(@slave_pos1=@slave_pos2, "OK", CONCAT(@slave_pos1, " != ", @slave_pos2)); +IF(@slave_pos1=@slave_pos2, "OK", CONCAT(@slave_pos1, " != ", @slave_pos2)) +OK +SELECT IF(@current_pos1=@current_pos2, "OK", CONCAT(@current_pos1, " != ", @current_pos2)); +IF(@current_pos1=@current_pos2, "OK", CONCAT(@current_pos1, " != ", @current_pos2)) +OK +include/start_slave.inc DROP TABLE t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_mdev382.result b/mysql-test/suite/rpl/r/rpl_mdev382.result index 2def74bb6d1..c4995a739db 100644 --- a/mysql-test/suite/rpl/r/rpl_mdev382.result +++ b/mysql-test/suite/rpl/r/rpl_mdev382.result @@ -256,7 +256,7 @@ master-bin.000001 # User var 1 # @`a``3`=9223372036854775807 master-bin.000001 # User var 1 # @`a``4`=18446744073709551615 master-bin.000001 # User var 1 # @`b```=-1.234560123456789e125 master-bin.000001 # User var 1 # @```c`=-1234501234567890123456789012345678901234567890123456789.0123456789 -master-bin.000001 # User var 1 # @```d```=_latin1 0x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 COLLATE latin1_swedish_ci +master-bin.000001 # User var 1 # @```d```=_latin1 X'78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878' COLLATE latin1_swedish_ci master-bin.000001 # Query 1 # use `db1``; select 'oops!'`; INSERT INTO t1 VALUES (@`a``1`+1, @`a``2`*100, @`a``3`-1, @`a``4`-1, @`b```/2, @```c`, substr(@```d```, 2, 98)) master-bin.000001 # Query 1 # COMMIT /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; @@ -292,7 +292,7 @@ SET @`a``3`:=9223372036854775807/*!*/; SET @`a``4`:=18446744073709551615/*!*/; SET @`b```:=-1.2345601234568e+125/*!*/; SET @```c`:=-1234501234567890123456789012345678901234567890123456789.0123456789/*!*/; -SET @```d```:=_latin1 0x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878 COLLATE `latin1_swedish_ci`/*!*/; +SET @```d```:=_latin1 X'78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878' COLLATE `latin1_swedish_ci`/*!*/; SET TIMESTAMP=1000000000/*!*/; INSERT INTO t1 VALUES (@`a``1`+1, @`a``2`*100, @`a``3`-1, @`a``4`-1, @`b```/2, @```c`, substr(@```d```, 2, 98)) /*!*/; diff --git a/mysql-test/suite/rpl/r/rpl_password_boundaries.result b/mysql-test/suite/rpl/r/rpl_password_boundaries.result index 71f32f492a2..a0ccc0ce33c 100644 --- a/mysql-test/suite/rpl/r/rpl_password_boundaries.result +++ b/mysql-test/suite/rpl/r/rpl_password_boundaries.result @@ -24,10 +24,10 @@ set sql_log_bin=1; include/stop_slave.inc change master to master_user='rpl33',master_password='0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef!'; ERROR HY000: String '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345' is too long for MASTER_PASSWORD (should be no longer than 96) -change master to master_user='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; -ERROR HY000: String 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long for MASTER_USER (should be no longer than 47) +change master to master_user='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; +ERROR HY000: String 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long for MASTER_USER (should be no longer than 128) change master to master_host='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'; -ERROR HY000: String 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbb' is too long for MASTER_HOST (should be no longer than 180) +ERROR HY000: String 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbb' is too long for MASTER_HOST (should be no longer than 60) [ on master ] set sql_log_bin=0; grant replication slave on *.* to rpl16cyr@127.0.0.1 identified by 'воттакойужпарольвоттакойужпарольвоттакойужпароль'; diff --git a/mysql-test/suite/rpl/r/rpl_row_until.result b/mysql-test/suite/rpl/r/rpl_row_until.result index 5629f5c8cdd..a09d44227a3 100644 --- a/mysql-test/suite/rpl/r/rpl_row_until.result +++ b/mysql-test/suite/rpl/r/rpl_row_until.result @@ -27,13 +27,6 @@ n 3 4 include/check_slave_param.inc [Exec_Master_Log_Pos] -START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', RELAY_LOG_POS=relay_pos_insert1_t2 -include/wait_for_slave_sql_to_stop.inc -SELECT * FROM t2; -n -1 -2 -include/check_slave_param.inc [Exec_Master_Log_Pos] START SLAVE; include/wait_for_slave_to_start.inc include/stop_slave.inc @@ -51,10 +44,19 @@ START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000009'; ERROR HY000: Incorrect parameter or combination of parameters for START SLAVE UNTIL START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', MASTER_LOG_POS=MASTER_LOG_POS; ERROR HY000: Incorrect parameter or combination of parameters for START SLAVE UNTIL -START SLAVE; START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=MASTER_LOG_POS; -Warnings: -Note 1254 Slave is already running include/stop_slave.inc RESET SLAVE; +include/start_slave.inc +include/rpl_reset.inc +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); +include/stop_slave_sql.inc +INSERT INTO t1 VALUES (2); +INSERT INTO t1 VALUES (3); +include/sync_slave_io_with_master.inc +include/wait_for_slave_sql_to_stop.inc +include/assert.inc [table t1 should have two rows.] +include/start_slave.inc +DROP TABLE t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_sp_effects.result b/mysql-test/suite/rpl/r/rpl_sp_effects.result index a6e3ae03963..413ff41879d 100644 --- a/mysql-test/suite/rpl/r/rpl_sp_effects.result +++ b/mysql-test/suite/rpl/r/rpl_sp_effects.result @@ -273,5 +273,21 @@ drop table t2; drop procedure sp_bug26199; drop function sf_bug26199; SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators; +set names utf8; +CREATE FUNCTION f() RETURNS timestamp DETERMINISTIC +BEGIN RETURN '2012-12-21 12:12:12'; END | +CREATE PROCEDURE p(t timestamp) +BEGIN +SET @t = t; +PREPARE stmt FROM " + UPDATE t1 SET a = @t WHERE '2012-12-31 08:00:00' < f() "; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +END | +create table t1 (a timestamp); +call p('2012-12-31 08:00:00'); +drop table t1; +drop procedure p; +drop function f; end of the tests include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_stm_until.result b/mysql-test/suite/rpl/r/rpl_stm_until.result index 9047825d565..b1cea5227f6 100644 --- a/mysql-test/suite/rpl/r/rpl_stm_until.result +++ b/mysql-test/suite/rpl/r/rpl_stm_until.result @@ -1,6 +1,7 @@ include/master-slave.inc [connection master] include/rpl_reset.inc +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); [on slave] include/stop_slave.inc ==== Create some events on master ==== @@ -34,7 +35,7 @@ n 3 4 include/check_slave_param.inc [Exec_Master_Log_Pos] -start slave until relay_log_file='slave-relay-bin.000004', relay_log_pos=RELAY_LOG_POS; +start slave until relay_log_file='slave-relay-bin.000003', relay_log_pos=RELAY_LOG_POS; include/wait_for_slave_io_to_start.inc include/wait_for_slave_sql_to_stop.inc select * from t2; @@ -94,18 +95,4 @@ one 1 drop table t1; start slave; -include/rpl_reset.inc -flush logs; -drop table if exists t1; -stop slave; -flush logs; -flush logs; -reset slave; -start slave until master_log_file='master-bin.000001', master_log_pos=MASTER_LOG_POS; /* to stop right before DROP */; -include/wait_for_slave_sql_to_stop.inc -show tables /* t1 must exist */; -Tables_in_test -t1 -drop table t1; -stop slave; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/rpl_temporal_mysql56.result b/mysql-test/suite/rpl/r/rpl_temporal_mysql56.result new file mode 100644 index 00000000000..99f81abb166 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_temporal_mysql56.result @@ -0,0 +1,84 @@ +include/master-slave.inc +[connection master] +SET TIME_ZONE='+00:00'; +SET TIME_ZONE='+00:00'; +INSERT INTO mysql56time VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111'); +INSERT INTO mysql56datetime VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +INSERT INTO mysql56timestamp VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +SELECT * FROM mysql56time; +t0 838:59:59 +t1 838:59:59.0 +t2 838:59:59.00 +t3 838:59:59.000 +t4 838:59:59.0000 +t5 838:59:59.00000 +t6 838:59:59.000000 +t0 00:00:00 +t1 00:00:00.0 +t2 00:00:00.00 +t3 00:00:00.000 +t4 00:00:00.0000 +t5 00:00:00.00000 +t6 00:00:00.000000 +t0 -838:59:59 +t1 -838:59:59.0 +t2 -838:59:59.00 +t3 -838:59:59.000 +t4 -838:59:59.0000 +t5 -838:59:59.00000 +t6 -838:59:59.000000 +t0 01:01:01 +t1 01:01:01.1 +t2 01:01:01.11 +t3 01:01:01.111 +t4 01:01:01.1111 +t5 01:01:01.11111 +t6 01:01:01.111111 +SELECT * FROM mysql56datetime; +dt0 0000-00-00 00:00:00 +dt1 0000-00-00 00:00:00.0 +dt2 0000-00-00 00:00:00.00 +dt3 0000-00-00 00:00:00.000 +dt4 0000-00-00 00:00:00.0000 +dt5 0000-00-00 00:00:00.00000 +dt6 0000-00-00 00:00:00.000000 +dt0 9999-12-31 23:59:59 +dt1 9999-12-31 23:59:59.9 +dt2 9999-12-31 23:59:59.99 +dt3 9999-12-31 23:59:59.999 +dt4 9999-12-31 23:59:59.9999 +dt5 9999-12-31 23:59:59.99999 +dt6 9999-12-31 23:59:59.999999 +dt0 2001-01-01 01:01:01 +dt1 2001-01-01 01:01:01.1 +dt2 2001-01-01 01:01:01.11 +dt3 2001-01-01 01:01:01.111 +dt4 2001-01-01 01:01:01.1111 +dt5 2001-01-01 01:01:01.11111 +dt6 2001-01-01 01:01:01.111111 +SELECT * FROM mysql56timestamp; +ts0 1970-01-01 00:00:01 +ts1 1970-01-01 00:00:01.0 +ts2 1970-01-01 00:00:01.00 +ts3 1970-01-01 00:00:01.000 +ts4 1970-01-01 00:00:01.0000 +ts5 1970-01-01 00:00:01.00000 +ts6 1970-01-01 00:00:01.000000 +ts0 2038-01-19 03:14:07 +ts1 2038-01-19 03:14:07.9 +ts2 2038-01-19 03:14:07.99 +ts3 2038-01-19 03:14:07.999 +ts4 2038-01-19 03:14:07.9999 +ts5 2038-01-19 03:14:07.99999 +ts6 2038-01-19 03:14:07.999999 +ts0 2001-01-01 01:01:01 +ts1 2001-01-01 01:01:01.1 +ts2 2001-01-01 01:01:01.11 +ts3 2001-01-01 01:01:01.111 +ts4 2001-01-01 01:01:01.1111 +ts5 2001-01-01 01:01:01.11111 +ts6 2001-01-01 01:01:01.111111 +DROP TABLE mysql56time; +DROP TABLE mysql56datetime; +DROP TABLE mysql56timestamp; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test b/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test index 86ee64b5e73..a97801f9ab0 100644 --- a/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test +++ b/mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test @@ -67,7 +67,9 @@ stop slave; reset slave; # Table was created from binlog, it may not be created if SQL thread is running # slowly and IO thread reaches incident before SQL thread applies it. +--disable_warnings drop table if exists t; +--enable_warnings reset master; --echo End of the tests diff --git a/mysql-test/suite/rpl/t/rpl_charset_sjis.test b/mysql-test/suite/rpl/t/rpl_charset_sjis.test index a3a3de8c1d0..7d3d21cf9a0 100644 --- a/mysql-test/suite/rpl/t/rpl_charset_sjis.test +++ b/mysql-test/suite/rpl/t/rpl_charset_sjis.test @@ -23,4 +23,37 @@ sync_slave_with_master; connection master; # End of 5.0 tests + +--echo # +--echo # Start of 5.5 tests +--echo # + +--echo # +--echo # Bug#MDEV-4489 Replication of big5, cp932, gbk, sjis strings makes wrong values on slave +--echo # + +connection master; +--echo --- on master --- +SET NAMES sjis; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0x31),(X'31'),('1'); +PREPARE stmt FROM 'INSERT INTO t1 (a) VALUES (?)'; +SET @a='1'; +EXECUTE stmt USING @a; +DROP PREPARE stmt; +SELECT * FROM t1; +sync_slave_with_master; +connection slave; +--echo --- on slave --- +SELECT * FROM t1; +connection master; +--echo --- on master --- +DROP TABLE t1; +sync_slave_with_master; +connection master; + +--echo # +--echo # End of 5.5 tests +--echo # + --source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test b/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test index 5f492419ae7..aea43a1c2a1 100644 --- a/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test +++ b/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test @@ -23,6 +23,18 @@ let $keep_connection= 1; --source include/rpl_init.inc --echo +#set auto inc variables at each server +--let $_rpl_server= $rpl_server_count +while ($_rpl_server) +{ + --let $rpl_connection_name= server_$_rpl_server + --source include/rpl_connection.inc + eval SET auto_increment_increment= $rpl_server_count; + eval SET auto_increment_offset= $_rpl_server; + + --dec $_rpl_server +} + # Preparing data. --echo *** Preparing data *** --connection server_1 diff --git a/mysql-test/suite/rpl/t/rpl_gtid_mdev4484.test b/mysql-test/suite/rpl/t/rpl_gtid_mdev4484.test new file mode 100644 index 00000000000..b3ff76c2afe --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_gtid_mdev4484.test @@ -0,0 +1,52 @@ +--source include/master-slave.inc +--source include/have_innodb.inc +--source include/have_debug.inc + +CREATE TABLE t1 (i int) ENGINE=InnoDB; + +--sync_slave_with_master + +--echo *** MDEV-4484, incorrect error handling when entries in gtid_slave_pos not found. *** +TRUNCATE TABLE mysql.gtid_slave_pos; + +--connection master +INSERT INTO t1 VALUES (1); +--sync_slave_with_master + +# Inject an artificial error deleting entries, and check that the error handling code works. +--connection slave +--source include/stop_slave.inc +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,gtid_slave_pos_simulate_failed_delete"; +--source include/start_slave.inc +SET sql_log_bin= 0; +CALL mtr.add_suppression("Can't find file"); +SET sql_log_bin= 1; + +--connection master +INSERT INTO t1 VALUES (2); + +--connection slave +--let $slave_sql_errno= 1942 +--source include/wait_for_slave_sql_error.inc +STOP SLAVE IO_THREAD; +SELECT domain_id, server_id, seq_no FROM mysql.gtid_slave_pos + ORDER BY domain_id, sub_id DESC LIMIT 1; +SET GLOBAL debug_dbug= @old_dbug; +--source include/start_slave.inc + +--connection master +INSERT INTO t1 VALUES (3); +--sync_slave_with_master + +--connection slave +SELECT domain_id, server_id, seq_no FROM mysql.gtid_slave_pos + ORDER BY domain_id, sub_id DESC LIMIT 1; +SELECT * FROM t1 ORDER BY i; + + +# Clean up +--connection master +DROP TABLE t1; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.cnf b/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.cnf new file mode 100644 index 00000000000..fccef215ccc --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.cnf @@ -0,0 +1,18 @@ +!include suite/rpl/rpl_1slave_base.cnf +!include include/default_client.cnf + +[mysqld.1] +log-slave-updates +gtid-domain-id=1 + +[mysqld.2] +log-slave-updates +gtid-domain-id=2 + +[mysqld.3] +log-slave-updates +gtid-domain-id=3 + +[ENV] +SERVER_MYPORT_3= @mysqld.3.port +SERVER_MYSOCK_3= @mysqld.3.socket diff --git a/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.test b/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.test new file mode 100644 index 00000000000..4a0c76d5c1d --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_gtid_mdev4485.test @@ -0,0 +1,40 @@ +--let $rpl_topology= 1->3 +--source include/rpl_init.inc + +--echo *** MDEV-4485. Master did not allow slave to connect from the very start (empty GTID pos) if GTIDs from other multi_source master was present *** + +--connection server_1 +create table t1 (i int); + +--connection server_2 +create table t2 (i int); + +--connection server_3 + +set default_master_connection = 'm2'; +--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2 +eval change master to master_host='127.0.0.1', master_port=$SERVER_MYPORT_2, master_user='root', master_use_gtid=slave_pos; +--source include/start_slave.inc + +--connection server_2 +insert into t2 values (1); +--save_master_pos + +--connection server_3 +--sync_with_master 0,'m2' + +--connection server_1 +drop table t1; + +--connection server_2 +drop table t2; + +--connection server_3 +--sync_with_master 0,'m2' +set default_master_connection = 'm2'; +--source include/stop_slave.inc +RESET SLAVE ALL; +set default_master_connection = ''; + +--connection server_1 +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_gtid_reconnect.test b/mysql-test/suite/rpl/t/rpl_gtid_reconnect.test new file mode 100644 index 00000000000..153a04d8918 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_gtid_reconnect.test @@ -0,0 +1,201 @@ +--let $rpl_topology=1->2 +--source include/rpl_init.inc +--source include/have_innodb.inc +--source include/have_debug.inc + + +--connection server_2 +--source include/stop_slave.inc +CHANGE MASTER TO master_use_gtid= current_pos; +--source include/start_slave.inc + +--connection server_1 +CREATE TABLE t1 (a INT); +FLUSH LOGS; +--save_master_pos + +--connection server_2 +--sync_with_master + + +# Prepare a string of events and have the slave replicate all of it. +--connection server_1 +SET gtid_domain_id=10; +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (3); +INSERT INTO t1 VALUES (4); +INSERT INTO t1 VALUES (5); +--save_master_pos + +--connection server_2 +--sync_with_master +--source include/stop_slave.inc +SELECT * FROM t1 ORDER BY a; + +# Now start the slave again, but force a reconnect. There was a bug that this +# reconnect would cause duplicate events. + +--connection server_1 +# Make sure to get rid of any old binlog dump thread so it does not +# interfere with our DBUG error injection. +--source include/kill_binlog_dump_threads.inc +INSERT INTO t1 VALUES (10); +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 ORDER BY a; + +--source include/stop_slave.inc +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; + +--connection server_1 +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; + +# A1 B1 A2 B2 A3 B3, slave reached A1 and B3 and stopped. Slave starts, +# reconnects at A2. There was a bug that B2 would be duplicated. + +SET gtid_domain_id=10; +SET gtid_seq_no=50; +INSERT INTO t1 VALUES (1); +SET gtid_domain_id=11; +INSERT INTO t1 VALUES (11); +SET gtid_domain_id=10; +SET gtid_seq_no=100; +INSERT INTO t1 VALUES (2); +SET gtid_domain_id=11; +INSERT INTO t1 VALUES (12); +SET gtid_domain_id=10; +INSERT INTO t1 VALUES (3); +SET gtid_domain_id=11; +SET gtid_seq_no=200; +INSERT INTO t1 VALUES (13); + +--connection server_2 +START SLAVE UNTIL master_gtid_pos="10-1-50,11-1-200"; +--source include/wait_for_slave_to_stop.inc +SELECT * FROM t1 ORDER BY a; + +--connection server_1 +--source include/kill_binlog_dump_threads.inc +INSERT INTO t1 VALUES (20); +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t1 ORDER BY a; + +--source include/stop_slave.inc +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; + +--connection server_1 +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; + +# A1 B1 A2 B2 A3 B3. START SLAVE UNTIL A1,B3, gets reconnect at B2. +# There was a bug that the UNTIL would be ignored, and A2 would be lost. + +--source include/kill_binlog_dump_threads.inc +SET gtid_domain_id= 9; +SET gtid_seq_no= 50; +INSERT INTO t1 VALUES (1); +SET gtid_domain_id= 10; +INSERT INTO t1 VALUES (11); +SET gtid_domain_id= 9; +INSERT INTO t1 VALUES (2); +SET gtid_domain_id= 10; +SET gtid_seq_no= 100; +INSERT INTO t1 VALUES (12); +SET gtid_domain_id= 9; +INSERT INTO t1 VALUES (3); +SET gtid_domain_id= 10; +SET gtid_seq_no= 200; +INSERT INTO t1 VALUES (13); +SET gtid_domain_id= 10; + +SET GLOBAL debug_dbug="+d,gtid_force_reconnect_at_10_1_100"; + +--connection server_2 +START SLAVE UNTIL master_gtid_pos="9-1-50,10-1-200"; +--source include/wait_for_slave_to_stop.inc +SELECT * FROM t1 ORDER BY a; + +--connection server_1 +SET GLOBAL debug_dbug= @old_debug; +INSERT INTO t1 VALUES (20); +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +SELECT * FROM t1 ORDER BY a; + + +--echo *** Test when slave IO thread needs to reconnect in the middle of an event group. *** +--connection server_2 +--source include/stop_slave.inc + +TRUNCATE t1; +RESET MASTER; +SET GLOBAL gtid_slave_pos= ""; + +--connection server_1 +SET GLOBAL debug_dbug= @old_debug; +TRUNCATE t1; +RESET MASTER; + +--source include/kill_binlog_dump_threads.inc +SET GLOBAL debug_dbug="+d,binlog_force_reconnect_after_22_events"; + +# 4 events for FD, fake rotate, gtid list, binlog checkpoint. +# 2 events for GTID, create table +CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; +# 3 events for BEGIN/query/COMMIT +INSERT INTO t2 VALUES (1); +# 4 events for BEGIN/query/query/COMMIT +BEGIN; +INSERT INTO t2 VALUES (10); +INSERT INTO t2 VALUES (11); +COMMIT; +# So this event group starts after 4+2+4+3=13 events. Or 16 in row-based. +BEGIN; +INSERT INTO t2 VALUES (20); +INSERT INTO t2 VALUES (21); +INSERT INTO t2 VALUES (22); +INSERT INTO t2 VALUES (23); +INSERT INTO t2 VALUES (24); +INSERT INTO t2 VALUES (25); +INSERT INTO t2 VALUES (26); +INSERT INTO t2 VALUES (27); +INSERT INTO t2 VALUES (28); +INSERT INTO t2 VALUES (29); +COMMIT; +--save_master_pos + +--connection server_2 +--source include/start_slave.inc +--sync_with_master +SELECT * FROM t2 ORDER BY a; + +--connection server_1 +SET GLOBAL debug_dbug= @old_debug; + + +# Clean up. +--connection server_1 +DROP TABLE t1, t2; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_gtid_stop_start.test b/mysql-test/suite/rpl/t/rpl_gtid_stop_start.test index 0833dfe1224..cc1da6b3c85 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_stop_start.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_stop_start.test @@ -93,6 +93,31 @@ INSERT INTO t1 VALUES(5); --source include/wait_condition.inc SELECT * FROM t1 ORDER BY a; +--echo *** Test that @@gtid_slave_pos and @@gtid_current_pos are correctly loaded even if slave threads have not started. *** +--let $slave_pos1= `SELECT @@GLOBAL.gtid_slave_pos` +--let $current_pos1= `SELECT @@GLOBAL.gtid_current_pos` + +--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +wait +EOF +--shutdown_server 30 +--source include/wait_until_disconnected.inc + +--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect +restart: --skip-slave-start=1 --skip-log-bin +EOF +--enable_reconnect +--source include/wait_until_connected_again.inc +--disable_query_log +eval SET @slave_pos1= "$slave_pos1"; +eval SET @current_pos1= "$current_pos1"; +--enable_query_log +SET @slave_pos2= @@GLOBAL.gtid_slave_pos; +SET @current_pos2= @@GLOBAL.gtid_current_pos; +SELECT IF(@slave_pos1=@slave_pos2, "OK", CONCAT(@slave_pos1, " != ", @slave_pos2)); +SELECT IF(@current_pos1=@current_pos2, "OK", CONCAT(@current_pos1, " != ", @current_pos2)); +--source include/start_slave.inc + --connection server_1 DROP TABLE t1; diff --git a/mysql-test/suite/rpl/t/rpl_password_boundaries.test b/mysql-test/suite/rpl/t/rpl_password_boundaries.test index cf8abfbda11..d812ab5efc8 100644 --- a/mysql-test/suite/rpl/t/rpl_password_boundaries.test +++ b/mysql-test/suite/rpl/t/rpl_password_boundaries.test @@ -53,7 +53,7 @@ change master to master_user='rpl33',master_password='0123456789abcdef0123456789 # Check also master_user and master_host --error ER_WRONG_STRING_LENGTH -change master to master_user='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; +change master to master_user='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; --error ER_WRONG_STRING_LENGTH change master to master_host='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'; diff --git a/mysql-test/suite/rpl/t/rpl_row_until.test b/mysql-test/suite/rpl/t/rpl_row_until.test index 182c84f1ee7..97b60a3055f 100644 --- a/mysql-test/suite/rpl/t/rpl_row_until.test +++ b/mysql-test/suite/rpl/t/rpl_row_until.test @@ -2,7 +2,13 @@ -- source include/have_binlog_format_row.inc -- source include/master-slave.inc -# Note: The test is dependent on binlog positions +############################################################################## +# The test is dependent on binlog positions. The test is divided into two +# sections. The first section checks START SLAVE UNTIL MASTER_LOG_FILE = +# 'log_name', MASTER_LOG_POS = log_pos followed by a couple of failure +# scenarios. The second section checks START SLAVE UNTIL RELAY_LOG_FILE = +# 'log_name', RELAY_LOG_POS = log_pos. +############################################################################## # Create some events on master connection master; @@ -24,13 +30,6 @@ CREATE TABLE t2(n INT NOT NULL AUTO_INCREMENT PRIMARY KEY); INSERT INTO t2 VALUES (1),(2); # Save master log position for query INSERT INTO t2 VALUES (1),(2); let $master_pos_insert1_t2= query_get_value(SHOW MASTER STATUS, Position, 1); -sync_slave_with_master; -#show binlog events; - -# Save relay log position for query INSERT INTO t2 VALUES (1),(2); -let $relay_pos_insert1_t2= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1); - -connection master; INSERT INTO t2 VALUES (3),(4); DROP TABLE t2; # Save master log position for query DROP TABLE t2; @@ -71,18 +70,6 @@ SELECT * FROM t1; --let $slave_param_value= $master_pos_drop_t1 --source include/check_slave_param.inc -# Try replicate all up to and not including the second insert to t2; -echo START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', RELAY_LOG_POS=relay_pos_insert1_t2; ---disable_query_log -eval START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', RELAY_LOG_POS=$relay_pos_insert1_t2; ---enable_query_log ---source include/wait_for_slave_sql_to_stop.inc -SELECT * FROM t2; - ---let $slave_param= Exec_Master_Log_Pos ---let $slave_param_value= $master_pos_insert1_t2 ---source include/check_slave_param.inc - # clean up START SLAVE; --source include/wait_for_slave_to_start.inc @@ -118,14 +105,54 @@ START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000009'; --replace_result 561 MASTER_LOG_POS --error 1277 START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', MASTER_LOG_POS=561; -# Warning should be given for second command -START SLAVE; --replace_result 740 MASTER_LOG_POS START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=740; --source include/stop_slave.inc -# Clear slave IO error. RESET SLAVE; +--source include/start_slave.inc ---let $rpl_only_running_threads= 1 +############################################################################## +# The second section - checks START SLAVE UNTIL RELAY_LOG_FILE =# 'log_name', +# RELAY_LOG_POS = log_pos. This section of the test does the following: +# 1) At master, create a table and inserts a value. Let slave replicate this. +# 2) Stop slave sql thread. +# 3) Insert some more values at master. Note that io thread copies this insert +# 4) Use start slave until to start the sql thread and check if it +# stops at the correct position. +############################################################################## + +--source include/rpl_reset.inc + +--connection master +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1); + +--sync_slave_with_master +--source include/stop_slave_sql.inc + +--connection master +INSERT INTO t1 VALUES (2); +--let $master_log_pos= query_get_value(SHOW MASTER STATUS, Position, 1) +INSERT INTO t1 VALUES (3); + +--source include/sync_slave_io_with_master.inc + +--let $relay_log_file= query_get_value(SHOW SLAVE STATUS, Relay_Log_File,1) +--source include/get_relay_log_pos.inc + +--disable_query_log +--eval start slave until relay_log_file='$relay_log_file', relay_log_pos=$relay_log_pos +--enable_query_log +--source include/wait_for_slave_sql_to_stop.inc + +--let $assert_cond= COUNT(*) = 2 FROM t1 +--let $assert_text= table t1 should have two rows. +--source include/assert.inc + +#cleanup +--source include/start_slave.inc +--connection master +DROP TABLE t1; +--sync_slave_with_master --source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_sp_effects.test b/mysql-test/suite/rpl/t/rpl_sp_effects.test index df13ff253b1..82d61d94bd4 100644 --- a/mysql-test/suite/rpl/t/rpl_sp_effects.test +++ b/mysql-test/suite/rpl/t/rpl_sp_effects.test @@ -260,5 +260,27 @@ SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creato sync_slave_with_master; +# +# Bug#16056537: MYSQLD CRASHES IN ITEM_FUNC_GET_USER_VAR::FIX_LENGTH_AND_DEC() +# +set names utf8; +--delimiter | +CREATE FUNCTION f() RETURNS timestamp DETERMINISTIC +BEGIN RETURN '2012-12-21 12:12:12'; END | +CREATE PROCEDURE p(t timestamp) +BEGIN + SET @t = t; + PREPARE stmt FROM " + UPDATE t1 SET a = @t WHERE '2012-12-31 08:00:00' < f() "; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; +END | +--delimiter ; +create table t1 (a timestamp); +call p('2012-12-31 08:00:00'); +drop table t1; +drop procedure p; +drop function f; + --echo end of the tests --source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_stm_until.test b/mysql-test/suite/rpl/t/rpl_stm_until.test index 210b6b50fa8..074d38ca0c6 100644 --- a/mysql-test/suite/rpl/t/rpl_stm_until.test +++ b/mysql-test/suite/rpl/t/rpl_stm_until.test @@ -22,6 +22,7 @@ -- source include/rpl_reset.inc # Test is dependent on binlog positions +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); # prepare version for substitutions let $VERSION=`select version()`; @@ -73,7 +74,7 @@ select * from t1; --let $slave_param_value= $master_log_pos_1 --source include/check_slave_param.inc -let $relay_log_file= slave-relay-bin.000004; +let $relay_log_file= slave-relay-bin.000003; let $master_log_pos= $master_log_pos_2; source include/get_relay_log_pos.inc; # try replicate all up to and not including the second insert to t2; @@ -187,47 +188,6 @@ connection slave; start slave; sync_with_master; - # Bug #47142 "slave start until" stops 1 event too late in 4.1 to 5.0 replication -# -# testing fixes that refine the start position of prior-5.0 master's event -# and by that provide correct execution of -# START SLAVE UNTIL ... master_log_pos= x; -# Keep the test at the end of the file because it manipulates with binlog files -# to substitute the genuine one with a prepared on 4.1 server. -# - ---source include/rpl_reset.inc - -connection master; ---disable_warnings -drop table if exists t1; # there is create table t1 in bug47142_master-bin.000001 ---enable_warnings -sync_slave_with_master; -connection slave; -stop slave; -connection master; - -flush logs; -let $MYSQLD_DATADIR= `select @@datadir`; ---remove_file $MYSQLD_DATADIR/master-bin.000001 ---copy_file $MYSQL_TEST_DIR/std_data/bug47142_master-bin.000001 $MYSQLD_DATADIR/master-bin.000001 -# this a constant bound to the bug47142_master-bin.000001 binlog file ---let $binlog_before_drop=294; - -connection slave; -stop slave; -reset slave; ---replace_regex /master_log_pos=[0-9]+/master_log_pos=MASTER_LOG_POS/ -eval start slave until master_log_file='master-bin.000001', master_log_pos=$binlog_before_drop /* to stop right before DROP */; ---source include/wait_for_slave_sql_to_stop.inc - -show tables /* t1 must exist */; - -# clean-up of Bug #47142 testing - -drop table t1; # drop on slave only, master does not have t1. -stop slave; - # End of tests --let $rpl_only_running_threads= 1 --source include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_temporal_mysql56.test b/mysql-test/suite/rpl/t/rpl_temporal_mysql56.test new file mode 100644 index 00000000000..f21f125ba30 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_temporal_mysql56.test @@ -0,0 +1,48 @@ +--source include/master-slave.inc + +connection master; +SET TIME_ZONE='+00:00'; +let $MYSQLD_MASTER_DATADIR= `select @@datadir`; + +connection slave; +SET TIME_ZONE='+00:00'; +let $MYSQLD_SLAVE_DATADIR= `select @@datadir`; + +--copy_file std_data/mysql56time.frm $MYSQLD_MASTER_DATADIR/test/mysql56time.frm +--copy_file std_data/mysql56time.MYD $MYSQLD_MASTER_DATADIR/test/mysql56time.MYD +--copy_file std_data/mysql56time.MYI $MYSQLD_MASTER_DATADIR/test/mysql56time.MYI +--copy_file std_data/mysql56time.frm $MYSQLD_SLAVE_DATADIR/test/mysql56time.frm +--copy_file std_data/mysql56time.MYD $MYSQLD_SLAVE_DATADIR/test/mysql56time.MYD +--copy_file std_data/mysql56time.MYI $MYSQLD_SLAVE_DATADIR/test/mysql56time.MYI + +--copy_file std_data/mysql56datetime.frm $MYSQLD_MASTER_DATADIR/test/mysql56datetime.frm +--copy_file std_data/mysql56datetime.MYD $MYSQLD_MASTER_DATADIR/test/mysql56datetime.MYD +--copy_file std_data/mysql56datetime.MYI $MYSQLD_MASTER_DATADIR/test/mysql56datetime.MYI +--copy_file std_data/mysql56datetime.frm $MYSQLD_SLAVE_DATADIR/test/mysql56datetime.frm +--copy_file std_data/mysql56datetime.MYD $MYSQLD_SLAVE_DATADIR/test/mysql56datetime.MYD +--copy_file std_data/mysql56datetime.MYI $MYSQLD_SLAVE_DATADIR/test/mysql56datetime.MYI + +--copy_file std_data/mysql56timestamp.frm $MYSQLD_MASTER_DATADIR/test/mysql56timestamp.frm +--copy_file std_data/mysql56timestamp.MYD $MYSQLD_MASTER_DATADIR/test/mysql56timestamp.MYD +--copy_file std_data/mysql56timestamp.MYI $MYSQLD_MASTER_DATADIR/test/mysql56timestamp.MYI +--copy_file std_data/mysql56timestamp.frm $MYSQLD_SLAVE_DATADIR/test/mysql56timestamp.frm +--copy_file std_data/mysql56timestamp.MYD $MYSQLD_SLAVE_DATADIR/test/mysql56timestamp.MYD +--copy_file std_data/mysql56timestamp.MYI $MYSQLD_SLAVE_DATADIR/test/mysql56timestamp.MYI + +connection master; +INSERT INTO mysql56time VALUES ('01:01:01','01:01:01.1','01:01:01.11','01:01:01.111','01:01:01.1111','01:01:01.11111','01:01:01.111111'); +INSERT INTO mysql56datetime VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +INSERT INTO mysql56timestamp VALUES ('2001-01-01 01:01:01','2001-01-01 01:01:01.1','2001-01-01 01:01:01.11','2001-01-01 01:01:01.111','2001-01-01 01:01:01.1111','2001-01-01 01:01:01.11111','2001-01-01 01:01:01.111111'); +sync_slave_with_master; + +connection slave; +--query_vertical SELECT * FROM mysql56time +--query_vertical SELECT * FROM mysql56datetime +--query_vertical SELECT * FROM mysql56timestamp + +connection master; +DROP TABLE mysql56time; +DROP TABLE mysql56datetime; +DROP TABLE mysql56timestamp; + +--source include/rpl_end.inc diff --git a/mysql-test/suite/sys_vars/r/innodb_buffer_pool_evict_basic.result b/mysql-test/suite/sys_vars/r/innodb_buffer_pool_evict_basic.result new file mode 100644 index 00000000000..459ad95bdc6 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/innodb_buffer_pool_evict_basic.result @@ -0,0 +1,7 @@ +SELECT @@global.innodb_buffer_pool_evict; +@@global.innodb_buffer_pool_evict + +SET GLOBAL innodb_buffer_pool_evict = 'uncompressed'; +SELECT @@global.innodb_buffer_pool_evict; +@@global.innodb_buffer_pool_evict + diff --git a/mysql-test/suite/sys_vars/t/innodb_buffer_pool_evict_basic.test b/mysql-test/suite/sys_vars/t/innodb_buffer_pool_evict_basic.test new file mode 100644 index 00000000000..ce42f64395f --- /dev/null +++ b/mysql-test/suite/sys_vars/t/innodb_buffer_pool_evict_basic.test @@ -0,0 +1,15 @@ +-- source include/have_innodb.inc +# This is a debug variable for now +-- source include/have_debug.inc + +if (`select plugin_auth_version <= "5.5.31-MariaDB-30.2" from information_schema.plugins where plugin_name='innodb'`) +{ + --skip Not fixed in XtraDB 5.5.31-MariaDB-30.2 or earlier +} + +SELECT @@global.innodb_buffer_pool_evict; + +SET GLOBAL innodb_buffer_pool_evict = 'uncompressed'; + +# Should always be empty. +SELECT @@global.innodb_buffer_pool_evict; diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index c39b7267f83..9cbc941402e 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -74,11 +74,11 @@ select 10E+0+'10'; # The following cast creates warnings -select CONVERT(DATE "2004-01-22 21:45:33" USING latin1); -select CONVERT(DATE "2004-01-22 21:45:33",CHAR); -select CONVERT(DATE "2004-01-22 21:45:33",CHAR(4)); -select CONVERT(DATE "2004-01-22 21:45:33",BINARY(4)); -select CAST(DATE "2004-01-22 21:45:33" AS BINARY(4)); +select CONVERT(TIMESTAMP "2004-01-22 21:45:33" USING latin1); +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR); +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",CHAR(4)); +select CONVERT(TIMESTAMP "2004-01-22 21:45:33",BINARY(4)); +select CAST(TIMESTAMP "2004-01-22 21:45:33" AS BINARY(4)); select CAST(0xb3 as signed); select CAST(0x8fffffffffffffff as signed); select CAST(0xffffffffffffffff as unsigned); @@ -412,6 +412,19 @@ WHERE CAST(a as BINARY)=x'62736D697468' DROP TABLE t1; +--echo # +--echo # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH +--echo # LONGTEXT, UNION, USER VARIABLE +--echo # Bug#14096619 UNABLE TO RESTORE DATABASE DUMP +--echo # + +CREATE TABLE t1 AS SELECT CONCAT(CAST(REPEAT('9', 1000) AS SIGNED)), + CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # End of test for Bug#13581962, Bug#14096619 + --echo End of 5.1 tests select cast("2101-00-01 02:03:04" as datetime); diff --git a/mysql-test/t/ctype_cp932_binlog_stm.test b/mysql-test/t/ctype_cp932_binlog_stm.test index 167840a649c..a83f48b1439 100644 --- a/mysql-test/t/ctype_cp932_binlog_stm.test +++ b/mysql-test/t/ctype_cp932_binlog_stm.test @@ -141,6 +141,23 @@ SELECT HEX(a), HEX(CONVERT(a using cp932)) as b FROM t1 HAVING b<>'3F' ORDER BY DROP TABLE t1; +--echo # +--echo # Bug#MDEV-4489 Replication of big5, cp932, gbk, sjis strings makes wrong values on slave +--echo # +let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1); +SET NAMES cp932; +CREATE TABLE t1 (a INT); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (0x31); +INSERT INTO t1 VALUES (X'31'); +PREPARE stmt FROM 'INSERT INTO t1 (a) VALUES (?)'; +SET @a='1'; +SELECT charset(@a); +EXECUTE stmt USING @a; +DROP PREPARE stmt; +DROP TABLE t1; +--source include/show_binlog_events.inc + --echo # --echo # End of 5.5 tests diff --git a/mysql-test/t/ctype_ucs2_query_cache-master.opt b/mysql-test/t/ctype_ucs2_query_cache-master.opt new file mode 100644 index 00000000000..413ebb9f898 --- /dev/null +++ b/mysql-test/t/ctype_ucs2_query_cache-master.opt @@ -0,0 +1 @@ +--collation-server=ucs2_unicode_ci --character-set-server=ucs2,latin1 --query-cache-size=1048576 diff --git a/mysql-test/t/ctype_ucs2_query_cache.test b/mysql-test/t/ctype_ucs2_query_cache.test new file mode 100644 index 00000000000..bdc1d079d5e --- /dev/null +++ b/mysql-test/t/ctype_ucs2_query_cache.test @@ -0,0 +1,19 @@ +-- source include/have_query_cache.inc +-- source include/have_ucs2.inc + +--echo # +--echo # Start of 5.5 tests +--echo # + +--echo # +--echo # Bug#MDEV-4518 Server crashes in is_white_space when it's run +--echo # with query cache, charset ucs2 and collation ucs2_unicode_ci +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3),(4); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 5.5 tests +--echo # diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 03696f385b5..fda20ca0ec5 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1811,6 +1811,21 @@ CREATE TABLE t2 AS SELECT CONCAT(s1) FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1, t2; +--echo # +--echo # Bug#13581962 HIGH MEMORY USAGE ATTEMPT, THEN CRASH WITH +--echo # LONGTEXT, UNION, USER VARIABLE +--echo # Bug#14096619 UNABLE TO RESTORE DATABASE DUMP +--echo # + +CREATE TABLE t1(f1 LONGTEXT CHARACTER SET utf8mb4); +INSERT INTO t1 VALUES ('a'); +SELECT @a:= CAST(f1 AS SIGNED) FROM t1 +UNION ALL +SELECT CAST(f1 AS SIGNED) FROM t1; +DROP TABLE t1; + +--echo # End of test for Bug#13581962,Bug#14096619 + --echo # --echo # End of 5.5 tests --echo # diff --git a/mysql-test/t/empty_user_table.test b/mysql-test/t/empty_user_table.test new file mode 100644 index 00000000000..b54f2109e30 --- /dev/null +++ b/mysql-test/t/empty_user_table.test @@ -0,0 +1,20 @@ +# +# MDEV-4462 mysqld gets SIGFPE when mysql.user table is empty +# + +source include/not_embedded.inc; + +create table t1 as select * from mysql.user; +truncate table mysql.user; +flush privileges; + +# connecting via unix socket gives ER_ACCESS_DENIED_ERROR +# connecting via tcp/ip gives ER_HOST_NOT_PRIVILEGED +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT +--error ER_ACCESS_DENIED_ERROR,ER_HOST_NOT_PRIVILEGED +connect (fail,localhost,u1); + +insert mysql.user select * from t1; +drop table t1; +flush privileges; + diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 97766fefa91..a5c35c0dff2 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -1380,7 +1380,30 @@ insert into t1 values (1, '2008-10-02'), (2, '2010-12-12'); select avg(export_set( 3, 'y', sha(i))), group_concat(d) from t1 group by d order by i; drop table t1; -#### End of 5.3 tests +--echo # +--echo # MDEV-4290: crash in st_select_lex::mark_as_dependent +--echo # +create table `t1`(`a` int); + +--error ER_INVALID_GROUP_FUNC_USE +select 1 from t1 v1 right join t1 on count(*); +--error ER_INVALID_GROUP_FUNC_USE +select 1 from t1 order by +( + select 1 from + ( + select 1 from t1 v1 right join t1 on count(*) + ) v +); +insert into t1 values (1),(1),(2),(2); +select count(*) from t1; +select z from (select count(*) as z from t1) v; +--echo # next is how it implemented now (may be changed in case of dependent +--echo # derived tables) +select z from (select count(*) as z from t1) v group by 1; +drop table t1; + +--echo # end of 5.3 tests --echo # --echo # Bug#52123 Assertion failed: aggregator == aggr->Aggrtype(), diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index f245b4f9f78..1a60b0c222a 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1538,6 +1538,18 @@ create table t1(a int) select null; select 1 div convert(a using utf8) from t1; drop table t1; +# +# BUG#11757250: REPLACE(...) INSIDE A STORED PROCEDURE. +# +create table t1 (a int); +create table t2 (a int); +create procedure foo (var char(100)) + select replace(var, '00000000', table_name) + from information_schema.tables where table_schema='test'; +--sorted_result +call foo('(( 00000000 ++ 00000000 ))'); +drop procedure foo; +drop table t1,t2; --echo # --echo # End of 5.5 tests diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index 731efe5648e..404f0447f56 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -956,3 +956,23 @@ SELECT a, ASTEXT(b) FROM t1; DROP TABLE t1; --echo End of 5.1 tests + +# +# MDEV-4521 MBRContains, MBRWithin no longer work with geometries of different type. +# +CREATE TABLE t1 ( + l LINESTRING NOT NULL, + SPATIAL KEY(l) +) ENGINE = myisam; + +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(0 0, 1 1)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(1 1, 2 2)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(2 2, 3 3)')); + +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); + +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); + +DROP TABLE t1; diff --git a/mysql-test/t/grant_4332.test b/mysql-test/t/grant_4332.test new file mode 100644 index 00000000000..f77d3be350f --- /dev/null +++ b/mysql-test/t/grant_4332.test @@ -0,0 +1,108 @@ +# +# MDEV-4332 Increase username length from 16 characters +# + +# user names here have the pattern +# 0 +# where '0' at the end is the end-of-name marker + +--source include/not_embedded.inc + +--enable_metadata +select user(); +--disable_metadata + +--error ER_WRONG_STRING_LENGTH +create user a17aaaaaaaaaaaaa0@localhost; + +alter table mysql.user modify User char(80) binary not null default ''; +alter table mysql.db modify User char(80) binary not null default ''; +alter table mysql.tables_priv modify User char(80) binary not null default ''; +alter table mysql.columns_priv modify User char(80) binary not null default ''; +alter table mysql.procs_priv modify User char(80) binary not null default ''; +alter table mysql.proc modify definer char(141) collate utf8_bin not null default ''; +alter table mysql.event modify definer char(141) collate utf8_bin not null default ''; + +--source include/restart_mysqld.inc + +set global event_scheduler = on; + +--enable_metadata +select user(); +--disable_metadata + +create user a17aaaaaaaaaaaaa0@localhost; +grant usage on *.* to a17aaaaaaaaaaaaa0@localhost; +grant select on mysql.user to b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; +grant select(User) on mysql.tables_priv to c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; + +connect (a17,localhost,a17aaaaaaaaaaaaa0,,); +connect (b64,localhost,b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0,,); +connect (c80,localhost,c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0,,); + +connection a17; +select user(), current_user(); +show grants; + +connection b64; +select user(), current_user(); +show grants; +select user,host from mysql.user where user like '%0'; +--error ER_TABLEACCESS_DENIED_ERROR +select user,host from mysql.db; + +connection c80; +select user(), current_user(); +show grants; +select user from mysql.tables_priv; +--error ER_COLUMNACCESS_DENIED_ERROR +select user,host from mysql.tables_priv; + +create procedure test.p1() select user(), current_user(), user from mysql.tables_priv; + +show create procedure test.p1; + +create table test.t1 (a text); +create event e1 on schedule every 1 second + do insert test.t1 values (concat(user(), ' ', current_user())); + +connection default; + +call test.p1(); + +disconnect a17; +disconnect b64; +disconnect c80; + +let $wait_timeout= 10; +let $wait_condition= SELECT 1 from t1; +--source include/wait_condition.inc + +select * from t1 limit 1; +--error ER_WRONG_STRING_LENGTH +grant usage on *.* to d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; + +--error ER_WRONG_STRING_LENGTH +drop user d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; +drop user c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; +drop user b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; +drop user a17aaaaaaaaaaaaa0@localhost; + +set global event_scheduler = off; +drop event e1; +drop procedure test.p1; +drop table t1; + +alter table mysql.user modify User char(16) binary not null default ''; +alter table mysql.db modify User char(16) binary not null default ''; +alter table mysql.tables_priv modify User char(16) binary not null default ''; +alter table mysql.columns_priv modify User char(16) binary not null default ''; +alter table mysql.procs_priv modify User char(16) binary not null default ''; +alter table mysql.proc modify definer char(77) collate utf8_bin not null default ''; +alter table mysql.event modify definer char(77) collate utf8_bin not null default ''; +flush privileges; + +--enable_metadata +select user(); +--disable_metadata + diff --git a/mysql-test/t/init_connection_query_cache-master.opt b/mysql-test/t/init_connection_query_cache-master.opt new file mode 100644 index 00000000000..7bef2af8d35 --- /dev/null +++ b/mysql-test/t/init_connection_query_cache-master.opt @@ -0,0 +1 @@ +--init_connect="select * from test.t1 where 0" diff --git a/mysql-test/t/init_connection_query_cache.test b/mysql-test/t/init_connection_query_cache.test new file mode 100644 index 00000000000..4d83304163e --- /dev/null +++ b/mysql-test/t/init_connection_query_cache.test @@ -0,0 +1,26 @@ +-- source include/have_query_cache.inc + +--echo # +--echo # MDEV-4520: Assertion `0' fails in Query_cache::end_of_result on +--echo # concurrent drop event and event execution +--echo # +set GLOBAL query_cache_size=1355776; + +create user mysqltest1@localhost; +grant SELECT on test.* to mysqltest1@localhost; + +create table t1 (a int); + +connect (con1,localhost,mysqltest1,,); +connection con1; +--echo # This explain put here to be sure that init connection query +--echo # has 'Impossible WHERE'. +explain extended select * from test.t1 where 0; +connection default; +disconnect con1; +revoke all privileges, grant option from mysqltest1@localhost; +drop user mysqltest1@localhost; + +drop table t1; + +set GLOBAL query_cache_size=default; diff --git a/mysql-test/t/innodb_ext_key.test b/mysql-test/t/innodb_ext_key.test index 31c6fca2b95..36414105917 100644 --- a/mysql-test/t/innodb_ext_key.test +++ b/mysql-test/t/innodb_ext_key.test @@ -539,6 +539,129 @@ select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; drop table t1,t2,t3; +--echo # +--echo # Bug mdev-4340: performance regression with extended_keys=on +--echo # + +set @save_optimizer_switch=@@optimizer_switch; + +CREATE TABLE t1 ( + page_id int(8) unsigned NOT NULL AUTO_INCREMENT, + page_namespace int(11) NOT NULL DEFAULT '0', + page_title varbinary(255) NOT NULL DEFAULT '', + page_restrictions tinyblob NOT NULL, + page_counter bigint(20) unsigned NOT NULL DEFAULT '0', + page_is_redirect tinyint(1) unsigned NOT NULL DEFAULT '0', + page_is_new tinyint(1) unsigned NOT NULL DEFAULT '0', + page_random double unsigned NOT NULL DEFAULT '0', + page_touched varbinary(14) NOT NULL DEFAULT '', + page_latest int(8) unsigned NOT NULL DEFAULT '0', + page_len int(8) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (page_id), + UNIQUE KEY name_title (page_namespace,page_title), + KEY page_random (page_random), + KEY page_len (page_len), + KEY page_redirect_namespace_len (page_is_redirect,page_namespace,page_len) +) ENGINE=InnoDB AUTO_INCREMENT=38929100 DEFAULT CHARSET=binary; +INSERT INTO t1 VALUES +(38928077,0,'Sandbox','',0,0,0,0,'',0,0),(38928078,1,'Sandbox','',0,0,0,1,'',0,0), +(38928079,2,'Sandbox','',0,0,0,2,'',0,0),(38928080,3,'Sandbox','',0,0,0,3,'',0,0), +(38928081,4,'Sandbox','',0,0,0,4,'',0,0),(38928082,5,'Sandbox','',0,0,0,5,'',0,0); + +CREATE TABLE t2 ( + rev_id int(8) unsigned NOT NULL AUTO_INCREMENT, + rev_page int(8) unsigned NOT NULL DEFAULT '0', + rev_text_id int(8) unsigned NOT NULL DEFAULT '0', + rev_comment varbinary(255) DEFAULT NULL, + rev_user int(5) unsigned NOT NULL DEFAULT '0', + rev_user_text varbinary(255) NOT NULL DEFAULT '', + rev_timestamp varbinary(14) NOT NULL DEFAULT '', + rev_minor_edit tinyint(1) unsigned NOT NULL DEFAULT '0', + rev_deleted tinyint(1) unsigned NOT NULL DEFAULT '0', + rev_len int(8) unsigned DEFAULT NULL, + rev_parent_id int(8) unsigned DEFAULT NULL, + rev_sha1 varbinary(32) NOT NULL DEFAULT '', + PRIMARY KEY (rev_page,rev_id), + UNIQUE KEY rev_id (rev_id), + KEY rev_timestamp (rev_timestamp), + KEY page_timestamp (rev_page,rev_timestamp), + KEY user_timestamp (rev_user,rev_timestamp), + KEY usertext_timestamp (rev_user_text,rev_timestamp,rev_user,rev_deleted,rev_minor_edit,rev_text_id,rev_comment) +) ENGINE=InnoDB DEFAULT CHARSET=binary; +INSERT INTO t2 VALUES +(547116222,20,0,NULL,3,'','',0,0,NULL,NULL,''),(547117245,20,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118268,20,0,NULL,5,'','',0,0,NULL,NULL,''),(547114177,21,0,NULL,1,'','',0,0,NULL,NULL,''), +(547115200,21,0,NULL,2,'','',0,0,NULL,NULL,''),(547116223,21,0,NULL,3,'','',0,0,NULL,NULL,''), +(547117246,21,0,NULL,4,'','',0,0,NULL,NULL,''),(547118269,21,0,NULL,5,'','',0,0,NULL,NULL,''), +(547114178,22,0,NULL,1,'','',0,0,NULL,NULL,''),(547115201,22,0,NULL,2,'','',0,0,NULL,NULL,''), +(547116224,22,0,NULL,3,'','',0,0,NULL,NULL,''),(547117247,22,0,NULL,4,'','',0,0,NULL,NULL,''), +(547116226,24,0,NULL,3,'','',0,0,NULL,NULL,''),(547117249,24,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118272,24,0,NULL,5,'','',0,0,NULL,NULL,''),(547114181,25,0,NULL,1,'','',0,0,NULL,NULL,''), +(547115204,25,0,NULL,2,'','',0,0,NULL,NULL,''),(547116227,25,0,NULL,3,'','',0,0,NULL,NULL,''), +(547116157,978,0,NULL,2,'','',0,0,NULL,NULL,''),(547117180,978,0,NULL,3,'','',0,0,NULL,NULL,''), +(547118203,978,0,NULL,4,'','',0,0,NULL,NULL,''),(547119226,978,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115135,979,0,NULL,1,'','',0,0,NULL,NULL,''),(547116158,979,0,NULL,2,'','',0,0,NULL,NULL,''), +(547116173,994,0,NULL,2,'','',0,0,NULL,NULL,''),(547117196,994,0,NULL,3,'','',0,0,NULL,NULL,''), +(547118219,994,0,NULL,4,'','',0,0,NULL,NULL,''),(547119242,994,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115151,995,0,NULL,1,'','',0,0,NULL,NULL,''),(547116174,995,0,NULL,2,'','',0,0,NULL,NULL,''), +(547117197,995,0,NULL,3,'','',0,0,NULL,NULL,''),(547118220,995,0,NULL,4,'','',0,0,NULL,NULL,''), +(547118223,998,0,NULL,4,'','',0,0,NULL,NULL,''),(547119246,998,0,NULL,5,'','',0,0,NULL,NULL,''), +(547115155,999,0,NULL,1,'','',0,0,NULL,NULL,''),(547116178,999,0,NULL,2,'','',0,0,NULL,NULL,''), +(547117201,999,0,NULL,3,'','',0,0,NULL,NULL,''),(547118224,999,0,NULL,4,'','',0,0,NULL,NULL,''), +(547119271,38928081,0,NULL,10,'','',0,0,NULL,NULL,''),(547119272,38928081,0,NULL,11,'','',0,0,NULL,NULL,''), +(547119273,38928081,0,NULL,12,'','',0,0,NULL,NULL,''),(547119274,38928081,0,NULL,13,'','',0,0,NULL,NULL,''), +(547119275,38928081,0,NULL,14,'','',0,0,NULL,NULL,''),(547119276,38928081,0,NULL,15,'','',0,0,NULL,NULL,''), +(547119277,38928081,0,NULL,16,'','',0,0,NULL,NULL,''),(547119278,38928081,0,NULL,17,'','',0,0,NULL,NULL,''), +(547119279,38928081,0,NULL,18,'','',0,0,NULL,NULL,''),(547119280,38928081,0,NULL,19,'','',0,0,NULL,NULL,''); + +CREATE TABLE t3 ( + old_id int(10) unsigned NOT NULL AUTO_INCREMENT, + old_text mediumblob NOT NULL, + old_flags tinyblob NOT NULL, + PRIMARY KEY (old_id) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +INSERT INTO t3 VALUES +(1,'text-0',''),(2,'text-1000',''),(3,'text-2000',''),(4,'text-3000',''), +(5,'text-4000',''),(6,'text-5000',''),(7,'text-6000',''),(8,'text-7000',''), +(9,'text-8000',''),(10,'text-9000',''),(11,'text-1',''),(12,'text-1001',''), +(13,'text-2001',''),(14,'text-3001',''),(15,'text-4001',''),(16,'text-5001',''), +(17,'text-6001',''),(18,'text-7001',''),(19,'text-8001',''),(20,'text-9001',''), +(21,'text-2',''),(22,'text-1002',''),(23,'text-2002',''),(24,'text-3002',''), +(25,'text-4002',''),(26,'text-5002',''),(27,'text-6002',''),(28,'text-7002',''), +(29,'text-8002',''),(30,'text-9002',''),(31,'text-3',''),(32,'text-1003',''), +(33,'text-2003',''),(34,'text-3003',''),(35,'text-4003',''),(36,'text-5003',''), +(37,'text-6003',''),(38,'text-7003',''),(39,'text-8003',''),(40,'text-9003',''), +(41,'text-4',''),(42,'text-1004',''),(43,'text-2004',''),(44,'text-3004',''), +(45,'text-4004',''),(46,'text-5004',''),(47,'text-6004',''),(48,'text-7004',''), +(49,'text-8004',''),(50,'text-9004',''),(51,'text-5',''),(52,'text-1005',''), +(53,'text-2005',''),(54,'text-3005',''),(55,'text-4005',''),(56,'text-5005',''), +(57,'text-6005',''),(58,'text-7005',''),(59,'text-8005',''),(60,'text-9005',''), +(61,'text-6',''),(62,'text-1006',''),(63,'text-2006',''),(64,'text-3006',''), +(65,'text-4006',''),(66,'text-5006',''),(67,'text-6006',''),(68,'text-7006',''), +(69,'text-8006',''),(70,'text-9006',''),(71,'text-7',''),(72,'text-1007',''), +(73,'text-2007',''),(74,'text-3007',''),(75,'text-4007',''),(76,'text-5007',''), +(77,'text-6007',''),(78,'text-7007',''),(79,'text-8007',''),(80,'text-9007',''), +(81,'text-8',''),(82,'text-1008',''),(83,'text-2008',''),(84,'text-3008',''), +(85,'text-4008',''),(86,'text-5008',''),(87,'text-6008',''),(88,'text-7008',''), +(89,'text-8008',''),(90,'text-9008',''),(91,'text-9',''),(92,'text-1009',''), +(93,'text-2009',''),(94,'text-3009',''),(95,'text-4009',''),(96,'text-5009',''), +(97,'text-6009',''),(98,'text-7009',''),(99,'text-8009',''),(100,'text-9009',''); + + +set optimizer_switch='extended_keys=off'; +EXPLAIN +SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 + WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' +ORDER BY rev_timestamp ASC LIMIT 10; + +set optimizer_switch='extended_keys=on'; +EXPLAIN +SELECT * FROM t1, t2 IGNORE INDEX (PRIMARY), t3 + WHERE page_id=rev_page AND rev_text_id=old_id AND page_namespace=4 AND page_title='Sandbox' +ORDER BY rev_timestamp ASC LIMIT 10; + +DROP TABLE t1,t2,t3; + set optimizer_switch=@save_optimizer_switch; set optimizer_switch=@save_ext_key_optimizer_switch; diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test index 3168e95f620..7b7d9236835 100644 --- a/mysql-test/t/join_nested.test +++ b/mysql-test/t/join_nested.test @@ -1287,3 +1287,27 @@ SET optimizer_switch=@save_optimizer_switch; --echo End of 5.0 tests +--echo # +--echo # MDEV-621: LP:693329 - Assertion `!is_interleave_error' failed on low optimizer_search_depth +--echo # +set @tmp_mdev621= @@optimizer_search_depth; +SET SESSION optimizer_search_depth = 4; + +CREATE TABLE t1 (f1 int,f2 int,f3 int,f4 int) ; +INSERT IGNORE INTO t1 VALUES (0,0,2,0),(NULL,0,2,0); +CREATE TABLE t2 (f1 int) ; +CREATE TABLE t3 (f3 int,PRIMARY KEY (f3)) ; +CREATE TABLE t4 (f5 int) ; +CREATE TABLE t5 (f2 int) ; + +SELECT alias2.f4 FROM t1 AS alias1 +LEFT JOIN t1 AS alias2 + LEFT JOIN t2 AS alias3 + LEFT JOIN t3 AS alias4 ON alias3.f1 = alias4.f3 + ON alias2.f1 +LEFT JOIN t4 AS alias5 + JOIN t5 ON alias5.f5 +ON alias2.f3 ON alias1.f2; +DROP TABLE t1,t2,t3,t4,t5; +set optimizer_search_depth= @tmp_mdev621; + diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 44f4afd451b..24885c056b8 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -1439,6 +1439,37 @@ GROUP BY t2.f1, t2.f2; DROP TABLE t1,t2; +--echo # +--echo # Bug#13068506 - QUERY WITH GROUP BY ON NON-AGGR COLUMN RETURNS +--echo # WRONG RESULT +--echo # + +CREATE TABLE t1 (i1 int); +INSERT INTO t1 VALUES (100), (101); + +CREATE TABLE t2 (i2 int, i3 int); +INSERT INTO t2 VALUES (20,1),(10,2); + +CREATE TABLE t3 (i4 int(11)); +INSERT INTO t3 VALUES (1),(2); + +let $query= SELECT ( + SELECT MAX( t2.i2 ) + FROM t3 RIGHT JOIN t2 ON ( t2.i3 = 2 ) + WHERE t2.i3 <> t1.i1 +) AS field1 +FROM t1; + +--echo +--eval $query; +--echo +--eval $query GROUP BY field1; + +--echo +drop table t1,t2,t3; + +--echo # End of test for Bug#13068506 + --echo End of 5.1 tests --echo # @@ -1622,4 +1653,21 @@ ORDER BY t1.b; DROP TABLE t1,t2; +--echo # +--echo # Bug mdev-4336: LEFT JOIN with disjunctive +--echo # IS NULL in WHERE +--echo # causes a hang and eventual crash +--echo # + +CREATE TABLE t1 ( + id int(11) NOT NULL, + modified datetime NOT NULL, + PRIMARY KEY (id) +); + +SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id + WHERE a.modified > b.modified or b.modified IS NULL; + +DROP TABLE t1; + SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/t/join_outer_innodb.test b/mysql-test/t/join_outer_innodb.test index adb555d5f85..539d85a8b11 100644 --- a/mysql-test/t/join_outer_innodb.test +++ b/mysql-test/t/join_outer_innodb.test @@ -350,3 +350,26 @@ explain select * from v1; drop view v1; drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; + + +--echo # +--echo # MDEV-4270: crash in fix_semijoin_strategies_for_picked_join_order +--echo # +drop table if exists t1,t2,t3; +create table t2(a int,unique key (a)) engine=innodb; +create table t3(b int) engine=innodb; +create table t1(a int,b int)engine=innodb; + +set @mdev4270_opl= @@optimizer_prune_level; +set @mdev4270_osd= @@optimizer_search_depth; +set optimizer_prune_level=0; +set optimizer_search_depth=2; + +select 1 from t1 join t2 a +natural left join t2 b +natural right outer join t3; + +drop table t1,t2,t3; +set optimizer_prune_level=@mdev4270_opl; +set optimizer_search_depth=@mdev4270_osd; + diff --git a/mysql-test/t/log_slow.test b/mysql-test/t/log_slow.test index af8a948d318..8d5a09d7a94 100644 --- a/mysql-test/t/log_slow.test +++ b/mysql-test/t/log_slow.test @@ -6,6 +6,7 @@ select @@log_slow_filter; select @@log_slow_rate_limit; select @@log_slow_verbosity; show variables like "log_slow%"; +set @org_slow_query_log= @@global.slow_query_log; # Some simple test to set log_slow_filter set @@log_slow_filter= "filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk,admin"; @@ -42,7 +43,18 @@ show fields from mysql.slow_log; flush slow logs; -# Reset used variables +# MDEV-4206 (empty filter should be no filter) +set long_query_time=0.1; +set log_slow_filter=''; +set global slow_query_log=1; +set global log_output='TABLE'; +select sleep(0.5); +select count(*) FROM mysql.slow_log; +truncate mysql.slow_log; +# Reset used variables +set @@long_query_time=default; +set global slow_query_log= @org_slow_query_log; set @@log_slow_filter=default; set @@log_slow_verbosity=default; +set global log_output= default; diff --git a/mysql-test/t/myisam-metadata.test b/mysql-test/t/myisam-metadata.test index 2bbcc89a702..609cf5d8c5e 100644 --- a/mysql-test/t/myisam-metadata.test +++ b/mysql-test/t/myisam-metadata.test @@ -30,16 +30,11 @@ while ($1) --enable_query_log --connect(con1,localhost,root,,) -SET debug_sync= 'myisam_after_repair_by_sort SIGNAL waiting WAIT_FOR go'; +SET debug_sync= 'myisam_before_repair_by_sort SIGNAL waiting WAIT_FOR go'; send ALTER TABLE t1 ENABLE KEYS; --connection default ---let $wait_timeout=60 ---let $show_statement= SHOW PROCESSLIST ---let $field= State ---let $condition= = 'Repair by sorting' ---source include/wait_show_condition.inc SET debug_sync= 'now WAIT_FOR waiting'; SET debug_sync= 'now SIGNAL go'; diff --git a/mysql-test/t/mysql_plugin.test b/mysql-test/t/mysql_plugin.test index a05b5a624d9..10bc03e0f06 100644 --- a/mysql-test/t/mysql_plugin.test +++ b/mysql-test/t/mysql_plugin.test @@ -110,13 +110,8 @@ SELECT * FROM mysql.plugin WHERE dl like 'libdaemon%' ORDER BY name; --echo # --echo # Enable the plugin... --echo # -let $expect_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file ---write_file $expect_file -wait -EOF + +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -132,9 +127,8 @@ EOF # # Restart the server # ---append_file $expect_file -restart -EOF + +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -155,12 +149,7 @@ eval INSERT INTO mysql.plugin VALUES ('wonky', '$DAEMONEXAMPLE'); --replace_regex /\.dll/.so/ SELECT * FROM mysql.plugin WHERE dl like 'libdaemon%' ORDER BY name; -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file ---write_file $expect_file -wait -EOF +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -177,9 +166,7 @@ EOF # # Restart the server # ---append_file $expect_file -restart -EOF +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -189,12 +176,7 @@ EOF --replace_regex /\.dll/.so/ SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file ---write_file $expect_file -wait -EOF +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -211,9 +193,7 @@ let $DAEMON_RELOAD = lib$DAEMONEXAMPLE; # # Restart the server # ---append_file $expect_file -restart -EOF +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -226,12 +206,8 @@ SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; --echo # --echo # Disable the plugin... --echo # -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file ---write_file $expect_file -wait -EOF + +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -248,9 +224,7 @@ EOF # # Restart the server # ---append_file $expect_file -restart -EOF +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc @@ -262,13 +236,8 @@ SELECT * FROM mysql.plugin WHERE dl like '%libdaemon%' ORDER BY name; # # Stop the server for error conditions # -let $expect_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file ---write_file $expect_file -wait -EOF + +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --shutdown_server 10 --source include/wait_until_disconnected.inc @@ -382,17 +351,14 @@ replace_result $MYSQL_PLUGIN mysql_plugin; # # Restart the server # ---append_file $expect_file -restart -EOF +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect --enable_reconnect --source include/wait_until_connected_again.inc # # Cleanup -# MTR will remove this file later, but this might be too late. ---error 0,1 ---remove_file $expect_file + +--remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect # Cleanup the share folder in the binary path. --remove_file $MYSQLD_BASEDIR/share/errmsg.sys diff --git a/mysql-test/t/mysqlshow.test b/mysql-test/t/mysqlshow.test index 045329fd2e0..8c60b64a5f1 100644 --- a/mysql-test/t/mysqlshow.test +++ b/mysql-test/t/mysqlshow.test @@ -36,7 +36,7 @@ DROP TABLE t1, t2; # # Bug #19147: mysqlshow INFORMATION_SCHEMA does not work # -# --exec $MYSQL_SHOW information_schema -# --exec $MYSQL_SHOW INFORMATION_SCHEMA -# --exec $MYSQL_SHOW inf_rmation_schema +#--exec $MYSQL_SHOW information_schema +#--exec $MYSQL_SHOW INFORMATION_SCHEMA +#--exec $MYSQL_SHOW inf_rmation_schema diff --git a/mysql-test/t/partition_innodb.test b/mysql-test/t/partition_innodb.test index a743ad45568..ea8faec0d51 100644 --- a/mysql-test/t/partition_innodb.test +++ b/mysql-test/t/partition_innodb.test @@ -60,8 +60,8 @@ insert into t1(c2,c3) values ("Test row",'2010-01-01 00:00:00'); SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test'; SELECT count(*) FROM t1 p where c3 in -(select c3 from t1 t where t.c3 < date '2011-04-26 19:19:44' - and t.c3 > date '2011-04-26 19:18:44') ; +(select c3 from t1 t where t.c3 < timestamp '2011-04-26 19:19:44' + and t.c3 > timestamp '2011-04-26 19:18:44') ; DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index af507b1f7ef..6a82a2901c5 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2493,7 +2493,7 @@ DROP TABLE t1,t2; # Bug #10650 # -select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; +select x'3136' + 0, X'3136' + 0, b'10' + 0, B'10' + 0; # # Bug #11398 Bug in field_conv() results in wrong result of join with index @@ -4289,6 +4289,7 @@ SELECT f1 FROM t1 GROUP BY 1; SELECT f1 FROM t1 GROUP BY '123' = 'abc'; SELECT 1 FROM t1 GROUP BY 1; drop table t1; +set sql_buffer_result= 0; --echo # @@ -4479,5 +4480,41 @@ WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1) OR Time_zone_id <> Time_zone_id ) AND Use_leap_seconds <> 'N'; +--echo # +--echo # Bug mdev-4274: result of simplification of OR badly merged +--echo # into embedding AND +--echo # + +CREATE TABLE t1 (a int, b int, INDEX idx(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8,8); + +CREATE TABLE t2 (c int, INDEX idx(c)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8), (9); + +EXPLAIN EXTENDED +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) + WHERE 1 IS NULL OR b < 33 AND b = c; +SELECT * FROM t1 INNER JOIN t2 ON ( c = a ) + WHERE 1 IS NULL OR b < 33 AND b = c; + +DROP TABLE t1,t2; + +--echo # +--echo # Bug mdev-4413: another manifestations of bug mdev-2474 +--echo # (valgrind complains) +--echo # + +CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,1); + +CREATE TABLE t2 (c int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0), (8); + +SELECT * FROM t1, t2 + WHERE c = a AND + ( 0 OR ( b BETWEEN 45 AND 300 OR a > 45 AND a < 100 ) AND b = c ); + +DROP TABLE t1, t2; + --echo End of 5.3 tests diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 9db6709a8d2..0fb3474f877 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9209,5 +9209,66 @@ DROP FUNCTION f2; DROP FUNCTION f3; DROP FUNCTION f4; ---echo # End of 5.5 test +--echo +--echo Stored procedures and a condition handler in a nested procedure call +--echo doesn't suppress the condition from being passed on to the calling +--echo procedure +--echo +--disable_warnings +drop procedure if exists p1; +drop procedure if exists p0; +--enable_warnings + +create table t1 (id int); +delimiter $$; +create procedure p1 () begin +declare i int default 0; +declare continue handler for not found begin +select "You should see this message and the warning that generated this" as "message"; +show warnings; +end; +select id into i from t1; +end$$ +create procedure p0 () begin +declare continue handler for not found begin +select "You should NOT see this message" as "message"; +end; +call p1(); +end$$ +delimiter ;$$ +call p0(); + +drop procedure p1; +drop procedure p0; +drop table t1; + +--echo +--echo Test if stored procedures propagates errors +--echo + +create table t1 (id int primary key); +delimiter $$; +create procedure p1 () begin +insert into t1 values(1); +insert into t1 values(2); +insert into t1 values(2); +insert into t1 values(3); +end$$ +create procedure p2 () begin + declare x int; + select id into x from t1 where id=5; +end$$ +delimiter ;$$ +--error ER_DUP_ENTRY +call p1(); +show warnings; +select * from t1; +call p2(); + +drop procedure p1; +drop procedure p2; + +drop table t1; + +--echo # End of 5.5 test diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index e2abb8040b3..bfdc6335f1d 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2540,5 +2540,49 @@ WHERE (field1) IN ($query); DROP TABLE t1, t2; +--echo # +--echo # MDEV-389: Wrong result (missing row) with semijoin, join_cache_level>4, LEFT JOIN... +--echo # (testcase only) +--echo # + +# Use another connection to get rid of this test's settings +connect (con1,localhost,root,,); +connection con1; + +SET join_cache_level = 5; +SET optimizer_switch = 'semijoin=on'; + +CREATE TABLE t1 (a INT NOT NULL, b CHAR(1), KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4,'p'),(1,'q'),(8,'e'); + +CREATE TABLE t2 (c INT, d CHAR(1), KEY(c), KEY(d)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,'f'),(2,'i'),(5,'h'),(3,'q'),(1,'g'); + +SELECT a, COUNT(*) AS cnt +FROM t1 LEFT JOIN t2 ON (d = b) +WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' ) +GROUP BY a ORDER BY a, cnt LIMIT 2; + +drop table t1, t2; +connection default; +disconnect con1; + +--echo # +--echo # MDEV-4071: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with ... +--echo # +CREATE TABLE t1 (b INT, c VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7,'v'),(0,'s'); + +CREATE TABLE t2 (a INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0),(8); + +SELECT c, SUM( DISTINCT b ) AS sm FROM t1 +WHERE ( 5, 108 ) IN ( SELECT MIN(a), MAX(a) FROM t2 ) +GROUP BY b +HAVING c <> ( SELECT MAX( c ) FROM t1 ) +ORDER BY sm; + +DROP TABLE t1,t2; + # The following command must be the last one the file set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test index 4c40b2b5487..711f2f4f9b6 100644 --- a/mysql-test/t/subselect_sj_mat.test +++ b/mysql-test/t/subselect_sj_mat.test @@ -1677,6 +1677,25 @@ SELECT * FROM t1, t2 WHERE b1 IN ( SELECT b2 FROM t2 WHERE b1 > 'o' ) AND ( b1 < DROP TABLE t1,t2; +--echo # +--echo # MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +--echo # +CREATE TABLE t1 ( + id int(11) NOT NULL +); + +CREATE TABLE t2 ( + id int(11) NOT NULL, + a_id int(11) DEFAULT NULL +); + +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); + +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); + +drop table t1,t2; + --echo # 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/temporal_literal.test b/mysql-test/t/temporal_literal.test new file mode 100644 index 00000000000..5d67f64a6f5 --- /dev/null +++ b/mysql-test/t/temporal_literal.test @@ -0,0 +1,217 @@ +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +SET NAMES latin1; + + +--echo # +--echo # Testing DATE literals +--echo # +--error ER_WRONG_VALUE +SELECT DATE'xxxx'; +--error ER_WRONG_VALUE +SELECT DATE'01'; +--error ER_WRONG_VALUE +SELECT DATE'01-01'; +--error ER_WRONG_VALUE +SELECT DATE'2001'; +--error ER_WRONG_VALUE +SELECT DATE'2001-01'; +SELECT DATE'2001-00-00'; +SELECT DATE'2001-01-00'; +SELECT DATE'0000-00-00'; +--error ER_WRONG_VALUE +SELECT DATE'2001-01-01 00:00:00'; +SELECT DATE'01:01:01'; +SELECT DATE'01-01-01'; +SELECT DATE'2010-01-01'; +SELECT DATE '2010-01-01'; +CREATE TABLE t1 AS SELECT DATE'2010-01-01'; +SHOW CREATE TABLE t1; +DROP TABLE t1; +CREATE TABLE t1 AS SELECT + {d'2001-01-01'}, + { d '2001-01-01' }, + {d'2001-01-01 10:10:10'}; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {d'2010-01-01'}; +EXPLAIN EXTENDED SELECT DATE'2010-01-01'; + +--echo # +--echo # Testing DATE literals in non-default sql_mode +--echo # +SET sql_mode=no_zero_in_date; +--error ER_WRONG_VALUE +SELECT DATE'2001-00-00'; +--error ER_WRONG_VALUE +SELECT DATE'2001-01-00'; +SELECT DATE'0000-00-00'; + +SET sql_mode=no_zero_date; +--error ER_WRONG_VALUE +SELECT DATE'0000-00-00'; +SET sql_mode=default; + +--echo # +--echo # Testing TIME literals +--echo # +--error ER_WRONG_VALUE +SELECT TIME'xxxx'; +--error ER_WRONG_VALUE +SELECT TIME'900:00:00'; +--error ER_WRONG_VALUE +SELECT TIME'-900:00:00'; +SELECT TIME'1 24:00:00'; +SELECT TIME'30 24:00:00'; +--error ER_WRONG_VALUE +SELECT TIME'0000-00-00 00:00:00'; +--error ER_WRONG_VALUE +SELECT TIME'40 24:00:00'; +SELECT TIME'10'; +SELECT TIME'10:10'; +SELECT TIME'10:11.12'; +SELECT TIME'10:10:10'; +SELECT TIME'10:10:10.'; +SELECT TIME'10:10:10.1'; +SELECT TIME'10:10:10.12'; +SELECT TIME'10:10:10.123'; +SELECT TIME'10:10:10.1234'; +SELECT TIME'10:10:10.12345'; +SELECT TIME'10:10:10.123456'; +SELECT TIME'-10:00:00'; +SELECT TIME '10:11:12'; +CREATE TABLE t1 AS SELECT + TIME'10:10:10', + TIME'10:10:10.', + TIME'10:10:10.1', + TIME'10:10:10.12', + TIME'10:10:10.123', + TIME'10:10:10.1234', + TIME'10:10:10.12345', + TIME'10:10:10.123456'; +SHOW CREATE TABLE t1; +DROP TABLE t1; +CREATE TABLE t1 AS SELECT + {t'10:10:10'}, + { t '10:10:10' }, + {t'10:10:10.'}, + {t'10:10:10.123456'}, + {t'2001-01-01'}; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {t'10:01:01'}; +EXPLAIN EXTENDED SELECT TIME'10:01:01'; + + +--echo # +--echo # Testing TIMESTAMP literals +--echo # +--error ER_WRONG_VALUE +SELECT TIMESTAMP'xxxx'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2010'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2010-01'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2010-01-01'; +SELECT TIMESTAMP'2010-01-01 00'; +SELECT TIMESTAMP'2010-01-01 00:01'; +SELECT TIMESTAMP'2010-01-01 10:10:10'; +SELECT TIMESTAMP'2010-01-01 10:10:10.'; +SELECT TIMESTAMP'2010-01-01 10:10:10.1'; +SELECT TIMESTAMP'2010-01-01 10:10:10.12'; +SELECT TIMESTAMP'2010-01-01 10:10:10.123'; +SELECT TIMESTAMP'2010-01-01 10:10:10.1234'; +SELECT TIMESTAMP'2010-01-01 10:10:10.12345'; +SELECT TIMESTAMP'2010-01-01 10:10:10.123456'; +SELECT TIMESTAMP '2010-01-01 10:20:30'; +CREATE TABLE t1 AS SELECT + TIMESTAMP'2010-01-01 10:10:10', + TIMESTAMP'2010-01-01 10:10:10.', + TIMESTAMP'2010-01-01 10:10:10.1', + TIMESTAMP'2010-01-01 10:10:10.12', + TIMESTAMP'2010-01-01 10:10:10.123', + TIMESTAMP'2010-01-01 10:10:10.1234', + TIMESTAMP'2010-01-01 10:10:10.12345', + TIMESTAMP'2010-01-01 10:10:10.123456'; +SHOW CREATE TABLE t1; +DROP TABLE t1; +CREATE TABLE t1 AS SELECT + {ts'2001-01-01 10:10:10'}, + { ts '2001-01-01 10:10:10' }, + {ts'2001-01-01 10:10:10.'}, + {ts'2001-01-01 10:10:10.123456'}, + {ts'2001-01-01'}; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXPLAIN EXTENDED SELECT {ts'2010-01-01 10:10:10'}; +EXPLAIN EXTENDED SELECT TIMESTAMP'2010-01-01 10:10:10'; + +--echo # +--echo # Testing nanosecond rounding for TIMESTAMP literals with bad dates +--echo # +SELECT TIMESTAMP'2001-00-00 00:00:00.999999'; +SELECT TIMESTAMP'2001-00-01 00:00:00.999999'; +SELECT TIMESTAMP'2001-01-00 00:00:00.999999'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2001-00-00 00:00:00.9999999'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2001-00-01 00:00:00.9999999'; +--error ER_WRONG_VALUE +SELECT TIMESTAMP'2001-01-00 00:00:00.9999999'; + +--echo # +--echo # String literal with bad dates and nanoseconds to DATETIME(N) +--echo # +CREATE TABLE t1 (a DATETIME(6)); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME(5)); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME); +INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); +INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Testing Item_date_literal::eq +--echo # +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2001-01-01'),('2003-01-01'); +SELECT * FROM t1 WHERE a BETWEEN DATE'2001-01-01' AND DATE'2002-01-01'; +SELECT DATE'2001-01-01' FROM t1 GROUP BY DATE'2001-01-01'; +DROP TABLE t1; + +--echo # +--echo # TIME literals in no-zero date context +--echo # +SELECT TO_DAYS(TIME'00:00:00'); +SELECT TO_SECONDS(TIME'00:00:00'); +SELECT DAYOFYEAR(TIME'00:00:00'); +SELECT WEEK(TIME'00:00:00'); +SELECT YEARWEEK(TIME'00:00:00'); +SELECT WEEKDAY(TIME'00:00:00'); +SELECT CONVERT_TZ(TIME'00:00:00','+00:00','+01:00'); +SELECT DATE_ADD(TIME'00:00:00', INTERVAL 1 HOUR); +SELECT TIMESTAMPDIFF(SECOND,TIME'00:00:00', TIME'00:00:00'); + +--echo # +--echo # Testing Item_func::fix_fields() +--echo # +--error ER_WRONG_ARGUMENTS +SELECT 'a' LIKE 'a' ESCAPE DATE'2001-01-01'; +--error ER_WRONG_ARGUMENTS +SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00'; +--error ER_WRONG_ARGUMENTS +SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00'; diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index d1648254fb2..05bc72291cd 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -471,6 +471,21 @@ insert into t1 values ('2000-12-03','22:55:23'),('2008-05-03','10:19:31'); select case when d = '2012-12-12' then d else t end as cond, group_concat( d ) from t1 group by cond; drop table t1; +--echo # +--echo # Semantics of the condition IS NULL +--echo # when the field belongs to an inner table of an outer join +--echo # + +create table t1 (a int, b date not null); +insert t1 values (1, 0), (2, '1999-01-02'); +create table t2 (c int); +insert t2 values (1),(3); + +select * from t2 left join t1 on t1.a=t2.c where t1.a is null; +select * from t2 left join t1 on t1.a=t2.c where t1.b is null; + +drop table t1,t2; + --echo End of 5.3 tests --echo # diff --git a/mysql-test/t/type_temporal_mysql56.test b/mysql-test/t/type_temporal_mysql56.test new file mode 100644 index 00000000000..98529bfe1c1 --- /dev/null +++ b/mysql-test/t/type_temporal_mysql56.test @@ -0,0 +1,23 @@ + +let $MYSQLD_DATADIR= `select @@datadir`; +--copy_file std_data/mysql56time.frm $MYSQLD_DATADIR/test/mysql56time.frm +--copy_file std_data/mysql56time.MYD $MYSQLD_DATADIR/test/mysql56time.MYD +--copy_file std_data/mysql56time.MYI $MYSQLD_DATADIR/test/mysql56time.MYI +SHOW CREATE TABLE mysql56time; +--query_vertical SELECT * FROM mysql56time +DROP TABLE mysql56time; + +--copy_file std_data/mysql56datetime.frm $MYSQLD_DATADIR/test/mysql56datetime.frm +--copy_file std_data/mysql56datetime.MYD $MYSQLD_DATADIR/test/mysql56datetime.MYD +--copy_file std_data/mysql56datetime.MYI $MYSQLD_DATADIR/test/mysql56datetime.MYI +SHOW CREATE TABLE mysql56datetime; +--query_vertical SELECT * FROM mysql56datetime +DROP TABLE mysql56datetime; + +--copy_file std_data/mysql56timestamp.frm $MYSQLD_DATADIR/test/mysql56timestamp.frm +--copy_file std_data/mysql56timestamp.MYD $MYSQLD_DATADIR/test/mysql56timestamp.MYD +--copy_file std_data/mysql56timestamp.MYI $MYSQLD_DATADIR/test/mysql56timestamp.MYI +SET TIME_ZONE='+00:00'; +SHOW CREATE TABLE mysql56timestamp; +--query_vertical SELECT * FROM mysql56timestamp +DROP TABLE mysql56timestamp; diff --git a/mysql-test/t/varbinary.test b/mysql-test/t/varbinary.test index 1f9f7b5412d..f03f3fcf703 100644 --- a/mysql-test/t/varbinary.test +++ b/mysql-test/t/varbinary.test @@ -13,7 +13,30 @@ drop table if exists t1; select 0x41,0x41+0,0x41 | 0x7fffffffffffffff | 0,0xffffffffffffffff | 0 ; select 0x31+1,concat(0x31)+1,-0xf; -select x'31',X'ffff'+0; +select x'31',0xffff+0; +select X'FFFF'+0; + +# +# Hex string vs hex hybrid +# +SELECT x'31'+0, 0x31+0; +SELECT x'31'+0.1e0, 0x31+0.1e0; +SELECT x'312E39'+0e0, 0x312E39+0e0; +SELECT CAST(x'31' AS SIGNED), CAST(0x31 AS SIGNED); +SELECT CAST(x'31' AS DECIMAL(10,1)), CAST(0x31 AS DECIMAL(10,1)); +SELECT CAST(x'312E39' AS SIGNED), CAST(0x312E39 AS SIGNED); +SELECT CAST(x'312E39' AS DECIMAL(10,1)), CAST(0x312E39 AS DECIMAL(10,1)); +EXPLAIN EXTENDED SELECT X'FFFF', 0xFFFF; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (X'31'),(0x31); +INSERT INTO t1 VALUES (X'312E39'),(0x312E39); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL(10,1)); +INSERT INTO t1 VALUES (X'31'),(0x31); +INSERT INTO t1 VALUES (X'312E39'),(0x312E39); +SELECT * FROM t1; +DROP TABLE t1; # # Test of hex constants in WHERE: @@ -115,7 +138,7 @@ select 0x41; select b'01000001'; -select x'41', 0+x'41'; +select x'41', 0+x'3635'; select N'abc', length(N'abc'); diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 08e7e68c225..244c5f039fa 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -1522,4 +1522,16 @@ set session collation_connection=2048; --error ER_UNKNOWN_COLLATION set session collation_database=2048; +# +# Bug #16044655 CRASH: SETTING DEFAULT VALUE FOR SOME VARIABLES +# +--error ER_NO_DEFAULT +set session rand_seed1=DEFAULT; + +# +# Bug #14211565 CRASH WHEN ATTEMPTING TO SET SYSTEM VARIABLE TO RESULT OF VALUES() +# +--error ER_BAD_FIELD_ERROR +set autocommit = values(v); + --echo End of 5.5 tests diff --git a/mysys/errors.c b/mysys/errors.c index ebbdc410901..11e7d04e79e 100644 --- a/mysys/errors.c +++ b/mysys/errors.c @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates - Copyright (c) 1995, 2012 Monty Program Ab + Copyright (c) 2000, 2013, Oracle and/or its affiliates + Copyright (c) 1995, 2013, 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/mf_format.c b/mysys/mf_format.c index 2b2356c08df..d20ce882459 100644 --- a/mysys/mf_format.c +++ b/mysys/mf_format.c @@ -46,7 +46,7 @@ char * fn_format(char * to, const char *name, const char *dir, else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev)) { /* Put 'dir' before the given path */ - strmake(buff,dev,sizeof(buff)-1); + strmake_buf(buff, dev); pos=convert_dirname(dev,dir,NullS); strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev)); } diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 30f269454c2..5b52998f3ca 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -553,7 +553,8 @@ int init_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, uint key_cache_block_si if (blocks < 8) { my_errno= ENOMEM; - my_error(EE_OUTOFMEMORY, MYF(0), blocks * keycache->key_cache_block_size); + my_error(EE_OUTOFMEMORY, MYF(ME_FATALERROR), + blocks * keycache->key_cache_block_size); goto err; } blocks= blocks / 4*3; diff --git a/mysys/my_lockmem.c b/mysys/my_lockmem.c index 8f06192d9f8..2e036936c70 100644 --- a/mysys/my_lockmem.c +++ b/mysys/my_lockmem.c @@ -43,7 +43,7 @@ uchar *my_malloc_lock(uint size,myf MyFlags) if (!(ptr=memalign(pagesize,size))) { if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),size); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_FATALERROR), size); DBUG_RETURN(0); } success = mlock((uchar*) ptr,size); diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index 5a84b051a23..2f3a5276a59 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -1,5 +1,6 @@ /* Copyright (c) 2000, 2010, Oracle and/or its affiliates + Copyright (c) 2009, 2013, 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 @@ -104,11 +105,8 @@ void *my_malloc(size_t size, myf my_flags) if (my_flags & MY_FAE) error_handler_hook=fatal_error_handler_hook; if (my_flags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, - MYF(ME_BELL | ME_WAITTANG | ME_NOREFRESH | (my_flags & ME_JUST_INFO)), - size); - DBUG_EXECUTE_IF("simulate_out_of_memory", - DBUG_SET("-d,simulate_out_of_memory");); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL + ME_WAITTANG + + ME_NOREFRESH + ME_FATALERROR),size); if (my_flags & MY_FAE) exit(1); } @@ -175,7 +173,7 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags) DBUG_RETURN(oldpoint); my_errno=errno; if (my_flags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), size); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL + ME_WAITTANG + ME_FATALERROR), size); } else { diff --git a/mysys/my_once.c b/mysys/my_once.c index 7df9b0a1981..b9232db9b2e 100644 --- a/mysys/my_once.c +++ b/mysys/my_once.c @@ -59,7 +59,7 @@ void* my_once_alloc(size_t Size, myf MyFlags) { my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),get_size); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_FATALERROR), get_size); return((uchar*) 0); } DBUG_PRINT("test",("my_once_malloc %lu byte malloced", (ulong) get_size)); diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 4e5bed84637..270cbc2f882 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -449,7 +449,7 @@ const char *my_thread_name(void) { my_thread_id id= my_thread_dbug_id(); sprintf(name_buff,"T@%lu", (ulong) id); - strmake(tmp->name,name_buff,THREAD_NAME_SIZE); + strmake_buf(tmp->name, name_buff); } return tmp->name; } diff --git a/mysys/my_write.c b/mysys/my_write.c index 3c94fab2ec7..a7985997036 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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/thr_alarm.c b/mysys/thr_alarm.c index 9c21033eca4..7fd87edda6c 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -66,6 +66,8 @@ static QUEUE alarm_queue; static uint max_used_alarms=0; pthread_t alarm_thread; +#define MY_THR_ALARM_QUEUE_EXTENT 10 + #ifdef USE_ALARM_THREAD static void *alarm_handler(void *arg); #define reschedule_alarms() mysql_cond_signal(&COND_alarm) @@ -89,7 +91,8 @@ void init_thr_alarm(uint max_alarms) alarm_aborted=0; next_alarm_expire_time= ~ (time_t) 0; init_queue(&alarm_queue, max_alarms+1, offsetof(ALARM,expire_time), 0, - compare_ulong, NullS, offsetof(ALARM, index_in_queue)+1, 0); + compare_ulong, NullS, offsetof(ALARM, index_in_queue)+1, + MY_THR_ALARM_QUEUE_EXTENT); sigfillset(&full_signal_set); /* Neaded to block signals */ mysql_mutex_init(key_LOCK_alarm, &LOCK_alarm, MY_MUTEX_INIT_FAST); mysql_cond_init(key_COND_alarm, &COND_alarm, NULL); @@ -140,7 +143,10 @@ void resize_thr_alarm(uint max_alarms) than max_alarms */ if (alarm_queue.elements < max_alarms) + { resize_queue(&alarm_queue,max_alarms+1); + max_used_alarms= alarm_queue.elements; + } mysql_mutex_unlock(&LOCK_alarm); } @@ -209,16 +215,10 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data) mysql_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */ if (alarm_queue.elements >= max_used_alarms) { - if (alarm_queue.elements == alarm_queue.max_elements) - { - DBUG_PRINT("info", ("alarm queue full")); - fprintf(stderr,"Warning: thr_alarm queue is full\n"); - goto abort; - } max_used_alarms=alarm_queue.elements+1; } reschedule= (ulong) next_alarm_expire_time > (ulong) next; - queue_insert(&alarm_queue,(uchar*) alarm_data); + queue_insert_safe(&alarm_queue, (uchar*) alarm_data); assert(alarm_data->index_in_queue > 0); /* Reschedule alarm if the current one has more than sec left */ @@ -238,11 +238,6 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data) (*alrm)= &alarm_data->alarmed; DBUG_RETURN(0); -abort: - if (alarm_data->malloced) - my_free(alarm_data); - mysql_mutex_unlock(&LOCK_alarm); - one_signal_hand_sigmask(SIG_SETMASK,&old_mask,NULL); abort_no_unlock: *alrm= 0; /* No alarm */ DBUG_RETURN(1); diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index 17cda782b30..c70aa342802 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -132,7 +132,7 @@ void safe_mutex_global_init(void) #ifdef SAFE_MUTEX_DETECT_DESTROY safe_mutex_create_root= 0; -#endif +#endif /* SAFE_MUTEX_DETECT_DESTROY */ } static inline void remove_from_active_list(safe_mutex_t *mp) @@ -553,7 +553,7 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, "on %s at %s, line %d\n", error, errno, mp->name, file, line); } -#endif +#endif /* EXTRA_DEBUG */ pthread_mutex_lock(&mp->global); /* Restore state as it was before */ mp->thread= save_state.thread; @@ -612,7 +612,7 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line) error=1; if (pthread_mutex_destroy(&mp->mutex)) error=1; -#endif +#endif /* __WIN__ */ mp->file= 0; /* Mark destroyed */ #ifdef SAFE_MUTEX_DETECT_DESTROY @@ -838,7 +838,7 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex, DBUG_VOID_RETURN; } -#elif defined(MY_PTHREAD_FASTMUTEX) +#elif defined(MY_PTHREAD_FASTMUTEX) /* !SAFE_MUTEX_DEFINED */ static ulong mutex_delay(ulong delayloops) { @@ -922,4 +922,4 @@ void fastmutex_global_init(void) #endif } -#endif /* defined(MY_PTHREAD_FASTMUTEX) */ +#endif /* defined(MY_PTHREAD_FASTMUTEX) && defined(SAFE_MUTEX_DEFINED) */ diff --git a/packaging/WiX/mysql_server.wxs.in b/packaging/WiX/mysql_server.wxs.in index 370830d82db..752dc15304e 100644 --- a/packaging/WiX/mysql_server.wxs.in +++ b/packaging/WiX/mysql_server.wxs.in @@ -34,8 +34,9 @@ Languages='1033' Compressed='yes' SummaryCodepage='1252' - Platform='@Platform@'/> - + Platform='@Platform@' + InstallScope="perMachine"/> + @@ -44,11 +45,13 @@ Minimum="@MAJOR_VERSION@.@MINOR_VERSION@.0" IncludeMinimum="yes" Maximum="@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@" + IncludeMaximum="yes" Property="OLDERVERSIONBEINGUPGRADED" MigrateFeatures="yes" /> diff --git a/packaging/rpm-uln/mysql.spec.sh b/packaging/rpm-uln/mysql.spec.sh index 3e2c5c3f11c..ec195bc9e16 100644 --- a/packaging/rpm-uln/mysql.spec.sh +++ b/packaging/rpm-uln/mysql.spec.sh @@ -268,11 +268,12 @@ Requires: bash Provides: mysql # MySQL (with caps) is upstream's spelling of their own RPMs for mysql -Conflicts: MySQL +Obsoletes: MySQL # mysql-cluster used to be built from this SRPM, but no more Obsoletes: mysql-cluster < 5.1.44 # We need cross-product "Obsoletes:" to allow cross-product upgrades: -Obsoletes: mysql mysql-advanced +Obsoletes: mysql < %{version}-%{release} +Obsoletes: mysql-advanced < %{version}-%{release} # Working around perl dependency checking bug in rpm FTTB. Remove later. %global __perl_requires %{SOURCE999} @@ -295,8 +296,9 @@ further info. Summary: The shared libraries required for MySQL clients Group: Applications/Databases Requires: /sbin/ldconfig +Obsoletes: mysql-libs < %{version}-%{release} +Obsoletes: mysql-libs-advanced < %{version}-%{release} Provides: mysql-libs -Obsoletes: mysql-libs mysql-libs-advanced %description -n mysql-libs%{product_suffix} The mysql-libs package provides the essential shared libraries for any @@ -318,9 +320,10 @@ Requires(preun): initscripts Requires(postun): initscripts # mysqlhotcopy needs DBI/DBD support Requires: perl-DBI, perl-DBD-MySQL +Obsoletes: MySQL-server +Obsoletes: mysql-server < %{version}-%{release} +Obsoletes: mysql-server-advanced < %{version}-%{release} Provides: mysql-server -Conflicts: MySQL-server -Obsoletes: mysql-server mysql-server-advanced %description -n mysql-server%{product_suffix} MySQL is a multi-user, multi-threaded SQL database server. MySQL is a @@ -334,9 +337,10 @@ Summary: Files for development of MySQL applications Group: Applications/Databases Requires: mysql%{product_suffix} = %{version}-%{release} Requires: openssl-devel +Obsoletes: MySQL-devel +Obsoletes: mysql-devel < %{version}-%{release} +Obsoletes: mysql-devel-advanced < %{version}-%{release} Provides: mysql-devel -Conflicts: MySQL-devel -Obsoletes: mysql-devel mysql-devel-advanced %description -n mysql-devel%{product_suffix} MySQL is a multi-user, multi-threaded SQL database server. This @@ -347,8 +351,9 @@ developing MySQL client applications. Summary: MySQL as an embeddable library Group: Applications/Databases +Obsoletes: mysql-embedded < %{version}-%{release} +Obsoletes: mysql-embedded-advanced < %{version}-%{release} Provides: mysql-embedded -Obsoletes: mysql-embedded mysql-embedded-advanced %description -n mysql-embedded%{product_suffix} MySQL is a multi-user, multi-threaded SQL database server. This @@ -362,8 +367,9 @@ Summary: Development files for MySQL as an embeddable library Group: Applications/Databases Requires: mysql-embedded%{product_suffix} = %{version}-%{release} Requires: mysql-devel%{product_suffix} = %{version}-%{release} +Obsoletes: mysql-embedded-devel < %{version}-%{release} +Obsoletes: mysql-embedded-devel-advanced < %{version}-%{release} Provides: mysql-embedded-devel -Obsoletes: mysql-embedded-devel mysql-embedded-devel-advanced %description -n mysql-embedded-devel%{product_suffix} MySQL is a multi-user, multi-threaded SQL database server. This @@ -376,9 +382,10 @@ Summary: The test suite distributed with MySQL Group: Applications/Databases Requires: mysql%{product_suffix} = %{version}-%{release} Requires: mysql-server%{product_suffix} = %{version}-%{release} +Obsoletes: MySQL-test +Obsoletes: mysql-test < %{version}-%{release} +Obsoletes: mysql-test-advanced < %{version}-%{release} Provides: mysql-test -Conflicts: MySQL-test -Obsoletes: mysql-test mysql-test-advanced %description -n mysql-test%{product_suffix} MySQL is a multi-user, multi-threaded SQL database server. This diff --git a/plugin/audit_null/audit_null.c b/plugin/audit_null/audit_null.c index 0616f192f20..2747063670c 100644 --- a/plugin/audit_null/audit_null.c +++ b/plugin/audit_null/audit_null.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. + Copyright (c) 2012, 2013, 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 @@ -22,11 +23,16 @@ #define __attribute__(A) #endif -static volatile int number_of_calls; /* for SHOW STATUS, see below */ -static volatile int number_of_calls_general_log; -static volatile int number_of_calls_general_error; -static volatile int number_of_calls_general_result; +#ifdef _MSC_VER +#define snprintf _snprintf +#endif +static volatile int ncalls; /* for SHOW STATUS, see below */ +static volatile int ncalls_general_log; +static volatile int ncalls_general_error; +static volatile int ncalls_general_result; + +FILE *f; /* Initialize the plugin at server start or plugin installation. @@ -44,11 +50,16 @@ static volatile int number_of_calls_general_result; static int audit_null_plugin_init(void *arg __attribute__((unused))) { - number_of_calls= 0; - number_of_calls_general_log= 0; - number_of_calls_general_error= 0; - number_of_calls_general_result= 0; - return(0); + ncalls= 0; + ncalls_general_log= 0; + ncalls_general_error= 0; + ncalls_general_result= 0; + + f = fopen("audit_null_tables.log", "w"); + if (!f) + return 1; + + return 0; } @@ -67,7 +78,8 @@ static int audit_null_plugin_init(void *arg __attribute__((unused))) static int audit_null_plugin_deinit(void *arg __attribute__((unused))) { - return(0); + fclose(f); + return 0; } @@ -86,7 +98,7 @@ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)), const void *event) { /* prone to races, oh well */ - number_of_calls++; + ncalls++; if (event_class == MYSQL_AUDIT_GENERAL_CLASS) { const struct mysql_event_general *event_general= @@ -94,18 +106,56 @@ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)), switch (event_general->event_subclass) { case MYSQL_AUDIT_GENERAL_LOG: - number_of_calls_general_log++; + ncalls_general_log++; + fprintf(f, "%s\t>> %s\n", event_general->general_user, + event_general->general_query); break; case MYSQL_AUDIT_GENERAL_ERROR: - number_of_calls_general_error++; + ncalls_general_error++; break; case MYSQL_AUDIT_GENERAL_RESULT: - number_of_calls_general_result++; + ncalls_general_result++; break; default: break; } } + else + if (event_class == MYSQL_AUDIT_TABLE_CLASS) + { + const struct mysql_event_table *event_table= + (const struct mysql_event_table *) event; + const char *ip= event_table->ip ? event_table->ip : ""; + const char *op= 0; + char buf[1024]; + + switch (event_table->event_subclass) + { + case MYSQL_AUDIT_TABLE_LOCK: + op= event_table->read_only ? "read" : "write"; + break; + case MYSQL_AUDIT_TABLE_CREATE: + op= "create"; + break; + case MYSQL_AUDIT_TABLE_DROP: + op= "drop"; + break; + case MYSQL_AUDIT_TABLE_ALTER: + op= "alter"; + break; + case MYSQL_AUDIT_TABLE_RENAME: + snprintf(buf, sizeof(buf), "rename to %s.%s", + event_table->new_database, event_table->new_table); + buf[sizeof(buf)-1]= 0; + op= buf; + break; + } + + fprintf(f, "%s[%s] @ %s [%s]\t%s.%s : %s\n", + event_table->priv_user, event_table->user, + event_table->host, ip, + event_table->database, event_table->table, op); + } } @@ -115,10 +165,8 @@ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)), static struct st_mysql_audit audit_null_descriptor= { - MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */ - NULL, /* release_thd function */ - audit_null_notify, /* notify function */ - { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK } /* class mask */ + MYSQL_AUDIT_INTERFACE_VERSION, NULL, audit_null_notify, + { MYSQL_AUDIT_GENERAL_CLASSMASK | MYSQL_AUDIT_TABLE_CLASSMASK } }; /* @@ -127,10 +175,10 @@ static struct st_mysql_audit audit_null_descriptor= static struct st_mysql_show_var simple_status[]= { - { "called", (char *) &number_of_calls, SHOW_INT }, - { "general_log", (char *) &number_of_calls_general_log, SHOW_INT }, - { "general_error", (char *) &number_of_calls_general_error, SHOW_INT }, - { "general_result", (char *) &number_of_calls_general_result, SHOW_INT }, + { "called", (char *) &ncalls, SHOW_INT }, + { "general_error", (char *) &ncalls_general_error, SHOW_INT }, + { "general_log", (char *) &ncalls_general_log, SHOW_INT }, + { "general_result", (char *) &ncalls_general_result, SHOW_INT }, { 0, 0, 0} }; diff --git a/plugin/qc_info/qc_info.cc b/plugin/qc_info/qc_info.cc index af13b6edf93..8489b14c5db 100644 --- a/plugin/qc_info/qc_info.cc +++ b/plugin/qc_info/qc_info.cc @@ -83,7 +83,7 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables, return 0; if (qc->try_lock(thd)) - return status; + return 0; // QC is or is being disabled /* loop through all queries in the query cache */ for (uint i= 0; i < queries->records; i++) diff --git a/regex/my_regex.h b/regex/my_regex.h index 30896e29b91..1f96b8c461e 100644 --- a/regex/my_regex.h +++ b/regex/my_regex.h @@ -28,7 +28,7 @@ typedef struct { /* === regcomp.c === */ -typedef int (*my_regex_stack_check_t)(); +typedef int (*my_regex_stack_check_t)(int); extern int my_regcomp(my_regex_t *, const char *, int, CHARSET_INFO *charset); #define REG_BASIC 0000 #define REG_EXTENDED 0001 diff --git a/regex/regcomp.c b/regex/regcomp.c index 6e2d2511fc1..abc18174f56 100644 --- a/regex/regcomp.c +++ b/regex/regcomp.c @@ -227,7 +227,7 @@ int stop; /* character this ERE should end at */ while (MORE() && (c = PEEK()) != '|' && c != stop) { if (my_regex_enough_mem_in_stack && - my_regex_enough_mem_in_stack()) + my_regex_enough_mem_in_stack(0)) { SETERROR(REG_ESPACE); return; diff --git a/scripts/mysql_system_tables_data.sql b/scripts/mysql_system_tables_data.sql index 878555e9458..a222d22b670 100644 --- a/scripts/mysql_system_tables_data.sql +++ b/scripts/mysql_system_tables_data.sql @@ -1,5 +1,4 @@ --- Copyright (c) 2007 MySQL AB, 2008 Sun Microsystems, Inc. --- Use is subject to license terms. +-- Copyright (c) 2007, 2013, Oracle and/or its affiliates. -- -- 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 @@ -21,7 +20,12 @@ -- When setting up a "cross bootstrap" database (e.g., creating data on a Unix -- host which will later be included in a Windows zip file), any lines -- containing "@current_hostname" are filtered out by mysql_install_db. -set @current_hostname= @@hostname; + +-- Get the hostname, if the hostname has any wildcard character like "_" or "%" +-- add escape character in front of wildcard character to convert "_" or "%" to +-- a plain character +SET @get_hostname= @@hostname; +SELECT REPLACE((SELECT REPLACE(@get_hostname,'_','\_')),'%','\%') INTO @current_hostname; -- Fill "db" table with default grants for anyone to @@ -33,10 +37,9 @@ INSERT INTO db SELECT * FROM tmp_db WHERE @had_db_table=0; DROP TABLE tmp_db; --- Fill "users" table with default users allowing root access --- from local machine if "users" table didn't exist before +-- Fill "user" table with default users allowing root access +-- from local machine if "user" table didn't exist before CREATE TEMPORARY TABLE tmp_user LIKE user; -set @current_hostname= @@hostname; INSERT INTO tmp_user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'',''); REPLACE INTO tmp_user SELECT @current_hostname,'root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'','' FROM dual WHERE LOWER( @current_hostname) != 'localhost'; REPLACE INTO tmp_user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'',''); diff --git a/sql-common/client.c b/sql-common/client.c index b00f1c5dc66..a3df782a937 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -803,7 +803,7 @@ restart: len-=2; if (protocol_41(mysql) && pos[0] == '#') { - strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + strmake_buf(net->sqlstate, pos+1); pos+= SQLSTATE_LENGTH+1; } else @@ -3173,7 +3173,7 @@ 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); + strmake_buf(UNIXaddr.sun_path, unix_socket); if (connect_sync_or_async(mysql, net, sock, (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr))) { diff --git a/sql-common/my_time.c b/sql-common/my_time.c index d4093bb4df9..b19f4d1d149 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -203,6 +203,46 @@ static uint skip_digits(const char **str, const char *end) return s - start; } + +/** + Check datetime, date, or normalized time (i.e. time without days) range. + @param ltime Datetime value. + @returns + @retval FALSE on success + @retval TRUE on error +*/ +my_bool check_datetime_range(const MYSQL_TIME *ltime) +{ + /* + In case of MYSQL_TIMESTAMP_TIME hour value can be up to TIME_MAX_HOUR. + In case of MYSQL_TIMESTAMP_DATETIME it cannot be bigger than 23. + */ + return + ltime->year > 9999 || ltime->month > 12 || ltime->day > 31 || + ltime->minute > 59 || ltime->second > 59 || + ltime->second_part > TIME_MAX_SECOND_PART || + (ltime->hour > + (ltime->time_type == MYSQL_TIMESTAMP_TIME ? TIME_MAX_HOUR : 23)); +} + + +static void get_microseconds(ulong *val, MYSQL_TIME_STATUS *status, + uint *number_of_fields, + const char **str, const char *end) +{ + const char *start= *str; + uint tmp= 0; /* For the case '10:10:10.' */ + if (get_digits(&tmp, number_of_fields, str, end, 6)) + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; + if ((status->precision= (*str - start)) < 6) + *val= tmp * log_10_int[6 - (*str - start)]; + else + *val= tmp; + if (skip_digits(str, end)) + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; +} + + /* Convert a timestamp string to a MYSQL_TIME value. @@ -217,9 +257,8 @@ static uint skip_digits(const char **str, const char *end) TIME_NO_ZERO_IN_DATE Don't allow partial dates TIME_NO_ZERO_DATE Don't allow 0000-00-00 date TIME_INVALID_DATES Allow 2000-02-31 - was_cut 0 Value OK - 1 If value was cut during conversion - 2 check_date(date,flags) considers date invalid + status Conversion status + DESCRIPTION At least the following formats are recogniced (based on number of digits) @@ -230,20 +269,29 @@ static uint skip_digits(const char **str, const char *end) The second part may have an optional .###### fraction part. - RETURN VALUES + status->warnings is set to: + 0 Value OK + MYSQL_TIME_WARN_TRUNCATED If value was cut during conversion + MYSQL_TIME_WARN_OUT_OF_RANGE check_date(date,flags) considers date invalid + + l_time->time_type is set as follows: MYSQL_TIMESTAMP_NONE String wasn't a timestamp, like [DD [HH:[MM:[SS]]]].fraction. + l_time is not changed. MYSQL_TIMESTAMP_DATE DATE string (YY MM and DD parts ok) MYSQL_TIMESTAMP_DATETIME Full timestamp MYSQL_TIMESTAMP_ERROR Timestamp with wrong values. All elements in l_time is set to 0 + RETURN VALUES + 0 - Ok + 1 - Error */ #define MAX_DATE_PARTS 8 -enum enum_mysql_timestamp_type +my_bool str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, - ulonglong flags, int *was_cut) + ulonglong flags, MYSQL_TIME_STATUS *status) { const char *end=str+length, *pos; uint number_of_fields= 0, digits, year_length, not_zero_date; @@ -252,19 +300,20 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, if (flags & TIME_TIME_ONLY) { - enum enum_mysql_timestamp_type ret; - ret= str_to_time(str, length, l_time, flags, was_cut); + my_bool ret= str_to_time(str, length, l_time, flags, status); DBUG_RETURN(ret); } - *was_cut= 0; + + my_time_status_init(status); /* Skip space at start */ for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++) ; if (str == end || ! my_isdigit(&my_charset_latin1, *str)) { - *was_cut= 1; - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); + status->warnings= MYSQL_TIME_WARN_TRUNCATED; + l_time->time_type= MYSQL_TIMESTAMP_NONE; + DBUG_RETURN(1); } /* @@ -293,50 +342,49 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, (only numbers like [YY]YYMMDD[T][hhmmss[.uuuuuu]]) */ year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; - *was_cut= get_digits(&l_time->year, &number_of_fields, &str, end, year_length) - || get_digits(&l_time->month, &number_of_fields, &str, end, 2) - || get_digits(&l_time->day, &number_of_fields, &str, end, 2) - || get_maybe_T(&str, end) - || get_digits(&l_time->hour, &number_of_fields, &str, end, 2) - || get_digits(&l_time->minute, &number_of_fields, &str, end, 2) - || get_digits(&l_time->second, &number_of_fields, &str, end, 2); + if (get_digits(&l_time->year, &number_of_fields, &str, end, year_length) + || get_digits(&l_time->month, &number_of_fields, &str, end, 2) + || get_digits(&l_time->day, &number_of_fields, &str, end, 2) + || get_maybe_T(&str, end) + || get_digits(&l_time->hour, &number_of_fields, &str, end, 2) + || get_digits(&l_time->minute, &number_of_fields, &str, end, 2) + || get_digits(&l_time->second, &number_of_fields, &str, end, 2)) + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; } else { const char *start= str; - *was_cut = get_number(&l_time->year, &number_of_fields, &str, end); + if (get_number(&l_time->year, &number_of_fields, &str, end)) + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; year_length= str - start; - if (!*was_cut) - *was_cut= get_punct(&str, end) - || get_number(&l_time->month, &number_of_fields, &str, end) - || get_punct(&str, end) - || get_number(&l_time->day, &number_of_fields, &str, end) - || get_date_time_separator(&number_of_fields, flags, &str, end) - || get_number(&l_time->hour, &number_of_fields, &str, end) - || get_punct(&str, end) - || get_number(&l_time->minute, &number_of_fields, &str, end) - || get_punct(&str, end) - || get_number(&l_time->second, &number_of_fields, &str, end); + if (!status->warnings && + (get_punct(&str, end) + || get_number(&l_time->month, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->day, &number_of_fields, &str, end) + || get_date_time_separator(&number_of_fields, flags, &str, end) + || get_number(&l_time->hour, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->minute, &number_of_fields, &str, end) + || get_punct(&str, end) + || get_number(&l_time->second, &number_of_fields, &str, end))) + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; } - if (number_of_fields < 3) - *was_cut= 1; - /* we're ok if date part is correct. even if the rest is truncated */ - if (*was_cut && number_of_fields < 3) - DBUG_RETURN(MYSQL_TIMESTAMP_NONE); - - if (!*was_cut && str < end && *str == '.') + if (number_of_fields < 3) { - uint second_part; - const char *start= ++str; - *was_cut= get_digits(&second_part, &number_of_fields, &str, end, 6); - if (str - start < 6) - second_part*= log_10_int[6 - (str - start)]; - l_time->second_part= second_part; - if (skip_digits(&str, end)) - *was_cut= 1; + l_time->time_type= MYSQL_TIMESTAMP_NONE; + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; + DBUG_RETURN(TRUE); + } + + if (!status->warnings && str < end && *str == '.') + { + str++; + get_microseconds(&l_time->second_part, status, + &number_of_fields, &str, end); } not_zero_date = l_time->year || l_time->month || l_time->day || @@ -349,11 +397,11 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, if (l_time->year > 9999 || l_time->month > 12 || l_time->day > 31 || l_time->hour > 23 || l_time->minute > 59 || l_time->second > 59) { - *was_cut= 1; + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; goto err; } - if (check_date(l_time, not_zero_date, flags, was_cut)) + if (check_date(l_time, not_zero_date, flags, &status->warnings)) goto err; l_time->time_type= (number_of_fields <= 3 ? @@ -363,16 +411,17 @@ str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, { if (!my_isspace(&my_charset_latin1,*str)) { - *was_cut= 1; + status->warnings= MYSQL_TIME_WARN_TRUNCATED; break; } } - DBUG_RETURN(l_time->time_type); + DBUG_RETURN(FALSE); err: bzero((char*) l_time, sizeof(*l_time)); - DBUG_RETURN(MYSQL_TIMESTAMP_ERROR); + l_time->time_type= MYSQL_TIMESTAMP_ERROR; + DBUG_RETURN(TRUE); } @@ -387,23 +436,26 @@ err: There may be an optional [.second_part] after seconds length Length of str l_time Store result here - warning Set MYSQL_TIME_WARN_TRUNCATED flag if the input string - was cut during conversion, and/or - MYSQL_TIME_WARN_OUT_OF_RANGE flag, if the value is - out of range. + status Conversion status + NOTES + Because of the extra days argument, this function can only work with times where the time arguments are in the above order. + status->warnings is set as follows: + MYSQL_TIME_WARN_TRUNCATED if the input string was cut during conversion, + and/or + MYSQL_TIME_WARN_OUT_OF_RANGE flag is set if the value is out of range. + RETURN - MYSQL_TIMESTAMP_TIME - MYSQL_TIMESTAMP_ERROR + FALSE on success + TRUE on error */ -enum enum_mysql_timestamp_type -str_to_time(const char *str, uint length, MYSQL_TIME *l_time, - ulonglong fuzzydate, int *warning) +my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time, + ulonglong fuzzydate, MYSQL_TIME_STATUS *status) { ulong date[5]; ulonglong value; @@ -411,7 +463,7 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, my_bool found_days,found_hours, neg= 0; uint UNINIT_VAR(state); - *warning= 0; + my_time_status_init(status); for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++) length--; if (str != end && *str == '-') @@ -421,22 +473,20 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, length--; } if (str == end) - return MYSQL_TIMESTAMP_ERROR; + { + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; + goto err; + } /* Check first if this is a full TIMESTAMP */ if (length >= 12) { /* Probably full timestamp */ - int was_cut; - enum enum_mysql_timestamp_type - res= str_to_datetime(str, length, l_time, + (void) str_to_datetime(str, length, l_time, (fuzzydate & ~TIME_TIME_ONLY) | TIME_DATETIME_ONLY, - &was_cut); - if ((int) res >= (int) MYSQL_TIMESTAMP_ERROR) - { - if (was_cut) - *warning|= MYSQL_TIME_WARN_TRUNCATED; - return res; - } + status); + if (l_time->time_type >= MYSQL_TIMESTAMP_ERROR) + return l_time->time_type == MYSQL_TIMESTAMP_ERROR; + my_time_status_init(status); } l_time->neg= neg; @@ -504,24 +554,15 @@ str_to_time(const char *str, uint length, MYSQL_TIME *l_time, fractional: /* Get fractional second part */ - if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_latin1,str[1])) + if (!status->warnings && str < end && *str == '.') { - int field_length= 5; - str++; value=(uint) (uchar) (*str - '0'); - while (++str != end && my_isdigit(&my_charset_latin1, *str)) - { - if (field_length-- > 0) - value= value*10 + (uint) (uchar) (*str - '0'); - } - if (field_length > 0) - value*= (long) log_10_int[field_length]; - else if (field_length < 0) - *warning|= MYSQL_TIME_WARN_TRUNCATED; - date[4]= (ulong) value; + uint number_of_fields= 0; + str++; + get_microseconds(&date[4], status, &number_of_fields, &str, end); } else - date[4]=0; - + date[4]= 0; + /* Check for exponent part: E | E */ /* (may occur as result of %g formatting of time value) */ if ((end - str) > 1 && @@ -530,7 +571,10 @@ fractional: ((str[1] == '-' || str[1] == '+') && (end - str) > 2 && my_isdigit(&my_charset_latin1, str[2])))) - return MYSQL_TIMESTAMP_ERROR; + { + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; + goto err; + } if (internal_format_positions[7] != 255) { @@ -553,8 +597,11 @@ fractional: if (date[0] > UINT_MAX || date[1] > UINT_MAX || date[2] > UINT_MAX || date[3] > UINT_MAX || date[4] > UINT_MAX) - return MYSQL_TIMESTAMP_ERROR; - + { + status->warnings|= MYSQL_TIME_WARN_OUT_OF_RANGE; + goto err; + } + l_time->year= 0; /* For protocol::store_time */ l_time->month= 0; l_time->day= date[0]; @@ -565,9 +612,9 @@ fractional: l_time->time_type= MYSQL_TIMESTAMP_TIME; /* Check if the value is valid and fits into MYSQL_TIME range */ - if (check_time_range(l_time, 6, warning)) - return MYSQL_TIMESTAMP_ERROR; - + if (check_time_range(l_time, 6, &status->warnings)) + return TRUE; + /* Check if there is garbage at end of the MYSQL_TIME specification */ if (str != end) { @@ -575,12 +622,17 @@ fractional: { if (!my_isspace(&my_charset_latin1,*str)) { - *warning|= MYSQL_TIME_WARN_TRUNCATED; + status->warnings|= MYSQL_TIME_WARN_TRUNCATED; break; } } while (++str != end); } - return MYSQL_TIMESTAMP_TIME; + return FALSE; + +err: + bzero((char*) l_time, sizeof(*l_time)); + l_time->time_type= MYSQL_TIMESTAMP_ERROR; + return TRUE; } @@ -610,7 +662,10 @@ int check_time_range(struct st_mysql_time *my_time, uint dec, int *warning) 999000, 999900, 999990, 999999}; if (my_time->minute >= 60 || my_time->second >= 60) + { + *warning|= MYSQL_TIME_WARN_TRUNCATED; return 1; + } hour= my_time->hour + (24*my_time->day); @@ -1101,6 +1156,27 @@ int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, uint digits) } +/** + Print a timestamp with an optional fractional part: XXXXX[.YYYYY] + + @param tm The timestamp value to print. + @param OUT to The string pointer to print at. + @param dec Precision, in the range 0..6. + @return The length of the result string. +*/ +int my_timeval_to_str(const struct timeval *tm, char *to, uint dec) +{ + char *pos= longlong10_to_str((longlong) tm->tv_sec, to, 10); + if (dec) + { + *pos++= '.'; + pos= fmt_number((uint) sec_part_shift(tm->tv_usec, dec), pos, dec); + } + *pos= '\0'; + return (int) (pos - to); +} + + /* Convert datetime value specified as number to broken-down TIME representation and form value of DATETIME type as side-effect. @@ -1357,7 +1433,7 @@ double TIME_to_double(const MYSQL_TIME *my_time) return my_time->neg ? -d : d; } -longlong pack_time(MYSQL_TIME *my_time) +longlong pack_time(const MYSQL_TIME *my_time) { return ((((((my_time->year * 13ULL + my_time->month) * 32ULL + diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index ffd8fab16fd..ff566cefc33 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -54,7 +54,7 @@ IF(WITH_WSREP) ENDIF() SET (SQL_SOURCE - ../sql-common/client.c derror.cc des_key_file.cc + ../sql-common/client.c compat56.cc derror.cc des_key_file.cc discover.cc ../libmysql/errmsg.c field.cc field_conv.cc filesort_utils.cc filesort.cc gstream.cc sha2.cc @@ -294,12 +294,9 @@ ADD_CUSTOM_TARGET(distclean IF(INSTALL_LAYOUT STREQUAL "STANDALONE") -# We need to create empty directories (data/test) the installation. -# This does not work with current CPack due to http://www.cmake.org/Bug/view.php?id=8767 -# Avoid completely empty directories and install dummy file instead. -SET(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/db.opt ) -FILE(WRITE ${DUMMY_FILE} "") -INSTALL(FILES ${DUMMY_FILE} DESTINATION data/test COMPONENT DataFiles) +# Copy db.opt into data/test/ +SET(DBOPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/db.opt ) +INSTALL(FILES ${DBOPT_FILE} DESTINATION data/test COMPONENT DataFiles) # Install initial database on windows IF(NOT CMAKE_CROSSCOMPILING) diff --git a/sql/compat56.cc b/sql/compat56.cc new file mode 100644 index 00000000000..3bd6b21a154 --- /dev/null +++ b/sql/compat56.cc @@ -0,0 +1,445 @@ +/* + Copyright (c) 2004, 2012, Oracle and/or its affiliates. + Copyright (c) 2013, MariaDB Foundation. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "my_global.h" +#include "compat56.h" +#include "myisampack.h" +#include "my_time.h" + +/*** MySQL56 TIME low-level memory and disk representation routines ***/ + +/* + In-memory format: + + 1 bit sign (Used for sign, when on disk) + 1 bit unused (Reserved for wider hour range, e.g. for intervals) + 10 bit hour (0-836) + 6 bit minute (0-59) + 6 bit second (0-59) + 24 bits microseconds (0-999999) + + Total: 48 bits = 6 bytes + Suhhhhhh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff +*/ + + +/** + Convert time value to MySQL56 numeric packed representation. + + @param ltime The value to convert. + @return Numeric packed representation. +*/ +longlong TIME_to_longlong_time_packed(const MYSQL_TIME *ltime) +{ + /* If month is 0, we mix day with hours: "1 00:10:10" -> "24:00:10" */ + long hms= (((ltime->month ? 0 : ltime->day * 24) + ltime->hour) << 12) | + (ltime->minute << 6) | ltime->second; + longlong tmp= MY_PACKED_TIME_MAKE(hms, ltime->second_part); + return ltime->neg ? -tmp : tmp; +} + + + +/** + Convert MySQL56 time packed numeric representation to time. + + @param OUT ltime The MYSQL_TIME variable to set. + @param tmp The packed numeric representation. +*/ +void TIME_from_longlong_time_packed(MYSQL_TIME *ltime, longlong tmp) +{ + long hms; + if ((ltime->neg= (tmp < 0))) + tmp= -tmp; + hms= MY_PACKED_TIME_GET_INT_PART(tmp); + ltime->year= (uint) 0; + ltime->month= (uint) 0; + ltime->day= (uint) 0; + ltime->hour= (uint) (hms >> 12) % (1 << 10); /* 10 bits starting at 12th */ + ltime->minute= (uint) (hms >> 6) % (1 << 6); /* 6 bits starting at 6th */ + ltime->second= (uint) hms % (1 << 6); /* 6 bits starting at 0th */ + ltime->second_part= MY_PACKED_TIME_GET_FRAC_PART(tmp); + ltime->time_type= MYSQL_TIMESTAMP_TIME; +} + + +/** + Calculate binary size of MySQL56 packed numeric time representation. + + @param dec Precision. +*/ +uint my_time_binary_length(uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + return 3 + (dec + 1) / 2; +} + + +/* + On disk we convert from signed representation to unsigned + representation using TIMEF_OFS, so all values become binary comparable. +*/ +#define TIMEF_OFS 0x800000000000LL +#define TIMEF_INT_OFS 0x800000LL + + +/** + Convert MySQL56 in-memory numeric time representation to on-disk representation + + @param nr Value in packed numeric time format. + @param OUT ptr The buffer to put value at. + @param dec Precision. +*/ +void my_time_packed_to_binary(longlong nr, uchar *ptr, uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + /* Make sure the stored value was previously properly rounded or truncated */ + DBUG_ASSERT((MY_PACKED_TIME_GET_FRAC_PART(nr) % + (int) log_10_int[TIME_SECOND_PART_DIGITS - dec]) == 0); + + switch (dec) + { + case 0: + default: + mi_int3store(ptr, TIMEF_INT_OFS + MY_PACKED_TIME_GET_INT_PART(nr)); + break; + + case 1: + case 2: + mi_int3store(ptr, TIMEF_INT_OFS + MY_PACKED_TIME_GET_INT_PART(nr)); + ptr[3]= (unsigned char) (char) (MY_PACKED_TIME_GET_FRAC_PART(nr) / 10000); + break; + + case 4: + case 3: + mi_int3store(ptr, TIMEF_INT_OFS + MY_PACKED_TIME_GET_INT_PART(nr)); + mi_int2store(ptr + 3, MY_PACKED_TIME_GET_FRAC_PART(nr) / 100); + break; + + case 5: + case 6: + mi_int6store(ptr, nr + TIMEF_OFS); + break; + } +} + + +/** + Convert MySQL56 on-disk time representation to in-memory packed numeric + representation. + + @param ptr The pointer to read the value at. + @param dec Precision. + @return Packed numeric time representation. +*/ +longlong my_time_packed_from_binary(const uchar *ptr, uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + + switch (dec) + { + case 0: + default: + { + longlong intpart= mi_uint3korr(ptr) - TIMEF_INT_OFS; + return MY_PACKED_TIME_MAKE_INT(intpart); + } + case 1: + case 2: + { + longlong intpart= mi_uint3korr(ptr) - TIMEF_INT_OFS; + int frac= (uint) ptr[3]; + if (intpart < 0 && frac) + { + /* + Negative values are stored with reverse fractional part order, + for binary sort compatibility. + + Disk value intpart frac Time value Memory value + 800000.00 0 0 00:00:00.00 0000000000.000000 + 7FFFFF.FF -1 255 -00:00:00.01 FFFFFFFFFF.FFD8F0 + 7FFFFF.9D -1 99 -00:00:00.99 FFFFFFFFFF.F0E4D0 + 7FFFFF.00 -1 0 -00:00:01.00 FFFFFFFFFF.000000 + 7FFFFE.FF -1 255 -00:00:01.01 FFFFFFFFFE.FFD8F0 + 7FFFFE.F6 -2 246 -00:00:01.10 FFFFFFFFFE.FE7960 + + Formula to convert fractional part from disk format + (now stored in "frac" variable) to absolute value: "0x100 - frac". + To reconstruct in-memory value, we shift + to the next integer value and then substruct fractional part. + */ + intpart++; /* Shift to the next integer value */ + frac-= 0x100; /* -(0x100 - frac) */ + } + return MY_PACKED_TIME_MAKE(intpart, frac * 10000); + } + + case 3: + case 4: + { + longlong intpart= mi_uint3korr(ptr) - TIMEF_INT_OFS; + int frac= mi_uint2korr(ptr + 3); + if (intpart < 0 && frac) + { + /* + Fix reverse fractional part order: "0x10000 - frac". + See comments for FSP=1 and FSP=2 above. + */ + intpart++; /* Shift to the next integer value */ + frac-= 0x10000; /* -(0x10000-frac) */ + } + return MY_PACKED_TIME_MAKE(intpart, frac * 100); + } + + case 5: + case 6: + return ((longlong) mi_uint6korr(ptr)) - TIMEF_OFS; + } +} + + +/*** MySQL56 DATETIME low-level memory and disk representation routines ***/ + +/* + 1 bit sign (used when on disk) + 17 bits year*13+month (year 0-9999, month 0-12) + 5 bits day (0-31) + 5 bits hour (0-23) + 6 bits minute (0-59) + 6 bits second (0-59) + 24 bits microseconds (0-999999) + + Total: 64 bits = 8 bytes + + SYYYYYYY.YYYYYYYY.YYdddddh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff +*/ + +/** + Convert datetime to MySQL56 packed numeric datetime representation. + @param ltime The value to convert. + @return Packed numeric representation of ltime. +*/ +longlong TIME_to_longlong_datetime_packed(const MYSQL_TIME *ltime) +{ + longlong ymd= ((ltime->year * 13 + ltime->month) << 5) | ltime->day; + longlong hms= (ltime->hour << 12) | (ltime->minute << 6) | ltime->second; + longlong tmp= MY_PACKED_TIME_MAKE(((ymd << 17) | hms), ltime->second_part); + DBUG_ASSERT(!check_datetime_range(ltime)); /* Make sure no overflow */ + return ltime->neg ? -tmp : tmp; +} + + +/** + Convert MySQL56 packed numeric datetime representation to MYSQL_TIME. + @param OUT ltime The datetime variable to convert to. + @param tmp The packed numeric datetime value. +*/ +void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, longlong tmp) +{ + longlong ymd, hms; + longlong ymdhms, ym; + if ((ltime->neg= (tmp < 0))) + tmp= -tmp; + + ltime->second_part= MY_PACKED_TIME_GET_FRAC_PART(tmp); + ymdhms= MY_PACKED_TIME_GET_INT_PART(tmp); + + ymd= ymdhms >> 17; + ym= ymd >> 5; + hms= ymdhms % (1 << 17); + + ltime->day= ymd % (1 << 5); + ltime->month= ym % 13; + ltime->year= ym / 13; + + ltime->second= hms % (1 << 6); + ltime->minute= (hms >> 6) % (1 << 6); + ltime->hour= (hms >> 12); + + ltime->time_type= MYSQL_TIMESTAMP_DATETIME; +} + + +/** + Calculate binary size of MySQL56 packed datetime representation. + @param dec Precision. +*/ +uint my_datetime_binary_length(uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + return 5 + (dec + 1) / 2; +} + + +/* + On disk we store as unsigned number with DATETIMEF_INT_OFS offset, + for HA_KETYPE_BINARY compatibilty purposes. +*/ +#define DATETIMEF_INT_OFS 0x8000000000LL + + +/** + Convert MySQL56 on-disk datetime representation + to in-memory packed numeric representation. + + @param ptr The pointer to read value at. + @param dec Precision. + @return In-memory packed numeric datetime representation. +*/ +longlong my_datetime_packed_from_binary(const uchar *ptr, uint dec) +{ + longlong intpart= mi_uint5korr(ptr) - DATETIMEF_INT_OFS; + int frac; + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + switch (dec) + { + case 0: + default: + return MY_PACKED_TIME_MAKE_INT(intpart); + case 1: + case 2: + frac= ((int) (signed char) ptr[5]) * 10000; + break; + case 3: + case 4: + frac= mi_sint2korr(ptr + 5) * 100; + break; + case 5: + case 6: + frac= mi_sint3korr(ptr + 5); + break; + } + return MY_PACKED_TIME_MAKE(intpart, frac); +} + + +/** + Store MySQL56 in-memory numeric packed datetime representation to disk. + + @param nr In-memory numeric packed datetime representation. + @param OUT ptr The pointer to store at. + @param dec Precision, 1-6. +*/ +void my_datetime_packed_to_binary(longlong nr, uchar *ptr, uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + /* The value being stored must have been properly rounded or truncated */ + DBUG_ASSERT((MY_PACKED_TIME_GET_FRAC_PART(nr) % + (int) log_10_int[TIME_SECOND_PART_DIGITS - dec]) == 0); + + mi_int5store(ptr, MY_PACKED_TIME_GET_INT_PART(nr) + DATETIMEF_INT_OFS); + switch (dec) + { + case 0: + default: + break; + case 1: + case 2: + ptr[5]= (unsigned char) (char) (MY_PACKED_TIME_GET_FRAC_PART(nr) / 10000); + break; + case 3: + case 4: + mi_int2store(ptr + 5, MY_PACKED_TIME_GET_FRAC_PART(nr) / 100); + break; + case 5: + case 6: + mi_int3store(ptr + 5, MY_PACKED_TIME_GET_FRAC_PART(nr)); + } +} + + +/*** MySQL56 TIMESTAMP low-level memory and disk representation routines ***/ + +/** + Calculate on-disk size of a timestamp value. + + @param dec Precision. +*/ +uint my_timestamp_binary_length(uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + return 4 + (dec + 1) / 2; +} + + +/** + Convert MySQL56 binary timestamp representation to in-memory representation. + + @param OUT tm The variable to convert to. + @param ptr The pointer to read the value from. + @param dec Precision. +*/ +void my_timestamp_from_binary(struct timeval *tm, const uchar *ptr, uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + tm->tv_sec= mi_uint4korr(ptr); + switch (dec) + { + case 0: + default: + tm->tv_usec= 0; + break; + case 1: + case 2: + tm->tv_usec= ((int) ptr[4]) * 10000; + break; + case 3: + case 4: + tm->tv_usec= mi_sint2korr(ptr + 4) * 100; + break; + case 5: + case 6: + tm->tv_usec= mi_sint3korr(ptr + 4); + } +} + + +/** + Convert MySQL56 in-memory timestamp representation to on-disk representation. + + @param tm The value to convert. + @param OUT ptr The pointer to store the value to. + @param dec Precision. +*/ +void my_timestamp_to_binary(const struct timeval *tm, uchar *ptr, uint dec) +{ + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + /* Stored value must have been previously properly rounded or truncated */ + DBUG_ASSERT((tm->tv_usec % + (int) log_10_int[TIME_SECOND_PART_DIGITS - dec]) == 0); + mi_int4store(ptr, tm->tv_sec); + switch (dec) + { + case 0: + default: + break; + case 1: + case 2: + ptr[4]= (unsigned char) (char) (tm->tv_usec / 10000); + break; + case 3: + case 4: + mi_int2store(ptr + 4, tm->tv_usec / 100); + break; + /* Impossible second precision. Fall through */ + case 5: + case 6: + mi_int3store(ptr + 4, tm->tv_usec); + } +} + +/****************************************/ diff --git a/sql/compat56.h b/sql/compat56.h new file mode 100644 index 00000000000..bb5e2670f7d --- /dev/null +++ b/sql/compat56.h @@ -0,0 +1,46 @@ +#ifndef COMPAT56_H_INCLUDED +#define COMPAT56_H_INCLUDED +/* + Copyright (c) 2004, 2012, Oracle and/or its affiliates. + Copyright (c) 2013 MariaDB Foundation. + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + + +/** MySQL56 routines and macros **/ +#define MY_PACKED_TIME_GET_INT_PART(x) ((x) >> 24) +#define MY_PACKED_TIME_GET_FRAC_PART(x) ((x) % (1LL << 24)) +#define MY_PACKED_TIME_MAKE(i, f) ((((longlong) (i)) << 24) + (f)) +#define MY_PACKED_TIME_MAKE_INT(i) ((((longlong) (i)) << 24)) + +longlong TIME_to_longlong_datetime_packed(const MYSQL_TIME *); +longlong TIME_to_longlong_time_packed(const MYSQL_TIME *); + +void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, longlong nr); +void TIME_from_longlong_time_packed(MYSQL_TIME *ltime, longlong nr); + +void my_datetime_packed_to_binary(longlong nr, uchar *ptr, uint dec); +longlong my_datetime_packed_from_binary(const uchar *ptr, uint dec); +uint my_datetime_binary_length(uint dec); + +void my_time_packed_to_binary(longlong nr, uchar *ptr, uint dec); +longlong my_time_packed_from_binary(const uchar *ptr, uint dec); +uint my_time_binary_length(uint dec); + +void my_timestamp_to_binary(const struct timeval *tm, uchar *ptr, uint dec); +void my_timestamp_from_binary(struct timeval *tm, const uchar *ptr, uint dec); +uint my_timestamp_binary_length(uint dec); +/** End of MySQL routines and macros **/ + +#endif /* COMPAT56_H_INCLUDED */ diff --git a/sql/db.opt b/sql/db.opt new file mode 100644 index 00000000000..d8429c4e0de --- /dev/null +++ b/sql/db.opt @@ -0,0 +1,2 @@ +default-character-set=latin1 +default-collation=latin1_swedish_ci diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 3b4119347c4..5c77456d907 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -55,7 +55,7 @@ const TABLE_FIELD_TYPE event_table_fields[ET_FIELD_COUNT] = }, { { C_STRING_WITH_LEN("definer") }, - { C_STRING_WITH_LEN("char(77)") }, + { C_STRING_WITH_LEN("char(") }, { C_STRING_WITH_LEN("utf8") } }, { diff --git a/sql/field.cc b/sql/field.cc index e85903d76c6..e6cab7184fd 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -87,6 +87,7 @@ const char field_separator=','; #define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO)) static inline int field_type2index (enum_field_types field_type) { + field_type= real_type_to_type(field_type); return (field_type < FIELDTYPE_TEAR_FROM ? field_type : ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) - 1); @@ -947,8 +948,10 @@ static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]= enum_field_types Field::field_type_merge(enum_field_types a, enum_field_types b) { - DBUG_ASSERT(a < FIELDTYPE_TEAR_FROM || a > FIELDTYPE_TEAR_TO); - DBUG_ASSERT(b < FIELDTYPE_TEAR_FROM || b > FIELDTYPE_TEAR_TO); + DBUG_ASSERT(real_type_to_type(a) < FIELDTYPE_TEAR_FROM || + real_type_to_type(a) > FIELDTYPE_TEAR_TO); + DBUG_ASSERT(real_type_to_type(b) < FIELDTYPE_TEAR_FROM || + real_type_to_type(b) > FIELDTYPE_TEAR_TO); return field_types_merge_rules[field_type2index(a)] [field_type2index(b)]; } @@ -1042,8 +1045,8 @@ CPP_UNNAMED_NS_END Item_result Field::result_merge_type(enum_field_types field_type) { - DBUG_ASSERT(field_type < FIELDTYPE_TEAR_FROM || field_type - > FIELDTYPE_TEAR_TO); + DBUG_ASSERT(real_type_to_type(field_type) < FIELDTYPE_TEAR_FROM || + real_type_to_type(field_type) > FIELDTYPE_TEAR_TO); return field_types_result_type[field_type2index(field_type)]; } @@ -1129,6 +1132,111 @@ void Field::make_sort_key(uchar *buff,uint length) } +/** + @brief + Determine the relative position of the field value in a numeric interval + + @details + The function returns a double number between 0.0 and 1.0 as the relative + position of the value of the this field in the numeric interval of [min,max]. + If the value is not in the interval the the function returns 0.0 when + the value is less than min, and, 1.0 when the value is greater than max. + + @param min value of the left end of the interval + @param max value of the right end of the interval + + @return + relative position of the field value in the numeric interval [min,max] +*/ + +double Field::pos_in_interval_val_real(Field *min, Field *max) +{ + double n, d; + n= val_real() - min->val_real(); + if (n < 0) + return 0.0; + d= max->val_real() - min->val_real(); + if (d <= 0) + return 1.0; + return min(n/d, 1.0); +} + + +static +inline ulonglong char_prefix_to_ulonglong(uchar *src) +{ + uint sz= sizeof(ulonglong); + for (uint i= 0; i < sz/2; i++) + { + uchar tmp= src[i]; + src[i]= src[sz-1-i]; + src[sz-1-i]= tmp; + } + return uint8korr(src); +} + + +/** + @brief + Determine the relative position of the field value in a string interval + + @details + The function returns a double number between 0.0 and 1.0 as the relative + position of the value of the this field in the string interval of [min,max]. + If the value is not in the interval the the function returns 0.0 when + the value is less than min, and, 1.0 when the value is greater than max. + + @note + To calculate the relative position of the string value v in the interval + [min, max] the function first converts the beginning of these three + strings v, min, max into the strings that are used for byte comparison. + For each string not more sizeof(ulonglong) first bytes are taken + from the result of conversion. Then these bytes are interpreted as the + big-endian representation of an ulonglong integer. The values of these + integer numbers obtained for the strings v, min, max are used to calculate + the position of v in [min,max] in the same way is it's done for numeric + fields (see Field::pos_in_interval_val_real). + + @todo + Improve the procedure for the case when min and max have the same + beginning + + @param min value of the left end of the interval + @param max value of the right end of the interval + + @return + relative position of the field value in the string interval [min,max] +*/ + +double Field::pos_in_interval_val_str(Field *min, Field *max, uint data_offset) +{ + uchar mp_prefix[sizeof(ulonglong)]; + uchar minp_prefix[sizeof(ulonglong)]; + uchar maxp_prefix[sizeof(ulonglong)]; + ulonglong mp, minp, maxp; + my_strnxfrm(charset(), mp_prefix, sizeof(mp), + ptr + data_offset, + data_length()); + my_strnxfrm(charset(), minp_prefix, sizeof(minp), + min->ptr + data_offset, + min->data_length()); + my_strnxfrm(charset(), maxp_prefix, sizeof(maxp), + max->ptr + data_offset, + max->data_length()); + mp= char_prefix_to_ulonglong(mp_prefix); + minp= char_prefix_to_ulonglong(minp_prefix); + maxp= char_prefix_to_ulonglong(maxp_prefix); + double n, d; + n= mp - minp; + if (n < 0) + return 0.0; + d= maxp - minp; + if (d <= 0) + return 1.0; + return min(n/d, 1.0); +} + + /** Numeric fields base class constructor. */ @@ -1274,36 +1382,6 @@ out_of_range: } -/** - @brief - Determine the relative position of the field value in a numeric interval - - @details - The function returns a double number between 0.0 and 1.0 as the relative - position of the value of the this field in the numeric interval of [min,max]. - If the value is not in the interval the the function returns 0.0 when - the value is less than min, and, 1.0 when the value is greater than max. - - @param min value of the left end of the interval - @param max value of the right end of the interval - - @return - relative position of the field value in the numeric interval [min,max] -*/ - -double Field_num::pos_in_interval(Field *min, Field *max) -{ - double n, d; - n= val_real() - min->val_real(); - if (n < 0) - return 0.0; - d= max->val_real() - min->val_real(); - if (d <= 0) - return 1.0; - return min(n/d, 1.0); -} - - /** Process decimal library return codes and issue warnings for overflow and truncation. @@ -1822,7 +1900,7 @@ bool Field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) String tmp(buff,sizeof(buff),&my_charset_bin),*res; if (!(res=val_str(&tmp)) || str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(), - ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR) + ltime, fuzzydate)) return 1; return 0; } @@ -4485,13 +4563,12 @@ Field_timestamp::Field_timestamp(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, - CHARSET_INFO *cs) - :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) + TABLE_SHARE *share) + :Field_temporal(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg) { /* For 4.0 MYD and 4.0 InnoDB compatibility */ - flags|= UNSIGNED_FLAG | BINARY_FLAG; + flags|= UNSIGNED_FLAG; if (unireg_check != NONE) { /* @@ -4570,18 +4647,18 @@ int Field_timestamp::store_time_dec(MYSQL_TIME *ltime, uint dec) int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) { MYSQL_TIME l_time; - int error; - int have_smth_to_conv; + MYSQL_TIME_STATUS status; + bool have_smth_to_conv; ErrConvString str(from, len, cs); THD *thd= get_thd(); /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ - have_smth_to_conv= (str_to_datetime(cs, from, len, &l_time, + have_smth_to_conv= !str_to_datetime(cs, from, len, &l_time, (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | - MODE_NO_ZERO_IN_DATE, &error) > - MYSQL_TIMESTAMP_ERROR); - return store_TIME_with_warning(thd, &l_time, &str, error, have_smth_to_conv); + MODE_NO_ZERO_IN_DATE, &status); + return store_TIME_with_warning(thd, &l_time, &str, + status.warnings, have_smth_to_conv); } @@ -4636,6 +4713,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) { MYSQL_TIME ltime; uint32 temp, temp2; + uint dec; char *to; val_buffer->alloc(field_length+1); @@ -4690,6 +4768,16 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) *to++= (char) ('0'+(char) (temp)); *to= 0; val_buffer->set_charset(&my_charset_numeric); + + if ((dec= decimals())) + { + ulong sec_part= (ulong) sec_part_shift(ltime.second_part, dec); + char *buf= const_cast(val_buffer->ptr() + MAX_DATETIME_WIDTH); + for (int i= dec; i > 0; i--, sec_part/= 10) + buf[i]= (char)(sec_part % 10) + '0'; + buf[0]= '.'; + buf[dec + 1]= 0; + } return val_buffer; } @@ -4743,7 +4831,14 @@ void Field_timestamp::sort_string(uchar *to,uint length __attribute__((unused))) void Field_timestamp::sql_type(String &res) const { - res.set_ascii(STRING_WITH_LEN("timestamp")); + if (!decimals()) + { + res.set_ascii(STRING_WITH_LEN("timestamp")); + return; + } + CHARSET_INFO *cs=res.charset(); + res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), + "timestamp(%u)", decimals())); } @@ -4783,13 +4878,6 @@ void Field_timestamp::set_explicit_default(Item *value) set_has_explicit_value(); } -void Field_timestamp_hires::sql_type(String &res) const -{ - CHARSET_INFO *cs=res.charset(); - res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), - "timestamp(%u)", dec)); -} - #ifdef NOT_USED static void store_native(ulonglong num, uchar *to, uint bytes) { @@ -4883,7 +4971,7 @@ my_time_t Field_timestamp_hires::get_timestamp(ulong *sec_part) const return mi_uint4korr(ptr); } -double Field_timestamp_hires::val_real(void) +double Field_timestamp_with_dec::val_real(void) { MYSQL_TIME ltime; if (get_date(<ime, TIME_NO_ZERO_DATE)) @@ -4894,31 +4982,14 @@ double Field_timestamp_hires::val_real(void) ltime.minute * 1e2 + ltime.second + ltime.second_part*1e-6; } -String *Field_timestamp_hires::val_str(String *val_buffer, String *val_ptr) -{ - String *tmp= Field_timestamp::val_str(val_buffer, val_ptr); - ulong sec_part= (ulong)read_bigendian(ptr+4, sec_part_bytes[dec]); - - if (tmp->ptr() == zero_timestamp) - return tmp; - - char *buf= const_cast(tmp->ptr() + MAX_DATETIME_WIDTH); - for (int i=dec; i>0; i--, sec_part/=10) - buf[i]= (char)(sec_part % 10) + '0'; - buf[0]= '.'; - buf[dec+1]= 0; - return tmp; -} - - -my_decimal *Field_timestamp_hires::val_decimal(my_decimal *d) +my_decimal *Field_timestamp_with_dec::val_decimal(my_decimal *d) { MYSQL_TIME ltime; get_date(<ime, 0); return TIME_to_my_decimal(<ime, d); } -int Field_timestamp_hires::store_decimal(const my_decimal *d) +int Field_timestamp::store_decimal(const my_decimal *d) { ulonglong nr; ulong sec_part; @@ -4941,7 +5012,7 @@ int Field_timestamp_hires::store_decimal(const my_decimal *d) return store_TIME_with_warning(thd, <ime, &str, error, tmp != -1); } -int Field_timestamp_hires::set_time() +int Field_timestamp_with_dec::set_time() { THD *thd= get_thd(); set_notnull(); @@ -4949,7 +5020,7 @@ int Field_timestamp_hires::set_time() return 0; } -bool Field_timestamp_hires::send_binary(Protocol *protocol) +bool Field_timestamp_with_dec::send_binary(Protocol *protocol) { MYSQL_TIME ltime; Field_timestamp::get_date(<ime, 0); @@ -4970,71 +5041,53 @@ int Field_timestamp_hires::cmp(const uchar *a_ptr, const uchar *b_ptr) } -void Field_timestamp_hires::sort_string(uchar *to,uint length) -{ - DBUG_ASSERT(length == Field_timestamp_hires::pack_length()); - memcpy(to, ptr, length); -} - uint32 Field_timestamp_hires::pack_length() const { return 4 + sec_part_bytes[dec]; } -void Field_timestamp_hires::make_field(Send_field *field) +void Field_timestamp_with_dec::make_field(Send_field *field) { Field::make_field(field); field->decimals= dec; } -/* - Store string into a date/time field - RETURN - 0 ok - 1 Value was cut during conversion - 2 value was out of range - 3 Datetime value that was cut (warning level NOTE) - This is used by opt_range.cc:get_mm_leaf(). -*/ -int Field_temporal::store_TIME_with_warning(MYSQL_TIME *ltime, - const ErrConv *str, - int was_cut, int have_smth_to_conv) +/************************************************************* +** MySQL-5.6 compatible TIMESTAMP(N) +**************************************************************/ + +void Field_timestampf::store_TIME(my_time_t timestamp, ulong sec_part) { - MYSQL_ERROR::enum_warning_level trunc_level= MYSQL_ERROR::WARN_LEVEL_WARN; - int ret= 2; - - ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; + struct timeval tm; + tm.tv_sec= timestamp; + tm.tv_usec= sec_part; + my_timeval_trunc(&tm, dec); + my_timestamp_to_binary(&tm, ptr, dec); +} - if (was_cut == 0 && - have_smth_to_conv == 0 && - mysql_type_to_time_type(type()) != MYSQL_TIMESTAMP_TIME) // special case: zero date - was_cut= MYSQL_TIME_WARN_OUT_OF_RANGE; - else - if (!have_smth_to_conv) - { - bzero(ltime, sizeof(*ltime)); - was_cut= MYSQL_TIME_WARN_TRUNCATED; - ret= 1; - } - else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && - mysql_type_to_time_type(type()) == MYSQL_TIMESTAMP_DATE && - (ltime->hour || ltime->minute || ltime->second || ltime->second_part)) - { - trunc_level= MYSQL_ERROR::WARN_LEVEL_NOTE; - was_cut|= MYSQL_TIME_WARN_TRUNCATED; - ret= 3; - } - else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && - mysql_type_to_time_type(type()) == MYSQL_TIMESTAMP_TIME && - (ltime->year || ltime->month)) - { - ltime->year= ltime->month= ltime->day= 0; - trunc_level= MYSQL_ERROR::WARN_LEVEL_NOTE; - was_cut|= MYSQL_TIME_WARN_TRUNCATED; - ret= 3; - } +my_time_t Field_timestampf::get_timestamp(ulong *sec_part) const +{ + struct timeval tm; + my_timestamp_from_binary(&tm, ptr, dec); + *sec_part= tm.tv_usec; + return tm.tv_sec; +} + + +/*************************************************************/ +uint Field_temporal::is_equal(Create_field *new_field) +{ + return new_field->sql_type == real_type() && + new_field->length == max_display_length(); +} + + +void Field_temporal::set_warnings(MYSQL_ERROR::enum_warning_level trunc_level, + const ErrConv *str, int was_cut, + timestamp_type ts_type) +{ /* error code logic: MYSQL_TIME_WARN_TRUNCATED means that the value was not a date/time at all. @@ -5051,31 +5104,70 @@ int Field_temporal::store_TIME_with_warning(MYSQL_TIME *ltime, if (was_cut & MYSQL_TIME_WARN_OUT_OF_RANGE) set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, str, mysql_type_to_time_type(type()), 1); +} + +/* + Store string into a date/time field + + RETURN + 0 ok + 1 Value was cut during conversion + 2 value was out of range + 3 Datetime value that was cut (warning level NOTE) + This is used by opt_range.cc:get_mm_leaf(). +*/ +int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME *ltime, + const ErrConv *str, + int was_cut, + int have_smth_to_conv) +{ + MYSQL_ERROR::enum_warning_level trunc_level= MYSQL_ERROR::WARN_LEVEL_WARN; + int ret= 2; + + ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; + + if (was_cut == 0 && have_smth_to_conv == 0) // special case: zero date + { + was_cut= MYSQL_TIME_WARN_OUT_OF_RANGE; + } + else if (!have_smth_to_conv) + { + bzero(ltime, sizeof(*ltime)); + was_cut= MYSQL_TIME_WARN_TRUNCATED; + ret= 1; + } + else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && + mysql_type_to_time_type(type()) == MYSQL_TIMESTAMP_DATE && + (ltime->hour || ltime->minute || ltime->second || ltime->second_part)) + { + trunc_level= MYSQL_ERROR::WARN_LEVEL_NOTE; + was_cut|= MYSQL_TIME_WARN_TRUNCATED; + ret= 3; + } + set_warnings(trunc_level, str, was_cut, mysql_type_to_time_type(type())); store_TIME(ltime); return was_cut ? ret : 0; } -int Field_temporal::store(const char *from,uint len,CHARSET_INFO *cs) +int Field_temporal_with_date::store(const char *from, uint len, CHARSET_INFO *cs) { MYSQL_TIME ltime; - int error; - enum enum_mysql_timestamp_type func_res; + MYSQL_TIME_STATUS status; THD *thd= get_thd(); ErrConvString str(from, len, cs); - - func_res= str_to_datetime(cs, from, len, <ime, - (TIME_FUZZY_DATE | - (thd->variables.sql_mode & - (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | - MODE_INVALID_DATES))), - &error); - return store_TIME_with_warning(<ime, &str, error, func_res > MYSQL_TIMESTAMP_ERROR); + bool func_res= !str_to_datetime(cs, from, len, <ime, + (TIME_FUZZY_DATE | + (thd->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | + MODE_INVALID_DATES))), + &status); + return store_TIME_with_warning(<ime, &str, status.warnings, func_res); } -int Field_temporal::store(double nr) +int Field_temporal_with_date::store(double nr) { int error= 0; MYSQL_TIME ltime; @@ -5092,7 +5184,7 @@ int Field_temporal::store(double nr) } -int Field_temporal::store(longlong nr, bool unsigned_val) +int Field_temporal_with_date::store(longlong nr, bool unsigned_val) { int error; MYSQL_TIME ltime; @@ -5110,7 +5202,7 @@ int Field_temporal::store(longlong nr, bool unsigned_val) } -int Field_temporal::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_temporal_with_date::store_time_dec(MYSQL_TIME *ltime, uint dec) { int error = 0, have_smth_to_conv= 1; MYSQL_TIME l_time= *ltime; @@ -5144,6 +5236,35 @@ my_decimal *Field_temporal::val_decimal(my_decimal *d) ** In number context: HHMMSS ** Stored as a 3 byte unsigned int ****************************************************************************/ +int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime, + const ErrConv *str, + int was_cut, + int have_smth_to_conv) +{ + MYSQL_ERROR::enum_warning_level trunc_level= MYSQL_ERROR::WARN_LEVEL_WARN; + int ret= 2; + + ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; + + if (!have_smth_to_conv) + { + bzero(ltime, sizeof(*ltime)); + was_cut= MYSQL_TIME_WARN_TRUNCATED; + ret= 1; + } + else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && + (ltime->year || ltime->month)) + { + ltime->year= ltime->month= ltime->day= 0; + trunc_level= MYSQL_ERROR::WARN_LEVEL_NOTE; + was_cut|= MYSQL_TIME_WARN_TRUNCATED; + ret= 3; + } + set_warnings(trunc_level, str, was_cut, MYSQL_TIMESTAMP_TIME); + store_TIME(ltime); + return was_cut ? ret : 0; +} + void Field_time::store_TIME(MYSQL_TIME *ltime) { @@ -5157,16 +5278,17 @@ void Field_time::store_TIME(MYSQL_TIME *ltime) int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { MYSQL_TIME ltime; + MYSQL_TIME_STATUS status; ErrConvString str(from, len, cs); - int was_cut; - int have_smth_to_conv= - str_to_time(cs, from, len, <ime, + bool have_smth_to_conv= + !str_to_time(cs, from, len, <ime, get_thd()->variables.sql_mode & (MODE_NO_ZERO_DATE | MODE_NO_ZERO_IN_DATE | MODE_INVALID_DATES), - &was_cut) > MYSQL_TIMESTAMP_ERROR; + &status); - return store_TIME_with_warning(<ime, &str, was_cut, have_smth_to_conv); + return store_TIME_with_warning(<ime, &str, + status.warnings, have_smth_to_conv); } @@ -5229,32 +5351,16 @@ longlong Field_time::val_int(void) my_charset_bin */ -String *Field_time::val_str(String *val_buffer, - String *val_ptr __attribute__((unused))) +String *Field_time::val_str(String *str, + String *unused __attribute__((unused))) { ASSERT_COLUMN_MARKED_FOR_READ; MYSQL_TIME ltime; - long tmp=(long) sint3korr(ptr); - ltime.neg= 0; - if (tmp < 0) - { - tmp= -tmp; - ltime.neg= 1; - } - ltime.year= ltime.month= 0; - ltime.day= (uint) 0; - ltime.hour= (uint) (tmp/10000); - ltime.minute= (uint) (tmp/100 % 100); - ltime.second= (uint) (tmp % 100); - ltime.second_part= 0; - - val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH); - uint length= (uint) my_time_to_str(<ime, - const_cast(val_buffer->ptr()), 0); - val_buffer->length(length); - val_buffer->set_charset(&my_charset_numeric); - - return val_buffer; + get_date(<ime, TIME_TIME_ONLY); + str->alloc(field_length + 1); + str->length(my_time_to_str(<ime, const_cast(str->ptr()), decimals())); + str->set_charset(&my_charset_numeric); + return str; } @@ -5297,8 +5403,8 @@ bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_time::send_binary(Protocol *protocol) { MYSQL_TIME ltime; - Field_time::get_date(<ime, TIME_TIME_ONLY); - return protocol->store_time(<ime, 0); + get_date(<ime, TIME_TIME_ONLY); + return protocol->store_time(<ime, decimals()); } @@ -5319,7 +5425,14 @@ void Field_time::sort_string(uchar *to,uint length __attribute__((unused))) void Field_time::sql_type(String &res) const { - res.set_ascii(STRING_WITH_LEN("time")); + if (decimals() == 0) + { + res.set_ascii(STRING_WITH_LEN("time")); + return; + } + const CHARSET_INFO *cs= res.charset(); + res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), + "time(%d)", decimals())); } int Field_time_hires::reset() @@ -5335,7 +5448,7 @@ void Field_time_hires::store_TIME(MYSQL_TIME *ltime) store_bigendian(packed, ptr, Field_time_hires::pack_length()); } -int Field_time_hires::store_decimal(const my_decimal *d) +int Field_time::store_decimal(const my_decimal *d) { ulonglong nr; ulong sec_part; @@ -5354,35 +5467,23 @@ uint32 Field_time_hires::pack_length() const return time_hires_bytes[dec]; } -longlong Field_time_hires::val_int(void) +longlong Field_time_with_dec::val_int(void) { ASSERT_COLUMN_MARKED_FOR_READ; MYSQL_TIME ltime; - Field_time_hires::get_date(<ime, TIME_TIME_ONLY); + get_date(<ime, TIME_TIME_ONLY); longlong val= TIME_to_ulonglong_time(<ime); return ltime.neg ? -val : val; } -double Field_time_hires::val_real(void) +double Field_time_with_dec::val_real(void) { ASSERT_COLUMN_MARKED_FOR_READ; MYSQL_TIME ltime; - Field_time_hires::get_date(<ime, TIME_TIME_ONLY); + get_date(<ime, TIME_TIME_ONLY); return TIME_to_double(<ime); } -String *Field_time_hires::val_str(String *str, - String *unused __attribute__((unused))) -{ - ASSERT_COLUMN_MARKED_FOR_READ; - MYSQL_TIME ltime; - Field_time_hires::get_date(<ime, TIME_TIME_ONLY); - str->alloc(field_length+1); - str->length(my_time_to_str(<ime, (char*) str->ptr(), dec)); - str->set_charset(&my_charset_bin); - return str; -} - bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { uint32 len= pack_length(); @@ -5402,14 +5503,6 @@ bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) } -bool Field_time_hires::send_binary(Protocol *protocol) -{ - MYSQL_TIME ltime; - Field_time_hires::get_date(<ime, TIME_TIME_ONLY); - return protocol->store_time(<ime, dec); -} - - int Field_time_hires::cmp(const uchar *a_ptr, const uchar *b_ptr) { ulonglong a=read_bigendian(a_ptr, Field_time_hires::pack_length()); @@ -5424,19 +5517,38 @@ void Field_time_hires::sort_string(uchar *to,uint length __attribute__((unused)) to[0]^= 128; } -void Field_time_hires::sql_type(String &res) const -{ - CHARSET_INFO *cs=res.charset(); - res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), - "time(%u)", dec)); -} - -void Field_time_hires::make_field(Send_field *field) +void Field_time_with_dec::make_field(Send_field *field) { Field::make_field(field); field->decimals= dec; } +/**************************************************************************** +** time type with fsp (MySQL-5.6 version) +** In string context: HH:MM:SS.FFFFFF +** In number context: HHMMSS.FFFFFF +****************************************************************************/ + +int Field_timef::reset() +{ + my_time_packed_to_binary(0, ptr, dec); + return 0; +} + +void Field_timef::store_TIME(MYSQL_TIME *ltime) +{ + my_time_trunc(ltime, decimals()); + longlong tmp= TIME_to_longlong_time_packed(ltime); + my_time_packed_to_binary(tmp, ptr, dec); +} + +bool Field_timef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +{ + longlong tmp= my_time_packed_from_binary(ptr, dec); + TIME_from_longlong_time_packed(ltime, tmp); + return false; +} + /**************************************************************************** ** year type ** Save in a byte the year 0, 1901->2155 @@ -5792,8 +5904,8 @@ bool Field_datetime::send_binary(Protocol *protocol) Field_datetime::get_date(&tm, TIME_FUZZY_DATE); return protocol->store(&tm, 0); } - - + + double Field_datetime::val_real(void) { return (double) Field_datetime::val_int(); @@ -5901,7 +6013,14 @@ void Field_datetime::sort_string(uchar *to,uint length __attribute__((unused))) void Field_datetime::sql_type(String &res) const { - res.set_ascii(STRING_WITH_LEN("datetime")); + if (decimals() == 0) + { + res.set_ascii(STRING_WITH_LEN("datetime")); + return; + } + CHARSET_INFO *cs= res.charset(); + res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), + "datetime(%u)", decimals())); } @@ -5924,7 +6043,7 @@ void Field_datetime_hires::store_TIME(MYSQL_TIME *ltime) store_bigendian(packed, ptr, Field_datetime_hires::pack_length()); } -int Field_datetime_hires::store_decimal(const my_decimal *d) +int Field_temporal_with_date::store_decimal(const my_decimal *d) { ulonglong nr; ulong sec_part; @@ -5949,38 +6068,38 @@ int Field_datetime_hires::store_decimal(const my_decimal *d) return store_TIME_with_warning(<ime, &str, error, tmp != -1); } -bool Field_datetime_hires::send_binary(Protocol *protocol) +bool Field_datetime_with_dec::send_binary(Protocol *protocol) { MYSQL_TIME ltime; - Field_datetime_hires::get_date(<ime, TIME_FUZZY_DATE); + get_date(<ime, TIME_FUZZY_DATE); return protocol->store(<ime, dec); } -double Field_datetime_hires::val_real(void) +double Field_datetime_with_dec::val_real(void) { MYSQL_TIME ltime; - Field_datetime_hires::get_date(<ime, TIME_FUZZY_DATE); + get_date(<ime, TIME_FUZZY_DATE); return TIME_to_double(<ime); } -longlong Field_datetime_hires::val_int(void) +longlong Field_datetime_with_dec::val_int(void) { MYSQL_TIME ltime; - Field_datetime_hires::get_date(<ime, TIME_FUZZY_DATE); + get_date(<ime, TIME_FUZZY_DATE); return TIME_to_ulonglong_datetime(<ime); } -String *Field_datetime_hires::val_str(String *str, - String *unused __attribute__((unused))) +String *Field_datetime_with_dec::val_str(String *str, + String *unused __attribute__((unused))) { MYSQL_TIME ltime; - Field_datetime_hires::get_date(<ime, TIME_FUZZY_DATE); + get_date(<ime, TIME_FUZZY_DATE); str->alloc(field_length+1); str->length(field_length); my_datetime_to_str(<ime, (char*) str->ptr(), dec); - str->set_charset(&my_charset_bin); + str->set_charset(&my_charset_numeric); return str; } @@ -6007,27 +6126,42 @@ int Field_datetime_hires::cmp(const uchar *a_ptr, const uchar *b_ptr) return a < b ? -1 : a > b ? 1 : 0; } -void Field_datetime_hires::sort_string(uchar *to, - uint length __attribute__((unused))) -{ - DBUG_ASSERT(length == Field_datetime_hires::pack_length()); - memcpy(to, ptr, length); -} - - -void Field_datetime_hires::sql_type(String &res) const -{ - CHARSET_INFO *cs=res.charset(); - res.length(cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(), - "datetime(%u)", dec)); -} - -void Field_datetime_hires::make_field(Send_field *field) +void Field_datetime_with_dec::make_field(Send_field *field) { Field::make_field(field); field->decimals= dec; } + +/**************************************************************************** +** MySQL-5.6 compatible DATETIME(N) +** +****************************************************************************/ +int Field_datetimef::reset() +{ + my_datetime_packed_to_binary(0, ptr, dec); + return 0; +} + +void Field_datetimef::store_TIME(MYSQL_TIME *ltime) +{ + my_time_trunc(ltime, decimals()); + longlong tmp= TIME_to_longlong_datetime_packed(ltime); + my_datetime_packed_to_binary(tmp, ptr, dec); +} + +bool Field_datetimef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +{ + longlong tmp= my_datetime_packed_from_binary(ptr, dec); + TIME_from_longlong_datetime_packed(ltime, tmp); + if (!tmp) + return fuzzydate & TIME_NO_ZERO_DATE; + if (!ltime->month || !ltime->day) + return !(fuzzydate & TIME_FUZZY_DATE); + return false; +} + + /**************************************************************************** ** string type ** A string may be varchar or binary @@ -6198,80 +6332,6 @@ int Field_str::store(double nr) return store(buff, length, &my_charset_numeric); } -static -inline ulonglong char_prefix_to_ulonglong(uchar *src) -{ - uint sz= sizeof(ulonglong); - for (uint i= 0; i < sz/2; i++) - { - uchar tmp= src[i]; - src[i]= src[sz-1-i]; - src[sz-1-i]= tmp; - } - return uint8korr(src); -} - -/** - @brief - Determine the relative position of the field value in a string interval - - @details - The function returns a double number between 0.0 and 1.0 as the relative - position of the value of the this field in the string interval of [min,max]. - If the value is not in the interval the the function returns 0.0 when - the value is less than min, and, 1.0 when the value is greater than max. - - @note - To calculate the relative position of the string value v in the interval - [min, max] the function first converts the beginning of these three - strings v, min, max into the strings that are used for byte comparison. - For each string not more sizeof(ulonglong) first bytes are taken - from the result of conversion. Then these bytes are interpreted as the - big-endian representation of an ulonglong integer. The values of these - integer numbers obtained for the strings v, min, max are used to calculate - the position of v in [min,max] in the same way is it's done for numeric - fields (see Field_num::pos_in_interval). - - @todo - Improve the procedure for the case when min and max have the same - beginning - - @param min value of the left end of the interval - @param max value of the right end of the interval - - @return - relative position of the field value in the string interval [min,max] -*/ - -double Field_str::pos_in_interval(Field *min, Field *max) -{ - uchar mp_prefix[sizeof(ulonglong)]; - uchar minp_prefix[sizeof(ulonglong)]; - uchar maxp_prefix[sizeof(ulonglong)]; - ulonglong mp, minp, maxp; - my_strnxfrm(charset(), mp_prefix, sizeof(mp), - ptr + length_size(), - data_length()); - my_strnxfrm(charset(), minp_prefix, sizeof(minp), - min->ptr + length_size(), - min->data_length()); - my_strnxfrm(charset(), maxp_prefix, sizeof(maxp), - max->ptr + length_size(), - max->data_length()); - mp= char_prefix_to_ulonglong(mp_prefix); - minp= char_prefix_to_ulonglong(minp_prefix); - maxp= char_prefix_to_ulonglong(maxp_prefix); - double n, d; - n= mp - minp; - if (n < 0) - return 0.0; - d= maxp - minp; - if (d <= 0) - return 1.0; - return min(n/d, 1.0); -} - - uint Field::is_equal(Create_field *new_field) { return (new_field->sql_type == real_type()); @@ -8482,36 +8542,6 @@ my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value) } -/** - @brief - Determine the relative position of the field value in a bit interval - - @details - The function returns a double number between 0.0 and 1.0 as the relative - position of the value of the this field in the bit interval of [min,max]. - If the value is not in the interval the the function returns 0.0 when - the value is less than min, and, 1.0 when the value is greater than max. - - @param min value of the left end of the interval - @param max value of the right end of the interval - - @return - relative position of the field value in the bit interval [min,max] -*/ - -double Field_bit::pos_in_interval(Field *min, Field *max) -{ - double n, d; - n= val_real() - min->val_real(); - if (n < 0) - return 0.0; - d= max->val_real() - min->val_real(); - if (d <= 0) - return 1.0; - return min(n/d, 1.0); -} - - /* Compare two bit fields using pointers within the record. SYNOPSIS @@ -9144,7 +9174,7 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP. */ if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) && - (fld_type_modifier & NOT_NULL_FLAG) && fld_type != MYSQL_TYPE_TIMESTAMP) + (fld_type_modifier & NOT_NULL_FLAG) && !is_timestamp_type(fld_type)) flags|= NO_DEFAULT_VALUE_FLAG; if (fld_length != NULL) @@ -9306,6 +9336,7 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, } break; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: if (length > MAX_DATETIME_PRECISION) { my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name, @@ -9323,6 +9354,7 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, length= MAX_DATE_WIDTH; break; case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIME2: if (length > MAX_DATETIME_PRECISION) { my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name, @@ -9332,6 +9364,7 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, length+= MIN_TIME_WIDTH + (length ? 1 : 0); break; case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: if (length > MAX_DATETIME_PRECISION) { my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name, @@ -9413,17 +9446,6 @@ bool Create_field::init(THD *thd, char *fld_name, enum_field_types fld_type, DBUG_RETURN(TRUE); } - switch (fld_type) { - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_NEWDATE: - case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_TIMESTAMP: - charset= &my_charset_numeric; - flags|= BINARY_FLAG; - default: break; - } - DBUG_RETURN(FALSE); /* success */ } @@ -9462,10 +9484,16 @@ uint32 calc_pack_length(enum_field_types type,uint32 length) case MYSQL_TYPE_TIME: return length > MIN_TIME_WIDTH ? time_hires_bytes[length - 1 - MIN_TIME_WIDTH] : 3; + case MYSQL_TYPE_TIME2: + return length > MIN_TIME_WIDTH ? + my_time_binary_length(length - MIN_TIME_WIDTH - 1) : 3; case MYSQL_TYPE_TIMESTAMP: return length > MAX_DATETIME_WIDTH ? 4 + sec_part_bytes[length - 1 - MAX_DATETIME_WIDTH] : 4; + case MYSQL_TYPE_TIMESTAMP2: + return length > MAX_DATETIME_WIDTH ? + my_timestamp_binary_length(length - MAX_DATETIME_WIDTH - 1) : 4; case MYSQL_TYPE_DATE: case MYSQL_TYPE_LONG : return 4; case MYSQL_TYPE_FLOAT : return sizeof(float); @@ -9474,6 +9502,9 @@ uint32 calc_pack_length(enum_field_types type,uint32 length) return length > MAX_DATETIME_WIDTH ? datetime_hires_bytes[length - 1 - MAX_DATETIME_WIDTH] : 8; + case MYSQL_TYPE_DATETIME2: + return length > MAX_DATETIME_WIDTH ? + my_datetime_binary_length(length - MAX_DATETIME_WIDTH - 1) : 5; case MYSQL_TYPE_LONGLONG: return 8; /* Don't crash if no longlong */ case MYSQL_TYPE_NULL : return 0; case MYSQL_TYPE_TINY_BLOB: return 1+portable_sizeof_char_ptr; @@ -9538,16 +9569,6 @@ Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length, null_bit= ((uchar) 1) << null_bit; } - switch (field_type) { - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_NEWDATE: - case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATETIME: - case MYSQL_TYPE_TIMESTAMP: - field_charset= &my_charset_numeric; - default: break; - } - DBUG_PRINT("debug", ("field_type: %d, field_length: %u, interval: %p, pack_flag: %s%s%s%s%s", field_type, field_length, interval, FLAGSTR(pack_flag, FIELDFLAG_BINARY), @@ -9661,30 +9682,51 @@ Field *make_field(TABLE_SHARE *share, uchar *ptr, uint32 field_length, uint dec= field_length > MAX_DATETIME_WIDTH ? field_length - MAX_DATETIME_WIDTH - 1: 0; return new_Field_timestamp(ptr, null_pos, null_bit, unireg_check, - field_name, share, dec, field_charset); + field_name, share, dec); + } + case MYSQL_TYPE_TIMESTAMP2: + { + uint dec= field_length > MAX_DATETIME_WIDTH ? + field_length - MAX_DATETIME_WIDTH - 1: 0; + return new Field_timestampf(ptr, null_pos, null_bit, unireg_check, + field_name, share, dec); } case MYSQL_TYPE_YEAR: return new Field_year(ptr,field_length,null_pos,null_bit, unireg_check, field_name); case MYSQL_TYPE_DATE: return new Field_date(ptr,null_pos,null_bit, - unireg_check, field_name, field_charset); + unireg_check, field_name); case MYSQL_TYPE_NEWDATE: return new Field_newdate(ptr,null_pos,null_bit, - unireg_check, field_name, field_charset); + unireg_check, field_name); case MYSQL_TYPE_TIME: { uint dec= field_length > MIN_TIME_WIDTH ? field_length - MIN_TIME_WIDTH - 1: 0; return new_Field_time(ptr, null_pos, null_bit, unireg_check, - field_name, dec, field_charset); + field_name, dec); + } + case MYSQL_TYPE_TIME2: + { + uint dec= field_length > MIN_TIME_WIDTH ? + field_length - MIN_TIME_WIDTH - 1: 0; + return new Field_timef(ptr, null_pos, null_bit, unireg_check, + field_name, dec); } case MYSQL_TYPE_DATETIME: { uint dec= field_length > MAX_DATETIME_WIDTH ? field_length - MAX_DATETIME_WIDTH - 1: 0; return new_Field_datetime(ptr, null_pos, null_bit, unireg_check, - field_name, dec, field_charset); + field_name, dec); + } + case MYSQL_TYPE_DATETIME2: + { + uint dec= field_length > MAX_DATETIME_WIDTH ? + field_length - MAX_DATETIME_WIDTH - 1: 0; + return new Field_datetimef(ptr, null_pos, null_bit, unireg_check, + field_name, dec); } case MYSQL_TYPE_NULL: return new Field_null(ptr, field_length, unireg_check, field_name, diff --git a/sql/field.h b/sql/field.h index 48d873beb32..feef0cbef08 100644 --- a/sql/field.h +++ b/sql/field.h @@ -30,6 +30,7 @@ #include "sql_string.h" /* String */ #include "my_decimal.h" /* my_decimal */ #include "sql_error.h" /* MYSQL_ERROR */ +#include "compat56.h" class Send_field; class Protocol; @@ -89,6 +90,42 @@ inline uint get_set_pack_length(int elements) return len > 4 ? 8 : len; } + +/** + Recognizer for concrete data type (called real_type for some reason), + returning true if it is one of the TIMESTAMP types. +*/ +inline bool is_timestamp_type(enum_field_types type) +{ + return type == MYSQL_TYPE_TIMESTAMP || type == MYSQL_TYPE_TIMESTAMP2; +} + + +/** + Convert temporal real types as retuned by field->real_type() + to field type as returned by field->type(). + + @param real_type Real type. + @retval Field type. +*/ +inline enum_field_types real_type_to_type(enum_field_types real_type) +{ + switch (real_type) + { + case MYSQL_TYPE_TIME2: + return MYSQL_TYPE_TIME; + case MYSQL_TYPE_DATETIME2: + return MYSQL_TYPE_DATETIME; + case MYSQL_TYPE_TIMESTAMP2: + return MYSQL_TYPE_TIMESTAMP; + case MYSQL_TYPE_NEWDATE: + return MYSQL_TYPE_DATE; + /* Note: NEWDECIMAL is a type, not only a real_type */ + default: return real_type; + } +} + + /* Virtual_column_info is the class to contain additional characteristics that is specific for a virtual/computed @@ -428,6 +465,54 @@ public: virtual uint32 key_length() const { return pack_length(); } virtual enum_field_types type() const =0; virtual enum_field_types real_type() const { return type(); } + virtual enum_field_types binlog_type() const + { + /* + Binlog stores field->type() as type code by default. For example, + it puts MYSQL_TYPE_STRING in case of CHAR, VARCHAR, SET and ENUM, + with extra data type details put into metadata. + + Binlog behaviour slightly differs between various MySQL and MariaDB + versions for the temporal data types TIME, DATETIME and TIMESTAMP. + + MySQL prior to 5.6 uses MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME + and MYSQL_TYPE_TIMESTAMP type codes in binlog and stores no + additional metadata. + + MariaDB-5.3 implements new versions for TIME, DATATIME, TIMESTAMP + with fractional second precision, but uses the old format for the + types TIME(0), DATETIME(0), TIMESTAMP(0), and it still stores + MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME and MYSQL_TYPE_TIMESTAMP in binlog, + with no additional metadata. + So row-based replication between temporal data types of + different precision is not possible in MariaDB. + + MySQL-5.6 also implements a new version of TIME, DATETIME, TIMESTAMP + which support fractional second precision 0..6, and use the new + format even for the types TIME(0), DATETIME(0), TIMESTAMP(0). + For these new data types, MySQL-5.6 stores new type codes + MYSQL_TYPE_TIME2, MYSQL_TYPE_DATETIME2, MYSQL_TYPE_TIMESTAMP2 in binlog, + with fractional precision 0..6 put into metadata. + This makes it in theory possible to do row-based replication between + columns of different fractional precision (e.g. from TIME(1) on master + to TIME(6) on slave). However, it's not currently fully implemented yet. + MySQL-5.6 can only do row-based replication from the old types + TIME, DATETIME, TIMESTAMP (represented by MYSQL_TYPE_TIME, + MYSQL_TYPE_DATETIME and MYSQL_TYPE_TIMESTAMP type codes in binlog) + to the new corresponding types TIME(0), DATETIME(0), TIMESTAMP(0). + + Note: MariaDB starting from the version 10.0 understands the new + MySQL-5.6 type codes MYSQL_TYPE_TIME2, MYSQL_TYPE_DATETIME2, + MYSQL_TYPE_TIMESTAMP2. When started over MySQL-5.6 tables both on + master and on slave, MariaDB-10.0 can also do row-based replication + from the old types TIME, DATETIME, TIMESTAMP to the new MySQL-5.6 + types TIME(0), DATETIME(0), TIMESTAMP(0). + + Note: perhaps binlog should eventually be modified to store + real_type() instead of type() for all column types. + */ + return type(); + } inline int cmp(const uchar *str) { return cmp(ptr,str); } virtual int cmp_max(const uchar *a, const uchar *b, uint max_len) { return cmp(a, b); } @@ -661,6 +746,16 @@ public: { return binary() ? &my_charset_bin : charset(); } virtual CHARSET_INFO *sort_charset(void) const { return charset(); } virtual bool has_charset(void) const { return FALSE; } + /* + match_collation_to_optimize_range() is to distinguish in + range optimizer (see opt_range.cc) between real string types: + CHAR, VARCHAR, TEXT + and the other string-alike types with result_type() == STRING_RESULT: + DATE, TIME, DATETIME, TIMESTAMP + We need it to decide whether to test if collation of the operation + matches collation of the field (needed only for real string types). + */ + virtual bool match_collation_to_optimize_range() const { return false; } virtual void set_charset(CHARSET_INFO *charset_arg) { } virtual enum Derivation derivation(void) const { return DERIVATION_IMPLICIT; } @@ -808,7 +903,8 @@ protected: { return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0; } - + double pos_in_interval_val_real(Field *min, Field *max); + double pos_in_interval_val_str(Field *min, Field *max, uint data_offset); }; @@ -847,7 +943,10 @@ public: bool get_int(CHARSET_INFO *cs, const char *from, uint len, longlong *rnd, ulonglong unsigned_max, longlong signed_min, longlong signed_max); - double pos_in_interval(Field *min, Field *max); + double pos_in_interval(Field *min, Field *max) + { + return pos_in_interval_val_real(min, max); + } }; @@ -860,23 +959,11 @@ public: uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg, CHARSET_INFO *charset); Item_result result_type () const { return STRING_RESULT; } - /* - match_collation_to_optimize_range() is to distinguish in - range optimizer (see opt_range.cc) between real string types: - CHAR, VARCHAR, TEXT - and the other string-alike types with result_type() == STRING_RESULT: - DATE, TIME, DATETIME, TIMESTAMP - We need it to decide whether to test if collation of the operation - matches collation of the field (needed only for real string types). - QQ: shouldn't DATE/TIME types have their own XXX_RESULT types eventually? - */ - virtual bool match_collation_to_optimize_range() const=0; uint decimals() const { return NOT_FIXED_DEC; } int store(double nr); int store(longlong nr, bool unsigned_val)=0; int store_decimal(const my_decimal *); int store(const char *to,uint length,CHARSET_INFO *cs)=0; - uint size_of() const { return sizeof(*this); } uint repertoire(void) const { return my_charset_repertoire(field_charset); @@ -894,7 +981,10 @@ public: uint is_equal(Create_field *new_field); bool eq_cmp_as_binary() { return test(flags & BINARY_FLAG); } virtual uint length_size() { return 0; } - double pos_in_interval(Field *min, Field *max); + double pos_in_interval(Field *min, Field *max) + { + return pos_in_interval_val_str(min, max, length_size()); + } }; /* base class for Field_string, Field_varstring and Field_blob */ @@ -914,6 +1004,7 @@ public: int store_decimal(const my_decimal *d); uint32 max_data_length() const; + bool match_collation_to_optimize_range() const { return true; } }; /* base class for float and double and decimal (old one) */ @@ -1323,7 +1414,6 @@ public: unireg_check_arg, field_name_arg, cs) {} enum_field_types type() const { return MYSQL_TYPE_NULL;} - bool match_collation_to_optimize_range() const { return FALSE; } int store(const char *to, uint length, CHARSET_INFO *cs) { null[0]=1; return 0; } int store(double nr) { null[0]=1; return 0; } @@ -1345,7 +1435,67 @@ public: }; -class Field_timestamp :public Field_str { +class Field_temporal: public Field { +public: + Field_temporal(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, + uchar null_bit_arg, utype unireg_check_arg, + const char *field_name_arg) + :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, + field_name_arg) + { flags|= BINARY_FLAG; } + Item_result result_type () const { return STRING_RESULT; } + uint32 max_display_length() { return field_length; } + bool str_needs_quotes() { return TRUE; } + enum Derivation derivation(void) const { return DERIVATION_NUMERIC; } + uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; } + CHARSET_INFO *charset(void) const { return &my_charset_numeric; } + const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } + bool binary() const { return true; } + enum Item_result cmp_type () const { return TIME_RESULT; } + uint is_equal(Create_field *new_field); + bool eq_def(Field *field) + { + return (Field::eq_def(field) && decimals() == field->decimals()); + } + my_decimal *val_decimal(my_decimal*); + void set_warnings(MYSQL_ERROR::enum_warning_level trunc_level, + const ErrConv *str, int was_cut, timestamp_type ts_type); + double pos_in_interval(Field *min, Field *max) + { + return pos_in_interval_val_real(min, max); + } +}; + + +/** + Abstract class for: + - DATE + - DATETIME + - DATETIME(1..6) + - DATETIME(0..6) - MySQL56 version +*/ +class Field_temporal_with_date: public Field_temporal { +protected: + int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, + int was_cut, int have_smth_to_conv); + virtual void store_TIME(MYSQL_TIME *ltime) = 0; +public: + Field_temporal_with_date(uchar *ptr_arg, uint32 len_arg, + uchar *null_ptr_arg, uchar null_bit_arg, + utype unireg_check_arg, + const char *field_name_arg) + :Field_temporal(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg) + {} + int store(const char *to, uint length, CHARSET_INFO *charset); + int store(double nr); + int store(longlong nr, bool unsigned_val); + int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_decimal(const my_decimal *); +}; + + +class Field_timestamp :public Field_temporal { protected: int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *, bool, bool); @@ -1353,21 +1503,14 @@ public: Field_timestamp(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, CHARSET_INFO *cs); - Field_timestamp(bool maybe_null_arg, const char *field_name_arg, - CHARSET_INFO *cs); + TABLE_SHARE *share); enum_field_types type() const { return MYSQL_TYPE_TIMESTAMP;} - bool match_collation_to_optimize_range() const { return FALSE; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } - enum Item_result cmp_type () const { return TIME_RESULT; } - enum Derivation derivation(void) const { return DERIVATION_NUMERIC; } - uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; } - CHARSET_INFO *charset(void) const { return &my_charset_numeric; } - bool binary() const { return 1; } int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_decimal(const my_decimal *); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -1377,7 +1520,6 @@ public: uint32 pack_length() const { return 4; } void sql_type(String &str) const; bool zero_pack() const { return 0; } - uint decimals() const { return 0; } virtual int set_time(); virtual void set_default() { @@ -1418,46 +1560,109 @@ public: { return unpack_int32(to, from, from_end); } + uint size_of() const { return sizeof(*this); } }; -class Field_timestamp_hires :public Field_timestamp { +/** + Abstract class for: + - TIMESTAMP(1..6) + - TIMESTAMP(0..6) - MySQL56 version +*/ +class Field_timestamp_with_dec :public Field_timestamp { +protected: uint dec; public: - Field_timestamp_hires(uchar *ptr_arg, - uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - TABLE_SHARE *share, uint dec_arg, CHARSET_INFO *cs) : - Field_timestamp(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + 1, null_ptr_arg, - null_bit_arg, unireg_check_arg, field_name_arg, share, cs), + Field_timestamp_with_dec(uchar *ptr_arg, + uchar *null_ptr_arg, uchar null_bit_arg, + enum utype unireg_check_arg, + const char *field_name_arg, + TABLE_SHARE *share, uint dec_arg) : + Field_timestamp(ptr_arg, + MAX_DATETIME_WIDTH + dec_arg + test(dec_arg), null_ptr_arg, + null_bit_arg, unireg_check_arg, field_name_arg, share), dec(dec_arg) { - DBUG_ASSERT(dec); DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); } - void sql_type(String &str) const; - my_time_t get_timestamp(ulong *sec_part) const; - void store_TIME(my_time_t timestamp, ulong sec_part); - int store_decimal(const my_decimal *d); - double val_real(void); - String *val_str(String*,String *); - my_decimal* val_decimal(my_decimal*); - bool send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); uint decimals() const { return dec; } - int set_time(); enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - void make_field(Send_field *field); - uint32 pack_length() const; uchar *pack(uchar *to, const uchar *from, uint max_length) { return Field::pack(to, from, max_length); } const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, uint param_data) { return Field::unpack(to, from, from_end, param_data); } + void make_field(Send_field *field); + void sort_string(uchar *to, uint length) + { + DBUG_ASSERT(length == pack_length()); + memcpy(to, ptr, length); + } + bool send_binary(Protocol *protocol); + double val_real(void); + my_decimal* val_decimal(my_decimal*); + int set_time(); +}; + + +class Field_timestamp_hires :public Field_timestamp_with_dec { +public: + Field_timestamp_hires(uchar *ptr_arg, + uchar *null_ptr_arg, uchar null_bit_arg, + enum utype unireg_check_arg, + const char *field_name_arg, + TABLE_SHARE *share, uint dec_arg) : + Field_timestamp_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg, share, dec_arg) + { + DBUG_ASSERT(dec); + } + my_time_t get_timestamp(ulong *sec_part) const; + void store_TIME(my_time_t timestamp, ulong sec_part); + int cmp(const uchar *,const uchar *); + uint32 pack_length() const; + uint size_of() const { return sizeof(*this); } +}; + + +/** + TIMESTAMP(0..6) - MySQL56 version +*/ +class Field_timestampf :public Field_timestamp_with_dec { + int do_save_field_metadata(uchar *metadata_ptr) + { + *metadata_ptr= decimals(); + return 1; + } +public: + Field_timestampf(uchar *ptr_arg, + uchar *null_ptr_arg, uchar null_bit_arg, + enum utype unireg_check_arg, + const char *field_name_arg, + TABLE_SHARE *share, uint dec_arg) : + Field_timestamp_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg, share, dec_arg) + {} + enum_field_types real_type() const { return MYSQL_TYPE_TIMESTAMP2; } + enum_field_types binlog_type() const { return MYSQL_TYPE_TIMESTAMP2; } + uint32 pack_length() const + { + return my_timestamp_binary_length(dec); + } + uint row_pack_length() { return pack_length(); } + uint pack_length_from_metadata(uint field_metadata) + { + DBUG_ENTER("Field_timestampf::pack_length_from_metadata"); + uint tmp= my_timestamp_binary_length(field_metadata); + DBUG_RETURN(tmp); + } + int cmp(const uchar *a_ptr,const uchar *b_ptr) + { + return memcmp(a_ptr, b_ptr, pack_length()); + } + void store_TIME(my_time_t timestamp, ulong sec_part); + my_time_t get_timestamp(ulong *sec_part) const; uint size_of() const { return sizeof(*this); } - bool eq_def(Field *field) - { return Field_str::eq_def(field) && dec == field->decimals(); } }; @@ -1484,56 +1689,24 @@ public: }; -class Field_temporal: public Field_str { -protected: - int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, - int was_cut, int have_smth_to_conv); - virtual void store_TIME(MYSQL_TIME *ltime) = 0; -public: - Field_temporal(uchar *ptr_arg,uint32 len_arg, uchar *null_ptr_arg, - uchar null_bit_arg, utype unireg_check_arg, - const char *field_name_arg, CHARSET_INFO *charset_arg) - :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, charset_arg) - { flags|= BINARY_FLAG; } - enum Derivation derivation(void) const { return DERIVATION_NUMERIC; } - uint repertoire(void) const { return MY_REPERTOIRE_NUMERIC; } - CHARSET_INFO *charset(void) const { return &my_charset_numeric; } - bool binary() const { return 1; } - bool match_collation_to_optimize_range() const { return FALSE; } - enum Item_result cmp_type () const { return TIME_RESULT; } - int store(const char *to,uint length,CHARSET_INFO *charset); - int store(double nr); - int store(longlong nr, bool unsigned_val); - int store_time_dec(MYSQL_TIME *ltime, uint dec); - my_decimal *val_decimal(my_decimal*); - bool eq_def(Field *field) - { - return (Field_str::eq_def(field) && decimals() == field->decimals()); - } -}; - -class Field_date :public Field_temporal { +class Field_date :public Field_temporal_with_date { void store_TIME(MYSQL_TIME *ltime); public: Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_temporal(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) {} + enum utype unireg_check_arg, const char *field_name_arg) + :Field_temporal_with_date(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg) {} enum_field_types type() const { return MYSQL_TYPE_DATE;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } int reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; } double val_real(void); longlong val_int(void); String *val_str(String*,String *); - uint decimals() const { return 0; } bool send_binary(Protocol *protocol); int cmp(const uchar *,const uchar *); void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 4; } void sql_type(String &str) const; - bool zero_pack() const { return 1; } uchar *pack(uchar* to, const uchar *from, uint max_length __attribute__((unused))) { @@ -1544,23 +1717,22 @@ public: { return unpack_int32(to, from, from_end); } + uint size_of() const { return sizeof(*this); } }; -class Field_newdate :public Field_temporal { +class Field_newdate :public Field_temporal_with_date { void store_TIME(MYSQL_TIME *ltime); public: Field_newdate(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - CHARSET_INFO *cs) - :Field_temporal(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) + enum utype unireg_check_arg, const char *field_name_arg) + :Field_temporal_with_date(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg) {} enum_field_types type() const { return MYSQL_TYPE_DATE;} enum_field_types real_type() const { return MYSQL_TYPE_NEWDATE; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_UINT24; } int reset(void) { ptr[0]=ptr[1]=ptr[2]=0; return 0; } - uint decimals() const { return 0; } double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -1569,19 +1741,22 @@ public: void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 3; } void sql_type(String &str) const; - bool zero_pack() const { return 1; } bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + uint size_of() const { return sizeof(*this); } }; class Field_time :public Field_temporal { - void store_TIME(MYSQL_TIME *ltime); +protected: + virtual void store_TIME(MYSQL_TIME *ltime); + int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, + int was_cut, int have_smth_to_conv); public: Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, - const char *field_name_arg, CHARSET_INFO *cs) + const char *field_name_arg) :Field_temporal(ptr_arg, length_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) + unireg_check_arg, field_name_arg) {} enum_field_types type() const { return MYSQL_TYPE_TIME;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } @@ -1589,7 +1764,7 @@ public: int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); - uint decimals() const { return 0; } + int store_decimal(const my_decimal *); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -1599,55 +1774,122 @@ public: void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 3; } void sql_type(String &str) const; - bool zero_pack() const { return 1; } + uint size_of() const { return sizeof(*this); } }; -class Field_time_hires :public Field_time { + +/** + Abstract class for: + - TIME(1..6) + - TIME(0..6) - MySQL56 version +*/ +class Field_time_with_dec :public Field_time { +protected: uint dec; +public: + Field_time_with_dec(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, + enum utype unireg_check_arg, const char *field_name_arg, + uint dec_arg) + :Field_time(ptr_arg, MIN_TIME_WIDTH + dec_arg + test(dec_arg), null_ptr_arg, + null_bit_arg, unireg_check_arg, field_name_arg), + dec(dec_arg) + { + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + } + uint decimals() const { return dec; } + enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } + longlong val_int(void); + double val_real(void); + void make_field(Send_field *); +}; + + +/** + TIME(1..6) +*/ +class Field_time_hires :public Field_time_with_dec { longlong zero_point; void store_TIME(MYSQL_TIME *ltime); public: Field_time_hires(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, - uint dec_arg, CHARSET_INFO *cs) - :Field_time(ptr_arg, MIN_TIME_WIDTH + dec_arg + 1, null_ptr_arg, - null_bit_arg, unireg_check_arg, field_name_arg, cs), - dec(dec_arg) + uint dec_arg) + :Field_time_with_dec(ptr_arg, null_ptr_arg, + null_bit_arg, unireg_check_arg, field_name_arg, + dec_arg) { DBUG_ASSERT(dec); - DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); zero_point= sec_part_shift( ((TIME_MAX_VALUE_SECONDS+1LL)*TIME_SECOND_PART_FACTOR), dec); } - enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - uint decimals() const { return dec; } - int store_decimal(const my_decimal *d); - longlong val_int(void); - double val_real(void); - String *val_str(String*,String *); int reset(void); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); - bool send_binary(Protocol *protocol); int cmp(const uchar *,const uchar *); void sort_string(uchar *buff,uint length); uint32 pack_length() const; - void sql_type(String &str) const; - void make_field(Send_field *); uint size_of() const { return sizeof(*this); } }; -class Field_datetime :public Field_temporal { + +/** + TIME(0..6) - MySQL56 version +*/ +class Field_timef :public Field_time_with_dec { + void store_TIME(MYSQL_TIME *ltime); + int do_save_field_metadata(uchar *metadata_ptr) + { + *metadata_ptr= decimals(); + return 1; + } +public: + Field_timef(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, + enum utype unireg_check_arg, const char *field_name_arg, + uint dec_arg) + :Field_time_with_dec(ptr_arg, null_ptr_arg, + null_bit_arg, unireg_check_arg, field_name_arg, + dec_arg) + { + DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); + } + enum_field_types real_type() const { return MYSQL_TYPE_TIME2; } + enum_field_types binlog_type() const { return MYSQL_TYPE_TIME2; } + uint32 pack_length() const + { + return my_time_binary_length(dec); + } + uint row_pack_length() { return pack_length(); } + uint pack_length_from_metadata(uint field_metadata) + { + DBUG_ENTER("Field_timef::pack_length_from_metadata"); + uint tmp= my_time_binary_length(field_metadata); + DBUG_RETURN(tmp); + } + void sort_string(uchar *to, uint length) + { + DBUG_ASSERT(length == Field_timef::pack_length()); + memcpy(to, ptr, length); + } + int cmp(const uchar *a_ptr, const uchar *b_ptr) + { + return memcmp(a_ptr, b_ptr, pack_length()); + } + int reset(); + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + uint size_of() const { return sizeof(*this); } +}; + + +class Field_datetime :public Field_temporal_with_date { void store_TIME(MYSQL_TIME *ltime); public: Field_datetime(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, - const char *field_name_arg, CHARSET_INFO *cs) - :Field_temporal(ptr_arg, length_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, cs) + const char *field_name_arg) + :Field_temporal_with_date(ptr_arg, length_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg) {} enum_field_types type() const { return MYSQL_TYPE_DATETIME;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } - uint decimals() const { return 0; } double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -1656,7 +1898,6 @@ public: void sort_string(uchar *buff,uint length); uint32 pack_length() const { return 8; } void sql_type(String &str) const; - bool zero_pack() const { return 1; } bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); virtual int set_time(); virtual void set_default() @@ -1690,85 +1931,149 @@ public: { return unpack_int64(to, from, from_end); } + uint size_of() const { return sizeof(*this); } }; -class Field_datetime_hires :public Field_datetime { - void store_TIME(MYSQL_TIME *ltime); +/** + Abstract class for: + - DATETIME(1..6) + - DATETIME(0..6) - MySQL56 version +*/ +class Field_datetime_with_dec :public Field_datetime { +protected: uint dec; public: - Field_datetime_hires(uchar *ptr_arg, uchar *null_ptr_arg, - uchar null_bit_arg, enum utype unireg_check_arg, - const char *field_name_arg, uint dec_arg, - CHARSET_INFO *cs) - :Field_datetime(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + 1, + Field_datetime_with_dec(uchar *ptr_arg, uchar *null_ptr_arg, + uchar null_bit_arg, enum utype unireg_check_arg, + const char *field_name_arg, uint dec_arg) + :Field_datetime(ptr_arg, MAX_DATETIME_WIDTH + dec_arg + test(dec_arg), null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, cs), dec(dec_arg) + field_name_arg), dec(dec_arg) { - DBUG_ASSERT(dec); DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); } - enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } uint decimals() const { return dec; } + enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } void make_field(Send_field *field); - int store_decimal(const my_decimal *d); - double val_real(void); - longlong val_int(void); - String *val_str(String*,String *); bool send_binary(Protocol *protocol); - int cmp(const uchar *,const uchar *); - void sort_string(uchar *buff,uint length); - uint32 pack_length() const; - void sql_type(String &str) const; - bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); uchar *pack(uchar *to, const uchar *from, uint max_length) { return Field::pack(to, from, max_length); } const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end, uint param_data) { return Field::unpack(to, from, from_end, param_data); } + void sort_string(uchar *to, uint length) + { + DBUG_ASSERT(length == pack_length()); + memcpy(to, ptr, length); + } + double val_real(void); + longlong val_int(void); + String *val_str(String*,String *); +}; + + +/** + DATETIME(1..6) +*/ +class Field_datetime_hires :public Field_datetime_with_dec { + void store_TIME(MYSQL_TIME *ltime); +public: + Field_datetime_hires(uchar *ptr_arg, uchar *null_ptr_arg, + uchar null_bit_arg, enum utype unireg_check_arg, + const char *field_name_arg, uint dec_arg) + :Field_datetime_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg, dec_arg) + { + DBUG_ASSERT(dec); + } + int cmp(const uchar *,const uchar *); + uint32 pack_length() const; + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); uint size_of() const { return sizeof(*this); } }; + +/** + DATETIME(0..6) - MySQL56 version +*/ +class Field_datetimef :public Field_datetime_with_dec { + void store_TIME(MYSQL_TIME *ltime); + int do_save_field_metadata(uchar *metadata_ptr) + { + *metadata_ptr= decimals(); + return 1; + } +public: + Field_datetimef(uchar *ptr_arg, uchar *null_ptr_arg, + uchar null_bit_arg, enum utype unireg_check_arg, + const char *field_name_arg, uint dec_arg) + :Field_datetime_with_dec(ptr_arg, null_ptr_arg, null_bit_arg, + unireg_check_arg, field_name_arg, dec_arg) + {} + enum_field_types real_type() const { return MYSQL_TYPE_DATETIME2; } + enum_field_types binlog_type() const { return MYSQL_TYPE_DATETIME2; } + uint32 pack_length() const + { + return my_datetime_binary_length(dec); + } + uint row_pack_length() { return pack_length(); } + uint pack_length_from_metadata(uint field_metadata) + { + DBUG_ENTER("Field_datetimef::pack_length_from_metadata"); + uint tmp= my_datetime_binary_length(field_metadata); + DBUG_RETURN(tmp); + } + int cmp(const uchar *a_ptr, const uchar *b_ptr) + { + return memcmp(a_ptr, b_ptr, pack_length()); + } + int reset(); + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); + uint size_of() const { return sizeof(*this); } +}; + + static inline Field_timestamp * new_Field_timestamp(uchar *ptr, uchar *null_ptr, uchar null_bit, enum Field::utype unireg_check, const char *field_name, - TABLE_SHARE *share, uint dec, CHARSET_INFO *cs) + TABLE_SHARE *share, uint dec) { if (dec==0) return new Field_timestamp(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit, - unireg_check, field_name, share, cs); + unireg_check, field_name, share); if (dec == NOT_FIXED_DEC) dec= MAX_DATETIME_PRECISION; return new Field_timestamp_hires(ptr, null_ptr, null_bit, unireg_check, - field_name, share, dec, cs); + field_name, share, dec); } static inline Field_time * new_Field_time(uchar *ptr, uchar *null_ptr, uchar null_bit, enum Field::utype unireg_check, const char *field_name, - uint dec, CHARSET_INFO *cs) + uint dec) { if (dec == 0) return new Field_time(ptr, MIN_TIME_WIDTH, null_ptr, null_bit, - unireg_check, field_name, cs); + unireg_check, field_name); if (dec == NOT_FIXED_DEC) dec= MAX_DATETIME_PRECISION; return new Field_time_hires(ptr, null_ptr, null_bit, - unireg_check, field_name, dec, cs); + unireg_check, field_name, dec); } static inline Field_datetime * new_Field_datetime(uchar *ptr, uchar *null_ptr, uchar null_bit, enum Field::utype unireg_check, - const char *field_name, uint dec, CHARSET_INFO *cs) + const char *field_name, uint dec) { if (dec == 0) return new Field_datetime(ptr, MAX_DATETIME_WIDTH, null_ptr, null_bit, - unireg_check, field_name, cs); + unireg_check, field_name); if (dec == NOT_FIXED_DEC) dec= MAX_DATETIME_PRECISION; return new Field_datetime_hires(ptr, null_ptr, null_bit, - unireg_check, field_name, dec, cs); + unireg_check, field_name, dec); } class Field_string :public Field_longstr { @@ -1795,7 +2100,6 @@ public: orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ? MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING); } - bool match_collation_to_optimize_range() const { return TRUE; } enum ha_base_keytype key_type() const { return binary() ? HA_KEYTYPE_BINARY : HA_KEYTYPE_TEXT; } bool zero_pack() const { return 0; } @@ -1876,7 +2180,6 @@ public: } enum_field_types type() const { return MYSQL_TYPE_VARCHAR; } - bool match_collation_to_optimize_range() const { return TRUE; } enum ha_base_keytype key_type() const; uint row_pack_length() { return field_length; } bool zero_pack() const { return 0; } @@ -1972,7 +2275,6 @@ public: :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info), packlength(packlength_arg) {} enum_field_types type() const { return MYSQL_TYPE_BLOB;} - bool match_collation_to_optimize_range() const { return TRUE; } enum ha_base_keytype key_type() const { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; } int store(const char *to,uint length,CHARSET_INFO *charset); @@ -2118,7 +2420,7 @@ public: { geom_type= geom_type_arg; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_VARBINARY2; } enum_field_types type() const { return MYSQL_TYPE_GEOMETRY; } - bool match_collation_to_optimize_range() const { return FALSE; } + bool match_collation_to_optimize_range() const { return false; } void sql_type(String &str) const; int store(const char *to, uint length, CHARSET_INFO *charset); int store(double nr); @@ -2156,7 +2458,6 @@ public: } Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type); enum_field_types type() const { return MYSQL_TYPE_STRING; } - bool match_collation_to_optimize_range() const { return FALSE; } enum Item_result cmp_type () const { return INT_RESULT; } enum ha_base_keytype key_type() const; int store(const char *to,uint length,CHARSET_INFO *charset); @@ -2309,7 +2610,10 @@ public: { store(*((longlong *)val), TRUE); } - double pos_in_interval(Field *min, Field *max); + double pos_in_interval(Field *min, Field *max) + { + return pos_in_interval_val_real(min, max); + } void get_image(uchar *buff, uint length, CHARSET_INFO *cs) { get_key_image(buff, length, itRAW); } void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index bd08cd2dc32..09ab6d48eba 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2012, Oracle and/or its affiliates. + Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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 @@ -63,6 +63,8 @@ #include "key.h" #include "sql_plugin.h" #include "table.h" /* HA_DATA_PARTITION */ +#include "sql_show.h" // append_identifier +#include "sql_admin.h" // SQL_ADMIN_MSG_TEXT_SIZE #include "debug_sync.h" @@ -287,6 +289,7 @@ void ha_partition::init_handler_variables() m_rec_length= 0; m_last_part= 0; m_rec0= 0; + m_err_rec= NULL; m_curr_key_info[0]= NULL; m_curr_key_info[1]= NULL; m_part_func_monotonicity_info= NON_MONOTONIC; @@ -1046,10 +1049,11 @@ int ha_partition::preload_keys(THD *thd, HA_CHECK_OPT *check_opt) 0 Success */ -static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, - handler *file, uint flag) +int ha_partition::handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, + uint part_id, uint flag) { int error; + handler *file= m_file[part_id]; DBUG_ENTER("handle_opt_part"); DBUG_PRINT("enter", ("flag = %u", flag)); @@ -1058,9 +1062,27 @@ static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, else if (flag == ANALYZE_PARTS) error= file->ha_analyze(thd, check_opt); else if (flag == CHECK_PARTS) + { error= file->ha_check(thd, check_opt); + if (!error || + error == HA_ADMIN_ALREADY_DONE || + error == HA_ADMIN_NOT_IMPLEMENTED) + { + if (check_opt->flags & (T_MEDIUM | T_EXTEND)) + error= check_misplaced_rows(part_id, false); + } + } else if (flag == REPAIR_PARTS) + { error= file->ha_repair(thd, check_opt); + if (!error || + error == HA_ADMIN_ALREADY_DONE || + error == HA_ADMIN_NOT_IMPLEMENTED) + { + if (check_opt->flags & (T_MEDIUM | T_EXTEND)) + error= check_misplaced_rows(part_id, true); + } + } else if (flag == ASSIGN_KEYCACHE_PARTS) error= file->assign_to_keycache(thd, check_opt); else if (flag == PRELOAD_KEYS_PARTS) @@ -1082,11 +1104,11 @@ static int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, TODO: move this into the handler, or rewrite mysql_admin_table. */ static bool print_admin_msg(THD* thd, const char* msg_type, - const char* db_name, const char* table_name, + const char* db_name, String &table_name, const char* op_name, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 6, 7); static bool print_admin_msg(THD* thd, const char* msg_type, - const char* db_name, const char* table_name, + const char* db_name, String &table_name, const char* op_name, const char *fmt, ...) { va_list args; @@ -1107,7 +1129,7 @@ static bool print_admin_msg(THD* thd, const char* msg_type, return TRUE; } - length=(uint) (strxmov(name, db_name, ".", table_name,NullS) - name); + length=(uint) (strxmov(name, db_name, ".", table_name.c_ptr_safe(), NullS) - name); /* TODO: switch from protocol to push_warning here. The main reason we didn't it yet is parallel repair. Due to following trace: @@ -1179,15 +1201,14 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, part= i * num_subparts + j; DBUG_PRINT("info", ("Optimize subpartition %u (%s)", part, sub_elem->partition_name)); - if ((error= handle_opt_part(thd, check_opt, m_file[part], flag))) + if ((error= handle_opt_part(thd, check_opt, part, flag))) { /* print a line which partition the error belongs to */ if (error != HA_ADMIN_NOT_IMPLEMENTED && error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, - table->alias.c_ptr(), + print_admin_msg(thd, "error", table_share->db.str, table->alias, opt_op_name[flag], "Subpartition %s returned error", sub_elem->partition_name); @@ -1206,15 +1227,14 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, { DBUG_PRINT("info", ("Optimize partition %u (%s)", i, part_elem->partition_name)); - if ((error= handle_opt_part(thd, check_opt, m_file[i], flag))) + if ((error= handle_opt_part(thd, check_opt, i, flag))) { /* print a line which partition the error belongs to */ if (error != HA_ADMIN_NOT_IMPLEMENTED && error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, "error", table_share->db.str, - table->alias.c_ptr(), + print_admin_msg(thd, "error", table_share->db.str, table->alias, opt_op_name[flag], "Partition %s returned error", part_elem->partition_name); } @@ -3583,7 +3603,7 @@ exit: Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc. new_data is always record[0] - old_data is normally record[1] but may be anything + old_data is always record[1] */ int ha_partition::update_row(const uchar *old_data, uchar *new_data) @@ -3593,6 +3613,7 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) int error= 0; longlong func_value; DBUG_ENTER("ha_partition::update_row"); + m_err_rec= NULL; if ((error= get_parts_for_update(old_data, new_data, table->record[0], m_part_info, &old_part_id, &new_part_id, @@ -3601,6 +3622,25 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data) m_part_info->err_value= func_value; goto exit; } + /* + The protocol for updating a row is: + 1) position the handler (cursor) on the row to be updated, + either through the last read row (rnd or index) or by rnd_pos. + 2) call update_row with both old and new full records as arguments. + + This means that m_last_part should already be set to actual partition + where the row was read from. And if that is not the same as the + calculated part_id we found a misplaced row, we return an error to + notify the user that something is broken in the row distribution + between partitions! Since we don't check all rows on read, we return an + error instead of correcting m_last_part, to make the user aware of the + problem! + */ + if (old_part_id != m_last_part) + { + m_err_rec= old_data; + DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); + } m_last_part= new_part_id; start_part_bulk_insert(thd, new_part_id); @@ -3705,12 +3745,34 @@ int ha_partition::delete_row(const uchar *buf) int error; THD *thd= ha_thd(); DBUG_ENTER("ha_partition::delete_row"); + m_err_rec= NULL; if ((error= get_part_for_delete(buf, m_rec0, m_part_info, &part_id))) { DBUG_RETURN(error); } - m_last_part= part_id; + /* + The protocol for deleting a row is: + 1) position the handler (cursor) on the row to be deleted, + either through the last read row (rnd or index) or by rnd_pos. + 2) call delete_row with the full record as argument. + + This means that m_last_part should already be set to actual partition + where the row was read from. And if that is not the same as the + calculated part_id we found a misplaced row, we return an error to + notify the user that something is broken in the row distribution + between partitions! Since we don't check all rows on read, we return an + error instead of forwarding the delete to the correct (m_last_part) + partition! + TODO: change the assert in InnoDB into an error instead and make this one + an assert instead and remove the get_part_for_delete()! + */ + if (part_id != m_last_part) + { + m_err_rec= buf; + DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); + } + tmp_disable_binlog(thd); error= m_file[part_id]->ha_delete_row(buf); reenable_binlog(thd); @@ -4557,7 +4619,6 @@ int ha_partition::index_init(uint inx, bool sorted) file= m_file; do { - /* TODO RONM: Change to index_init() when code is stable */ if (bitmap_is_set(&(m_part_info->used_partitions), (file - m_file))) if ((error= (*file)->ha_index_init(inx, sorted))) { @@ -7010,6 +7071,57 @@ enum row_type ha_partition::get_row_type() const } +void ha_partition::append_row_to_str(String &str) +{ + Field **field_ptr; + const uchar *rec; + bool is_rec0= !m_err_rec || m_err_rec == table->record[0]; + if (is_rec0) + rec= table->record[0]; + else + rec= m_err_rec; + // If PK, use full PK instead of full part field array! + if (table->s->primary_key != MAX_KEY) + { + KEY *key= table->key_info + table->s->primary_key; + KEY_PART_INFO *key_part= key->key_part; + KEY_PART_INFO *key_part_end= key_part + key->key_parts; + if (!is_rec0) + set_key_field_ptr(key, rec, table->record[0]); + for (; key_part != key_part_end; key_part++) + { + Field *field= key_part->field; + str.append(" "); + str.append(field->field_name); + str.append(":"); + field_unpack(&str, field, rec, 0, false); + } + if (!is_rec0) + set_key_field_ptr(key, table->record[0], rec); + } + else + { + if (!is_rec0) + set_field_ptr(m_part_info->full_part_field_array, rec, + table->record[0]); + /* No primary key, use full partition field array. */ + for (field_ptr= m_part_info->full_part_field_array; + *field_ptr; + field_ptr++) + { + Field *field= *field_ptr; + str.append(" "); + str.append(field->field_name); + str.append(":"); + field_unpack(&str, field, rec, 0, false); + } + if (!is_rec0) + set_field_ptr(m_part_info->full_part_field_array, table->record[0], + rec); + } +} + + void ha_partition::print_error(int error, myf errflag) { THD *thd= ha_thd(); @@ -7018,24 +7130,72 @@ void ha_partition::print_error(int error, myf errflag) /* Should probably look for my own errors first */ DBUG_PRINT("enter", ("error: %d", error)); - if ((error == HA_ERR_NO_PARTITION_FOUND) && - ! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION)) - m_part_info->print_no_partition_found(table); - else + if (error == HA_ERR_NO_PARTITION_FOUND) { - /* In case m_file has not been initialized, like in bug#42438 */ - if (m_file) + switch(thd_sql_command(thd)) { - if (m_last_part >= m_tot_parts) + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + if (m_err_rec) { - DBUG_ASSERT(0); - m_last_part= 0; + uint max_length; + char buf[MAX_KEY_LENGTH]; + const char *msg= "Found a row in wrong partition ("; + String str(buf,sizeof(buf),system_charset_info); + uint32 part_id; + /* Should only happen on DELETE or UPDATE! */ + str.length(0); + str.append_ulonglong(m_last_part); + str.append(" != "); + if (!get_part_for_delete(m_err_rec, m_rec0, m_part_info, &part_id)) + { + str.append_ulonglong(part_id); + } + str.append(")"); + append_row_to_str(str); + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s' corrupted: %s%s\n" + "Please CHECK and REPAIR the table!", + table->s->table_name.str, msg, str.c_ptr_safe()); + + max_length= (MYSQL_ERRMSG_SIZE- + (uint) strlen(msg)); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_printf_error(ER_NO_PARTITION_FOR_GIVEN_VALUE, "%s%s", MYF(0), + msg, str.c_ptr_safe()); + m_err_rec= NULL; + DBUG_VOID_RETURN; } - m_file[m_last_part]->print_error(error, errflag); + default: + { + if (!(thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION)) + { + m_part_info->print_no_partition_found(table); + DBUG_VOID_RETURN; + } + } + /* fall through to generic error handling. */ } - else - handler::print_error(error, errflag); } + + /* In case m_file has not been initialized, like in bug#42438 */ + if (m_file) + { + if (m_last_part >= m_tot_parts) + { + DBUG_ASSERT(0); + m_last_part= 0; + } + m_file[m_last_part]->print_error(error, errflag); + } + else + handler::print_error(error, errflag); DBUG_VOID_RETURN; } @@ -7729,6 +7889,288 @@ int ha_partition::indexes_are_disabled(void) } +/** + Check/fix misplaced rows. + + @param read_part_id Partition to check/fix. + @param repair If true, move misplaced rows to correct partition. + + @return Operation status. + @retval 0 Success + @retval != 0 Error +*/ + +int ha_partition::check_misplaced_rows(uint read_part_id, bool repair) +{ + int result= 0; + uint32 correct_part_id; + longlong func_value; + longlong num_misplaced_rows= 0; + + DBUG_ENTER("ha_partition::check_misplaced_rows"); + + DBUG_ASSERT(m_file); + + if (repair) + { + /* We must read the full row, if we need to move it! */ + bitmap_set_all(table->read_set); + bitmap_set_all(table->write_set); + } + else + { + /* Only need to read the partitioning fields. */ + bitmap_union(table->read_set, &m_part_info->full_part_field_set); + } + + if ((result= m_file[read_part_id]->ha_rnd_init(1))) + DBUG_RETURN(result); + + while (true) + { + if ((result= m_file[read_part_id]->rnd_next(m_rec0))) + { + if (result == HA_ERR_RECORD_DELETED) + continue; + if (result != HA_ERR_END_OF_FILE) + break; + + if (num_misplaced_rows > 0) + { + print_admin_msg(ha_thd(), "warning", table_share->db.str, table->alias, + opt_op_name[REPAIR_PARTS], + "Moved %lld misplaced rows", + num_misplaced_rows); + } + /* End-of-file reached, all rows are now OK, reset result and break. */ + result= 0; + break; + } + + result= m_part_info->get_partition_id(m_part_info, &correct_part_id, + &func_value); + if (result) + break; + + if (correct_part_id != read_part_id) + { + num_misplaced_rows++; + if (!repair) + { + /* Check. */ + print_admin_msg(ha_thd(), "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + "Found a misplaced row"); + /* Break on first misplaced row! */ + result= HA_ADMIN_NEEDS_UPGRADE; + break; + } + else + { + DBUG_PRINT("info", ("Moving row from partition %d to %d", + read_part_id, correct_part_id)); + + /* + Insert row into correct partition. Notice that there are no commit + for every N row, so the repair will be one large transaction! + */ + if ((result= m_file[correct_part_id]->ha_write_row(m_rec0))) + { + /* + We have failed to insert a row, it might have been a duplicate! + */ + char buf[MAX_KEY_LENGTH]; + String str(buf,sizeof(buf),system_charset_info); + str.length(0); + if (result == HA_ERR_FOUND_DUPP_KEY) + { + str.append("Duplicate key found, " + "please update or delete the record:\n"); + result= HA_ADMIN_CORRUPT; + } + m_err_rec= NULL; + append_row_to_str(str); + + /* + If the engine supports transactions, the failure will be + rollbacked. + */ + if (!m_file[correct_part_id]->has_transactions()) + { + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s' failed to move/insert a row" + " from part %d into part %d:\n%s", + table->s->table_name.str, + read_part_id, + correct_part_id, + str.c_ptr_safe()); + } + print_admin_msg(ha_thd(), "error", table_share->db.str, table->alias, + opt_op_name[REPAIR_PARTS], + "Failed to move/insert a row" + " from part %d into part %d:\n%s", + read_part_id, + correct_part_id, + str.c_ptr_safe()); + break; + } + + /* Delete row from wrong partition. */ + if ((result= m_file[read_part_id]->ha_delete_row(m_rec0))) + { + if (m_file[correct_part_id]->has_transactions()) + break; + /* + We have introduced a duplicate, since we failed to remove it + from the wrong partition. + */ + char buf[MAX_KEY_LENGTH]; + String str(buf,sizeof(buf),system_charset_info); + str.length(0); + m_err_rec= NULL; + append_row_to_str(str); + + /* Log this error, so the DBA can notice it and fix it! */ + sql_print_error("Table '%-192s': Delete from part %d failed with" + " error %d. But it was already inserted into" + " part %d, when moving the misplaced row!" + "\nPlease manually fix the duplicate row:\n%s", + table->s->table_name.str, + read_part_id, + result, + correct_part_id, + str.c_ptr_safe()); + break; + } + } + } + } + + int tmp_result= m_file[read_part_id]->ha_rnd_end(); + DBUG_RETURN(result ? result : tmp_result); +} + + +#define KEY_PARTITIONING_CHANGED_STR \ + "KEY () partitioning changed, please run:\nALTER TABLE %s.%s %s" + +int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt) +{ + int error= HA_ADMIN_NEEDS_CHECK; + DBUG_ENTER("ha_partition::check_for_upgrade"); + + /* + This is called even without FOR UPGRADE, + if the .frm version is lower than the current version. + In that case return that it needs checking! + */ + if (!(check_opt->sql_flags & TT_FOR_UPGRADE)) + DBUG_RETURN(error); + + /* + Partitions will be checked for during their ha_check! + + Check if KEY (sub)partitioning was used and any field's hash calculation + differs from 5.1, see bug#14521864. + */ + if (table->s->mysql_version < 50503 && // 5.1 table (<5.5.3) + ((m_part_info->part_type == HASH_PARTITION && // KEY partitioned + m_part_info->list_of_part_fields) || + (m_is_sub_partitioned && // KEY subpartitioned + m_part_info->list_of_subpart_fields))) + { + Field **field; + if (m_is_sub_partitioned) + { + field= m_part_info->subpart_field_array; + } + else + { + field= m_part_info->part_field_array; + } + for (; *field; field++) + { + switch ((*field)->real_type()) { + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_SET: + { + THD *thd= ha_thd(); + char *part_buf; + String db_name, table_name; + uint part_buf_len; + bool skip_generation= false; + partition_info::enum_key_algorithm old_algorithm; + old_algorithm= m_part_info->key_algorithm; + error= HA_ADMIN_FAILED; + append_identifier(ha_thd(), &db_name, table_share->db.str, + table_share->db.length); + append_identifier(ha_thd(), &table_name, table_share->table_name.str, + table_share->table_name.length); + if (m_part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE) + { + /* + Only possible when someone tampered with .frm files, + like during tests :) + */ + skip_generation= true; + } + m_part_info->key_algorithm= partition_info::KEY_ALGORITHM_51; + if (skip_generation || + !(part_buf= generate_partition_syntax(m_part_info, + &part_buf_len, + true, + true, + NULL, + NULL, + NULL)) || + /* Also check that the length is smaller than the output field! */ + (part_buf_len + db_name.length() + table_name.length()) >= + (SQL_ADMIN_MSG_TEXT_SIZE - + (strlen(KEY_PARTITIONING_CHANGED_STR) - 3))) + { + print_admin_msg(thd, "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + KEY_PARTITIONING_CHANGED_STR, + db_name.c_ptr_safe(), table_name.c_ptr_safe(), + ", but add ALGORITHM = 1" + " between 'KEY' and '(' to change the metadata" + " without the need of a full table rebuild."); + } + else + { + print_admin_msg(thd, "error", table_share->db.str, table->alias, + opt_op_name[CHECK_PARTS], + KEY_PARTITIONING_CHANGED_STR, + db_name.c_ptr_safe(), table_name.c_ptr_safe(), + part_buf); + } + m_part_info->key_algorithm= old_algorithm; + DBUG_RETURN(error); + } + default: + /* Not affected! */ + ; + } + } + } + + DBUG_RETURN(error); +} + + struct st_mysql_storage_engine partition_storage_engine= { MYSQL_HANDLERTON_INTERFACE_VERSION }; diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 55f199401f3..fd1056d7b3f 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -2,7 +2,7 @@ #define HA_PARTITION_INCLUDED /* - Copyright (c) 2005, 2012, Oracle and/or its affiliates. + Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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 @@ -25,13 +25,15 @@ #include "queues.h" /* QUEUE */ enum partition_keywords -{ +{ PKW_HASH= 0, PKW_RANGE, PKW_LIST, PKW_KEY, PKW_MAXVALUE, PKW_LINEAR, - PKW_COLUMNS + PKW_COLUMNS, PKW_ALGORITHM }; #define PARTITION_BYTES_IN_POS 2 -#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | HA_REC_NOT_IN_SEQ) +#define PARTITION_ENABLED_TABLE_FLAGS (HA_FILE_BASED | \ + HA_REC_NOT_IN_SEQ | \ + HA_CAN_REPAIR) #define PARTITION_DISABLED_TABLE_FLAGS (HA_CAN_GEOMETRY | \ HA_CAN_FULLTEXT | \ HA_DUPLICATE_POS | \ @@ -84,6 +86,7 @@ private: */ KEY *m_curr_key_info[3]; // Current index uchar *m_rec0; // table->record[0] + const uchar *m_err_rec; // record which gave error QUEUE m_queue; // Prio queue used by sorted read /* Since the partition handler is a handler on top of other handlers, it @@ -1089,9 +1092,18 @@ public: virtual bool check_and_repair(THD *thd); virtual bool auto_repair(int error) const; virtual bool is_crashed() const; + virtual int check_for_upgrade(HA_CHECK_OPT *check_opt); private: int handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, uint flags); + int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, uint part_id, + uint flag); + /** + Check if the rows are placed in the correct partition. If the given + argument is true, then move the rows to the correct partition. + */ + int check_misplaced_rows(uint read_part_id, bool repair); + void append_row_to_str(String &str); public: /* ------------------------------------------------------------------------- diff --git a/sql/handler.cc b/sql/handler.cc index 8c8089a61fb..ec30057758c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. - Copyright (c) 2009, 2012, Monty Program Ab. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2013, 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 @@ -40,6 +40,7 @@ #include "probes_mysql.h" #include #include "debug_sync.h" // DEBUG_SYNC +#include "sql_audit.h" #ifdef WITH_PARTITION_STORAGE_ENGINE #include "ha_partition.h" @@ -275,7 +276,8 @@ handler *get_ha_partition(partition_info *part_info) } else { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast(sizeof(ha_partition))); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast(sizeof(ha_partition))); } DBUG_RETURN(((handler*) partition)); } @@ -2260,7 +2262,7 @@ handle_condition(THD *, { *cond_hdl= NULL; /* Grab the error message */ - strmake(buff, msg, sizeof(buff)-1); + strmake_buf(buff, msg); return TRUE; } @@ -3778,6 +3780,9 @@ int handler::ha_check(THD *thd, HA_CHECK_OPT *check_opt) } if ((error= check(thd, check_opt))) return error; + /* Skip updating frm version if not main handler. */ + if (table->file != this) + return error; return update_frm_version(table); } @@ -4030,7 +4035,6 @@ int handler::ha_delete_table(const char *name) { mark_trx_read_write(); - return delete_table(name); } @@ -4063,8 +4067,11 @@ int handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info) { mark_trx_read_write(); - - return create(name, form, info); + int error= create(name, form, info); + if (!error && + !(info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER))) + mysql_audit_create_table(form); + return error; } @@ -5575,7 +5582,11 @@ int handler::ha_external_lock(THD *thd, int lock_type) { error= external_lock(thd, lock_type); }) if (error == 0) + { cached_table_flags= table_flags(); + if (table_share->tmp_table == NO_TMP_TABLE) + mysql_audit_external_lock(thd, table_share, lock_type); + } if (MYSQL_HANDLER_RDLOCK_DONE_ENABLED() || MYSQL_HANDLER_WRLOCK_DONE_ENABLED() || @@ -5630,6 +5641,8 @@ int handler::ha_write_row(uchar *buf) Log_func *log_func= Write_rows_log_event::binlog_row_logging_function; DBUG_ENTER("handler::ha_write_row"); DEBUG_SYNC_C("ha_write_row_start"); + DBUG_EXECUTE_IF("inject_error_ha_write_row", + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); ); MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); @@ -5660,6 +5673,7 @@ int handler::ha_update_row(const uchar *old_data, uchar *new_data) (and the old record is in record[1]). */ DBUG_ASSERT(new_data == table->record[0]); + DBUG_ASSERT(old_data == table->record[1]); MYSQL_UPDATE_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); @@ -5681,6 +5695,13 @@ int handler::ha_delete_row(const uchar *buf) { int error; Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function; + /* + Normally table->record[0] is used, but sometimes table->record[1] is used. + */ + DBUG_ASSERT(buf == table->record[0] || + buf == table->record[1]); + DBUG_EXECUTE_IF("inject_error_ha_delete_row", + return HA_ERR_INTERNAL_ERROR; ); MYSQL_DELETE_ROW_START(table_share->db.str, table_share->table_name.str); mark_trx_read_write(); diff --git a/sql/handler.h b/sql/handler.h index c5639053fe2..c67360da44d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -287,7 +287,7 @@ (yes, the sum is deliberately inaccurate) TODO remove the limit, use dynarrays */ -#define MAX_HA 15 +#define MAX_HA 64 /* Use this instead of 0 as the initial value for the slot number of @@ -320,7 +320,7 @@ #define HA_LEX_CREATE_TMP_TABLE 1 #define HA_LEX_CREATE_IF_NOT_EXISTS 2 #define HA_LEX_CREATE_TABLE_LIKE 4 -#define HA_CREATE_TMP_ALTER 8 +#define HA_CREATE_TMP_ALTER 8 #define HA_MAX_REC_LENGTH 65535 /* Table caching type */ diff --git a/sql/item.cc b/sql/item.cc index ecc7917022e..21eacb38401 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2010, 2013, Monty Program Ab This program is free software; you can redistribute it and/or modify @@ -377,6 +377,27 @@ my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value) } +longlong Item::val_int_from_date() +{ + DBUG_ASSERT(fixed == 1); + MYSQL_TIME ltime; + if (get_date(<ime, TIME_FUZZY_DATE)) + return 0; + longlong v= TIME_to_ulonglong(<ime); + return ltime.neg ? -v : v; +} + + +double Item::val_real_from_date() +{ + DBUG_ASSERT(fixed == 1); + MYSQL_TIME ltime; + if (get_date(<ime, TIME_FUZZY_DATE)) + return 0; + return TIME_to_double(<ime); +} + + double Item::val_real_from_decimal() { /* Note that fix_fields may not be called for Item_avg_field items */ @@ -513,7 +534,7 @@ Item::Item(THD *thd, Item *item): with_field(item->with_field), fixed(item->fixed), is_autogenerated_name(item->is_autogenerated_name), - with_subselect(item->with_subselect), + with_subselect(item->has_subquery()), collation(item->collation), cmp_context(item->cmp_context) { @@ -651,9 +672,12 @@ Item_result Item::cmp_type() const case MYSQL_TYPE_GEOMETRY: return STRING_RESULT; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIME2: case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: case MYSQL_TYPE_NEWDATE: return TIME_RESULT; }; @@ -1269,7 +1293,7 @@ bool Item::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) String tmp(buff,sizeof(buff), &my_charset_bin),*res; if (!(res=val_str(&tmp)) || str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(), - ltime, fuzzydate) <= MYSQL_TIMESTAMP_ERROR) + ltime, fuzzydate)) goto err; break; } @@ -3218,11 +3242,7 @@ void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type, value.time= *tm; value.time.time_type= time_type; - if (value.time.year > 9999 || value.time.month > 12 || - value.time.day > 31 || - (time_type != MYSQL_TIMESTAMP_TIME && value.time.hour > 23) || - value.time.minute > 59 || value.time.second > 59 || - value.time.second_part > TIME_MAX_SECOND_PART) + if (check_datetime_range(&value.time)) { ErrConvTime str(&value.time); make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, @@ -4416,7 +4436,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) if (db_name && lower_case_table_names) { /* Convert database to lower case for comparison */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } @@ -5678,19 +5698,17 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table, bool fixed_length) break; case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_DATE: - field= new Field_newdate(0, null_ptr, 0, Field::NONE, name, &my_charset_bin); + field= new Field_newdate(0, null_ptr, 0, Field::NONE, name); break; case MYSQL_TYPE_TIME: - field= new_Field_time(0, null_ptr, 0, Field::NONE, name, - decimals, &my_charset_bin); + field= new_Field_time(0, null_ptr, 0, Field::NONE, name, decimals); break; case MYSQL_TYPE_TIMESTAMP: field= new_Field_timestamp(0, null_ptr, 0, - Field::NONE, name, 0, decimals, &my_charset_bin); + Field::NONE, name, 0, decimals); break; case MYSQL_TYPE_DATETIME: - field= new_Field_datetime(0, null_ptr, 0, Field::NONE, name, - decimals, &my_charset_bin); + field= new_Field_datetime(0, null_ptr, 0, Field::NONE, name, decimals); break; case MYSQL_TYPE_YEAR: field= new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE, @@ -6127,17 +6145,8 @@ inline uint char_val(char X) X-'a'+10); } -Item_hex_string::Item_hex_string() -{ - hex_string_init("", 0); -} -Item_hex_string::Item_hex_string(const char *str, uint str_length) -{ - hex_string_init(str, str_length); -} - -void Item_hex_string::hex_string_init(const char *str, uint str_length) +void Item_hex_constant::hex_string_init(const char *str, uint str_length) { max_length=(str_length+1)/2; char *ptr=(char*) sql_alloc(max_length+1); @@ -6161,7 +6170,7 @@ void Item_hex_string::hex_string_init(const char *str, uint str_length) unsigned_flag= 1; } -longlong Item_hex_string::val_int() +longlong Item_hex_hybrid::val_int() { // following assert is redundant, because fixed=1 assigned in constructor DBUG_ASSERT(fixed == 1); @@ -6175,17 +6184,7 @@ longlong Item_hex_string::val_int() } -my_decimal *Item_hex_string::val_decimal(my_decimal *decimal_value) -{ - // following assert is redundant, because fixed=1 assigned in constructor - DBUG_ASSERT(fixed == 1); - ulonglong value= (ulonglong)val_int(); - int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value); - return (decimal_value); -} - - -int Item_hex_string::save_in_field(Field *field, bool no_conversions) +int Item_hex_hybrid::save_in_field(Field *field, bool no_conversions) { field->set_notnull(); if (field->result_type() == STRING_RESULT) @@ -6218,22 +6217,27 @@ warn: } -void Item_hex_string::print(String *str, enum_query_type query_type) +void Item_hex_hybrid::print(String *str, enum_query_type query_type) { - char *end= (char*) str_value.ptr() + str_value.length(), - *ptr= end - min(str_value.length(), sizeof(longlong)); + uint32 len= min(str_value.length(), sizeof(longlong)); + const char *ptr= str_value.ptr() + str_value.length() - len; str->append("0x"); - for (; ptr != end ; ptr++) - { - str->append(_dig_vec_lower[((uchar) *ptr) >> 4]); - str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]); - } + str->append_hex(ptr, len); } -bool Item_hex_string::eq(const Item *arg, bool binary_cmp) const +void Item_hex_string::print(String *str, enum_query_type query_type) { - if (arg->basic_const_item() && arg->type() == type()) + str->append("X'"); + str->append_hex(str_value.ptr(), str_value.length()); + str->append("'"); +} + + +bool Item_hex_constant::eq(const Item *arg, bool binary_cmp) const +{ + if (arg->basic_const_item() && arg->type() == type() && + arg->cast_to_int_type() == cast_to_int_type()) { if (binary_cmp) return !stringcmp(&str_value, &arg->str_value); @@ -6243,7 +6247,7 @@ bool Item_hex_string::eq(const Item *arg, bool binary_cmp) const } -Item *Item_hex_string::safe_charset_converter(CHARSET_INFO *tocs) +Item *Item_hex_constant::safe_charset_converter(CHARSET_INFO *tocs) { Item_string *conv; String tmp, *str= val_str(&tmp); @@ -6300,6 +6304,76 @@ Item_bin_string::Item_bin_string(const char *str, uint str_length) } +bool Item_temporal_literal::eq(const Item *item, bool binary_cmp) const +{ + return + item->basic_const_item() && type() == item->type() && + field_type() == ((Item_temporal_literal *) item)->field_type() && + !my_time_compare(&cached_time, + &((Item_temporal_literal *) item)->cached_time); +} + + +void Item_date_literal::print(String *str, enum_query_type query_type) +{ + str->append("DATE'"); + char buf[MAX_DATE_STRING_REP_LENGTH]; + my_date_to_str(&cached_time, buf); + str->append(buf); + str->append('\''); +} + + +bool Item_date_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +{ + DBUG_ASSERT(fixed); + *ltime= cached_time; + return (null_value= check_date_with_warn(ltime, fuzzy_date, + MYSQL_TIMESTAMP_ERROR)); +} + + +void Item_datetime_literal::print(String *str, enum_query_type query_type) +{ + str->append("TIMESTAMP'"); + char buf[MAX_DATE_STRING_REP_LENGTH]; + my_datetime_to_str(&cached_time, buf, decimals); + str->append(buf); + str->append('\''); +} + + +bool Item_datetime_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +{ + DBUG_ASSERT(fixed); + *ltime= cached_time; + return (null_value= check_date_with_warn(ltime, fuzzy_date, + MYSQL_TIMESTAMP_ERROR)); +} + + +void Item_time_literal::print(String *str, enum_query_type query_type) +{ + str->append("TIME'"); + char buf[MAX_DATE_STRING_REP_LENGTH]; + my_time_to_str(&cached_time, buf, decimals); + str->append(buf); + str->append('\''); +} + + +bool Item_time_literal::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) +{ + DBUG_ASSERT(fixed); + *ltime= cached_time; + if (fuzzy_date & TIME_TIME_ONLY) + return (null_value= false); + return (null_value= check_date_with_warn(ltime, fuzzy_date, + MYSQL_TIMESTAMP_ERROR)); +} + + + /** Pack data in buffer for sending. */ diff --git a/sql/item.h b/sql/item.h index b3d08011a39..a298f16a93b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1,8 +1,8 @@ #ifndef SQL_ITEM_INCLUDED #define SQL_ITEM_INCLUDED -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. - Copyright (c) 2009, 2013 Monty Program Ab +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2013 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 @@ -384,6 +384,12 @@ struct Name_resolution_context: Sql_alloc { (*error_processor)(thd, error_processor_data); } + st_select_lex *outer_select() + { + return (outer_context ? + outer_context->select_lex : + NULL); + } }; @@ -593,7 +599,8 @@ public: SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM, XPATH_NODESET, XPATH_NODESET_CMP, - VIEW_FIXER_ITEM, EXPR_CACHE_ITEM}; + VIEW_FIXER_ITEM, EXPR_CACHE_ITEM, + DATE_ITEM}; enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; @@ -950,7 +957,9 @@ public: my_decimal *val_decimal_from_date(my_decimal *decimal_value); my_decimal *val_decimal_from_time(my_decimal *decimal_value); longlong val_int_from_decimal(); + longlong val_int_from_date(); double val_real_from_decimal(); + double val_real_from_date(); int save_time_in_field(Field *field); int save_date_in_field(Field *field); @@ -1107,8 +1116,8 @@ public: */ virtual CHARSET_INFO *charset_for_protocol(void) const { - return result_type() == STRING_RESULT ? collation.collation : - &my_charset_bin; + return cmp_type() == STRING_RESULT ? collation.collation : + &my_charset_bin; }; virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg) @@ -1466,6 +1475,12 @@ public: Return TRUE if the item points to a column of an outer-joined table. */ virtual bool is_outer_field() const { DBUG_ASSERT(fixed); return FALSE; } + + /** + Checks if this item or any of its decendents contains a subquery. + */ + virtual bool has_subquery() const { return with_subselect; } + Item* set_expr_cache(THD *thd); virtual Item_equal *get_item_equal() { return NULL; } @@ -2754,41 +2769,221 @@ public: }; -class Item_hex_string: public Item_basic_constant +/** + Item_hex_constant -- a common class for hex literals: X'HHHH' and 0xHHHH +*/ +class Item_hex_constant: public Item_basic_constant { +private: + void hex_string_init(const char *str, uint str_length); public: - Item_hex_string(); - Item_hex_string(const char *str,uint str_length); - enum Type type() const { return VARBIN_ITEM; } - double val_real() - { - DBUG_ASSERT(fixed == 1); - return (double) (ulonglong) Item_hex_string::val_int(); + Item_hex_constant() + { + hex_string_init("", 0); } - longlong val_int(); - bool basic_const_item() const { return 1; } - String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } - my_decimal *val_decimal(my_decimal *); - int save_in_field(Field *field, bool no_conversions); + Item_hex_constant(const char *str, uint str_length) + { + hex_string_init(str, str_length); + } + enum Type type() const { return VARBIN_ITEM; } enum Item_result result_type () const { return STRING_RESULT; } - enum Item_result cast_to_int_type() const { return INT_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } - virtual void print(String *str, enum_query_type query_type); - bool eq(const Item *item, bool binary_cmp) const; virtual Item *safe_charset_converter(CHARSET_INFO *tocs); bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_vcol_func_processor(uchar *arg) { return FALSE;} -private: - void hex_string_init(const char *str, uint str_length); + bool basic_const_item() const { return 1; } + bool eq(const Item *item, bool binary_cmp) const; + String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } }; -class Item_bin_string: public Item_hex_string +/** + Item_hex_hybrid -- is a class implementing 0xHHHH literals, e.g.: + SELECT 0x3132; + They can behave as numbers and as strings depending on context. +*/ +class Item_hex_hybrid: public Item_hex_constant +{ +public: + Item_hex_hybrid(): Item_hex_constant() {} + Item_hex_hybrid(const char *str, uint str_length): + Item_hex_constant(str, str_length) {} + double val_real() + { + DBUG_ASSERT(fixed == 1); + return (double) (ulonglong) Item_hex_hybrid::val_int(); + } + longlong val_int(); + my_decimal *val_decimal(my_decimal *decimal_value) + { + // following assert is redundant, because fixed=1 assigned in constructor + DBUG_ASSERT(fixed == 1); + ulonglong value= (ulonglong) Item_hex_hybrid::val_int(); + int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value); + return decimal_value; + } + int save_in_field(Field *field, bool no_conversions); + enum Item_result cast_to_int_type() const { return INT_RESULT; } + void print(String *str, enum_query_type query_type); +}; + + +/** + Item_hex_string -- is a class implementing X'HHHH' literals, e.g.: + SELECT X'3132'; + Unlike Item_hex_hybrid, X'HHHH' literals behave as strings in all contexts. + X'HHHH' are also used in replication of string constants in case of + "dangerous" charsets (sjis, cp932, big5, gbk) who can have backslash (0x5C) + as the second byte of a multi-byte character, so using '\' escaping for + these charsets is not desirable. +*/ +class Item_hex_string: public Item_hex_constant +{ +public: + Item_hex_string(): Item_hex_constant() {} + Item_hex_string(const char *str, uint str_length): + Item_hex_constant(str, str_length) {} + longlong val_int() + { + DBUG_ASSERT(fixed == 1); + return longlong_from_string_with_check(str_value.charset(), + str_value.ptr(), + str_value.ptr()+ + str_value.length()); + } + double val_real() + { + DBUG_ASSERT(fixed == 1); + return double_from_string_with_check(str_value.charset(), + str_value.ptr(), + str_value.ptr() + + str_value.length()); + } + my_decimal *val_decimal(my_decimal *decimal_value) + { + return val_decimal_from_string(decimal_value); + } + int save_in_field(Field *field, bool no_conversions) + { + field->set_notnull(); + return field->store(str_value.ptr(), str_value.length(), + collation.collation); + } + enum Item_result cast_to_int_type() const { return STRING_RESULT; } + void print(String *str, enum_query_type query_type); +}; + + +class Item_bin_string: public Item_hex_hybrid { public: Item_bin_string(const char *str,uint str_length); }; + +class Item_temporal_literal :public Item_basic_constant +{ + //sql_mode= current_thd->variables.sql_mode & + // (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE); +protected: + MYSQL_TIME cached_time; +public: + /** + Constructor for Item_date_literal. + @param ltime DATE value. + */ + Item_temporal_literal(MYSQL_TIME *ltime) :Item_basic_constant() + { + collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); + decimals= 0; + cached_time= *ltime; + } + Item_temporal_literal(MYSQL_TIME *ltime, uint dec_arg) :Item_basic_constant() + { + collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); + decimals= dec_arg; + cached_time= *ltime; + } + bool basic_const_item() const { return true; } + bool const_item() const { return true; } + enum Type type() const { return DATE_ITEM; } + bool eq(const Item *item, bool binary_cmp) const; + enum Item_result result_type () const { return STRING_RESULT; } + Item_result cmp_type() const { return TIME_RESULT; } + + bool check_partition_func_processor(uchar *int_arg) {return FALSE;} + bool check_vcol_func_processor(uchar *arg) { return FALSE;} + + String *val_str(String *str) + { return val_string_from_date(str); } + longlong val_int() + { return val_int_from_date(); } + double val_real() + { return val_real_from_date(); } + my_decimal *val_decimal(my_decimal *decimal_value) + { return val_decimal_from_date(decimal_value); } + Field *tmp_table_field(TABLE *table) + { return tmp_table_field_from_field_type(table, 0); } + int save_in_field(Field *field, bool no_conversions) + { return save_date_in_field(field); } +}; + + +/** + DATE'2010-01-01' +*/ +class Item_date_literal: public Item_temporal_literal +{ +public: + Item_date_literal(MYSQL_TIME *ltime) + :Item_temporal_literal(ltime) + { + max_length= MAX_DATE_WIDTH; + fixed= 1; + } + enum_field_types field_type() const { return MYSQL_TYPE_DATE; } + void print(String *str, enum_query_type query_type); + bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); +}; + + +/** + TIME'10:10:10' +*/ +class Item_time_literal: public Item_temporal_literal +{ +public: + Item_time_literal(MYSQL_TIME *ltime, uint dec_arg) + :Item_temporal_literal(ltime, dec_arg) + { + max_length= MIN_TIME_WIDTH + (decimals ? decimals + 1 : 0); + fixed= 1; + } + enum_field_types field_type() const { return MYSQL_TYPE_TIME; } + void print(String *str, enum_query_type query_type); + bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); +}; + + +/** + TIMESTAMP'2001-01-01 10:20:30' +*/ +class Item_datetime_literal: public Item_temporal_literal +{ +public: + Item_datetime_literal(MYSQL_TIME *ltime, uint dec_arg) + :Item_temporal_literal(ltime, dec_arg) + { + max_length= MAX_DATETIME_WIDTH + (decimals ? decimals + 1 : 0); + fixed= 1; + } + enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } + void print(String *str, enum_query_type query_type); + bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date); +}; + + + class Item_result_field :public Item /* Item with result field */ { public: @@ -2987,6 +3182,14 @@ public: DBUG_ASSERT(ref); return (*ref)->is_outer_field(); } + + /** + Checks if the item tree that ref points to contains a subquery. + */ + virtual bool has_subquery() const + { + return (*ref)->has_subquery(); + } }; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 7ca85a72cfa..057d75676dc 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -721,31 +721,31 @@ bool get_mysql_time_from_str(THD *thd, String *str, timestamp_type warn_type, const char *warn_name, MYSQL_TIME *l_time) { bool value; - int error; - enum_mysql_timestamp_type timestamp_type; + MYSQL_TIME_STATUS status; int flags= TIME_FUZZY_DATE | MODE_INVALID_DATES; ErrConvString err(str); - if (warn_type == MYSQL_TIMESTAMP_TIME) - flags|= TIME_TIME_ONLY; + DBUG_ASSERT(warn_type != MYSQL_TIMESTAMP_TIME); - timestamp_type= - str_to_datetime(str->charset(), str->ptr(), str->length(), - l_time, flags, &error); - - if (timestamp_type > MYSQL_TIMESTAMP_ERROR) + if (!str_to_datetime(str->charset(), str->ptr(), str->length(), + l_time, flags, &status)) + { + DBUG_ASSERT(l_time->time_type == MYSQL_TIMESTAMP_DATETIME || + l_time->time_type == MYSQL_TIMESTAMP_DATE); /* Do not return yet, we may still want to throw a "trailing garbage" warning. */ value= FALSE; + } else { + DBUG_ASSERT(l_time->time_type != MYSQL_TIMESTAMP_TIME); + DBUG_ASSERT(status.warnings != 0); // Must be set by set_to_datetime() value= TRUE; - error= 1; /* force warning */ } - if (error > 0) + if (status.warnings > 0) make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, &err, warn_type, warn_name); @@ -4352,7 +4352,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) with_sum_func= with_sum_func || item->with_sum_func; with_field= with_field || item->with_field; - with_subselect|= item->with_subselect; + with_subselect|= item->has_subquery(); if (item->maybe_null) maybe_null=1; } @@ -5052,7 +5052,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref) return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; with_field= args[0]->with_field || args[1]->with_field; - with_subselect|= args[0]->with_subselect | args[1]->with_subselect; + with_subselect= args[0]->has_subquery() || args[1]->has_subquery(); max_length= 1; decimals= 0; diff --git a/sql/item_create.cc b/sql/item_create.cc index ce4dc7ced8f..c6d0f09907b 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -32,6 +32,7 @@ #include "set_var.h" #include "sp_head.h" #include "sp.h" +#include "sql_time.h" /* ============================================================================= @@ -5821,6 +5822,70 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, } +/** + Builder for datetime literals: + TIME'00:00:00', DATE'2001-01-01', TIMESTAMP'2001-01-01 00:00:00'. + @param thd The current thread + @param str Character literal + @param length Length of str + @param type Type of literal (TIME, DATE or DATETIME) + @param send_error Whether to generate an error on failure +*/ + +Item *create_temporal_literal(THD *thd, + const char *str, uint length, + CHARSET_INFO *cs, + enum_field_types type, + bool send_error) +{ + MYSQL_TIME_STATUS status; + MYSQL_TIME ltime; + Item *item= NULL; + ulonglong datetime_flags= thd->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | + MODE_NO_ZERO_DATE | + MODE_INVALID_DATES); + ulonglong flags= TIME_FUZZY_DATE | datetime_flags; + + switch(type) + { + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_NEWDATE: + if (!str_to_datetime(cs, str, length, <ime, flags, &status) && + ltime.time_type == MYSQL_TIMESTAMP_DATE && !status.warnings) + item= new (thd->mem_root) Item_date_literal(<ime); + break; + case MYSQL_TYPE_DATETIME: + if (!str_to_datetime(cs, str, length, <ime, flags, &status) && + ltime.time_type == MYSQL_TIMESTAMP_DATETIME && !status.warnings) + item= new (thd->mem_root) Item_datetime_literal(<ime, + status.precision); + break; + case MYSQL_TYPE_TIME: + if (!str_to_time(cs, str, length, <ime, 0, &status) && + ltime.time_type == MYSQL_TIMESTAMP_TIME && !status.warnings) + item= new (thd->mem_root) Item_time_literal(<ime, + status.precision); + break; + default: + DBUG_ASSERT(0); + } + + if (item) + return item; + + if (send_error) + { + const char *typestr= + (type == MYSQL_TYPE_DATE) ? "DATE" : + (type == MYSQL_TYPE_TIME) ? "TIME" : "DATETIME"; + ErrConvString err(str, length, thd->variables.character_set_client); + my_error(ER_WRONG_VALUE, MYF(0), typestr, err.ptr()); + } + return NULL; +} + + static List *create_func_dyncol_prepare(THD *thd, DYNCALL_CREATE_DEF **dfs, List &list) diff --git a/sql/item_create.h b/sql/item_create.h index 5ecb45e9eae..5f1a8c6006d 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -168,6 +168,11 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, const char *len, const char *dec, CHARSET_INFO *cs); +Item *create_temporal_literal(THD *thd, + const char *str, uint length, + CHARSET_INFO *cs, + enum_field_types type, + bool send_error); int item_create_init(); void item_create_cleanup(); diff --git a/sql/item_func.cc b/sql/item_func.cc index a231b245b53..7aad5ea0fd6 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ #pragma implementation // gcc: Class implementation #endif -#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_plugin.h" #include "sql_priv.h" /* It is necessary to include set_var.h instead of item.h because there @@ -52,8 +52,6 @@ #include "sp.h" #include "set_var.h" #include "debug_sync.h" -#include -#include #ifdef NO_EMBEDDED_ACCESS_CHECKS #define sp_restore_security_context(A,B) while (0) {} @@ -225,7 +223,7 @@ Item_func::fix_fields(THD *thd, Item **ref) with_field= with_field || item->with_field; used_tables_cache|= item->used_tables(); const_item_cache&= item->const_item(); - with_subselect|= item->with_subselect; + with_subselect|= item->has_subquery(); } } fix_length_and_dec(); @@ -5478,7 +5476,7 @@ enum Item_result Item_func_get_user_var::result_type() const void Item_func_get_user_var::print(String *str, enum_query_type query_type) { str->append(STRING_WITH_LEN("(@")); - str->append(name.str,name.length); + append_identifier(current_thd, str, name.str, name.length); str->append(')'); } diff --git a/sql/item_func.h b/sql/item_func.h index ab6ec706248..bdf91810d81 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -552,12 +552,18 @@ public: class Item_func_signed :public Item_int_func { public: - Item_func_signed(Item *a) :Item_int_func(a) {} + Item_func_signed(Item *a) :Item_int_func(a) + { + unsigned_flag= 0; + } const char *func_name() const { return "cast_as_signed"; } longlong val_int(); longlong val_int_from_str(int *error); void fix_length_and_dec() - { fix_char_length(args[0]->max_char_length()); unsigned_flag=0; } + { + fix_char_length(min(args[0]->max_char_length(), + MY_INT64_NUM_DECIMAL_DIGITS)); + } virtual void print(String *str, enum_query_type query_type); uint decimal_precision() const { return args[0]->decimal_precision(); } }; @@ -566,14 +572,11 @@ public: class Item_func_unsigned :public Item_func_signed { public: - Item_func_unsigned(Item *a) :Item_func_signed(a) {} - const char *func_name() const { return "cast_as_unsigned"; } - void fix_length_and_dec() + Item_func_unsigned(Item *a) :Item_func_signed(a) { - fix_char_length(min(args[0]->max_char_length(), - DECIMAL_MAX_PRECISION + 2)); - unsigned_flag=1; + unsigned_flag= 1; } + const char *func_name() const { return "cast_as_unsigned"; } longlong val_int(); virtual void print(String *str, enum_query_type query_type); }; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5dcd83681c6..1495456bda4 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -62,6 +62,8 @@ C_MODE_END #include #include "sql_statistics.h" +size_t username_char_length= 16; + /** @todo Remove this. It is not safe to use a shared String object. */ @@ -3970,7 +3972,9 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg) type= DYN_COL_NULL; break; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: type= DYN_COL_DATETIME; break; case MYSQL_TYPE_DATE: @@ -3978,6 +3982,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg) type= DYN_COL_DATE; break; case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIME2: type= DYN_COL_TIME; break; case MYSQL_TYPE_VARCHAR: @@ -4720,7 +4725,7 @@ bool Item_dyncol_get::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) if (str_to_datetime_with_warn(&my_charset_numeric, val.x.string.value.str, val.x.string.value.length, - ltime, fuzzy_date) <= MYSQL_TIMESTAMP_ERROR) + ltime, fuzzy_date)) goto null; return 0; case DYN_COL_DATETIME: diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 169da25e826..9daddf94c0b 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -25,6 +25,8 @@ #pragma interface /* gcc class implementation */ #endif +extern size_t username_char_length; + class MY_LOCALE; class Item_str_func :public Item_func @@ -510,8 +512,8 @@ public: bool fix_fields(THD *thd, Item **ref); void fix_length_and_dec() { - max_length= (USERNAME_LENGTH + - (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN); + max_length= (username_char_length + + HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN; } const char *func_name() const { return "user"; } const char *fully_qualified_func_name() const { return "user()"; } diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 03afd1a4365..92fff032095 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -65,7 +65,15 @@ ulonglong Item_sum::ram_limitation(THD *thd) bool Item_sum::init_sum_func_check(THD *thd) { - if (!thd->lex->allow_sum_func) + SELECT_LEX *curr_sel= thd->lex->current_select; + if (!curr_sel->name_visibility_map) + { + for (SELECT_LEX *sl= curr_sel; sl; sl= sl->context.outer_select()) + { + curr_sel->name_visibility_map|= (1 << sl-> nest_level); + } + } + if (!(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) { my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), MYF(0)); @@ -136,8 +144,11 @@ bool Item_sum::init_sum_func_check(THD *thd) bool Item_sum::check_sum_func(THD *thd, Item **ref) { + SELECT_LEX *curr_sel= thd->lex->current_select; + nesting_map allow_sum_func= (thd->lex->allow_sum_func & + curr_sel->name_visibility_map); bool invalid= FALSE; - nesting_map allow_sum_func= thd->lex->allow_sum_func; + DBUG_ASSERT(curr_sel->name_visibility_map); // should be set already /* The value of max_arg_level is updated if an argument of the set function contains a column reference resolved against a subquery whose level is @@ -172,7 +183,7 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) if (!invalid && aggr_level < 0) { aggr_level= nest_level; - aggr_sel= thd->lex->current_select; + aggr_sel= curr_sel; } /* By this moment we either found a subquery where the set function is @@ -309,9 +320,9 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) { SELECT_LEX *sl; nesting_map allow_sum_func= thd->lex->allow_sum_func; - for (sl= thd->lex->current_select->master_unit()->outer_select() ; + for (sl= thd->lex->current_select->context.outer_select() ; sl && sl->nest_level > max_arg_level; - sl= sl->master_unit()->outer_select() ) + sl= sl->context.outer_select()) { if (aggr_level < 0 && (allow_sum_func & ((nesting_map)1 << sl->nest_level))) @@ -1296,16 +1307,16 @@ Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table, switch (args[0]->field_type()) { case MYSQL_TYPE_DATE: field= new Field_newdate(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE, - name, collation.collation); + name); break; case MYSQL_TYPE_TIME: field= new_Field_time(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE, - name, decimals, collation.collation); + name, decimals); break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATETIME: field= new_Field_datetime(0, maybe_null ? (uchar*)"" : 0, 0, Field::NONE, - name, decimals, collation.collation); + name, decimals); break; default: return Item_sum::create_tmp_field(group, table, convert_blob_length); diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index f43a4e79431..c0e623f499c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1574,7 +1574,7 @@ static void set_sec_part(ulong sec_part, MYSQL_TIME *ltime, Item *item) { ltime->second_part= sec_part; if (item->decimals < TIME_SECOND_PART_DIGITS) - ltime->second_part= sec_part_truncate(ltime->second_part, item->decimals); + my_time_trunc(ltime, item->decimals); } } @@ -2411,7 +2411,7 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) if (get_arg0_time(ltime)) return 1; if (decimals < TIME_SECOND_PART_DIGITS) - ltime->second_part= sec_part_truncate(ltime->second_part, decimals); + my_time_trunc(ltime, decimals); /* MYSQL_TIMESTAMP_TIME value can have non-zero day part, which we should not lose. @@ -2430,17 +2430,8 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; ltime->time_type= MYSQL_TIMESTAMP_DATE; - - int unused; - if (check_date(ltime, ltime->year || ltime->month || ltime->day, - fuzzy_date, &unused)) - { - ErrConvTime str(ltime); - make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, - &str, MYSQL_TIMESTAMP_DATE, 0); - return (null_value= 1); - } - return (null_value= 0); + return (null_value= check_date_with_warn(ltime, fuzzy_date, + MYSQL_TIMESTAMP_DATE)); } @@ -2450,8 +2441,7 @@ bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) return 1; if (decimals < TIME_SECOND_PART_DIGITS) - ltime->second_part= sec_part_truncate(ltime->second_part, decimals); - + my_time_trunc(ltime, decimals); /* ltime is valid MYSQL_TYPE_TIME (according to fuzzy_date). diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 9b2db9e816e..3f58fe09af1 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -489,7 +489,6 @@ public: Item_temporal_func(Item *a, Item *b) :Item_func(a,b) {} Item_temporal_func(Item *a, Item *b, Item *c) :Item_func(a,b,c) {} enum Item_result result_type () const { return STRING_RESULT; } - CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } Item_result cmp_type() const { return TIME_RESULT; } String *val_str(String *str); diff --git a/sql/key.cc b/sql/key.cc index dd7818119c8..0d3db2d5bf5 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -335,6 +335,70 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) return 0; } + +/** + Unpack a field and append it. + + @param[inout] to String to append the field contents to. + @param field Field to unpack. + @param rec Record which contains the field data. + @param max_length Maximum length of field to unpack + or 0 for unlimited. + @param prefix_key The field is used as a prefix key. +*/ + +void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, + bool prefix_key) +{ + String tmp; + DBUG_ENTER("field_unpack"); + if (!max_length) + max_length= field->pack_length(); + if (field) + { + if (field->is_null()) + { + to->append(STRING_WITH_LEN("NULL")); + DBUG_VOID_RETURN; + } + CHARSET_INFO *cs= field->charset(); + field->val_str(&tmp); + /* + For BINARY(N) strip trailing zeroes to make + the error message nice-looking + */ + if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length()) + { + const char *tmp_end= tmp.ptr() + tmp.length(); + while (tmp_end > tmp.ptr() && !*--tmp_end) ; + tmp.length(tmp_end - tmp.ptr() + 1); + } + if (cs->mbmaxlen > 1 && prefix_key) + { + /* + Prefix key, multi-byte charset. + For the columns of type CHAR(N), the above val_str() + call will return exactly "key_part->length" bytes, + which can break a multi-byte characters in the middle. + Align, returning not more than "char_length" characters. + */ + uint charpos, char_length= max_length / cs->mbmaxlen; + if ((charpos= my_charpos(cs, tmp.ptr(), + tmp.ptr() + tmp.length(), + char_length)) < tmp.length()) + tmp.length(charpos); + } + if (max_length < field->pack_length()) + tmp.length(min(tmp.length(),max_length)); + ErrConvString err(&tmp); + to->append(err.ptr()); + } + else + to->append(STRING_WITH_LEN("???")); + DBUG_VOID_RETURN; +} + + /* unpack key-fields from record to some buffer. @@ -352,8 +416,6 @@ bool key_cmp_if_same(TABLE *table,const uchar *key,uint idx,uint key_length) void key_unpack(String *to,TABLE *table,uint idx) { KEY_PART_INFO *key_part,*key_part_end; - Field *field; - String tmp; my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set); DBUG_ENTER("key_unpack"); @@ -369,47 +431,13 @@ void key_unpack(String *to,TABLE *table,uint idx) { if (table->record[0][key_part->null_offset] & key_part->null_bit) { - to->append(STRING_WITH_LEN("NULL")); - continue; + to->append(STRING_WITH_LEN("NULL")); + continue; } } - if ((field=key_part->field)) - { - CHARSET_INFO *cs= field->charset(); - field->val_str(&tmp); - /* - For BINARY(N) strip trailing zeroes to make - the error message nice-looking - */ - if (field->binary() && field->type() == MYSQL_TYPE_STRING && tmp.length()) - { - const char *tmp_end= tmp.ptr() + tmp.length(); - while (tmp_end > tmp.ptr() && !*--tmp_end) ; - tmp.length(tmp_end - tmp.ptr() + 1); - } - if (cs->mbmaxlen > 1 && (key_part->key_part_flag & HA_PART_KEY_SEG)) - { - /* - Prefix key, multi-byte charset. - For the columns of type CHAR(N), the above val_str() - call will return exactly "key_part->length" bytes, - which can break a multi-byte characters in the middle. - Align, returning not more than "char_length" characters. - */ - uint charpos, char_length= key_part->length / cs->mbmaxlen; - if ((charpos= my_charpos(cs, tmp.ptr(), - tmp.ptr() + tmp.length(), - char_length)) < tmp.length()) - tmp.length(charpos); - } - if (key_part->length < field->pack_length()) - tmp.length(min(tmp.length(),key_part->length)); - ErrConvString err(&tmp); - to->append(err.ptr()); - } - else - to->append(STRING_WITH_LEN("???")); - } + field_unpack(to, key_part->field, table->record[0], key_part->length, + test(key_part->key_part_flag & HA_PART_KEY_SEG)); + } dbug_tmp_restore_column_map(table->read_set, old_map); DBUG_VOID_RETURN; } diff --git a/sql/key.h b/sql/key.h index 8bf6f88fa04..0eeda58cd17 100644 --- a/sql/key.h +++ b/sql/key.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -33,6 +33,8 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info, uint key_length); bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length); void key_unpack(String *to,TABLE *form,uint index); +void field_unpack(String *to, Field *field, const uchar *rec, uint max_length, + bool prefix_key); bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields); int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length); ulong key_hashnr(KEY *key_info, uint used_key_parts, const uchar *key); diff --git a/sql/log.cc b/sql/log.cc index aba3c67583b..36940579ce5 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -189,7 +189,7 @@ Silence_log_table_errors::handle_condition(THD *, MYSQL_ERROR ** cond_hdl) { *cond_hdl= NULL; - strmake(m_message, msg, sizeof(m_message)-1); + strmake_buf(m_message, msg); return TRUE; } @@ -3557,8 +3557,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, mysql_file_sync(log_file.file, MYF(MY_WME|MY_SYNC_FILESIZE))) goto err; mysql_mutex_lock(&LOCK_commit_ordered); - strmake(last_commit_pos_file, log_file_name, - sizeof(last_commit_pos_file)-1); + strmake_buf(last_commit_pos_file, log_file_name); last_commit_pos_offset= my_b_tell(&log_file); mysql_mutex_unlock(&LOCK_commit_ordered); @@ -3646,7 +3645,7 @@ int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo) int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO* linfo) { - strmake(linfo->log_file_name, log_file_name, sizeof(linfo->log_file_name)-1); + strmake_buf(linfo->log_file_name, log_file_name); linfo->pos = my_b_tell(&log_file); return 0; } @@ -4167,8 +4166,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) Reset rli's coordinates to the current log. */ rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); /* If we removed the rli->group_relay_log_name file, @@ -4178,8 +4176,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) if (included) { rli->group_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); rli->notify_group_relay_log_name_update(); } @@ -4687,9 +4684,7 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) else { if (stat_area.st_mtime < purge_time) - strmake(to_log, - log_info.log_file_name, - sizeof(log_info.log_file_name) - 1); + strmake_buf(to_log, log_info.log_file_name); else break; } @@ -5332,8 +5327,7 @@ binlog_start_consistent_snapshot(handlerton *hton, THD *thd) binlog_cache_mngr *const cache_mngr= thd->binlog_setup_trx_data(); /* Server layer calls us with LOCK_commit_ordered locked, so this is safe. */ - strmake(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file, - sizeof(cache_mngr->last_commit_pos_file)-1); + strmake_buf(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file); cache_mngr->last_commit_pos_offset= mysql_bin_log.last_commit_pos_offset; trans_register_ha(thd, TRUE, hton); @@ -6968,8 +6962,8 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) if ((current->error= write_transaction_or_stmt(current))) current->commit_errno= errno; - strmake(cache_mngr->last_commit_pos_file, log_file_name, - sizeof(cache_mngr->last_commit_pos_file)-1); + + strmake_buf(cache_mngr->last_commit_pos_file, log_file_name); commit_offset= my_b_write_tell(&log_file); cache_mngr->last_commit_pos_offset= commit_offset; if (cache_mngr->using_xa && cache_mngr->xa_xid) @@ -8488,7 +8482,7 @@ int TC_LOG_BINLOG::open(const char *opt_name) do { - strmake(log_name, log_info.log_file_name, sizeof(log_name)-1); + strmake_buf(log_name, log_info.log_file_name); } while (!(error= find_next_log(&log_info, 1))); if (error != LOG_INFO_EOF) @@ -9221,7 +9215,7 @@ static void set_binlog_snapshot_file(const char *src) { int dir_len = dirname_length(src); - strmake(binlog_snapshot_file, src + dir_len, sizeof(binlog_snapshot_file)-1); + strmake_buf(binlog_snapshot_file, src + dir_len); } /* diff --git a/sql/log_event.cc b/sql/log_event.cc index 2968764920e..6bb96bf2f7d 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -48,6 +48,7 @@ #include #include "sql_show.h" // append_identifier #include +#include "compat56.h" #if WITH_WSREP #include "wsrep_mysqld.h" @@ -675,16 +676,18 @@ static inline int read_str(const char **buf, const char *buf_end, /** - Transforms a string into "" or its expression in 0x... form. + Transforms a string into "" or its expression in X'HHHH' form. */ char *str_to_hex(char *to, const char *from, uint len) { if (len) { - *to++= '0'; - *to++= 'x'; + *to++= 'X'; + *to++= '\''; to= octet2hex(to, from, len); + *to++= '\''; + *to= '\0'; } else to= strmov(to, "\"\""); @@ -705,7 +708,7 @@ append_query_string(THD *thd, CHARSET_INFO *csinfo, { char *beg, *ptr; uint32 const orig_len= to->length(); - if (to->reserve(orig_len + from->length()*2+3)) + if (to->reserve(orig_len + from->length() * 2 + 4)) return 1; beg= (char*) to->ptr() + to->length(); @@ -1273,7 +1276,9 @@ bool Log_event::write_header(IO_CACHE* file, ulong event_data_length) int Log_event::read_log_event(IO_CACHE* file, String* packet, mysql_mutex_t* log_lock, - uint8 checksum_alg_arg) + uint8 checksum_alg_arg, + const char *log_file_name_arg, + bool* is_binlog_active) { ulong data_len; int result=0; @@ -1283,6 +1288,10 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, if (log_lock) mysql_mutex_lock(log_lock); + + if (log_file_name_arg) + *is_binlog_active= mysql_bin_log.is_active(log_file_name_arg); + if (my_b_read(file, (uchar*) buf, sizeof(buf))) { /* @@ -2123,6 +2132,17 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr, return 4; } + case MYSQL_TYPE_TIMESTAMP2: + { + char buf[MAX_DATE_STRING_REP_LENGTH]; + struct timeval tm; + my_timestamp_from_binary(&tm, ptr, meta); + int buflen= my_timeval_to_str(&tm, buf, meta); + my_b_write(file, buf, buflen); + my_snprintf(typestr, typestr_length, "TIMESTAMP(%d)", meta); + return my_timestamp_binary_length(meta); + } + case MYSQL_TYPE_DATETIME: { ulong d, t; @@ -2137,15 +2157,41 @@ log_event_print_value(IO_CACHE *file, const uchar *ptr, return 8; } + case MYSQL_TYPE_DATETIME2: + { + char buf[MAX_DATE_STRING_REP_LENGTH]; + MYSQL_TIME ltime; + longlong packed= my_datetime_packed_from_binary(ptr, meta); + TIME_from_longlong_datetime_packed(<ime, packed); + int buflen= my_datetime_to_str(<ime, buf, meta); + my_b_write_quoted(file, (uchar *) buf, buflen); + my_snprintf(typestr, typestr_length, "DATETIME(%d)", meta); + return my_datetime_binary_length(meta); + } + case MYSQL_TYPE_TIME: { - uint32 i32= uint3korr(ptr); - my_b_printf(file, "'%02d:%02d:%02d'", - i32 / 10000, (i32 % 10000) / 100, i32 % 100); + int32 tmp= sint3korr(ptr); + int32 i32= tmp >= 0 ? tmp : - tmp; + const char *sign= tmp < 0 ? "-" : ""; + my_b_printf(file, "'%s%02d:%02d:%02d'", + sign, i32 / 10000, (i32 % 10000) / 100, i32 % 100, i32); my_snprintf(typestr, typestr_length, "TIME"); return 3; } - + + case MYSQL_TYPE_TIME2: + { + char buf[MAX_DATE_STRING_REP_LENGTH]; + MYSQL_TIME ltime; + longlong packed= my_time_packed_from_binary(ptr, meta); + TIME_from_longlong_time_packed(<ime, packed); + int buflen= my_time_to_str(<ime, buf, meta); + my_b_write_quoted(file, (uchar *) buf, buflen); + my_snprintf(typestr, typestr_length, "TIME(%d)", meta); + return my_time_binary_length(meta); + } + case MYSQL_TYPE_NEWDATE: { uint32 tmp= uint3korr(ptr); @@ -7053,7 +7099,7 @@ void User_var_log_event::pack_info(THD *thd, Protocol* protocol) buf.append(" ")) return; old_len= buf.length(); - if (buf.reserve(old_len + val_len*2 + 2 + sizeof(" COLLATE ") + + if (buf.reserve(old_len + val_len * 2 + 3 + sizeof(" COLLATE ") + MY_CS_NAME_SIZE)) return; beg= const_cast(buf.ptr()) + old_len; @@ -7096,10 +7142,9 @@ User_var_log_event(const char* buf, uint event_len, /* We don't know yet is_null value, so we must assume that name_len may have the bigger value possible, is_null= True and there is no - payload for val. + payload for val, or even that name_len is 0. */ - if (0 == name_len || - !valid_buffer_range(name_len, buf_start, name, + if (!valid_buffer_range(name_len, buf_start, name, event_len - UV_VAL_IS_NULL)) { error= true; @@ -7322,7 +7367,8 @@ void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) char *hex_str; CHARSET_INFO *cs; - hex_str= (char *)my_malloc(2*val_len+1+2,MYF(MY_WME)); // 2 hex digits / byte + // 2 hex digits / byte + hex_str= (char *) my_malloc(2 * val_len + 1 + 3, MYF(MY_WME)); if (!hex_str) return; str_to_hex(hex_str, val, val_len); @@ -9868,7 +9914,7 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, { m_coltype= reinterpret_cast(m_memory); for (unsigned int i= 0 ; i < m_table->s->fields ; ++i) - m_coltype[i]= m_table->field[i]->type(); + m_coltype[i]= m_table->field[i]->binlog_type(); } /* @@ -10272,6 +10318,7 @@ int Table_map_log_event::do_apply_event(Relay_log_info const *rli) table_list->table_id= DBUG_EVALUATE_IF("inject_tblmap_same_id_maps_diff_table", 0, m_table_id); table_list->updating= 1; + table_list->required_type= FRMTYPE_TABLE; DBUG_PRINT("debug", ("table: %s is mapped to %u", table_list->table_name, table_list->table_id)); enum_tbl_map_status tblmap_status= check_table_map(rli, table_list); if (tblmap_status == OK_TO_PROCESS) diff --git a/sql/log_event.h b/sql/log_event.h index b5b488f320d..b54e2028ef2 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -1121,8 +1121,35 @@ public: const Format_description_log_event *description_event, my_bool crc_check); + + /** + Reads an event from a binlog or relay log. Used by the dump thread + this method reads the event into a raw buffer without parsing it. + + @Note If mutex is 0, the read will proceed without mutex. + + @Note If a log name is given than the method will check if the + given binlog is still active. + + @param[in] file log file to be read + @param[out] packet packet to hold the event + @param[in] lock the lock to be used upon read + @param[in] log_file_name_arg the log's file name + @param[out] is_binlog_active is the current log still active + + @retval 0 success + @retval LOG_READ_EOF end of file, nothing was read + @retval LOG_READ_BOGUS malformed event + @retval LOG_READ_IO io error while reading + @retval LOG_READ_MEM packet memory allocation failed + @retval LOG_READ_TRUNC only a partial event could be read + @retval LOG_READ_TOO_LARGE event too large + */ static int read_log_event(IO_CACHE* file, String* packet, - mysql_mutex_t* log_lock, uint8 checksum_alg_arg); + mysql_mutex_t* log_lock, + uint8 checksum_alg_arg, + const char *log_file_name_arg = NULL, + bool* is_binlog_active = NULL); /* init_show_field_list() prepares the column names and types for the output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG diff --git a/sql/mdl.cc b/sql/mdl.cc index e7321d35e77..91e1766bf6c 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -97,7 +97,7 @@ PSI_stage_info MDL_key::m_namespace_to_wait_state_name[NAMESPACE_END]= {0, "Waiting for trigger metadata lock", 0}, {0, "Waiting for event metadata lock", 0}, {0, "Waiting for commit lock", 0}, - {0, "User lock"} /* Be compatible with old status. */ + {0, "User lock", 0} /* Be compatible with old status. */ }; #ifdef HAVE_PSI_INTERFACE diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 6a1ca2e09d3..6f28760c055 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -54,6 +54,7 @@ static char *opt_os_password; static my_bool opt_default_user; static my_bool opt_allow_remote_root_access; static my_bool opt_skip_networking; +static my_bool opt_verbose_bootstrap; static my_bool verbose_errors; @@ -83,6 +84,8 @@ static struct my_option my_long_options[]= 0, 0}, {"silent", 's', "Print less information", &opt_silent, &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose-bootstrap", 'o', "Include mysqld bootstrap output",&opt_verbose_bootstrap, + &opt_verbose_bootstrap, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -244,11 +247,12 @@ static char *init_bootstrap_command_line(char *cmdline, size_t size) get_basedir(basedir, sizeof(basedir), mysqld_path); my_snprintf(cmdline, size-1, - "\"\"%s\" --no-defaults --bootstrap" - " \"--language=%s\\share\\english\"" + "\"\"%s\" --no-defaults %s --bootstrap" + " \"--lc-messages-dir=%s/share\"" " --basedir=. --datadir=. --default-storage-engine=myisam" " --max_allowed_packet=9M " - " --net-buffer-length=16k\"", mysqld_path, basedir); + " --net-buffer-length=16k\"", mysqld_path, + opt_verbose_bootstrap?"--console":"", basedir ); return cmdline; } @@ -377,7 +381,7 @@ static int register_service() static void clean_directory(const char *dir) { char dir2[MAX_PATH+2]; - *(strmake(dir2, dir, MAX_PATH+1)+1)= 0; + *(strmake_buf(dir2, dir)+1)= 0; SHFILEOPSTRUCT fileop; fileop.hwnd= NULL; /* no status display */ @@ -552,7 +556,9 @@ static int create_db_instance() /* Do mysqld --bootstrap. */ init_bootstrap_command_line(cmdline, sizeof(cmdline)); - /* verbose("Executing %s", cmdline); */ + + if(opt_verbose_bootstrap) + printf("Executing %s\n", cmdline); in= popen(cmdline, "wt"); if (!in) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1b61167cf3b..4fbda3a764e 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -14,7 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_plugin.h" #include "sql_priv.h" #include "unireg.h" #include @@ -1062,7 +1062,8 @@ static PSI_cond_info all_server_conds[]= PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, key_thread_handle_manager, key_thread_main, - key_thread_one_connection, key_thread_signal_hand; + key_thread_one_connection, key_thread_signal_hand, + key_thread_slave_init; static PSI_thread_info all_server_threads[]= { @@ -1087,7 +1088,8 @@ static PSI_thread_info all_server_threads[]= { &key_thread_handle_manager, "manager", PSI_FLAG_GLOBAL}, { &key_thread_main, "main", PSI_FLAG_GLOBAL}, { &key_thread_one_connection, "one_connection", 0}, - { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL} + { &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL}, + { &key_thread_slave_init, "slave_init", PSI_FLAG_GLOBAL} }; #ifdef HAVE_MMAP @@ -3551,14 +3553,25 @@ sizeof(load_default_groups)/sizeof(load_default_groups[0]); #ifndef EMBEDDED_LIBRARY -static -int -check_enough_stack_size() +/** + This function is used to check for stack overrun for pathological + cases of regular expressions and 'like' expressions. + The call to current_thd is quite expensive, so we try to avoid it + for the normal cases. + The size of each stack frame for the wildcmp() routines is ~128 bytes, + so checking *every* recursive call is not necessary. + */ +extern "C" int +check_enough_stack_size(int recurse_level) { uchar stack_top; + if (recurse_level % 16 != 0) + return 0; - return check_stack_overrun(current_thd, STACK_MIN_SIZE, - &stack_top); + THD *my_thd= current_thd; + if (my_thd != NULL) + return check_stack_overrun(my_thd, STACK_MIN_SIZE * 2, &stack_top); + return 0; } #endif @@ -3916,7 +3929,7 @@ static int init_common_variables() WideCharToMultiByte(CP_UTF8,0, wtz_name, -1, system_time_zone, sizeof(system_time_zone) - 1, NULL, NULL); #else - strmake(system_time_zone, tz_name, sizeof(system_time_zone)-1); + strmake_buf(system_time_zone, tz_name); #endif /* _WIN32 */ #endif /* HAVE_TZNAME */ @@ -4192,6 +4205,7 @@ static int init_common_variables() item_init(); #ifndef EMBEDDED_LIBRARY my_regex_init(&my_charset_latin1, check_enough_stack_size); + my_string_stack_guard= check_enough_stack_size; #else my_regex_init(&my_charset_latin1, NULL); #endif @@ -4739,6 +4753,7 @@ will be ignored as the --log-bin option is not defined."); { WSREP_ERROR("Could not append %s/bin to PATH", mysql_home); } + DBUG_ASSERT(!opt_bin_log || opt_bin_logname); if (wsrep_before_SE()) { @@ -4753,7 +4768,7 @@ will be ignored as the --log-bin option is not defined."); { /* Reports an error and aborts, if the --log-bin's path is a directory.*/ - if (opt_bin_logname && + if (opt_bin_logname[0] && opt_bin_logname[strlen(opt_bin_logname) - 1] == FN_LIBCHAR) { sql_print_error("Path '%s' is a directory name, please specify \ @@ -4775,7 +4790,7 @@ a file name for --log-bin-index option", opt_binlog_index_name); char buf[FN_REFLEN]; const char *ln; ln= mysql_bin_log.generate_name(opt_bin_logname, "-bin", 1, buf); - if (!opt_bin_logname && !opt_binlog_index_name) + if (!opt_bin_logname[0] && !opt_binlog_index_name) { /* User didn't give us info to name the binlog index file. @@ -8108,8 +8123,8 @@ static int mysql_init_variables(void) /* Set directory paths */ mysql_real_data_home_len= - strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR), - sizeof(mysql_real_data_home)-1) - mysql_real_data_home; + strmake_buf(mysql_real_data_home, + get_relative_path(MYSQL_DATADIR)) - mysql_real_data_home; /* Replication parameters */ master_info_file= (char*) "master.info", relay_log_info_file= (char*) "relay-log.info"; @@ -8218,7 +8233,7 @@ static int mysql_init_variables(void) const char *tmpenv; if (!(tmpenv = getenv("MY_BASEDIR_VERSION"))) tmpenv = DEFAULT_MYSQL_HOME; - (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1); + strmake_buf(mysql_home, tmpenv); #endif #ifdef WITH_WSREP if (WSREP_ON && wsrep_init_vars()) @@ -8261,7 +8276,7 @@ mysqld_get_one_option(int optid, global_system_variables.tx_isolation= ISO_SERIALIZABLE; break; case 'b': - strmake(mysql_home,argument,sizeof(mysql_home)-1); + strmake_buf(mysql_home, argument); break; case 'C': if (default_collation_name == compiled_default_collation_name) @@ -8272,7 +8287,7 @@ mysqld_get_one_option(int optid, opt_log=1; break; case 'h': - strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1); + strmake_buf(mysql_real_data_home, argument); /* Correct pointer set by my_getopt (for embedded library) */ mysql_real_data_home_ptr= mysql_real_data_home; break; @@ -8283,7 +8298,7 @@ mysqld_get_one_option(int optid, sql_print_warning("Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user); break; case 'L': - strmake(lc_messages_dir, argument, sizeof(lc_messages_dir)-1); + strmake_buf(lc_messages_dir, argument); break; case OPT_BINLOG_FORMAT: binlog_format_used= true; @@ -9103,7 +9118,7 @@ static int fix_paths(void) char *sharedir=get_relative_path(SHAREDIR); if (test_if_hard_path(sharedir)) - strmake(buff,sharedir,sizeof(buff)-1); /* purecov: tested */ + strmake_buf(buff, sharedir); /* purecov: tested */ else strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS); convert_dirname(buff,buff,NullS); @@ -9111,7 +9126,7 @@ static int fix_paths(void) /* If --character-sets-dir isn't given, use shared library dir */ if (charsets_dir) - strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir)-1); + strmake_buf(mysql_charsets_dir, charsets_dir); else strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff, CHARSET_DIR, NullS); diff --git a/sql/mysqld.h b/sql/mysqld.h index 55a631c3ccf..c1b481c94bd 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -293,7 +293,7 @@ extern PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy; extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert, key_thread_handle_manager, key_thread_kill_server, key_thread_main, - key_thread_one_connection, key_thread_signal_hand; + key_thread_one_connection, key_thread_signal_hand, key_thread_slave_init; extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest, key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file, diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 37a7944bbaf..e8213ea8dd6 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7689,6 +7689,14 @@ static SEL_TREE *get_full_func_mm_tree(RANGE_OPT_PARAM *param, param->current_table); DBUG_ENTER("get_full_func_mm_tree"); +#ifdef HAVE_SPATIAL + if (field_item->field->type() == MYSQL_TYPE_GEOMETRY) + { + /* We have to be able to store all sorts of spatial features here */ + ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY; + } +#endif /*HAVE_SPATIAL*/ + for (uint i= 0; i < cond_func->arg_count; i++) { Item *arg= cond_func->arguments()[i]->real_item(); @@ -8006,10 +8014,10 @@ get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field, */ if (field->result_type() == STRING_RESULT && - ((Field_str*) field)->match_collation_to_optimize_range() && + field->match_collation_to_optimize_range() && value->result_type() == STRING_RESULT && key_part->image_type == Field::itRAW && - ((Field_str*)field)->charset() != conf_func->compare_collation() && + field->charset() != conf_func->compare_collation() && !(conf_func->compare_collation()->state & MY_CS_BINSORT && (type == Item_func::EQUAL_FUNC || type == Item_func::EQ_FUNC))) goto end; @@ -11248,9 +11256,13 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() do { + DBUG_EXECUTE_IF("innodb_quick_report_deadlock", + DBUG_SET("+d,innodb_report_deadlock");); if ((error= quick->get_next())) { - quick_with_last_rowid->file->unlock_row(); + /* On certain errors like deadlock, trx might be rolled back.*/ + if (!current_thd->transaction_rollback_request) + quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } quick->file->position(quick->record); @@ -11276,7 +11288,9 @@ int QUICK_ROR_INTERSECT_SELECT::get_next() quick->file->unlock_row(); /* row not in range; unlock */ if ((error= quick->get_next())) { - quick_with_last_rowid->file->unlock_row(); + /* On certain errors like deadlock, trx might be rolled back.*/ + if (!current_thd->transaction_rollback_request) + quick_with_last_rowid->file->unlock_row(); DBUG_RETURN(error); } } @@ -12161,13 +12175,15 @@ cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts, NGA1.If in the index I there is a gap between the last GROUP attribute G_k, and the MIN/MAX attribute C, then NGA must consist of exactly the index attributes that constitute the gap. As a result there is a - permutation of NGA that coincides with the gap in the index - . + permutation of NGA, BA=, that coincides with the gap + in the index. NGA2.If BA <> {}, then the WHERE clause must contain a conjunction EQ of equality conditions for all NG_i of the form (NG_i = const) or (const = NG_i), such that each NG_i is referenced in exactly one conjunct. Informally, the predicates provide constants to fill the gap in the index. + NGA3.If BA <> {}, there can only be one range. TODO: This is a code + limitation and is not strictly needed. See BUG#15947433 WA1. There are no other attributes in the WHERE clause except the ones referenced in predicates RNG, PA, PC, EQ defined above. Therefore WA is subset of (GA union NGA union C) for GA,NGA,C that pass the @@ -12869,7 +12885,7 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, */ ((args[1]->result_type() == STRING_RESULT && image_type == Field::itRAW && - ((Field_str*) min_max_arg_item->field)->charset() != + min_max_arg_item->field->charset() != pred->compare_collation()) || /* @@ -12909,6 +12925,74 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, } +/* + Get SEL_ARG tree, if any, for the keypart covering non grouping + attribute (NGA) field 'nga_field'. + + This function enforces the NGA3 test: If 'keypart_tree' contains a + condition for 'nga_field', there can only be one range. In the + opposite case, this function returns with error and 'cur_range' + should not be used. + + Note that the NGA1 and NGA2 requirements, like whether or not the + range predicate for 'nga_field' is equality, is not tested by this + function. + + @param[in] nga_field The NGA field we want the SEL_ARG tree for + @param[in] keypart_tree Root node of the SEL_ARG* tree for the index + @param[out] cur_range The SEL_ARG tree, if any, for the keypart + covering field 'keypart_field' + @retval true 'keypart_tree' contained a predicate for 'nga_field' but + multiple ranges exists. 'cur_range' should not be used. + @retval false otherwise +*/ + +static bool +get_sel_arg_for_keypart(Field *nga_field, + SEL_ARG *keypart_tree, + SEL_ARG **cur_range) +{ + if(keypart_tree == NULL) + return false; + if(keypart_tree->field->eq(nga_field)) + { + /* + Enforce NGA3: If a condition for nga_field has been found, only + a single range is allowed. + */ + if (keypart_tree->prev || keypart_tree->next) + return true; // There are multiple ranges + + *cur_range= keypart_tree; + return false; + } + + SEL_ARG *found_tree= NULL; + SEL_ARG *first_kp= keypart_tree->first(); + + for (SEL_ARG *cur_kp= first_kp; cur_kp && !found_tree; + cur_kp= cur_kp->next) + { + if (cur_kp->next_key_part) + { + if (get_sel_arg_for_keypart(nga_field, + cur_kp->next_key_part, + &found_tree)) + return true; + + } + /* + Enforce NGA3: If a condition for nga_field has been found,only + a single range is allowed. + */ + if (found_tree && first_kp->next) + return true; // There are multiple ranges + } + *cur_range= found_tree; + return false; +} + + /* Extract a sequence of constants from a conjunction of equality predicates. @@ -12923,12 +13007,13 @@ check_group_min_max_predicates(Item *cond, Item_field *min_max_arg_item, key_infix [out] Infix of constants to be used for index lookup key_infix_len [out] Lenghth of the infix first_non_infix_part [out] The first keypart after the infix (if any) - + DESCRIPTION - Test conditions (NGA1, NGA2) from get_best_group_min_max(). Namely, - for each keypart field NGF_i not in GROUP-BY, check that there is a - constant equality predicate among conds with the form (NGF_i = const_ci) or - (const_ci = NGF_i). + Test conditions (NGA1, NGA2, NGA3) from get_best_group_min_max(). Namely, + for each keypart field NG_i not in GROUP-BY, check that there is exactly one + constant equality predicate among conds with the form (NG_i = const_ci) or + (const_ci = NG_i).. In addition, there can only be one range when there is + such a gap. Thus all the NGF_i attributes must fill the 'gap' between the last group-by attribute and the MIN/MAX attribute in the index (if present). If these conditions hold, copy each constant from its corresponding predicate into @@ -12957,17 +13042,14 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree, uchar *key_ptr= key_infix; for (cur_part= first_non_group_part; cur_part != end_part; cur_part++) { + cur_range= NULL; /* Find the range tree for the current keypart. We assume that - index_range_tree points to the leftmost keypart in the index. + index_range_tree points to the first keypart in the index. */ - for (cur_range= index_range_tree; - cur_range && cur_range->type == SEL_ARG::KEY_RANGE; - cur_range= cur_range->next_key_part) - { - if (cur_range->field->eq(cur_part->field)) - break; - } + if(get_sel_arg_for_keypart(cur_part->field, index_range_tree, &cur_range)) + return false; + if (!cur_range || cur_range->type != SEL_ARG::KEY_RANGE) { if (min_max_arg_part) @@ -12979,9 +13061,6 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree, } } - /* Check that the current range tree is a single point interval. */ - if (cur_range->prev || cur_range->next) - return FALSE; /* This is not the only range predicate for the field. */ if ((cur_range->min_flag & NO_MIN_RANGE) || (cur_range->max_flag & NO_MAX_RANGE) || (cur_range->min_flag & NEAR_MIN) || (cur_range->max_flag & NEAR_MAX)) diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 33164c1ed12..1542efa7415 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1482,7 +1482,7 @@ void check_equality(Dep_analysis_context *ctx, Dep_module_expr **eq_mod, collation of the operation differ from the field collation. */ if (field->cmp_type() == STRING_RESULT && - ((Field_str*)field)->charset() != cond->compare_collation()) + field->charset() != cond->compare_collation()) return; } } diff --git a/sql/partition_element.h b/sql/partition_element.h index 87f3d00e68c..4f03d91035a 100644 --- a/sql/partition_element.h +++ b/sql/partition_element.h @@ -1,7 +1,7 @@ #ifndef PARTITION_ELEMENT_INCLUDED #define PARTITION_ELEMENT_INCLUDED -/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -107,9 +107,8 @@ public: enum partition_state part_state; uint16 nodegroup_id; bool has_null_value; - /* signed_flag and max_value only relevant for subpartitions */ - bool signed_flag; - bool max_value; + bool signed_flag; // Range value signed + bool max_value; // MAXVALUE range partition_element() : part_max_rows(0), part_min_rows(0), range_value(0), diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 934f4e970cb..34e47331664 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1,5 +1,4 @@ -/* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. 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 @@ -2173,9 +2172,36 @@ int partition_info::fix_parser_data(THD *thd) if (!(part_type == RANGE_PARTITION || part_type == LIST_PARTITION)) { - /* Nothing to do for HASH/KEY partitioning */ + if (part_type == HASH_PARTITION && list_of_part_fields) + { + /* KEY partitioning, check ALGORITHM = N. Should not pass the parser! */ + if (key_algorithm > KEY_ALGORITHM_55) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + DBUG_RETURN(true); + } + /* If not set, use DEFAULT = 2 for CREATE and ALTER! */ + if ((thd_sql_command(thd) == SQLCOM_CREATE_TABLE || + thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && + key_algorithm == KEY_ALGORITHM_NONE) + key_algorithm= KEY_ALGORITHM_55; + } DBUG_RETURN(FALSE); } + if (is_sub_partitioned() && list_of_subpart_fields) + { + /* KEY subpartitioning, check ALGORITHM = N. Should not pass the parser! */ + if (key_algorithm > KEY_ALGORITHM_55) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + DBUG_RETURN(true); + } + /* If not set, use DEFAULT = 2 for CREATE and ALTER! */ + if ((thd_sql_command(thd) == SQLCOM_CREATE_TABLE || + thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && + key_algorithm == KEY_ALGORITHM_NONE) + key_algorithm= KEY_ALGORITHM_55; + } do { part_elem= it++; @@ -2224,6 +2250,263 @@ int partition_info::fix_parser_data(THD *thd) DBUG_RETURN(FALSE); } + +/** + helper function to compare strings that can also be + a NULL pointer. + + @param a char pointer (can be NULL). + @param b char pointer (can be NULL). + + @return false if equal + @retval true strings differs + @retval false strings is equal +*/ + +static bool strcmp_null(const char *a, const char *b) +{ + if (!a && !b) + return false; + if (a && b && !strcmp(a, b)) + return false; + return true; +} + + +/** + Check if the new part_info has the same partitioning. + + @param new_part_info New partition definition to compare with. + + @return True if not considered to have changed the partitioning. + @retval true Allowed change (only .frm change, compatible distribution). + @retval false Different partitioning, will need redistribution of rows. + + @note Currently only used to allow changing from non-set key_algorithm + to a specified key_algorithm, to avoid rebuild when upgrading from 5.1 of + such partitioned tables using numeric colums in the partitioning expression. + For more info see bug#14521864. + Does not check if columns etc has changed, i.e. only for + alter_info->flags == ALTER_PARTITION. +*/ + +bool partition_info::has_same_partitioning(partition_info *new_part_info) +{ + DBUG_ENTER("partition_info::has_same_partitioning"); + + DBUG_ASSERT(part_field_array && part_field_array[0]); + + /* + Only consider pre 5.5.3 .frm's to have same partitioning as + a new one with KEY ALGORITHM = 1 (). + */ + + if (part_field_array[0]->table->s->mysql_version >= 50503) + DBUG_RETURN(false); + + if (!new_part_info || + part_type != new_part_info->part_type || + num_parts != new_part_info->num_parts || + use_default_partitions != new_part_info->use_default_partitions || + new_part_info->is_sub_partitioned() != is_sub_partitioned()) + DBUG_RETURN(false); + + if (part_type != HASH_PARTITION) + { + /* + RANGE or LIST partitioning, check if KEY subpartitioned. + Also COLUMNS partitioning was added in 5.5, so treat that as different. + */ + if (!is_sub_partitioned() || + !new_part_info->is_sub_partitioned() || + column_list || + new_part_info->column_list || + !list_of_subpart_fields || + !new_part_info->list_of_subpart_fields || + new_part_info->num_subparts != num_subparts || + new_part_info->subpart_field_list.elements != + subpart_field_list.elements || + new_part_info->use_default_subpartitions != + use_default_subpartitions) + DBUG_RETURN(false); + } + else + { + /* Check if KEY partitioned. */ + if (!new_part_info->list_of_part_fields || + !list_of_part_fields || + new_part_info->part_field_list.elements != part_field_list.elements) + DBUG_RETURN(false); + } + + /* Check that it will use the same fields in KEY (fields) list. */ + List_iterator old_field_name_it(part_field_list); + List_iterator new_field_name_it(new_part_info->part_field_list); + char *old_name, *new_name; + while ((old_name= old_field_name_it++)) + { + new_name= new_field_name_it++; + if (!new_name || my_strcasecmp(system_charset_info, + new_name, + old_name)) + DBUG_RETURN(false); + } + + if (is_sub_partitioned()) + { + /* Check that it will use the same fields in KEY subpart fields list. */ + List_iterator old_field_name_it(subpart_field_list); + List_iterator new_field_name_it(new_part_info->subpart_field_list); + char *old_name, *new_name; + while ((old_name= old_field_name_it++)) + { + new_name= new_field_name_it++; + if (!new_name || my_strcasecmp(system_charset_info, + new_name, + old_name)) + DBUG_RETURN(false); + } + } + + if (!use_default_partitions) + { + /* + Loop over partitions/subpartition to verify that they are + the same, including state and name. + */ + List_iterator part_it(partitions); + List_iterator new_part_it(new_part_info->partitions); + uint i= 0; + do + { + partition_element *part_elem= part_it++; + partition_element *new_part_elem= new_part_it++; + /* + The following must match: + partition_name, tablespace_name, data_file_name, index_file_name, + engine_type, part_max_rows, part_min_rows, nodegroup_id. + (max_value, signed_flag, has_null_value only on partition level, + RANGE/LIST) + The following can differ: + - part_comment + part_state must be PART_NORMAL! + */ + if (!part_elem || !new_part_elem || + strcmp(part_elem->partition_name, + new_part_elem->partition_name) || + part_elem->part_state != PART_NORMAL || + new_part_elem->part_state != PART_NORMAL || + part_elem->max_value != new_part_elem->max_value || + part_elem->signed_flag != new_part_elem->signed_flag || + part_elem->has_null_value != new_part_elem->has_null_value) + DBUG_RETURN(false); + + /* new_part_elem may not have engine_type set! */ + if (new_part_elem->engine_type && + part_elem->engine_type != new_part_elem->engine_type) + DBUG_RETURN(false); + + if (is_sub_partitioned()) + { + /* + Check that both old and new partition has the same definition + (VALUES IN/VALUES LESS THAN) (No COLUMNS partitioning, see above) + */ + if (part_type == LIST_PARTITION) + { + List_iterator list_vals(part_elem->list_val_list); + List_iterator + new_list_vals(new_part_elem->list_val_list); + part_elem_value *val; + part_elem_value *new_val; + while ((val= list_vals++)) + { + new_val= new_list_vals++; + if (!new_val) + DBUG_RETURN(false); + if ((!val->null_value && !new_val->null_value) && + val->value != new_val->value) + DBUG_RETURN(false); + } + if (new_list_vals++) + DBUG_RETURN(false); + } + else + { + DBUG_ASSERT(part_type == RANGE_PARTITION); + if (new_part_elem->range_value != part_elem->range_value) + DBUG_RETURN(false); + } + + if (!use_default_subpartitions) + { + List_iterator + sub_part_it(part_elem->subpartitions); + List_iterator + new_sub_part_it(new_part_elem->subpartitions); + uint j= 0; + do + { + partition_element *sub_part_elem= sub_part_it++; + partition_element *new_sub_part_elem= new_sub_part_it++; + /* new_part_elem may not have engine_type set! */ + if (new_sub_part_elem->engine_type && + sub_part_elem->engine_type != new_part_elem->engine_type) + DBUG_RETURN(false); + + if (strcmp(sub_part_elem->partition_name, + new_sub_part_elem->partition_name) || + sub_part_elem->part_state != PART_NORMAL || + new_sub_part_elem->part_state != PART_NORMAL || + sub_part_elem->part_min_rows != + new_sub_part_elem->part_min_rows || + sub_part_elem->part_max_rows != + new_sub_part_elem->part_max_rows || + sub_part_elem->nodegroup_id != + new_sub_part_elem->nodegroup_id) + DBUG_RETURN(false); + + if (strcmp_null(sub_part_elem->data_file_name, + new_sub_part_elem->data_file_name) || + strcmp_null(sub_part_elem->index_file_name, + new_sub_part_elem->index_file_name) || + strcmp_null(sub_part_elem->tablespace_name, + new_sub_part_elem->tablespace_name)) + DBUG_RETURN(false); + + } while (++j < num_subparts); + } + } + else + { + if (part_elem->part_min_rows != new_part_elem->part_min_rows || + part_elem->part_max_rows != new_part_elem->part_max_rows || + part_elem->nodegroup_id != new_part_elem->nodegroup_id) + DBUG_RETURN(false); + + if (strcmp_null(part_elem->data_file_name, + new_part_elem->data_file_name) || + strcmp_null(part_elem->index_file_name, + new_part_elem->index_file_name) || + strcmp_null(part_elem->tablespace_name, + new_part_elem->tablespace_name)) + DBUG_RETURN(false); + } + } while (++i < num_parts); + } + + /* + Only if key_algorithm was not specified before and it is now set, + consider this as nothing was changed, and allow change without rebuild! + */ + if (key_algorithm != partition_info::KEY_ALGORITHM_NONE || + new_part_info->key_algorithm == partition_info::KEY_ALGORITHM_NONE) + DBUG_RETURN(false); + + DBUG_RETURN(true); +} + + void partition_info::print_debug(const char *str, uint *value) { DBUG_ENTER("print_debug"); diff --git a/sql/partition_info.h b/sql/partition_info.h index 2fbdfff6636..17c9cb383ee 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -1,7 +1,7 @@ #ifndef PARTITION_INFO_INCLUDED #define PARTITION_INFO_INCLUDED -/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -192,6 +192,19 @@ public: but mainly of use to handlers supporting partitioning. */ uint16 linear_hash_mask; + /* + PARTITION BY KEY ALGORITHM=N + Which algorithm to use for hashing the fields. + N = 1 - Use 5.1 hashing (numeric fields are hashed as binary) + N = 2 - Use 5.5 hashing (numeric fields are hashed like latin1 bytes) + */ + enum enum_key_algorithm + { + KEY_ALGORITHM_NONE= 0, + KEY_ALGORITHM_51= 1, + KEY_ALGORITHM_55= 2 + }; + enum_key_algorithm key_algorithm; bool use_default_partitions; bool use_default_num_partitions; @@ -232,6 +245,7 @@ public: count_curr_subparts(0), part_error_code(0), num_list_values(0), num_part_fields(0), num_subpart_fields(0), num_full_part_fields(0), has_null_part_id(0), linear_hash_mask(0), + key_algorithm(KEY_ALGORITHM_NONE), use_default_partitions(TRUE), use_default_num_partitions(TRUE), use_default_subpartitions(TRUE), use_default_num_subpartitions(TRUE), default_partitions_setup(FALSE), defined_max_value(FALSE), @@ -298,6 +312,7 @@ public: bool add_column_list_value(THD *thd, Item *item); void set_show_version_string(String *packet); void report_part_expr_error(bool use_subpart_expr); + bool has_same_partitioning(partition_info *new_part_info); private: static int list_part_cmp(const void* a, const void* b); bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info, diff --git a/sql/protocol.cc b/sql/protocol.cc index a86da94af61..d46365df0ad 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1435,7 +1435,7 @@ bool Protocol_binary::store(MYSQL_TIME *tm, int decimals) DBUG_ASSERT(decimals == AUTO_SEC_PART_DIGITS || (decimals >= 0 && decimals <= TIME_SECOND_PART_DIGITS)); if (decimals != AUTO_SEC_PART_DIGITS) - tm->second_part= sec_part_truncate(tm->second_part, decimals); + my_time_trunc(tm, decimals); int4store(pos+7, tm->second_part); if (tm->second_part) length=11; @@ -1477,7 +1477,7 @@ bool Protocol_binary::store_time(MYSQL_TIME *tm, int decimals) DBUG_ASSERT(decimals == AUTO_SEC_PART_DIGITS || (decimals >= 0 && decimals <= TIME_SECOND_PART_DIGITS)); if (decimals != AUTO_SEC_PART_DIGITS) - tm->second_part= sec_part_truncate(tm->second_part, decimals); + my_time_trunc(tm, decimals); int4store(pos+8, tm->second_part); if (tm->second_part) length=12; diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index b34b890060b..d5e9380296e 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -179,6 +179,22 @@ rpl_slave_state::get_element(uint32 domain_id) } +int +rpl_slave_state::put_back_list(uint32 domain_id, list_element *list) +{ + element *e; + if (!(e= (element *)my_hash_search(&hash, (const uchar *)&domain_id, 0))) + return 1; + while (list) + { + list_element *next= list->next; + e->add(list); + list= next; + } + return 0; +} + + int rpl_slave_state::truncate_state_table(THD *thd) { @@ -330,7 +346,10 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, table->field[3]->store(gtid->seq_no, true); DBUG_EXECUTE_IF("inject_crash_before_write_rpl_slave_state", DBUG_SUICIDE();); if ((err= table->file->ha_write_row(table->record[0]))) - goto end; + { + table->file->print_error(err, MYF(0)); + goto end; + } lock(); if ((elem= get_element(gtid->domain_id)) == NULL) @@ -351,23 +370,42 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, bitmap_set_bit(table->read_set, table->field[1]->field_index); if ((err= table->file->ha_index_init(0, 0))) + { + table->file->print_error(err, MYF(0)); goto end; + } while (elist) { uchar key_buffer[4+8]; + DBUG_EXECUTE_IF("gtid_slave_pos_simulate_failed_delete", + { err= ENOENT; + table->file->print_error(err, MYF(0)); + /* `break' does not work in DBUG_EXECUTE_IF */ + goto dbug_break; }); + next= elist->next; table->field[1]->store(elist->sub_id, true); /* domain_id is already set in table->record[0] from write_row() above. */ key_copy(key_buffer, table->record[0], &table->key_info[0], 0, false); - if ((err= table->file->ha_index_read_map(table->record[1], key_buffer, - HA_WHOLE_KEY, HA_READ_KEY_EXACT)) || - (err= table->file->ha_delete_row(table->record[1]))) - break; + if (table->file->ha_index_read_map(table->record[1], key_buffer, + HA_WHOLE_KEY, HA_READ_KEY_EXACT)) + /* We cannot find the row, assume it is already deleted. */ + ; + else if ((err= table->file->ha_delete_row(table->record[1]))) + table->file->print_error(err, MYF(0)); + /* + In case of error, we still discard the element from the list. We do + not want to endlessly error on the same element in case of table + corruption or such. + */ my_free(elist); elist= next; + if (err) + break; } +IF_DBUG(dbug_break:, ) table->file->ha_index_end(); if(!err && opt_bin_log && @@ -382,9 +420,16 @@ end: if (err) { /* - ToDo: If error, we need to put any remaining elist back into the HASH so - we can do another delete attempt later. + If error, we need to put any remaining elist back into the HASH so we + can do another delete attempt later. */ + if (elist) + { + lock(); + put_back_list(gtid->domain_id, elist); + unlock(); + } + ha_rollback_trans(thd, FALSE); close_thread_tables(thd); } @@ -437,26 +482,10 @@ rpl_slave_state_tostring_helper(String *dest, const rpl_gtid *gtid, bool *first) } -/* - Prepare the current slave state as a string, suitable for sending to the - master to request to receive binlog events starting from that GTID state. - - The state consists of the most recently applied GTID for each domain_id, - ie. the one with the highest sub_id within each domain_id. - - Optinally, extra_gtids is a list of GTIDs from the binlog. This is used when - a server was previously a master and now needs to connect to a new master as - a slave. For each domain_id, if the GTID in the binlog was logged with our - own server_id _and_ has a higher seq_no than what is in the slave state, - then this should be used as the position to start replicating at. This - allows to promote a slave as new master, and connect the old master as a - slave with MASTER_GTID_POS=AUTO. -*/ - int -rpl_slave_state::tostring(String *dest, rpl_gtid *extra_gtids, uint32 num_extra) +rpl_slave_state::iterate(int (*cb)(rpl_gtid *, void *), void *data, + rpl_gtid *extra_gtids, uint32 num_extra) { - bool first= true; uint32 i; HASH gtid_hash; uchar *rec; @@ -510,7 +539,7 @@ rpl_slave_state::tostring(String *dest, rpl_gtid *extra_gtids, uint32 num_extra) } } - if (rpl_slave_state_tostring_helper(dest, &best_gtid, &first)) + if ((res= (*cb)(&best_gtid, data))) { unlock(); goto err; @@ -523,7 +552,7 @@ rpl_slave_state::tostring(String *dest, rpl_gtid *extra_gtids, uint32 num_extra) for (i= 0; i < gtid_hash.records; ++i) { gtid= (rpl_gtid *)my_hash_element(>id_hash, i); - if (rpl_slave_state_tostring_helper(dest, gtid, &first)) + if ((res= (*cb)(gtid, data))) goto err; } @@ -536,6 +565,44 @@ err: } +struct rpl_slave_state_tostring_data { + String *dest; + bool first; +}; +static int +rpl_slave_state_tostring_cb(rpl_gtid *gtid, void *data) +{ + rpl_slave_state_tostring_data *p= (rpl_slave_state_tostring_data *)data; + return rpl_slave_state_tostring_helper(p->dest, gtid, &p->first); +} + + +/* + Prepare the current slave state as a string, suitable for sending to the + master to request to receive binlog events starting from that GTID state. + + The state consists of the most recently applied GTID for each domain_id, + ie. the one with the highest sub_id within each domain_id. + + Optinally, extra_gtids is a list of GTIDs from the binlog. This is used when + a server was previously a master and now needs to connect to a new master as + a slave. For each domain_id, if the GTID in the binlog was logged with our + own server_id _and_ has a higher seq_no than what is in the slave state, + then this should be used as the position to start replicating at. This + allows to promote a slave as new master, and connect the old master as a + slave with MASTER_GTID_POS=AUTO. +*/ +int +rpl_slave_state::tostring(String *dest, rpl_gtid *extra_gtids, uint32 num_extra) +{ + struct rpl_slave_state_tostring_data data; + data.first= true; + data.dest= dest; + + return iterate(rpl_slave_state_tostring_cb, &data, extra_gtids, num_extra); +} + + /* Lookup a domain_id in the current replication slave state. @@ -581,9 +648,6 @@ rpl_slave_state::domain_to_gtid(uint32 domain_id, rpl_gtid *out_gtid) Parse a GTID at the start of a string, and update the pointer to point at the first character after the parsed GTID. - GTID can be in short form with domain_id=0 implied, SERVERID-SEQNO. - Or long form, DOMAINID-SERVERID-SEQNO. - Returns 0 on ok, non-zero on parse error. */ static int @@ -1172,7 +1236,7 @@ slave_connection_state::load(char *slave_request, size_t len) rpl_gtid *gtid; const rpl_gtid *gtid2; - my_hash_reset(&hash); + reset(); p= slave_request; end= slave_request + len; if (p == end) @@ -1225,7 +1289,7 @@ slave_connection_state::load(const rpl_gtid *gtid_list, uint32 count) { uint32 i; - my_hash_reset(&hash); + reset(); for (i= 0; i < count; ++i) if (update(>id_list[i])) return 1; @@ -1233,6 +1297,28 @@ slave_connection_state::load(const rpl_gtid *gtid_list, uint32 count) } +static int +slave_connection_state_load_cb(rpl_gtid *gtid, void *data) +{ + slave_connection_state *state= (slave_connection_state *)data; + return state->update(gtid); +} + + +/* + Same as rpl_slave_state::tostring(), but populates a slave_connection_state + instead. +*/ +int +slave_connection_state::load(rpl_slave_state *state, + rpl_gtid *extra_gtids, uint32 num_extra) +{ + reset(); + return state->iterate(slave_connection_state_load_cb, this, + extra_gtids, num_extra); +} + + rpl_gtid * slave_connection_state::find(uint32 domain_id) { diff --git a/sql/rpl_gtid.h b/sql/rpl_gtid.h index fefce684c2c..4d5302020bf 100644 --- a/sql/rpl_gtid.h +++ b/sql/rpl_gtid.h @@ -93,6 +93,8 @@ struct rpl_slave_state int record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, bool in_transaction, bool in_statement); uint64 next_subid(uint32 domain_id); + int iterate(int (*cb)(rpl_gtid *, void *), void *data, + rpl_gtid *extra_gtids, uint32 num_extra); int tostring(String *dest, rpl_gtid *extra_gtids, uint32 num_extra); bool domain_to_gtid(uint32 domain_id, rpl_gtid *out_gtid); int load(THD *thd, char *state_from_master, size_t len, bool reset, @@ -103,6 +105,7 @@ struct rpl_slave_state void unlock() { DBUG_ASSERT(inited); mysql_mutex_unlock(&LOCK_slave_state); } element *get_element(uint32 domain_id); + int put_back_list(uint32 domain_id, list_element *list); void update_state_hash(uint64 sub_id, rpl_gtid *gtid); int record_and_update_gtid(THD *thd, Relay_log_info *rli); @@ -177,8 +180,10 @@ struct slave_connection_state slave_connection_state(); ~slave_connection_state(); + void reset() { my_hash_reset(&hash); } int load(char *slave_request, size_t len); int load(const rpl_gtid *gtid_list, uint32 count); + int load(rpl_slave_state *state, rpl_gtid *extra_gtids, uint32 num_extra); rpl_gtid *find(uint32 domain_id); int update(const rpl_gtid *in_gtid); void remove(const rpl_gtid *gtid); diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index a68fd055d74..12bdf722bec 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -38,7 +38,8 @@ Master_info::Master_info(LEX_STRING *connection_name_arg, connect_retry(DEFAULT_CONNECT_RETRY), inited(0), abort_slave(0), slave_running(0), slave_run_id(0), sync_counter(0), heartbeat_period(0), received_heartbeats(0), master_id(0), - using_gtid(USE_GTID_NO) + using_gtid(USE_GTID_NO), events_queued_since_last_gtid(0), + gtid_reconnect_event_skip_count(0), gtid_event_seen(false) { host[0] = 0; user[0] = 0; password[0] = 0; ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0; @@ -148,6 +149,23 @@ void Master_info::clear_in_memory_info(bool all) } } + +const char * +Master_info::using_gtid_astext(enum enum_using_gtid arg) +{ + switch (arg) + { + case USE_GTID_NO: + return "No"; + case USE_GTID_SLAVE_POS: + return "Slave_Pos"; + default: + DBUG_ASSERT(arg == USE_GTID_CURRENT_POS); + return "Current_Pos"; + } +} + + void init_master_log_pos(Master_info* mi) { DBUG_ENTER("init_master_log_pos"); @@ -155,6 +173,10 @@ void init_master_log_pos(Master_info* mi) mi->master_log_name[0] = 0; mi->master_log_pos = BIN_LOG_HEADER_SIZE; // skip magic number mi->using_gtid= Master_info::USE_GTID_NO; + mi->gtid_current_pos.reset(); + mi->events_queued_since_last_gtid= 0; + mi->gtid_reconnect_event_skip_count= 0; + mi->gtid_event_seen= false; /* Intentionally init ssl_verify_server_cert to 0, no option available */ mi->ssl_verify_server_cert= 0; diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h index 7e3709993ed..ad6c57e21c4 100644 --- a/sql/rpl_mi.h +++ b/sql/rpl_mi.h @@ -61,6 +61,10 @@ typedef struct st_mysql MYSQL; class Master_info : public Slave_reporting_capability { public: + enum enum_using_gtid { + USE_GTID_NO= 0, USE_GTID_CURRENT_POS= 1, USE_GTID_SLAVE_POS= 2 + }; + Master_info(LEX_STRING *connection_name, bool is_slave_recovery); ~Master_info(); bool shall_ignore_server_id(ulong s_id); @@ -70,11 +74,12 @@ class Master_info : public Slave_reporting_capability /* If malloc() in initialization failed */ return connection_name.str == 0; } + static const char *using_gtid_astext(enum enum_using_gtid arg); /* the variables below are needed because we can change masters on the fly */ char master_log_name[FN_REFLEN+6]; /* Room for multi-*/ char host[HOSTNAME_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1]; - char user[USERNAME_LENGTH*+1]; + char user[USERNAME_LENGTH+1]; char password[MAX_PASSWORD_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1]; LEX_STRING connection_name; /* User supplied connection name */ LEX_STRING cmp_connection_name; /* Connection name in lower case */ @@ -136,9 +141,35 @@ class Master_info : public Slave_reporting_capability Note that you can not change the numeric values of these, they are used in master.info. */ - enum { - USE_GTID_NO= 0, USE_GTID_CURRENT_POS= 1, USE_GTID_SLAVE_POS= 2 - } using_gtid; + enum enum_using_gtid using_gtid; + + /* + This GTID position records how far we have fetched into the relay logs. + This is used to continue fetching when the IO thread reconnects to the + master. + + (Full slave stop/start does not use it, as it resets the relay logs). + */ + slave_connection_state gtid_current_pos; + /* + If events_queued_since_last_gtid is non-zero, it is the number of events + queued so far in the relaylog of a GTID-prefixed event group. + It is zero when no partial event group has been queued at the moment. + */ + uint64 events_queued_since_last_gtid; + /* + The GTID of the partially-queued event group, when + events_queued_since_last_gtid is non-zero. + */ + rpl_gtid last_queued_gtid; + /* + When slave IO thread needs to reconnect, gtid_reconnect_event_skip_count + counts number of events to skip from the first GTID-prefixed event group, + to avoid duplicating events in the relay log. + */ + uint64 gtid_reconnect_event_skip_count; + /* gtid_event_seen is false until we receive first GTID event from master. */ + bool gtid_event_seen; }; int init_master_info(Master_info* mi, const char* master_info_fname, const char* slave_info_fname, diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 543c6d9fffe..7c8396ceaae 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -327,8 +327,7 @@ Failed to open the existing relay log info file '%s' (errno %d)", msg="Error reading slave log configuration"; goto err; } - strmake(rli->event_relay_log_name,rli->group_relay_log_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->group_relay_log_name); rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos; rli->group_master_log_pos= master_log_pos; @@ -546,10 +545,8 @@ int init_relay_log_pos(Relay_log_info* rli,const char* log, *errmsg="Could not find target log during relay log initialization"; goto err; } - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); if (rli->relay_log.is_active(rli->linfo.log_file_name)) { /* @@ -889,8 +886,7 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, mysql_mutex_lock(&data_lock); inc_event_relay_log_pos(); group_relay_log_pos= event_relay_log_pos; - strmake(group_relay_log_name,event_relay_log_name, - sizeof(group_relay_log_name)-1); + strmake_buf(group_relay_log_name,event_relay_log_name); notify_group_relay_log_name_update(); @@ -1025,10 +1021,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, if (!just_reset) { /* Save name of used relay log file */ - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; rli->log_space_total= 0; @@ -1426,7 +1420,10 @@ rpl_load_gtid_slave_state(THD *thd) bitmap_set_all(table->read_set); if ((err= table->file->ha_rnd_init_with_error(1))) + { + table->file->print_error(err, MYF(0)); goto end; + } table_scanned= true; for (;;) { @@ -1441,7 +1438,10 @@ rpl_load_gtid_slave_state(THD *thd) else if (err == HA_ERR_END_OF_FILE) break; else + { + table->file->print_error(err, MYF(0)); goto end; + } } domain_id= (ulonglong)table->field[0]->val_int(); sub_id= (ulonglong)table->field[1]->val_int(); @@ -1466,6 +1466,7 @@ rpl_load_gtid_slave_state(THD *thd) if (!(entry= (struct local_element *)my_malloc(sizeof(*entry), MYF(MY_WME)))) { + my_error(ER_OUTOFMEMORY, MYF(0), (int)sizeof(*entry)); err= 1; goto end; } @@ -1476,12 +1477,18 @@ rpl_load_gtid_slave_state(THD *thd) if ((err= my_hash_insert(&hash, (uchar *)entry))) { my_free(entry); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); goto end; } } } rpl_global_gtid_slave_state.lock(); + if (rpl_global_gtid_slave_state.loaded) + { + rpl_global_gtid_slave_state.unlock(); + goto end; + } for (i= 0; i < hash.records; ++i) { entry= (struct local_element *)my_hash_element(&hash, i); @@ -1491,14 +1498,15 @@ rpl_load_gtid_slave_state(THD *thd) entry->gtid.seq_no))) { rpl_global_gtid_slave_state.unlock(); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); goto end; } if (opt_bin_log && mysql_bin_log.bump_seq_no_counter_if_needed(entry->gtid.domain_id, entry->gtid.seq_no)) { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); rpl_global_gtid_slave_state.unlock(); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); goto end; } } diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index 1be97b34204..ac8a8fe356b 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -109,12 +109,15 @@ max_display_length_for_field(enum_field_types sql_type, unsigned int metadata) case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIME2: return 3; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: return 4; case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: return 8; case MYSQL_TYPE_BIT: @@ -262,12 +265,21 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const case MYSQL_TYPE_TIME: length= 3; break; + case MYSQL_TYPE_TIME2: + length= my_time_binary_length(m_field_metadata[col]); + break; case MYSQL_TYPE_TIMESTAMP: length= 4; break; + case MYSQL_TYPE_TIMESTAMP2: + length= my_timestamp_binary_length(m_field_metadata[col]); + break; case MYSQL_TYPE_DATETIME: length= 8; break; + case MYSQL_TYPE_DATETIME2: + length= my_datetime_binary_length(m_field_metadata[col]); + break; case MYSQL_TYPE_BIT: { /* @@ -376,6 +388,7 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_ break; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: str->set_ascii(STRING_WITH_LEN("timestamp")); break; @@ -393,10 +406,12 @@ void show_sql_type(enum_field_types type, uint16 metadata, String *str, CHARSET_ break; case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIME2: str->set_ascii(STRING_WITH_LEN("time")); break; case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: str->set_ascii(STRING_WITH_LEN("datetime")); break; @@ -615,6 +630,23 @@ can_convert_field_to(Field *field, else DBUG_RETURN(false); } + else if (metadata == 0 && + ((field->real_type() == MYSQL_TYPE_TIMESTAMP2 && + source_type == MYSQL_TYPE_TIMESTAMP) || + (field->real_type() == MYSQL_TYPE_TIME2 && + source_type == MYSQL_TYPE_TIME) || + (field->real_type() == MYSQL_TYPE_DATETIME2 && + source_type == MYSQL_TYPE_DATETIME))) + { + /* + TS-TODO: conversion from FSP1>FSP2. + Can do non-lossy conversion + from old TIME, TIMESTAMP, DATETIME + to MySQL56 TIME(0), TIMESTAMP(0), DATETIME(0). + */ + *order_var= -1; + DBUG_RETURN(true); + } else if (!slave_type_conversions_options) DBUG_RETURN(false); @@ -739,6 +771,9 @@ can_convert_field_to(Field *field, case MYSQL_TYPE_NULL: case MYSQL_TYPE_ENUM: case MYSQL_TYPE_SET: + case MYSQL_TYPE_TIMESTAMP2: + case MYSQL_TYPE_DATETIME2: + case MYSQL_TYPE_TIME2: DBUG_RETURN(false); } DBUG_RETURN(false); // To keep GCC happy @@ -939,7 +974,7 @@ TABLE *table_def::create_conversion_table(THD *thd, Relay_log_info *rli, TABLE * DBUG_PRINT("debug", ("sql_type: %d, target_field: '%s', max_length: %d, decimals: %d," " maybe_null: %d, unsigned_flag: %d, pack_length: %u", - type(col), target_table->field[col]->field_name, + binlog_type(col), target_table->field[col]->field_name, max_length, decimals, TRUE, FALSE, pack_length)); field_def->init_for_tmp_table(type(col), max_length, @@ -993,7 +1028,7 @@ table_def::table_def(unsigned char *types, ulong size, int index= 0; for (unsigned int i= 0; i < m_size; i++) { - switch (m_type[i]) { + switch (binlog_type(i)) { case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: @@ -1042,6 +1077,11 @@ table_def::table_def(unsigned char *types, ulong size, m_field_metadata[i]= x; break; } + case MYSQL_TYPE_TIME2: + case MYSQL_TYPE_DATETIME2: + case MYSQL_TYPE_TIMESTAMP2: + m_field_metadata[i]= field_metadata[index++]; + break; default: m_field_metadata[i]= 0; break; @@ -1173,6 +1213,7 @@ void Deferred_log_events::rewind() Log_event *ev= *(Log_event **) dynamic_array_ptr(&array, i); delete ev; } + last_added= NULL; if (array.elements > array.max_element) freeze_size(&array); reset_dynamic(&array); diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h index 79f4517c492..b08721aa8c2 100644 --- a/sql/rpl_utility.h +++ b/sql/rpl_utility.h @@ -65,6 +65,14 @@ public: ulong size() const { return m_size; } + /** + Returns internal binlog type code for one field, + without translation to real types. + */ + enum_field_types binlog_type(ulong index) const + { + return static_cast(m_type[index]); + } /* Return a representation of the type data for one field. @@ -82,7 +90,7 @@ public: either MYSQL_TYPE_STRING, MYSQL_TYPE_ENUM, or MYSQL_TYPE_SET, so we might need to modify the type to get the real type. */ - enum_field_types source_type= static_cast(m_type[index]); + enum_field_types source_type= binlog_type(index); uint16 source_metadata= m_field_metadata[index]; switch (source_type) { diff --git a/sql/set_var.cc b/sql/set_var.cc index 363f03579ef..d9741ca3481 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. - Copyright (c) 2008, 2012, Monty Program Ab +/* Copyright (c) 2002, 2013, Oracle and/or its affiliates. + Copyright (c) 2008, 2013, 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 @@ -16,7 +16,7 @@ /* variable declarations are in sys_vars.cc now !!! */ -#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_plugin.h" #include "sql_class.h" // set_var.h: session_var_ptr #include "set_var.h" #include "sql_priv.h" @@ -251,16 +251,14 @@ uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) return session_value_ptr(thd, base); } -bool sys_var::set_default(THD *thd, enum_var_type type) +bool sys_var::set_default(THD *thd, set_var* var) { - set_var var(type, this, &null_lex_str, 0); - - if (type == OPT_GLOBAL || scope() == GLOBAL) - global_save_default(thd, &var); + if (var->type == OPT_GLOBAL || scope() == GLOBAL) + global_save_default(thd, var); else - session_save_default(thd, &var); + session_save_default(thd, var); - return check(thd, &var) || update(thd, &var); + return check(thd, var) || update(thd, var); } @@ -771,7 +769,7 @@ int set_var::light_check(THD *thd) */ int set_var::update(THD *thd) { - return value ? var->update(thd, this) : var->set_default(thd, type); + return value ? var->update(thd, this) : var->set_default(thd, this); } diff --git a/sql/set_var.h b/sql/set_var.h index 52964a1f29d..4e13dfb2987 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -1,6 +1,6 @@ #ifndef SET_VAR_INCLUDED #define SET_VAR_INCLUDED -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. +/* Copyright (c) 2002, 2013, Oracle and/or its affiliates. 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 @@ -105,7 +105,13 @@ public: bool check(THD *thd, set_var *var); uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base); - bool set_default(THD *thd, enum_var_type type); + + /** + Update the system variable with the default value from either + session or global scope. The default value is stored in the + 'var' argument. Return false when successful. + */ + bool set_default(THD *thd, set_var *var); bool update(THD *thd, set_var *var); longlong val_int(bool *is_null, THD *thd, enum_var_type type, LEX_STRING *base); diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index ad055273155..5c60de14742 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6760,7 +6760,7 @@ ER_GTID_OPEN_TABLE_FAILED ER_GTID_POSITION_NOT_FOUND_IN_BINLOG eng "Connecting slave requested to start from GTID %u-%u-%llu, which is not in the master's binlog" ER_CANNOT_LOAD_SLAVE_GTID_STATE - eng "Failed to load replication slave GTID state from table %s.%s" + eng "Failed to load replication slave GTID position from table %s.%s" ER_MASTER_GTID_POS_CONFLICTS_WITH_BINLOG eng "Specified GTID %u-%u-%llu conflicts with the binary log which contains a more recent GTID %u-%u-%llu. If MASTER_GTID_POS=CURRENT_POS is used, the binlog position will override the new value of @@gtid_slave_pos." ER_MASTER_GTID_POS_MISSING_DOMAIN @@ -6771,3 +6771,5 @@ ER_GTID_STRICT_OUT_OF_ORDER eng "An attempt was made to binlog GTID %u-%u-%llu which would create an out-of-order sequence number with existing GTID %u-%u-%llu, and gtid strict mode is enabled." ER_GTID_START_FROM_BINLOG_HOLE eng "The binlog on the master is missing the GTID %u-%u-%llu requested by the slave (even though both a prior and a subsequent sequence number does exist), and GTID strict mode is enabled" +ER_SLAVE_UNEXPECTED_MASTER_SWITCH + eng "Unexpected GTID received from master after reconnect. This normally indicates that the master server was replaced without restarting the slave threads. %s" diff --git a/sql/slave.cc b/sql/slave.cc index 327f1b763a3..fe250103fb3 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -117,7 +117,7 @@ static const char *reconnect_messages[SLAVE_RECON_ACT_MAX][SLAVE_RECON_MSG_MAX]= registration on master", "Reconnecting after a failed registration on master", "failed registering on master, reconnecting to try again, \ -log '%s' at position %s", +log '%s' at position %s%s", "COM_REGISTER_SLAVE", "Slave I/O thread killed during or after reconnect" }, @@ -125,7 +125,7 @@ log '%s' at position %s", "Waiting to reconnect after a failed binlog dump request", "Slave I/O thread killed while retrying master dump", "Reconnecting after a failed binlog dump request", - "failed dump request, reconnecting to try again, log '%s' at position %s", + "failed dump request, reconnecting to try again, log '%s' at position %s%s", "COM_BINLOG_DUMP", "Slave I/O thread killed during or after reconnect" }, @@ -134,7 +134,7 @@ log '%s' at position %s", "Slave I/O thread killed while waiting to reconnect after a failed read", "Reconnecting after a failed master event read", "Slave I/O thread: Failed reading log event, reconnecting to retry, \ -log '%s' at position %s", +log '%s' at position %s%s", "", "Slave I/O thread killed during or after a reconnect done to recover from \ failed read" @@ -256,6 +256,66 @@ static void init_slave_psi_keys(void) } #endif /* HAVE_PSI_INTERFACE */ + +static bool slave_init_thread_running; + + +pthread_handler_t +handle_slave_init(void *arg __attribute__((unused))) +{ + THD *thd; + + my_thread_init(); + thd= new THD; + thd->thread_stack= (char*) &thd; /* Set approximate stack start */ + mysql_mutex_lock(&LOCK_thread_count); + thd->thread_id= thread_id++; + mysql_mutex_unlock(&LOCK_thread_count); + thd->store_globals(); + + thd_proc_info(thd, "Loading slave GTID position from table"); + if (rpl_load_gtid_slave_state(thd)) + sql_print_warning("Failed to load slave replication state from table " + "%s.%s: %u: %s", "mysql", + rpl_gtid_slave_state_table_name.str, + thd->stmt_da->sql_errno(), thd->stmt_da->message()); + + mysql_mutex_lock(&LOCK_thread_count); + delete thd; + mysql_mutex_unlock(&LOCK_thread_count); + my_thread_end(); + + mysql_mutex_lock(&LOCK_thread_count); + slave_init_thread_running= false; + mysql_cond_signal(&COND_thread_count); + mysql_mutex_unlock(&LOCK_thread_count); + + return 0; +} + + +static int +run_slave_init_thread() +{ + pthread_t th; + + slave_init_thread_running= true; + if (mysql_thread_create(key_thread_slave_init, &th, NULL, + handle_slave_init, NULL)) + { + sql_print_error("Failed to create thread while initialising slave"); + return 1; + } + + mysql_mutex_lock(&LOCK_thread_count); + while (slave_init_thread_running) + mysql_cond_wait(&COND_thread_count, &LOCK_thread_count); + mysql_mutex_unlock(&LOCK_thread_count); + + return 0; +} + + /* Initialize slave structures */ int init_slave() @@ -267,6 +327,9 @@ int init_slave() init_slave_psi_keys(); #endif + if (run_slave_init_thread()) + return 1; + /* This is called when mysqld starts. Before client connections are accepted. However bootstrap may conflict with us if it does START SLAVE. @@ -384,16 +447,13 @@ int init_recovery(Master_info* mi, const char** errmsg) { mi->master_log_pos= max(BIN_LOG_HEADER_SIZE, rli->group_master_log_pos); - strmake(mi->master_log_name, rli->group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, rli->group_master_log_name); sql_print_warning("Recovery from master pos %ld and file %s.", (ulong) mi->master_log_pos, mi->master_log_name); - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; } @@ -833,9 +893,13 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start, purge_relay_logs(&mi->rli, NULL, 0, &errmsg); mi->master_log_name[0]= 0; mi->master_log_pos= 0; + error= rpl_load_gtid_state(&mi->gtid_current_pos, mi->using_gtid == + Master_info::USE_GTID_CURRENT_POS); + mi->events_queued_since_last_gtid= 0; + mi->gtid_reconnect_event_skip_count= 0; } - if (thread_mask & SLAVE_IO) + if (!error && (thread_mask & SLAVE_IO)) error= start_slave_thread( #ifdef HAVE_PSI_INTERFACE key_thread_slave_io, @@ -1827,18 +1891,9 @@ past_checksum: after_set_capability: #endif - /* - Request dump start from slave replication GTID state. - - Only request GTID position the first time we connect after CHANGE MASTER - or after starting both IO or SQL thread. - - Otherwise, if the IO thread was ahead of the SQL thread before the - restart or reconnect, we might end up re-fetching and hence re-applying - the same event(s) again. - */ - if (mi->using_gtid != Master_info::USE_GTID_NO && !mi->master_log_name[0]) + if (mi->using_gtid != Master_info::USE_GTID_NO) { + /* Request dump to start from slave replication GTID state. */ int rc; char str_buf[256]; String query_str(str_buf, sizeof(str_buf), system_charset_info); @@ -1867,9 +1922,7 @@ after_set_capability: query_str.append(STRING_WITH_LEN("SET @slave_connect_state='"), system_charset_info); - if (rpl_append_gtid_state(&query_str, - mi->using_gtid == - Master_info::USE_GTID_CURRENT_POS)) + if (mi->gtid_current_pos.append_to_string(&query_str)) { err_code= ER_OUTOFMEMORY; errmsg= "The slave I/O thread stops because a fatal out-of-memory " @@ -1970,7 +2023,7 @@ after_set_capability: } } } - if (mi->using_gtid == Master_info::USE_GTID_NO) + else { /* If we are not using GTID to connect this time, then instead request @@ -2551,10 +2604,7 @@ static bool send_show_master_info_data(THD *thd, Master_info *mi, bool full, protocol->store(mi->ssl_ca, &my_charset_bin); // Master_Ssl_Crlpath protocol->store(mi->ssl_capath, &my_charset_bin); - protocol->store((mi->using_gtid==Master_info::USE_GTID_NO ? "No" : - (mi->using_gtid==Master_info::USE_GTID_SLAVE_POS ? - "Slave_Pos" : "Current_Pos")), - &my_charset_bin); + protocol->store(mi->using_gtid_astext(mi->using_gtid), &my_charset_bin); if (full) { protocol->store((uint32) mi->rli.retried_trans); @@ -3403,8 +3453,22 @@ static int try_to_reconnect(THD *thd, MYSQL *mysql, Master_info *mi, if (!suppress_warnings) { char buf[256], llbuff[22]; + String tmp; + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + tmp.append(STRING_WITH_LEN("; GTID position '")); + mi->gtid_current_pos.append_to_string(&tmp); + if (mi->events_queued_since_last_gtid == 0) + tmp.append(STRING_WITH_LEN("'")); + else + { + tmp.append(STRING_WITH_LEN("', GTID event skip ")); + tmp.append_ulonglong((ulonglong)mi->events_queued_since_last_gtid); + } + } my_snprintf(buf, sizeof(buf), messages[SLAVE_RECON_MSG_FAILED], - IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff)); + IO_RPL_LOG_NAME, llstr(mi->master_log_pos, llbuff), + tmp.c_ptr_safe()); /* Raise a warining during registering on master/requesting dump. Log a message reading event. @@ -3496,6 +3560,16 @@ pthread_handler_t handle_slave_io(void *arg) /* This must be called before run any binlog_relay_io hooks */ my_pthread_setspecific_ptr(RPL_MASTER_INFO, mi); + /* Load the set of seen GTIDs, if we did not already. */ + if (rpl_load_gtid_slave_state(thd)) + { + mi->report(ERROR_LEVEL, thd->stmt_da->sql_errno(), + "Unable to load replication GTID slave state from mysql.%s: %s", + rpl_gtid_slave_state_table_name.str, thd->stmt_da->message()); + goto err; + } + + if (RUN_HOOK(binlog_relay_io, thread_start, (thd, mi))) { mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, @@ -3514,11 +3588,21 @@ pthread_handler_t handle_slave_io(void *arg) // we can get killed during safe_connect if (!safe_connect(thd, mysql, mi)) { - sql_print_information("Slave I/O thread: connected to master '%s@%s:%d'," - "replication started in log '%s' at position %s", - mi->user, mi->host, mi->port, - IO_RPL_LOG_NAME, - llstr(mi->master_log_pos,llbuff)); + if (mi->using_gtid == Master_info::USE_GTID_NO) + sql_print_information("Slave I/O thread: connected to master '%s@%s:%d'," + "replication started in log '%s' at position %s", + mi->user, mi->host, mi->port, + IO_RPL_LOG_NAME, + llstr(mi->master_log_pos,llbuff)); + else + { + String tmp; + mi->gtid_current_pos.to_string(&tmp); + sql_print_information("Slave I/O thread: connected to master '%s@%s:%d'," + "replication starts at GTID position '%s'", + mi->user, mi->host, mi->port, tmp.c_ptr_safe()); + } + /* Adding MAX_LOG_EVENT_HEADER_LEN to the max_packet_size on the I/O thread, since a replication event can become this much larger than @@ -3535,6 +3619,25 @@ pthread_handler_t handle_slave_io(void *arg) connected: + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + /* + When the IO thread (re)connects to the master using GTID, it will + connect at the start of an event group. But the IO thread may have + previously logged part of the following event group to the relay + log. + + When the IO and SQL thread are started together, we erase any previous + relay logs, but this is not possible/desirable while the SQL thread is + running. To avoid duplicating partial event groups in the relay logs in + this case, we remember the count of events in any partially logged event + group before the reconnect, and then here at connect we set up a counter + to skip the already-logged part of the group. + */ + mi->gtid_reconnect_event_skip_count= mi->events_queued_since_last_gtid; + mi->gtid_event_seen= false; + } + #ifdef ENABLED_DEBUG_SYNC DBUG_EXECUTE_IF("dbug.before_get_running_status_yes", { @@ -3760,8 +3863,19 @@ log space"); // error = 0; err: // print the current replication position - sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s", - IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff)); + if (mi->using_gtid == Master_info::USE_GTID_NO) + sql_print_information("Slave I/O thread exiting, read up to log '%s', " + "position %s", + IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff)); + else + { + String tmp; + mi->gtid_current_pos.to_string(&tmp); + sql_print_information("Slave I/O thread exiting, read up to log '%s', " + "position %s; GTID position %s", + IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff), + tmp.c_ptr_safe()); + } RUN_HOOK(binlog_relay_io, thread_stop, (thd, mi)); thd->reset_query(); thd->reset_db(NULL, 0); @@ -4033,10 +4147,20 @@ pthread_handler_t handle_slave_sql(void *arg) rli->group_master_log_name, llstr(rli->group_master_log_pos,llbuff))); if (global_system_variables.log_warnings) + { + String tmp; + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + tmp.append(STRING_WITH_LEN("; GTID position '")); + rpl_append_gtid_state(&tmp, + mi->using_gtid==Master_info::USE_GTID_CURRENT_POS); + tmp.append(STRING_WITH_LEN("'")); + } sql_print_information("Slave SQL thread initialized, starting replication in \ -log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, +log '%s' at position %s, relay log '%s' position: %s%s", RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name, - llstr(rli->group_relay_log_pos,llbuff1)); + llstr(rli->group_relay_log_pos,llbuff1), tmp.c_ptr_safe()); + } if (check_temp_dir(rli->slave_patternload_file)) { @@ -4074,8 +4198,8 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, mysql_mutex_lock(&rli->data_lock); if (rli->slave_skip_counter) { - strmake(saved_log_name, rli->group_relay_log_name, FN_REFLEN - 1); - strmake(saved_master_log_name, rli->group_master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, rli->group_relay_log_name); + strmake_buf(saved_master_log_name, rli->group_master_log_name); saved_log_pos= rli->group_relay_log_pos; saved_master_log_pos= rli->group_master_log_pos; saved_skip= rli->slave_skip_counter; @@ -4170,16 +4294,35 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, sql_print_warning("Slave: %s Error_code: %d", err->get_message_text(), err->get_sql_errno()); } if (udf_error) + { + String tmp; + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + tmp.append(STRING_WITH_LEN("; GTID position '")); + rpl_append_gtid_state(&tmp, false); + tmp.append(STRING_WITH_LEN("'")); + } sql_print_error("Error loading user-defined library, slave SQL " "thread aborted. Install the missing library, and restart the " "slave SQL thread with \"SLAVE START\". We stopped at log '%s' " - "position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, - llbuff)); + "position %s%s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, + llbuff), tmp.c_ptr_safe()); + } else + { + String tmp; + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + tmp.append(STRING_WITH_LEN("; GTID position '")); + rpl_append_gtid_state(&tmp, false); + tmp.append(STRING_WITH_LEN("'")); + } sql_print_error("\ Error running query, slave SQL thread aborted. Fix the problem, and restart \ the slave SQL thread with \"SLAVE START\". We stopped at log \ -'%s' position %s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, llbuff)); +'%s' position %s%s", RPL_LOG_NAME, llstr(rli->group_master_log_pos, llbuff), + tmp.c_ptr_safe()); + } } goto err; } @@ -4187,9 +4330,20 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ } /* Thread stopped. Print the current replication position to the log */ - sql_print_information("Slave SQL thread exiting, replication stopped in log " - "'%s' at position %s", - RPL_LOG_NAME, llstr(rli->group_master_log_pos,llbuff)); + { + String tmp; + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + tmp.append(STRING_WITH_LEN("; GTID position '")); + rpl_append_gtid_state(&tmp, false); + tmp.append(STRING_WITH_LEN("'")); + } + sql_print_information("Slave SQL thread exiting, replication stopped in " + "log '%s' at position %s%s", + RPL_LOG_NAME, + llstr(rli->group_master_log_pos,llbuff), + tmp.c_ptr_safe()); + } err: @@ -4664,6 +4818,8 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) mysql_mutex_t *log_lock= rli->relay_log.get_log_lock(); ulong s_id; bool unlock_data_lock= TRUE; + bool gtid_skip_enqueue= false; + /* FD_q must have been prepared for the first R_a event inside get_master_version_and_clock() @@ -4850,6 +5006,19 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) /* installing new value of checksum Alg for relay log */ mi->rli.relay_log.relay_log_checksum_alg= tmp->checksum_alg; + /* + Do not queue any format description event that we receive after a + reconnect where we are skipping over a partial event group received + before the reconnect. + + (If we queued such an event, and it was the first format_description + event after master restart, the slave SQL thread would think that + the partial event group before it in the relay log was from a + previous master crash and should be rolled back). + */ + if (unlikely(mi->gtid_reconnect_event_skip_count && !mi->gtid_event_seen)) + gtid_skip_enqueue= true; + /* Though this does some conversion to the slave's format, this will preserve the master's binlog format version, and number of event types. @@ -4945,18 +5114,113 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) " UNTIL master_gtid_pos %s", str.c_ptr_safe()); mi->abort_slave= true; } + event_pos= glev->log_pos; delete glev; /* - Do not update position for fake Gtid_list event (which has a zero - end_log_pos). + We use fake Gtid_list events to update the old-style position (among + other things). + + Early code created fake Gtid_list events with zero log_pos, those should + not modify old-style position. */ - inc_pos= uint4korr(buf+LOG_POS_OFFSET) ? event_len : 0; + if (event_pos == 0 || event_pos <= mi->master_log_pos) + inc_pos= 0; + else + inc_pos= event_pos - mi->master_log_pos; + } + break; + + case GTID_EVENT: + { + uchar dummy_flag; + + if (mi->using_gtid == Master_info::USE_GTID_NO) + goto default_action; + if (unlikely(!mi->gtid_event_seen)) + { + mi->gtid_event_seen= true; + if (mi->gtid_reconnect_event_skip_count) + { + rpl_gtid gtid; + + /* + If we are reconnecting, and we need to skip a partial event group + already queued to the relay log before the reconnect, then we check + that we actually get the same event group (same GTID) as before, so + we do not end up with half of one group and half another. + + The only way we should be able to receive a different GTID than what + we expect is if the binlog on the master (or more likely the whole + master server) was replaced with a different one, one the same IP + address, _and_ the new master happens to have domains in a different + order so we get the GTID from a different domain first. Still, it is + best to protect against this case. + */ + if (Gtid_log_event::peek(buf, event_len, checksum_alg, + >id.domain_id, >id.server_id, + >id.seq_no, &dummy_flag)) + { + error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE; + goto err; + } + if (gtid.domain_id != mi->last_queued_gtid.domain_id || + gtid.server_id != mi->last_queued_gtid.server_id || + gtid.seq_no != mi->last_queued_gtid.seq_no) + { + bool first; + error= ER_SLAVE_UNEXPECTED_MASTER_SWITCH; + error_msg.append(STRING_WITH_LEN("Expected: ")); + first= true; + rpl_slave_state_tostring_helper(&error_msg, &mi->last_queued_gtid, + &first); + error_msg.append(STRING_WITH_LEN(", received: ")); + first= true; + rpl_slave_state_tostring_helper(&error_msg, >id, &first); + goto err; + } + } + } + + if (unlikely(mi->gtid_reconnect_event_skip_count)) + { + goto default_action; + } + + /* + We have successfully queued to relay log everything before this GTID, so + in case of reconnect we can start from after any previous GTID. + */ + if (mi->events_queued_since_last_gtid) + { + mi->gtid_current_pos.update(&mi->last_queued_gtid); + mi->events_queued_since_last_gtid= 0; + } + if (Gtid_log_event::peek(buf, event_len, checksum_alg, + &mi->last_queued_gtid.domain_id, + &mi->last_queued_gtid.server_id, + &mi->last_queued_gtid.seq_no, &dummy_flag)) + { + error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE; + goto err; + } + ++mi->events_queued_since_last_gtid; } break; default: default_action: + if (mi->using_gtid != Master_info::USE_GTID_NO && mi->gtid_event_seen) + { + if (unlikely(mi->gtid_reconnect_event_skip_count)) + { + --mi->gtid_reconnect_event_skip_count; + gtid_skip_enqueue= true; + } + else if (mi->events_queued_since_last_gtid) + ++mi->events_queued_since_last_gtid; + } + inc_pos= event_len; break; } @@ -5041,8 +5305,16 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) } else { - /* write the event to the relay log */ - if (likely(!(rli->relay_log.appendv(buf,event_len,0)))) + /* + Write the event to the relay log, unless we reconnected in the middle + of an event group and now need to skip the initial part of the group that + we already wrote before reconnecting. + */ + if (unlikely(gtid_skip_enqueue)) + { + mi->master_log_pos+= inc_pos; + } + else if (likely(!(rli->relay_log.appendv(buf,event_len,0)))) { mi->master_log_pos+= inc_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); @@ -5780,8 +6052,7 @@ static Log_event* next_event(Relay_log_info* rli) goto err; } rli->event_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); flush_relay_log_info(rli); } diff --git a/sql/sp.cc b/sql/sp.cc index b60411a9121..0f32f7a305b 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -114,7 +114,7 @@ TABLE_FIELD_TYPE proc_table_fields[MYSQL_PROC_FIELD_COUNT] = }, { { C_STRING_WITH_LEN("definer") }, - { C_STRING_WITH_LEN("char(77)") }, + { C_STRING_WITH_LEN("char(") }, { C_STRING_WITH_LEN("utf8") } }, { diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 37f5e97110a..98e807722a3 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1159,8 +1159,9 @@ find_handler_after_execution(THD *thd, sp_rcontext *ctx) MYSQL_ERROR *err; while ((err= it++)) { - if (err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN && - err->get_level() != MYSQL_ERROR::WARN_LEVEL_NOTE) + if ((err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN && + err->get_level() != MYSQL_ERROR::WARN_LEVEL_NOTE) || + err->handled()) continue; if (ctx->find_handler(thd, @@ -1169,6 +1170,7 @@ find_handler_after_execution(THD *thd, sp_rcontext *ctx) err->get_level(), err->get_message_text())) { + err->mark_handled(); break; } } @@ -1418,6 +1420,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) Will write this SP statement into binlog separately. TODO: consider changing the condition to "not inside event union". */ + MEM_ROOT *user_var_events_alloc_saved= thd->user_var_events_alloc; if (thd->locked_tables_mode <= LTM_LOCK_TABLES) thd->user_var_events_alloc= thd->mem_root; @@ -1433,7 +1436,7 @@ sp_head::execute(THD *thd, bool merge_da_on_success) if (thd->locked_tables_mode <= LTM_LOCK_TABLES) { reset_dynamic(&thd->user_var_events); - thd->user_var_events_alloc= NULL;//DEBUG + thd->user_var_events_alloc= user_var_events_alloc_saved; } /* we should cleanup free_list and memroot, used by instruction */ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index d056727c2fd..7e261cc755c 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -70,7 +70,7 @@ TABLE_FIELD_TYPE mysql_db_table_fields[MYSQL_DB_FIELD_COUNT] = { }, { { C_STRING_WITH_LEN("User") }, - { C_STRING_WITH_LEN("char(16)") }, + { C_STRING_WITH_LEN("char(") }, {NULL, 0} }, { @@ -829,6 +829,7 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables) goto end; table->use_all_columns(); (void) my_init_dynamic_array(&acl_users,sizeof(ACL_USER), 50, 100, MYF(0)); + username_char_length= min(table->field[1]->char_length(), USERNAME_CHAR_LENGTH); password_length= table->field[2]->field_length / table->field[2]->charset()->mbmaxlen; if (password_length < SCRAMBLED_PASSWORD_CHAR_LENGTH_323) @@ -1436,12 +1437,12 @@ bool acl_getroot(Security_context *sctx, char *user, char *host, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; } @@ -8193,6 +8194,12 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) cs->coll->hash_sort(cs, (uchar*) sctx->user, strlen(sctx->user), &nr1, &nr2); mysql_mutex_lock(&acl_cache->lock); + if (!acl_users.elements) + { + mysql_mutex_unlock(&acl_cache->lock); + login_failed_error(mpvio->thd); + DBUG_RETURN(1); + } uint i= nr1 % acl_users.elements; ACL_USER *acl_user_tmp= dynamic_element(&acl_users, i, ACL_USER*); mpvio->acl_user= acl_user_tmp->copy(mpvio->thd->mem_root); @@ -8218,10 +8225,9 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) mpvio->auth_info.user_name= sctx->user; mpvio->auth_info.user_name_length= strlen(sctx->user); mpvio->auth_info.auth_string= mpvio->acl_user->auth_string.str; - mpvio->auth_info.auth_string_length= - (unsigned long) mpvio->acl_user->auth_string.length; - strmake(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? - mpvio->acl_user->user : "", USERNAME_LENGTH); + mpvio->auth_info.auth_string_length= (unsigned long) mpvio->acl_user->auth_string.length; + strmake_buf(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? + mpvio->acl_user->user : ""); DBUG_PRINT("info", ("exit: user=%s, auth_string=%s, authenticated as=%s" "plugin=%s", @@ -8305,7 +8311,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) /* Clear variables that are allocated */ thd->user_connect= 0; - strmake(sctx->priv_user, sctx->user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, sctx->user); if (thd->make_lex_string(&mpvio->db, db_buff, db_len) == 0) DBUG_RETURN(1); /* The error is set by make_lex_string(). */ @@ -8520,14 +8526,15 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio, /* Clip username to allowed length in characters (not bytes). This is - mostly for backward compatibility. + mostly for backward compatibility (to truncate long usernames, as + old 5.1 did) */ { CHARSET_INFO *cs= system_charset_info; int err; user_len= (uint) cs->cset->well_formed_len(cs, user, user + user_len, - USERNAME_CHAR_LENGTH, &err); + username_char_length, &err); user[user_len]= '\0'; } @@ -9122,12 +9129,12 @@ bool acl_authenticate(THD *thd, uint connect_errors, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, acl_user->user, USERNAME_LENGTH - 1); + strmake_buf(sctx->priv_user, acl_user->user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index a9b7624af3c..d08cd7915ab 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -329,7 +329,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, item->maybe_null = 1; field_list.push_back(item = new Item_empty_string("Msg_type", 10)); item->maybe_null = 1; - field_list.push_back(item = new Item_empty_string("Msg_text", 255)); + field_list.push_back(item = new Item_empty_string("Msg_text", + SQL_ADMIN_MSG_TEXT_SIZE)); item->maybe_null = 1; if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) diff --git a/sql/sql_admin.h b/sql/sql_admin.h index f7ec76efd5e..5398e3019f1 100644 --- a/sql/sql_admin.h +++ b/sql/sql_admin.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -16,6 +16,8 @@ #ifndef SQL_TABLE_MAINTENANCE_H #define SQL_TABLE_MAINTENANCE_H +/* Must be able to hold ALTER TABLE t PARTITION BY ... KEY ALGORITHM = 1 ... */ +#define SQL_ADMIN_MSG_TEXT_SIZE 128 * 1024 bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, LEX_STRING *key_cache_name); diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 793eead9869..07a5243e836 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -31,8 +31,7 @@ unsigned long mysql_global_audit_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; static mysql_mutex_t LOCK_audit_mask; -static void event_class_dispatch(THD *thd, unsigned int event_class, - const void *event); +static void event_class_dispatch(THD *, unsigned int, const void *); static inline @@ -111,9 +110,36 @@ static void connection_class_handler(THD *thd, uint event_subclass, va_list ap) } +static void table_class_handler(THD *thd, uint event_subclass, va_list ap) +{ + mysql_event_table event; + event.event_subclass= event_subclass; + event.read_only= va_arg(ap, int); + event.thread_id= va_arg(ap, unsigned long); + event.user= va_arg(ap, const char *); + event.priv_user= va_arg(ap, const char *); + event.priv_host= va_arg(ap, const char *); + event.external_user= va_arg(ap, const char *); + event.proxy_user= va_arg(ap, const char *); + event.host= va_arg(ap, const char *); + event.ip= va_arg(ap, const char *); + event.database= va_arg(ap, const char *); + event.database_length= va_arg(ap, unsigned int); + event.table= va_arg(ap, const char *); + event.table_length= va_arg(ap, unsigned int); + event.new_database= va_arg(ap, const char *); + event.new_database_length= va_arg(ap, unsigned int); + event.new_table= va_arg(ap, const char *); + event.new_table_length= va_arg(ap, unsigned int); + event_class_dispatch(thd, MYSQL_AUDIT_TABLE_CLASS, &event); +} + + static audit_handler_t audit_handlers[] = { - general_class_handler, connection_class_handler + general_class_handler, connection_class_handler, + 0,0,0,0,0,0,0,0,0,0,0,0,0, /* placeholders */ + table_class_handler }; static const uint audit_handlers_count= diff --git a/sql/sql_audit.h b/sql/sql_audit.h index a651ce61374..22fdd221e62 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -48,18 +48,24 @@ static inline bool mysql_audit_connection_enabled() return mysql_global_audit_mask[0] & MYSQL_AUDIT_CONNECTION_CLASSMASK; } +static inline bool mysql_audit_table_enabled() +{ + return mysql_global_audit_mask[0] & MYSQL_AUDIT_TABLE_CLASSMASK; +} + #else static inline void mysql_audit_notify(THD *thd, uint event_class, uint event_subtype, ...) { } #define mysql_audit_general_enabled() 0 #define mysql_audit_connection_enabled() 0 +#define mysql_audit_table_enabled() 0 #endif extern void mysql_audit_release(THD *thd); #define MAX_USER_HOST_SIZE 512 static inline uint make_user_name(THD *thd, char *buf) { - Security_context *sctx= thd->security_ctx; + const Security_context *sctx= thd->security_ctx; return strxnmov(buf, MAX_USER_HOST_SIZE, sctx->priv_user[0] ? sctx->priv_user : "", "[", sctx->user ? sctx->user : "", "] @ ", @@ -197,4 +203,87 @@ void mysql_audit_notify_connection_change_user(THD *thd) } } +static inline +void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) +{ + if (lock != F_UNLCK && mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_LOCK, + (int)(lock == F_RDLCK), (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, share->db.str, (uint)share->db.length, + share->table_name.str, (uint)share->table_name.length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_create_table(TABLE *table) +{ + if (mysql_audit_table_enabled()) + { + THD *thd= table->in_use; + const TABLE_SHARE *share= table->s; + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_CREATE, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, share->db.str, (uint)share->db.length, + share->table_name.str, (uint)share->table_name.length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_drop_table(THD *thd, TABLE_LIST *table) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_DROP, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, table->db, (uint)table->db_length, + table->table_name, (uint)table->table_name_length, + 0,0,0,0); + } +} + +static inline +void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb, + const char *new_db, const char *new_tb) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_RENAME, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, + old_db, (uint)strlen(old_db), old_tb, (uint)strlen(old_tb), + new_db, (uint)strlen(new_db), new_tb, (uint)strlen(new_tb)); + } +} + +static inline +void mysql_audit_alter_table(THD *thd, TABLE_LIST *table) +{ + if (mysql_audit_table_enabled()) + { + const Security_context *sctx= thd->security_ctx; + mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, MYSQL_AUDIT_TABLE_ALTER, + 0, (ulong)thd->thread_id, + sctx->user, sctx->priv_user, sctx->priv_host, + sctx->external_user, sctx->proxy_user, sctx->host, + sctx->ip, table->db, (uint)table->db_length, + table->table_name, (uint)table->table_name_length, + 0,0,0,0); + } +} + #endif /* SQL_AUDIT_INCLUDED */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c9630aef126..931fb07f70c 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6864,7 +6864,7 @@ find_field_in_tables(THD *thd, Item_ident *item, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db, sizeof(name_buff)-1); + strmake_buf(name_buff, db); my_casedn_str(files_charset_info, name_buff); db= name_buff; } @@ -8437,7 +8437,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc index a4664da2bf6..3bb5deab406 100644 --- a/sql/sql_binlog.cc +++ b/sql/sql_binlog.cc @@ -107,7 +107,7 @@ void mysql_client_binlog_statement(THD* thd) rli->relay_log.description_event_for_exec && buf)) { - my_error(ER_OUTOFMEMORY, MYF(0), 1); /* needed 1 bytes */ + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), 1); /* needed 1 bytes */ goto end; } diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index ba204f48978..436f7043c49 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -472,6 +472,8 @@ static void make_base_query(String *new_query, /* The following is guaranteed by the query_cache interface */ DBUG_ASSERT(query[query_length] == 0); DBUG_ASSERT(!is_white_space(query[0])); + /* We do not support UCS2, UTF16, UTF32 as a client character set */ + DBUG_ASSERT(current_thd->variables.character_set_client->mbminlen == 1); new_query->length(0); // Don't copy anything from old buffer if (new_query->realloc(query_length + additional_length)) @@ -2439,7 +2441,28 @@ void Query_cache::init() m_cache_status= Query_cache::OK; m_requests_in_progress= 0; initialized = 1; - query_state_map= default_charset_info->state_map; + /* + Using state_map from latin1 should be fine in all cases: + 1. We do not support UCS2, UTF16, UTF32 as a client character set. + 2. The other character sets are compatible on the lower ASCII-range + 0x00-0x20, and have the following characters marked as spaces: + + 0x09 TAB + 0x0A LINE FEED + 0x0B VERTICAL TAB + 0x0C FORM FEED + 0x0D CARRIAGE RETUR + 0x20 SPACE + + Additionally, only some of the ASCII-compatible character sets + (including latin1) can have 0xA0 mapped to "NON-BREAK SPACE" + and thus marked as space. + That should not be a problem for those charsets that map 0xA0 + to something else: the parser will just return syntax error + if this character appears straight in the query + (i.e. not inside a string literal or comment). + */ + query_state_map= my_charset_latin1.state_map; /* If we explicitly turn off query cache from the command line query cache will be disabled for the reminder of the server life @@ -3971,6 +3994,18 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, } +/* +In non-embedded QC intercepts result in net_real_write +but if we have no net.vio then net_real_write +will not be called, so QC can't get results of the query +*/ +#ifdef EMBEDDED_LIBRARY +#define qc_is_able_to_intercept_result(T) 1 +#else +#define qc_is_able_to_intercept_result(T) ((T)->net.vio) +#endif + + /* If query is cacheable return number tables in query (query without tables are not cached) @@ -3986,7 +4021,8 @@ Query_cache::is_cacheable(THD *thd, LEX *lex, if (thd->lex->safe_to_cache_query && (thd->variables.query_cache_type == 1 || (thd->variables.query_cache_type == 2 && (lex->select_lex.options & - OPTION_TO_QUERY_CACHE)))) + OPTION_TO_QUERY_CACHE))) && + qc_is_able_to_intercept_result(thd)) { DBUG_PRINT("qcache", ("options: %lx %lx type: %u", (long) OPTION_TO_QUERY_CACHE, @@ -4008,11 +4044,12 @@ Query_cache::is_cacheable(THD *thd, LEX *lex, } DBUG_PRINT("qcache", - ("not interesting query: %d or not cacheable, options %lx %lx type: %u", + ("not interesting query: %d or not cacheable, options %lx %lx type: %u net->vio present: %u", (int) lex->sql_command, (long) OPTION_TO_QUERY_CACHE, (long) lex->select_lex.options, - (int) thd->variables.query_cache_type)); + (int) thd->variables.query_cache_type, + (uint) test(qc_is_able_to_intercept_result(thd)))); DBUG_RETURN(0); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 71df97dd964..fcf707f46b7 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -35,6 +35,7 @@ #include "sql_cache.h" // query_cache_abort #include "sql_base.h" // close_thread_tables #include "sql_time.h" // date_time_format_copy +#include "tztime.h" // MYSQL_TIME <-> my_time_t #include "sql_acl.h" // NO_ACCESS, // acl_getroot_no_password #include "sql_base.h" // close_temporary_tables @@ -1412,10 +1413,16 @@ MYSQL_ERROR* THD::raise_condition(uint sql_errno, query_cache_abort(&query_cache_tls); - /* When simulating OOM, skip writing to error log to avoid mtr errors */ - DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_RETURN(NULL);); - - cond= warning_info->push_warning(this, sql_errno, sqlstate, level, msg); + /* + Avoid pushing a condition for fatal out of memory errors as this will + require memory allocation and therefore might fail. Non fatal out of + memory errors can occur if raised by SIGNAL/RESIGNAL statement. + */ + if (!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY || + sql_errno == ER_OUTOFMEMORY))) + { + cond= warning_info->push_warning(this, sql_errno, sqlstate, level, msg); + } DBUG_RETURN(cond); } @@ -1464,6 +1471,26 @@ void thd_get_xid(const MYSQL_THD thd, MYSQL_XID *xid) *xid = *(MYSQL_XID *) &thd->transaction.xid_state.xid; } + +extern "C" +my_time_t thd_TIME_to_gmt_sec(MYSQL_THD thd, const MYSQL_TIME *ltime, + unsigned int *errcode) +{ + Time_zone *tz= thd ? thd->variables.time_zone : + global_system_variables.time_zone; + return tz->TIME_to_gmt_sec(ltime, errcode); +} + + +extern "C" +void thd_gmt_sec_to_TIME(MYSQL_THD thd, MYSQL_TIME *ltime, my_time_t t) +{ + Time_zone *tz= thd ? thd->variables.time_zone : + global_system_variables.time_zone; + tz->gmt_sec_to_TIME(ltime, t); +} + + #ifdef _WIN32 extern "C" THD *_current_thd_noinline(void) { @@ -2358,7 +2385,7 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length) key_length + 1); if (!new_table) { - my_error(EE_OUTOFMEMORY, MYF(ME_BELL), + my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_FATALERROR), ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); killed= KILL_CONNECTION; return 0; @@ -2831,7 +2858,7 @@ select_export::prepare(List &list, SELECT_LEX_UNIT *u) bool string_results= FALSE, non_string_results= FALSE; unit= u; if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) - strmake(path,exchange->file_name,FN_REFLEN-1); + strmake_buf(path,exchange->file_name); write_cs= exchange->cs ? exchange->cs : &my_charset_bin; @@ -2969,7 +2996,7 @@ int select_export::send_data(List &items) set_if_smaller(estimated_bytes, UINT_MAX32); if (cvt_str.realloc((uint32) estimated_bytes)) { - my_error(ER_OUTOFMEMORY, MYF(0), (uint32) estimated_bytes); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), (uint32) estimated_bytes); goto err; } diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index b3af783c566..acf1ba489ad 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -438,7 +438,7 @@ void init_user_stats(USER_STATS *user_stats, memcpy(user_stats->user, user, user_length); user_stats->user[user_length]= 0; user_stats->user_name_length= user_length; - strmake(user_stats->priv_user, priv_user, sizeof(user_stats->priv_user)-1); + strmake_buf(user_stats->priv_user, priv_user); user_stats->total_connections= total_connections; user_stats->concurrent_connections= concurrent_connections; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 1fed2a37e15..1d52be4272a 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -686,7 +686,7 @@ multi_delete::initialize_tables(JOIN *join) tab; tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) { - if (tab->table->map & tables_to_delete_from) + if (!tab->bush_children && tab->table->map & tables_to_delete_from) { /* We are going to delete from this table */ TABLE *tbl=walk->table=tab->table; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 23a60267737..8cfc304e0e7 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -185,6 +185,7 @@ MYSQL_ERROR::MYSQL_ERROR() m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin), m_message_text(), m_sql_errno(0), + m_handled(0), m_level(MYSQL_ERROR::WARN_LEVEL_ERROR), m_mem_root(NULL) { @@ -212,6 +213,7 @@ void MYSQL_ERROR::clear() m_cursor_name.length(0); m_message_text.length(0); m_sql_errno= 0; + m_handled= 0; m_level= MYSQL_ERROR::WARN_LEVEL_ERROR; } @@ -229,6 +231,7 @@ MYSQL_ERROR::MYSQL_ERROR(MEM_ROOT *mem_root) m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin), m_message_text(), m_sql_errno(0), + m_handled(0), m_level(MYSQL_ERROR::WARN_LEVEL_ERROR), m_mem_root(mem_root) { @@ -267,6 +270,7 @@ MYSQL_ERROR::copy_opt_attributes(const MYSQL_ERROR *cond) copy_string(m_mem_root, & m_table_name, & cond->m_table_name); copy_string(m_mem_root, & m_column_name, & cond->m_column_name); copy_string(m_mem_root, & m_cursor_name, & cond->m_cursor_name); + m_handled= cond->m_handled; } void @@ -367,7 +371,7 @@ Diagnostics_area::set_ok_status(THD *thd, ulonglong affected_rows_arg, m_affected_rows= affected_rows_arg; m_last_insert_id= last_insert_id_arg; if (message_arg) - strmake(m_message, message_arg, sizeof(m_message) - 1); + strmake_buf(m_message, message_arg); else m_message[0]= '\0'; m_status= DA_OK; @@ -435,7 +439,7 @@ Diagnostics_area::set_error_status(THD *thd, uint sql_errno_arg, m_sql_errno= sql_errno_arg; memcpy(m_sqlstate, sqlstate, SQLSTATE_LENGTH); m_sqlstate[SQLSTATE_LENGTH]= '\0'; - strmake(m_message, message_arg, sizeof(m_message)-1); + strmake_buf(m_message, message_arg); m_status= DA_ERROR; DBUG_VOID_RETURN; diff --git a/sql/sql_error.h b/sql/sql_error.h index fadd3b51ec6..ae9ef9f8d47 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -197,6 +197,17 @@ public: ~MYSQL_ERROR() {} + /** check if condition was handled by a condition handler */ + bool handled() const + { + return m_handled; + } + /** mark that condition was handled */ + void mark_handled() + { + m_handled= 1; + } + private: /* The interface of MYSQL_ERROR is mostly private, by design, @@ -310,6 +321,9 @@ private: /** MySQL extension, MYSQL_ERRNO condition item. */ uint m_sql_errno; + /** Marker if error/warning was handled by a continue handler */ + bool m_handled; + /** SQL RETURNED_SQLSTATE condition item. This member is always NUL terminated. diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index d1e5d731183..06efaea8a5b 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -1,5 +1,5 @@ -/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. - Copyright (c) 2011 Monty Program Ab +/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. + Copyright (c) 2011, 2013, 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 @@ -1010,11 +1010,13 @@ static SQL_HANDLER *mysql_ha_find_match(THD *thd, TABLE_LIST *tables) for (tables= first; tables; tables= tables->next_local) { + if (tables->is_anonymous_derived_table()) + continue; if ((! *tables->db || ! my_strcasecmp(&my_charset_latin1, hash_tables->db.str, - tables->db)) && + tables->get_db_name())) && ! my_strcasecmp(&my_charset_latin1, hash_tables->table_name.str, - tables->table_name)) + tables->get_table_name())) { /* Link into hash_tables list */ hash_tables->next= head; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 34b4385ce94..b3d77300576 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1999,8 +1999,7 @@ public: DBUG_ENTER("Delayed_insert constructor"); thd.security_ctx->user=(char*) delayed_user; thd.security_ctx->host=(char*) my_localhost; - strmake(thd.security_ctx->priv_user, thd.security_ctx->user, - USERNAME_LENGTH); + strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user); thd.current_tablenr=0; thd.set_command(COM_DELAYED_INSERT); thd.lex->current_select= 0; // for my_message_sql diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 1ba132b534b..3e53f8e0211 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1423,7 +1423,7 @@ int lex_one_token(void *arg, void *yythd) yylval->lex_str=get_token(lip, 2, // skip x' length-3); // don't count x' and last ' - return (HEX_NUM); + return HEX_STRING; case MY_LEX_BIN_NUMBER: // Found b'bin-string' lip->yySkip(); // Accept opening ' @@ -1950,6 +1950,7 @@ void st_select_lex::init_select() merged_into= 0; m_non_agg_field_used= false; m_agg_func_used= false; + name_visibility_map= 0; } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 9cdc8d7d0b6..58cd6316066 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -831,6 +831,9 @@ public: */ List *prev_join_using; + /* namp of nesting SELECT visibility (for aggregate functions check) */ + nesting_map name_visibility_map; + void init_query(); void init_select(); st_select_lex_unit* master_unit(); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 888aebd52b2..8dc07ee36e8 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1933,7 +1933,8 @@ void log_slow_statement(THD *thd) /* Follow the slow log filter configuration. */ if (!thd->enable_slow_log || - !(thd->variables.log_slow_filter & thd->query_plan_flags)) + (thd->variables.log_slow_filter + && !(thd->variables.log_slow_filter & thd->query_plan_flags))) DBUG_VOID_RETURN; if (((thd->server_status & SERVER_QUERY_WAS_SLOW) || @@ -3275,13 +3276,34 @@ end_with_restore_list: { LEX_MASTER_INFO* lex_mi= &thd->lex->mi; Master_info *mi; + int load_error; + + load_error= rpl_load_gtid_slave_state(thd); + mysql_mutex_lock(&LOCK_active_mi); if ((mi= (master_info_index-> get_master_info(&lex_mi->connection_name, MYSQL_ERROR::WARN_LEVEL_ERROR)))) + { + if (load_error) + { + /* + We cannot start a slave using GTID if we cannot load the GTID position + from the mysql.gtid_slave_pos table. But we can allow non-GTID + replication (useful eg. during upgrade). + */ + if (mi->using_gtid != Master_info::USE_GTID_NO) + { + mysql_mutex_unlock(&LOCK_active_mi); + break; + } + else + thd->clear_error(); + } if (!start_slave(thd, mi, 1 /* net report*/)) my_ok(thd); + } mysql_mutex_unlock(&LOCK_active_mi); break; } diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index b2e2016b47d..5bac6643772 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. +/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -87,7 +87,9 @@ const LEX_STRING partition_keywords[]= { C_STRING_WITH_LEN("KEY") }, { C_STRING_WITH_LEN("MAXVALUE") }, { C_STRING_WITH_LEN("LINEAR ") }, - { C_STRING_WITH_LEN(" COLUMNS") } + { C_STRING_WITH_LEN(" COLUMNS") }, + { C_STRING_WITH_LEN("ALGORITHM") } + }; static const char *part_str= "PARTITION"; static const char *sub_str= "SUB"; @@ -368,7 +370,7 @@ int get_parts_for_update(const uchar *old_data, uchar *new_data, longlong old_func_value; DBUG_ENTER("get_parts_for_update"); - DBUG_ASSERT(new_data == rec0); + DBUG_ASSERT(new_data == rec0); // table->record[0] set_field_ptr(part_field_array, old_data, rec0); error= part_info->get_partition_id(part_info, old_part_id, &old_func_value); @@ -526,12 +528,12 @@ static bool set_up_field_array(TABLE *table, } if (num_fields > MAX_REF_PARTS) { - char *ptr; + char *err_str; if (is_sub_part) - ptr= (char*)"subpartition function"; + err_str= (char*)"subpartition function"; else - ptr= (char*)"partition function"; - my_error(ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0), ptr); + err_str= (char*)"partition function"; + my_error(ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR, MYF(0), err_str); DBUG_RETURN(TRUE); } if (num_fields == 0) @@ -1561,7 +1563,7 @@ bool field_is_partition_charset(Field *field) !(field->type() == MYSQL_TYPE_VARCHAR)) return FALSE; { - CHARSET_INFO *cs= ((Field_str*)field)->charset(); + CHARSET_INFO *cs= field->charset(); if (!(field->type() == MYSQL_TYPE_STRING) || !(cs->state & MY_CS_BINSORT)) return TRUE; @@ -1604,7 +1606,7 @@ bool check_part_func_fields(Field **ptr, bool ok_with_charsets) */ if (field_is_partition_charset(field)) { - CHARSET_INFO *cs= ((Field_str*)field)->charset(); + CHARSET_INFO *cs= field->charset(); if (!ok_with_charsets || cs->mbmaxlen > 1 || cs->strxfrm_multiply > 1) @@ -2088,6 +2090,8 @@ static int check_part_field(enum_field_types sql_type, case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIME2: + case MYSQL_TYPE_DATETIME2: *result_type= STRING_RESULT; *need_cs_check= TRUE; return FALSE; @@ -2100,6 +2104,7 @@ static int check_part_field(enum_field_types sql_type, case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: case MYSQL_TYPE_NULL: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: @@ -2339,6 +2344,58 @@ end: return err; } + +/** + Add 'KEY' word, with optional 'ALGORTIHM = N'. + + @param fptr File to write to. + @param part_info partition_info holding the used key_algorithm + @param current_comment_start NULL, or comment string encapsulating the + PARTITION BY clause. + + @return Operation status. + @retval 0 Success + @retval != 0 Failure +*/ + +static int add_key_with_algorithm(File fptr, partition_info *part_info, + const char *current_comment_start) +{ + int err= 0; + err+= add_part_key_word(fptr, partition_keywords[PKW_KEY].str); + + /* + current_comment_start is given when called from SHOW CREATE TABLE, + Then only add ALGORITHM = 1, not the default 2 or non-set 0! + For .frm current_comment_start is NULL, then add ALGORITHM if != 0. + */ + if (part_info->key_algorithm == partition_info::KEY_ALGORITHM_51 || // SHOW + (!current_comment_start && // .frm + (part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE))) + { + /* If we already are within a comment, end that comment first. */ + if (current_comment_start) + err+= add_string(fptr, "*/ "); + err+= add_string(fptr, "/*!50531 "); + err+= add_part_key_word(fptr, partition_keywords[PKW_ALGORITHM].str); + err+= add_equal(fptr); + err+= add_space(fptr); + err+= add_int(fptr, part_info->key_algorithm); + err+= add_space(fptr); + err+= add_string(fptr, "*/ "); + if (current_comment_start) + { + /* Skip new line. */ + if (current_comment_start[0] == '\n') + current_comment_start++; + err+= add_string(fptr, current_comment_start); + err+= add_space(fptr); + } + } + return err; +} + + /* Generate the partition syntax from the partition data structure. Useful for support of generating defaults, SHOW CREATE TABLES @@ -2383,7 +2440,8 @@ char *generate_partition_syntax(partition_info *part_info, bool use_sql_alloc, bool show_partition_options, HA_CREATE_INFO *create_info, - Alter_info *alter_info) + Alter_info *alter_info, + const char *current_comment_start) { uint i,j, tot_num_parts, num_subparts; partition_element *part_elem; @@ -2417,7 +2475,8 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_string(fptr, partition_keywords[PKW_LINEAR].str); if (part_info->list_of_part_fields) { - err+= add_part_key_word(fptr, partition_keywords[PKW_KEY].str); + err+= add_key_with_algorithm(fptr, part_info, + current_comment_start); err+= add_part_field_list(fptr, part_info->part_field_list); } else @@ -2457,8 +2516,9 @@ char *generate_partition_syntax(partition_info *part_info, err+= add_string(fptr, partition_keywords[PKW_LINEAR].str); if (part_info->list_of_subpart_fields) { - add_part_key_word(fptr, partition_keywords[PKW_KEY].str); - add_part_field_list(fptr, part_info->subpart_field_list); + err+= add_key_with_algorithm(fptr, part_info, + current_comment_start); + err+= add_part_field_list(fptr, part_info->subpart_field_list); } else err+= add_part_key_word(fptr, partition_keywords[PKW_HASH].str); @@ -2667,10 +2727,82 @@ static uint32 calculate_key_value(Field **field_array) { ulong nr1= 1; ulong nr2= 4; + bool use_51_hash; + use_51_hash= test((*field_array)->table->part_info->key_algorithm == + partition_info::KEY_ALGORITHM_51); do { Field *field= *field_array; + if (use_51_hash) + { + switch (field->real_type()) { + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_NEWDATE: + { + if (field->is_null()) + { + nr1^= (nr1 << 1) | 1; + continue; + } + /* Force this to my_hash_sort_bin, which was used in 5.1! */ + uint len= field->pack_length(); + my_charset_bin.coll->hash_sort(&my_charset_bin, field->ptr, len, + &nr1, &nr2); + /* Done with this field, continue with next one. */ + continue; + } + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_BIT: + /* Not affected, same in 5.1 and 5.5 */ + break; + /* + ENUM/SET uses my_hash_sort_simple in 5.1 (i.e. my_charset_latin1) + and my_hash_sort_bin in 5.5! + */ + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_SET: + { + if (field->is_null()) + { + nr1^= (nr1 << 1) | 1; + continue; + } + /* Force this to my_hash_sort_bin, which was used in 5.1! */ + uint len= field->pack_length(); + my_charset_latin1.coll->hash_sort(&my_charset_latin1, field->ptr, + len, &nr1, &nr2); + continue; + } + /* These types should not be allowed for partitioning! */ + case MYSQL_TYPE_NULL: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_GEOMETRY: + /* fall through. */ + default: + DBUG_ASSERT(0); // New type? + /* Fall through for default hashing (5.5). */ + } + /* fall through, use collation based hashing. */ + } field->hash(&nr1, &nr2); } while (*(++field_array)); return (uint32) nr1; @@ -2845,7 +2977,7 @@ static void copy_to_part_field_buffers(Field **ptr, restore_ptr++; if (!field->maybe_null() || !field->is_null()) { - CHARSET_INFO *cs= ((Field_str*)field)->charset(); + CHARSET_INFO *cs= field->charset(); uint max_len= field->pack_length(); uint data_len= field->data_length(); uchar *field_buf= *field_bufs; @@ -5411,14 +5543,25 @@ the generated partition syntax in a correct manner. Need to cater for engine types that can handle partition without using the partition handler. */ - if (thd->work_part_info != table->part_info) + if (part_info != table->part_info) { - DBUG_PRINT("info", ("partition changed")); - *partition_changed= TRUE; - if (thd->work_part_info->fix_parser_data(thd)) + if (part_info->fix_parser_data(thd)) { goto err; } + /* + Compare the old and new part_info. If only key_algorithm + change is done, don't consider it as changed partitioning (to avoid + rebuild). This is to handle KEY (numeric_cols) partitioned tables + created in 5.1. For more info, see bug#14521864. + */ + if (alter_info->flags != ALTER_PARTITION || + !table->part_info || + !table->part_info->has_same_partitioning(part_info)) + { + DBUG_PRINT("info", ("partition changed")); + *partition_changed= true; + } } /* Set up partition default_engine_type either from the create_info @@ -6970,7 +7113,8 @@ void set_key_field_ptr(KEY *key_info, const uchar *new_buf, void mem_alloc_error(size_t size) { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast(size)); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast(size)); } #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -7057,12 +7201,12 @@ void make_used_partitions_str(partition_info *part_info, String *parts_str) definition) IMPLEMENTATION - There are two available interval analyzer functions: - (1) get_part_iter_for_interval_via_mapping + There are three available interval analyzer functions: + (1) get_part_iter_for_interval_via_mapping (2) get_part_iter_for_interval_cols_via_map (3) get_part_iter_for_interval_via_walking - They both have limited applicability: + They all have limited applicability: (1) is applicable for "PARTITION BY (func(t.field))", where func is a monotonic function. @@ -7435,6 +7579,9 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, get_endpoint_func UNINIT_VAR(get_endpoint); bool can_match_multiple_values; /* is not '=' */ uint field_len= field->pack_length_in_rec(); + MYSQL_TIME start_date; + bool check_zero_dates= false; + bool zero_in_start_date= true; DBUG_ENTER("get_part_iter_for_interval_via_mapping"); DBUG_ASSERT(!is_subpart); (void) store_length_array; @@ -7491,6 +7638,7 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, { /* col is NOT NULL, but F(col) can return NULL, add NULL partition */ part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE; + check_zero_dates= true; } } @@ -7534,6 +7682,19 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, DBUG_RETURN(1); } part_iter->part_nums.cur= part_iter->part_nums.start; + if (check_zero_dates && !part_info->part_expr->null_value) + { + if (!(flags & NO_MAX_RANGE) && + (field->type() == MYSQL_TYPE_DATE || + field->type() == MYSQL_TYPE_DATETIME)) + { + /* Monotonic, but return NULL for dates with zeros in month/day. */ + zero_in_start_date= field->get_date(&start_date, 0); + DBUG_PRINT("info", ("zero start %u %04d-%02d-%02d", + zero_in_start_date, start_date.year, + start_date.month, start_date.day)); + } + } if (part_iter->part_nums.start == max_endpoint_val) DBUG_RETURN(0); /* No partitions */ } @@ -7547,6 +7708,29 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info, store_key_image_to_rec(field, max_value, field_len); bool include_endp= !test(flags & NEAR_MAX); part_iter->part_nums.end= get_endpoint(part_info, 0, include_endp); + if (check_zero_dates && + !zero_in_start_date && + !part_info->part_expr->null_value) + { + MYSQL_TIME end_date; + bool zero_in_end_date= field->get_date(&end_date, 0); + /* + This is an optimization for TO_DAYS()/TO_SECONDS() to avoid scanning + the NULL partition for ranges that cannot include a date with 0 as + month/day. + */ + DBUG_PRINT("info", ("zero end %u %04d-%02d-%02d", + zero_in_end_date, + end_date.year, end_date.month, end_date.day)); + DBUG_ASSERT(!memcmp(((Item_func*) part_info->part_expr)->func_name(), + "to_days", 7) || + !memcmp(((Item_func*) part_info->part_expr)->func_name(), + "to_seconds", 10)); + if (!zero_in_end_date && + start_date.month == end_date.month && + start_date.year == end_date.year) + part_iter->ret_null_part= part_iter->ret_null_part_orig= false; + } if (part_iter->part_nums.start >= part_iter->part_nums.end && !part_iter->ret_null_part) DBUG_RETURN(0); /* No partitions */ diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 8db07f836b0..cf532c45c66 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -1,8 +1,7 @@ #ifndef SQL_PARTITION_INCLUDED #define SQL_PARTITION_INCLUDED -/* - Copyright (c) 2006, 2010, Oracle and/or its affiliates. +/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. 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 @@ -267,7 +266,8 @@ char *generate_partition_syntax(partition_info *part_info, uint *buf_length, bool use_sql_alloc, bool show_partition_options, HA_CREATE_INFO *create_info, - Alter_info *alter_info); + Alter_info *alter_info, + const char *current_comment_start); bool partition_key_modified(TABLE *table, const MY_BITMAP *fields); #else #define partition_key_modified(X,Y) 0 diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index 4edd47de855..b9bf3dbc217 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -141,7 +141,9 @@ bool Alter_table_truncate_partition_statement::execute(THD *thd) TODO: Add support for TRUNCATE PARTITION for NDB and other engines supporting native partitioning. */ - if (first_table->table->s->db_type() != partition_hton) + + if (!first_table->table || first_table->view || + first_table->table->s->db_type() != partition_hton) { my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); DBUG_RETURN(TRUE); diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index c0a547c46d8..51a0e58d8ab 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -15,9 +15,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "sql_plugin.h" #include "sql_priv.h" // SHOW_MY_BOOL #include "unireg.h" -#include "my_global.h" // REQUIRED by m_string.h #include "sql_class.h" // set_var.h: THD #include "sys_vars_shared.h" #include "sql_locale.h" diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 906ff20ddb7..5327b27e97c 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -17,7 +17,6 @@ #ifndef _sql_plugin_h #define _sql_plugin_h -#include /* the following #define adds server-only members to enum_mysql_show_type, @@ -27,7 +26,7 @@ SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \ SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING -#include +#include #undef SHOW_always_last #include "m_string.h" /* LEX_STRING */ diff --git a/sql/sql_plugin_compat.h b/sql/sql_plugin_compat.h index 8c6014f8dc6..5c7bb620575 100644 --- a/sql/sql_plugin_compat.h +++ b/sql/sql_plugin_compat.h @@ -16,9 +16,9 @@ /* old plugin api structures, used for backward compatibility */ #define upgrade_var(X) latest->X= X -#define upgrade_str(X) strmake(latest->X, X, sizeof(X)) +#define upgrade_str(X) strmake_buf(latest->X, X) #define downgrade_var(X) X= latest->X -#define downgrade_str(X) strmake(X, latest->X, sizeof(X)-1) +#define downgrade_str(X) strmake_buf(X, latest->X) /**************************************************************/ /* Authentication API, version 0x0100 *************************/ diff --git a/sql/sql_plugin_services.h b/sql/sql_plugin_services.h index d2f60a6e08c..838b994b6e8 100644 --- a/sql/sql_plugin_services.h +++ b/sql/sql_plugin_services.h @@ -54,6 +54,11 @@ static struct kill_statement_service_st thd_kill_statement_handler= { thd_kill_level }; +static struct thd_timezone_service_st thd_timezone_handler= { + thd_TIME_to_gmt_sec, + thd_gmt_sec_to_TIME +}; + static struct st_service_ref list_of_services[]= { { "my_snprintf_service", VERSION_my_snprintf, &my_snprintf_handler }, @@ -61,6 +66,7 @@ static struct st_service_ref list_of_services[]= { "thd_wait_service", VERSION_thd_wait, &thd_wait_handler }, { "progress_report_service", VERSION_progress_report, &progress_report_handler }, { "debug_sync_service", VERSION_debug_sync, 0 }, // updated in plugin_init() - { "thd_kill_statement_service", VERSION_kill_statement, &thd_kill_statement_handler } + { "thd_kill_statement_service", VERSION_kill_statement, &thd_kill_statement_handler }, + { "thd_timezone_service", VERSION_thd_timezone, &thd_timezone_handler }, }; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7ccc6aaad39..001526b5b3b 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -879,7 +879,7 @@ static bool insert_params_with_log(Prepared_statement *stmt, uchar *null_array, if (param->state == Item_param::NO_VALUE) DBUG_RETURN(1); - if (param->limit_clause_param && param->item_type != Item::INT_ITEM) + if (param->limit_clause_param) { param->set_int(param->val_int(), MY_INT64_NUM_DECIMAL_DIGITS); param->item_type= Item::INT_ITEM; @@ -1503,7 +1503,8 @@ static int mysql_test_select(Prepared_statement *stmt, if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) { - my_error(ER_OUTOFMEMORY, MYF(0), static_cast(sizeof(select_send))); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), + static_cast(sizeof(select_send))); goto error; } @@ -1877,7 +1878,7 @@ static bool mysql_test_multidelete(Prepared_statement *stmt, stmt->thd->lex->current_select= &stmt->thd->lex->select_lex; if (add_item_to_list(stmt->thd, new Item_null())) { - my_error(ER_OUTOFMEMORY, MYF(0), 0); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), 0); goto error; } @@ -3885,7 +3886,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) alloc_query(thd, (char*) expanded_query->ptr(), expanded_query->length())) { - my_error(ER_OUTOFMEMORY, 0, expanded_query->length()); + my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), expanded_query->length()); goto error; } /* @@ -4426,7 +4427,7 @@ bool Protocol_local::store(const char *str, size_t length, bool Protocol_local::store(MYSQL_TIME *time, int decimals) { if (decimals != AUTO_SEC_PART_DIGITS) - time->second_part= sec_part_truncate(time->second_part, decimals); + my_time_trunc(time, decimals); return store_column(time, sizeof(MYSQL_TIME)); } @@ -4444,7 +4445,7 @@ bool Protocol_local::store_date(MYSQL_TIME *time) bool Protocol_local::store_time(MYSQL_TIME *time, int decimals) { if (decimals != AUTO_SEC_PART_DIGITS) - time->second_part= sec_part_truncate(time->second_part, decimals); + my_time_trunc(time, decimals); return store_column(time, sizeof(MYSQL_TIME)); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 9e3da1ce641..0d6c97842d4 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2008, 2013, Monty Program Ab This program is free software; you can redistribute it and/or modify @@ -50,7 +50,7 @@ extern TYPELIB binlog_checksum_typelib; static int fake_event_header(String* packet, Log_event_type event_type, ulong extra_len, my_bool *do_checksum, ha_checksum *crc, const char** errmsg, - uint8 checksum_alg_arg) + uint8 checksum_alg_arg, uint32 end_pos) { char header[LOG_EVENT_HEADER_LEN]; ulong event_len; @@ -70,7 +70,7 @@ fake_event_header(String* packet, Log_event_type event_type, ulong extra_len, int4store(header + EVENT_LEN_OFFSET, event_len); int2store(header + FLAGS_OFFSET, LOG_EVENT_ARTIFICIAL_F); // TODO: check what problems this may cause and fix them - int4store(header + LOG_POS_OFFSET, 0); + int4store(header + LOG_POS_OFFSET, end_pos); if (packet->append(header, sizeof(header))) { *errmsg= "Failed due to out-of-memory writing event"; @@ -146,7 +146,7 @@ static int fake_rotate_event(NET* net, String* packet, char* log_file_name, if ((err= fake_event_header(packet, ROTATE_EVENT, ident_len + ROTATE_HEADER_LEN, &do_checksum, &crc, - errmsg, checksum_alg_arg))) + errmsg, checksum_alg_arg, 0))) DBUG_RETURN(err); int8store(buf+R_POS_OFFSET,position); @@ -169,7 +169,7 @@ static int fake_rotate_event(NET* net, String* packet, char* log_file_name, static int fake_gtid_list_event(NET* net, String* packet, Gtid_list_log_event *glev, const char** errmsg, - uint8 checksum_alg_arg) + uint8 checksum_alg_arg, uint32 current_pos) { my_bool do_checksum; int err; @@ -185,7 +185,7 @@ static int fake_gtid_list_event(NET* net, String* packet, } if ((err= fake_event_header(packet, GTID_LIST_EVENT, str.length(), &do_checksum, &crc, - errmsg, checksum_alg_arg))) + errmsg, checksum_alg_arg, current_pos))) return err; packet->append(str); @@ -901,8 +901,6 @@ check_slave_start_position(THD *thd, slave_connection_state *st, rpl_gtid **delete_list= NULL; uint32 delete_idx= 0; bool slave_state_loaded= false; - uint32 missing_domains= 0; - rpl_gtid missing_domain_gtid; for (i= 0; i < st->hash.records; ++i) { @@ -943,14 +941,7 @@ check_slave_start_position(THD *thd, slave_connection_state *st, We do not have anything in this domain, neither in the binlog nor in the slave state. So we are probably one master in a multi-master setup, and this domain is served by a different master. - - This is not an error, however if we are missing _all_ domains - requested by the slave, then we still give error (below, after - the loop). */ - if (!missing_domains) - missing_domain_gtid= *slave_gtid; - ++missing_domains; continue; } @@ -1043,14 +1034,6 @@ check_slave_start_position(THD *thd, slave_connection_state *st, } } - if (missing_domains == st->hash.records && missing_domains > 0) - { - *errormsg= "Requested slave GTID state not found in binlog"; - *error_gtid= missing_domain_gtid; - err= ER_GTID_POSITION_NOT_FOUND_IN_BINLOG; - goto end; - } - /* Do any delayed deletes from the hash. */ if (delete_list) { @@ -1423,7 +1406,7 @@ is_until_reached(THD *thd, NET *net, String *packet, ulong *ev_offset, enum_gtid_until_state gtid_until_group, Log_event_type event_type, uint8 current_checksum_alg, ushort flags, const char **errmsg, - rpl_binlog_state *until_binlog_state) + rpl_binlog_state *until_binlog_state, uint32 current_pos) { switch (gtid_until_group) { @@ -1454,7 +1437,8 @@ is_until_reached(THD *thd, NET *net, String *packet, ulong *ev_offset, return true; Gtid_list_log_event glev(until_binlog_state, Gtid_list_log_event::FLAG_UNTIL_REACHED); - if (fake_gtid_list_event(net, packet, &glev, errmsg, current_checksum_alg)) + if (fake_gtid_list_event(net, packet, &glev, errmsg, current_checksum_alg, + current_pos)) return true; *errmsg= NULL; return true; @@ -1525,6 +1509,19 @@ send_event_to_slave(THD *thd, NET *net, String* const packet, ushort flags, return "Failed to read Gtid_log_event: corrupt binlog"; } + DBUG_EXECUTE_IF("gtid_force_reconnect_at_10_1_100", + { + rpl_gtid *dbug_gtid; + if ((dbug_gtid= until_binlog_state->find(10,1)) && + dbug_gtid->seq_no == 100) + { + DBUG_SET("-d,gtid_force_reconnect_at_10_1_100"); + DBUG_SET_INITIAL("-d,gtid_force_reconnect_at_10_1_100"); + my_errno= ER_UNKNOWN_ERROR; + return "DBUG-injected forced reconnect"; + } + }); + if (until_binlog_state->update(&event_gtid, false)) { my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG; @@ -1544,19 +1541,31 @@ send_event_to_slave(THD *thd, NET *net, String* const packet, ushort flags, if (event_gtid.server_id == gtid->server_id && event_gtid.seq_no >= gtid->seq_no) { - /* - In strict mode, it is an error if the slave requests to start in - a "hole" in the master's binlog: a GTID that does not exist, even - though both the prior and subsequent seq_no exists for same - domain_id and server_id. - */ - if (slave_gtid_strict_mode && event_gtid.seq_no > gtid->seq_no) + if (event_gtid.seq_no > gtid->seq_no) { - my_errno= ER_GTID_START_FROM_BINLOG_HOLE; - *error_gtid= *gtid; - return "The binlog on the master is missing the GTID requested " - "by the slave (even though both a prior and a subsequent " - "sequence number does exist), and GTID strict mode is enabled."; + /* + In strict mode, it is an error if the slave requests to start + in a "hole" in the master's binlog: a GTID that does not + exist, even though both the prior and subsequent seq_no exists + for same domain_id and server_id. + */ + if (slave_gtid_strict_mode) + { + my_errno= ER_GTID_START_FROM_BINLOG_HOLE; + *error_gtid= *gtid; + return "The binlog on the master is missing the GTID requested " + "by the slave (even though both a prior and a subsequent " + "sequence number does exist), and GTID strict mode is enabled."; + } + } + else + { + /* + Send a fake Gtid_list event to the slave. + This allows the slave to update its current binlog position + so MASTER_POS_WAIT() and MASTER_GTID_WAIT() can work. + */ +// send_fake_gtid_list_event(until_binlog_state); } /* Delete this entry if we have reached slave start position (so we @@ -1812,8 +1821,10 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, uint8 current_checksum_alg= BINLOG_CHECKSUM_ALG_UNDEF; int old_max_allowed_packet= thd->variables.max_allowed_packet; + #ifndef DBUG_OFF int left_events = max_binlog_dump_events; + uint dbug_reconnect_counter= 0; #endif DBUG_ENTER("mysql_binlog_send"); DBUG_PRINT("enter",("log_ident: '%s' pos: %ld", log_ident, (long) pos)); @@ -1847,6 +1858,13 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, until_gtid_state= &until_gtid_state_obj; } + DBUG_EXECUTE_IF("binlog_force_reconnect_after_22_events", + { + DBUG_SET("-d,binlog_force_reconnect_after_22_events"); + DBUG_SET_INITIAL("-d,binlog_force_reconnect_after_22_events"); + dbug_reconnect_counter= 22; + }); + /* We want to corrupt the first event, in Log_event::read_log_event(). But we do not want the corruption to happen early, eg. when client does @@ -2130,9 +2148,12 @@ impossible position"; if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg)) goto err; + bool is_active_binlog= false; while (!(killed= thd->killed) && !(error = Log_event::read_log_event(&log, packet, log_lock, - current_checksum_alg))) + current_checksum_alg, + log_file_name, + &is_active_binlog))) { #ifndef DBUG_OFF if (max_binlog_dump_events && !left_events--) @@ -2193,6 +2214,19 @@ impossible position"; (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F; } +#ifndef DBUG_OFF + if (dbug_reconnect_counter > 0) + { + --dbug_reconnect_counter; + if (dbug_reconnect_counter == 0) + { + errmsg= "DBUG-injected forced reconnect"; + my_errno= ER_UNKNOWN_ERROR; + goto err; + } + } +#endif + if ((tmp_msg= send_event_to_slave(thd, net, packet, flags, event_type, log_file_name, &log, mariadb_slave_capability, ev_offset, @@ -2208,7 +2242,7 @@ impossible position"; if (until_gtid_state && is_until_reached(thd, net, packet, &ev_offset, gtid_until_group, event_type, current_checksum_alg, flags, &errmsg, - &until_binlog_state)) + &until_binlog_state, my_b_tell(&log))) { if (errmsg) { @@ -2233,6 +2267,13 @@ impossible position"; if (killed) goto end; + DBUG_EXECUTE_IF("wait_after_binlog_EOF", + { + const char act[]= "now wait_for signal.rotate_finished"; + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); + /* TODO: now that we are logging the offset, check to make sure the recorded offset and the actual match. @@ -2243,8 +2284,11 @@ impossible position"; if (test_for_non_eof_log_read_errors(error, &errmsg)) goto err; - if (!(flags & BINLOG_DUMP_NON_BLOCK) && - mysql_bin_log.is_active(log_file_name)) + /* + We should only move to the next binlog when the last read event + came from a already deactivated binlog. + */ + if (!(flags & BINLOG_DUMP_NON_BLOCK) && is_active_binlog) { /* Block until there is more data in the log @@ -2298,7 +2342,8 @@ impossible position"; mysql_mutex_unlock(log_lock); read_packet = 1; p_coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET); - event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]); + event_type= + (Log_event_type)((uchar)(*packet)[LOG_EVENT_OFFSET+ev_offset]); break; case LOG_READ_EOF: @@ -2390,7 +2435,7 @@ impossible position"; until_gtid_state && is_until_reached(thd, net, packet, &ev_offset, gtid_until_group, event_type, current_checksum_alg, flags, &errmsg, - &until_binlog_state)) + &until_binlog_state, my_b_tell(&log))) { if (errmsg) { @@ -2628,8 +2673,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) We don't check thd->lex->mi.log_file_name for NULL here since it is checked in sql_yacc.yy */ - strmake(mi->rli.until_log_name, thd->lex->mi.log_file_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.log_file_name); } else if (thd->lex->mi.relay_log_pos) { @@ -2637,8 +2681,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) slave_errno=ER_BAD_SLAVE_UNTIL_COND; mi->rli.until_condition= Relay_log_info::UNTIL_RELAY_POS; mi->rli.until_log_pos= thd->lex->mi.relay_log_pos; - strmake(mi->rli.until_log_name, thd->lex->mi.relay_log_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.relay_log_name); } else if (thd->lex->mi.gtid_pos_str.str) { @@ -2945,14 +2988,15 @@ void kill_zombie_dump_threads(uint32 slave_server_id) */ static bool get_string_parameter(char *to, const char *from, size_t length, - const char *name) + const char *name, CHARSET_INFO *cs) { if (from) // Empty paramaters allowed { - size_t from_length; - if ((from_length= strlen(from)) > length) + size_t from_length= strlen(from); + uint from_numchars= cs->cset->numchars(cs, from, from + from_length); + if (from_numchars > length / cs->mbmaxlen) { - my_error(ER_WRONG_STRING_LENGTH, MYF(0), from, name, (int) length); + my_error(ER_WRONG_STRING_LENGTH, MYF(0), from, name, length / cs->mbmaxlen); return 1; } memcpy(to, from, from_length+1); @@ -2986,6 +3030,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) char saved_host[HOSTNAME_LENGTH + 1]; uint saved_port; char saved_log_name[FN_REFLEN]; + Master_info::enum_using_gtid saved_using_gtid; char master_info_file_tmp[FN_REFLEN]; char relay_log_info_file_tmp[FN_REFLEN]; my_off_t saved_log_pos; @@ -3071,10 +3116,11 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) /* Before processing the command, save the previous state. */ - strmake(saved_host, mi->host, HOSTNAME_LENGTH); + strmake_buf(saved_host, mi->host); saved_port= mi->port; - strmake(saved_log_name, mi->master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, mi->master_log_name); saved_log_pos= mi->master_log_pos; + saved_using_gtid= mi->using_gtid; /* If the user specified host or port without binlog or position, @@ -3088,8 +3134,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) } if (lex_mi->log_file_name) - strmake(mi->master_log_name, lex_mi->log_file_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, lex_mi->log_file_name); if (lex_mi->pos) { mi->master_log_pos= lex_mi->pos; @@ -3097,11 +3142,12 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); if (get_string_parameter(mi->host, lex_mi->host, sizeof(mi->host)-1, - "MASTER_HOST") || + "MASTER_HOST", system_charset_info) || get_string_parameter(mi->user, lex_mi->user, sizeof(mi->user)-1, - "MASTER_USER") || + "MASTER_USER", system_charset_info) || get_string_parameter(mi->password, lex_mi->password, - sizeof(mi->password)-1, "MASTER_PASSWORD")) + sizeof(mi->password)-1, "MASTER_PASSWORD", + &my_charset_bin)) { ret= TRUE; goto err; @@ -3153,19 +3199,19 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE); if (lex_mi->ssl_ca) - strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1); + strmake_buf(mi->ssl_ca, lex_mi->ssl_ca); if (lex_mi->ssl_capath) - strmake(mi->ssl_capath, lex_mi->ssl_capath, sizeof(mi->ssl_capath)-1); + strmake_buf(mi->ssl_capath, lex_mi->ssl_capath); if (lex_mi->ssl_cert) - strmake(mi->ssl_cert, lex_mi->ssl_cert, sizeof(mi->ssl_cert)-1); + strmake_buf(mi->ssl_cert, lex_mi->ssl_cert); if (lex_mi->ssl_cipher) - strmake(mi->ssl_cipher, lex_mi->ssl_cipher, sizeof(mi->ssl_cipher)-1); + strmake_buf(mi->ssl_cipher, lex_mi->ssl_cipher); if (lex_mi->ssl_key) - strmake(mi->ssl_key, lex_mi->ssl_key, sizeof(mi->ssl_key)-1); + strmake_buf(mi->ssl_key, lex_mi->ssl_key); if (lex_mi->ssl_crl) - strmake(mi->ssl_crl, lex_mi->ssl_crl, sizeof(mi->ssl_crl)-1); + strmake_buf(mi->ssl_crl, lex_mi->ssl_crl); if (lex_mi->ssl_crlpath) - strmake(mi->ssl_crlpath, lex_mi->ssl_crlpath, sizeof(mi->ssl_crlpath)-1); + strmake_buf(mi->ssl_crlpath, lex_mi->ssl_crlpath); #ifndef HAVE_OPENSSL if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath || @@ -3180,10 +3226,8 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) need_relay_log_purge= 0; char relay_log_name[FN_REFLEN]; mi->rli.relay_log.make_log_name(relay_log_name, lex_mi->relay_log_name); - strmake(mi->rli.group_relay_log_name, relay_log_name, - sizeof(mi->rli.group_relay_log_name)-1); - strmake(mi->rli.event_relay_log_name, relay_log_name, - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(mi->rli.group_relay_log_name, relay_log_name); + strmake_buf(mi->rli.event_relay_log_name, relay_log_name); } if (lex_mi->relay_log_pos) @@ -3228,8 +3272,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) */ mi->master_log_pos = max(BIN_LOG_HEADER_SIZE, mi->rli.group_master_log_pos); - strmake(mi->master_log_name, mi->rli.group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, mi->rli.group_master_log_name); } /* @@ -3293,8 +3336,7 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) */ mi->rli.group_master_log_pos= mi->master_log_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - strmake(mi->rli.group_master_log_name,mi->master_log_name, - sizeof(mi->rli.group_master_log_name)-1); + strmake_buf(mi->rli.group_master_log_name,mi->master_log_name); if (!mi->rli.group_master_log_name[0]) // uninitialized case mi->rli.group_master_log_pos=0; @@ -3312,6 +3354,11 @@ bool change_master(THD* thd, Master_info* mi, bool *master_info_added) "master_log_pos='%ld'.", saved_host, saved_port, saved_log_name, (ulong) saved_log_pos, mi->host, mi->port, mi->master_log_name, (ulong) mi->master_log_pos); + if (saved_using_gtid != Master_info::USE_GTID_NO || + mi->using_gtid != Master_info::USE_GTID_NO) + sql_print_information("Previous Using_Gtid=%s. New Using_Gtid=%s", + mi->using_gtid_astext(saved_using_gtid), + mi->using_gtid_astext(mi->using_gtid)); /* If we don't write new coordinates to disk now, then old will remain in @@ -3773,11 +3820,11 @@ rpl_deinit_gtid_slave_state() /* - Format the current GTID state as a string, for use when connecting to a - master server with GTID, or for returning the value of @@global.gtid_state. + Format the current GTID state as a string, for returning the value of + @@global.gtid_slave_pos. If the flag use_binlog is true, then the contents of the binary log (if - enabled) is merged into the current GTID state. + enabled) is merged into the current GTID state (@@global.gtid_current_pos). */ int rpl_append_gtid_state(String *dest, bool use_binlog) @@ -3790,10 +3837,35 @@ rpl_append_gtid_state(String *dest, bool use_binlog) (err= mysql_bin_log.get_most_recent_gtid_list(>id_list, &num_gtids))) return err; - rpl_global_gtid_slave_state.tostring(dest, gtid_list, num_gtids); + err= rpl_global_gtid_slave_state.tostring(dest, gtid_list, num_gtids); my_free(gtid_list); - return 0; + return err; +} + + +/* + Load the current GITD position into a slave_connection_state, for use when + connecting to a master server with GTID. + + If the flag use_binlog is true, then the contents of the binary log (if + enabled) is merged into the current GTID state (master_use_gtid=current_pos). +*/ +int +rpl_load_gtid_state(slave_connection_state *state, bool use_binlog) +{ + int err; + rpl_gtid *gtid_list= NULL; + uint32 num_gtids= 0; + + if (use_binlog && opt_bin_log && + (err= mysql_bin_log.get_most_recent_gtid_list(>id_list, &num_gtids))) + return err; + + err= state->load(&rpl_global_gtid_slave_state, gtid_list, num_gtids); + my_free(gtid_list); + + return err; } diff --git a/sql/sql_repl.h b/sql/sql_repl.h index 820ffed0928..917da9b598e 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -32,6 +32,8 @@ typedef struct st_slave_info THD* thd; } SLAVE_INFO; +struct slave_connection_state; + extern my_bool opt_show_slave_auth_info; extern char *master_host, *master_info_file; extern bool server_id_supplied; @@ -70,6 +72,7 @@ void rpl_init_gtid_slave_state(); void rpl_deinit_gtid_slave_state(); int gtid_state_from_binlog_pos(const char *name, uint32 pos, String *out_str); int rpl_append_gtid_state(String *dest, bool use_binlog); +int rpl_load_gtid_state(slave_connection_state *state, bool use_binlog); bool rpl_gtid_pos_check(THD *thd, char *str, size_t len); bool rpl_gtid_pos_update(THD *thd, char *str, size_t len); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c19c7aa95a7..737f568fd62 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2495,7 +2495,12 @@ void JOIN::exec_inner() List *curr_all_fields= &all_fields; List *curr_fields_list= &fields_list; TABLE *curr_tmp_table= 0; - bool tmp_having_used_tables_updated= FALSE; + /* + curr_join->join_free() will call JOIN::cleanup(full=TRUE). It will not + be safe to call update_used_tables() after that. + */ + if (curr_join->tmp_having) + curr_join->tmp_having->update_used_tables(); /* Initialize examined rows here because the values from all join parts @@ -2751,16 +2756,6 @@ void JOIN::exec_inner() curr_join->select_distinct=0; /* Each row is unique */ - /* - curr_join->join_free() will call JOIN::cleanup(full=TRUE). It will not - be safe to call update_used_tables() after that. - */ - if (curr_join->tmp_having) - { - curr_join->tmp_having->update_used_tables(); - tmp_having_used_tables_updated= TRUE; - } - curr_join->join_free(); /* Free quick selects */ if (curr_join->select_distinct && ! curr_join->group_list) @@ -2841,9 +2836,6 @@ void JOIN::exec_inner() if (curr_join->tmp_having && ! curr_join->group_list && ! curr_join->sort_and_group) { - // Some tables may have been const - if (!tmp_having_used_tables_updated) - curr_join->tmp_having->update_used_tables(); JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables]; table_map used_tables= (curr_join->const_table_map | curr_table->table->map); @@ -3692,9 +3684,16 @@ make_join_statistics(JOIN *join, List &tables_list, !table->fulltext_searched && (!embedding || (embedding->sj_on_expr && !embedding->embedding))) { + key_map base_part, base_const_ref, base_eq_part; + base_part.set_prefix(keyinfo->key_parts); + base_const_ref= const_ref; + base_const_ref.intersect(base_part); + base_eq_part= eq_part; + base_eq_part.intersect(base_part); if (table->actual_key_flags(keyinfo) & HA_NOSAME) { - if (const_ref == eq_part && + + if (base_const_ref == base_eq_part && !has_expensive_keyparts && !((outer_join & table->map) && (*s->on_expr_ref)->is_expensive())) @@ -3720,7 +3719,7 @@ make_join_statistics(JOIN *join, List &tables_list, else found_ref|= refs; // Table is const if all refs are const } - else if (const_ref == eq_part) + else if (base_const_ref == base_eq_part) s->const_keys.set_bit(key); } } @@ -4308,7 +4307,7 @@ add_key_field(JOIN *join, { if ((*value)->cmp_type() != STRING_RESULT) return; - if (((Field_str*)field)->charset() != cond->compare_collation()) + if (field->charset() != cond->compare_collation()) return; } } @@ -11414,7 +11413,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, *simple_order=0; // Must do a temp table to sort else if (!(order_tables & not_const_tables)) { - if (order->item[0]->with_subselect) + if (order->item[0]->has_subquery()) { /* Delay the evaluation of constant ORDER and/or GROUP expressions that @@ -11858,7 +11857,7 @@ static bool check_simple_equality(Item *left_item, Item *right_item, if (field_item->cmp_type() == STRING_RESULT) { - CHARSET_INFO *cs= ((Field_str*) field_item->field)->charset(); + CHARSET_INFO *cs= field_item->field->charset(); if (!item) { Item_func_eq *eq_item; @@ -13734,13 +13733,13 @@ static void restore_prev_nj_state(JOIN_TAB *last) bool was_fully_covered= nest->is_fully_covered(); + join->cur_embedding_map|= nest->nj_map; + if (--nest->counter == 0) join->cur_embedding_map&= ~nest->nj_map; if (!was_fully_covered) break; - - join->cur_embedding_map|= nest->nj_map; } } } @@ -13960,7 +13959,27 @@ internal_remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) if (new_item_and_list->is_empty()) li.remove(); else + { + Item *list_item; + Item *new_list_item; + uint cnt= new_item_and_list->elements; + List_iterator it(*new_item_and_list); + while ((list_item= it++)) + { + uchar* is_subst_valid= (uchar *) Item::ANY_SUBST; + new_list_item= + list_item->compile(&Item::subst_argument_checker, + &is_subst_valid, + &Item::equal_fields_propagator, + (uchar *) &cond_and->cond_equal); + if (new_list_item != list_item) + it.replace(new_list_item); + new_list_item->update_used_tables(); + } li.replace(*new_item_and_list); + for (cnt--; cnt; cnt--) + item= li++; + } cond_and_list->concat((List*) cond_equal_items); } else if (new_item->type() == Item::FUNC_ITEM && @@ -13980,7 +13999,13 @@ internal_remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) if (new_item->type() == Item::COND_ITEM && ((Item_cond*) new_item)->functype() == ((Item_cond*) cond)->functype()) - li.replace(*((Item_cond*) new_item)->argument_list()); + { + List *arg_list= ((Item_cond*) new_item)->argument_list(); + uint cnt= arg_list->elements; + li.replace(*arg_list); + for ( cnt--; cnt; cnt--) + item= li++; + } else li.replace(new_item); } @@ -14671,6 +14696,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, case Item::REAL_ITEM: case Item::DECIMAL_ITEM: case Item::STRING_ITEM: + case Item::DATE_ITEM: case Item::REF_ITEM: case Item::NULL_ITEM: case Item::VARBIN_ITEM: @@ -19326,7 +19352,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, !(table->file->index_flags(best_key, 0, 1) & HA_CLUSTERED_INDEX))) goto use_filesort; - if (table->quick_keys.is_set(best_key) && best_key != ref_key) + if (select && + table->quick_keys.is_set(best_key) && best_key != ref_key) { key_map map; map.clear_all(); // Force the creation of quick select @@ -19904,7 +19931,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, } if (copy_blobs(first_field)) { - my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0)); + my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(ME_FATALERROR)); error=0; goto err; } @@ -19937,7 +19964,8 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, if (!found) break; // End of file /* Restart search on saved row */ - error=file->restart_rnd_next(record); + if ((error= file->restart_rnd_next(record))) + goto err; } file->extra(HA_EXTRA_NO_CACHE); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index feba387d3b4..e6f0be69bc6 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2009, 2013, Monty Program Ab This program is free software; you can redistribute it and/or modify @@ -17,7 +17,7 @@ /* Function with list databases, tables or fields */ -#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_plugin.h" #include "sql_priv.h" #include "unireg.h" #include "sql_acl.h" // fill_schema_*_privileges @@ -1561,6 +1561,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, MODE_MYSQL323 | MODE_MYSQL40)) != 0; my_bitmap_map *old_map; + int error= 0; DBUG_ENTER("store_create_info"); DBUG_PRINT("enter",("table: %s", table->s->table_name.str)); @@ -1924,28 +1925,35 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, } #ifdef WITH_PARTITION_STORAGE_ENGINE { - /* - Partition syntax for CREATE TABLE is at the end of the syntax. - */ - uint part_syntax_len; - char *part_syntax; if (table->part_info && - (!table->part_info->is_auto_partitioned) && - ((part_syntax= generate_partition_syntax(table->part_info, + !((table->s->db_type()->partition_flags() & HA_USE_AUTO_PARTITION) && + table->part_info->is_auto_partitioned)) + { + /* + Partition syntax for CREATE TABLE is at the end of the syntax. + */ + uint part_syntax_len; + char *part_syntax; + String comment_start; + table->part_info->set_show_version_string(&comment_start); + if ((part_syntax= generate_partition_syntax(table->part_info, &part_syntax_len, FALSE, show_table_options, - NULL, NULL)))) - { - table->part_info->set_show_version_string(packet); - packet->append(part_syntax, part_syntax_len); - packet->append(STRING_WITH_LEN(" */")); - my_free(part_syntax); + NULL, NULL, + comment_start.c_ptr()))) + { + packet->append(comment_start); + if (packet->append(part_syntax, part_syntax_len) || + packet->append(STRING_WITH_LEN(" */"))) + error= 1; + my_free(part_syntax); + } } } #endif tmp_restore_column_map(table->read_set, old_map); - DBUG_RETURN(0); + DBUG_RETURN(error); } @@ -2185,7 +2193,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) DBUG_ENTER("mysqld_list_processes"); field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS)); - field_list.push_back(new Item_empty_string("User",16)); + field_list.push_back(new Item_empty_string("User", USERNAME_CHAR_LENGTH)); field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN)); field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN)); field->maybe_null=1; @@ -7251,7 +7259,7 @@ struct schema_table_ref ST_FIELD_INFO user_stats_fields_info[]= { - {"USER", USERNAME_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, + {"USER", USERNAME_CHAR_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, {"TOTAL_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Total_connections",SKIP_OPEN_TABLE}, {"CONCURRENT_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Concurrent_connections",SKIP_OPEN_TABLE}, {"CONNECTED_TIME", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Connected_time",SKIP_OPEN_TABLE}, @@ -8623,7 +8631,8 @@ ST_FIELD_INFO variables_fields_info[]= ST_FIELD_INFO processlist_fields_info[]= { {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE}, - {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE}, + {"USER", USERNAME_CHAR_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", + SKIP_OPEN_TABLE}, {"HOST", LIST_PROCESS_HOST_LEN, MYSQL_TYPE_STRING, 0, 0, "Host", SKIP_OPEN_TABLE}, {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Db", SKIP_OPEN_TABLE}, diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 21748861204..f1cb5e07eca 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -758,7 +758,7 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length) { if (from->Alloced_length >= from_length) return from; - if (from->alloced || !to || from == to) + if ((from->alloced && (from->Alloced_length != 0)) || !to || from == to) { (void) from->realloc(from_length); return from; diff --git a/sql/sql_string.h b/sql/sql_string.h index 2a5f43b35f2..4ce08a5d9e6 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -378,6 +378,16 @@ public: } return 0; } + bool append_hex(const char *src, uint32 srclen) + { + for (const char *end= src + srclen ; src != end ; src++) + { + if (append(_dig_vec_lower[((uchar) *src) >> 4]) || + append(_dig_vec_lower[((uchar) *src) & 0x0F])) + return true; + } + return false; + } bool fill(uint32 max_length,char fill); void strip_sp(); friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 6bb650f55db..9ce1b863086 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2000, 2013, Oracle and/or its affiliates. Copyright (c) 2010, 2013, Monty Program Ab. This program is free software; you can redistribute it and/or modify @@ -53,6 +53,7 @@ #include "sql_parse.h" #include "sql_show.h" #include "transaction.h" +#include "sql_audit.h" #ifdef __WIN__ #include @@ -1690,7 +1691,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) &syntax_len, TRUE, TRUE, lpt->create_info, - lpt->alter_info))) + lpt->alter_info, + NULL))) { DBUG_RETURN(TRUE); } @@ -1793,7 +1795,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) &syntax_len, TRUE, TRUE, lpt->create_info, - lpt->alter_info))) + lpt->alter_info, + NULL))) { error= 1; goto err; @@ -2379,6 +2382,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, PSI_CALL_drop_table_share(table->internal_tmp_table, table->db, table->db_length, table->table_name, table->table_name_length); + mysql_audit_drop_table(thd, table); } DBUG_PRINT("table", ("table: 0x%lx s: 0x%lx", (long) table->table, @@ -2786,6 +2790,8 @@ int prepare_create_field(Create_field *sql_field, case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIME2: + case MYSQL_TYPE_DATETIME2: case MYSQL_TYPE_NULL: sql_field->pack_flag=f_settype((uint) sql_field->sql_type); break; @@ -2804,6 +2810,7 @@ int prepare_create_field(Create_field *sql_field, (sql_field->decimals << FIELDFLAG_DEC_SHIFT)); break; case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TIMESTAMP2: /* fall-through */ default: sql_field->pack_flag=(FIELDFLAG_NUMBER | @@ -2889,7 +2896,7 @@ void promote_first_timestamp_column(List *column_definitions) while ((column_definition= it++) != NULL) { - if (column_definition->sql_type == MYSQL_TYPE_TIMESTAMP || // TIMESTAMP + if (is_timestamp_type(column_definition->sql_type) || // TIMESTAMP column_definition->unireg_check == Field::TIMESTAMP_OLD_FIELD) // Legacy { if ((column_definition->flags & NOT_NULL_FLAG) != 0 && // NOT NULL, @@ -3850,7 +3857,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, if (thd->variables.sql_mode & MODE_NO_ZERO_DATE && !sql_field->def && - sql_field->sql_type == MYSQL_TYPE_TIMESTAMP && + is_timestamp_type(sql_field->sql_type) && (sql_field->flags & NOT_NULL_FLAG) && (type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD)) { @@ -4206,7 +4213,8 @@ handler *mysql_create_frm_image(THD *thd, &syntax_len, TRUE, TRUE, create_info, - alter_info))) + alter_info, + NULL))) goto err; part_info->part_info_string= part_syntax_buf; part_info->part_info_len= syntax_len; @@ -4688,6 +4696,8 @@ mysql_rename_table(handlerton *base, const char *old_db, my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE"); else if (error) my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error); + else if (!(flags & FN_IS_TMP)) + mysql_audit_rename_table(thd, old_db, old_name, new_db, new_name); /* Remove the old table share from the pfs table share array. The new table @@ -5943,7 +5953,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, */ if ((def->sql_type == MYSQL_TYPE_DATE || def->sql_type == MYSQL_TYPE_NEWDATE || - def->sql_type == MYSQL_TYPE_DATETIME) && + def->sql_type == MYSQL_TYPE_DATETIME || + def->sql_type == MYSQL_TYPE_DATETIME2) && !alter_info->datetime_field && !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) && thd->variables.sql_mode & MODE_NO_ZERO_DATE) @@ -6355,6 +6366,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, mysql_ha_rm_tables(thd, table_list); + mysql_audit_alter_table(thd, table_list); + /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */ if (alter_info->tablespace_op != NO_TABLESPACE_OP) /* Conditionally writes to binlog. */ @@ -7579,6 +7592,7 @@ err: t_type= MYSQL_TIMESTAMP_DATE; break; case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DATETIME2: f_val= "0000-00-00 00:00:00"; t_type= MYSQL_TIMESTAMP_DATETIME; break; diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 5b3286d77b0..93b35b4918f 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -629,7 +629,7 @@ Max used alarms: %u\n\ Next alarm time: %lu\n", alarm_info.active_alarms, alarm_info.max_used_alarms, - alarm_info.next_alarm_time); + (ulong)alarm_info.next_alarm_time); #endif display_table_locks(); fflush(stdout); diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 89c2e3b7086..ff2ec62f815 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -214,6 +214,22 @@ ulong convert_month_to_period(ulong month) } +bool +check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, + timestamp_type ts_type) +{ + int unused; + if (check_date(ltime, fuzzy_date, &unused)) + { + ErrConvTime str(ltime); + make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + &str, ts_type, 0); + return true; + } + return false; +} + + /* Convert a string to 8-bit representation, for use in str_to_time/str_to_date/str_to_date. @@ -249,9 +265,9 @@ to_ascii(CHARSET_INFO *cs, /* Character set-aware version of str_to_time() */ -timestamp_type +bool str_to_time(CHARSET_INFO *cs, const char *str,uint length, - MYSQL_TIME *l_time, ulonglong fuzzydate, int *warning) + MYSQL_TIME *l_time, ulonglong fuzzydate, MYSQL_TIME_STATUS *status) { char cnv[32]; if ((cs->state & MY_CS_NONASCII) != 0) @@ -259,14 +275,14 @@ str_to_time(CHARSET_INFO *cs, const char *str,uint length, length= to_ascii(cs, str, length, cnv, sizeof(cnv)); str= cnv; } - return str_to_time(str, length, l_time, fuzzydate, warning); + return str_to_time(str, length, l_time, fuzzydate, status); } /* Character set-aware version of str_to_datetime() */ -timestamp_type str_to_datetime(CHARSET_INFO *cs, - const char *str, uint length, - MYSQL_TIME *l_time, ulonglong flags, int *was_cut) +bool str_to_datetime(CHARSET_INFO *cs, const char *str, uint length, + MYSQL_TIME *l_time, ulonglong flags, + MYSQL_TIME_STATUS *status) { char cnv[32]; if ((cs->state & MY_CS_NONASCII) != 0) @@ -274,7 +290,7 @@ timestamp_type str_to_datetime(CHARSET_INFO *cs, length= to_ascii(cs, str, length, cnv, sizeof(cnv)); str= cnv; } - return str_to_datetime(str, length, l_time, flags, was_cut); + return str_to_datetime(str, length, l_time, flags, status); } @@ -286,26 +302,24 @@ timestamp_type str_to_datetime(CHARSET_INFO *cs, See description of str_to_datetime() for more information. */ -timestamp_type +bool str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, uint length, MYSQL_TIME *l_time, ulonglong flags) { - int was_cut; + MYSQL_TIME_STATUS status; THD *thd= current_thd; - timestamp_type ts_type; - - ts_type= str_to_datetime(cs, str, length, l_time, + bool ret_val= str_to_datetime(cs, str, length, l_time, (flags | (sql_mode_for_dates(thd))), - &was_cut); - if (was_cut || ts_type <= MYSQL_TIMESTAMP_ERROR) + &status); + if (ret_val || status.warnings) make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, str, length, flags & TIME_TIME_ONLY ? - MYSQL_TIMESTAMP_TIME : ts_type, NullS); + MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); DBUG_EXECUTE_IF("str_to_datetime_warn", push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_YES, str);); - return ts_type; + return ret_val; } @@ -1055,7 +1069,7 @@ calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *s */ -int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b) +int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b) { ulonglong a_t= pack_time(a); ulonglong b_t= pack_time(b); diff --git a/sql/sql_time.h b/sql/sql_time.h index c1a75bb2ad3..cf029f143b3 100644 --- a/sql/sql_time.h +++ b/sql/sql_time.h @@ -35,11 +35,9 @@ ulong convert_period_to_month(ulong period); ulong convert_month_to_period(ulong month); bool get_date_from_daynr(long daynr,uint *year, uint *month, uint *day); my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, uint *error_code); -bool str_to_time_with_warn(CHARSET_INFO *cs, const char *str, uint length, - MYSQL_TIME *l_time, ulonglong fuzzydate); -timestamp_type str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, - uint length, MYSQL_TIME *l_time, - ulonglong flags); +bool str_to_datetime_with_warn(CHARSET_INFO *cs, const char *str, + uint length, MYSQL_TIME *l_time, + ulonglong flags); bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime, ulonglong fuzzydate, const char *name); @@ -76,7 +74,7 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval); bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *seconds_out, long *microseconds_out); -int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b); +int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b); void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds); uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year); @@ -86,12 +84,14 @@ bool parse_date_time_format(timestamp_type format_type, const char *format, uint format_length, DATE_TIME_FORMAT *date_time_format); /* Character set-aware version of str_to_time() */ -timestamp_type str_to_time(CHARSET_INFO *cs, const char *str,uint length, - MYSQL_TIME *l_time, ulonglong fuzzydate, int *warning); +bool str_to_time(CHARSET_INFO *cs, const char *str,uint length, + MYSQL_TIME *l_time, ulonglong fuzzydate, + MYSQL_TIME_STATUS *status); /* Character set-aware version of str_to_datetime() */ -timestamp_type str_to_datetime(CHARSET_INFO *cs, - const char *str, uint length, - MYSQL_TIME *l_time, ulonglong flags, int *was_cut); +bool str_to_datetime(CHARSET_INFO *cs, + const char *str, uint length, + MYSQL_TIME *l_time, ulonglong flags, + MYSQL_TIME_STATUS *status); /* convenience wrapper */ inline bool parse_date_time_format(timestamp_type format_type, @@ -110,4 +110,18 @@ extern DATE_TIME_FORMAT global_time_format; extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[]; extern LEX_STRING interval_type_to_name[]; + +static inline bool +non_zero_date(const MYSQL_TIME *ltime) +{ + return ltime->year || ltime->month || ltime->day; +} +static inline bool +check_date(const MYSQL_TIME *ltime, ulonglong flags, int *was_cut) +{ + return check_date(ltime, non_zero_date(ltime), flags, was_cut); +} +bool check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, + timestamp_type ts_type); + #endif /* SQL_TIME_INCLUDED */ diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 5b5bd0ed2fc..63df46c7094 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1152,9 +1152,10 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, TODO: when VIEWs will be stored in cache, table mem_root should be used here */ - if (parser->parse((uchar*)table, thd->mem_root, view_parameters, - required_view_parameters, &file_parser_dummy_hook)) - goto err; + if ((result= parser->parse((uchar*)table, thd->mem_root, + view_parameters, required_view_parameters, + &file_parser_dummy_hook))) + goto end; /* check old format view .frm @@ -1217,6 +1218,11 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, now Lex placed in statement memory */ table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local; + if (!table->view) + { + result= true; + goto end; + } { char old_db_buf[SAFE_NAME_LEN+1]; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 6be7c23fb0d..0dc8ed7037e 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1,6 +1,6 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. - Copyright (c) 2010, 2011 Monty Program Ab + Copyright (c) 2000, 2013, Oracle and/or its affiliates. + 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 @@ -32,6 +32,7 @@ #define YYTHD ((THD *)yythd) #define YYLIP (& YYTHD->m_parser_state->m_lip) #define YYPS (& YYTHD->m_parser_state->m_yacc) +#define YYCSCL YYTHD->variables.character_set_client #define MYSQL_YACC #define YYINITDEPTH 100 @@ -899,10 +900,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %pure_parser /* We have threads */ /* - Currently there are 170 shift/reduce conflicts. + Currently there are 167 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 170 +%expect 167 /* Comments for TOKENS. @@ -1133,6 +1134,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token HAVING /* SQL-2003-R */ %token HELP_SYM %token HEX_NUM +%token HEX_STRING %token HIGH_PRIORITY %token HOST_SYM %token HOSTS_SYM @@ -1566,7 +1568,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %left INTERVAL_SYM %type - IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM + IDENT IDENT_QUOTED TEXT_STRING DECIMAL_NUM FLOAT_NUM NUM LONG_NUM + HEX_NUM HEX_STRING hex_num_or_string LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text IDENT_sys TEXT_STRING_sys TEXT_STRING_literal NCHAR_STRING opt_component key_cache_name @@ -1626,7 +1629,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); replace_lock_option opt_low_priority insert_lock_option load_data_lock %type - literal text_literal insert_ident order_ident + literal text_literal insert_ident order_ident temporal_literal simple_ident expr opt_expr opt_else sum_expr in_sum_expr variable variable_aux bool_pri predicate bit_expr @@ -4591,7 +4594,7 @@ partition: ; part_type_def: - opt_linear KEY_SYM '(' part_field_list ')' + opt_linear KEY_SYM opt_key_algo '(' part_field_list ')' { partition_info *part_info= Lex->part_info; part_info->list_of_part_fields= TRUE; @@ -4617,6 +4620,25 @@ opt_linear: { Lex->part_info->linear_hash_ind= TRUE;} ; +opt_key_algo: + /* empty */ + { Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_NONE;} + | ALGORITHM_SYM EQ real_ulong_num + { + switch ($3) { + case 1: + Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_51; + break; + case 2: + Lex->part_info->key_algorithm= partition_info::KEY_ALGORITHM_55; + break; + default: + my_parse_error(ER(ER_SYNTAX_ERROR)); + MYSQL_YYABORT; + } + } + ; + part_field_list: /* empty */ {} | part_field_item_list {} @@ -4698,7 +4720,7 @@ opt_sub_part: | SUBPARTITION_SYM BY opt_linear HASH_SYM sub_part_func { Lex->part_info->subpart_type= HASH_PARTITION; } opt_num_subparts {} - | SUBPARTITION_SYM BY opt_linear KEY_SYM + | SUBPARTITION_SYM BY opt_linear KEY_SYM opt_key_algo '(' sub_part_field_list ')' { partition_info *part_info= Lex->part_info; @@ -6159,6 +6181,11 @@ now_or_signed_literal: { $$=$1; } ; +hex_num_or_string: + HEX_NUM {} + | HEX_STRING {} + ; + charset: CHAR_SYM SET {} | CHARSET {} @@ -8715,7 +8742,48 @@ simple_expr: MYSQL_YYABORT; } | '{' ident expr '}' - { $$= $3; } + { + Item_string *item; + $$= NULL; + /* + If "expr" is reasonably short pure ASCII string literal, + try to parse known ODBC style date, time or timestamp literals, + e.g: + SELECT {d'2001-01-01'}; + SELECT {t'10:20:30'}; + SELECT {ts'2001-01-01 10:20:30'}; + */ + if ($3->type() == Item::STRING_ITEM && + (item= (Item_string *) $3) && + item->collation.repertoire == MY_REPERTOIRE_ASCII && + item->str_value.length() < MAX_DATE_STRING_REP_LENGTH * 4) + { + enum_field_types type= MYSQL_TYPE_STRING; + LEX_STRING *ls= &$2; + if (ls->length == 1) + { + if (ls->str[0] == 'd') /* {d'2001-01-01'} */ + type= MYSQL_TYPE_DATE; + else if (ls->str[0] == 't') /* {t'10:20:30'} */ + type= MYSQL_TYPE_TIME; + } + else if (ls->length == 2) /* {ts'2001-01-01 10:20:30'} */ + { + if (ls->str[0] == 't' && ls->str[1] == 's') + type= MYSQL_TYPE_DATETIME; + } + if (type != MYSQL_TYPE_STRING) + { + $$= create_temporal_literal(YYTHD, + item->str_value.ptr(), + item->str_value.length(), + item->str_value.charset(), + type, false); + } + } + if ($$ == NULL) + $$= $3; + } | MATCH ident_list_arg AGAINST '(' bit_expr fulltext_options ')' { $2->push_front($5); @@ -12638,7 +12706,7 @@ text_string: } | HEX_NUM { - Item *tmp= new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); + Item *tmp= new (YYTHD->mem_root) Item_hex_hybrid($1.str, $1.length); if (tmp == NULL) MYSQL_YYABORT; /* @@ -12648,6 +12716,14 @@ text_string: tmp->quick_fix_field(); $$= tmp->val_str((String*) 0); } + | HEX_STRING + { + Item *tmp= new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); + if (tmp == NULL) + MYSQL_YYABORT; + tmp->quick_fix_field(); + $$= tmp->val_str((String*) 0); + } | BIN_NUM { Item *tmp= new (YYTHD->mem_root) Item_bin_string($1.str, $1.length); @@ -12696,6 +12772,7 @@ signed_literal: literal: text_literal { $$ = $1; } | NUM_literal { $$ = $1; } + | temporal_literal { $$= $1; } | NULL_SYM { $$ = new (YYTHD->mem_root) Item_null(); @@ -12716,6 +12793,12 @@ literal: MYSQL_YYABORT; } | HEX_NUM + { + $$ = new (YYTHD->mem_root) Item_hex_hybrid($1.str, $1.length); + if ($$ == NULL) + MYSQL_YYABORT; + } + | HEX_STRING { $$ = new (YYTHD->mem_root) Item_hex_string($1.str, $1.length); if ($$ == NULL) @@ -12727,7 +12810,7 @@ literal: if ($$ == NULL) MYSQL_YYABORT; } - | UNDERSCORE_CHARSET HEX_NUM + | UNDERSCORE_CHARSET hex_num_or_string { Item *tmp= new (YYTHD->mem_root) Item_hex_string($2.str, $2.length); if (tmp == NULL) @@ -12784,9 +12867,6 @@ literal: $$= item_str; } - | DATE_SYM text_literal { $$ = $2; } - | TIME_SYM text_literal { $$ = $2; } - | TIMESTAMP text_literal { $$ = $2; } ; NUM_literal: @@ -12835,6 +12915,31 @@ NUM_literal: } ; + +temporal_literal: + DATE_SYM TEXT_STRING + { + if (!($$= create_temporal_literal(YYTHD, $2.str, $2.length, YYCSCL, + MYSQL_TYPE_DATE, true))) + MYSQL_YYABORT; + } + | TIME_SYM TEXT_STRING + { + if (!($$= create_temporal_literal(YYTHD, $2.str, $2.length, YYCSCL, + MYSQL_TYPE_TIME, true))) + MYSQL_YYABORT; + } + | TIMESTAMP TEXT_STRING + { + if (!($$= create_temporal_literal(YYTHD, $2.str, $2.length, YYCSCL, + MYSQL_TYPE_DATETIME, true))) + MYSQL_YYABORT; + } + ; + + + + /********************************************************************** ** Creating different items. **********************************************************************/ @@ -13283,7 +13388,7 @@ user: $$->auth= empty_lex_str; if (check_string_char_length(&$$->user, ER(ER_USERNAME), - USERNAME_CHAR_LENGTH, + username_char_length, system_charset_info, 0)) MYSQL_YYABORT; } @@ -13298,7 +13403,7 @@ user: $$->auth= empty_lex_str; if (check_string_char_length(&$$->user, ER(ER_USERNAME), - USERNAME_CHAR_LENGTH, + username_char_length, system_charset_info, 0) || check_host_name(&$$->host)) MYSQL_YYABORT; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 9ca504fd275..565b5cafe3e 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -31,7 +31,7 @@ (for example in storage/myisam/ha_myisam.cc) ! */ -#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "sql_plugin.h" #include "sql_priv.h" #include "sql_class.h" // set_var.h: THD #include "sys_vars.h" @@ -1392,6 +1392,12 @@ Sys_var_gtid_binlog_pos::global_value_ptr(THD *thd, LEX_STRING *base) String str(buf, sizeof(buf), system_charset_info); char *p; + if (!rpl_global_gtid_slave_state.loaded) + { + my_error(ER_CANNOT_LOAD_SLAVE_GTID_STATE, MYF(0), "mysql", + rpl_gtid_slave_state_table_name.str); + return NULL; + } str.length(0); if ((opt_bin_log && mysql_bin_log.append_state_pos(&str)) || !(p= thd->strmake(str.ptr(), str.length()))) @@ -1438,6 +1444,14 @@ Sys_var_gtid_slave_pos::do_check(THD *thd, set_var *var) bool running; DBUG_ASSERT(var->type == OPT_GLOBAL); + + if (!rpl_global_gtid_slave_state.loaded) + { + my_error(ER_CANNOT_LOAD_SLAVE_GTID_STATE, MYF(0), "mysql", + rpl_gtid_slave_state_table_name.str); + return true; + } + mysql_mutex_lock(&LOCK_active_mi); running= master_info_index->give_error_if_slave_running(); mysql_mutex_unlock(&LOCK_active_mi); @@ -1496,6 +1510,13 @@ Sys_var_gtid_slave_pos::global_value_ptr(THD *thd, LEX_STRING *base) String str; char *p; + if (!rpl_global_gtid_slave_state.loaded) + { + my_error(ER_CANNOT_LOAD_SLAVE_GTID_STATE, MYF(0), "mysql", + rpl_gtid_slave_state_table_name.str); + return NULL; + } + str.length(0); if (rpl_append_gtid_state(&str, false) || !(p= thd->strmake(str.ptr(), str.length()))) diff --git a/sql/table.cc b/sql/table.cc index 2f867eb7dc4..32a841ffd46 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3281,7 +3281,7 @@ bool get_field(MEM_ROOT *mem, Field *field, String *res) } if (!(to= strmake_root(mem, str.ptr(), length))) length= 0; // Safety fix - res->set(to, length, ((Field_str*)field)->charset()); + res->set(to, length, field->charset()); return 0; } diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc index 69df00a2c9a..658a04d877e 100644 --- a/sql/threadpool_unix.cc +++ b/sql/threadpool_unix.cc @@ -286,6 +286,20 @@ static void *native_event_get_userdata(native_event *event) } #elif defined(HAVE_KQUEUE) + +/* + NetBSD is incompatible with other BSDs , last parameter in EV_SET macro + (udata, user data) needs to be intptr_t, whereas it needs to be void* + everywhere else. +*/ + +#ifdef __NetBSD__ +#define MY_EV_SET(a, b, c, d, e, f, g) EV_SET(a, b, c, d, e, f, (intptr_t)g) +#else +#define MY_EV_SET(a, b, c, d, e, f, g) EV_SET(a, b, c, d, e, f, g) +#endif + + int io_poll_create() { return kqueue(); @@ -294,7 +308,7 @@ int io_poll_create() int io_poll_start_read(int pollfd, int fd, void *data) { struct kevent ke; - EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, + MY_EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, 0, 0, data); return kevent(pollfd, &ke, 1, 0, 0, 0); } @@ -303,7 +317,7 @@ int io_poll_start_read(int pollfd, int fd, void *data) int io_poll_associate_fd(int pollfd, int fd, void *data) { struct kevent ke; - EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, + MY_EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, 0, 0, data); return io_poll_start_read(pollfd,fd, data); } @@ -312,7 +326,7 @@ int io_poll_associate_fd(int pollfd, int fd, void *data) int io_poll_disassociate_fd(int pollfd, int fd) { struct kevent ke; - EV_SET(&ke,fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); + MY_EV_SET(&ke,fd, EVFILT_READ, EV_DELETE, 0, 0, 0); return kevent(pollfd, &ke, 1, 0, 0, 0); } @@ -337,7 +351,7 @@ int io_poll_wait(int pollfd, struct kevent *events, int maxevents, int timeout_m static void* native_event_get_userdata(native_event *event) { - return event->udata; + return (void *)event->udata; } #elif defined (__sun) diff --git a/sql/tztime.cc b/sql/tztime.cc index 5e1e8bec7b3..f5e9182522e 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -2559,7 +2559,7 @@ main(int argc, char **argv) if (argc == 2) { - root_name_end= strmake(fullname, argv[1], FN_REFLEN); + root_name_end= strmake_buf(fullname, argv[1]); printf("TRUNCATE TABLE time_zone;\n"); printf("TRUNCATE TABLE time_zone_name;\n"); @@ -2713,7 +2713,7 @@ main(int argc, char **argv) (int)t, (int)t1); /* Let us load time zone description */ - str_end= strmake(fullname, TZDIR, FN_REFLEN); + str_end= strmake_buf(fullname, TZDIR); strmake(str_end, "/MET", FN_REFLEN - (str_end - fullname)); if (tz_load(fullname, &tz_info, &tz_storage)) diff --git a/storage/cassandra/CMakeLists.txt b/storage/cassandra/CMakeLists.txt index 63e413ccb7b..78cb1f8b7e8 100644 --- a/storage/cassandra/CMakeLists.txt +++ b/storage/cassandra/CMakeLists.txt @@ -60,12 +60,12 @@ IF(CASSANDRASE_OK) IF(RPM) SET(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} cassandra-engine PARENT_SCOPE) - SET(CPACK_RPM_cassandra_engine_PACKAGE_REQUIRES "MariaDB-server" PARENT_SCOPE) + SET(CPACK_RPM_cassandra-engine_PACKAGE_REQUIRES "MariaDB-server" PARENT_SCOPE) # workarounds for cmake issues #13248 and #12864: - SET(CPACK_RPM_cassandra_engine_USER_FILELIST ${ignored} "%config(noreplace) /etc/my.cnf.d/*" PARENT_SCOPE) - SET(CPACK_RPM_cassandra_engine_PACKAGE_PROVIDES "cmake_bug_13248" PARENT_SCOPE) - SET(CPACK_RPM_cassandra_engine_PACKAGE_OBSOLETES "cmake_bug_13248" PARENT_SCOPE) + SET(CPACK_RPM_cassandra-engine_USER_FILELIST ${ignored} "%config(noreplace) /etc/my.cnf.d/*" PARENT_SCOPE) + SET(CPACK_RPM_cassandra-engine_PACKAGE_PROVIDES "cmake_bug_13248" PARENT_SCOPE) + SET(CPACK_RPM_cassandra-engine_PACKAGE_OBSOLETES "cmake_bug_13248" PARENT_SCOPE) ENDIF(RPM) ENDIF(CASSANDRASE_OK) diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 4f02924d6b3..f25b33c7ccf 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -18,25 +18,27 @@ SET(CONNECT_PLUGIN_DYNAMIC "connect") SET(CONNECT_SOURCES ha_connect.cc connect.cc user_connect.cc mycat.cc -fmdlex.c osutil.c plugutil.c rcmsg.c +fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h csort.cpp maputil.cpp plgdbutl.cpp colblk.cpp reldef.cpp tabcol.cpp table.cpp filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamvct.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabmul.cpp tabsys.cpp tabvct.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp filamzip.cpp tabtbl.cpp myutil.cpp +tabutil.cpp tabxcl.cpp taboccur.cpp tabpivot.cpp block.h catalog.h checklvl.h colblk.h connect.h csort.h engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h -global.h ha_connect.h maputil.h msgid.h mycat.h myutil.h os.h +global.h ha_connect.h inihandl.h maputil.h msgid.h mycat.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabmul.h tabsys.h tabtbl.h tabvct.h -user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) +user_connect.h valblk.h value.h xindex.h xobject.h xtable.h +tabutil.h tabxcl.h taboccur.h tabpivot.h) # # Definitions that are shared for all OSes # add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS ) -add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT ) +add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT ) # @@ -46,7 +48,6 @@ IF(UNIX) # Bar: -Wfatal-errors removed (does not present in gcc on solaris10) if(WITH_WARNINGS) add_definitions(-Wall -Wextra -Wmissing-declarations) - add_definitions(-Wno-non-virtual-dtor) message(STATUS "CONNECT: GCC: All warnings enabled") else() add_definitions(-Wall -Wmissing-declarations) @@ -62,13 +63,11 @@ IF(UNIX) # add_definitions(-Wno-int-to-pointer-cast) # Bar: -Wno-narrowing commented (does not present in gcc on solaris10) # add_definitions(-Wno-narrowing) - add_definitions(-Wno-non-virtual-dtor) # This switch is for pure C only: # add_definitions(-Wno-implicit-function-declaration) # These switches are for C++ only # add_definitions(-Wno-reorder) -# add_definitions(-Wno-delete-non-virtual-dtor) message(STATUS "CONNECT: GCC: Some warnings disabled") endif(WITH_WARNINGS) @@ -176,7 +175,7 @@ OPTION(CONNECT_WITH_MYSQL IF(CONNECT_WITH_MYSQL) SET(CONNECT_SOURCES ${CONNECT_SOURCES} - myconn.cpp myconn.h tabmysql.cpp tabxml.h) + myconn.cpp myconn.h tabmysql.cpp tabmysql.h) add_definitions(-DMYSQL_SUPPORT) IF(NOT UNIX) # @@ -289,10 +288,10 @@ ENDIF(INSTALL_SYSCONFDIR) IF(RPM) SET(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} connect-engine PARENT_SCOPE) - SET(CPACK_RPM_connect_engine_PACKAGE_REQUIRES "MariaDB-server" PARENT_SCOPE) + SET(CPACK_RPM_connect-engine_PACKAGE_REQUIRES "MariaDB-server" PARENT_SCOPE) # workarounds for cmake issues #13248 and #12864: - SET(CPACK_RPM_connect_engine_USER_FILELIST ${ignored} "%config(noreplace) /etc/my.cnf.d/*" PARENT_SCOPE) - SET(CPACK_RPM_connect_engine_PACKAGE_PROVIDES "cmake_bug_13248" PARENT_SCOPE) - SET(CPACK_RPM_connect_engine_PACKAGE_OBSOLETES "cmake_bug_13248" PARENT_SCOPE) + SET(CPACK_RPM_connect-engine_USER_FILELIST ${ignored} "%config(noreplace) /etc/my.cnf.d/*" PARENT_SCOPE) + SET(CPACK_RPM_connect-engine_PACKAGE_PROVIDES "cmake_bug_13248" PARENT_SCOPE) + SET(CPACK_RPM_connect-engine_PACKAGE_OBSOLETES "cmake_bug_13248" PARENT_SCOPE) ENDIF(RPM) diff --git a/storage/connect/catalog.h b/storage/connect/catalog.h index 4f0584ef7bc..3a06aea7a30 100644 --- a/storage/connect/catalog.h +++ b/storage/connect/catalog.h @@ -62,14 +62,9 @@ class DllExport CATALOG { virtual ~CATALOG() { } // Make -Wdelete-non-virtual-dtor happy // Implementation - void *GetDescp(void) {return Descp;} - PRELDEF GetTo_Desc(void) {return To_Desc;} -//PSZ GetDescFile(void) {return DescFile;} int GetCblen(void) {return Cblen;} bool GetDefHuge(void) {return DefHuge;} void SetDefHuge(bool b) {DefHuge = b;} -//bool GetSepIndex(void) {return SepIndex;} -//void SetSepIndex(bool b) {SepIndex = b;} char *GetCbuf(void) {return Cbuf;} char *GetDataPath(void) {return (char*)DataPath;} @@ -115,15 +110,10 @@ class DllExport CATALOG { virtual PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) {return NULL;} // Members - PRELDEF To_Desc; /* To chain of relation desc. */ - void *Descp; /* To DB description area */ -//AREADEF DescArea; /* Table desc. area size */ char *Cbuf; /* Buffer used for col section */ int Cblen; /* Length of suballoc. buffer */ CURTAB Ctb; /* Used to enumerate tables */ bool DefHuge; /* true: tables default to huge */ -//bool SepIndex; /* true: separate index files */ -//char DescFile[_MAX_PATH]; /* DB description filename */ LPCSTR DataPath; /* Is the Path of DB data dir */ }; // end of class CATALOG diff --git a/storage/connect/colblk.cpp b/storage/connect/colblk.cpp index cdbf6f4b42b..dfdc82e99a7 100644 --- a/storage/connect/colblk.cpp +++ b/storage/connect/colblk.cpp @@ -159,19 +159,6 @@ bool COLBLK::CheckSort(PTDB tdbp) return (tdbp == To_Tdb); } // end of CheckSort -/***********************************************************************/ -/* MarkCol: see PlugMarkCol for column references to mark. */ -/***********************************************************************/ -void COLBLK::MarkCol(ushort bits) - { - ColUse |= bits; - -#ifdef DEBTRACE - htrc(" column R%d.%s marked as %04X\n", - To_Tdb->GetTdb_No(), Name, ColUse); -#endif - } // end of MarkCol - /***********************************************************************/ /* InitValue: prepare a column block for read operation. */ /* Now we use Format.Length for the len parameter to avoid strings */ diff --git a/storage/connect/colblk.h b/storage/connect/colblk.h index cf6fb443308..5fbb118fc72 100644 --- a/storage/connect/colblk.h +++ b/storage/connect/colblk.h @@ -64,7 +64,6 @@ class DllExport COLBLK : public XOBJECT { virtual bool IsSpecial(void) {return false;} virtual int CheckSpcCol(PTDB tdbp, int n) {return 2;} virtual bool CheckSort(PTDB tdbp); - virtual void MarkCol(ushort bits); virtual bool Eval(PGLOBAL g); virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual void SetTo_Val(PVAL valp) {} diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 54816f80e5c..e0c722bc01f 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -31,7 +31,6 @@ /* global.h is header containing all global declarations. */ /* plgdbsem.h is header containing the DB applic. declarations. */ /***********************************************************************/ -#define MYSQL_SERVER 1 #define DONT_DEFINE_VOID #include "handler.h" #undef OFFSET @@ -71,10 +70,7 @@ int rename_file_ext(const char *from, const char *to,const char *ext); PGLOBAL CntExit(PGLOBAL g) { if (g) { - PDBUSER dup= PlgGetUser(g); - CntEndDB(g); - free(dup); if (g->Activityp) delete g->Activityp; @@ -94,13 +90,10 @@ void CntEndDB(PGLOBAL g) PDBUSER dbuserp= PlgGetUser(g); if (dbuserp) { - if (dbuserp->Catalog) { + if (dbuserp->Catalog) delete dbuserp->Catalog; - dbuserp->Catalog= NULL; - } // endif Catalog - *dbuserp->Name= '\0'; -// *dbuserp->Work= '\0'; + free(dbuserp); } // endif dbuserp } // end of CntEndDB @@ -258,10 +251,12 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, return true; } // endif tdbp - if (!c1) - // Allocate all column blocks for that table - tdbp->ColDB(g, NULL, 0); - else for (p= c1; *p; p+= n) { + if (!c1) { + if (mode == MODE_INSERT) + // Allocate all column blocks for that table + tdbp->ColDB(g, NULL, 0); + + } else for (p= c1; *p; p+= n) { // Allocate only used column blocks if (xtrace) printf("Allocating column %s\n", p); @@ -657,11 +652,6 @@ int CntIndexInit(PGLOBAL g, PTDB ptdb, int id) cdp= tdbp->Key(k)->GetCdp(); valp= AllocateValue(g, cdp->GetType(), cdp->GetLength()); tdbp->To_Link[k]= new(g) CONSTANT(valp); - -//if (kdp->Klen && tdbp->To_Link[k]->GetResultType() == TYPE_STRING) -// ((XCOLBLK*)tdbp->To_Link[k])->SetLength(kdp->Klen); - -//((PCOL)tdbp->To_Link[k])->InitValue(g); } // endfor k // Make the index on xdp @@ -826,7 +816,7 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, p+= valp->GetClen(); - if (len[i] == p - kp) { + if (len[i] == (unsigned)(p - kp)) { n++; break; } else if (len[i] < (unsigned)(p - kp)) { diff --git a/storage/connect/connect.h b/storage/connect/connect.h index 3fd52d283c6..e81e54776c9 100644 --- a/storage/connect/connect.h +++ b/storage/connect/connect.h @@ -44,6 +44,7 @@ RCODE CntDeleteRow(PGLOBAL g, PTDB tdbp, bool all); bool CntInfo(PGLOBAL g, PTDB tdbp, PXF info); int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, bool *incl, key_part_map *kmap); +PGLOBAL CntExit(PGLOBAL g); /***********************************************************************/ /* Definition of classes XCOLCRT, XIXDEF, XKPDEF, DOXDEF, TDBDOX */ diff --git a/storage/connect/domdoc.h b/storage/connect/domdoc.h index fc157950df8..0fd0a58ffdb 100644 --- a/storage/connect/domdoc.h +++ b/storage/connect/domdoc.h @@ -35,6 +35,7 @@ class DOMDOC : public XMLDOCUMENT { // Properties virtual short GetDocType(void) {return TYPE_FB_XML;} virtual void *GetDocPtr(void) {return Docp;} + virtual void SetNofree(bool b) {} // Only libxml2 // Methods virtual bool Initialize(PGLOBAL g); diff --git a/storage/connect/filamdbf.cpp b/storage/connect/filamdbf.cpp index 3575a6b422a..0a67195b200 100644 --- a/storage/connect/filamdbf.cpp +++ b/storage/connect/filamdbf.cpp @@ -178,15 +178,13 @@ static int dbfhead(PGLOBAL g, FILE *file, PSZ fn, DBFHEADER *buf) /****************************************************************************/ PQRYRES DBFColumns(PGLOBAL g, const char *fn, BOOL info) { - static int dbtype[] = {DB_CHAR, DB_SHORT, DB_CHAR, - DB_INT, DB_INT, DB_SHORT}; static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT}; static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, FLD_LENGTH, FLD_SCALE}; static unsigned int length[] = {11, 6, 8, 10, 10, 6}; char buf[2], filename[_MAX_PATH]; - int ncol = sizeof(dbtype) / sizeof(int); + int ncol = sizeof(buftyp) / sizeof(int); int rc, type, len, field, fields; BOOL bad; DBFHEADER mainhead; @@ -228,8 +226,7 @@ PQRYRES DBFColumns(PGLOBAL g, const char *fn, BOOL info) fields = 0; qrp = PlgAllocResult(g, ncol, fields, IDS_COLUMNS + 3, - dbtype, buftyp, fldtyp, length, true, false); -//qrp->Info = info || (rc == RC_INFO); + buftyp, fldtyp, length, true, false); if (info) return qrp; diff --git a/storage/connect/filamfix.cpp b/storage/connect/filamfix.cpp index b7cbc76a553..d493a2f2568 100644 --- a/storage/connect/filamfix.cpp +++ b/storage/connect/filamfix.cpp @@ -425,9 +425,9 @@ int FIXFAM::DeleteRecords(PGLOBAL g, int irc) /* for compatibility with Text files and other OS's. */ /*****************************************************************/ char filename[_MAX_PATH]; - int rc, h; + int h; - rc = PlugCloseFile(g, To_Fb); + /*rc= */PlugCloseFile(g, To_Fb); PlugSetPath(filename, To_File, Tdbp->GetPath()); if ((h= global_open(g, MSGID_OPEN_STRERROR, filename, O_WRONLY)) <= 0) diff --git a/storage/connect/filamtxt.cpp b/storage/connect/filamtxt.cpp index ed4467b6392..2291f2c2b00 100644 --- a/storage/connect/filamtxt.cpp +++ b/storage/connect/filamtxt.cpp @@ -786,10 +786,10 @@ int DOSFAM::DeleteRecords(PGLOBAL g, int irc) /* for compatibility with Text files and other OS's. */ /*****************************************************************/ char filename[_MAX_PATH]; - int h, rc; // File handle, return code + int h; // File handle, return code PlugSetPath(filename, To_File, Tdbp->GetPath()); - rc = PlugCloseFile(g, To_Fb); + /*rc=*/ PlugCloseFile(g, To_Fb); if ((h= global_open(g, MSGID_OPEN_STRERROR, filename, O_WRONLY)) <= 0) return RC_FX; diff --git a/storage/connect/filamvct.cpp b/storage/connect/filamvct.cpp index 47ac07c6554..2b66437d127 100755 --- a/storage/connect/filamvct.cpp +++ b/storage/connect/filamvct.cpp @@ -10,15 +10,15 @@ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ /* This program are the VCT file access method classes. */ -/* Added in version 2: F */ +/* Added in version 2: F */ /* - Split Vec format. */ /* - Partial delete. */ -/* - Use of tempfile for update. */ +/* - Use of tempfile for update. */ /* */ /***********************************************************************/ /***********************************************************************/ -/* Include relevant MariaDB header file. */ +/* Include relevant MariaDB header file. */ /***********************************************************************/ #include "my_global.h" #if defined(WIN32) @@ -35,7 +35,6 @@ #include #include #include -//#define strerror(X) _strerror(X) #define NO_ERROR 0 #else // !UNIX #include @@ -204,7 +203,6 @@ bool VCTFAM::SetBlockInfo(PGLOBAL g) { char filename[_MAX_PATH]; bool rc = false; - int k; size_t n; VECHEADER vh; FILE *s; @@ -216,7 +214,7 @@ bool VCTFAM::SetBlockInfo(PGLOBAL g) s = Stream; if (Header == 1) - k = fseek(s, 0, SEEK_SET); + /*k =*/ fseek(s, 0, SEEK_SET); } else s= global_fopen(g, MSGID_CANNOT_OPEN, filename, "r+b"); @@ -230,7 +228,7 @@ bool VCTFAM::SetBlockInfo(PGLOBAL g) sprintf(g->Message, "Error opening header file %s", filename); return true; } else if (Header == 3) - k = fseek(s, -(int)sizeof(VECHEADER), SEEK_END); + /*k =*/ fseek(s, -(int)sizeof(VECHEADER), SEEK_END); vh.MaxRec = MaxBlk * Bsize; vh.NumRec = (Block - 1) * Nrec + Last; @@ -775,10 +773,10 @@ int VCTFAM::DeleteRecords(PGLOBAL g, int irc) /* checked for compatibility with Text files and other OS's. */ /***************************************************************/ char filename[_MAX_PATH]; - int rc, h; + int h; - rc = CleanUnusedSpace(g); // Clean last block - rc = PlugCloseFile(g, To_Fb); + /*rc =*/ CleanUnusedSpace(g); // Clean last block + /*rc =*/ PlugCloseFile(g, To_Fb); Stream = NULL; // For SetBlockInfo PlugSetPath(filename, To_File, Tdbp->GetPath()); @@ -1705,7 +1703,7 @@ int VCMFAM::DeleteRecords(PGLOBAL g, int irc) /***********************************************************************/ void VCMFAM::CloseTableFile(PGLOBAL g) { - int rc = 0, wrc = RC_OK; + int wrc = RC_OK; MODE mode = Tdbp->GetMode(); if (mode == MODE_INSERT) { @@ -1728,7 +1726,7 @@ void VCMFAM::CloseTableFile(PGLOBAL g) PlugCloseFile(g, To_Fb); if (wrc != RC_FX) - rc = ResetTableSize(g, Block, Last); + /*rc =*/ ResetTableSize(g, Block, Last); } else if (mode != MODE_DELETE) PlugCloseFile(g, To_Fb); @@ -1823,7 +1821,7 @@ bool VECFAM::OpenTableFile(PGLOBAL g) { char opmode[4]; int i; - bool b; + bool b= false; PCOLDEF cdp; PVCTCOL cp; MODE mode = Tdbp->GetMode(); @@ -2205,11 +2203,11 @@ int VECFAM::DeleteRecords(PGLOBAL g, int irc) /* for compatibility with other OS's. */ /*****************************************************************/ char filename[_MAX_PATH]; - int h, rc; // File handle, return code + int h; // File handle, return code for (int i = 0; i < Ncol; i++) { sprintf(filename, Colfn, i + 1); - rc = PlugCloseFile(g, To_Fbs[i]); + /*rc =*/ PlugCloseFile(g, To_Fbs[i]); if ((h= global_open(g, MSGID_OPEN_STRERROR, filename, O_WRONLY)) <= 0) return RC_FX; @@ -3118,7 +3116,6 @@ int BGVFAM::GetBlockInfo(PGLOBAL g) { char filename[_MAX_PATH]; int n; - bool b; VECHEADER vh; HANDLE h; @@ -3162,7 +3159,7 @@ int BGVFAM::GetBlockInfo(PGLOBAL g) return n; } else if (Header == 3) - b = BigSeek(g, h, -(BIGINT)sizeof(vh), true); + /*b = */ BigSeek(g, h, -(BIGINT)sizeof(vh), true); if (BigRead(g, h, &vh, sizeof(vh))) { sprintf(g->Message, "Error reading header file %s", filename); @@ -3190,7 +3187,7 @@ int BGVFAM::GetBlockInfo(PGLOBAL g) bool BGVFAM::SetBlockInfo(PGLOBAL g) { char filename[_MAX_PATH]; - bool bk, b = false, rc = false; + bool b = false, rc = false; VECHEADER vh; HANDLE h = INVALID_HANDLE_VALUE; @@ -3201,7 +3198,7 @@ bool BGVFAM::SetBlockInfo(PGLOBAL g) h = Hfile; if (Header == 1) - bk = BigSeek(g, h, (BIGINT)0); + /*bk =*/ BigSeek(g, h, (BIGINT)0); } else b = true; @@ -3230,7 +3227,7 @@ bool BGVFAM::SetBlockInfo(PGLOBAL g) } // endif h if (Header == 3) - bk = BigSeek(g, h, -(BIGINT)sizeof(vh), true); + /*bk =*/ BigSeek(g, h, -(BIGINT)sizeof(vh), true); vh.MaxRec = MaxBlk * Bsize; vh.NumRec = (Block - 1) * Nrec + Last; diff --git a/storage/connect/fmdlex.c b/storage/connect/fmdlex.c index 9ab8f2e03c5..a7213b1ed57 100644 --- a/storage/connect/fmdlex.c +++ b/storage/connect/fmdlex.c @@ -20,12 +20,13 @@ */ #define FLEX_SCANNER - #if WIN32 #define __STDC__ 1 #endif - #include +#ifndef WIN32 +#include +#endif /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ @@ -47,7 +48,7 @@ /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST -#else /* ! __cplusplus */ +#else /* ! __cplusplus */ #ifdef __STDC__ @@ -131,7 +132,7 @@ extern "C" { * int a single C statement (which needs a semi-colon terminator). This * avoids problems with code like: * - * if ( condition_holds ) + * if ( condition_holds ) * yyless( 5 ); * else * do_something_else(); @@ -161,7 +162,7 @@ struct yy_buffer_state FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ + char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. @@ -220,7 +221,7 @@ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ +static int yy_init = 1; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches @@ -394,7 +395,6 @@ char *yytext; #include #include "preparse.h" -#define isatty _isatty #define fileno _fileno #undef YY_DECL #define YY_DECL int yylex YY_PROTO((PDTP ppp)) @@ -406,6 +406,8 @@ char *yytext; #undef yywrap #define yywrap ddwrap #endif /* UNIX */ +int yywrap(void); + static PDTP pp; static void MakeParm(int n); static void MakeMMDD(int n); @@ -520,10 +522,7 @@ YY_DECL if (pp->InFmt) {*pp->InFmt = '\0'; pp->InFmt[pp->Outsize -1] = '\0'; } if (pp->OutFmt) {*pp->OutFmt = '\0'; pp->OutFmt[pp->Outsize -1] = '\0'; } pp->Curp = pp->Format; - if (!yy_init) { /* Restart that stupid Flex otherwise parsing last input */ - yy_init_buffer( yy_current_buffer, yyin ); - yy_load_buffer_state(); - } // endif yy_init + yy_init = 1; /* This is a new input */ if ( yy_init ) @@ -533,7 +532,7 @@ YY_DECL #endif if ( ! yy_start ) - yy_start = 1; /* first start state */ + yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -552,7 +551,7 @@ YY_DECL yy_init = 0; } - while ( 1 ) /* loops until end-of-file is reached */ + while ( 1 ) /* loops until end-of-file is reached */ { yy_cp = yy_c_buf_p; @@ -1114,7 +1113,7 @@ static int input() } c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ + *yy_c_buf_p = '\0'; /* preserve yytext */ yy_hold_char = *++yy_c_buf_p; return c; @@ -1520,6 +1519,10 @@ void Quotout(char *text) int yywrap(void) { + /* Avoid memory leak */ + if (yy_current_buffer) + yy_delete_buffer(yy_current_buffer); + return 1; } /* end of yywrap */ diff --git a/storage/connect/global.h b/storage/connect/global.h index ae50e5ac160..3702f050501 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -239,10 +239,12 @@ DllExport short GetLineLength(PGLOBAL); // Console line length DllExport PGLOBAL PlugInit(LPCSTR, uint); // Plug global initialization DllExport int PlugExit(PGLOBAL); // Plug global termination DllExport LPSTR PlugRemoveType(LPSTR, LPCSTR); -DllExport LPCSTR PlugSetPath(LPSTR, LPCSTR, LPCSTR); +DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir); +DllExport BOOL PlugIsAbsolutePath(LPCSTR path); DllExport void *PlugAllocMem(PGLOBAL, uint); DllExport BOOL PlugSubSet(PGLOBAL, void *, uint); DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t); +DllExport char *PlugDup(PGLOBAL g, const char *str); DllExport void *MakePtr(void *, OFFSET); DllExport void htrc(char const *fmt, ...); diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 8136e6d0263..3325d39f1d8 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -27,11 +27,12 @@ ha_connect will let you create/open/delete tables, the created table can be done specifying an already existing file, the drop table command will just suppress the table definition but not the eventual data file. - Indexes are not yet supported but data can be inserted, updated or deleted. + Indexes are not supported for all table types but data can be inserted, + updated or deleted. You can enable the CONNECT storage engine in your build by doing the following during your build process:
./configure - --with-connect-storage-engine (not implemented yet) + --with-connect-storage-engine You can install the CONNECT handler as all other storage handlers. @@ -122,6 +123,7 @@ #include "tabmysql.h" #endif // MYSQL_SUPPORT #include "filamdbf.h" +#include "tabxcl.h" #include "tabfmt.h" #include "reldef.h" #include "tabcol.h" @@ -136,6 +138,7 @@ #include "mycat.h" #include "myutil.h" #include "preparse.h" +#include "inihandl.h" #define PLGXINI "plgcnx.ini" /* Configuration settings file */ #define my_strupr(p) my_caseup_str(default_charset_info, (p)); @@ -143,10 +146,13 @@ #define my_stricmp(a,b) my_strcasecmp(default_charset_info, (a), (b)) #ifdef LIBXML2_SUPPORT -void XmlInitParserLib(void); -void XmlCleanupParserLib(void); +#include "libdoc.h" #endif // LIBXML2_SUPPORT +#include "taboccur.h" +#include "tabpivot.h" + + /***********************************************************************/ /* DB static variables. */ /***********************************************************************/ @@ -156,7 +162,7 @@ extern "C" char nmfile[]; extern "C" char pdebug[]; extern "C" { - char version[]= "Version 1.01.0004 April 10, 2013"; + char version[]= "Version 1.01.0006 Mai 21, 2013"; #if defined(XMSG) char msglang[]; // Default message language @@ -187,44 +193,13 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, handlerton *connect_hton; /** - structure for CREATE TABLE options (table options) + CREATE TABLE option list (table options) These can be specified in the CREATE TABLE: CREATE TABLE ( ... ) {...here...} */ -struct ha_table_option_struct { - const char *type; - const char *filename; - const char *optname; - const char *tabname; - const char *tablist; - const char *dbname; - const char *separator; -//const char *connect; - const char *qchar; - const char *module; - const char *subtype; - const char *catfunc; - const char *oplist; - const char *data_charset; - ulonglong lrecl; - ulonglong elements; -//ulonglong estimate; - ulonglong multiple; - ulonglong header; - ulonglong quoted; - ulonglong ending; - ulonglong compressed; - bool mapped; - bool huge; - bool split; - bool readonly; - bool sepindex; - }; - ha_create_table_option connect_table_option_list[]= { - // These option are for stand alone Connect tables HA_TOPTION_STRING("TABLE_TYPE", type), HA_TOPTION_STRING("FILE_NAME", filename), HA_TOPTION_STRING("XFILE_NAME", optname), @@ -237,6 +212,8 @@ ha_create_table_option connect_table_option_list[]= HA_TOPTION_STRING("MODULE", module), HA_TOPTION_STRING("SUBTYPE", subtype), HA_TOPTION_STRING("CATFUNC", catfunc), + HA_TOPTION_STRING("SRCDEF", srcdef), + HA_TOPTION_STRING("COLIST", colist), HA_TOPTION_STRING("OPTION_LIST", oplist), HA_TOPTION_STRING("DATA_CHARSET", data_charset), HA_TOPTION_NUMBER("LRECL", lrecl, 0, 0, INT_MAX32, 1), @@ -244,8 +221,8 @@ ha_create_table_option connect_table_option_list[]= //HA_TOPTION_NUMBER("ESTIMATE", estimate, 0, 0, INT_MAX32, 1), HA_TOPTION_NUMBER("MULTIPLE", multiple, 0, 0, 2, 1), HA_TOPTION_NUMBER("HEADER", header, 0, 0, 3, 1), - HA_TOPTION_NUMBER("QUOTED", quoted, -1, 0, 3, 1), - HA_TOPTION_NUMBER("ENDING", ending, -1, 0, INT_MAX32, 1), + HA_TOPTION_NUMBER("QUOTED", quoted, (ulonglong) -1, 0, 3, 1), + HA_TOPTION_NUMBER("ENDING", ending, (ulonglong) -1, 0, INT_MAX32, 1), HA_TOPTION_NUMBER("COMPRESS", compressed, 0, 0, 2, 1), //HA_TOPTION_BOOL("COMPRESS", compressed, 0), HA_TOPTION_BOOL("MAPPED", mapped, 0), @@ -258,25 +235,14 @@ ha_create_table_option connect_table_option_list[]= /** - structure for CREATE TABLE options (field options) + CREATE TABLE option list (field options) These can be specified in the CREATE TABLE per field: CREATE TABLE ( field ... {...here...}, ... ) */ -struct ha_field_option_struct -{ - ulonglong offset; - ulonglong freq; // Not used by this version - ulonglong opt; // Not used by this version - ulonglong fldlen; - const char *dateformat; - const char *fieldformat; - char *special; -}; - ha_create_table_option connect_field_option_list[]= { - HA_FOPTION_NUMBER("FLAG", offset, -1, 0, INT_MAX32, 1), + HA_FOPTION_NUMBER("FLAG", offset, (ulonglong) -1, 0, INT_MAX32, 1), HA_FOPTION_NUMBER("FREQUENCY", freq, 0, 0, INT_MAX32, 1), // not used HA_FOPTION_NUMBER("OPT_VALUE", opt, 0, 0, 2, 1), // used for indexing HA_FOPTION_NUMBER("FIELD_LENGTH", fldlen, 0, 0, INT_MAX32, 1), @@ -327,6 +293,13 @@ static void init_connect_psi_keys() {} #endif +DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR name, LPCSTR dir) +{ + const char *res= PlugSetPath(to, mysql_data_home, name, dir); + return res; +} + + /** @brief If frm_error() is called then we will use this to determine @@ -345,9 +318,8 @@ static void init_connect_psi_keys() {} delete_table method in handler.cc */ static const char *ha_connect_exts[]= { - ".tbl", ".dnx", ".fnx", ".bnx", ".vnx", ".dbx", ".dos", ".fix", ".csv", - ".fmt", ".dbf", ".xml", ".ini", ".vec", ".odbc", ".mysql", ".dir", - ".mac", ".wmi", ".bin", ".oem", + ".dos", ".fix", ".csv",".bin", ".fmt", ".dbf", ".xml", ".ini", ".vec", + ".dnx", ".fnx", ".bnx", ".vnx", ".dbx", NULL }; @@ -381,6 +353,9 @@ static int connect_init_func(void *p) trace= xtrace; } // endif xtrace +#if !defined(WIN32) + PROFILE_Close(connectini); +#endif // !WIN32 init_connect_psi_keys(); @@ -415,6 +390,10 @@ static int connect_done_func(void *p) XmlCleanupParserLib(); #endif // LIBXML2_SUPPORT +#if !defined(WIN32) + PROFILE_End(); +#endif // !WIN32 + for (pc= user_connect::to_users; pc; pc= pn) { if (pc->g) PlugCleanup(pc->g, true); @@ -632,7 +611,7 @@ static char *GetListOption(PGLOBAL g, const char *opname, } else { if (pn) { - n= pn - pk; + n= min(pn - pk, 15); memcpy(key, pk, n); key[n]= 0; } else @@ -687,8 +666,7 @@ char *ha_connect::GetStringOption(char *opname, char *sdef) else if (!stricmp(opname, "Separator")) opval= (char*)options->separator; else if (!stricmp(opname, "Connect")) -// opval= (char*)options->connect; - opval= table->s->connect_string.str; + opval= (tshp) ? tshp->connect_string.str : table->s->connect_string.str; else if (!stricmp(opname, "Qchar")) opval= (char*)options->qchar; else if (!stricmp(opname, "Module")) @@ -697,6 +675,10 @@ char *ha_connect::GetStringOption(char *opname, char *sdef) opval= (char*)options->subtype; else if (!stricmp(opname, "Catfunc")) opval= (char*)options->catfunc; + else if (!stricmp(opname, "Srcdef")) + opval= (char*)options->srcdef; + else if (!stricmp(opname, "Colist")) + opval= (char*)options->colist; else if (!stricmp(opname, "Data_charset")) opval= (char*)options->data_charset; @@ -708,6 +690,14 @@ char *ha_connect::GetStringOption(char *opname, char *sdef) // Return the handler default value if (!stricmp(opname, "Dbname") || !stricmp(opname, "Database")) opval= (char*)GetDBName(NULL); // Current database + else if (!stricmp(opname, "Type")) // Default type + opval= (!options) ? NULL : + (options->srcdef) ? (char*)"MYSQL" : + (options->tabname) ? (char*)"PROXY" : (char*)"DOS"; + else if (!stricmp(opname, "User")) // Connected user + opval= (char *) "root"; + else if (!stricmp(opname, "Host")) // Connected user host + opval= (char *) "localhost"; else opval= sdef; // Caller default @@ -728,7 +718,9 @@ bool ha_connect::GetBooleanOption(char *opname, bool bdef) char *pv; PTOS options= GetTableOptionStruct(table); - if (!options) + if (!stricmp(opname, "View")) + opval= (tshp) ? tshp->is_view : table->s->is_view; + else if (!options) ; else if (!stricmp(opname, "Mapped")) opval= options->mapped; @@ -773,9 +765,9 @@ bool ha_connect::SetBooleanOption(char *opname, bool b) /****************************************************************************/ int ha_connect::GetIntegerOption(char *opname) { - int opval= NO_IVAL; - char *pv; - PTOS options= GetTableOptionStruct(table); + ulonglong opval= NO_IVAL; + char *pv; + PTOS options= GetTableOptionStruct(table); if (!options) ; @@ -799,11 +791,11 @@ int ha_connect::GetIntegerOption(char *opname) else if (!stricmp(opname, "Compressed")) opval= (options->compressed); - if (opval == NO_IVAL && options && options->oplist) + if (opval == (ulonglong)NO_IVAL && options && options->oplist) if ((pv= GetListOption(xp->g, opname, options->oplist))) - opval= atoi(pv); + opval= (unsigned)atoll(pv); - return opval; + return (int)opval; } // end of GetIntegerOption /****************************************************************************/ @@ -852,7 +844,7 @@ PFOS ha_connect::GetFieldOptionStruct(Field *fdp) /****************************************************************************/ /* Returns the column description structure used to make the column. */ /****************************************************************************/ -void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) +void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) { const char *cp; ha_field_option_struct *fop; @@ -870,7 +862,7 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) } else fldp= (tshp) ? tshp->field : table->field; - if (!(fp= *fldp)) + if (!fldp || !(fp= *fldp)) return NULL; // Get the CONNECT field options structure @@ -885,13 +877,13 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) pcf->Name= (char*)fp->field_name; pcf->Prec= 0; - pcf->Opt= (fop) ? fop->opt : 0; + pcf->Opt= (fop) ? (int)fop->opt : 0; if ((pcf->Length= fp->field_length) < 0) pcf->Length= 256; // BLOB? if (fop) { - pcf->Offset= fop->offset; + pcf->Offset= (int)fop->offset; // pcf->Freq= fop->freq; pcf->Datefmt= (char*)fop->dateformat; pcf->Fieldfmt= (char*)fop->fieldformat; @@ -905,7 +897,9 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) switch (fp->type()) { case MYSQL_TYPE_BLOB: case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_VAR_STRING: pcf->Flags |= U_VAR; + /* no break */ case MYSQL_TYPE_STRING: pcf->Type= TYPE_STRING; @@ -941,7 +935,7 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) // Field_length is only used for DATE columns if (fop->fldlen) - pcf->Length= fop->fldlen; + pcf->Length= (int)fop->fldlen; else { int len; @@ -969,6 +963,7 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) break; default: pcf->Type=TYPE_ERROR; + break; } // endswitch type // This is used to skip null bit @@ -980,7 +975,15 @@ void *ha_connect::GetColumnOption(void *field, PCOLINFO pcf) pcf->Flags |= U_VIRTUAL; pcf->Key= 0; // Not used when called from MySQL - pcf->Remark= fp->comment.str; + + // Get the comment if any + if (fp->comment.str && fp->comment.length) { + pcf->Remark= (char*)PlugSubAlloc(g, NULL, fp->comment.length + 1); + memcpy(pcf->Remark, fp->comment.str, fp->comment.length); + pcf->Remark[fp->comment.length] = 0; + } else + pcf->Remark= NULL; + return fldp; } // end of GetColumnOption @@ -1122,8 +1125,9 @@ PTDB ha_connect::GetTDB(PGLOBAL g) table_name= GetTableName(); - if (tdbp && !stricmp(tdbp->GetName(), table_name) - && tdbp->GetMode() == xmod && !xp->CheckQuery(valid_query_id)) { + if (!xp->CheckQuery(valid_query_id) && tdbp + && !stricmp(tdbp->GetName(), table_name) + && tdbp->GetMode() == xmod) { tp= tdbp; tp->SetMode(xmod); } else if ((tp= CntGetTDB(g, table_name, xmod, this))) @@ -1329,6 +1333,7 @@ int ha_connect::MakeRecord(char *buf) break; default: fmt= "%Y-%m-%d %H:%M:%S"; + break; } // endswitch type // Get date in the format required by MySQL fields @@ -1342,6 +1347,7 @@ int ha_connect::MakeRecord(char *buf) // Passthru default: p= value->GetCharString(val); + break; } // endswitch Type if (p) { @@ -1461,6 +1467,7 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf) attribute.charset(), charset, &cnv_errors); value->SetValue_psz(data_charset_value.c_ptr_safe()); } + break; } // endswitch Type #ifdef NEWCHANGE @@ -1568,6 +1575,7 @@ const char *ha_connect::GetValStr(OPVAL vop, bool neg) break; default: val= " ? "; + break; } /* endswitch */ return val; @@ -1874,11 +1882,13 @@ int ha_connect::open(const char *name, int mode, uint test_if_locked) // Try to get the user if possible xp= GetUser(ha_thd(), xp); - PGLOBAL g= xp->g; + PGLOBAL g= (xp) ? xp->g : NULL; // Try to set the database environment if (g) rc= (CntCheckDB(g, this, name)) ? (-2) : 0; + else + rc= HA_ERR_INTERNAL_ERROR; DBUG_RETURN(rc); } // end of open @@ -2168,6 +2178,7 @@ int ha_connect::ReadIndexed(uchar *buf, OPVAL op, const uchar *key, uint key_len DBUG_PRINT("ReadIndexed", ("%s", xp->g->Message)); printf("ReadIndexed: %s\n", xp->g->Message); rc= HA_ERR_INTERNAL_ERROR; + break; } // endswitch RC if (xtrace > 1) @@ -2210,7 +2221,7 @@ int ha_connect::index_read(uchar * buf, const uchar * key, uint key_len, case HA_READ_KEY_EXACT: op= OP_EQ; break; case HA_READ_AFTER_KEY: op= OP_GT; break; case HA_READ_KEY_OR_NEXT: op= OP_GE; break; - default: DBUG_RETURN(-1); + default: DBUG_RETURN(-1); break; } // endswitch find_flag if (xtrace > 1) @@ -2688,18 +2699,24 @@ int ha_connect::delete_all_rows() bool ha_connect::check_privileges(THD *thd, PTOS options) { - if (!options->type) - options->type= "DOS"; + if (!options->type) { + if (options->srcdef) + options->type= "MYSQL"; + else if (options->tabname) + options->type= "PROXY"; + else + options->type= "DOS"; + + } // endif type switch (GetTypeID(options->type)) { case TAB_UNDEF: - case TAB_CATLG: +// case TAB_CATLG: case TAB_PLG: case TAB_JCT: case TAB_DMY: case TAB_NIY: - case TAB_PIVOT: my_printf_error(ER_UNKNOWN_ERROR, "Unsupported table type %s", MYF(0), options->type); return true; @@ -2733,13 +2750,18 @@ bool ha_connect::check_privileges(THD *thd, PTOS options) case TAB_OEM: return check_access(thd, FILE_ACL, NULL, NULL, NULL, 0, 0); + // This is temporary until a solution is found case TAB_TBL: + case TAB_XCL: + case TAB_PRX: + case TAB_OCCUR: + case TAB_PIVOT: return false; } my_printf_error(ER_UNKNOWN_ERROR, "check_privileges failed", MYF(0)); return true; -} +} // end of check_privileges // Check that two indexes are equivalent bool ha_connect::IsSameIndex(PIXDEF xp1, PIXDEF xp2) @@ -2791,12 +2813,14 @@ bool ha_connect::IsSameIndex(PIXDEF xp1, PIXDEF xp2) int ha_connect::external_lock(THD *thd, int lock_type) { int rc= 0; - bool del= false, xcheck=false, cras= false; + bool xcheck=false, cras= false; MODE newmode; PTOS options= GetTableOptionStruct(table); PGLOBAL g= GetPlug(thd, xp); DBUG_ENTER("ha_connect::external_lock"); + DBUG_ASSERT(thd == current_thd); + if (xtrace) printf("%p external_lock: lock_type=%d\n", this, lock_type); @@ -2820,6 +2844,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) case F_UNLCK: default: newmode= MODE_ANY; + break; } // endswitch mode if (newmode == MODE_ANY) { @@ -2831,6 +2856,10 @@ int ha_connect::external_lock(THD *thd, int lock_type) bool oldsep= ((PCHK)g->Xchk)->oldsep; bool newsep= ((PCHK)g->Xchk)->newsep; PTDBDOS tdp= (PTDBDOS)(tdbp ? tdbp : GetTDB(g)); + + if (!tdp) + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + PDOSDEF ddp= (PDOSDEF)tdp->GetDef(); PIXDEF xp, xp1, xp2, drp=NULL, adp= NULL; PIXDEF oldpix= ((PCHK)g->Xchk)->oldpix; @@ -2906,23 +2935,32 @@ int ha_connect::external_lock(THD *thd, int lock_type) } // endelse Xchk - if (CloseTable(g)) + if (CloseTable(g)) { + // This is an error while builing index +#if defined(_DEBUG) + // Make it a warning to avoid crash + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + rc= 0; +#else // !_DEBUG + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; +#endif // !DEBUG + } // endif Close DBUG_RETURN(rc); } // endif MODE_ANY if (xtrace) { - printf("%p external_lock: cmdtype=%d\n", this, thd->lex->sql_command); - printf("Cmd=%.*s\n", (int) thd->query_string.length(), - thd->query_string.str()); + LEX_STRING *query_string= thd_query_string(thd); + printf("%p external_lock: cmdtype=%d\n", this, thd_sql_command(thd)); + printf("Cmd=%.*s\n", (int) query_string->length, query_string->str); } // endif xtrace // Next code is temporarily replaced until sql_command is set stop= false; if (newmode == MODE_WRITE) { - switch (thd->lex->sql_command) { + switch (thd_sql_command(thd)) { case SQLCOM_CREATE_TABLE: case SQLCOM_INSERT: case SQLCOM_LOAD: @@ -2935,7 +2973,6 @@ int ha_connect::external_lock(THD *thd, int lock_type) // break; case SQLCOM_DELETE: case SQLCOM_DELETE_MULTI: - del= true; case SQLCOM_TRUNCATE: newmode= MODE_DELETE; break; @@ -2962,13 +2999,14 @@ int ha_connect::external_lock(THD *thd, int lock_type) newmode= MODE_ANY; break; default: - printf("Unsupported sql_command=%d", thd->lex->sql_command); - sprintf(g->Message, "Unsupported sql_command=%d", thd->lex->sql_command); + printf("Unsupported sql_command=%d", thd_sql_command(thd)); + sprintf(g->Message, "Unsupported sql_command=%d", thd_sql_command(thd)); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + break; } // endswitch newmode } else if (newmode == MODE_READ) { - switch (thd->lex->sql_command) { + switch (thd_sql_command(thd)) { case SQLCOM_CREATE_TABLE: xcheck= true; cras= true; @@ -2999,9 +3037,10 @@ int ha_connect::external_lock(THD *thd, int lock_type) newmode= MODE_ANY; break; default: - printf("Unsupported sql_command=%d", thd->lex->sql_command); - sprintf(g->Message, "Unsupported sql_command=%d", thd->lex->sql_command); + printf("Unsupported sql_command=%d", thd_sql_command(thd)); + sprintf(g->Message, "Unsupported sql_command=%d", thd_sql_command(thd)); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + break; } // endswitch newmode } // endif's newmode @@ -3036,8 +3075,15 @@ int ha_connect::external_lock(THD *thd, int lock_type) // This can NOT be called without open called first, but // the table can have been closed since then } else if (!tdbp || xp->CheckQuery(valid_query_id) || xmod != newmode) { - if (tdbp) - CloseTable(g); + if (tdbp) { + // If this is called by a later query, the table may have + // been already closed and the tdbp is not valid anymore. + if (xp->last_query_id == valid_query_id) + rc= CloseTable(g); + else + tdbp= NULL; + + }// endif tdbp xmod= newmode; @@ -3102,6 +3148,63 @@ THR_LOCK_DATA **ha_connect::store_lock(THD *thd, } +/** + Searches for a pointer to the last occurrence of the + character c in the string src. + Returns true on failure, false on success. +*/ +static bool +strnrchr(LEX_CSTRING *ls, const char *src, size_t length, int c) +{ + const char *srcend, *s; + for (s= srcend= src + length; s > src; s--) + { + if (s[-1] == c) + { + ls->str= s; + ls->length= srcend - s; + return false; + } + } + return true; +} + + +/** + Split filename into database and table name. +*/ +static bool +filename_to_dbname_and_tablename(const char *filename, + char *database, size_t database_size, + char *table, size_t table_size) +{ +#if defined(WIN32) + char slash= '\\'; +#else // !WIN32 + char slash= '/'; +#endif // !WIN32 + LEX_CSTRING d, t; + size_t length= strlen(filename); + + /* Find filename - the rightmost directory part */ + if (strnrchr(&t, filename, length, slash) || t.length + 1 > table_size) + return true; + memcpy(table, t.str, t.length); + table[t.length]= '\0'; + if (!(length-= t.length)) + return true; + + length--; /* Skip slash */ + + /* Find database name - the second rightmost directory part */ + if (strnrchr(&d, filename, length, slash) || d.length + 1 > database_size) + return true; + memcpy(database, d.str, d.length); + database[d.length]= '\0'; + return false; +} + + /** @brief Used to delete or rename a table. By the time delete_table() has been @@ -3128,22 +3231,20 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) DBUG_ENTER("ha_connect::delete_or_rename_table"); /* We have to retrieve the information about this table options. */ ha_table_option_struct *pos; -#if defined(WIN32) - const char *fmt= ".\\%[^\\]\\%s"; -#else // !WIN32 - const char *fmt= "./%[^/]/%s"; -#endif // !WIN32 char key[MAX_DBKEY_LENGTH], db[128], tabname[128]; - int rc; + int rc = 0; uint key_length; TABLE_SHARE *share; THD *thd= current_thd; - if (to) - if (sscanf(to, fmt, db, tabname) != 2 || *tabname == '#') - goto fin; + if (to && (filename_to_dbname_and_tablename(to, db, sizeof(db), + tabname, sizeof(tabname)) || + *tabname == '#')) + goto fin; - if (sscanf(name, fmt, db, tabname) != 2 || *tabname == '#') + if (filename_to_dbname_and_tablename(name, db, sizeof(db), + tabname, sizeof(tabname)) || + *tabname == '#') goto fin; key_length= create_table_def_key(key, db, tabname); @@ -3177,7 +3278,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) err: free_table_share(share); fin: - DBUG_RETURN(0); + DBUG_RETURN(rc); } // end of delete_or_rename_table int ha_connect::delete_table(const char *name) @@ -3267,35 +3368,43 @@ static char *encode(PGLOBAL g, char *cnm) Return 0 if ok */ -bool add_field(String *sql, const char *field_name, const char *type, - int len, int dec, uint tm, const char *rem) +static bool add_field(String *sql, const char *field_name, const char *type, + int len, int dec, uint tm, const char *rem, int flag) { bool error= false; + error|= sql->append('`'); error|= sql->append(field_name); - error|= sql->append(' '); + error|= sql->append("` "); error|= sql->append(type); + if (len) { error|= sql->append('('); error|= sql->append_ulonglong(len); - if (dec) { + + if (dec || !strcmp(type, "DOUBLE")) { error|= sql->append(','); error|= sql->append_ulonglong(dec); - } + } // endif dec + error|= sql->append(')'); - } + } // endif len if (tm) error|= sql->append(STRING_WITH_LEN(" NOT NULL"), system_charset_info); if (rem && *rem) { - error|= sql->append(" COMMENT='"); + error|= sql->append(" COMMENT '"); error|= sql->append_for_single_quote(rem, strlen(rem)); error|= sql->append("'"); - } + } // endif rem + + if (flag) { + error|= sql->append(" FLAG="); + error|= sql->append_ulonglong(flag); + } // endif flag sql->append(','); - return error; } // end of add_field @@ -3314,18 +3423,17 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, { char spc= ',', qch= 0; const char *fncn= "?"; - const char *user, *fn, *tab, *db, *host, *pwd, *prt, *sep; // *csn; - char *dsn; + const char *user, *fn, *db, *host, *pwd, *prt, *sep, *tbl, *src; + const char *col, *ocl, *rnk, *pic, *fcl; + char *tab, *dsn; #if defined(WIN32) char *nsp= NULL, *cls= NULL; #endif // WIN32 - int port= MYSQL_PORT, hdr= 0, mxr= 0, b= 0; + int port= 0, hdr= 0, mxr= 0, b= 0; uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL); - bool ok= false, dbf= false; + bool bif, ok= false, dbf= false; TABTYPE ttp= TAB_UNDEF; - MEM_ROOT *mem= thd->mem_root; - CHARSET_INFO *cs; - PQRYRES qrp; + PQRYRES qrp= NULL; PCOLRES crp; PGLOBAL g= GetPlug(thd, NULL); PTOS topt= table_s->option_struct; @@ -3338,51 +3446,88 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, sql.copy(STRING_WITH_LEN("CREATE TABLE whatever ("), system_charset_info); - user= host= pwd= prt= dsn= NULL; + user= host= pwd= prt= tbl= src= col= ocl= pic= fcl= rnk= dsn= NULL; // Get the useful create options - ttp= GetTypeID(topt->type); - fn= topt->filename; - tab= topt->tabname; - db= topt->dbname; + ttp= GetTypeID(topt->type); + fn= topt->filename; + tab= (char*)topt->tabname; + src= topt->srcdef; + db= topt->dbname; fncn= topt->catfunc; fnc= GetFuncID(fncn); - sep= topt->separator; + sep= topt->separator; spc= (!sep || !strcmp(sep, "\\t")) ? '\t' : *sep; - qch= topt->qchar ? *topt->qchar : topt->quoted >= 0 ? '"' : 0; - hdr= topt->header; + qch= topt->qchar ? *topt->qchar : (signed)topt->quoted >= 0 ? '"' : 0; + hdr= (int)topt->header; + tbl= topt->tablist; + col= topt->colist; + if (topt->oplist) { - host= GetListOption(g,"host", topt->oplist, "localhost"); - user= GetListOption(g,"user", topt->oplist, "root"); - // Default value db can come from the DBNAME=xxx option. - db= GetListOption(g,"database", topt->oplist, db); - pwd= GetListOption(g,"password", topt->oplist); - prt= GetListOption(g,"port", topt->oplist); - port= (prt) ? atoi(prt) : MYSQL_PORT; + host= GetListOption(g,"host", topt->oplist, "localhost"); + user= GetListOption(g,"user", topt->oplist, "root"); + // Default value db can come from the DBNAME=xxx option. + db= GetListOption(g,"database", topt->oplist, db); + col= GetListOption(g,"colist", topt->oplist, col); + ocl= GetListOption(g,"occurcol", topt->oplist, NULL); + pic= GetListOption(g,"pivotcol", topt->oplist, NULL); + fcl= GetListOption(g,"fnccol", topt->oplist, NULL); + rnk= GetListOption(g,"rankcol", topt->oplist, NULL); + pwd= GetListOption(g,"password", topt->oplist); + prt= GetListOption(g,"port", topt->oplist); + port= (prt) ? atoi(prt) : 0; #if defined(WIN32) - nsp= GetListOption(g,"namespace", topt->oplist); - cls= GetListOption(g,"class", topt->oplist); + nsp= GetListOption(g,"namespace", topt->oplist); + cls= GetListOption(g,"class", topt->oplist); #endif // WIN32 - mxr= atoi(GetListOption(g,"maxerr", topt->oplist, "0")); - } // endelse option_list + mxr= atoi(GetListOption(g,"maxerr", topt->oplist, "0")); + } else { + host= "localhost"; + user= "root"; + } // endif option_list if (!db) - db= thd->db; // Default value + db= table_s->db.str; // Default value // Check table type if (ttp == TAB_UNDEF) { - strcpy(g->Message, "No table_type. Was set to DOS"); + topt->type= (src) ? "MYSQL" : (tab) ? "PROXY" : "DOS"; + ttp= GetTypeID(topt->type); + sprintf(g->Message, "No table_type. Was set to %s", topt->type); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); - ttp= TAB_DOS; - topt->type= "DOS"; } else if (ttp == TAB_NIY) { sprintf(g->Message, "Unsupported table type %s", topt->type); my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); return HA_ERR_INTERNAL_ERROR; } // endif ttp - if (!tab && !(fnc & (FNC_TABLE | FNC_COL))) - tab= (char*)create_info->alias; + if (!tab) { + if (ttp == TAB_TBL) { + // Make tab the first table of the list + char *p; + + if (!tbl) { + strcpy(g->Message, "Missing table list"); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + return HA_ERR_INTERNAL_ERROR; + } // endif tbl + + tab= (char*)PlugSubAlloc(g, NULL, strlen(tbl) + 1); + strcpy(tab, tbl); + + if ((p= strchr(tab, ','))) + *p= 0; + + if ((p=strchr(tab, '.'))) { + *p= 0; + db= tab; + tab= p + 1; + } // endif p + + } else if (ttp != TAB_ODBC || !(fnc & (FNC_TABLE | FNC_COL))) + tab= (char*)create_info->alias; + + } // endif tab switch (ttp) { #if defined(ODBC_SUPPORT) @@ -3433,7 +3578,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ok= false; } else if (!user) - user= "root"; // Avoid crash + user= "root"; break; #endif // MYSQL_SUPPORT @@ -3442,8 +3587,17 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ok= true; break; #endif // WIN32 + case TAB_PIVOT: + supfnc = FNC_NO; + case TAB_PRX: + case TAB_TBL: + case TAB_XCL: + case TAB_OCCUR: + ok= true; + break; default: sprintf(g->Message, "Cannot get column info for table type %s", topt->type); + break; } // endif ttp // Check for supported catalog function @@ -3453,19 +3607,36 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ok= false; } // endif supfnc + if (src && fnc != FNC_NO) { + strcpy(g->Message, "Cannot make catalog table from srcdef"); + ok= false; + } // endif src + + // Here we should test the flag column options when + // this function is called in case of CREATE .. SELECT + if (ok) { char *cnm, *rem; - int i, len, dec, typ; + int i, len, dec, typ, flg; const char *type; PDBUSER dup= PlgGetUser(g); PCATLG cat= (dup) ? dup->Catalog : NULL; if (cat) - cat->SetDataPath(g, thd->db); + cat->SetDataPath(g, table_s->db.str); else return HA_ERR_INTERNAL_ERROR; // Should never happen - switch (ttp) { + if (src && ttp != TAB_PIVOT) { + qrp= SrcColumns(g, host, db, user, pwd, src, port); + + if (qrp && ttp == TAB_OCCUR) + if (OcrSrcCols(g, qrp, col, ocl, rnk)) { + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + return HA_ERR_INTERNAL_ERROR; + } // endif OcrSrcCols + + } else switch (ttp) { case TAB_DBF: qrp= DBFColumns(g, fn, fnc == FNC_COL); break; @@ -3487,6 +3658,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, break; default: sprintf(g->Message, "invalid catfunc %s", fncn); + break; } // endswitch info break; @@ -3494,7 +3666,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, #if defined(MYSQL_SUPPORT) case TAB_MYSQL: qrp= MyColumns(g, host, db, user, pwd, tab, - NULL, port, false, fnc == FNC_COL); + NULL, port, fnc == FNC_COL); break; #endif // MYSQL_SUPPORT case TAB_CSV: @@ -3505,6 +3677,26 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, qrp= WMIColumns(g, nsp, cls, fnc == FNC_COL); break; #endif // WIN32 + case TAB_PRX: + case TAB_TBL: + case TAB_XCL: + case TAB_OCCUR: + bif= fnc == FNC_COL; + qrp= TabColumns(g, thd, db, tab, bif); + + if (!qrp && bif && fnc != FNC_COL) // tab is a view + qrp= MyColumns(g, host, db, user, pwd, tab, NULL, port, false); + + if (qrp && ttp == TAB_OCCUR && fnc != FNC_COL) + if (OcrColumns(g, qrp, col, ocl, rnk)) { + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + return HA_ERR_INTERNAL_ERROR; + } // endif OcrColumns + + break; + case TAB_PIVOT: + qrp= PivotColumns(g, tab, src, pic, fcl, host, db, user, pwd, port); + break; default: strcpy(g->Message, "System error during assisted discovery"); break; @@ -3515,15 +3707,17 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, return HA_ERR_INTERNAL_ERROR; } // endif qrp - if (fnc != FNC_NO) { - // Catalog table - for (crp=qrp->Colresp; !b && crp; crp= crp->Next) { + if (fnc != FNC_NO || src || ttp == TAB_PIVOT) { + // Catalog like table + for (crp= qrp->Colresp; !b && crp; crp= crp->Next) { cnm= encode(g, crp->Name); type= PLGtoMYSQLtype(crp->Type, dbf); len= crp->Length; + dec= crp->Prec; + flg= crp->Flag; // Now add the field - if (add_field(&sql, cnm, type, len, 0, NOT_NULL_FLAG, 0)) + if (add_field(&sql, cnm, type, len, dec, NOT_NULL_FLAG, 0, flg)) b= HA_ERR_OUT_OF_MEM; } // endfor crp @@ -3532,7 +3726,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, rem= NULL; typ= len= dec= 0; tm= NOT_NULL_FLAG; - cs= NULL; + cnm= (char*)"noname"; for (crp= qrp->Colresp; crp; crp= crp->Next) switch (crp->Fld) { @@ -3587,11 +3781,16 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, } // endif ttp #endif // ODBC_SUPPORT + // Make the arguments as required by add_fields type= PLGtoMYSQLtype(typ, true); + if (typ == TYPE_DATE) len= 0; - if (add_field(&sql, cnm, type, len, dec, tm, rem)) + + // Now add the field + if (add_field(&sql, cnm, type, len, dec, tm, rem, 0)) b= HA_ERR_OUT_OF_MEM; + } // endfor i sql.length(sql.length()-1); // remove the trailing comma @@ -3602,59 +3801,79 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ulonglong vull; const char *vstr; bool oom= false; + switch (opt->type) { case HA_OPTION_TYPE_ULL: - vull= *(ulonglong*)(((char*)topt) + opt->offset); + vull= *(ulonglong*)(((char*)topt) + opt->offset); + if (vull != opt->def_value) { oom|= sql.append(' '); oom|= sql.append(opt->name); oom|= sql.append('='); oom|= sql.append_ulonglong(vull); - } + } // endif vull + break; case HA_OPTION_TYPE_STRING: - vstr= *(char**)(((char*)topt) + opt->offset); + vstr= *(char**)(((char*)topt) + opt->offset); + if (vstr) { oom|= sql.append(' '); oom|= sql.append(opt->name); oom|= sql.append("='"); oom|= sql.append_for_single_quote(vstr, strlen(vstr)); oom|= sql.append('\''); - } + } // endif vstr + break; case HA_OPTION_TYPE_BOOL: - vull= *(bool*)(((char*)topt) + opt->offset); + vull= *(bool*)(((char*)topt) + opt->offset); + if (vull != opt->def_value) { oom|= sql.append(' '); oom|= sql.append(opt->name); oom|= sql.append('='); oom|= sql.append(vull ? "ON" : "OFF"); - } + } // endif vull + break; default: // no enums here, good :) break; - } + } // endswitch type + if (oom) b= HA_ERR_OUT_OF_MEM; - } + + } // endfor opt if (create_info->connect_string.length) { bool oom= false; + oom|= sql.append(' '); oom|= sql.append("CONNECTION='"); oom|= sql.append_for_single_quote(create_info->connect_string.str, create_info->connect_string.length); oom|= sql.append('\''); + if (oom) b= HA_ERR_OUT_OF_MEM; - } + + } // endif string if (create_info->default_table_charset) { bool oom= false; + oom|= sql.append(' '); oom|= sql.append("CHARSET="); oom|= sql.append(create_info->default_table_charset->csname); - } + + if (oom) + b= HA_ERR_OUT_OF_MEM; + + } // endif charset + + if (xtrace) + printf("s_init: %.*s\n", sql.length(), sql.ptr()); if (!b) b= table_s->init_from_sql_statement_string(thd, true, @@ -3664,7 +3883,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); return HA_ERR_INTERNAL_ERROR; -} // end of pre_create +} // end of connect_assisted_discovery /** @brief @@ -3700,7 +3919,8 @@ int ha_connect::create(const char *name, TABLE *table_arg, Field *fp; TABTYPE type; TABLE *st= table; // Probably unuseful - xp= GetUser(ha_thd(), xp); + THD *thd= ha_thd(); + xp= GetUser(thd, xp); PGLOBAL g= xp->g; DBUG_ENTER("ha_connect::create"); @@ -3710,7 +3930,20 @@ int ha_connect::create(const char *name, TABLE *table_arg, DBUG_ASSERT(options); type= GetTypeID(options->type); - if (check_privileges(ha_thd(), options)) + // Check table type + if (type == TAB_UNDEF) { + options->type= (options->srcdef) ? "MYSQL" : + (options->tabname) ? "PROXY" : "DOS"; + type= GetTypeID(options->type); + sprintf(g->Message, "No table_type. Will be set to %s", options->type); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + } else if (type == TAB_NIY) { + sprintf(g->Message, "Unsupported table type %s", options->type); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif ttp + + if (check_privileges(thd, options)) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); if (options->data_charset) { @@ -3737,6 +3970,35 @@ int ha_connect::create(const char *name, TABLE *table_arg, } else dbf= (GetTypeID(options->type) == TAB_DBF && !options->catfunc); + // Can be null in ALTER TABLE + if (create_info->alias) + // Check whether a table is defined on itself + switch (type) { + case TAB_PRX: + case TAB_XCL: + case TAB_OCCUR: + if (options->srcdef) { + strcpy(g->Message, "Cannot check looping reference"); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + } else if (options->tabname) { + if (!stricmp(options->tabname, create_info->alias) && + (!options->dbname || !stricmp(options->dbname, table_arg->s->db.str))) { + sprintf(g->Message, "A %s table cannot refer to itself", + options->type); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif tab + + } else { + strcpy(g->Message, "Missing object table name or definition"); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif tabname + + default: /* do nothing */; + break; + } // endswitch ttp + if (type == TAB_XML) { bool dom; // True: MS-DOM, False libxml2 char *xsup= GetListOption(g, "Xmlsup", options->oplist, "*"); @@ -3757,6 +4019,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, break; default: dom= false; + break; } // endswitch xsup #if !defined(DOMDOC_SUPPORT) @@ -3795,6 +4058,14 @@ int ha_connect::create(const char *name, TABLE *table_arg, DBUG_RETURN(rc); } // endif flags + if (fp->flags & (BLOB_FLAG | ENUM_FLAG | SET_FLAG)) { + sprintf(g->Message, "Unsupported type for column %s", + fp->field_name); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + rc= HA_ERR_INTERNAL_ERROR; + DBUG_RETURN(rc); + } // endif flags + switch (fp->type()) { case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: @@ -3834,6 +4105,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, "Unsupported type for column '%s'", MYF(0), fp->field_name); DBUG_RETURN(rc); + break; } // endswitch type if ((fp)->real_maybe_null() && !IsTypeNullable(type)) { @@ -3906,8 +4178,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, strcat(strcat(buf, "."), lwt); sprintf(g->Message, "No file name. Table will use %s", buf); - push_warning(table->in_use, - MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); strcat(strcat(strcpy(dbpath, "./"), table->s->db.str), "/"); PlugSetPath(fn, buf, dbpath); @@ -3935,8 +4206,8 @@ int ha_connect::create(const char *name, TABLE *table_arg, PIXDEF xdp; // We should be in CREATE TABLE - if (table->in_use->lex->sql_command != SQLCOM_CREATE_TABLE) - push_warning(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN, 0, + if (thd_sql_command(table->in_use) != SQLCOM_CREATE_TABLE) + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, "Wrong command in create, please contact CONNECT team"); // Get the index definitions @@ -3945,7 +4216,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, PCATLG cat= (dup) ? dup->Catalog : NULL; if (cat) { - cat->SetDataPath(g, table_arg->in_use->db); + cat->SetDataPath(g, table_arg->s->db.str); if ((rc= optimize(table->in_use, NULL))) { printf("Create rc=%d %s\n", rc, g->Message); diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index b8c92479543..abf82b2d1a8 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -1,4 +1,4 @@ -/* Copyright (C) Olivier Bertrand 2004 - 2011 +/* Copyright (C) Olivier Bertrand 2004 - 2013 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 @@ -64,6 +64,61 @@ typedef struct ha_field_option_struct FOS, *PFOS; extern handlerton *connect_hton; +/** + structure for CREATE TABLE options (table options) + + These can be specified in the CREATE TABLE: + CREATE TABLE ( ... ) {...here...} +*/ +struct ha_table_option_struct { + const char *type; + const char *filename; + const char *optname; + const char *tabname; + const char *tablist; + const char *dbname; + const char *separator; +//const char *connect; + const char *qchar; + const char *module; + const char *subtype; + const char *catfunc; + const char *srcdef; + const char *colist; + const char *oplist; + const char *data_charset; + ulonglong lrecl; + ulonglong elements; +//ulonglong estimate; + ulonglong multiple; + ulonglong header; + ulonglong quoted; + ulonglong ending; + ulonglong compressed; + bool mapped; + bool huge; + bool split; + bool readonly; + bool sepindex; + }; + +/** + structure for CREATE TABLE options (field options) + + These can be specified in the CREATE TABLE per field: + CREATE TABLE ( field ... {...here...}, ... ) +*/ +struct ha_field_option_struct +{ + ulonglong offset; + ulonglong freq; // Not used by this version + ulonglong opt; // Not used by this version + ulonglong fldlen; + const char *dateformat; + const char *fieldformat; + char *special; +}; + /** @brief CONNECT_SHARE is a structure that will be shared among all open handlers. This example implements the minimum of what you will probably need. @@ -99,7 +154,7 @@ public: int GetIntegerOption(char *opname); bool SetIntegerOption(char *opname, int n); PFOS GetFieldOptionStruct(Field *fp); - void *GetColumnOption(void *field, PCOLINFO pcf); + void *GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf); PIXDEF GetIndexInfo(void); const char *GetDBName(const char *name); const char *GetTableName(void); @@ -143,8 +198,7 @@ public: { return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_HAS_RECORDS | HA_NO_AUTO_INCREMENT | HA_NO_PREFIX_CHAR_KEYS | - HA_NO_COPY_ON_ALTER | - HA_CAN_VIRTUAL_COLUMNS | + HA_NO_COPY_ON_ALTER | HA_CAN_VIRTUAL_COLUMNS | HA_NULL_IN_KEY | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE); } diff --git a/storage/connect/inihandl.c b/storage/connect/inihandl.c index 25629b04e60..0dc7a53faf3 100644 --- a/storage/connect/inihandl.c +++ b/storage/connect/inihandl.c @@ -29,9 +29,8 @@ //#include //#include #include "my_global.h" -//#include "osutil.h" #include "global.h" - +#include "inihandl.h" // The types and variables used locally //typedef int bool; @@ -609,6 +608,31 @@ void PROFILE_Close(LPCSTR filename) } // end of PROFILE_Close +/*********************************************************************** + * PROFILE_End + * + * Terminate and release the cache. + ***********************************************************************/ +void PROFILE_End(void) +{ + int i; + + if (trace) + htrc("PROFILE_End: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES); + + /* Close all opened files and free the cache structure */ + for (i = 0; i < N_CACHED_PROFILES; i++) { + if (trace) + htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i); + + CurProfile = MRUProfile[i]; + PROFILE_ReleaseFile(); + free(MRUProfile[i]); + } // endfor i + +} // end of PROFILE_End + + /*********************************************************************** * PROFILE_DeleteSection * @@ -672,7 +696,7 @@ static BOOL PROFILE_DeleteKey(PROFILESECTION* *section, * * Delete all keys from a profile tree. ***********************************************************************/ -void PROFILE_DeleteAllKeys(LPCSTR section_name) +static void PROFILE_DeleteAllKeys(LPCSTR section_name) { PROFILESECTION* *section= &CurProfile->section; @@ -1038,6 +1062,7 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name, * Convenience function that turns a string 'xxx, yyy, zzz' into * the 'xxx\0 yyy, zzz' and returns a pointer to the 'yyy, zzz'. ***********************************************************************/ +#if 0 char *PROFILE_GetStringItem(char* start) { char *lpchX, *lpch; @@ -1065,6 +1090,7 @@ char *PROFILE_GetStringItem(char* start) return NULL; } // end of PROFILE_GetStringItem +#endif /********************************************************************** * if allow_section_name_copy is TRUE, allow the copying : @@ -1132,7 +1158,7 @@ static int PROFILE_GetPrivateProfileString(LPCSTR section, LPCSTR entry, * GetPrivateProfileStringA (KERNEL32.@) ***********************************************************************/ int GetPrivateProfileString(LPCSTR section, LPCSTR entry, LPCSTR def_val, - LPSTR buffer, uint len, LPCSTR filename) + LPSTR buffer, DWORD len, LPCSTR filename) { return PROFILE_GetPrivateProfileString(section, entry, def_val, buffer, len, filename, TRUE); @@ -1308,7 +1334,8 @@ BOOL WritePrivateProfileSection(LPCSTR section, * Note that when the buffer is big enough then the return value may be any * value between 1 and len-1 (or len in Win95), including len-2. */ -DWORD GetPrivateProfileSectionNames(LPSTR buffer, DWORD size, LPCSTR filename) +static DWORD +GetPrivateProfileSectionNames(LPSTR buffer, DWORD size, LPCSTR filename) { DWORD ret = 0; diff --git a/storage/connect/inihandl.h b/storage/connect/inihandl.h new file mode 100644 index 00000000000..f0b7c9afe5c --- /dev/null +++ b/storage/connect/inihandl.h @@ -0,0 +1,55 @@ +#ifndef __INIHANDL_H__ +#define __INIHANDL_H__ + +#if defined(UNIX) || defined(UNIV_LINUX) + +#ifdef __cplusplus +extern "C" { +#endif + +void PROFILE_Close(LPCSTR filename); +void PROFILE_End(void); + +int GetPrivateProfileString( + LPCTSTR lpAppName, // section name + LPCTSTR lpKeyName, // key name + LPCTSTR lpDefault, // default string + LPTSTR lpReturnedString, // destination buffer + DWORD nSize, // size of destination buffer + LPCTSTR lpFileName // initialization file name + ); + +uint GetPrivateProfileInt( + LPCTSTR lpAppName, // section name + LPCTSTR lpKeyName, // key name + INT nDefault, // return value if key name not found + LPCTSTR lpFileName // initialization file name + ); + +BOOL WritePrivateProfileString( + LPCTSTR lpAppName, // section name + LPCTSTR lpKeyName, // key name + LPCTSTR lpString, // string to add + LPCTSTR lpFileName // initialization file + ); + +int GetPrivateProfileSection( + LPCTSTR lpAppName, // section name + LPTSTR lpReturnedString, // return buffer + DWORD nSize, // size of return buffer + LPCTSTR lpFileName // initialization file name + ); + +BOOL WritePrivateProfileSection( + LPCTSTR lpAppName, // section name + LPCTSTR lpString, // data + LPCTSTR lpFileName // file name + ); + +#ifdef __cplusplus +} +#endif + +#endif /* defined(UNIX) */ + +#endif /* __INIHANDL_H__ */ diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp index 95b98931680..45f379350f5 100644 --- a/storage/connect/libdoc.cpp +++ b/storage/connect/libdoc.cpp @@ -25,11 +25,207 @@ #include "sql_string.h" +/******************************************************************/ +/* Declaration of XML document processing using libxml2 */ +/* Author: Olivier Bertrand 2007-2012 */ +/******************************************************************/ +#include "plgxml.h" + +typedef class LIBXMLDOC *PXDOC2; +typedef class XML2NODE *PNODE2; +typedef class XML2ATTR *PATTR2; +typedef class XML2NODELIST *PLIST2; + +/******************************************************************/ +/* XML2 block. Must have the same layout than FBLOCK up to Type. */ +/******************************************************************/ +typedef struct _x2block { /* Loaded XML file block */ + struct _x2block *Next; + LPCSTR Fname; /* Point on file name */ + size_t Length; /* Used to tell if read mode */ + short Count; /* Nb of times file is used */ + short Type; /* TYPE_FB_XML */ + int Retcode; /* Return code from Load */ + xmlDocPtr Docp; /* Document interface pointer */ +// xmlXPathContextPtr Ctxp; +// xmlXPathObjectPtr Xop; + } X2BLOCK, *PX2BLOCK; + +/******************************************************************/ +/* Declaration of libxml2 document. */ +/******************************************************************/ +class LIBXMLDOC : public XMLDOCUMENT { + friend class XML2NODE; + friend class XML2ATTR; + public: + // Constructor + LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp); + + // Properties + virtual short GetDocType(void) {return TYPE_FB_XML2;} + virtual void *GetDocPtr(void) {return Docp;} + virtual void SetNofree(bool b) {Nofreelist = b;} + + // Methods + virtual bool Initialize(PGLOBAL g); + virtual bool ParseFile(char *fn); + virtual bool NewDoc(PGLOBAL g, char *ver); + virtual void AddComment(PGLOBAL g, char *com); + virtual PXNODE GetRoot(PGLOBAL g); + virtual PXNODE NewRoot(PGLOBAL g, char *name); + virtual PXNODE NewPnode(PGLOBAL g, char *name); + virtual PXATTR NewPattr(PGLOBAL g); + virtual PXLIST NewPlist(PGLOBAL g); + virtual int DumpDoc(PGLOBAL g, char *ofn); + virtual void CloseDoc(PGLOBAL g, PFBLOCK xp); + virtual PFBLOCK LinkXblock(PGLOBAL g, MODE m, int rc, char *fn); + + protected: +// bool CheckDocument(FILE *of, xmlNodePtr np); + xmlNodeSetPtr GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp); + int Decode(xmlChar *cnt, char *buf, int n); + xmlChar *Encode(PGLOBAL g, char *txt); + + // Members + xmlDocPtr Docp; + xmlNodeSetPtr Nlist; + xmlXPathContextPtr Ctxp; + xmlXPathObjectPtr Xop; + char *Buf; // Temporary + bool Nofreelist; +}; // end of class LIBXMLDOC + +/******************************************************************/ +/* Declaration of libxml2 node. */ +/******************************************************************/ +class XML2NODE : public XMLNODE { + friend class LIBXMLDOC; + friend class XML2NODELIST; + public: + // Properties + virtual char *GetName(PGLOBAL g) {return (char*)Nodep->name;} + virtual int GetType(void); + virtual PXNODE GetNext(PGLOBAL g); + virtual PXNODE GetChild(PGLOBAL g); + + // Methods + virtual RCODE GetContent(PGLOBAL g, char *buf, int len); + virtual bool SetContent(PGLOBAL g, char *txtp, int len); + virtual PXNODE Clone(PGLOBAL g, PXNODE np); + virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp); + virtual PXLIST SelectNodes(PGLOBAL g, char *xp, PXLIST lp); + virtual PXNODE SelectSingleNode(PGLOBAL g, char *xp, PXNODE np); + virtual PXATTR GetAttribute(PGLOBAL g, char *name, PXATTR ap); + virtual PXNODE AddChildNode(PGLOBAL g, char *name, PXNODE np); + virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap); + virtual void AddText(PGLOBAL g, char *txtp); + virtual void DeleteChild(PGLOBAL g, PXNODE dnp); + + protected: + // Constructor + XML2NODE(PXDOC dp, xmlNodePtr np); + + // Members + xmlDocPtr Docp; + xmlChar *Content; + xmlNodePtr Nodep; +}; // end of class XML2NODE + +/******************************************************************/ +/* Declaration of libxml2 node list. */ +/******************************************************************/ +class XML2NODELIST : public XMLNODELIST { + friend class LIBXMLDOC; + friend class XML2NODE; + public: + // Methods + virtual int GetLength(void); + virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np); + + protected: + // Constructor + XML2NODELIST(PXDOC dp, xmlNodeSetPtr lp); + + // Members + xmlNodeSetPtr Listp; +}; // end of class XML2NODELIST + +/******************************************************************/ +/* Declaration of libxml2 attribute. */ +/******************************************************************/ +class XML2ATTR : public XMLATTRIBUTE { + friend class LIBXMLDOC; + friend class XML2NODE; + public: + // Properties +//virtual char *GetText(void); + + // Methods + virtual bool SetText(PGLOBAL g, char *txtp, int len); + + protected: + // Constructor + XML2ATTR(PXDOC dp, xmlAttrPtr ap, xmlNodePtr np); + + // Members + xmlAttrPtr Atrp; + xmlNodePtr Parent; +}; // end of class XML2ATTR + + + extern "C" { extern char version[]; extern int trace; } // "C" +#if defined(MEMORY_TRACE) +static xmlFreeFunc Free; +static xmlMallocFunc Malloc; +static xmlMallocFunc MallocA; +static xmlReallocFunc Realloc; +static xmlStrdupFunc Strdup; + +void xmlMyFree(void *mem) +{ + if (trace) + htrc("Freeing at %p\n", mem); + Free(mem); +} // end of xmlMyFree + +void *xmlMyMalloc(size_t size) +{ + void *p = Malloc(size); + if (trace) + htrc("Allocating %.5d at %p\n", size, p); + return p; +} // end of xmlMyMalloc + +void *xmlMyMallocAtomic(size_t size) +{ + void *p = MallocA(size); + if (trace) + htrc("Atom alloc %.5d at %p\n", size, p); + return p; +} // end of xmlMyMallocAtomic + +void *xmlMyRealloc(void *mem, size_t size) +{ + void *p = Realloc(mem, size); + if (trace) + htrc("ReAlloc %.5d to %p from %p\n", size, p, mem); + return p; +} // end of xmlMyRealloc + +char *xmlMyStrdup(const char *str) +{ + char *p = Strdup(str); + if (trace) + htrc("Duplicating to %p from %p %s\n", p, str, str); + return p; +} // end of xmlMyStrdup +#endif // MEMORY_TRACE + /******************************************************************/ /* Return a LIBXMLDOC as a XMLDOC. */ /******************************************************************/ @@ -44,6 +240,17 @@ PXDOC GetLibxmlDoc(PGLOBAL g, char *nsl, char *nsdf, /******************************************************************/ void XmlInitParserLib(void) { +#if defined(MEMORY_TRACE) +int rc = xmlGcMemGet(&Free, &Malloc, &MallocA, &Realloc, &Strdup); + +if (!rc) + rc = xmlGcMemSetup(xmlMyFree, + xmlMyMalloc, + xmlMyMallocAtomic, + xmlMyRealloc, + xmlMyStrdup); + +#endif // MEMORY_TRACE xmlInitParser(); } // end of XmlInitParserLib @@ -63,6 +270,9 @@ void CloseXML2File(PGLOBAL g, PFBLOCK fp, bool all) { PX2BLOCK xp = (PX2BLOCK)fp; + if (trace) + htrc("CloseXML2File: xp=%p count=%d\n", xp, (xp) ? xp->Count : 0); + if (xp && xp->Count > 1 && !all) { xp->Count--; } else if (xp && xp->Count > 0) { @@ -85,6 +295,8 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp) Nlist = NULL; Ctxp = NULL; Xop = NULL; + Buf = NULL; + Nofreelist = false; } // end of LIBXMLDOC constructor /******************************************************************/ @@ -101,6 +313,9 @@ bool LIBXMLDOC::Initialize(PGLOBAL g) /******************************************************************/ bool LIBXMLDOC::ParseFile(char *fn) { + if (trace) + htrc("ParseFile\n"); + if ((Docp = xmlParseFile(fn))) { if (Docp->encoding) Encoding = (char*)Docp->encoding; @@ -149,6 +364,9 @@ bool LIBXMLDOC::NewDoc(PGLOBAL g, char *ver) /******************************************************************/ void LIBXMLDOC::AddComment(PGLOBAL g, char *txtp) { + if (trace) + htrc("AddComment: %s\n", txtp); + xmlNodePtr cp = xmlNewDocComment(Docp, BAD_CAST txtp); xmlAddChild((xmlNodePtr)Docp, cp); } // end of AddText @@ -158,6 +376,9 @@ void LIBXMLDOC::AddComment(PGLOBAL g, char *txtp) /******************************************************************/ PXNODE LIBXMLDOC::GetRoot(PGLOBAL g) { + if (trace) + htrc("GetRoot\n"); + xmlNodePtr root = xmlDocGetRootElement(Docp); if (!root) @@ -171,6 +392,9 @@ PXNODE LIBXMLDOC::GetRoot(PGLOBAL g) /******************************************************************/ PXNODE LIBXMLDOC::NewRoot(PGLOBAL g, char *name) { + if (trace) + htrc("NewRoot: %s\n", name); + xmlNodePtr root = xmlNewDocNode(Docp, NULL, BAD_CAST name, NULL); if (root) { @@ -186,6 +410,9 @@ PXNODE LIBXMLDOC::NewRoot(PGLOBAL g, char *name) /******************************************************************/ PXNODE LIBXMLDOC::NewPnode(PGLOBAL g, char *name) { + if (trace) + htrc("NewNode: %s\n", name); + xmlNodePtr nop; if (name) { @@ -224,6 +451,9 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn) int rc = 0; FILE *of; + if (trace) + htrc("DumpDoc: %s\n", ofn); + if (!(of= global_fopen(g, MSGID_CANNOT_OPEN, ofn, "w"))) return -1; @@ -264,7 +494,13 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn) /******************************************************************/ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp) { + if (trace) + htrc("CloseDoc: xp=%p count=%d\n", xp, (xp) ? xp->Count : 0); + if (xp && xp->Count == 1) { + if (Nlist) + xmlXPathFreeNodeSet(Nlist); + if (Xop) xmlXPathFreeObject(Xop); @@ -284,12 +520,18 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) xmlNodeSetPtr nl; if (trace) - htrc("GetNodeList %s np=%p\n", xp, np); + htrc("GetNodeList: %s np=%p\n", xp, np); if (!Ctxp) { // Init Xpath + if (trace) + htrc("Calling xmlPathInit\n"); + xmlXPathInit(); + if (trace) + htrc("Calling xmlXPathNewContext Docp=%p\n", Docp); + // Create xpath evaluation context if (!(Ctxp = xmlXPathNewContext(Docp))) { strcpy(g->Message, MSG(XPATH_CNTX_ERR)); @@ -301,7 +543,11 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) } // endif xpathCtx // Register namespaces from list (if any) - for (PNS nsp = Namespaces; nsp; nsp = nsp->Next) + for (PNS nsp = Namespaces; nsp; nsp = nsp->Next) { + if (trace) + htrc("Calling xmlXPathRegisterNs Prefix=%s Uri=%s\n", + nsp->Prefix, nsp->Uri); + if (xmlXPathRegisterNs(Ctxp, BAD_CAST nsp->Prefix, BAD_CAST nsp->Uri)) { sprintf(g->Message, MSG(REGISTER_ERR), nsp->Prefix, nsp->Uri); @@ -312,12 +558,27 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) return NULL; } // endif Registering - } else - xmlXPathFreeNodeSetList(Xop); // To be checked + } // endfor nsp + + } else { + if (trace) + htrc("Calling xmlXPathFreeNodeSetList Xop=%p\n", Xop); + + if (Nofreelist) { + // Making Nlist that must not be freed yet + xmlXPathFreeNodeSetList(Xop); // Caused memory leak + Nofreelist = false; + } else + xmlXPathFreeObject(Xop); // Caused node not found + + } // endif Ctxp // Set the context to the calling node Ctxp->node = np; + if (trace) + htrc("Calling xmlXPathEval %s Ctxp=%p\n", xp, Ctxp); + // Evaluate table xpath if (!(Xop = xmlXPathEval(BAD_CAST xp, Ctxp))) { sprintf(g->Message, MSG(XPATH_EVAL_ERR), xp); @@ -439,6 +700,9 @@ int XML2NODE::GetType(void) /******************************************************************/ PXNODE XML2NODE::GetNext(PGLOBAL g) { + if (trace) + htrc("GetNext\n"); + if (!Nodep->next) Next = NULL; else if (!Next) @@ -452,6 +716,9 @@ PXNODE XML2NODE::GetNext(PGLOBAL g) /******************************************************************/ PXNODE XML2NODE::GetChild(PGLOBAL g) { + if (trace) + htrc("GetChild\n"); + if (!Nodep->children) Children = NULL; else if (!Children) @@ -467,6 +734,9 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) { RCODE rc = RC_OK; + if (trace) + htrc("GetContent\n"); + if (Content) xmlFree(Content); @@ -505,18 +775,24 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) } else *buf = '\0'; + if (trace) + htrc("GetContent: %s\n", buf); + return rc; - } // end of GetText + } // end of GetContent /******************************************************************/ /* Set the content of a node. */ /******************************************************************/ bool XML2NODE::SetContent(PGLOBAL g, char *txtp, int len) { + if (trace) + htrc("SetContent: %s\n", txtp); + xmlChar *buf = xmlEncodeEntitiesReentrant(Docp, BAD_CAST txtp); if (trace) - htrc("SetContent %s -> %s\n", txtp, buf); + htrc("SetContent: %s -> %s\n", txtp, buf); xmlNodeSetContent(Nodep, buf); xmlFree(buf); @@ -528,6 +804,9 @@ bool XML2NODE::SetContent(PGLOBAL g, char *txtp, int len) /******************************************************************/ PXNODE XML2NODE::Clone(PGLOBAL g, PXNODE np) { + if (trace) + htrc("Clone: np=%p\n", np); + if (np) { ((PNODE2)np)->Nodep = Nodep; return np; @@ -542,7 +821,7 @@ PXNODE XML2NODE::Clone(PGLOBAL g, PXNODE np) PXLIST XML2NODE::GetChildElements(PGLOBAL g, char *xp, PXLIST lp) { if (trace) - htrc("GetChildElements %s\n", xp); + htrc("GetChildElements: %s\n", xp); return SelectNodes(g, (xp) ? xp : (char*)"*", lp); } // end of GetChildElements @@ -553,7 +832,7 @@ PXLIST XML2NODE::GetChildElements(PGLOBAL g, char *xp, PXLIST lp) PXLIST XML2NODE::SelectNodes(PGLOBAL g, char *xp, PXLIST lp) { if (trace) - htrc("SelectNodes %s\n", xp); + htrc("SelectNodes: %s\n", xp); xmlNodeSetPtr nl = ((PXDOC2)Doc)->GetNodeList(g, Nodep, xp); @@ -571,7 +850,7 @@ PXLIST XML2NODE::SelectNodes(PGLOBAL g, char *xp, PXLIST lp) PXNODE XML2NODE::SelectSingleNode(PGLOBAL g, char *xp, PXNODE np) { if (trace) - htrc("SelectSingleNode %s\n", xp); + htrc("SelectSingleNode: %s\n", xp); xmlNodeSetPtr nl = ((PXDOC2)Doc)->GetNodeList(g, Nodep, xp); @@ -593,7 +872,7 @@ PXNODE XML2NODE::SelectSingleNode(PGLOBAL g, char *xp, PXNODE np) PXATTR XML2NODE::GetAttribute(PGLOBAL g, char *name, PXATTR ap) { if (trace) - htrc("GetAttribute %s\n", name); + htrc("GetAttribute: %s\n", name); xmlAttrPtr atp = xmlHasProp(Nodep, BAD_CAST name); @@ -618,7 +897,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, char *name, PXNODE np) char *p, *pn, *pf = NULL; if (trace) - htrc("AddChildNode %s\n", name); + htrc("AddChildNode: %s\n", name); // Is a prefix specified if ((pn = strchr(name, ':'))) { @@ -669,7 +948,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, char *name, PXNODE np) PXATTR XML2NODE::AddProperty(PGLOBAL g, char *name, PXATTR ap) { if (trace) - htrc("AddProperty %s\n", name); + htrc("AddProperty: %s\n", name); xmlAttrPtr atp = xmlNewProp(Nodep, BAD_CAST name, NULL); @@ -692,7 +971,7 @@ PXATTR XML2NODE::AddProperty(PGLOBAL g, char *name, PXATTR ap) void XML2NODE::AddText(PGLOBAL g, char *txtp) { if (trace) - htrc("AddText %s\n", txtp); + htrc("AddText: %s\n", txtp); // This is to avoid a blank line when inserting a new line xmlNodePtr np = xmlGetLastChild(Nodep); @@ -711,6 +990,9 @@ void XML2NODE::AddText(PGLOBAL g, char *txtp) /******************************************************************/ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp) { + if (trace) + htrc("DeleteChild: node=%p\n", dnp); + xmlNodePtr np = ((PNODE2)dnp)->Nodep; xmlNodePtr text = np->next; @@ -750,7 +1032,7 @@ int XML2NODELIST::GetLength(void) PXNODE XML2NODELIST::GetItem(PGLOBAL g, int n, PXNODE np) { if (trace) - htrc("GetItem %d\n", n); + htrc("GetItem: %d\n", n); if (!Listp || Listp->nodeNr <= n) return NULL; @@ -781,7 +1063,7 @@ XML2ATTR::XML2ATTR(PXDOC dp, xmlAttrPtr ap, xmlNodePtr np) bool XML2ATTR::SetText(PGLOBAL g, char *txtp, int len) { if (trace) - htrc("SetText %s %d\n", txtp, len); + htrc("SetText: %s %d\n", txtp, len); xmlSetProp(Parent, Atrp->name, BAD_CAST txtp); return false; diff --git a/storage/connect/libdoc.h b/storage/connect/libdoc.h index 97f97f99ccc..a0cead4e904 100644 --- a/storage/connect/libdoc.h +++ b/storage/connect/libdoc.h @@ -1,144 +1,6 @@ -/******************************************************************/ -/* Declaration of XML document processing using libxml2 */ -/* Author: Olivier Bertrand 2007-2012 */ -/******************************************************************/ -#include "plgxml.h" - -typedef class LIBXMLDOC *PXDOC2; -typedef class XML2NODE *PNODE2; -typedef class XML2ATTR *PATTR2; -typedef class XML2NODELIST *PLIST2; - -/******************************************************************/ -/* XML2 block. Must have the same layout than FBLOCK up to Type. */ -/******************************************************************/ -typedef struct _x2block { /* Loaded XML file block */ - struct _x2block *Next; - LPCSTR Fname; /* Point on file name */ - size_t Length; /* Used to tell if read mode */ - short Count; /* Nb of times file is used */ - short Type; /* TYPE_FB_XML */ - int Retcode; /* Return code from Load */ - xmlDocPtr Docp; /* Document interface pointer */ -// xmlXPathContextPtr Ctxp; -// xmlXPathObjectPtr Xop; - } X2BLOCK, *PX2BLOCK; - -/******************************************************************/ -/* Declaration of libxml2 document. */ -/******************************************************************/ -class LIBXMLDOC : public XMLDOCUMENT { - friend class XML2NODE; - friend class XML2ATTR; - public: - // Constructor - LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp); - - // Properties - virtual short GetDocType(void) {return TYPE_FB_XML2;} - virtual void *GetDocPtr(void) {return Docp;} - - // Methods - virtual bool Initialize(PGLOBAL g); - virtual bool ParseFile(char *fn); - virtual bool NewDoc(PGLOBAL g, char *ver); - virtual void AddComment(PGLOBAL g, char *com); - virtual PXNODE GetRoot(PGLOBAL g); - virtual PXNODE NewRoot(PGLOBAL g, char *name); - virtual PXNODE NewPnode(PGLOBAL g, char *name); - virtual PXATTR NewPattr(PGLOBAL g); - virtual PXLIST NewPlist(PGLOBAL g); - virtual int DumpDoc(PGLOBAL g, char *ofn); - virtual void CloseDoc(PGLOBAL g, PFBLOCK xp); - virtual PFBLOCK LinkXblock(PGLOBAL g, MODE m, int rc, char *fn); - - protected: -// bool CheckDocument(FILE *of, xmlNodePtr np); - xmlNodeSetPtr GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp); - int Decode(xmlChar *cnt, char *buf, int n); - xmlChar *Encode(PGLOBAL g, char *txt); - - // Members - xmlDocPtr Docp; - xmlNodeSetPtr Nlist; - xmlXPathContextPtr Ctxp; - xmlXPathObjectPtr Xop; - char *Buf; // Temporary -}; // end of class LIBXMLDOC - -/******************************************************************/ -/* Declaration of libxml2 node. */ -/******************************************************************/ -class XML2NODE : public XMLNODE { - friend class LIBXMLDOC; - friend class XML2NODELIST; - public: - // Properties - virtual char *GetName(PGLOBAL g) {return (char*)Nodep->name;} - virtual int GetType(void); - virtual PXNODE GetNext(PGLOBAL g); - virtual PXNODE GetChild(PGLOBAL g); - - // Methods - virtual RCODE GetContent(PGLOBAL g, char *buf, int len); - virtual bool SetContent(PGLOBAL g, char *txtp, int len); - virtual PXNODE Clone(PGLOBAL g, PXNODE np); - virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp); - virtual PXLIST SelectNodes(PGLOBAL g, char *xp, PXLIST lp); - virtual PXNODE SelectSingleNode(PGLOBAL g, char *xp, PXNODE np); - virtual PXATTR GetAttribute(PGLOBAL g, char *name, PXATTR ap); - virtual PXNODE AddChildNode(PGLOBAL g, char *name, PXNODE np); - virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap); - virtual void AddText(PGLOBAL g, char *txtp); - virtual void DeleteChild(PGLOBAL g, PXNODE dnp); - - protected: - // Constructor - XML2NODE(PXDOC dp, xmlNodePtr np); - - // Members - xmlDocPtr Docp; - xmlChar *Content; - xmlNodePtr Nodep; -}; // end of class XML2NODE - -/******************************************************************/ -/* Declaration of libxml2 node list. */ -/******************************************************************/ -class XML2NODELIST : public XMLNODELIST { - friend class LIBXMLDOC; - friend class XML2NODE; - public: - // Methods - virtual int GetLength(void); - virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np); - - protected: - // Constructor - XML2NODELIST(PXDOC dp, xmlNodeSetPtr lp); - - // Members - xmlNodeSetPtr Listp; -}; // end of class XML2NODELIST - -/******************************************************************/ -/* Declaration of libxml2 attribute. */ -/******************************************************************/ -class XML2ATTR : public XMLATTRIBUTE { - friend class LIBXMLDOC; - friend class XML2NODE; - public: - // Properties -//virtual char *GetText(void); - - // Methods - virtual bool SetText(PGLOBAL g, char *txtp, int len); - - protected: - // Constructor - XML2ATTR(PXDOC dp, xmlAttrPtr ap, xmlNodePtr np); - - // Members - xmlAttrPtr Atrp; - xmlNodePtr Parent; -}; // end of class XML2ATTR +#ifndef LIBDOC_H_INCLUDED +#define LIBDOC_H_INCLUDED +void XmlInitParserLib(void); +void XmlCleanupParserLib(void); +void CloseXML2File(PGLOBAL, PFBLOCK, bool); +#endif diff --git a/storage/connect/maputil.h b/storage/connect/maputil.h index 8ab41487a63..b5e54affcea 100644 --- a/storage/connect/maputil.h +++ b/storage/connect/maputil.h @@ -13,7 +13,6 @@ typedef struct { HANDLE CreateFileMap(PGLOBAL, LPCSTR, MEMMAP *, MODE, bool); bool CloseMemMap(void *memory, size_t dwSize); -my_bool CloseFileHandle(HANDLE h); #ifdef __cplusplus } diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index 4db70efe27f..3c75c0b63b3 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -68,7 +68,10 @@ #include "tabmac.h" #include "tabwmi.h" #endif // WIN32 +//#include "tabtbl.h" +#include "tabxcl.h" #include "tabtbl.h" +#include "taboccur.h" #if defined(XML_SUPPORT) #include "tabxml.h" #endif // XML_SUPPORT @@ -117,6 +120,7 @@ TABTYPE GetTypeID(const char *type) #endif #ifdef MYSQL_SUPPORT : (!stricmp(type, "MYSQL")) ? TAB_MYSQL + : (!stricmp(type, "MYPRX")) ? TAB_MYSQL #endif : (!stricmp(type, "DIR")) ? TAB_DIR #ifdef WIN32 @@ -124,6 +128,13 @@ TABTYPE GetTypeID(const char *type) : (!stricmp(type, "WMI")) ? TAB_WMI #endif : (!stricmp(type, "TBL")) ? TAB_TBL + : (!stricmp(type, "XCOL")) ? TAB_XCL + : (!stricmp(type, "OCCUR")) ? TAB_OCCUR + : (!stricmp(type, "CATLG")) ? TAB_PRX // Legacy + : (!stricmp(type, "PROXY")) ? TAB_PRX +#ifdef PIVOT_SUPPORT + : (!stricmp(type, "PIVOT")) ? TAB_PIVOT +#endif : (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY; } // end of GetTypeID @@ -186,7 +197,6 @@ bool IsTypeNullable(TABTYPE type) break; } // endswitch type - return nullable; } // end of IsTypeNullable @@ -246,15 +256,11 @@ uint GetFuncID(const char *func) /***********************************************************************/ CATALOG::CATALOG(void) { - To_Desc= NULL; -//*DescFile= '\0'; #if defined(WIN32) DataPath= ".\\"; #else // !WIN32 DataPath= "./"; #endif // !WIN32 - Descp= NULL; -//memset(&DescArea, 0, sizeof(AREADEF)); memset(&Ctb, 0, sizeof(CURTAB)); Cbuf= NULL; Cblen= 0; @@ -269,17 +275,14 @@ CATALOG::CATALOG(void) MYCAT::MYCAT(PHC hc) : CATALOG() { Hc= hc; - To_Desc= NULL; DefHuge= false; -//SepIndex= true; // Temporay until we can store offet and size } // end of MYCAT constructor /***********************************************************************/ -/* When using volatile storage, reset values pointing to Sarea. */ +/* Nothing to do for CONNECT. */ /***********************************************************************/ void MYCAT::Reset(void) { - To_Desc= NULL; } // end of Reset /***********************************************************************/ @@ -290,6 +293,13 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path) if (path) { size_t len= strlen(path) + (*path != '.' ? 4 : 1); char *buf= (char*)PlugSubAlloc(g, NULL, len); + + if (PlugIsAbsolutePath(path)) + { + strcpy(buf, path); + *datapath= buf; + return; + } if (*path != '.') { #if defined(WIN32) @@ -373,30 +383,32 @@ int MYCAT::GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size) /***********************************************************************/ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef) { - char *sval, *s= Hc->GetStringOption(what, sdef); + char *sval= NULL, *s= Hc->GetStringOption(what, sdef); if (s) { sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1); strcpy(sval, s); } else if (!stricmp(what, "filename")) { // Return default file name - char *ftype= Hc->GetStringOption("Type", "dos"); + char *ftype= Hc->GetStringOption("Type", "*"); int i, n; - sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 12); - strcat(strcpy(sval, Hc->GetTableName()), "."); - n= strlen(sval); + if (IsFileType(GetTypeID(ftype))) { + sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 12); + strcat(strcpy(sval, Hc->GetTableName()), "."); + n= strlen(sval); + + // Fold ftype to lower case + for (i= 0; i < 12; i++) + if (!ftype[i]) { + sval[n+i]= 0; + break; + } else + sval[n+i]= tolower(ftype[i]); - // Fold ftype to lower case - for (i= 0; i < 12; i++) - if (!ftype[i]) { - sval[n+i]= 0; - break; - } else - sval[n+i]= tolower(ftype[i]); + } // endif FileType - } else - sval = NULL; + } // endif s return sval; } // end of GetStringCatInfo @@ -406,15 +418,17 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef) /***********************************************************************/ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) { - char *type= GetStringCatInfo(g, "Type", "DOS"); + char *type= GetStringCatInfo(g, "Type", "*"); int i, loff, poff, nof, nlg; void *field= NULL; TABTYPE tc; PCOLDEF cdp, lcdp= NULL, tocols= NULL; PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO)); + memset(pcf, 0, sizeof(COLINFO)); + // Get a unique char identifier for type - tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_CATLG; + tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX; // Take care of the column definitions i= poff= nof= nlg= 0; @@ -443,6 +457,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) case TAB_INI: case TAB_MAC: case TAB_TBL: + case TAB_XCL: + case TAB_OCCUR: + case TAB_PRX: case TAB_OEM: poff = 0; // Offset represents an independant flag break; @@ -452,7 +469,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) } // endswitch tc do { - field= Hc->GetColumnOption(field, pcf); + field= Hc->GetColumnOption(g, field, pcf); } while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/)); if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) { @@ -576,9 +593,7 @@ bool MYCAT::GetIndexInfo(PGLOBAL g, PTABDEF defp) /***********************************************************************/ /* GetTableDesc: retrieve a table descriptor. */ -/* Look for a table descriptor matching the name and type. If found */ -/* in storage, return a pointer to it, else look in the XDB file. If */ -/* found, make and add the descriptor and return a pointer to it. */ +/* Look for a table descriptor matching the name and type. */ /***********************************************************************/ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name, LPCSTR type, PRELDEF *prp) @@ -586,13 +601,9 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name, if (xtrace) printf("GetTableDesc: name=%s am=%s\n", name, SVP(type)); - // Firstly check whether this table descriptor is in memory - if (To_Desc) - return To_Desc; - // If not specified get the type of this table - if (!type && !(type= Hc->GetStringOption("Type"))) - type= "DOS"; + if (!type) + type= Hc->GetStringOption("Type","*"); return MakeTableDesc(g, name, type); } // end of GetTableDesc @@ -636,17 +647,20 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) #endif // WIN32 case TAB_OEM: tdp= new(g) OEMDEF; break; case TAB_TBL: tdp= new(g) TBLDEF; break; + case TAB_XCL: tdp= new(g) XCLDEF; break; + case TAB_PRX: tdp= new(g) PRXDEF; break; + case TAB_OCCUR: tdp= new(g) OCCURDEF; break; #if defined(MYSQL_SUPPORT) case TAB_MYSQL: tdp= new(g) MYSQLDEF; break; #endif // MYSQL_SUPPORT -//#if defined(PIVOT_SUPPORT) -// case TAB_PIVOT: tdp= new(g) PIVOTDEF; break; -//#endif // PIVOT_SUPPORT +#if defined(PIVOT_SUPPORT) + case TAB_PIVOT: tdp= new(g) PIVOTDEF; break; +#endif // PIVOT_SUPPORT default: sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); } // endswitch - // Do make the table/view definition from XDB file information + // Do make the table/view definition if (tdp && tdp->Define(g, this, name, am)) tdp= NULL; @@ -694,7 +708,6 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type) /***********************************************************************/ void MYCAT::ClearDB(PGLOBAL g) { - To_Desc= NULL; } // end of ClearDB /* ------------------------ End of MYCAT --------------------------- */ diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index 3edf07004ea..4cad68a9a1e 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -62,21 +62,25 @@ static char *server_groups[] = { #endif // EMBEDDED extern "C" int trace; +extern MYSQL_PLUGIN_IMPORT uint mysqld_port; + +// Returns the current used port +uint GetDefaultPort(void) +{ + return mysqld_port; +} // end of GetDefaultPort /************************************************************************/ /* MyColumns: constructs the result blocks containing all columns */ -/* of a MySQL table that will be retrieved by GetData commands. */ -/* key = TRUE when called from Create Table to get key informations. */ +/* of a MySQL table or view. */ +/* info = TRUE to get catalog column informations. */ /************************************************************************/ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, const char *user, const char *pwd, const char *table, const char *colpat, - int port, bool key, bool info) + int port, bool info) { - static int dbtype[] = {DB_CHAR, DB_SHORT, DB_CHAR, DB_INT, - DB_CHAR, DB_SHORT, DB_SHORT, DB_SHORT, - DB_CHAR, DB_CHAR, DB_CHAR}; - static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, + static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING, TYPE_STRING, TYPE_STRING}; static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, @@ -84,12 +88,15 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, FLD_REM, FLD_NO, FLD_CHARSET}; static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 256, 32, 32}; char *fld, *fmt, cmd[128]; - int i, n, nf, ncol = sizeof(dbtype) / sizeof(int); + int i, n, nf, ncol = sizeof(buftyp) / sizeof(int); int len, type, prec, rc, k = 0; PQRYRES qrp; PCOLRES crp; MYSQLC myc; + if (!port) + port = mysqld_port; + if (!info) { /********************************************************************/ /* Open the connection with the MySQL server. */ @@ -123,14 +130,11 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, length[0] = 128; } // endif info -//if (!key) // We are not called from Create table -// ncol--; // No date format column yet - /**********************************************************************/ /* Allocate the structures used to refer to the result set. */ /**********************************************************************/ qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, - dbtype, buftyp, fldtyp, length, true, true); + buftyp, fldtyp, length, true, true); // Some columns must be renamed for (i = 0, crp = qrp->Colresp; crp; crp = crp->Next) @@ -218,6 +222,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, crp->Kdata->SetValue(fld, i); } // endfor i +#if 0 if (k > 1) { // Multicolumn primary key PVBLK vbp = qrp->Colresp->Next->Next->Next->Next->Kdata; @@ -227,6 +232,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, vbp->SetValue(k, i); } // endif k +#endif // 0 /**********************************************************************/ /* Close MySQL connection. */ @@ -239,6 +245,33 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, return qrp; } // end of MyColumns +/************************************************************************/ +/* SrcColumns: constructs the result blocks containing all columns */ +/* resulting from an SQL source definition query execution. */ +/************************************************************************/ +PQRYRES SrcColumns(PGLOBAL g, const char *host, const char *db, + const char *user, const char *pwd, + const char *srcdef, int port) + { + int w; + MYSQLC myc; + PQRYRES qrp = NULL; + + if (!port) + port = mysqld_port; + + // Open a MySQL connection for this table + if (myc.Open(g, host, db, user, pwd, port)) + return NULL; + + // Send the source command to MySQL + if (myc.ExecSQL(g, srcdef, &w) == RC_OK) + qrp = myc.GetResult(g); + + myc.Close(); + return qrp; + } // end of SrcColumns + /* -------------------------- Class MYSQLC --------------------------- */ /***********************************************************************/ @@ -278,6 +311,8 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, const char *user, const char *pwd, int pt) { + uint cto = 60, nrt = 120; + m_DB = mysql_init(NULL); if (!m_DB) { @@ -285,10 +320,12 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, return RC_FX; } // endif m_DB - // Notice that the client and server use separate group names. - // This is critical, because the server will not accept the - // client's options, and vice versa. - mysql_options(m_DB, MYSQL_READ_DEFAULT_GROUP, "PlugDB_CLIENT"); + // Removed to do like FEDERATED do +//mysql_options(m_DB, MYSQL_READ_DEFAULT_GROUP, "client-mariadb"); + mysql_options(m_DB, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL); + mysql_options(m_DB, MYSQL_OPT_CONNECT_TIMEOUT, &cto); + mysql_options(m_DB, MYSQL_OPT_READ_TIMEOUT, &nrt); +//mysql_options(m_DB, MYSQL_OPT_WRITE_TIMEOUT, ...); #if 0 if (pwd && !strcmp(pwd, "*")) { @@ -645,6 +682,7 @@ PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb) *pcrp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); crp = *pcrp; pcrp = &crp->Next; + memset(crp, 0, sizeof(COLRES)); crp->Ncol = ++qrp->Nbcol; crp->Name = (char*)PlugSubAlloc(g, NULL, fld->name_length + 1); @@ -658,10 +696,9 @@ PQRYRES MYSQLC::GetResult(PGLOBAL g, bool pdb) // For direct MySQL connection, display the MySQL date string crp->Type = TYPE_STRING; - crp->Prec = fld->decimals; + crp->Prec = (crp->Type == TYPE_FLOAT) ? fld->decimals : 0; crp->Length = fld->max_length; crp->Clen = GetTypeSize(crp->Type, crp->Length); - crp->DBtype = GetDBType((int)crp->Type); if (!(crp->Kdata = AllocValBlock(g, NULL, crp->Type, m_Rows, crp->Clen, 0, FALSE, TRUE))) { diff --git a/storage/connect/myconn.h b/storage/connect/myconn.h index 72ce58e70aa..f8c8c3dcbae 100644 --- a/storage/connect/myconn.h +++ b/storage/connect/myconn.h @@ -38,7 +38,13 @@ typedef class MYSQLC *PMYC; PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, const char *user, const char *pwd, const char *table, const char *colpat, - int port, bool key, bool info); + int port, bool info); + +PQRYRES SrcColumns(PGLOBAL g, const char *host, const char *db, + const char *user, const char *pwd, + const char *srcdef, int port); + +uint GetDefaultPort(void); /* -------------------------- MYCONN class --------------------------- */ @@ -47,6 +53,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db, /***********************************************************************/ class DllItem MYSQLC { friend class TDBMYSQL; + friend class MYSQLCOL; // Construction public: MYSQLC(void); diff --git a/storage/connect/mysql-test/connect/r/bin.result b/storage/connect/mysql-test/connect/r/bin.result index d476aef6293..c64b270b538 100644 --- a/storage/connect/mysql-test/connect/r/bin.result +++ b/storage/connect/mysql-test/connect/r/bin.result @@ -1,98 +1,4 @@ # -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN; -Warnings: -Warning 1105 No file name. Table will use t1.bin -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN; -Warnings: -Warning 1105 No file name. Table will use t1.bin -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# -# # Testing errors # CREATE TABLE t1 diff --git a/storage/connect/mysql-test/connect/r/csv.result b/storage/connect/mysql-test/connect/r/csv.result index 34734e164c0..b2498326edb 100644 --- a/storage/connect/mysql-test/connect/r/csv.result +++ b/storage/connect/mysql-test/connect/r/csv.result @@ -1,97 +1,3 @@ -# -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV; -Warnings: -Warning 1105 No file name. Table will use t1.csv -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV; -Warnings: -Warning 1105 No file name. Table will use t1.csv -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# SET NAMES utf8; # # Testing errors diff --git a/storage/connect/mysql-test/connect/r/dbf.result b/storage/connect/mysql-test/connect/r/dbf.result index 27abbb84dc6..cbe4f4db620 100644 --- a/storage/connect/mysql-test/connect/r/dbf.result +++ b/storage/connect/mysql-test/connect/r/dbf.result @@ -1,98 +1,4 @@ # -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF; -Warnings: -Warning 1105 No file name. Table will use t1.dbf -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF; -Warnings: -Warning 1105 No file name. Table will use t1.dbf -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# -# # Testing errors # CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; @@ -488,22 +394,22 @@ CREATE TABLE t1 ( a BLOB ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; -ERROR HY000: Unsupported type for column 'a' +ERROR HY000: Unsupported type for column a CREATE TABLE t1 ( a TINYBLOB ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; -ERROR HY000: Unsupported type for column 'a' +ERROR HY000: Unsupported type for column a CREATE TABLE t1 ( a MEDIUMBLOB ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; -ERROR HY000: Unsupported type for column 'a' +ERROR HY000: Unsupported type for column a CREATE TABLE t1 ( a LONGBLOB ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; -ERROR HY000: Unsupported type for column 'a' +ERROR HY000: Unsupported type for column a # # Testing DATE # diff --git a/storage/connect/mysql-test/connect/r/dir.result b/storage/connect/mysql-test/connect/r/dir.result index 7beae815580..f4feb5fa960 100644 --- a/storage/connect/mysql-test/connect/r/dir.result +++ b/storage/connect/mysql-test/connect/r/dir.result @@ -1,72 +1,3 @@ -# -# Testing FILE privilege -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 ( -path VARCHAR(256) NOT NULL flag=1, -fname VARCHAR(256) NOT NULL, -ftype CHAR(4) NOT NULL, -size DOUBLE(12,0) NOT NULL flag=5 -) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 ( -path VARCHAR(256) NOT NULL flag=1, -fname VARCHAR(256) NOT NULL, -ftype CHAR(4) NOT NULL, -size DOUBLE(12,0) NOT NULL flag=5 -) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; -SELECT fname, ftype, size FROM t1 WHERE size>0; -fname ftype size -t1 .frm 1081 -SELECT user(); -user() -user@localhost -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO t1 VALUES (); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1 WHERE path='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET path='yyy' WHERE path='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (1,1,1,1); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET path=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -DROP USER user@localhost; -# -# Testing FILE privileges done -# CREATE TABLE t1 ( path VARCHAR(256) NOT NULL flag=1, fname VARCHAR(256) NOT NULL, diff --git a/storage/connect/mysql-test/connect/r/fix.result b/storage/connect/mysql-test/connect/r/fix.result index e9eb31d9bc8..c8f51abe961 100644 --- a/storage/connect/mysql-test/connect/r/fix.result +++ b/storage/connect/mysql-test/connect/r/fix.result @@ -1,98 +1,4 @@ # -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX; -Warnings: -Warning 1105 No file name. Table will use t1.fix -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX; -Warnings: -Warning 1105 No file name. Table will use t1.fix -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# -# # Testing errors # CREATE TABLE t1 diff --git a/storage/connect/mysql-test/connect/r/fmt.result b/storage/connect/mysql-test/connect/r/fmt.result index dc3b42b2231..0be10f69bfd 100644 --- a/storage/connect/mysql-test/connect/r/fmt.result +++ b/storage/connect/mysql-test/connect/r/fmt.result @@ -18,7 +18,7 @@ CREATE TABLE t1 id INT NOT NULL field_format=' %n%d%n' ) ENGINE=CONNECT TABLE_TYPE=FMT FILE_NAME='t1.txt'; INSERT INTO t1 VALUES (10),(20); -ERROR HY000: Got error 122 'Writing FMT files is not implemented yet' from CONNECT +ERROR HY000: Got error 174 'Writing FMT files is not implemented yet' from CONNECT DROP TABLE t1; # # Testing manual examples @@ -59,7 +59,7 @@ ID NAME DEPNO SALARY 56 POIROT-DELMOTTE 0 18009.00 345 67 19000.25 UPDATE t1 SET SALARY=1234; -ERROR HY000: Got error 122 'Writing FMT files is not implemented yet' from CONNECT +ERROR HY000: Got error 174 'Writing FMT files is not implemented yet' from CONNECT DELETE FROM t1 WHERE ID=56; SELECT * FROM t1; ID NAME DEPNO SALARY diff --git a/storage/connect/mysql-test/connect/r/grant.result b/storage/connect/mysql-test/connect/r/grant.result new file mode 100644 index 00000000000..ba5728703a5 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/grant.result @@ -0,0 +1,539 @@ +# +# Testing FILE privilege +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 ( +path VARCHAR(256) NOT NULL flag=1, +fname VARCHAR(256) NOT NULL, +ftype CHAR(4) NOT NULL, +size DOUBLE(12,0) NOT NULL flag=5 +) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 ( +path VARCHAR(256) NOT NULL flag=1, +fname VARCHAR(256) NOT NULL, +ftype CHAR(4) NOT NULL, +size DOUBLE(12,0) NOT NULL flag=5 +) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; +SELECT fname, ftype, size FROM t1 WHERE size>0; +fname ftype size +t1 .frm 1081 +SELECT user(); +user() +user@localhost +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO t1 VALUES (); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1 WHERE path='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET path='yyy' WHERE path='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (1,1,1,1); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET path=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +DROP USER user@localhost; +# +# Testing FILE privileges done +# +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN; +Warnings: +Warning 1105 No file name. Table will use t1.bin +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=BIN; +Warnings: +Warning 1105 No file name. Table will use t1.bin +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV; +Warnings: +Warning 1105 No file name. Table will use t1.csv +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=CSV; +Warnings: +Warning 1105 No file name. Table will use t1.csv +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF; +Warnings: +Warning 1105 No file name. Table will use t1.dbf +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=DBF; +Warnings: +Warning 1105 No file name. Table will use t1.dbf +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX; +Warnings: +Warning 1105 No file name. Table will use t1.fix +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=FIX; +Warnings: +Warning 1105 No file name. Table will use t1.fix +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100; +Warnings: +Warning 1105 No file name. Table will use t1.vec +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100 FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100; +Warnings: +Warning 1105 No file name. Table will use t1.vec +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# diff --git a/storage/connect/mysql-test/connect/r/ini.result b/storage/connect/mysql-test/connect/r/ini.result index da846d466ba..83ba98fbd84 100644 --- a/storage/connect/mysql-test/connect/r/ini.result +++ b/storage/connect/mysql-test/connect/r/ini.result @@ -1,83 +1,4 @@ # -# Checking FILE privileges -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI; -Warnings: -Warning 1105 No file name. Table will use t1.ini -INSERT INTO t1 VALUES ('sec1','val1'); -SELECT * FROM t1; -sec val -sec1 val1 -UPDATE t1 SET val='val11'; -SELECT * FROM t1; -sec val -sec1 val11 -DELETE FROM t1; -SELECT * FROM t1; -sec val -INSERT INTO t1 VALUES('sec2','val2'); -TRUNCATE TABLE t1; -SELECT * FROM t1; -sec val -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -sec val -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES ('sec1','val1'); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES ('sec2','val2'); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET val='val11'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES ('sec3','val3'); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET val='val11'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP VIEW v1; -DROP TABLE t1; -DROP USER user@localhost; -# -# Checking FILE privileges: done -# -# # Testing errors # CREATE TABLE t1 diff --git a/storage/connect/mysql-test/connect/r/ini_grant.result b/storage/connect/mysql-test/connect/r/ini_grant.result new file mode 100644 index 00000000000..c3acf7c8dfc --- /dev/null +++ b/storage/connect/mysql-test/connect/r/ini_grant.result @@ -0,0 +1,79 @@ +# +# Checking FILE privileges +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI; +Warnings: +Warning 1105 No file name. Table will use t1.ini +INSERT INTO t1 VALUES ('sec1','val1'); +SELECT * FROM t1; +sec val +sec1 val1 +UPDATE t1 SET val='val11'; +SELECT * FROM t1; +sec val +sec1 val11 +DELETE FROM t1; +SELECT * FROM t1; +sec val +INSERT INTO t1 VALUES('sec2','val2'); +TRUNCATE TABLE t1; +SELECT * FROM t1; +sec val +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +sec val +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES ('sec1','val1'); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES ('sec2','val2'); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET val='val11'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES ('sec3','val3'); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET val='val11'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP VIEW v1; +DROP TABLE t1; +DROP USER user@localhost; +# +# Checking FILE privileges: done +# diff --git a/storage/connect/mysql-test/connect/r/mul.result b/storage/connect/mysql-test/connect/r/mul.result new file mode 100644 index 00000000000..d362da13739 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/mul.result @@ -0,0 +1,57 @@ +# +# Testing multiple 1 +# +CREATE TABLE `t1` ( +`a` char(10) DEFAULT NULL, +`b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `sep_char`=';'; +Warnings: +Warning 1105 No file name. Table will use t1.csv +INSERT INTO t1 VALUES('test1','bla'); +SELECT * FROM t1; +a b +test1 bla +CREATE TABLE `t2` ( +`a` char(10) DEFAULT NULL, +`b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `sep_char`=';'; +Warnings: +Warning 1105 No file name. Table will use t2.csv +INSERT INTO t2 VALUES('test2','blub'); +SELECT * FROM t2; +a b +test2 blub +CREATE TABLE `t_all` ( +`a` char(10) DEFAULT NULL, +`b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `file_name`='t*.csv' `sep_char`=';' `multiple`=1; +SELECT * FROM t_all order by `a`; +a b +test1 bla +test2 blub +# +# Testing multiple 2 +# +CREATE table fnlist ( +fn char(8) not null +) ENGINE=CONNECT DEFAULT CHARSET=latin1 table_type=DOS; +Warnings: +Warning 1105 No file name. Table will use fnlist.dos +INSERT INTO fnlist VALUES('t1.csv'),('t2.csv'); +SELECT fn FROM fnlist; +fn +t1.csv +t2.csv +CREATE TABLE `tblist` ( +`a` char(10) DEFAULT NULL, +`b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `file_name`='fnlist.dos' `sep_char`=';' `multiple`=2; +SELECT * FROM tblist; +a b +test1 bla +test2 blub +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t_all; +DROP TABLE fnlist; +DROP TABLE tblist; diff --git a/storage/connect/mysql-test/connect/r/mysql.result b/storage/connect/mysql-test/connect/r/mysql.result index a538c57c5ce..8d5507e121a 100644 --- a/storage/connect/mysql-test/connect/r/mysql.result +++ b/storage/connect/mysql-test/connect/r/mysql.result @@ -1,66 +1,3 @@ -# -# Testing FILE privilege -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL OPTION_LIST='host=localhost,user=root1,port=PORT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1remote (a INT NOT NULL); -INSERT INTO t1remote VALUES (10),(20),(30); -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL TABNAME=t1remote OPTION_LIST='host=localhost,user=root,port=PORT'; -SELECT * FROM t1; -a -10 -20 -30 -SELECT user(); -user() -user@localhost -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO t1 VALUES ('xxx'); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1 WHERE a='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a='yyy' WHERE a='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1, t1remote; -DROP USER user@localhost; -# -# Testing FILE privileges done -# CREATE TABLE t1 (a int, b char(10)); INSERT INTO t1 VALUES (NULL,NULL),(0,'test00'),(1,'test01'),(2,'test02'),(3,'test03'); SELECT * FROM t1; diff --git a/storage/connect/mysql-test/connect/r/mysql_grant.result b/storage/connect/mysql-test/connect/r/mysql_grant.result new file mode 100644 index 00000000000..f8d0ee6ad6f --- /dev/null +++ b/storage/connect/mysql-test/connect/r/mysql_grant.result @@ -0,0 +1,63 @@ +# +# Testing FILE privilege +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL OPTION_LIST='host=localhost,user=root1,port=PORT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1remote (a INT NOT NULL); +INSERT INTO t1remote VALUES (10),(20),(30); +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL TABNAME=t1remote OPTION_LIST='host=localhost,user=root,port=PORT'; +SELECT * FROM t1; +a +10 +20 +30 +SELECT user(); +user() +user@localhost +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO t1 VALUES ('xxx'); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1 WHERE a='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a='yyy' WHERE a='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1, t1remote; +DROP USER user@localhost; +# +# Testing FILE privileges done +# diff --git a/storage/connect/mysql-test/connect/r/occur.result b/storage/connect/mysql-test/connect/r/occur.result new file mode 100644 index 00000000000..a497dfc9942 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/occur.result @@ -0,0 +1,255 @@ +CREATE TABLE employee ( +serialno CHAR(5) NOT NULL, +name VARCHAR(12) NOT NULL FLAG=6, +sex TINYINT(1) NOT NULL, +title VARCHAR(15) NOT NULL FLAG=20, +manager CHAR(5) DEFAULT NULL, +department CHAR(4) NOT NULL FLAG=41, +secretary CHAR(5) DEFAULT NULL FLAG=46, +salary DOUBLE(8,2) NOT NULL FLAG=52 +) ENGINE=connect TABLE_TYPE=fix FILE_NAME='employee.dat' ENDING=1; +SELECT * FROM employee; +serialno name sex title manager department secretary salary +74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00 +02345 SMITH 1 ENGINEER 31416 2452 11111 9000.00 +78943 MERCHANT 1 SALESMAN 70012 0318 24888 8700.00 +07654 FUNNIGUY 1 ADMINISTRATOR 40567 0319 33333 8500.00 +45678 BUGHAPPY 1 PROGRAMMER 40567 0319 12345 8500.00 +34567 BIGHEAD 1 SCIENTIST 31416 2452 11111 8000.00 +77777 SHRINKY 2 ADMINISTRATOR 70012 0318 27845 7500.00 +74234 WALTER 1 ENGINEER 70012 0318 24888 7400.00 +56789 FODDERMAN 1 SALESMAN 40567 0319 12345 7000.00 +73452 TONGHO 1 ENGINEER 70012 0318 24888 6800.00 +22222 SHORTSIGHT 2 SECRETARY 87777 0021 NULL 5500.00 +55555 MESSIFUL 2 SECRETARY 40567 0319 12345 5000.50 +27845 HONEY 2 SECRETARY 70012 0318 24888 4900.00 +98765 GOOSEPEN 1 ADMINISTRATOR 07654 0319 33333 4700.00 +11111 CHERRY 2 SECRETARY 31416 2452 NULL 4500.00 +33333 MONAPENNY 2 SECRETARY 07654 0319 NULL 3800.00 +12345 KITTY 2 TYPIST 40567 0319 NULL 3000.45 +24888 PLUMHEAD 2 TYPIST 27845 0318 NULL 2800.00 +87777 STRONG 1 DIRECTOR NULL 0021 22222 23000.00 +76543 BULLOZER 1 SALESMAN 40567 0319 12345 14800.00 +70012 WERTHER 1 DIRECTOR 87777 0318 27845 14500.00 +40567 QUINN 1 DIRECTOR 87777 0319 55555 14000.00 +31416 ORELLY 1 ENGINEER 87777 2452 11111 13400.00 +36666 BIGHORN 1 SCIENTIST 31416 2452 11111 11000.00 +00137 BROWNY 1 ENGINEER 40567 0319 12345 10500.00 +73111 WHEELFOR 1 SALESMAN 70012 0318 24888 10030.00 +00023 MARTIN 1 ENGINEER 40567 0319 12345 10000.00 +CREATE TABLE occurs (name CHAR(12), sex CHAR(1), title CHAR(15), department CHAR(4), salary DOUBLE(8,2), id_of CHAR(12), id CHAR(5) NOT NULL) ENGINE=CONNECT TABLE_TYPE=OCCUR TABNAME=employee OPTION_LIST='OccurCol=ID,RankCol=ID_OF,Colist=serialno;manager;secretary,port=PORT';; +SELECT * FROM occurs; +name sex title department salary id_of id +BANCROFT 2 SALESMAN 0318 9600.00 serialno 74200 +BANCROFT 2 SALESMAN 0318 9600.00 manager 70012 +BANCROFT 2 SALESMAN 0318 9600.00 secretary 24888 +SMITH 1 ENGINEER 2452 9000.00 serialno 02345 +SMITH 1 ENGINEER 2452 9000.00 manager 31416 +SMITH 1 ENGINEER 2452 9000.00 secretary 11111 +MERCHANT 1 SALESMAN 0318 8700.00 serialno 78943 +MERCHANT 1 SALESMAN 0318 8700.00 manager 70012 +MERCHANT 1 SALESMAN 0318 8700.00 secretary 24888 +FUNNIGUY 1 ADMINISTRATOR 0319 8500.00 serialno 07654 +FUNNIGUY 1 ADMINISTRATOR 0319 8500.00 manager 40567 +FUNNIGUY 1 ADMINISTRATOR 0319 8500.00 secretary 33333 +BUGHAPPY 1 PROGRAMMER 0319 8500.00 serialno 45678 +BUGHAPPY 1 PROGRAMMER 0319 8500.00 manager 40567 +BUGHAPPY 1 PROGRAMMER 0319 8500.00 secretary 12345 +BIGHEAD 1 SCIENTIST 2452 8000.00 serialno 34567 +BIGHEAD 1 SCIENTIST 2452 8000.00 manager 31416 +BIGHEAD 1 SCIENTIST 2452 8000.00 secretary 11111 +SHRINKY 2 ADMINISTRATOR 0318 7500.00 serialno 77777 +SHRINKY 2 ADMINISTRATOR 0318 7500.00 manager 70012 +SHRINKY 2 ADMINISTRATOR 0318 7500.00 secretary 27845 +WALTER 1 ENGINEER 0318 7400.00 serialno 74234 +WALTER 1 ENGINEER 0318 7400.00 manager 70012 +WALTER 1 ENGINEER 0318 7400.00 secretary 24888 +FODDERMAN 1 SALESMAN 0319 7000.00 serialno 56789 +FODDERMAN 1 SALESMAN 0319 7000.00 manager 40567 +FODDERMAN 1 SALESMAN 0319 7000.00 secretary 12345 +TONGHO 1 ENGINEER 0318 6800.00 serialno 73452 +TONGHO 1 ENGINEER 0318 6800.00 manager 70012 +TONGHO 1 ENGINEER 0318 6800.00 secretary 24888 +SHORTSIGHT 2 SECRETARY 0021 5500.00 serialno 22222 +SHORTSIGHT 2 SECRETARY 0021 5500.00 manager 87777 +MESSIFUL 2 SECRETARY 0319 5000.50 serialno 55555 +MESSIFUL 2 SECRETARY 0319 5000.50 manager 40567 +MESSIFUL 2 SECRETARY 0319 5000.50 secretary 12345 +HONEY 2 SECRETARY 0318 4900.00 serialno 27845 +HONEY 2 SECRETARY 0318 4900.00 manager 70012 +HONEY 2 SECRETARY 0318 4900.00 secretary 24888 +GOOSEPEN 1 ADMINISTRATOR 0319 4700.00 serialno 98765 +GOOSEPEN 1 ADMINISTRATOR 0319 4700.00 manager 07654 +GOOSEPEN 1 ADMINISTRATOR 0319 4700.00 secretary 33333 +CHERRY 2 SECRETARY 2452 4500.00 serialno 11111 +CHERRY 2 SECRETARY 2452 4500.00 manager 31416 +MONAPENNY 2 SECRETARY 0319 3800.00 serialno 33333 +MONAPENNY 2 SECRETARY 0319 3800.00 manager 07654 +KITTY 2 TYPIST 0319 3000.45 serialno 12345 +KITTY 2 TYPIST 0319 3000.45 manager 40567 +PLUMHEAD 2 TYPIST 0318 2800.00 serialno 24888 +PLUMHEAD 2 TYPIST 0318 2800.00 manager 27845 +STRONG 1 DIRECTOR 0021 23000.00 serialno 87777 +STRONG 1 DIRECTOR 0021 23000.00 secretary 22222 +BULLOZER 1 SALESMAN 0319 14800.00 serialno 76543 +BULLOZER 1 SALESMAN 0319 14800.00 manager 40567 +BULLOZER 1 SALESMAN 0319 14800.00 secretary 12345 +WERTHER 1 DIRECTOR 0318 14500.00 serialno 70012 +WERTHER 1 DIRECTOR 0318 14500.00 manager 87777 +WERTHER 1 DIRECTOR 0318 14500.00 secretary 27845 +QUINN 1 DIRECTOR 0319 14000.00 serialno 40567 +QUINN 1 DIRECTOR 0319 14000.00 manager 87777 +QUINN 1 DIRECTOR 0319 14000.00 secretary 55555 +ORELLY 1 ENGINEER 2452 13400.00 serialno 31416 +ORELLY 1 ENGINEER 2452 13400.00 manager 87777 +ORELLY 1 ENGINEER 2452 13400.00 secretary 11111 +BIGHORN 1 SCIENTIST 2452 11000.00 serialno 36666 +BIGHORN 1 SCIENTIST 2452 11000.00 manager 31416 +BIGHORN 1 SCIENTIST 2452 11000.00 secretary 11111 +BROWNY 1 ENGINEER 0319 10500.00 serialno 00137 +BROWNY 1 ENGINEER 0319 10500.00 manager 40567 +BROWNY 1 ENGINEER 0319 10500.00 secretary 12345 +WHEELFOR 1 SALESMAN 0318 10030.00 serialno 73111 +WHEELFOR 1 SALESMAN 0318 10030.00 manager 70012 +WHEELFOR 1 SALESMAN 0318 10030.00 secretary 24888 +MARTIN 1 ENGINEER 0319 10000.00 serialno 00023 +MARTIN 1 ENGINEER 0319 10000.00 manager 40567 +MARTIN 1 ENGINEER 0319 10000.00 secretary 12345 +DROP TABLE occurs; +DROP TABLE employee; +CREATE TABLE pets ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0, +cat INT NOT NULL DEFAULT 0, +rabbit INT NOT NULL DEFAULT 0, +bird INT NOT NULL DEFAULT 0, +fish INT NOT NULL DEFAULT 0) ENGINE=MYISAM; +INSERT INTO pets(name,dog) VALUES('John',2); +INSERT INTO pets(name,cat) VALUES('Bill',1); +INSERT INTO pets(name,dog,cat) VALUES('Mary',1,1); +INSERT INTO pets(name,rabbit) VALUES('Lisbeth',2); +INSERT INTO pets(name,cat,bird) VALUES('Kevin',2,6); +INSERT INTO pets(name,dog,fish) VALUES('Donald',1,3); +SELECT * FROM pets; +name dog cat rabbit bird fish +John 2 0 0 0 0 +Bill 0 1 0 0 0 +Mary 1 1 0 0 0 +Lisbeth 0 0 2 0 0 +Kevin 0 2 0 6 0 +Donald 1 0 0 0 3 +CREATE TABLE xpet (name VARCHAR(12) NOT NULL, race CHAR(6) NOT NULL, number INT) ENGINE=CONNECT TABLE_TYPE=OCCUR TABNAME=pets OPTION_LIST='OccurCol=number,RankCol=race,Colist=dog;cat;rabbit;bird;fish,port=PORT'; +SELECT * FROM xpet; +name race number +John dog 2 +John cat 0 +John rabbit 0 +John bird 0 +John fish 0 +Bill dog 0 +Bill cat 1 +Bill rabbit 0 +Bill bird 0 +Bill fish 0 +Mary dog 1 +Mary cat 1 +Mary rabbit 0 +Mary bird 0 +Mary fish 0 +Lisbeth dog 0 +Lisbeth cat 0 +Lisbeth rabbit 2 +Lisbeth bird 0 +Lisbeth fish 0 +Kevin dog 0 +Kevin cat 2 +Kevin rabbit 0 +Kevin bird 6 +Kevin fish 0 +Donald dog 1 +Donald cat 0 +Donald rabbit 0 +Donald bird 0 +Donald fish 3 +SELECT name FROM xpet; +name +John +Bill +Mary +Lisbeth +Kevin +Donald +SELECT name FROM xpet WHERE race = 'cat' AND number = 0; +name +John +Lisbeth +Donald +SELECT name, SUM(number) pets FROM xpet GROUP BY name; +name pets +Bill 1 +Donald 4 +John 2 +Kevin 8 +Lisbeth 2 +Mary 2 +ALTER TABLE xpet MODIFY number INT NOT NULL; +SELECT * FROM xpet; +name race number +John dog 2 +Bill cat 1 +Mary dog 1 +Mary cat 1 +Lisbeth rabbit 2 +Kevin cat 2 +Kevin bird 6 +Donald dog 1 +Donald fish 3 +SELECT * FROM xpet WHERE number > 1; +name race number +John dog 2 +Lisbeth rabbit 2 +Kevin cat 2 +Kevin bird 6 +Donald fish 3 +SELECT DISTINCT name FROM xpet WHERE number > 1; +name +John +Lisbeth +Kevin +Donald +SELECT name FROM xpet; +name +John +Bill +Mary +Lisbeth +Kevin +Donald +SELECT name, race FROM xpet; +name race +John +Bill +Mary +Lisbeth +Kevin +Donald +SELECT name, count(*) FROM xpet GROUP BY name, LEAST(number,1); +name count(*) +Bill 1 +Donald 2 +John 1 +Kevin 2 +Lisbeth 1 +Mary 2 +SELECT name, number, count(*) FROM xpet GROUP BY name, number; +name number count(*) +Bill 1 1 +Donald 1 1 +Donald 3 1 +John 2 1 +Kevin 2 1 +Kevin 6 1 +Lisbeth 2 1 +Mary 1 2 +DROP TABLE xpet; +DROP TABLE pets; diff --git a/storage/connect/mysql-test/connect/r/odbc_sqlite3.result b/storage/connect/mysql-test/connect/r/odbc_sqlite3.result index 87f7803166c..339dbb6a53d 100644 --- a/storage/connect/mysql-test/connect/r/odbc_sqlite3.result +++ b/storage/connect/mysql-test/connect/r/odbc_sqlite3.result @@ -4,20 +4,6 @@ t1 CREATE TABLE `t1` ( `Attributes` varchar(256) NOT NULL ) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Drivers' SET NAMES utf8; -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Sources; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=SQLite3 ODBC Driver;Database=MTR_SUITE_DIR/std_data/test.sqlite3;NoWCHAR=yes' CHARSET=utf8 DATA_CHARSET=utf8;; SHOW CREATE TABLE t1; Table Create Table @@ -31,42 +17,27 @@ test2 тест1 тест2 ÆÇÈÉË -SELECT user(); -user() -user@localhost -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO t1 VALUES ('xxx'); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1 WHERE a='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a='yyy' WHERE a='xxx'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` varchar(64) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +a +test1 +test2 +тест1 +тест2 +ÆÇÈÉË +DROP TABLE t2; CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost +a +test1 +test2 +тест1 +тест2 +ÆÇÈÉË DROP VIEW v1; DROP TABLE t1; -DROP USER user@localhost; diff --git a/storage/connect/mysql-test/connect/r/odbc_sqlite3_grant.result b/storage/connect/mysql-test/connect/r/odbc_sqlite3_grant.result new file mode 100644 index 00000000000..87f7803166c --- /dev/null +++ b/storage/connect/mysql-test/connect/r/odbc_sqlite3_grant.result @@ -0,0 +1,72 @@ +Table Create Table +t1 CREATE TABLE `t1` ( + `Description` varchar(128) NOT NULL, + `Attributes` varchar(256) NOT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='ODBC' `CATFUNC`='Drivers' +SET NAMES utf8; +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Sources; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=SQLite3 ODBC Driver;Database=MTR_SUITE_DIR/std_data/test.sqlite3;NoWCHAR=yes' CHARSET=utf8 DATA_CHARSET=utf8;; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(64) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='Driver=SQLite3 ODBC Driver;Database=MTR_SUITE_DIR/std_data/test.sqlite3;NoWCHAR=yes' `TABLE_TYPE`='ODBC' `DATA_CHARSET`='utf8' +SELECT * FROM t1; +a +test1 +test2 +тест1 +тест2 +ÆÇÈÉË +SELECT user(); +user() +user@localhost +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO t1 VALUES ('xxx'); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1 WHERE a='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a='yyy' WHERE a='xxx'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +DROP USER user@localhost; diff --git a/storage/connect/mysql-test/connect/r/pivot.result b/storage/connect/mysql-test/connect/r/pivot.result new file mode 100644 index 00000000000..1b790662c4b --- /dev/null +++ b/storage/connect/mysql-test/connect/r/pivot.result @@ -0,0 +1,230 @@ +# +# Testing the PIVOT table type +# +CREATE TABLE expenses ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +What CHAR(12) NOT NULL, +Amount DOUBLE(8,2)) +ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='expenses.txt' ENDING=2; +SELECT * FROM expenses; +Who Week What Amount +Joe 3 Beer 18.00 +Beth 4 Food 17.00 +Janet 5 Beer 14.00 +Joe 3 Food 12.00 +Joe 4 Beer 19.00 +Janet 5 Car 12.00 +Joe 3 Food 19.00 +Beth 4 Beer 15.00 +Janet 5 Beer 19.00 +Joe 3 Car 20.00 +Joe 4 Beer 16.00 +Beth 5 Food 12.00 +Beth 3 Beer 16.00 +Joe 4 Food 17.00 +Joe 5 Beer 14.00 +Janet 3 Car 19.00 +Joe 4 Food 17.00 +Beth 5 Beer 20.00 +Janet 3 Food 18.00 +Joe 4 Beer 14.00 +Joe 5 Food 12.00 +Janet 3 Beer 18.00 +Janet 4 Car 17.00 +Janet 5 Food 12.00 +# +# Pivoting from What +# +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +Beer DOUBLE(8,2) FLAG=1, +Car DOUBLE(8,2) FLAG=1, +Food DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=expenses; +ALTER TABLE pivex OPTION_LIST='port=PORT'; +Warnings: +Warning 1105 The current version of CONNECT did not check what you changed in ALTER. Use at your own risk +SELECT * FROM pivex; +Who Week Beer Car Food +Beth 3 16.00 0.00 0.00 +Beth 4 15.00 0.00 17.00 +Beth 5 20.00 0.00 12.00 +Janet 3 18.00 19.00 18.00 +Janet 4 0.00 17.00 0.00 +Janet 5 33.00 12.00 12.00 +Joe 3 18.00 20.00 31.00 +Joe 4 49.00 0.00 34.00 +Joe 5 14.00 0.00 12.00 +# +# Restricting the columns in a Pivot Table +# +ALTER TABLE pivex DROP COLUMN week; +SELECT * FROM pivex; +Who Beer Car Food +Beth 51.00 0.00 29.00 +Janet 51.00 48.00 30.00 +Joe 81.00 20.00 77.00 +# +# Using a source definition +# +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +Beer DOUBLE(8,2) FLAG=1, +Car DOUBLE(8,2) FLAG=1, +Food DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT +SRCDEF='select who, week, what, sum(amount) as amount from expenses where week in (4,5) group by who, week, what'; +ALTER TABLE pivex OPTION_LIST='PivotCol=what,FncCol=amount,port=PORT'; +Warnings: +Warning 1105 The current version of CONNECT did not check what you changed in ALTER. Use at your own risk +SELECT * FROM pivex; +Who Week Beer Car Food +Beth 4 15.00 0.00 17.00 +Beth 5 20.00 0.00 12.00 +Janet 4 0.00 17.00 0.00 +Janet 5 33.00 12.00 12.00 +Joe 4 49.00 0.00 34.00 +Joe 5 14.00 0.00 12.00 +# +# Pivoting from Week +# +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +What CHAR(12) NOT NULL, +`3` DOUBLE(8,2) FLAG=1, +`4` DOUBLE(8,2) FLAG=1, +`5` DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=expenses; +ALTER TABLE pivex OPTION_LIST='PivotCol=Week,port=PORT'; +Warnings: +Warning 1105 The current version of CONNECT did not check what you changed in ALTER. Use at your own risk +SELECT * FROM pivex; +Who What 3 4 5 +Beth Beer 16.00 15.00 20.00 +Beth Food 0.00 17.00 12.00 +Janet Beer 18.00 0.00 33.00 +Janet Car 19.00 17.00 12.00 +Janet Food 18.00 0.00 12.00 +Joe Beer 18.00 49.00 14.00 +Joe Car 20.00 0.00 0.00 +Joe Food 31.00 34.00 12.00 +# +# Using scalar functions and expresssions +# +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +What CHAR(12) NOT NULL, +First DOUBLE(8,2) FLAG=1, +Middle DOUBLE(8,2) FLAG=1, +Last DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT +SRCDEF='select who, what, case when week=3 then ''First'' when week=5 then ''Last'' else ''Middle'' end as wk, sum(amount) * 6.56 as amnt from expenses group by who, what, wk'; +ALTER TABLE pivex OPTION_LIST='PivotCol=wk,FncCol=amnt,port=PORT'; +Warnings: +Warning 1105 The current version of CONNECT did not check what you changed in ALTER. Use at your own risk +SELECT * FROM pivex; +Who What First Middle Last +Beth Beer 104.96 98.40 131.20 +Beth Food 0.00 111.52 78.72 +Janet Beer 118.08 0.00 216.48 +Janet Car 124.64 111.52 78.72 +Janet Food 118.08 0.00 78.72 +Joe Beer 118.08 321.44 91.84 +Joe Car 131.20 0.00 0.00 +Joe Food 203.36 223.04 78.72 +DROP TABLE pivex; +DROP TABLE expenses; +# +# Make the PETS table +# +CREATE TABLE pets ( +Name VARCHAR(12) NOT NULL, +Race CHAR(6) NOT NULL, +Number INT NOT NULL) ENGINE=MYISAM; +INSERT INTO pets VALUES('John','dog',2); +INSERT INTO pets VALUES('Bill','cat',1); +INSERT INTO pets VALUES('Mary','dog',1); +INSERT INTO pets VALUES('Mary','cat',1); +INSERT INTO pets VALUES('Lisbeth','rabbit',2); +INSERT INTO pets VALUES('Kevin','cat',2); +INSERT INTO pets VALUES('Kevin','bird',6); +INSERT INTO pets VALUES('Donald','dog',1); +INSERT INTO pets VALUES('Donald','fish',3); +SELECT * FROM pets; +Name Race Number +John dog 2 +Bill cat 1 +Mary dog 1 +Mary cat 1 +Lisbeth rabbit 2 +Kevin cat 2 +Kevin bird 6 +Donald dog 1 +Donald fish 3 +# +# Pivot the PETS table +# +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1, +rabbit INT NOT NULL DEFAULT 0 FLAG=1, +bird INT NOT NULL DEFAULT 0 FLAG=1, +fish INT NOT NULL DEFAULT 0 FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +SELECT * FROM pivet; +name dog cat rabbit bird fish +John 2 0 0 0 0 +Bill 0 1 0 0 0 +Mary 1 1 0 0 0 +Lisbeth 0 0 2 0 0 +Kevin 0 2 0 6 0 +Donald 1 0 0 0 3 +DROP TABLE pivet; +# +# Testing the "data" column list +# +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +SELECT * FROM pivet; +ERROR HY000: Got error 122 'Cannot find matching column' from CONNECT +ALTER TABLE pivet OPTION_LIST='PivotCol=race,groupby=1,accept=1'; +Warnings: +Warning 1105 The current version of CONNECT did not check what you changed in ALTER. Use at your own risk +SELECT * FROM pivet; +name dog cat +John 2 0 +Bill 0 1 +Mary 1 1 +Lisbeth 0 0 +Kevin 0 2 +Donald 1 0 +DROP TABLE pivet; +# +# Adding a "dump" column +# +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1, +other INT NOT NULL DEFAULT 0 FLAG=2) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +SELECT * FROM pivet; +name dog cat other +John 2 0 0 +Bill 0 1 0 +Mary 1 1 0 +Lisbeth 0 0 2 +Kevin 0 2 6 +Donald 1 0 3 +DROP TABLE pivet; +DROP TABLE pets; diff --git a/storage/connect/mysql-test/connect/r/tbl.result b/storage/connect/mysql-test/connect/r/tbl.result index 01a6afcebe8..bc77516c22d 100644 --- a/storage/connect/mysql-test/connect/r/tbl.result +++ b/storage/connect/mysql-test/connect/r/tbl.result @@ -4,6 +4,9 @@ CREATE TABLE t1 ( a INT NOT NULL, message CHAR(10)) ENGINE=connect; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos INSERT INTO t1 VALUES (1,'Testing'),(2,'dos table'),(3,'t1'); SELECT * FROM t1; a message diff --git a/storage/connect/mysql-test/connect/r/upd.result b/storage/connect/mysql-test/connect/r/upd.result index 24cfdafaa9a..fa519c4b688 100644 --- a/storage/connect/mysql-test/connect/r/upd.result +++ b/storage/connect/mysql-test/connect/r/upd.result @@ -59,6 +59,9 @@ END// # Testing DOS table changes # CREATE TABLE t1 ENGINE=connect AS SELECT * FROM employee; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos CALL test.tst_up(); serialno name sex title manager department secretary salary 74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00 @@ -154,6 +157,9 @@ serialno name sex title manager department secretary salary # Testing DOS table changes # CREATE TABLE t1 ENGINE=connect mapped=yes AS SELECT * FROM employee; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos CALL test.tst_up(); serialno name sex title manager department secretary salary 74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00 diff --git a/storage/connect/mysql-test/connect/r/vec.result b/storage/connect/mysql-test/connect/r/vec.result index 9461966aef7..65513dc07db 100644 --- a/storage/connect/mysql-test/connect/r/vec.result +++ b/storage/connect/mysql-test/connect/r/vec.result @@ -1,97 +1,3 @@ -# -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100; -Warnings: -Warning 1105 No file name. Table will use t1.vec -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100 FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=VEC MAX_ROWS=100; -Warnings: -Warning 1105 No file name. Table will use t1.vec -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# CREATE TABLE dir1 ( spath VARCHAR(256) NOT NULL flag=1, fname VARCHAR(256) NOT NULL, diff --git a/storage/connect/mysql-test/connect/r/xcol.result b/storage/connect/mysql-test/connect/r/xcol.result new file mode 100644 index 00000000000..f6899b47504 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/xcol.result @@ -0,0 +1,85 @@ +# +# Checking XCOL tables +# +CREATE TABLE chlist ( +mother char(12) NOT NULL COMMENT 'The mother of the listed children', +children varchar(30) DEFAULT NULL COMMENT 'The comma separated list of children' +) ENGINE=CONNECT; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use chlist.dos +INSERT INTO chlist VALUES('Sophia','Vivian, Antony'); +INSERT INTO chlist VALUES('Lisbeth','Lucy,Charles,Diana'); +INSERT INTO chlist VALUES('Corinne',NULL); +INSERT INTO chlist VALUES('Claude','Marc'); +INSERT INTO chlist VALUES('Janet','Arthur,Sandra,Peter,John'); +SELECT * FROM chlist; +mother children +Sophia Vivian, Antony +Lisbeth Lucy,Charles,Diana +Corinne NULL +Claude Marc +Janet Arthur,Sandra,Peter,John +CREATE TABLE child ENGINE=CONNECT TABLE_TYPE=XCOL TABNAME=chlist OPTION_LIST='colname=children,port=PORT'; +SELECT * FROM child; +mother children +Sophia Vivian +Sophia Antony +Lisbeth Lucy +Lisbeth Charles +Lisbeth Diana +Corinne NULL +Claude Marc +Janet Arthur +Janet Sandra +Janet Peter +Janet John +SELECT * FROM child ORDER BY mother; +mother children +Claude Marc +Corinne NULL +Janet Peter +Janet Sandra +Janet Arthur +Janet John +Lisbeth Diana +Lisbeth Charles +Lisbeth Lucy +Sophia Antony +Sophia Vivian +SELECT * FROM child ORDER BY children; +mother children +Corinne NULL +Sophia Antony +Janet Arthur +Lisbeth Charles +Lisbeth Diana +Janet John +Lisbeth Lucy +Claude Marc +Janet Peter +Janet Sandra +Sophia Vivian +SELECT mother FROM child; +mother +Sophia +Lisbeth +Corinne +Claude +Janet +SELECT mother, COUNT(*) FROM child GROUP BY mother; +mother COUNT(*) +Claude 1 +Corinne 1 +Janet 1 +Lisbeth 1 +Sophia 1 +SELECT mother, COUNT(children) FROM child GROUP BY mother; +mother COUNT(children) +Claude 1 +Corinne 0 +Janet 4 +Lisbeth 3 +Sophia 2 +DROP TABLE child; +DROP TABLE chlist; diff --git a/storage/connect/mysql-test/connect/r/xml.result b/storage/connect/mysql-test/connect/r/xml.result index e7dcf8f4c73..67fcc5f121e 100644 --- a/storage/connect/mysql-test/connect/r/xml.result +++ b/storage/connect/mysql-test/connect/r/xml.result @@ -1,99 +1,5 @@ Warnings: Warning 1105 No file name. Table will use t1.xml -# -# Beginning of grant.inc -# -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; -SELECT user(); -user() -user@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; -Warnings: -Warning 1105 No file name. Table will use t1.xml -INSERT INTO t1 VALUES (10); -SELECT * FROM t1; -a -10 -UPDATE t1 SET a=20; -SELECT * FROM t1; -a -20 -DELETE FROM t1; -SELECT * FROM t1; -a -INSERT INTO t1 VALUES(10); -TRUNCATE TABLE t1; -SELECT * FROM t1; -a -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -a -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row' FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row' FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -INSERT INTO t1 VALUES (10); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE t1 SET a=20; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -TRUNCATE TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 READONLY=1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -ALTER TABLE t1 FILE_NAME='t2.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -CREATE VIEW v1 AS SELECT * FROM t1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -# Testing a VIEW created with FILE privileges but accessed with no FILE -SELECT user(); -user() -root@localhost -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT user(); -user() -user@localhost -SELECT * FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -INSERT INTO v1 VALUES (2); -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -UPDATE v1 SET a=123; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DELETE FROM v1; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -SELECT user(); -user() -root@localhost -DROP VIEW v1; -DROP TABLE t1; -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; -Warnings: -Warning 1105 No file name. Table will use t1.xml -INSERT INTO t1 VALUES (10); -SELECT user(); -user() -user@localhost -ALTER TABLE t1 FILE_NAME='t1.EXT'; -ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) -DROP TABLE t1; -DROP USER user@localhost; -# -# End of grant.inc -# SET NAMES utf8; # # Testing tag values @@ -253,8 +159,8 @@ TITLE XML, Langage et Applications TRANSLATOR NULL PUBLISHER Eyrolles Paris DATEPUB 1998 -SELECT LOAD_FILE('test/xsample2.xml'); -LOAD_FILE('test/xsample2.xml') +SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml; +xml @@ -467,7 +373,7 @@ SELECT node, hex(node) FROM t1; node ÀÁÂÃ hex(node) C0C1C2C3 DROP TABLE t1; -SET @a=LOAD_FILE('test/t1.xml'); +SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml'); SELECT LEFT(@a,38); LEFT(@a,38) SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node')); @@ -481,7 +387,7 @@ SELECT node, hex(node) FROM t1; node ÀÁÂÃ hex(node) C0C1C2C3 DROP TABLE t1; -SET @a=LOAD_FILE('test/t1.xml'); +SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml'); SELECT LEFT(@a,43); LEFT(@a,43) SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node')); @@ -504,10 +410,10 @@ hex(node) D090D091D092D093 node &<>"' hex(node) 263C3E2227 DROP TABLE t1; -SET @a=LOAD_FILE('test/t1.xml'); +SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml'); SELECT CAST(@a AS CHAR CHARACTER SET latin1); CAST(@a AS CHAR CHARACTER SET latin1) - + ÀÁÂÃ diff --git a/storage/connect/mysql-test/connect/r/xml_grant.result b/storage/connect/mysql-test/connect/r/xml_grant.result new file mode 100644 index 00000000000..ea38e57af86 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/xml_grant.result @@ -0,0 +1,96 @@ +Warnings: +Warning 1105 No file name. Table will use t1.xml +# +# Beginning of grant.inc +# +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +SELECT user(); +user() +user@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; +Warnings: +Warning 1105 No file name. Table will use t1.xml +INSERT INTO t1 VALUES (10); +SELECT * FROM t1; +a +10 +UPDATE t1 SET a=20; +SELECT * FROM t1; +a +20 +DELETE FROM t1; +SELECT * FROM t1; +a +INSERT INTO t1 VALUES(10); +TRUNCATE TABLE t1; +SELECT * FROM t1; +a +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row' FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row' FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +INSERT INTO t1 VALUES (10); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE t1 SET a=20; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +TRUNCATE TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 READONLY=1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +ALTER TABLE t1 FILE_NAME='t2.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +CREATE VIEW v1 AS SELECT * FROM t1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +# Testing a VIEW created with FILE privileges but accessed with no FILE +SELECT user(); +user() +root@localhost +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT user(); +user() +user@localhost +SELECT * FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +INSERT INTO v1 VALUES (2); +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +UPDATE v1 SET a=123; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DELETE FROM v1; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +SELECT user(); +user() +root@localhost +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; +Warnings: +Warning 1105 No file name. Table will use t1.xml +INSERT INTO t1 VALUES (10); +SELECT user(); +user() +user@localhost +ALTER TABLE t1 FILE_NAME='t1.EXT'; +ERROR 28000: Access denied for user 'user'@'localhost' (using password: NO) +DROP TABLE t1; +DROP USER user@localhost; +# +# End of grant.inc +# diff --git a/storage/connect/mysql-test/connect/std_data/expenses.txt b/storage/connect/mysql-test/connect/std_data/expenses.txt new file mode 100644 index 00000000000..66a94edbb9a --- /dev/null +++ b/storage/connect/mysql-test/connect/std_data/expenses.txt @@ -0,0 +1,24 @@ +Joe 3Beer 18.00 +Beth 4Food 17.00 +Janet 5Beer 14.00 +Joe 3Food 12.00 +Joe 4Beer 19.00 +Janet 5Car 12.00 +Joe 3Food 19.00 +Beth 4Beer 15.00 +Janet 5Beer 19.00 +Joe 3Car 20.00 +Joe 4Beer 16.00 +Beth 5Food 12.00 +Beth 3Beer 16.00 +Joe 4Food 17.00 +Joe 5Beer 14.00 +Janet 3Car 19.00 +Joe 4Food 17.00 +Beth 5Beer 20.00 +Janet 3Food 18.00 +Joe 4Beer 14.00 +Joe 5Food 12.00 +Janet 3Beer 18.00 +Janet 4Car 17.00 +Janet 5Food 12.00 diff --git a/storage/connect/mysql-test/connect/t/bin.test b/storage/connect/mysql-test/connect/t/bin.test index 0266fd3e357..a9dab32987e 100644 --- a/storage/connect/mysql-test/connect/t/bin.test +++ b/storage/connect/mysql-test/connect/t/bin.test @@ -1,9 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=BIN; -let $FILE_EXT=BIN; ---source grant.inc - --copy_file $MTR_SUITE_DIR/std_data/Testbal.dat $MYSQLD_DATADIR/test/Testbal.dat --echo # diff --git a/storage/connect/mysql-test/connect/t/csv.test b/storage/connect/mysql-test/connect/t/csv.test index 6578ba83a9a..685ac434df7 100644 --- a/storage/connect/mysql-test/connect/t/csv.test +++ b/storage/connect/mysql-test/connect/t/csv.test @@ -1,9 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=CSV; -let $FILE_EXT=CSV; ---source grant.inc - --copy_file $MTR_SUITE_DIR/std_data/people.csv $MYSQLD_DATADIR/test/people.csv SET NAMES utf8; diff --git a/storage/connect/mysql-test/connect/t/dbf.test b/storage/connect/mysql-test/connect/t/dbf.test index fb0bc21f52d..b9a1b6e2183 100644 --- a/storage/connect/mysql-test/connect/t/dbf.test +++ b/storage/connect/mysql-test/connect/t/dbf.test @@ -1,9 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=DBF; -let $FILE_EXT=DBF; ---source grant.inc - --echo # --echo # Testing errors --echo # diff --git a/storage/connect/mysql-test/connect/t/dir.test b/storage/connect/mysql-test/connect/t/dir.test index 073cdaa380b..fb69813d9f0 100644 --- a/storage/connect/mysql-test/connect/t/dir.test +++ b/storage/connect/mysql-test/connect/t/dir.test @@ -1,76 +1,6 @@ let $MYSQLD_DATADIR= `select @@datadir`; ---echo # ---echo # Testing FILE privilege ---echo # -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; ---connect(user,localhost,user,,) ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -CREATE TABLE t1 ( - path VARCHAR(256) NOT NULL flag=1, - fname VARCHAR(256) NOT NULL, - ftype CHAR(4) NOT NULL, - size DOUBLE(12,0) NOT NULL flag=5 -) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; ---connection default -SELECT user(); -CREATE TABLE t1 ( - path VARCHAR(256) NOT NULL flag=1, - fname VARCHAR(256) NOT NULL, - ftype CHAR(4) NOT NULL, - size DOUBLE(12,0) NOT NULL flag=5 -) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; -# "size>0" to skip directory names on Windows ---replace_result $MYSQLD_DATADIR DATADIR/ -SELECT fname, ftype, size FROM t1 WHERE size>0; - ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM t1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO t1 VALUES (); ---error ER_ACCESS_DENIED_ERROR -DELETE FROM t1 WHERE path='xxx'; ---error ER_ACCESS_DENIED_ERROR -UPDATE t1 SET path='yyy' WHERE path='xxx'; ---error ER_ACCESS_DENIED_ERROR -TRUNCATE TABLE t1; ---error ER_ACCESS_DENIED_ERROR -ALTER TABLE t1 READONLY=1; ---error ER_ACCESS_DENIED_ERROR -CREATE VIEW v1 AS SELECT * FROM t1; - ---echo # Testing a VIEW created with FILE privileges but accessed with no FILE ---connection default -SELECT user(); -CREATE VIEW v1 AS SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM v1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO v1 VALUES (1,1,1,1); ---error ER_ACCESS_DENIED_ERROR -UPDATE v1 SET path=123; ---error ER_ACCESS_DENIED_ERROR -DELETE FROM v1; - ---disconnect user ---connection default -SELECT user(); -DROP VIEW v1; -DROP TABLE t1; -DROP USER user@localhost; ---echo # ---echo # Testing FILE privileges done ---echo # - - CREATE TABLE t1 ( path VARCHAR(256) NOT NULL flag=1, fname VARCHAR(256) NOT NULL, diff --git a/storage/connect/mysql-test/connect/t/fix.test b/storage/connect/mysql-test/connect/t/fix.test index d2dfeb21352..c3cec55a217 100644 --- a/storage/connect/mysql-test/connect/t/fix.test +++ b/storage/connect/mysql-test/connect/t/fix.test @@ -1,9 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=FIX; -let $FILE_EXT=FIX; ---source grant.inc - --copy_file $MTR_SUITE_DIR/std_data/dept.dat $MYSQLD_DATADIR/test/dept.dat --copy_file $MTR_SUITE_DIR/std_data/boys.txt $MYSQLD_DATADIR/test/boys.txt --copy_file $MTR_SUITE_DIR/std_data/boyswin.txt $MYSQLD_DATADIR/test/boyswin.txt diff --git a/storage/connect/mysql-test/connect/t/fmt.test b/storage/connect/mysql-test/connect/t/fmt.test index de7f8c06c1b..662bc70c8b1 100644 --- a/storage/connect/mysql-test/connect/t/fmt.test +++ b/storage/connect/mysql-test/connect/t/fmt.test @@ -1,85 +1,85 @@ -let $MYSQLD_DATADIR= `select @@datadir`; ---copy_file $MTR_SUITE_DIR/std_data/funny.txt $MYSQLD_DATADIR/test/funny.txt ---copy_file $MTR_SUITE_DIR/std_data/funny2.txt $MYSQLD_DATADIR/test/funny2.txt - ---echo # ---echo # Testing errors ---echo # -CREATE TABLE t1 -( - ID INT NOT NULL field_format=' %n%d%n' -) Engine=CONNECT table_type=FMT file_name='nonexistent.txt'; ---replace_regex /on .*test.nonexistent.txt/on DATADIR\/test\/nonexistent.txt/ -# TODO: check why this is needed for Windows ---replace_result Open(rt) Open(rb) -SELECT * FROM t1; -DROP TABLE t1; - - ---echo # ---echo # Testing update on FMT tables ---echo # -CREATE TABLE t1 -( - id INT NOT NULL field_format=' %n%d%n' -) ENGINE=CONNECT TABLE_TYPE=FMT FILE_NAME='t1.txt'; ---error ER_GET_ERRMSG -INSERT INTO t1 VALUES (10),(20); -# TODO: -#--error ER_GET_ERRMSG -#UPDATE t1 SET id=20; -#TRUNCATE TABLE t1; -#DELETE FROM t1 WHERE id=10; -#SELECT * FROM t1; -DROP TABLE t1; ---remove_file $MYSQLD_DATADIR/test/t1.txt - - ---echo # ---echo # Testing manual examples ---echo # -CREATE TABLE t1 -( - ID Integer(5) not null field_format=' %n%d%n', - NAME Char(16) not null field_format=" , '%n%[^']%n'", - DEPNO Integer(4) not null field_format=' , #%n%d%n', - SALARY Double(12,2) not null field_format=' ; %n%f%n' -) Engine=CONNECT table_type=FMT file_name='funny.txt'; -SELECT * FROM t1; -DROP TABLE t1; - -# -# TODO: shoudn't a warning instead of error be returned on bad format? -# -CREATE TABLE t1 -( - ID Integer(5) not null field_format=' %n%d%n', - NAME Char(16) not null field_format=" , '%n%[^']%n'", - DEPNO Integer(4) not null field_format=' , #%n%d%n', - SALARY Double(12,2) not null field_format=' ; %n%f%n' -) Engine=CONNECT table_type=FMT file_name='funny2.txt'; ---error ER_GET_ERRMSG -SELECT * FROM t1; -DROP TABLE t1; - -CREATE TABLE t1 -( - ID Integer(5) not null field_format=' %n%d%n', - NAME Char(16) not null field_format=' , ''%n%[^'']%m', - DEPNO Integer(4) not null field_format=''' , #%n%d%m', - SALARY Double(12,2) not null field_format=' ; %n%f%n' -) Engine=CONNECT table_type=FMT file_name='funny2.txt'; -SELECT * FROM t1; ---error ER_GET_ERRMSG -UPDATE t1 SET SALARY=1234; -# TODO: this query crashes -# UPDATE t1 SET SALARY=1234 WHERE ID=56; -DELETE FROM t1 WHERE ID=56; -SELECT * FROM t1; -DROP TABLE t1; - -# -# Clean up -# ---remove_file $MYSQLD_DATADIR/test/funny.txt ---remove_file $MYSQLD_DATADIR/test/funny2.txt +let $MYSQLD_DATADIR= `select @@datadir`; +--copy_file $MTR_SUITE_DIR/std_data/funny.txt $MYSQLD_DATADIR/test/funny.txt +--copy_file $MTR_SUITE_DIR/std_data/funny2.txt $MYSQLD_DATADIR/test/funny2.txt + +--echo # +--echo # Testing errors +--echo # +CREATE TABLE t1 +( + ID INT NOT NULL field_format=' %n%d%n' +) Engine=CONNECT table_type=FMT file_name='nonexistent.txt'; +--replace_regex /on .*test.nonexistent.txt/on DATADIR\/test\/nonexistent.txt/ +# TODO: check why this is needed for Windows +--replace_result Open(rt) Open(rb) +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Testing update on FMT tables +--echo # +CREATE TABLE t1 +( + id INT NOT NULL field_format=' %n%d%n' +) ENGINE=CONNECT TABLE_TYPE=FMT FILE_NAME='t1.txt'; +--error ER_GET_ERRMSG +INSERT INTO t1 VALUES (10),(20); +# TODO: +#--error ER_GET_ERRMSG +#UPDATE t1 SET id=20; +#TRUNCATE TABLE t1; +#DELETE FROM t1 WHERE id=10; +#SELECT * FROM t1; +DROP TABLE t1; +#--remove_file $MYSQLD_DATADIR/test/t1.txt + + +--echo # +--echo # Testing manual examples +--echo # +CREATE TABLE t1 +( + ID Integer(5) not null field_format=' %n%d%n', + NAME Char(16) not null field_format=" , '%n%[^']%n'", + DEPNO Integer(4) not null field_format=' , #%n%d%n', + SALARY Double(12,2) not null field_format=' ; %n%f%n' +) Engine=CONNECT table_type=FMT file_name='funny.txt'; +SELECT * FROM t1; +DROP TABLE t1; + +# +# TODO: shoudn't a warning instead of error be returned on bad format? +# +CREATE TABLE t1 +( + ID Integer(5) not null field_format=' %n%d%n', + NAME Char(16) not null field_format=" , '%n%[^']%n'", + DEPNO Integer(4) not null field_format=' , #%n%d%n', + SALARY Double(12,2) not null field_format=' ; %n%f%n' +) Engine=CONNECT table_type=FMT file_name='funny2.txt'; +--error ER_GET_ERRMSG +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 +( + ID Integer(5) not null field_format=' %n%d%n', + NAME Char(16) not null field_format=' , ''%n%[^'']%m', + DEPNO Integer(4) not null field_format=''' , #%n%d%m', + SALARY Double(12,2) not null field_format=' ; %n%f%n' +) Engine=CONNECT table_type=FMT file_name='funny2.txt'; +SELECT * FROM t1; +--error ER_GET_ERRMSG +UPDATE t1 SET SALARY=1234; +# TODO: this query crashes +# UPDATE t1 SET SALARY=1234 WHERE ID=56; +DELETE FROM t1 WHERE ID=56; +SELECT * FROM t1; +DROP TABLE t1; + +# +# Clean up +# +--remove_file $MYSQLD_DATADIR/test/funny.txt +--remove_file $MYSQLD_DATADIR/test/funny2.txt diff --git a/storage/connect/mysql-test/connect/t/grant.test b/storage/connect/mysql-test/connect/t/grant.test new file mode 100644 index 00000000000..909bb4117a1 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/grant.test @@ -0,0 +1,95 @@ +-- source include/not_embedded.inc + +let $MYSQLD_DATADIR= `select @@datadir`; + +--echo # +--echo # Testing FILE privilege +--echo # +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +--connect(user,localhost,user,,) +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +CREATE TABLE t1 ( + path VARCHAR(256) NOT NULL flag=1, + fname VARCHAR(256) NOT NULL, + ftype CHAR(4) NOT NULL, + size DOUBLE(12,0) NOT NULL flag=5 +) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; +--connection default +SELECT user(); +CREATE TABLE t1 ( + path VARCHAR(256) NOT NULL flag=1, + fname VARCHAR(256) NOT NULL, + ftype CHAR(4) NOT NULL, + size DOUBLE(12,0) NOT NULL flag=5 +) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; +# "size>0" to skip directory names on Windows +--replace_result $MYSQLD_DATADIR DATADIR/ +SELECT fname, ftype, size FROM t1 WHERE size>0; + +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO t1 VALUES (); +--error ER_ACCESS_DENIED_ERROR +DELETE FROM t1 WHERE path='xxx'; +--error ER_ACCESS_DENIED_ERROR +UPDATE t1 SET path='yyy' WHERE path='xxx'; +--error ER_ACCESS_DENIED_ERROR +TRUNCATE TABLE t1; +--error ER_ACCESS_DENIED_ERROR +ALTER TABLE t1 READONLY=1; +--error ER_ACCESS_DENIED_ERROR +CREATE VIEW v1 AS SELECT * FROM t1; + +--echo # Testing a VIEW created with FILE privileges but accessed with no FILE +--connection default +SELECT user(); +CREATE VIEW v1 AS SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO v1 VALUES (1,1,1,1); +--error ER_ACCESS_DENIED_ERROR +UPDATE v1 SET path=123; +--error ER_ACCESS_DENIED_ERROR +DELETE FROM v1; + +--disconnect user +--connection default +SELECT user(); +DROP VIEW v1; +DROP TABLE t1; +DROP USER user@localhost; +--echo # +--echo # Testing FILE privileges done +--echo # + + +let $TABLE_OPTIONS=TABLE_TYPE=BIN; +let $FILE_EXT=BIN; +--source grant.inc + +let $TABLE_OPTIONS=TABLE_TYPE=CSV; +let $FILE_EXT=CSV; +--source grant.inc + +let $TABLE_OPTIONS=TABLE_TYPE=DBF; +let $FILE_EXT=DBF; +--source grant.inc + +let $TABLE_OPTIONS=TABLE_TYPE=FIX; +let $FILE_EXT=FIX; +--source grant.inc + +let $TABLE_OPTIONS=TABLE_TYPE=VEC MAX_ROWS=100; +let $FILE_EXT=VEC; +--source grant.inc + + diff --git a/storage/connect/mysql-test/connect/t/have_odbc_sqlite3.inc b/storage/connect/mysql-test/connect/t/have_odbc_sqlite3.inc new file mode 100644 index 00000000000..9528e00ff56 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/have_odbc_sqlite3.inc @@ -0,0 +1,15 @@ +--disable_query_log +--error 0,ER_UNKNOWN_ERROR +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; +if ($mysql_errno) +{ + Skip No ODBC support; +} +if (!`SELECT count(*) FROM t1 WHERE Description='SQLite3 ODBC Driver'`) +{ + DROP TABLE t1; + Skip Need SQLite3 ODBC Driver; +} +SHOW CREATE TABLE t1; +DROP TABLE t1; +--enable_query_log diff --git a/storage/connect/mysql-test/connect/t/ini.test b/storage/connect/mysql-test/connect/t/ini.test index e862f3cd672..0d23142ac9e 100644 --- a/storage/connect/mysql-test/connect/t/ini.test +++ b/storage/connect/mysql-test/connect/t/ini.test @@ -1,80 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; ---echo # ---echo # Checking FILE privileges ---echo # -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; ---connect(user,localhost,user,,) ---connection user -SELECT user(); -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI; -INSERT INTO t1 VALUES ('sec1','val1'); -SELECT * FROM t1; -UPDATE t1 SET val='val11'; -SELECT * FROM t1; -DELETE FROM t1; -SELECT * FROM t1; -INSERT INTO t1 VALUES('sec2','val2'); -TRUNCATE TABLE t1; -SELECT * FROM t1; -CREATE VIEW v1 AS SELECT * FROM t1; -SELECT * FROM v1; -DROP VIEW v1; -DROP TABLE t1; -# Making sure DROP erased the data file ---error 1 ---remove_file $MYSQLD_DATADIR/test/t1.ini ---error ER_ACCESS_DENIED_ERROR -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; ---connection default -SELECT user(); -CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; -INSERT INTO t1 VALUES ('sec1','val1'); ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -INSERT INTO t1 VALUES ('sec2','val2'); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM t1; ---error ER_ACCESS_DENIED_ERROR -UPDATE t1 SET val='val11'; ---error ER_ACCESS_DENIED_ERROR -DELETE FROM t1; ---error ER_ACCESS_DENIED_ERROR -TRUNCATE TABLE t1; ---error ER_ACCESS_DENIED_ERROR -ALTER TABLE t1 READONLY=1; ---error ER_ACCESS_DENIED_ERROR -DROP TABLE t1; ---error ER_ACCESS_DENIED_ERROR -CREATE VIEW v1 AS SELECT * FROM t1; ---echo # Testing a VIEW created with FILE privileges but accessed with no FILE ---connection default -SELECT user(); -CREATE VIEW v1 AS SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM v1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO v1 VALUES ('sec3','val3'); ---error ER_ACCESS_DENIED_ERROR -UPDATE v1 SET val='val11'; ---error ER_ACCESS_DENIED_ERROR -DELETE FROM v1; ---disconnect user ---connection default -DROP VIEW v1; -DROP TABLE t1; ---remove_file $MYSQLD_DATADIR/test/t1.EXT -DROP USER user@localhost; - ---echo # ---echo # Checking FILE privileges: done ---echo # - - --copy_file $MTR_SUITE_DIR/std_data/contact.ini $MYSQLD_DATADIR/test/contact.ini --echo # diff --git a/storage/connect/mysql-test/connect/t/ini_grant.test b/storage/connect/mysql-test/connect/t/ini_grant.test new file mode 100644 index 00000000000..30678645692 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/ini_grant.test @@ -0,0 +1,79 @@ +-- source include/not_embedded.inc + +let $MYSQLD_DATADIR= `select @@datadir`; + +--echo # +--echo # Checking FILE privileges +--echo # +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +--connect(user,localhost,user,,) +--connection user +SELECT user(); +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI; +INSERT INTO t1 VALUES ('sec1','val1'); +SELECT * FROM t1; +UPDATE t1 SET val='val11'; +SELECT * FROM t1; +DELETE FROM t1; +SELECT * FROM t1; +INSERT INTO t1 VALUES('sec2','val2'); +TRUNCATE TABLE t1; +SELECT * FROM t1; +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM v1; +DROP VIEW v1; +DROP TABLE t1; +# Making sure DROP erased the data file +--error 1 +--remove_file $MYSQLD_DATADIR/test/t1.ini +--error ER_ACCESS_DENIED_ERROR +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; +--connection default +SELECT user(); +CREATE TABLE t1 (sec CHAR(10) NOT NULL FLAG=1, val CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=INI FILE_NAME='t1.EXT'; +INSERT INTO t1 VALUES ('sec1','val1'); +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +INSERT INTO t1 VALUES ('sec2','val2'); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_ACCESS_DENIED_ERROR +UPDATE t1 SET val='val11'; +--error ER_ACCESS_DENIED_ERROR +DELETE FROM t1; +--error ER_ACCESS_DENIED_ERROR +TRUNCATE TABLE t1; +--error ER_ACCESS_DENIED_ERROR +ALTER TABLE t1 READONLY=1; +--error ER_ACCESS_DENIED_ERROR +DROP TABLE t1; +--error ER_ACCESS_DENIED_ERROR +CREATE VIEW v1 AS SELECT * FROM t1; +--echo # Testing a VIEW created with FILE privileges but accessed with no FILE +--connection default +SELECT user(); +CREATE VIEW v1 AS SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO v1 VALUES ('sec3','val3'); +--error ER_ACCESS_DENIED_ERROR +UPDATE v1 SET val='val11'; +--error ER_ACCESS_DENIED_ERROR +DELETE FROM v1; +--disconnect user +--connection default +DROP VIEW v1; +DROP TABLE t1; +--remove_file $MYSQLD_DATADIR/test/t1.EXT +DROP USER user@localhost; + +--echo # +--echo # Checking FILE privileges: done +--echo # + + diff --git a/storage/connect/mysql-test/connect/t/mul.test b/storage/connect/mysql-test/connect/t/mul.test new file mode 100644 index 00000000000..451b38799ad --- /dev/null +++ b/storage/connect/mysql-test/connect/t/mul.test @@ -0,0 +1,43 @@ +--echo # +--echo # Testing multiple 1 +--echo # +CREATE TABLE `t1` ( + `a` char(10) DEFAULT NULL, + `b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `sep_char`=';'; +INSERT INTO t1 VALUES('test1','bla'); +SELECT * FROM t1; + +CREATE TABLE `t2` ( + `a` char(10) DEFAULT NULL, + `b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `sep_char`=';'; +INSERT INTO t2 VALUES('test2','blub'); +SELECT * FROM t2; + +CREATE TABLE `t_all` ( + `a` char(10) DEFAULT NULL, + `b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `file_name`='t*.csv' `sep_char`=';' `multiple`=1; +SELECT * FROM t_all order by `a`; + +--echo # +--echo # Testing multiple 2 +--echo # +CREATE table fnlist ( +fn char(8) not null +) ENGINE=CONNECT DEFAULT CHARSET=latin1 table_type=DOS; +INSERT INTO fnlist VALUES('t1.csv'),('t2.csv'); +SELECT fn FROM fnlist; + +CREATE TABLE `tblist` ( + `a` char(10) DEFAULT NULL, + `b` char(10) DEFAULT NULL +) ENGINE=CONNECT DEFAULT CHARSET=latin1 `table_type`=CSV `file_name`='fnlist.dos' `sep_char`=';' `multiple`=2; +SELECT * FROM tblist; + +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t_all; +DROP TABLE fnlist; +DROP TABLE tblist; diff --git a/storage/connect/mysql-test/connect/t/mysql.test b/storage/connect/mysql-test/connect/t/mysql.test index 45d26cdf9eb..c7eacbd3d06 100644 --- a/storage/connect/mysql-test/connect/t/mysql.test +++ b/storage/connect/mysql-test/connect/t/mysql.test @@ -1,3 +1,10 @@ +-- source include/not_embedded.inc + +# +# TODO: consider a possibility to run this test +# against some remote MySQL server +# + let $PORT= `select @@port`; --disable_query_log @@ -14,66 +21,6 @@ if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES DROP TABLE t1; --enable_query_log ---echo # ---echo # Testing FILE privilege ---echo # -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; ---connect(user,localhost,user,,) ---connection user -SELECT user(); ---replace_result $PORT PORT ---error ER_ACCESS_DENIED_ERROR ---eval CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL OPTION_LIST='host=localhost,user=root1,port=$PORT' ---connection default -SELECT user(); -CREATE TABLE t1remote (a INT NOT NULL); -INSERT INTO t1remote VALUES (10),(20),(30); ---replace_result $PORT PORT ---eval CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL TABNAME=t1remote OPTION_LIST='host=localhost,user=root,port=$PORT' -SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM t1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO t1 VALUES ('xxx'); ---error ER_ACCESS_DENIED_ERROR -DELETE FROM t1 WHERE a='xxx'; ---error ER_ACCESS_DENIED_ERROR -UPDATE t1 SET a='yyy' WHERE a='xxx'; ---error ER_ACCESS_DENIED_ERROR -TRUNCATE TABLE t1; ---error ER_ACCESS_DENIED_ERROR -ALTER TABLE t1 READONLY=1; ---error ER_ACCESS_DENIED_ERROR -CREATE VIEW v1 AS SELECT * FROM t1; - ---echo # Testing a VIEW created with FILE privileges but accessed with no FILE ---connection default -SELECT user(); -CREATE VIEW v1 AS SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM v1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO v1 VALUES (2); ---error ER_ACCESS_DENIED_ERROR -UPDATE v1 SET a=123; ---error ER_ACCESS_DENIED_ERROR -DELETE FROM v1; - ---disconnect user ---connection default -SELECT user(); -DROP VIEW v1; -DROP TABLE t1, t1remote; -DROP USER user@localhost; ---echo # ---echo # Testing FILE privileges done ---echo # - # TODO: remote VARCHAR is displayed as CHAR CREATE TABLE t1 (a int, b char(10)); diff --git a/storage/connect/mysql-test/connect/t/mysql_grant.test b/storage/connect/mysql-test/connect/t/mysql_grant.test new file mode 100644 index 00000000000..e825e70a84b --- /dev/null +++ b/storage/connect/mysql-test/connect/t/mysql_grant.test @@ -0,0 +1,78 @@ +-- source include/not_embedded.inc + +let $PORT= `select @@port`; + +--disable_query_log +--replace_result $PORT PORT +--error 0,ER_UNKNOWN_ERROR +--eval CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT' +if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1' + AND ENGINE='CONNECT' + AND CREATE_OPTIONS LIKE '%`table_type`=MySQL%'`) +{ + Skip Need MySQL support; +} +DROP TABLE t1; +--enable_query_log + +--echo # +--echo # Testing FILE privilege +--echo # +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +--connect(user,localhost,user,,) +--connection user +SELECT user(); +--replace_result $PORT PORT +--error ER_ACCESS_DENIED_ERROR +--eval CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL OPTION_LIST='host=localhost,user=root1,port=$PORT' +--connection default +SELECT user(); +CREATE TABLE t1remote (a INT NOT NULL); +INSERT INTO t1remote VALUES (10),(20),(30); +--replace_result $PORT PORT +--eval CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=MySQL TABNAME=t1remote OPTION_LIST='host=localhost,user=root,port=$PORT' +SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO t1 VALUES ('xxx'); +--error ER_ACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a='xxx'; +--error ER_ACCESS_DENIED_ERROR +UPDATE t1 SET a='yyy' WHERE a='xxx'; +--error ER_ACCESS_DENIED_ERROR +TRUNCATE TABLE t1; +--error ER_ACCESS_DENIED_ERROR +ALTER TABLE t1 READONLY=1; +--error ER_ACCESS_DENIED_ERROR +CREATE VIEW v1 AS SELECT * FROM t1; + +--echo # Testing a VIEW created with FILE privileges but accessed with no FILE +--connection default +SELECT user(); +CREATE VIEW v1 AS SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO v1 VALUES (2); +--error ER_ACCESS_DENIED_ERROR +UPDATE v1 SET a=123; +--error ER_ACCESS_DENIED_ERROR +DELETE FROM v1; + +--disconnect user +--connection default +SELECT user(); +DROP VIEW v1; +DROP TABLE t1, t1remote; +DROP USER user@localhost; +--echo # +--echo # Testing FILE privileges done +--echo # + diff --git a/storage/connect/mysql-test/connect/t/occur.test b/storage/connect/mysql-test/connect/t/occur.test new file mode 100644 index 00000000000..36a4caafda1 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/occur.test @@ -0,0 +1,61 @@ +-- source include/not_embedded.inc + +let $MYSQLD_DATADIR= `select @@datadir`; +let $PORT= `select @@port`; +--copy_file $MTR_SUITE_DIR/std_data/employee.dat $MYSQLD_DATADIR/test/employee.dat + +CREATE TABLE employee ( +serialno CHAR(5) NOT NULL, +name VARCHAR(12) NOT NULL FLAG=6, +sex TINYINT(1) NOT NULL, +title VARCHAR(15) NOT NULL FLAG=20, +manager CHAR(5) DEFAULT NULL, +department CHAR(4) NOT NULL FLAG=41, +secretary CHAR(5) DEFAULT NULL FLAG=46, +salary DOUBLE(8,2) NOT NULL FLAG=52 +) ENGINE=connect TABLE_TYPE=fix FILE_NAME='employee.dat' ENDING=1; +SELECT * FROM employee; + +--replace_result $PORT PORT +--eval CREATE TABLE occurs (name CHAR(12), sex CHAR(1), title CHAR(15), department CHAR(4), salary DOUBLE(8,2), id_of CHAR(12), id CHAR(5) NOT NULL) ENGINE=CONNECT TABLE_TYPE=OCCUR TABNAME=employee OPTION_LIST='OccurCol=ID,RankCol=ID_OF,Colist=serialno;manager;secretary,port=$PORT'; +SELECT * FROM occurs; + +DROP TABLE occurs; +DROP TABLE employee; + +CREATE TABLE pets ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0, +cat INT NOT NULL DEFAULT 0, +rabbit INT NOT NULL DEFAULT 0, +bird INT NOT NULL DEFAULT 0, +fish INT NOT NULL DEFAULT 0) ENGINE=MYISAM; +INSERT INTO pets(name,dog) VALUES('John',2); +INSERT INTO pets(name,cat) VALUES('Bill',1); +INSERT INTO pets(name,dog,cat) VALUES('Mary',1,1); +INSERT INTO pets(name,rabbit) VALUES('Lisbeth',2); +INSERT INTO pets(name,cat,bird) VALUES('Kevin',2,6); +INSERT INTO pets(name,dog,fish) VALUES('Donald',1,3); +SELECT * FROM pets; + +--replace_result $PORT PORT +--eval CREATE TABLE xpet (name VARCHAR(12) NOT NULL, race CHAR(6) NOT NULL, number INT) ENGINE=CONNECT TABLE_TYPE=OCCUR TABNAME=pets OPTION_LIST='OccurCol=number,RankCol=race,Colist=dog;cat;rabbit;bird;fish,port=$PORT' + +SELECT * FROM xpet; +SELECT name FROM xpet; +SELECT name FROM xpet WHERE race = 'cat' AND number = 0; +SELECT name, SUM(number) pets FROM xpet GROUP BY name; + +ALTER TABLE xpet MODIFY number INT NOT NULL; + +SELECT * FROM xpet; +SELECT * FROM xpet WHERE number > 1; +SELECT DISTINCT name FROM xpet WHERE number > 1; +SELECT name FROM xpet; +SELECT name, race FROM xpet; +SELECT name, count(*) FROM xpet GROUP BY name, LEAST(number,1); +SELECT name, number, count(*) FROM xpet GROUP BY name, number; + +DROP TABLE xpet; +DROP TABLE pets; +--remove_file $MYSQLD_DATADIR/test/employee.dat diff --git a/storage/connect/mysql-test/connect/t/odbc_sqlite3.test b/storage/connect/mysql-test/connect/t/odbc_sqlite3.test index 5f6abb0e2bc..2705b4f47fb 100644 --- a/storage/connect/mysql-test/connect/t/odbc_sqlite3.test +++ b/storage/connect/mysql-test/connect/t/odbc_sqlite3.test @@ -1,59 +1,49 @@ +--source have_odbc_sqlite3.inc + # # To run this test, install SQLite3 ODBC Driver from # http://www.ch-werner.de/sqliteodbc/ -# The installer file is sqliteodbc.exe +# +# Note, the test does not need a DSN to be created +# (only the driver is required) +# +# +# On Windows: +# ----------- +# Download and run the installer file sqliteodbc.exe # Version sqliteodbc-0.991 is known to Work. +# After running the installer the test should start working automatically. # -# On Windows the test should start working automatically +# On Linux: +# -------- +# 1. Download the source tarball, e.g.: sqliteodbc-0.993.tar.gz +# 2. Unpack the sources: +# tar -zxf sqliteodbc-0.993.tar.gz +# 3. Compile the source and install: +# cd sqliteodbc-0.993 +# ./configure --prefix=/opt/sqliteodbc +# make +# sudo make install # -# On Linux add these lines into /etc/odbcinst.ini +# (you can use a different --prefix, according to your preferences) +# +# 4. Add these lines into /etc/odbcinst.ini # #[SQLite3 ODBC Driver] #Description=SQLite3 ODBC Driver #Driver=/opt/sqliteodbc/libsqlite3odbc.so #Setup=/opt/sqliteodbc/libsqlite3odbc.so # -# (adjust the directory "/opt/sqliteodbc/" according to your OS settings) +# Adjust the directory "/opt/sqliteodbc/" according to --prefix +# that you chose on step #3. # -# Note, the test does not need a DSN to be created. # ---disable_query_log ---error 0,ER_UNKNOWN_ERROR -CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; -if ($mysql_errno) -{ - Skip No ODBC support; -} -if (!`SELECT count(*) FROM t1 WHERE Description='SQLite3 ODBC Driver'`) -{ - DROP TABLE t1; - Skip Need SQLite3 ODBC Driver; -} -SHOW CREATE TABLE t1; -DROP TABLE t1; ---enable_query_log - SET NAMES utf8; let $MYSQLD_DATADIR= `select @@datadir`; -GRANT ALL PRIVILEGES ON *.* TO user@localhost; -REVOKE FILE ON *.* FROM user@localhost; ---connect(user,localhost,user,,) ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC; ---error ER_ACCESS_DENIED_ERROR -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; ---error ER_ACCESS_DENIED_ERROR -CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Sources; ---connection default -SELECT user(); - - # # For some reasons Windows does not allow to remove the data base # file after "DROP TABLE t1". So unlike in odbc_xls.test we won't copy @@ -66,42 +56,14 @@ let $Database=$MTR_SUITE_DIR/std_data/test.sqlite3; --replace_result $MTR_SUITE_DIR MTR_SUITE_DIR SHOW CREATE TABLE t1; SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR -SELECT * FROM t1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO t1 VALUES ('xxx'); ---error ER_ACCESS_DENIED_ERROR -DELETE FROM t1 WHERE a='xxx'; ---error ER_ACCESS_DENIED_ERROR -UPDATE t1 SET a='yyy' WHERE a='xxx'; ---error ER_ACCESS_DENIED_ERROR -TRUNCATE TABLE t1; ---error ER_ACCESS_DENIED_ERROR -ALTER TABLE t1 READONLY=1; ---error ER_ACCESS_DENIED_ERROR -CREATE VIEW v1 AS SELECT * FROM t1; ---echo # Testing a VIEW created with FILE privileges but accessed with no FILE ---connection default -SELECT user(); +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2; +DROP TABLE t2; + CREATE VIEW v1 AS SELECT * FROM t1; ---connection user -SELECT user(); ---error ER_ACCESS_DENIED_ERROR SELECT * FROM v1; ---error ER_ACCESS_DENIED_ERROR -INSERT INTO v1 VALUES (2); ---error ER_ACCESS_DENIED_ERROR -UPDATE v1 SET a=123; ---error ER_ACCESS_DENIED_ERROR -DELETE FROM v1; ---disconnect user ---connection default -SELECT user(); DROP VIEW v1; DROP TABLE t1; - -DROP USER user@localhost; diff --git a/storage/connect/mysql-test/connect/t/odbc_sqlite3_grant.test b/storage/connect/mysql-test/connect/t/odbc_sqlite3_grant.test new file mode 100644 index 00000000000..7664a4473ba --- /dev/null +++ b/storage/connect/mysql-test/connect/t/odbc_sqlite3_grant.test @@ -0,0 +1,79 @@ +-- source include/not_embedded.inc +-- source have_odbc_sqlite3.inc + +# +# For the instructions on how to setup SQLite3 ODBC DSN, +# please see odbc_sqlite3.test +# + +SET NAMES utf8; + +let $MYSQLD_DATADIR= `select @@datadir`; + + +GRANT ALL PRIVILEGES ON *.* TO user@localhost; +REVOKE FILE ON *.* FROM user@localhost; +--connect(user,localhost,user,,) +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC; +--error ER_ACCESS_DENIED_ERROR +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Drivers; +--error ER_ACCESS_DENIED_ERROR +CREATE TABLE t1 (a INT NOT NULL) ENGINE=CONNECT TABLE_TYPE=ODBC CATFUNC=Sources; +--connection default +SELECT user(); + + +# +# For some reasons Windows does not allow to remove the data base +# file after "DROP TABLE t1". So unlike in odbc_xls.test we won't copy +# the data file, we'll use directly the file in std_data. +# As we do not do any modifications in the database, this should be OK. +# +let $Database=$MTR_SUITE_DIR/std_data/test.sqlite3; +--replace_result $MTR_SUITE_DIR MTR_SUITE_DIR +--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='Driver=SQLite3 ODBC Driver;Database=$Database;NoWCHAR=yes' CHARSET=utf8 DATA_CHARSET=utf8; +--replace_result $MTR_SUITE_DIR MTR_SUITE_DIR +SHOW CREATE TABLE t1; +SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM t1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO t1 VALUES ('xxx'); +--error ER_ACCESS_DENIED_ERROR +DELETE FROM t1 WHERE a='xxx'; +--error ER_ACCESS_DENIED_ERROR +UPDATE t1 SET a='yyy' WHERE a='xxx'; +--error ER_ACCESS_DENIED_ERROR +TRUNCATE TABLE t1; +--error ER_ACCESS_DENIED_ERROR +ALTER TABLE t1 READONLY=1; +--error ER_ACCESS_DENIED_ERROR +CREATE VIEW v1 AS SELECT * FROM t1; + +--echo # Testing a VIEW created with FILE privileges but accessed with no FILE +--connection default +SELECT user(); +CREATE VIEW v1 AS SELECT * FROM t1; +--connection user +SELECT user(); +--error ER_ACCESS_DENIED_ERROR +SELECT * FROM v1; +--error ER_ACCESS_DENIED_ERROR +INSERT INTO v1 VALUES (2); +--error ER_ACCESS_DENIED_ERROR +UPDATE v1 SET a=123; +--error ER_ACCESS_DENIED_ERROR +DELETE FROM v1; + +--disconnect user +--connection default +SELECT user(); +DROP VIEW v1; +DROP TABLE t1; + +DROP USER user@localhost; diff --git a/storage/connect/mysql-test/connect/t/pivot.test b/storage/connect/mysql-test/connect/t/pivot.test new file mode 100644 index 00000000000..7679434bca8 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/pivot.test @@ -0,0 +1,146 @@ +-- source include/not_embedded.inc + +let $MYSQLD_DATADIR= `select @@datadir`; +let $PORT= `select @@port`; +--copy_file $MTR_SUITE_DIR/std_data/expenses.txt $MYSQLD_DATADIR/test/expenses.txt + +--echo # +--echo # Testing the PIVOT table type +--echo # +CREATE TABLE expenses ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +What CHAR(12) NOT NULL, +Amount DOUBLE(8,2)) +ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='expenses.txt' ENDING=2; +SELECT * FROM expenses; + +--echo # +--echo # Pivoting from What +--echo # +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +Beer DOUBLE(8,2) FLAG=1, +Car DOUBLE(8,2) FLAG=1, +Food DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=expenses; +--replace_result $PORT PORT +--eval ALTER TABLE pivex OPTION_LIST='port=$PORT' +SELECT * FROM pivex; + +--echo # +--echo # Restricting the columns in a Pivot Table +--echo # +ALTER TABLE pivex DROP COLUMN week; +SELECT * FROM pivex; + +--echo # +--echo # Using a source definition +--echo # +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +Week INT(2) NOT NULL, +Beer DOUBLE(8,2) FLAG=1, +Car DOUBLE(8,2) FLAG=1, +Food DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT +SRCDEF='select who, week, what, sum(amount) as amount from expenses where week in (4,5) group by who, week, what'; +--replace_result $PORT PORT +--eval ALTER TABLE pivex OPTION_LIST='PivotCol=what,FncCol=amount,port=$PORT' +SELECT * FROM pivex; + +--echo # +--echo # Pivoting from Week +--echo # +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +What CHAR(12) NOT NULL, +`3` DOUBLE(8,2) FLAG=1, +`4` DOUBLE(8,2) FLAG=1, +`5` DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=expenses; +--replace_result $PORT PORT +--eval ALTER TABLE pivex OPTION_LIST='PivotCol=Week,port=$PORT' +SELECT * FROM pivex; + +--echo # +--echo # Using scalar functions and expresssions +--echo # +DROP TABLE pivex; +CREATE TABLE pivex ( +Who CHAR(10) NOT NULL, +What CHAR(12) NOT NULL, +First DOUBLE(8,2) FLAG=1, +Middle DOUBLE(8,2) FLAG=1, +Last DOUBLE(8,2) FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT +SRCDEF='select who, what, case when week=3 then ''First'' when week=5 then ''Last'' else ''Middle'' end as wk, sum(amount) * 6.56 as amnt from expenses group by who, what, wk'; +--replace_result $PORT PORT +--eval ALTER TABLE pivex OPTION_LIST='PivotCol=wk,FncCol=amnt,port=$PORT' +SELECT * FROM pivex; +DROP TABLE pivex; +DROP TABLE expenses; + +--echo # +--echo # Make the PETS table +--echo # +CREATE TABLE pets ( +Name VARCHAR(12) NOT NULL, +Race CHAR(6) NOT NULL, +Number INT NOT NULL) ENGINE=MYISAM; +INSERT INTO pets VALUES('John','dog',2); +INSERT INTO pets VALUES('Bill','cat',1); +INSERT INTO pets VALUES('Mary','dog',1); +INSERT INTO pets VALUES('Mary','cat',1); +INSERT INTO pets VALUES('Lisbeth','rabbit',2); +INSERT INTO pets VALUES('Kevin','cat',2); +INSERT INTO pets VALUES('Kevin','bird',6); +INSERT INTO pets VALUES('Donald','dog',1); +INSERT INTO pets VALUES('Donald','fish',3); +SELECT * FROM pets; + +--echo # +--echo # Pivot the PETS table +--echo # +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1, +rabbit INT NOT NULL DEFAULT 0 FLAG=1, +bird INT NOT NULL DEFAULT 0 FLAG=1, +fish INT NOT NULL DEFAULT 0 FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +SELECT * FROM pivet; +DROP TABLE pivet; + +--echo # +--echo # Testing the "data" column list +--echo # +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +--error ER_GET_ERRMSG +SELECT * FROM pivet; +ALTER TABLE pivet OPTION_LIST='PivotCol=race,groupby=1,accept=1'; +SELECT * FROM pivet; +DROP TABLE pivet; + +--echo # +--echo # Adding a "dump" column +--echo # +CREATE TABLE pivet ( +name VARCHAR(12) NOT NULL, +dog INT NOT NULL DEFAULT 0 FLAG=1, +cat INT NOT NULL DEFAULT 0 FLAG=1, +other INT NOT NULL DEFAULT 0 FLAG=2) +ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=pets OPTION_LIST='PivotCol=race,groupby=1'; +SELECT * FROM pivet; + +DROP TABLE pivet; +DROP TABLE pets; +--remove_file $MYSQLD_DATADIR/test/expenses.txt diff --git a/storage/connect/mysql-test/connect/t/tbl.test b/storage/connect/mysql-test/connect/t/tbl.test index 143c7643afd..bdd928366ef 100644 --- a/storage/connect/mysql-test/connect/t/tbl.test +++ b/storage/connect/mysql-test/connect/t/tbl.test @@ -1,3 +1,5 @@ +-- source include/not_embedded.inc + let $MYSQLD_DATADIR= `select @@datadir`; let $PORT= `select @@port`; diff --git a/storage/connect/mysql-test/connect/t/vec.test b/storage/connect/mysql-test/connect/t/vec.test index 79ed4eabd86..ee504e9925a 100644 --- a/storage/connect/mysql-test/connect/t/vec.test +++ b/storage/connect/mysql-test/connect/t/vec.test @@ -1,9 +1,5 @@ let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=VEC MAX_ROWS=100; -let $FILE_EXT=VEC; ---source grant.inc - CREATE TABLE dir1 ( spath VARCHAR(256) NOT NULL flag=1, fname VARCHAR(256) NOT NULL, diff --git a/storage/connect/mysql-test/connect/t/xcol.test b/storage/connect/mysql-test/connect/t/xcol.test new file mode 100644 index 00000000000..b6998ee77e0 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/xcol.test @@ -0,0 +1,28 @@ +let $MYSQLD_DATADIR= `select @@datadir`; +let $PORT= `select @@port`; + +--echo # +--echo # Checking XCOL tables +--echo # +CREATE TABLE chlist ( +mother char(12) NOT NULL COMMENT 'The mother of the listed children', +children varchar(30) DEFAULT NULL COMMENT 'The comma separated list of children' +) ENGINE=CONNECT; +INSERT INTO chlist VALUES('Sophia','Vivian, Antony'); +INSERT INTO chlist VALUES('Lisbeth','Lucy,Charles,Diana'); +INSERT INTO chlist VALUES('Corinne',NULL); +INSERT INTO chlist VALUES('Claude','Marc'); +INSERT INTO chlist VALUES('Janet','Arthur,Sandra,Peter,John'); +SELECT * FROM chlist; + +--replace_result $PORT PORT +--eval CREATE TABLE child ENGINE=CONNECT TABLE_TYPE=XCOL TABNAME=chlist OPTION_LIST='colname=children,port=$PORT' +SELECT * FROM child; +SELECT * FROM child ORDER BY mother; +SELECT * FROM child ORDER BY children; +SELECT mother FROM child; +SELECT mother, COUNT(*) FROM child GROUP BY mother; +SELECT mother, COUNT(children) FROM child GROUP BY mother; + +DROP TABLE child; +DROP TABLE chlist; diff --git a/storage/connect/mysql-test/connect/t/xml.test b/storage/connect/mysql-test/connect/t/xml.test index 96e7e1a3a97..3914bed307d 100644 --- a/storage/connect/mysql-test/connect/t/xml.test +++ b/storage/connect/mysql-test/connect/t/xml.test @@ -16,11 +16,6 @@ DROP TABLE t1; let $MYSQLD_DATADIR= `select @@datadir`; -let $TABLE_OPTIONS=TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; -let $FILE_EXT=XML; ---source grant.inc - - SET NAMES utf8; --vertical_results @@ -132,7 +127,8 @@ INSERT INTO t1 (ISBN, LANG, SUBJECT, AUTHOR, TITLE, PUBLISHEr, DATEPUB) VALUES('9782212090529','fr','général','Alain Michard', 'XML, Langage et Applications','Eyrolles Paris',1998); SELECT * FROM t1; -SELECT LOAD_FILE('test/xsample2.xml'); +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +--eval SELECT LOAD_FILE('$MYSQLD_DATADIR/test/xsample2.xml') AS xml DROP TABLE t1; --remove_file $MYSQLD_DATADIR/test/xsample2.xml @@ -289,7 +285,8 @@ INSERT INTO t1 VALUES (_latin1 0xC0C1C2C3); SELECT node, hex(node) FROM t1; DROP TABLE t1; --chmod 0777 $MYSQLD_DATADIR/test/t1.xml -SET @a=LOAD_FILE('test/t1.xml'); +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +--eval SET @a=LOAD_FILE('$MYSQLD_DATADIR/test/t1.xml') SELECT LEFT(@a,38); SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node')); --remove_file $MYSQLD_DATADIR/test/t1.xml @@ -302,7 +299,8 @@ INSERT INTO t1 VALUES (_latin1 0xC0C1C2C3); SELECT node, hex(node) FROM t1; DROP TABLE t1; --chmod 0777 $MYSQLD_DATADIR/test/t1.xml -SET @a=LOAD_FILE('test/t1.xml'); +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +--eval SET @a=LOAD_FILE('$MYSQLD_DATADIR/test/t1.xml') SELECT LEFT(@a,43); SELECT HEX(EXTRACTVALUE(@a,'/t1/line/node')); --remove_file $MYSQLD_DATADIR/test/t1.xml @@ -321,7 +319,8 @@ INSERT INTO t1 VALUES ('&<>"\''); SELECT node, hex(node) FROM t1; DROP TABLE t1; --chmod 0777 $MYSQLD_DATADIR/test/t1.xml -SET @a=LOAD_FILE('test/t1.xml'); +--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR +--eval SET @a=LOAD_FILE('$MYSQLD_DATADIR/test/t1.xml') SELECT CAST(@a AS CHAR CHARACTER SET latin1); --remove_file $MYSQLD_DATADIR/test/t1.xml diff --git a/storage/connect/mysql-test/connect/t/xml_grant.test b/storage/connect/mysql-test/connect/t/xml_grant.test new file mode 100644 index 00000000000..f8401efaa64 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/xml_grant.test @@ -0,0 +1,23 @@ +-- source include/not_embedded.inc + +--disable_query_log +--error 0,ER_UNKNOWN_ERROR +CREATE TABLE t1 (a VARCHAR(10)) +ENGINE=CONNECT TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2'; +if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1' + AND ENGINE='CONNECT' + AND CREATE_OPTIONS LIKE '%`table_type`=XML%' + AND CREATE_OPTIONS LIKE '%xmlsup=libxml2%'`) +{ + Skip Need LIBXML2; +} +DROP TABLE t1; +--enable_query_log + + +let $MYSQLD_DATADIR= `select @@datadir`; + +let $TABLE_OPTIONS=TABLE_TYPE=XML OPTION_LIST='xmlsup=libxml2,rownode=row'; +let $FILE_EXT=XML; +--source grant.inc diff --git a/storage/connect/myutil.cpp b/storage/connect/myutil.cpp index 19c478ecbd8..b266b7b79c1 100644 --- a/storage/connect/myutil.cpp +++ b/storage/connect/myutil.cpp @@ -23,6 +23,7 @@ #include "plgdbsem.h" //#include "value.h" //#include "valblk.h" +#include "myutil.h" #define DLL_EXPORT // Items are exported from this DLL /************************************************************************/ diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 6de2acef391..69fddb2d9f8 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -36,6 +36,7 @@ //#include "kindex.h" #include "xtable.h" #include "tabodbc.h" +#include "odbccat.h" #include "plgcnx.h" // For DB types #include "resource.h" #include "valblk.h" @@ -47,9 +48,7 @@ /***********************************************************************/ #pragma comment(lib, "odbc32.lib") extern "C" HINSTANCE s_hModule; // Saved module handle -#else // !WIN32 -extern "C" int GetRcString(int id, char *buf, int bufsize); -#endif // !WIN32 +#endif // WIN32 /***********************************************************************/ /* Some macro's (should be defined elsewhere to be more accessible) */ @@ -176,7 +175,7 @@ int TranslateSQLType(int stp, int prec, int& len) /***********************************************************************/ /* Allocate the structure used to refer to the result set. */ /***********************************************************************/ -CATPARM *AllocCatInfo(PGLOBAL g, CATINFO fid, char *tab, PQRYRES qrp) +static CATPARM *AllocCatInfo(PGLOBAL g, CATINFO fid, char *tab, PQRYRES qrp) { size_t i, m, n; CATPARM *cap; @@ -203,7 +202,7 @@ CATPARM *AllocCatInfo(PGLOBAL g, CATINFO fid, char *tab, PQRYRES qrp) /***********************************************************************/ /* Check for nulls and reset them to Null (?) values. */ /***********************************************************************/ -void ResetNullValues(CATPARM *cap) +static void ResetNullValues(CATPARM *cap) { int i, n, ncol; PCOLRES crp; @@ -230,11 +229,7 @@ void ResetNullValues(CATPARM *cap) PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, char *colpat, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, - DB_CHAR, DB_SHORT, DB_CHAR, - DB_INT, DB_INT, DB_SHORT, - DB_SHORT, DB_SHORT, DB_CHAR}; - static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, + static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; @@ -247,7 +242,7 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, int maxres; PQRYRES qrp; CATPARM *cap; - ODBConn *ocp; + ODBConn *ocp = NULL; /************************************************************************/ /* Do an evaluation of the result size. */ @@ -285,7 +280,7 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, /* Allocate the structures used to refer to the result set. */ /************************************************************************/ qrp = PlgAllocResult(g, ncol, maxres, IDS_COLUMNS, - dbtype, buftyp, fldtyp, length, true, true); + buftyp, fldtyp, length, true, true); if (info) // Info table return qrp; @@ -309,6 +304,9 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table, } else qrp = NULL; + /* Cleanup */ + ocp->Close(); + /************************************************************************/ /* Return the result pointer for use by GetData routines. */ /************************************************************************/ @@ -396,7 +394,6 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info) /*************************************************************************/ PQRYRES ODBCDataSources(PGLOBAL g, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR}; static int buftyp[] = {TYPE_STRING, TYPE_STRING}; static XFLD fldtyp[] = {FLD_NAME, FLD_REM}; static unsigned int length[] = {0, 256}; @@ -425,7 +422,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) /* Allocate the structures used to refer to the result set. */ /************************************************************************/ qrp = PlgAllocResult(g, ncol, maxres, IDS_DSRC, - dbtype, buftyp, fldtyp, length, true, true); + buftyp, fldtyp, length, true, true); /************************************************************************/ /* Now get the results into blocks. */ @@ -446,7 +443,6 @@ PQRYRES ODBCDataSources(PGLOBAL g, bool info) /*************************************************************************/ PQRYRES ODBCDrivers(PGLOBAL g, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR}; static int buftyp[] = {TYPE_STRING, TYPE_STRING}; static XFLD fldtyp[] = {FLD_NAME, FLD_REM}; static unsigned int length[] = {128, 256}; @@ -471,7 +467,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) /* Allocate the structures used to refer to the result set. */ /************************************************************************/ qrp = PlgAllocResult(g, ncol, maxres, IDS_DRIVER, - dbtype, buftyp, fldtyp, length, true, true); + buftyp, fldtyp, length, true, true); /************************************************************************/ /* Now get the results into blocks. */ @@ -492,8 +488,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) /***********************************************************************/ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) { - static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_CHAR, DB_CHAR}; - static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, + static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING}; static XFLD fldtyp[] = {FLD_QUALIF, FLD_OWNER, FLD_NAME, FLD_TYPE, FLD_REM}; @@ -502,7 +497,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) int maxres; PQRYRES qrp; CATPARM *cap; - ODBConn *ocp; + ODBConn *ocp = NULL; /************************************************************************/ /* Do an evaluation of the result size. */ @@ -536,7 +531,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) /************************************************************************/ /* Allocate the structures used to refer to the result set. */ /************************************************************************/ - qrp = PlgAllocResult(g, ncol, maxres, IDS_TABLES, dbtype, buftyp, + qrp = PlgAllocResult(g, ncol, maxres, IDS_TABLES, buftyp, fldtyp, length, true, true); if (info) @@ -579,8 +574,6 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) /**************************************************************************/ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) { - static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, - DB_CHAR, DB_SHORT, DB_CHAR}; static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING}; static unsigned int length[] = {0, 0, 0, 0, 6, 128}; @@ -623,7 +616,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) /* Allocate the structure used to refer to the result set. */ /************************************************************************/ qrp = PlgAllocResult(g, ncol, maxres, IDS_PKEY, - dbtype, buftyp, NULL, length, true, true); + buftyp, NULL, length, true, true); if (trace) htrc("Getting pkey results ncol=%d\n", qrp->Nbcol); @@ -662,9 +655,6 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, int un, int acc) { - static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_SHORT, DB_CHAR, - DB_CHAR, DB_SHORT, DB_SHORT, DB_CHAR, DB_CHAR, - DB_INT, DB_INT, DB_CHAR}; static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_STRING, @@ -708,7 +698,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, /* Allocate the structure used to refer to the result set. */ /************************************************************************/ qrp = PlgAllocResult(g, ncol, maxres, IDS_STAT, - dbtype, buftyp, NULL, length, true, true); + buftyp, NULL, length, true, true); if (trace) htrc("Getting stat results ncol=%d\n", qrp->Nbcol); @@ -967,17 +957,17 @@ int ODBConn::Open(PSZ ConnectString, DWORD options) // Allocate the HDBC and make connection try { - PSZ ver; + /*PSZ ver;*/ AllocConnect(options); - ver = GetStringInfo(SQL_ODBC_VER); + /*ver = GetStringInfo(SQL_ODBC_VER);*/ if (Connect(options)) { strcpy(g->Message, MSG(CONNECT_CANCEL)); return 0; } // endif - ver = GetStringInfo(SQL_DRIVER_ODBC_VER); + /*ver = GetStringInfo(SQL_DRIVER_ODBC_VER);*/ } catch(DBX *xp) { // strcpy(g->Message, xp->m_ErrMsg[0]); strcpy(g->Message, xp->GetErrorMessage(0)); @@ -1226,13 +1216,13 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols) b = false; if (m_hstmt) { - RETCODE rc; + /*RETCODE rc;*/ // All this did not seems to make sense and was been commented out // if (IsOpen()) // Close(SQL_CLOSE); - rc = SQLFreeStmt(m_hstmt, SQL_CLOSE); + /*rc =*/ SQLFreeStmt(m_hstmt, SQL_CLOSE); hstmt = m_hstmt; m_hstmt = NULL; ThrowDBX(MSG(SEQUENCE_ERROR)); @@ -1664,7 +1654,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) PCOLRES crp; RETCODE rc; HSTMT hstmt = NULL; - SQLLEN *vl, *vlen; + SQLLEN *vl, *vlen = NULL; PVAL *pval = NULL; try { @@ -1686,8 +1676,10 @@ int ODBConn::GetCatInfo(CATPARM *cap) // Attempt to set rowset size. // In case of failure reset it to 0 to use Fetch. if (m_Catver == 3) // ODBC Ver 3 - rc = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, - (SQLPOINTER)m_RowsetSize, 0); + { + SQLULEN tmp= m_RowsetSize; + rc = SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, &tmp, 0); + } else rc = SQLSetStmtOption(hstmt, SQL_ROWSET_SIZE, m_RowsetSize); @@ -1844,7 +1836,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) /***********************************************************************/ void ODBConn::Close() { - RETCODE rc; + /*RETCODE rc;*/ #if 0 // Close any open recordsets @@ -1869,13 +1861,13 @@ void ODBConn::Close() if (m_hstmt) { // Is required for multiple tables - rc = SQLFreeStmt(m_hstmt, SQL_DROP); + /*rc =*/ SQLFreeStmt(m_hstmt, SQL_DROP); m_hstmt = NULL; } // endif m_hstmt if (m_hdbc != SQL_NULL_HDBC) { - rc = SQLDisconnect(m_hdbc); - rc = SQLFreeConnect(m_hdbc); + /*rc =*/ SQLDisconnect(m_hdbc); + /*rc =*/ SQLFreeConnect(m_hdbc); m_hdbc = SQL_NULL_HDBC; // AfxLockGlobals(CRIT_ODBC); diff --git a/storage/connect/osutil.c b/storage/connect/osutil.c index 45c834a4cfc..ad92caefe95 100644 --- a/storage/connect/osutil.c +++ b/storage/connect/osutil.c @@ -142,10 +142,12 @@ my_bool CloseFileHandle(HANDLE h) return (close(h)) ? TRUE : FALSE; } /* end of CloseFileHandle */ +#if 0 void Sleep(DWORD time) { //FIXME: TODO } /* end of Sleep */ +#endif int GetLastError() { @@ -179,7 +181,7 @@ char *_fullpath(char *absPath, const char *relPath, size_t maxLength) } else { char buff[2*_MAX_PATH]; - getcwd(buff, _MAX_PATH); + assert(getcwd(buff, _MAX_PATH) != NULL); strcat(buff,"/"); strcat(buff, relPath); strncpy(absPath, buff, maxLength); @@ -200,19 +202,7 @@ BOOL MessageBeep(uint i) return TRUE; } /* end of MessageBeep */ -LPSTR _strerror(int errn) - { - static char buff[256]; - - sprintf(buff,"error: %d", errn); - return buff; - } /* end of _strerror */ - -int _isatty(int fileNo) - { - return isatty(fileNo); - } /* end of _isatty */ - +#if 0 /* This function is ridiculous and should be revisited */ DWORD FormatMessage(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, ...) @@ -227,5 +217,6 @@ DWORD FormatMessage(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, strncpy(lpBuffer, buff, nSize); return min(n, nSize); } /* end of FormatMessage */ +#endif #endif // UNIX diff --git a/storage/connect/osutil.h b/storage/connect/osutil.h index 440373dd7a1..63a3e18084c 100644 --- a/storage/connect/osutil.h +++ b/storage/connect/osutil.h @@ -32,44 +32,6 @@ char *_fullpath(char *absPath, const char *relPath, size_t maxLength); BOOL MessageBeep(uint); unsigned long _filelength(int fd); -void PROFILE_Close(LPCSTR filename); - -int GetPrivateProfileString( - LPCTSTR lpAppName, // section name - LPCTSTR lpKeyName, // key name - LPCTSTR lpDefault, // default string - LPTSTR lpReturnedString, // destination buffer - int nSize, // size of destination buffer - LPCTSTR lpFileName // initialization file name - ); - -uint GetPrivateProfileInt( - LPCTSTR lpAppName, // section name - LPCTSTR lpKeyName, // key name - INT nDefault, // return value if key name not found - LPCTSTR lpFileName // initialization file name - ); - -BOOL WritePrivateProfileString( - LPCTSTR lpAppName, // section name - LPCTSTR lpKeyName, // key name - LPCTSTR lpString, // string to add - LPCTSTR lpFileName // initialization file - ); - -int GetPrivateProfileSection( - LPCTSTR lpAppName, // section name - LPTSTR lpReturnedString, // return buffer - int nSize, // size of return buffer - LPCTSTR lpFileName // initialization file name - ); - -BOOL WritePrivateProfileSection( - LPCTSTR lpAppName, // section name - LPCTSTR lpString, // data - LPCTSTR lpFileName // file name - ); - PSZ strupr(PSZ s); PSZ strlwr(PSZ s); @@ -90,12 +52,14 @@ typedef __int64 FILEPOS; #define XSTR(x) ((x)?(x):"") + #ifdef __cplusplus extern "C" { #endif - +my_bool CloseFileHandle(HANDLE h); #ifdef __cplusplus } #endif + #endif /* __OSUTIL_H__ */ diff --git a/storage/connect/plgcnx.h b/storage/connect/plgcnx.h index 33b0ba64edc..7ce72b45268 100644 --- a/storage/connect/plgcnx.h +++ b/storage/connect/plgcnx.h @@ -49,17 +49,6 @@ enum RCODE {RC_OK = 0, /* No error return code */ RC_INFO = 4}; /* Success with info */ #endif // !RC_OK_DEFINED -/**************************************************************************/ -/* Data types. */ -/**************************************************************************/ -enum XDBTYPE {DB_ERROR = 0, /* Unknown or wrong type */ - DB_STRING = 1, /* Null terminated string */ - DB_CHAR = 2, /* Character array */ - DB_SHORT = 3, /* Used by some catalog functions */ - DB_INT = 4, /* Long integer array */ - DB_DOUBLE = 5, /* Double float array */ - DB_DATE = 6}; /* Datetime value array */ - /**************************************************************************/ /* Index of info values within the info int integer array. */ /**************************************************************************/ diff --git a/storage/connect/plgdbsem.h b/storage/connect/plgdbsem.h index 611b0067e18..44ad8605747 100644 --- a/storage/connect/plgdbsem.h +++ b/storage/connect/plgdbsem.h @@ -24,8 +24,8 @@ #define DOS_BUFF_LEN 100 /* Number of lines in binary file buffer */ #undef DOMAIN /* For Unix version */ -enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Correl Block */ - TYPE_COLUMN = 51, /* Column Name/Correl Block */ +enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Srcdef/... Block */ + TYPE_COLUMN = 51, /* Column Name/Qualifier Block */ // TYPE_OPVAL = 52, /* Operator value (OPVAL) */ TYPE_TDB = 53, /* Table Description Block */ TYPE_COLBLK = 54, /* Column Description Block */ @@ -69,12 +69,14 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */ TAB_WMI = 14, /* WMI tables (Windows only) */ TAB_TBL = 15, /* Collection of CONNECT tables */ TAB_OEM = 16, /* OEM implemented table */ - TAB_CATLG = 17, /* Catalog table */ - TAB_PLG = 18, /* PLG NIY */ - TAB_PIVOT = 19, /* PIVOT NIY */ - TAB_JCT = 20, /* Junction tables NIY */ - TAB_DMY = 21, /* DMY Dummy tables NIY */ - TAB_NIY = 22}; /* Table not implemented yet */ + TAB_XCL = 17, /* XCL table */ + TAB_OCCUR = 18, /* OCCUR table */ + TAB_PRX = 19, /* Proxy (catalog) table */ + TAB_PLG = 20, /* PLG NIY */ + TAB_PIVOT = 21, /* PIVOT NIY */ + TAB_JCT = 22, /* Junction tables NIY */ + TAB_DMY = 23, /* DMY Dummy tables NIY */ + TAB_NIY = 24}; /* Table not implemented yet */ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */ TYPE_AM_ROWID = 1, /* ROWID type (special column) */ @@ -511,12 +513,12 @@ typedef struct _colres { PVBLK Kdata; /* Column block of values */ char *Nulls; /* Column null value array */ int Type; /* Internal type */ - int DBtype; /* Data type */ int Datasize; /* Overall data size */ int Ncol; /* Column number */ int Clen; /* Data individual internal size */ int Length; /* Data individual print length */ int Prec; /* Precision */ + int Flag; /* Flag option value */ XFLD Fld; /* Type of field info */ } COLRES; @@ -543,7 +545,7 @@ int ExtractDate(char *, PDTP, int, int val[6]); /* Allocate the result structure that will contain result data. */ /**************************************************************************/ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, - int *dbtype, int *buftyp, XFLD *fldtyp, + int *buftyp, XFLD *fldtyp, unsigned int *length, bool blank, bool nonull); /***********************************************************************/ @@ -563,7 +565,8 @@ DllExport void PlgDBfree(MBLOCK&); //lExport int GetIniSize(char *, char *, char *, char *); //lExport bool WritePrivateProfileInt(LPCSTR, LPCSTR, int, LPCSTR); DllExport void NewPointer(PTABS, void *, void *); - +DllExport char *GetIni(int n= 0); +DllExport void SetTrc(void); #define MSGID_NONE 0 #define MSGID_CANNOT_OPEN 1 @@ -576,5 +579,6 @@ DllExport void NewPointer(PTABS, void *, void *); FILE *global_fopen(GLOBAL *g, int msgid, const char *path, const char *mode); int global_open(GLOBAL *g, int msgid, const char *filename, int flags); int global_open(GLOBAL *g, int msgid, const char *filename, int flags, int mode); +DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR name, LPCSTR dir); bool PushWarning(PGLOBAL, PTDBASE); diff --git a/storage/connect/plgdbutl.cpp b/storage/connect/plgdbutl.cpp index 6d1e502945b..5ea8457f25e 100644 --- a/storage/connect/plgdbutl.cpp +++ b/storage/connect/plgdbutl.cpp @@ -67,6 +67,7 @@ #include "xtable.h" // header of TBX, TDB and TDBASE classes #include "tabcol.h" // header of XTAB and COLUMN classes #include "valblk.h" +#include "rcmsg.h" /***********************************************************************/ /* Macro or external routine definition */ @@ -126,10 +127,9 @@ void CloseXMLFile(PGLOBAL, PFBLOCK, bool); #endif // DOMDOC_SUPPORT #ifdef LIBXML2_SUPPORT -void CloseXML2File(PGLOBAL, PFBLOCK, bool); +#include "libdoc.h" #endif // LIBXML2_SUPPORT -extern "C" int GetRcString(int id, char *buf, int bufsize); /***********************************************************************/ /* Routines for file IO with error reporting to g->Message */ @@ -222,7 +222,7 @@ int global_open(GLOBAL *g, int msgid, const char *path, int flags, int mode) /**************************************************************************/ /* Utility for external callers (such as XDB) */ /**************************************************************************/ -DllExport char *GetIni(int n = 0) +DllExport char *GetIni(int n) { switch (n) { case 1: return plgxini; break; @@ -270,7 +270,7 @@ void ptrc(char const *fmt, ...) /* Allocate the result structure that will contain result data. */ /**************************************************************************/ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, - int *dbtype, int *buftyp, XFLD *fldtyp, + int *buftyp, XFLD *fldtyp, unsigned int *length, bool blank, bool nonull) { char cname[NAM_LEN+1]; @@ -298,13 +298,13 @@ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, *pcrp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); crp = *pcrp; pcrp = &crp->Next; + memset(crp, 0, sizeof(COLRES)); crp->Colp = NULL; crp->Ncol = ++qrp->Nbcol; crp->Type = buftyp[i]; crp->Length = length[i]; crp->Clen = GetTypeSize(crp->Type, length[i]); crp->Prec = 0; - crp->DBtype = dbtype[i]; if (ids > 0) { #if defined(XMSG) @@ -520,6 +520,7 @@ bool PlgSetXdbPath(PGLOBAL g, PSZ dbname, PSZ dbpath, /* Extract from a path name the required component. */ /* This function assumes there is enough space in the buffer. */ /***********************************************************************/ +#if 0 char *ExtractFromPath(PGLOBAL g, char *pBuff, char *FileName, OPVAL op) { char *drive = NULL, *direc = NULL, *fname = NULL, *ftype = NULL; @@ -540,13 +541,14 @@ char *ExtractFromPath(PGLOBAL g, char *pBuff, char *FileName, OPVAL op) _splitpath(FileName, drive, direc, fname, ftype); return pBuff; } // end of PlgExtractFromPath +#endif /***********************************************************************/ /* Check the occurence and matching of a pattern against a string. */ /* Because this function is only used for catalog name checking, */ /* it must be case insensitive. */ /***********************************************************************/ -bool PlugCheckPattern(PGLOBAL g, LPCSTR string, LPCSTR pat) +static bool PlugCheckPattern(PGLOBAL g, LPCSTR string, LPCSTR pat) { if (pat && strlen(pat)) { // This leaves 512 bytes (MAX_STR / 2) for each components diff --git a/storage/connect/plgxml.h b/storage/connect/plgxml.h index 8fc95eabef7..b8352c36c14 100644 --- a/storage/connect/plgxml.h +++ b/storage/connect/plgxml.h @@ -69,6 +69,7 @@ class XMLDOCUMENT : public BLOCK { // Properties virtual short GetDocType(void) = 0; virtual void *GetDocPtr(void) = 0; + virtual void SetNofree(bool b) = 0; // Methods virtual bool Initialize(PGLOBAL) = 0; diff --git a/storage/connect/plugutil.c b/storage/connect/plugutil.c index 693ae96cf52..7910f1ea318 100644 --- a/storage/connect/plugutil.c +++ b/storage/connect/plugutil.c @@ -107,7 +107,7 @@ ACTIVITY defActivity = { /* Describes activity and language */ #endif // XMSG || NEWMSG #if defined(UNIX) || defined(UNIV_LINUX) -int GetRcString(int id, char *buf, int bufsize); +#include "rcmsg.h" #endif // UNIX /**************************************************************************/ @@ -147,6 +147,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) if (!(g = malloc(sizeof(GLOBAL)))) { fprintf(stderr, MSG(GLOBAL_ERROR), (int)sizeof(GLOBAL)); + return NULL; } else { g->Sarea_Size = worksize; g->Trace = 0; @@ -180,7 +181,9 @@ int PlugExit(PGLOBAL g) if (!g) return rc; - free(g->Sarea); + if (g->Sarea) + free(g->Sarea); + free(g); return rc; } /* end of PlugExit */ @@ -216,11 +219,23 @@ LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName) return pBuff; } // end of PlugRemoveType + +BOOL PlugIsAbsolutePath(LPCSTR path) +{ +#if defined(WIN32) + return ((path[0] >= 'a' && path[0] <= 'z') || + (path[0] >= 'A' && path[0] <= 'Z')) && path[1] == ':'; +#else + return path[0] == '/'; +#endif +} + + /***********************************************************************/ /* Set the full path of a file relatively to a given path. */ /* Note: this routine is not really implemented for Unix. */ /***********************************************************************/ -LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR FileName, LPCSTR defpath) +LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) { char newname[_MAX_PATH]; char direc[_MAX_DIR], defdir[_MAX_DIR]; @@ -237,6 +252,22 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR FileName, LPCSTR defpath) return pBuff; } // endif + if (PlugIsAbsolutePath(FileName)) + { + strcpy(pBuff, FileName); // FileName includes absolute path + return pBuff; + } // endif + + if (strcmp(prefix, ".") && !PlugIsAbsolutePath(defpath)) + { + char tmp[_MAX_PATH]; + int len= snprintf(tmp, sizeof(tmp) - 1, "%s%s%s", + prefix, defpath, FileName); + memcpy(pBuff, tmp, (size_t) len); + pBuff[len]= '\0'; + return pBuff; + } + _splitpath(FileName, drive, direc, fname, ftype); _splitpath(defpath, defdrv, defdir, NULL, NULL); @@ -480,6 +511,23 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) return (memp); } /* end of PlugSubAlloc */ +/***********************************************************************/ +/* This routine suballocate a copy of the passed string. */ +/***********************************************************************/ +char *PlugDup(PGLOBAL g, const char *str) + { + char *buf; + size_t len; + + if (str && (len = strlen(str))) { + buf = (char*)PlugSubAlloc(g, NULL, len + 1); + strcpy(buf, str); + } else + buf = NULL; + + return(buf); + } /* end of PlugDup */ + /***********************************************************************/ /* This routine makes a pointer from an offset to a memory pointer. */ /***********************************************************************/ @@ -491,9 +539,10 @@ void *MakePtr(void *memp, OFFSET offset) /***********************************************************************/ /* This routine makes an offset from a pointer new format. */ /***********************************************************************/ +#if 0 OFFSET MakeOff(void *memp, void *ptr) { return ((!ptr) ? 0 : (OFFSET)((char *)ptr - (char *)memp)); } /* end of MakeOff */ - +#endif /*--------------------- End of PLUGUTIL program -----------------------*/ diff --git a/storage/connect/rcmsg.c b/storage/connect/rcmsg.c index e1a71cde9c6..0c63fd55242 100644 --- a/storage/connect/rcmsg.c +++ b/storage/connect/rcmsg.c @@ -14,6 +14,7 @@ /***********************************************************************/ #include #include "resource.h" +#include "rcmsg.h" char *GetMsgid(int id) { diff --git a/storage/connect/rcmsg.h b/storage/connect/rcmsg.h new file mode 100644 index 00000000000..b22e77f5175 --- /dev/null +++ b/storage/connect/rcmsg.h @@ -0,0 +1,15 @@ +#ifndef __RCMSG_H__ +#define __RCMSG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +char *GetMsgid(int id); +int GetRcString(int id, char *buf, int bufsize); + +#ifdef __cplusplus +} +#endif + +#endif /* __RCMSG_H__ */ diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index 77f2f43ec31..8525fd09cbc 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -90,11 +90,9 @@ TABDEF::TABDEF(void) /***********************************************************************/ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) { -//char buf[8]; int poff = 0; - void *memp = cat->Descp; - Name = (PSZ)PlugSubAlloc(g, memp, strlen(name) + 1); + Name = (PSZ)PlugSubAlloc(g, NULL, strlen(name) + 1); strcpy(Name, name); Cat = cat; Catfunc = GetFuncID(Cat->GetStringCatInfo(g, "Catfunc", NULL)); @@ -127,7 +125,6 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) PTABDEF xdefp; XGETDEF getdef = NULL; PCATLG cat = Cat; - void *memp = cat->Descp; #if defined(WIN32) // Is the DLL already loaded? @@ -189,7 +186,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) sprintf(g->Message, MSG(DEF_ALLOC_ERROR), Subtype); // Get the table definition block - if (!(xdefp = getdef(g, memp))) + if (!(xdefp = getdef(g, NULL))) return NULL; // Have the external class do its complete definition @@ -223,15 +220,13 @@ bool OEMDEF::DeleteTableFile(PGLOBAL g) /***********************************************************************/ bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - void *memp = Cat->Descp; - Module = Cat->GetStringCatInfo(g, "Module", ""); Subtype = Cat->GetStringCatInfo(g, "Subtype", Module); if (!*Module) Module = Subtype; - Desc = (char*)PlugSubAlloc(g, memp, strlen(Module) + Desc = (char*)PlugSubAlloc(g, NULL, strlen(Module) + strlen(Subtype) + 3); sprintf(Desc, "%s(%s)", Module, Subtype); return false; @@ -304,7 +299,7 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode) else txfp = new(g) DOSFAM(defp); - } else if (rfm == RECFM_FIX || rfm == RECFM_FIX) { + } else if (rfm == RECFM_FIX || rfm == RECFM_BIN) { if (map) txfp = new(g) MPXFAM(defp); else diff --git a/storage/connect/tabcol.cpp b/storage/connect/tabcol.cpp index f0e010291c3..9af52043f0c 100644 --- a/storage/connect/tabcol.cpp +++ b/storage/connect/tabcol.cpp @@ -1,7 +1,7 @@ /************* TabCol C++ Functions Source Code File (.CPP) ************/ -/* Name: TABCOL.CPP Version 2.6 */ +/* Name: TABCOL.CPP Version 2.7 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 1998-2012 */ +/* (C) Copyright to the author Olivier BERTRAND 1998-2013 */ /* */ /* This file contains the PlugDB++ XTAB, COLUMN and XORDER methods. */ /***********************************************************************/ @@ -23,18 +23,18 @@ #include "tabcol.h" /***********************************************************************/ -/* XTAB public constructor (in which Correl defaults to Name). */ +/* XTAB public constructor. */ /***********************************************************************/ -XTAB::XTAB(LPCSTR name, LPCSTR correl) : Name(name) +XTAB::XTAB(LPCSTR name, LPCSTR srcdef) : Name(name) { Next = NULL; To_Tdb = NULL; - Correl = (correl) ? correl : name; + Srcdef = srcdef; Creator = NULL; Qualifier = NULL; #ifdef DEBTRACE - htrc(" making new TABLE %s %s\n", Name, Correl); + htrc(" making new TABLE %s %s\n", Name, Srcdef); #endif } // end of XTAB constructor @@ -45,12 +45,12 @@ XTAB::XTAB(PTABLE tp) : Name(tp->Name) { Next = NULL; To_Tdb = NULL; - Correl = tp->Correl; + Srcdef = tp->Srcdef; Creator = tp->Creator; Qualifier = tp->Qualifier; #ifdef DEBTRACE - htrc(" making copy TABLE %s %s\n", Name, Correl); + htrc(" making copy TABLE %s %s\n", Name, Srcdef); #endif } // end of XTAB constructor @@ -83,7 +83,7 @@ void XTAB::Print(PGLOBAL g, FILE *f, uint n) for (PTABLE tp = this; tp; tp = tp->Next) { fprintf(f, "%sTABLE: %s.%s %s\n", - m, SVP(tp->Creator), tp->Name, SVP(tp->Correl)); + m, SVP(tp->Creator), tp->Name, SVP(tp->Srcdef)); PlugPutOut(g, f, TYPE_TDB, tp->To_Tdb, n + 2); } /* endfor tp */ @@ -101,7 +101,7 @@ void XTAB::Print(PGLOBAL g, char *ps, uint z) for (PTABLE tp = this; tp && n > 0; tp = tp->Next) { i = sprintf(buf, "TABLE: %s.%s %s To_Tdb=%p ", - SVP(tp->Creator), tp->Name, SVP(tp->Correl), tp->To_Tdb); + SVP(tp->Creator), tp->Name, SVP(tp->Srcdef), tp->To_Tdb); strncat(ps, buf, n); n -= i; } // endif tp diff --git a/storage/connect/tabcol.h b/storage/connect/tabcol.h index 5cc2050f872..c5ebfdbb10d 100644 --- a/storage/connect/tabcol.h +++ b/storage/connect/tabcol.h @@ -1,7 +1,7 @@ /*************** TabCol H Declares Source Code File (.H) ***************/ -/* Name: TABCOL.H Version 2.7 */ +/* Name: TABCOL.H Version 2.8 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 1998-2012 */ +/* (C) Copyright to the author Olivier BERTRAND 1998-2013 */ /* */ /* This file contains the XTAB, COLUMN and XORDER class definitions. */ /***********************************************************************/ @@ -15,22 +15,24 @@ /***********************************************************************/ /* Definition of class XTAB with all its method functions. */ /***********************************************************************/ - class DllExport XTAB: public BLOCK { // Table Name-Owner-Correl block. +class DllExport XTAB: public BLOCK { // Table Name-Owner-Srcdef block. + friend class TDBPRX; + friend class TDBTBM; public: // Constructors - XTAB(LPCSTR name, LPCSTR correl = NULL); + XTAB(LPCSTR name, LPCSTR srcdef = NULL); XTAB(PTABLE tp); // Implementation PTABLE GetNext(void) {return Next;} PTDB GetTo_Tdb(void) {return To_Tdb;} LPCSTR GetName(void) {return Name;} - LPCSTR GetCorrel(void) {return Correl;} + LPCSTR GetSrc(void) {return Srcdef;} LPCSTR GetCreator(void) {return Creator;} LPCSTR GetQualifier(void) {return Qualifier;} void SetTo_Tdb(PTDB tdbp) {To_Tdb = tdbp;} void SetName(LPCSTR name) {Name = name;} - void SetCorrel(LPCSTR correl) {Correl = correl;} + void SetSrc(LPCSTR srcdef) {Srcdef = srcdef;} void SetCreator(LPCSTR crname) {Creator = crname;} void SetQualifier(LPCSTR qname) {Qualifier = qname;} @@ -43,8 +45,8 @@ // Members PTABLE Next; // Points to next table in chain PTDB To_Tdb; // Points to Table description Block - LPCSTR Name; // Table name (can be changed by LNA and PLG) - LPCSTR Correl; // Correlation name + LPCSTR Name; // Table name + LPCSTR Srcdef; // Table Source definition LPCSTR Creator; // Creator name LPCSTR Qualifier; // Qualifier name }; // end of class XTAB @@ -85,7 +87,6 @@ class DllExport COLUMN: public XOBJECT { // Column Name/Qualifier block. virtual bool Eval(PGLOBAL) {assert(false); return true;} virtual int CheckSpcCol(PTDB, int) {assert(false); return 2;} virtual bool CheckSort(PTDB) {assert(false); return false;} - virtual void MarkCol(ushort) {assert(false);} private: // Members diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp index 288396276bc..b828c44d648 100644 --- a/storage/connect/tabdos.cpp +++ b/storage/connect/tabdos.cpp @@ -1047,7 +1047,7 @@ bool DOSCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) /***********************************************************************/ void DOSCOL::ReadColumn(PGLOBAL g) { - char *p; + char *p = NULL; int i, rc; int field; double dval; diff --git a/storage/connect/tabfix.cpp b/storage/connect/tabfix.cpp index 801de79aad9..4cad405452e 100644 --- a/storage/connect/tabfix.cpp +++ b/storage/connect/tabfix.cpp @@ -327,7 +327,7 @@ BINCOL::BINCOL(BINCOL *col1, PTDB tdbp) : DOSCOL(col1, tdbp) /***********************************************************************/ void BINCOL::ReadColumn(PGLOBAL g) { - char *p; + char *p = NULL; int rc; PTDBFIX tdbp = (PTDBFIX)To_Tdb; diff --git a/storage/connect/tabfmt.cpp b/storage/connect/tabfmt.cpp index 51631107f6e..860a1304a14 100644 --- a/storage/connect/tabfmt.cpp +++ b/storage/connect/tabfmt.cpp @@ -78,8 +78,6 @@ extern "C" int trace; PQRYRES CSVColumns(PGLOBAL g, const char *fn, char sep, char q, int hdr, int mxr, bool info) { - static int dbtype[] = {DB_CHAR, DB_SHORT, DB_CHAR, - DB_INT, DB_INT, DB_SHORT}; static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT}; static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, @@ -87,7 +85,7 @@ PQRYRES CSVColumns(PGLOBAL g, const char *fn, char sep, char q, static unsigned int length[] = {6, 6, 8, 10, 10, 6}; char *p, *colname[MAXCOL], dechar, filename[_MAX_PATH], buf[4096]; int i, imax, hmax, n, nerr, phase, blank, digit, dec, type; - int ncol = sizeof(dbtype) / sizeof(int); + int ncol = sizeof(buftyp) / sizeof(int); int num_read = 0, num_max = 10000000; // Statistics int len[MAXCOL], typ[MAXCOL], prc[MAXCOL]; FILE *infile; @@ -341,7 +339,7 @@ PQRYRES CSVColumns(PGLOBAL g, const char *fn, char sep, char q, /* Allocate the structures used to refer to the result set. */ /*********************************************************************/ qrp = PlgAllocResult(g, ncol, imax, IDS_COLUMNS + 3, - dbtype, buftyp, fldtyp, length, true, false); + buftyp, fldtyp, length, true, false); qrp->Nblin = imax; if (info) @@ -1090,7 +1088,12 @@ bool TDBFMT::OpenDB(PGLOBAL g) { Linenum = 0; - if (Use != USE_OPEN && (Columns || Mode == MODE_UPDATE)) { + if (Mode == MODE_INSERT || Mode == MODE_UPDATE) { + sprintf(g->Message, MSG(FMT_WRITE_NIY), "FMT"); + return true; // NIY + } // endif Mode + + if (Use != USE_OPEN && Columns) { // Make the formats used to read records PSZ pfm; int i, n; @@ -1098,17 +1101,12 @@ bool TDBFMT::OpenDB(PGLOBAL g) PCOLDEF cdp; PDOSDEF tdp = (PDOSDEF)To_Def; -// if (Mode != MODE_UPDATE) { - for (colp = (PCSVCOL)Columns; colp; colp = (PCSVCOL)colp->Next) - if (!colp->IsSpecial()) // Not a pseudo column - Fields = max(Fields, (int)colp->Fldnum); + for (colp = (PCSVCOL)Columns; colp; colp = (PCSVCOL)colp->Next) + if (!colp->IsSpecial()) // Not a pseudo column + Fields = max(Fields, (int)colp->Fldnum); - if (Columns) - Fields++; // Fldnum was 0 based - -// } else -// for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext()) -// Fields++; + if (Columns) + Fields++; // Fldnum was 0 based To_Fld = PlugSubAlloc(g, NULL, Lrecl + 1); FldFormat = (PSZ*)PlugSubAlloc(g, NULL, sizeof(PSZ) * Fields); diff --git a/storage/connect/tabmul.cpp b/storage/connect/tabmul.cpp old mode 100644 new mode 100755 index 5fe18ef5b1d..146e2891ec7 --- a/storage/connect/tabmul.cpp +++ b/storage/connect/tabmul.cpp @@ -68,6 +68,8 @@ #include "tabdos.h" // TDBDOS and DOSCOL class dcls #include "tabmul.h" // TDBMUL and MULCOL classes dcls +extern "C" int trace; + /* ------------------------- Class TDBMUL ---------------------------- */ /***********************************************************************/ @@ -122,15 +124,25 @@ PTDB TDBMUL::Duplicate(PGLOBAL g) /***********************************************************************/ bool TDBMUL::InitFileNames(PGLOBAL g) { -#define PFNZ 8192 - char *pfn[PFNZ], filename[_MAX_DRIVE+_MAX_DIR+_MAX_FNAME+_MAX_EXT]; +#define PFNZ 4096 +#define FNSZ _MAX_DRIVE+_MAX_DIR+_MAX_FNAME+_MAX_EXT + char *pfn[PFNZ]; + char *filename; int rc, n = 0; + if (trace) + htrc("in InitFileName: fn[]=%d\n", FNSZ); + + filename = (char*)PlugSubAlloc(g, NULL, FNSZ); + // The sub table may need to refer to the Table original block Tdbp->SetTable(To_Table); // Was not set at construction PlugSetPath(filename, Tdbp->GetFile(g), Tdbp->GetPath()); + if (trace) + htrc("InitFileName: fn='%s'\n", filename); + if (Mul == 1) { /*******************************************************************/ /* To_File is a multiple name with special characters */ @@ -194,15 +206,28 @@ bool TDBMUL::InitFileNames(PGLOBAL g) _splitpath(filename, NULL, direc, pattern, ftype); strcat(pattern, ftype); + if (trace) + htrc("direc=%s pattern=%s ftype=%s\n", direc, pattern, ftype); + // Start searching files in the target directory. if (!(dir = opendir(direc))) { sprintf(g->Message, MSG(BAD_DIRECTORY), direc, strerror(errno)); + + if (trace) + htrc("%s\n", g->Message); + return true; } // endif dir + if (trace) + htrc("dir opened: reading files\n"); + while ((entry = readdir(dir)) && n < PFNZ) { strcat(strcpy(fn, direc), entry->d_name); + if (trace) + htrc("%s read\n", fn); + if (lstat(fn, &fileinfo) < 0) { sprintf(g->Message, "%s: %s", fn, strerror(errno)); return true; @@ -218,6 +243,10 @@ bool TDBMUL::InitFileNames(PGLOBAL g) strcat(strcpy(filename, direc), entry->d_name); pfn[n] = (char*)PlugSubAlloc(g, NULL, strlen(filename) + 1); strcpy(pfn[n++], filename); + + if (trace) + htrc("Adding pfn[%d] %s\n", n, filename); + } // endwhile readdir // Close the dir handle. @@ -235,7 +264,7 @@ bool TDBMUL::InitFileNames(PGLOBAL g) return true; while (n < PFNZ) { - if (!fgets(filename, sizeof(filename), stream)) { + if (!fgets(filename, FNSZ, stream)) { fclose(stream); break; } // endif fgets @@ -364,9 +393,12 @@ int TDBMUL::Cardinality(PGLOBAL g) int TDBMUL::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { - int i; + int i; int mxsz; + if (trace) + htrc("TDBMUL::GetMaxSize: Filenames=%p\n", Filenames); + if (!Filenames && InitFileNames(g)) return -1; @@ -420,10 +452,9 @@ int TDBMUL::RowNumber(PGLOBAL g, bool b) /***********************************************************************/ bool TDBMUL::OpenDB(PGLOBAL g) { -#ifdef DEBTRACE - htrc("MUL OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", - this, Tdb_No, Use, To_Key_Col, Mode); -#endif + if (trace) + htrc("MUL OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", + this, Tdb_No, Use, To_Key_Col, Mode); if (Use == USE_OPEN) { /*******************************************************************/ @@ -451,7 +482,7 @@ bool TDBMUL::OpenDB(PGLOBAL g) /*********************************************************************/ /* Open the first table file of the list. */ /*********************************************************************/ -//if (!Filenames && InitFileNames(g)) done in GetMaxSize +//if (!Filenames && InitFileNames(g)) // was done in GetMaxSize // return true; if (Filenames[iFile = 0]) { @@ -735,10 +766,9 @@ int TDBDIR::GetMaxSize(PGLOBAL g) /***********************************************************************/ bool TDBDIR::OpenDB(PGLOBAL g) { -#ifdef DEBTRACE - htrc("DIR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", - this, Tdb_No, Use, Mode); -#endif + if (trace) + htrc("DIR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", + this, Tdb_No, Use, Mode); if (Use == USE_OPEN) { /*******************************************************************/ @@ -898,11 +928,9 @@ void DIRCOL::ReadColumn(PGLOBAL g) { PTDBDIR tdbp = (PTDBDIR)To_Tdb; -#ifdef DEBTRACE - fprintf(debug, - "DIR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", - Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); -#endif + if (trace) + htrc("DIR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", + Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); /*********************************************************************/ /* Retrieve the information corresponding to the column number. */ @@ -1304,10 +1332,9 @@ int TDBDHR::GetMaxSize(PGLOBAL g) /***********************************************************************/ bool TDBDHR::OpenDB(PGLOBAL g) { -#ifdef DEBTRACE - htrc("DHR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", - this, Tdb_No, Use, Mode); -#endif + if (trace) + htrc("DHR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", + this, Tdb_No, Use, Mode); if (Use == USE_OPEN) { /*******************************************************************/ @@ -1442,11 +1469,9 @@ void DHRCOL::ReadColumn(PGLOBAL g) int rc; PTDBDHR tdbp = (PTDBDHR)To_Tdb; -#ifdef DEBTRACE - fprintf(debug, - "DHR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", - Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); -#endif + if (trace) + htrc("DHR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", + Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); /*********************************************************************/ /* Retrieve the information corresponding to the column number. */ diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 7b38cc8ab1b..030f5760601 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -31,7 +31,10 @@ /* IBM, Borland, GNU or Microsoft C++ Compiler and Linker */ /* */ /************************************************************************/ +#define MYSQL_SERVER 1 #include "my_global.h" +#include "sql_class.h" +#include "sql_servers.h" #if defined(WIN32) //#include #else // !WIN32 @@ -57,6 +60,7 @@ #include "reldef.h" #include "tabmysql.h" #include "valblk.h" +#include "tabutil.h" #if defined(_CONSOLE) void PrintResult(PGLOBAL, PSEM, PQRYRES); @@ -75,13 +79,54 @@ MYSQLDEF::MYSQLDEF(void) Hostname = NULL; Database = NULL; Tabname = NULL; + Srcdef = NULL; Username = NULL; Password = NULL; Portnumber = 0; + Isview = FALSE; Bind = FALSE; Delayed = FALSE; } // end of MYSQLDEF constructor +/***********************************************************************/ +/* Get connection info from the declared server. */ +/***********************************************************************/ +bool MYSQLDEF::GetServerInfo(PGLOBAL g, const char *server_name) +{ + THD *thd= current_thd; + MEM_ROOT *mem= thd->mem_root; + FOREIGN_SERVER *server, server_buffer; + DBUG_ENTER("GetServerInfo"); + DBUG_PRINT("info", ("server_name %s", server_name)); + + if (!server_name || !strlen(server_name)) { + DBUG_PRINT("info", ("server_name not defined!")); + strcpy(g->Message, "server_name not defined!"); + DBUG_RETURN(true); + } // endif server_name + + // get_server_by_name() clones the server if exists and allocates + // copies of strings in the supplied mem_root + if (!(server= get_server_by_name(mem, server_name, &server_buffer))) { + DBUG_PRINT("info", ("get_server_by_name returned > 0 error condition!")); + /* need to come up with error handling */ + strcpy(g->Message, "get_server_by_name returned > 0 error condition!"); + DBUG_RETURN(true); + } // endif server + + DBUG_PRINT("info", ("get_server_by_name returned server at %lx", + (long unsigned int) server)); + + // TODO: We need to examine which of these can really be NULL + Hostname = PlugDup(g, server->host); + Database = PlugDup(g, server->db); + Username = PlugDup(g, server->username); + Password = PlugDup(g, server->password); + Portnumber = (server->port) ? server->port : GetDefaultPort(); + + DBUG_RETURN(false); +} // end of GetServerInfo + /***********************************************************************/ /* Parse connection string */ /* */ @@ -131,54 +176,25 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url) if ((!strstr(url, "://") && (!strchr(url, '@')))) { // No :// or @ in connection string. Must be a straight // connection name of either "server" or "server/table" - strcpy(g->Message, "Using Federated server not implemented yet"); - return true; -#if 0 - /* ok, so we do a little parsing, but not completely! */ - share->parsed= FALSE; - /* - If there is a single '/' in the connection string, this means the user is - specifying a table name - */ + // ok, so we do a little parsing, but not completely! + if ((Tabname= strchr(url, '/'))) { + // If there is a single '/' in the connection string, + // this means the user is specifying a table name + *Tabname++= '\0'; - if ((share->table_name= strchr(share->connection_string, '/'))) - { - *share->table_name++= '\0'; - share->table_name_length= strlen(share->table_name); + // there better not be any more '/'s ! + if (strchr(Tabname, '/')) + return true; - DBUG_PRINT("info", - ("internal format, parsed table_name " - "share->connection_string: %s share->table_name: %s", - share->connection_string, share->table_name)); + } else + // Otherwise, straight server name, + // use tablename of federatedx table as remote table name + Tabname= Name; - /* - there better not be any more '/'s ! - */ - if (strchr(share->table_name, '/')) - goto error; - } - /* - Otherwise, straight server name, use tablename of federatedx table - as remote table name - */ - else - { - /* - Connection specifies everything but, resort to - expecting remote and foreign table names to match - */ - share->table_name= strmake_root(mem_root, table->s->table_name.str, - (share->table_name_length= - table->s->table_name.length)); - DBUG_PRINT("info", - ("internal format, default table_name " - "share->connection_string: %s share->table_name: %s", - share->connection_string, share->table_name)); - } + if (trace) + htrc("server: %s Tabname: %s", url, Tabname); - if ((error_num= get_connection(mem_root, share))) - goto error; -#endif // 0 + return GetServerInfo(g, url); } else { // URL, parse it char *sport, *scheme = url; @@ -243,10 +259,13 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url) if ((sport = strchr(Hostname, ':'))) *sport++ = 0; - Portnumber = (sport && sport[0]) ? atoi(sport) : MYSQL_PORT; + Portnumber = (sport && sport[0]) ? atoi(sport) : GetDefaultPort(); + + if (Username[0] == 0) + Username = Cat->GetStringCatInfo(g, "User", "*"); if (Hostname[0] == 0) - Hostname = "localhost"; + Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); if (!Database || !*Database) Database = Cat->GetStringCatInfo(g, "Database", "*"); @@ -272,24 +291,57 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url) /***********************************************************************/ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - char *url = Cat->GetStringCatInfo(g, "Connect", NULL); + char *url; Desc = "MySQL Table"; - if (!url || !*url) { - // Not using the connection URL - Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); - Database = Cat->GetStringCatInfo(g, "Database", "*"); - Tabname = Cat->GetStringCatInfo(g, "Name", Name); // Deprecated - Tabname = Cat->GetStringCatInfo(g, "Tabname", Tabname); - Username = Cat->GetStringCatInfo(g, "User", "root"); - Password = Cat->GetStringCatInfo(g, "Password", NULL); - Portnumber = Cat->GetIntCatInfo("Port", MYSQL_PORT); - } else if (ParseURL(g, url)) - return TRUE; + if (stricmp(am, "MYPRX")) { + // Normal case of specific MYSQL table + url = Cat->GetStringCatInfo(g, "Connect", NULL); + + if (!url || !*url) { + // Not using the connection URL + Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); + Database = Cat->GetStringCatInfo(g, "Database", "*"); + Tabname = Cat->GetStringCatInfo(g, "Name", Name); // Deprecated + Tabname = Cat->GetStringCatInfo(g, "Tabname", Tabname); + Username = Cat->GetStringCatInfo(g, "User", "*"); + Password = Cat->GetStringCatInfo(g, "Password", NULL); + Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort()); + } else if (ParseURL(g, url)) + return TRUE; + + Bind = !!Cat->GetIntCatInfo("Bind", 0); + Delayed = !!Cat->GetIntCatInfo("Delayed", 0); + } else { + // MYSQL access from a PROXY table + Database = Cat->GetStringCatInfo(g, "Database", "*"); + Isview = Cat->GetBoolCatInfo("View", FALSE); + + // We must get other connection parms from the calling table + Remove_tshp(Cat); + url = Cat->GetStringCatInfo(g, "Connect", NULL); + + if (!url || !*url) { + Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); + Username = Cat->GetStringCatInfo(g, "User", "*"); + Password = Cat->GetStringCatInfo(g, "Password", NULL); + Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort()); + } else { + char *locdb = Database; + + if (ParseURL(g, url)) + return TRUE; + + Database = locdb; + } // endif url + + Tabname = Name; + } // endif am + + if ((Srcdef = Cat->GetStringCatInfo(g, "Srcdef", NULL))) + Isview = TRUE; - Bind = !!Cat->GetIntCatInfo("Bind", 0); - Delayed = !!Cat->GetIntCatInfo("Delayed", 0); return FALSE; } // end of DefineAM @@ -316,18 +368,22 @@ TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp) Host = tdp->GetHostname(); Database = tdp->GetDatabase(); Tabname = tdp->GetTabname(); + Srcdef = tdp->GetSrcdef(); User = tdp->GetUsername(); Pwd = tdp->GetPassword(); Port = tdp->GetPortnumber(); + Isview = tdp->Isview; Prep = tdp->Bind; Delayed = tdp->Delayed; } else { Host = NULL; Database = NULL; Tabname = NULL; + Srcdef = NULL; User = NULL; Pwd = NULL; Port = 0; + Isview = FALSE; Prep = FALSE; Delayed = FALSE; } // endif tdp @@ -347,9 +403,11 @@ TDBMYSQL::TDBMYSQL(PGLOBAL g, PTDBMY tdbp) : TDBASE(tdbp) Host = tdbp->Host; Database = tdbp->Database; Tabname = tdbp->Tabname; + Srcdef = tdbp->Srcdef; User = tdbp->User; Pwd = tdbp->Pwd; Port = tdbp->Port; + Isview = tdbp->Isview; Prep = tdbp->Prep; Delayed = tdbp->Delayed; Bind = NULL; @@ -395,55 +453,54 @@ PCOL TDBMYSQL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) /***********************************************************************/ bool TDBMYSQL::MakeSelect(PGLOBAL g) { - char *colist; char *tk = "`"; - int len = 0, ncol = 0, rank = 0; + int rank = 0; bool b = FALSE; PCOL colp; - PDBUSER dup = PlgGetUser(g); +//PDBUSER dup = PlgGetUser(g); if (Query) return FALSE; // already done - for (colp = Columns; colp; colp = colp->GetNext()) - ncol++; + if (Srcdef) { + Query = Srcdef; + return false; + } // endif Srcdef - if (ncol) { - colist = (char*)PlugSubAlloc(g, NULL, (NAM_LEN + 4) * ncol); - *colist = '\0'; + //Find the address of the suballocated query + Query = (char*)PlugSubAlloc(g, NULL, 0); + strcpy(Query, "SELECT "); + if (Columns) { for (colp = Columns; colp; colp = colp->GetNext()) if (colp->IsSpecial()) { strcpy(g->Message, MSG(NO_SPEC_COL)); return TRUE; } else { if (b) - strcat(colist, ", "); + strcat(Query, ", "); else b = TRUE; - strcat(strcat(strcat(colist, tk), colp->GetName()), tk); + strcat(strcat(strcat(Query, tk), colp->GetName()), tk); ((PMYCOL)colp)->Rank = rank++; } // endif colp } else { - // ncol == 0 can occur for queries such as Query count(*) from... - // for which we will count the rows from Query '*' from... + // ncol == 0 can occur for views or queries such as + // Query count(*) from... for which we will count the rows from + // Query '*' from... // (the use of a char constant minimize the result storage) - colist = (char*)PlugSubAlloc(g, NULL, 2); - strcpy(colist, "'*'"); + strcat(Query, (Isview) ? "*" : "'*'"); } // endif ncol - // Below 32 is space to contain extra stuff - len += (strlen(colist) + strlen(Tabname) + 32); - len += (To_Filter ? strlen(To_Filter) + 7 : 0); - Query = (char*)PlugSubAlloc(g, NULL, len); - strcat(strcpy(Query, "SELECT "), colist); strcat(strcat(strcat(strcat(Query, " FROM "), tk), Tabname), tk); if (To_Filter) strcat(strcat(Query, " WHERE "), To_Filter); + // Now we know how much to suballocate + PlugSubAlloc(g, NULL, strlen(Query) + 1); return FALSE; } // end of MakeSelect @@ -710,11 +767,6 @@ int TDBMYSQL::BindColumns(PGLOBAL g) } // endif prep #endif // MYSQL_PREPARED_STATEMENTS - for (PMYCOL colp = (PMYCOL)Columns; colp; colp = (PMYCOL)colp->Next) - if (colp->Buf_Type == TYPE_DATE) - // Format must match DATETIME MySQL type - ((DTVAL*)colp->GetValue())->SetFormat(g, "YYYY-MM-DD hh:mm:ss", 19); - return RC_OK; } // end of BindColumns @@ -728,7 +780,7 @@ bool TDBMYSQL::OpenDB(PGLOBAL g) /* Table already open, just replace it at its beginning. */ /*******************************************************************/ Myc.Rewind(); - return FALSE; + return false; } // endif use /*********************************************************************/ @@ -740,10 +792,18 @@ bool TDBMYSQL::OpenDB(PGLOBAL g) /*********************************************************************/ if (!Myc.Connected()) { if (Myc.Open(g, Host, Database, User, Pwd, Port)) - return TRUE; + return true; } // endif Connected + /*********************************************************************/ + /* Take care of DATE columns. */ + /*********************************************************************/ + for (PMYCOL colp = (PMYCOL)Columns; colp; colp = (PMYCOL)colp->Next) + if (colp->Buf_Type == TYPE_DATE) + // Format must match DATETIME MySQL type + ((DTVAL*)colp->GetValue())->SetFormat(g, "YYYY-MM-DD hh:mm:ss", 19); + /*********************************************************************/ /* Allocate whatever is used for getting results. */ /*********************************************************************/ @@ -751,7 +811,24 @@ bool TDBMYSQL::OpenDB(PGLOBAL g) if (!MakeSelect(g)) m_Rc = Myc.ExecSQL(g, Query); +#if 0 + if (!Myc.m_Res || !Myc.m_Fields) { + sprintf(g->Message, "%s result", (Myc.m_Res) ? "Void" : "No"); + Myc.Close(); + return true; + } // endif m_Res +#endif // 0 + + if (!m_Rc && Srcdef) + if (SetColumnRanks(g)) + return true; + } else if (Mode == MODE_INSERT) { + if (Srcdef) { + strcpy(g->Message, "No insert into anonym views"); + return true; + } // endif Srcdef + if (!MakeInsert(g)) { #if defined(MYSQL_PREPARED_STATEMENTS) int n = (Prep) ? Myc.PrepareSQL(g, Query) : Nparm; @@ -803,6 +880,78 @@ bool TDBMYSQL::OpenDB(PGLOBAL g) return FALSE; } // end of OpenDB +/***********************************************************************/ +/* Set the rank of columns in the result set. */ +/***********************************************************************/ +bool TDBMYSQL::SetColumnRanks(PGLOBAL g) + { + for (PCOL colp = Columns; colp; colp = colp->GetNext()) + if (((PMYCOL)colp)->FindRank(g)) + return TRUE; + + return FALSE; + } // end of SetColumnRanks + +/***********************************************************************/ +/* Called by Parent table to make the columns of a View. */ +/***********************************************************************/ +PCOL TDBMYSQL::MakeFieldColumn(PGLOBAL g, char *name) + { + int n; + MYSQL_FIELD *fld; + PCOL cp, colp = NULL; + + for (n = 0; n < Myc.m_Fields; n++) { + fld = &Myc.m_Res->fields[n]; + + if (!stricmp(name, fld->name)) { + colp = new(g) MYSQLCOL(fld, this, n); + + if (colp->InitValue(g)) + return NULL; + + if (!Columns) + Columns = colp; + else for (cp = Columns; cp; cp = cp->GetNext()) + if (!cp->GetNext()) { + cp->SetNext(colp); + break; + } // endif Next + + break; + } // endif name + + } // endfor n + + if (!colp) + sprintf(g->Message, "Column %s is not in view", name); + + return colp; + } // end of MakeFieldColumn + +/***********************************************************************/ +/* Called by Pivot tables to find default column names in a View */ +/* as the name of last field not equal to the passed name. */ +/***********************************************************************/ +char *TDBMYSQL::FindFieldColumn(char *name) + { + int n; + MYSQL_FIELD *fld; + char *cp = NULL; + + for (n = Myc.m_Fields - 1; n >= 0; n--) { + fld = &Myc.m_Res->fields[n]; + + if (!name || stricmp(name, fld->name)) { + cp = fld->name; + break; + } // endif name + + } // endfor n + + return cp; + } // end of FindFieldColumn + /***********************************************************************/ /* Data Base read routine for MYSQL access method. */ /***********************************************************************/ @@ -916,7 +1065,7 @@ MYSQLCOL::MYSQLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am) tdbp->SetColumns(this); } // endif cprec - // Set additional Dos access method information for column. + // Set additional MySQL access method information for column. Long = cdp->GetLong(); Bind = NULL; To_Val = NULL; @@ -928,6 +1077,33 @@ MYSQLCOL::MYSQLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am) } // end of MYSQLCOL constructor +/***********************************************************************/ +/* MYSQLCOL public constructor. */ +/***********************************************************************/ +MYSQLCOL::MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PSZ am) + : COLBLK(NULL, tdbp, i) + { + Name = fld->name; + Opt = 0; + Long = fld->length; + Buf_Type = MYSQLtoPLG(fld->type); + strcpy(Format.Type, GetFormatType(Buf_Type)); + Format.Length = Long; + Format.Prec = fld->decimals; + ColUse = U_P; + Nullable = !IS_NOT_NULL(fld->flags); + + // Set additional MySQL access method information for column. + Bind = NULL; + To_Val = NULL; + Slen = 0; + Rank = i; + + if (trace) + htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); + + } // end of MYSQLCOL constructor + /***********************************************************************/ /* MYSQLCOL constructor used for copying columns. */ /* tdbp is the pointer to the new table descriptor. */ @@ -941,6 +1117,24 @@ MYSQLCOL::MYSQLCOL(MYSQLCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) Rank = col1->Rank; } // end of MYSQLCOL copy constructor +/***********************************************************************/ +/* FindRank: Find the rank of this column in the result set. */ +/***********************************************************************/ +bool MYSQLCOL::FindRank(PGLOBAL g) +{ + int n; + MYSQLC myc = ((PTDBMY)To_Tdb)->Myc; + + for (n = 0; n < myc.m_Fields; n++) + if (!stricmp(Name, myc.m_Res->fields[n].name)) { + Rank = n; + return false; + } // endif Name + + sprintf(g->Message, "Column %s not in result set", Name); + return true; +} // end of FindRank + /***********************************************************************/ /* SetBuffer: prepare a column block for write operation. */ /***********************************************************************/ @@ -1000,10 +1194,6 @@ void MYSQLCOL::InitBind(PGLOBAL g) memset(Bind, 0, sizeof(MYSQL_BIND)); if (Buf_Type == TYPE_DATE) { - // Default format must match DATETIME MySQL type -// if (!((DTVAL*)Value)->IsFormatted()) - ((DTVAL*)Value)->SetFormat(g, "YYYY-MM-DD hh:mm:ss", 19); - Bind->buffer_type = PLGtoMYSQL(TYPE_STRING, false); Bind->buffer = (char *)PlugSubAlloc(g,NULL, 20); Bind->buffer_length = 20; @@ -1026,11 +1216,6 @@ void MYSQLCOL::ReadColumn(PGLOBAL g) int rc; PTDBMY tdbp = (PTDBMY)To_Tdb; - if (trace) - htrc("MySQL ReadColumn: name=%s\n", Name); - - assert (Rank >= 0); - /*********************************************************************/ /* If physical fetching of the line was deferred, do it now. */ /*********************************************************************/ @@ -1043,14 +1228,17 @@ void MYSQLCOL::ReadColumn(PGLOBAL g) } else tdbp->Fetched = TRUE; - if ((buf = ((PTDBMY)To_Tdb)->Myc.GetCharField(Rank))) + if ((buf = ((PTDBMY)To_Tdb)->Myc.GetCharField(Rank))) { + if (trace) + htrc("MySQL ReadColumn: name=%s buf=%s\n", Name, buf); + Value->SetValue_char(buf, Long); - else { + } else { if (Nullable) Value->SetNull(true); Value->Reset(); // Null value - } // endelse + } // endif buf } // end of ReadColumn @@ -1068,7 +1256,7 @@ void MYSQLCOL::WriteColumn(PGLOBAL g) #if defined(MYSQL_PREPARED_STATEMENTS) if (((PTDBMY)To_Tdb)->Prep) { if (Buf_Type == TYPE_DATE) { - Value->ShowValue((char *)Bind->buffer, (int)*Bind->length); + Value->ShowValue((char *)Bind->buffer, (int)Bind->buffer_length); Slen = strlen((char *)Bind->buffer); } else if (IsTypeChar(Buf_Type)) Slen = strlen(Value->GetCharValue()); @@ -1098,5 +1286,5 @@ TDBMCL::TDBMCL(PMYDEF tdp) : TDBCAT(tdp) /***********************************************************************/ PQRYRES TDBMCL::GetResult(PGLOBAL g) { - return MyColumns(g, Host, Db, User, Pwd, Tab, NULL, Port, false, false); + return MyColumns(g, Host, Db, User, Pwd, Tab, NULL, Port, false); } // end of GetResult diff --git a/storage/connect/tabmysql.h b/storage/connect/tabmysql.h index 56d21550df6..16e2d650229 100644 --- a/storage/connect/tabmysql.h +++ b/storage/connect/tabmysql.h @@ -30,6 +30,7 @@ class MYSQLDEF : public TABDEF {/* Logical table description */ inline PSZ GetHostname(void) {return Hostname;}; inline PSZ GetDatabase(void) {return Database;}; inline PSZ GetTabname(void) {return Tabname;} + inline PSZ GetSrcdef(void) {return Srcdef;} inline PSZ GetUsername(void) {return Username;}; inline PSZ GetPassword(void) {return Password;}; inline int GetPortnumber(void) {return Portnumber;} @@ -38,15 +39,18 @@ class MYSQLDEF : public TABDEF {/* Logical table description */ virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); virtual PTDB GetTable(PGLOBAL g, MODE m); bool ParseURL(PGLOBAL g, char *url); + bool GetServerInfo(PGLOBAL g, const char *server_name); protected: // Members PSZ Hostname; /* Host machine to use */ PSZ Database; /* Database to be used by server */ PSZ Tabname; /* External table name */ + PSZ Srcdef; /* The source table SQL definition */ PSZ Username; /* User logon name */ PSZ Password; /* Password logon info */ int Portnumber; /* MySQL port number (0 = default) */ + bool Isview; /* TRUE if this table is a MySQL view */ bool Bind; /* Use prepared statement on insert */ bool Delayed; /* Delayed insert */ }; // end of MYSQLDEF @@ -72,6 +76,7 @@ class TDBMYSQL : public TDBASE { virtual int GetProgMax(PGLOBAL g); virtual void ResetDB(void) {N = 0;} virtual int RowNumber(PGLOBAL g, bool b = FALSE); + virtual bool IsView(void) {return Isview;} void SetDatabase(LPCSTR db) {Database = (char*)db;} // Database routines @@ -83,6 +88,11 @@ class TDBMYSQL : public TDBASE { virtual int DeleteDB(PGLOBAL g, int irc); virtual void CloseDB(PGLOBAL g); + // Specific routines + bool SetColumnRanks(PGLOBAL g); + PCOL MakeFieldColumn(PGLOBAL g, char *name); + PSZ FindFieldColumn(char *name); + protected: // Internal functions bool MakeSelect(PGLOBAL g); @@ -99,9 +109,11 @@ class TDBMYSQL : public TDBASE { char *Pwd; // Password logon info char *Database; // Database to be used by server char *Tabname; // External table name + char *Srcdef; // The source table SQL definition char *Query; // Points to SQL query - char *Qbuf; // Used for not prepared insert + char *Qbuf; // Used for not prepared insert bool Fetched; // True when fetch was done + bool Isview; // True if this table is a MySQL view bool Prep; // Use prepared statement on insert bool Delayed; // Use delayed insert int m_Rc; // Return code from command @@ -119,6 +131,7 @@ class MYSQLCOL : public COLBLK { public: // Constructors MYSQLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "MYSQL"); + MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PSZ am = "MYSQL"); MYSQLCOL(MYSQLCOL *colp, PTDB tdbp); // Constructor used in copy process // Implementation @@ -129,6 +142,7 @@ class MYSQLCOL : public COLBLK { virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual void ReadColumn(PGLOBAL g); virtual void WriteColumn(PGLOBAL g); + bool FindRank(PGLOBAL g); protected: // Default constructor not to be used diff --git a/storage/connect/taboccur.cpp b/storage/connect/taboccur.cpp new file mode 100644 index 00000000000..478edb14f9e --- /dev/null +++ b/storage/connect/taboccur.cpp @@ -0,0 +1,592 @@ +/************ TabOccur CPP Declares Source Code File (.CPP) ************/ +/* Name: TABOCCUR.CPP Version 1.1 */ +/* */ +/* (C) Copyright to the author Olivier BERTRAND 2013 */ +/* */ +/* OCCUR: Table that provides a view of a source table where the */ +/* contain of several columns of the source table is placed in only */ +/* one column, the OCCUR column, this resulting into several rows. */ +/***********************************************************************/ + +/***********************************************************************/ +/* Include relevant section of system dependant header files. */ +/***********************************************************************/ +#include "my_global.h" +#if defined(WIN32) +#include +#include +#if defined(__BORLANDC__) +#define __MFC_COMPAT__ // To define min/max as macro +#endif +//#include +#else +#if defined(UNIX) +#include +#include +#include +#include +#include +#include "osutil.h" +#else +//#include +#endif +//#include +#endif + +/***********************************************************************/ +/* Include application header files: */ +/***********************************************************************/ +#include "table.h" // MySQL table definitions +#include "global.h" +#include "plgdbsem.h" +#include "reldef.h" +#include "filamtxt.h" +#include "tabdos.h" +#include "tabcol.h" +#include "taboccur.h" +#include "xtable.h" +#if defined(MYSQL_SUPPORT) +#include "tabmysql.h" +#endif // MYSQL_SUPPORT +#include "ha_connect.h" +#include "mycat.h" + +extern "C" int trace; + +/***********************************************************************/ +/* Prepare and count columns in the column list. */ +/***********************************************************************/ +static int PrepareColist(char *colist) + { + char *p, *pn; + int n = 0; + + // Count the number of columns and change separator into null char + for (pn = colist; ; pn += (strlen(pn) + 1)) + // Separator can be ; if colist was specified in the option_list + if ((p = strchr(pn, ',')) || (p = strchr(pn, ';'))) { + *p++ = '\0'; + n++; + } else { + if (*pn) + n++; + + break; + } // endif p + + return n; + } // end of PrepareColist + +/************************************************************************/ +/* OcrColumns: constructs the result blocks containing all the columns */ +/* of the object table that will be retrieved by GetData commands. */ +/************************************************************************/ +bool OcrColumns(PGLOBAL g, PQRYRES qrp, const char *col, + const char *ocr, const char *rank) + { + char *pn, *colist; + int i, k, m, n = 0, c = 0, j = qrp->Nblin; + bool rk, b = false; + PCOLRES crp; + + if (!col || !*col) { + strcpy(g->Message, "Missing colist"); + return true; + } // endif col + + // Prepare the column list + colist = (char*)PlugSubAlloc(g, NULL, strlen(col) + 1); + strcpy(colist, col); + m = PrepareColist(colist); + + if ((rk = (rank && *rank))) { + if (m == 1) { + strcpy(g->Message, "Cannot handle one column colist and rank"); + return true; + } // endif m + + for (k = 0, pn = colist; k < m; k++, pn += (strlen(pn) + 1)) + n = max(n, (signed)strlen(pn)); + + } // endif k + + // Default occur column name is the 1st colist column name + if (!ocr || !*ocr) + ocr = colist; + + /**********************************************************************/ + /* Replace the columns of the colist by the rank and occur columns. */ + /**********************************************************************/ + for (i = 0; i < qrp->Nblin; i++) { + for (k = 0, pn = colist; k < m; k++, pn += (strlen(pn) + 1)) + if (!stricmp(pn, qrp->Colresp->Kdata->GetCharValue(i))) + break; + + if (k < m) { + // This column belongs to colist + if (rk) { + // Place the rank column here + for (crp = qrp->Colresp; crp; crp = crp->Next) + switch (crp->Fld) { + case FLD_NAME: crp->Kdata->SetValue((char*)rank, i); break; + case FLD_TYPE: crp->Kdata->SetValue(TYPE_STRING, i); break; + case FLD_PREC: crp->Kdata->SetValue(n, i); break; + case FLD_SCALE: crp->Kdata->SetValue(0, i); break; + case FLD_NULL: crp->Kdata->SetValue(0, i); break; + case FLD_REM: crp->Kdata->Reset(i); break; + default: ; // Ignored by CONNECT + } // endswich Fld + + rk = false; + } else if (!b) { + // First remaining listed column, will be the occur column + for (crp = qrp->Colresp; crp; crp = crp->Next) + switch (crp->Fld) { + case FLD_NAME: crp->Kdata->SetValue((char*)ocr, i); break; + case FLD_REM: crp->Kdata->Reset(i); break; + default: ; // Nothing to do + } // endswich Fld + + b = true; + } else if (j == qrp->Nblin) + j = i; // Column to remove + + c++; + } else if (j < i) { + // Move this column in empty spot + for (crp = qrp->Colresp; crp; crp = crp->Next) + crp->Kdata->Move(i, j); + + j++; + } // endif k + + } // endfor i + + // Check whether all columns of the list where found + if (c < m) { + strcpy(g->Message, "Some colist columns are not in the source table"); + return true; + } // endif crp + + /**********************************************************************/ + /* Set the number of columns of the table. */ + /**********************************************************************/ + qrp->Nblin = j; + return false; + } // end of OcrColumns + +/************************************************************************/ +/* OcrSrcCols: constructs the result blocks containing all the columns */ +/* of the object table that will be retrieved by GetData commands. */ +/************************************************************************/ +bool OcrSrcCols(PGLOBAL g, PQRYRES qrp, const char *col, + const char *ocr, const char *rank) + { + char *pn, *colist; + int i, k, m, n = 0, c = 0; + bool rk, b = false; + PCOLRES crp, rcrp, *pcrp; + + if (!col || !*col) { + strcpy(g->Message, "Missing colist"); + return true; + } // endif col + + // Prepare the column list + colist = (char*)PlugSubAlloc(g, NULL, strlen(col) + 1); + strcpy(colist, col); + m = PrepareColist(colist); + + if ((rk = (rank && *rank))) + for (k = 0, pn = colist; k < m; k++, pn += (strlen(pn) + 1)) + n = max(n, (signed)strlen(pn)); + + // Default occur column name is the 1st colist column name + if (!ocr || !*ocr) + ocr = colist; + + /**********************************************************************/ + /* Replace the columns of the colist by the rank and occur columns. */ + /**********************************************************************/ + for (i = 0, pcrp = &qrp->Colresp; crp = *pcrp; ) { + for (k = 0, pn = colist; k < m; k++, pn += (strlen(pn) + 1)) + if (!stricmp(pn, crp->Name)) + break; + + if (k < m) { + // This column belongs to colist + c++; + + if (!b) { + if (rk) { + // Add the rank column here + rcrp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); + memset(rcrp, 0, sizeof(COLRES)); + rcrp->Next = crp; + rcrp->Name = (char*)rank; + rcrp->Type = TYPE_STRING; + rcrp->Length = n; + rcrp->Ncol = ++i; + *pcrp = rcrp; + } // endif rk + + // First remaining listed column, will be the occur column + crp->Name = (char*)ocr; + b = true; + } else { + *pcrp = crp->Next; // Remove this column + continue; + } // endif b + + } // endif k + + crp->Ncol = ++i; + pcrp = &crp->Next; + } // endfor pcrp + + // Check whether all columns of the list where found + if (c < m) { + strcpy(g->Message, "Some colist columns are not in the source table"); + return true; + } // endif crp + + /**********************************************************************/ + /* Set the number of columns of the table. */ + /**********************************************************************/ + qrp->Nblin = i; + return false; + } // end of OcrSrcCols + +/* -------------- Implementation of the OCCUR classes ---------------- */ + +/***********************************************************************/ +/* DefineAM: define specific AM block values from OCCUR table. */ +/***********************************************************************/ +bool OCCURDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) + { + Rcol = Cat->GetStringCatInfo(g, "RankCol", ""); + Colist = Cat->GetStringCatInfo(g, "Colist", ""); + Xcol = Cat->GetStringCatInfo(g, "OccurCol", Colist); + return PRXDEF::DefineAM(g, am, poff); + } // end of DefineAM + +/***********************************************************************/ +/* GetTable: makes a new TDB of the proper type. */ +/***********************************************************************/ +PTDB OCCURDEF::GetTable(PGLOBAL g, MODE m) + { + if (Catfunc != FNC_COL) + return new(g) TDBOCCUR(this); + else + return new(g) TDBTBC(this); + + } // end of GetTable + +/* ------------------------------------------------------------------- */ + +/***********************************************************************/ +/* Implementation of the TDBOCCUR class. */ +/***********************************************************************/ +TDBOCCUR::TDBOCCUR(POCCURDEF tdp) : TDBPRX(tdp) + { +//Tdbp = NULL; // Source table (in TDBPRX) + Tabname = tdp->Tablep->GetName(); // Name of source table + Colist = tdp->Colist; // List of source columns + Xcolumn = tdp->Xcol; // Occur column name + Rcolumn = tdp->Rcol; // Rank column name + Xcolp = NULL; // To the OCCURCOL column + Col = NULL; // To source column blocks array + Mult = PrepareColist(Colist); // Multiplication factor + N = 0; // The current table index + M = 0; // The occurence rank + RowFlag = 0; // 0: Ok, 1: Same, 2: Skip + } // end of TDBOCCUR constructor + +/***********************************************************************/ +/* Allocate OCCUR/SRC column description block. */ +/***********************************************************************/ +PCOL TDBOCCUR::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) + { + PCOL colp = NULL; + + if (!stricmp(cdp->GetName(), Rcolumn)) { + // Allocate a RANK column + colp = new(g) RANKCOL(cdp, this, n); + } else if (!stricmp(cdp->GetName(), Xcolumn)) { + // Allocate the OCCUR column + colp = Xcolp = new(g) OCCURCOL(cdp, this, n); + } else + return new(g) PRXCOL(cdp, this, cprec, n); + + if (cprec) { + colp->SetNext(cprec->GetNext()); + cprec->SetNext(colp); + } else { + colp->SetNext(Columns); + Columns = colp; + } // endif cprec + + return colp; + } // end of MakeCol + +/***********************************************************************/ +/* Initializes the table. */ +/***********************************************************************/ +bool TDBOCCUR::InitTable(PGLOBAL g) + { + if (!Tdbp) + // Get the table description block of this table + if (!(Tdbp = GetSubTable(g, ((POCCURDEF)To_Def)->Tablep, TRUE))) + return TRUE; + + if (!Tdbp->IsView()) + if (MakeColumnList(g)) + return TRUE; + + return FALSE; + } // end of InitTable + +/***********************************************************************/ +/* Allocate OCCUR column description block. */ +/***********************************************************************/ +bool TDBOCCUR::MakeColumnList(PGLOBAL g) + { + char *pn; + int i; + PCOL colp; + + for (colp = Columns; colp; colp = colp->GetNext()) + if (colp->GetAmType() == TYPE_AM_PRX) + if (((PPRXCOL)colp)->Init(g)) + return true; + + Col = (PCOL*)PlugSubAlloc(g, NULL, Mult * sizeof(PCOL)); + + for (i = 0, pn = Colist; i < Mult; i++, pn += (strlen(pn) + 1)) { + if (!(Col[i] = Tdbp->ColDB(g, pn, 0))) { + // Column not found in table + sprintf(g->Message, MSG(COL_ISNOT_TABLE), pn, Tabname); + return true; + } // endif Col + + if (Col[i]->InitValue(g)) { + strcpy(g->Message, "OCCUR InitValue failed"); + return true; + } // endif InitValue + + } // endfor i + + return false; + } // end of MakeColumnList + +/***********************************************************************/ +/* Allocate OCCUR column description block for a view. */ +/***********************************************************************/ +bool TDBOCCUR::ViewColumnList(PGLOBAL g) + { + char *pn; + int i; + PCOL colp, cp; + PTDBMY tdbp; + + if (!Tdbp->IsView()) + return false; + + if (Tdbp->GetAmType() != TYPE_AM_MYSQL) { + strcpy(g->Message, "View is not MySQL"); + return true; + } else + tdbp = (PTDBMY)Tdbp; + + for (cp = Columns; cp; cp = cp->GetNext()) + if (cp->GetAmType() == TYPE_AM_PRX) { + if ((colp = tdbp->MakeFieldColumn(g, cp->GetName()))) { + ((PPRXCOL)cp)->Colp = colp; + ((PPRXCOL)cp)->To_Val = colp->GetValue(); + } else + return true; + + } // endif Type + + Col = (PCOL*)PlugSubAlloc(g, NULL, Mult * sizeof(PCOL)); + + for (i = 0, pn = Colist; i < Mult; i++, pn += (strlen(pn) + 1)) + if (!(Col[i] = tdbp->MakeFieldColumn(g, pn))) { + // Column not found in table + sprintf(g->Message, MSG(COL_ISNOT_TABLE), pn, Tabname); + return true; + } // endif Col + + return false; + } // end of ViewColumnList + +/***********************************************************************/ +/* OCCUR GetMaxSize: returns the maximum number of rows in the table. */ +/***********************************************************************/ +int TDBOCCUR::GetMaxSize(PGLOBAL g) + { + if (MaxSize < 0) { + if (!(Tdbp = GetSubTable(g, ((POCCURDEF)To_Def)->Tablep, TRUE))) + return 0; + + MaxSize = Mult * Tdbp->GetMaxSize(g); + } // endif MaxSize + + return MaxSize; + } // end of GetMaxSize + +/***********************************************************************/ +/* In this sample, ROWID will be the (virtual) row number, */ +/* while ROWNUM will be the occurence rank in the multiple column. */ +/***********************************************************************/ +int TDBOCCUR::RowNumber(PGLOBAL g, bool b) + { + return (b) ? M : N; + } // end of RowNumber + +/***********************************************************************/ +/* OCCUR Access Method opening routine. */ +/***********************************************************************/ +bool TDBOCCUR::OpenDB(PGLOBAL g) + { + if (Use == USE_OPEN) { + /*******************************************************************/ + /* Table already open, just replace it at its beginning. */ + /*******************************************************************/ + N = M = 0; + RowFlag = 0; + + if (Xcolp) + Xcolp->Xreset(); + + return Tdbp->OpenDB(g); + } // endif use + + + if (Mode != MODE_READ) { + /*******************************************************************/ + /* Currently OCCUR tables cannot be modified. */ + /*******************************************************************/ + strcpy(g->Message, "OCCUR tables are read only"); + return TRUE; + } // endif Mode + + /*********************************************************************/ + /* Do it here if not done yet. */ + /*********************************************************************/ + if (InitTable(g)) + return TRUE; + + if (Xcolp) + // Lock this column so it is evaluated by its table only + Xcolp->AddStatus(BUF_READ); + + if (To_Key_Col || To_Kindex) { + /*******************************************************************/ + /* Direct access of OCCUR tables is not implemented yet. */ + /*******************************************************************/ + strcpy(g->Message, "No direct access to OCCUR tables"); + return TRUE; + } // endif To_Key_Col + + /*********************************************************************/ + /* Do open the source table. */ + /*********************************************************************/ + if (Tdbp->OpenDB(g)) + return TRUE; + + return ViewColumnList(g); + } // end of OpenDB + +/***********************************************************************/ +/* Data Base read routine for OCCUR access method. */ +/***********************************************************************/ +int TDBOCCUR::ReadDB(PGLOBAL g) + { + int rc = RC_OK; + + /*********************************************************************/ + /* Now start the multi reading process. */ + /*********************************************************************/ + do { + if (RowFlag != 1) + if ((rc = Tdbp->ReadDB(g)) != RC_OK) + break; + + if (Xcolp) { + RowFlag = 0; + Xcolp->ReadColumn(g); + M = Xcolp->GetI(); + } // endif Xcolp + + } while (RowFlag == 2); + + N++; + return rc; + } // end of ReadDB + +// ------------------------ OCCURCOL functions ---------------------------- + +/***********************************************************************/ +/* OCCURCOL public constructor. */ +/***********************************************************************/ +OCCURCOL::OCCURCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n) + : COLBLK(cdp, tdbp, n) + { + // Set additional OCCUR access method information for column. + I = 0; + } // end of OCCURCOL constructor + +/***********************************************************************/ +/* ReadColumn: what this routine does is to access the columns of */ +/* list, extract their value and convert it to buffer type. */ +/***********************************************************************/ +void OCCURCOL::ReadColumn(PGLOBAL g) + { + PTDBOCCUR tdbp = (PTDBOCCUR)To_Tdb; + PCOL *col = tdbp->Col; + + for (; I < tdbp->Mult; I++) { + col[I]->ReadColumn(g); + + if (Nullable || !col[I]->GetValue()->IsZero()) + break; + + } // endfor I + + if (I == tdbp->Mult) { + // No more values, go to next source row + tdbp->RowFlag = 2; + I = 0; + return; + } // endif I + + // Set the OCCUR column value from the Ith source column value + Value->SetValue_pval(col[I++]->GetValue()); + tdbp->RowFlag = 1; + } // end of ReadColumn + + +// ------------------------ RANKCOL functions --------------------------- + +/***********************************************************************/ +/* ReadColumn: what this routine does is to access the Mth columns of */ +/* list, extract its name and set to it the rank column value. */ +/***********************************************************************/ +void RANKCOL::ReadColumn(PGLOBAL g) + { + PTDBOCCUR tdbp = (PTDBOCCUR)To_Tdb; + PCOL *col = tdbp->Col; + + // Set the RANK column value from the Mth source column name + if (tdbp->M) + Value->SetValue_psz(col[tdbp->M - 1]->GetName()); + else { + Value->Reset(); + + if (Nullable) + Value->SetNull(true); + + } // endelse + + } // end of ReadColumn diff --git a/storage/connect/taboccur.h b/storage/connect/taboccur.h new file mode 100644 index 00000000000..6cfece5634e --- /dev/null +++ b/storage/connect/taboccur.h @@ -0,0 +1,145 @@ +// TABOCCUR.H Olivier Bertrand 2013 +// Defines the OCCUR tables + +#include "tabutil.h" + +#define TYPE_AM_OCCUR (AMT)128 + +typedef class OCCURDEF *POCCURDEF; +typedef class TDBOCCUR *PTDBOCCUR; +typedef class OCCURCOL *POCCURCOL; +typedef class RANKCOL *PRANKCOL; + +/* -------------------------- OCCUR classes -------------------------- */ + +/***********************************************************************/ +/* OCCUR: Table that provides a view of a source table where the */ +/* contain of several columns of the source table is placed in only */ +/* one column, the OCCUR column, this resulting into several rows. */ +/***********************************************************************/ + +/***********************************************************************/ +/* OCCUR table. */ +/***********************************************************************/ +class OCCURDEF : public PRXDEF { /* Logical table description */ + friend class TDBOCCUR; + public: + // Constructor + OCCURDEF(void) {Pseudo = 3; Colist = Xcol = NULL;} + + // Implementation + virtual const char *GetType(void) {return "OCCUR";} + + // Methods + virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); + virtual PTDB GetTable(PGLOBAL g, MODE m); + + protected: + // Members + char *Colist; /* The source column list */ + char *Xcol; /* The multiple occurence column */ + char *Rcol; /* The rank column */ + }; // end of OCCURDEF + +/***********************************************************************/ +/* This is the class declaration for the OCCUR table. */ +/***********************************************************************/ +class TDBOCCUR : public TDBPRX { + friend class OCCURCOL; + friend class RANKCOL; + public: + // Constructor + TDBOCCUR(POCCURDEF tdp); + + // Implementation + virtual AMT GetAmType(void) {return TYPE_AM_OCCUR;} + void SetTdbp(PTDBASE tdbp) {Tdbp = tdbp;} + + // Methods + virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} + virtual int RowNumber(PGLOBAL g, bool b = FALSE); + bool MakeColumnList(PGLOBAL g); + bool ViewColumnList(PGLOBAL g); + + // Database routines + virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); + virtual bool InitTable(PGLOBAL g); + virtual int GetMaxSize(PGLOBAL g); + virtual bool OpenDB(PGLOBAL g); + virtual int ReadDB(PGLOBAL g); + + protected: + // Members +//PTDBASE Tdbp; // To the source table or view + LPCSTR Tabname; // Name of source table + char *Colist; // Source column list + char *Xcolumn; // Occurence column name + char *Rcolumn; // Rank column name + POCCURCOL Xcolp; // To the OCCURCOL column + PCOL *Col; // To source multiple columns + int Mult; // Multiplication factor + int N; // The current table index + int M; // The occurence rank + BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip + }; // end of class TDBOCCUR + +/***********************************************************************/ +/* Class OCCURCOL: for the multiple occurence column. */ +/***********************************************************************/ +class OCCURCOL : public COLBLK { + public: + // Constructors + OCCURCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n); + + // Implementation + virtual int GetAmType(void) {return TYPE_AM_OCCUR;} + int GetI(void) {return I;} + + // Methods + virtual void Reset(void) {} // Evaluated only by TDBOCCUR + virtual void ReadColumn(PGLOBAL g); + void Xreset(void) {I = 0;}; + + protected: + // Default constructor not to be used + OCCURCOL(void) {} + + // Members + int I; + }; // end of class OCCURCOL + +/***********************************************************************/ +/* Class RANKCOL: for the multiple occurence column ranking. */ +/***********************************************************************/ +class RANKCOL : public COLBLK { + public: + // Constructors + RANKCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n) : COLBLK(cdp, tdbp, n) {} + + // Implementation + virtual int GetAmType(void) {return TYPE_AM_OCCUR;} + + // Methods + virtual void ReadColumn(PGLOBAL g); + + protected: + // Default constructor not to be used + RANKCOL(void) {} + + // Members + }; // end of class RANKCOL + +/***********************************************************************/ +/* Definition of class XCOLDEF. */ +/* This class purpose is just to access COLDEF protected items! */ +/***********************************************************************/ +class XCOLDEF: public COLDEF { + friend class TDBOCCUR; + }; // end of class XCOLDEF + + +bool OcrColumns(PGLOBAL g, PQRYRES qrp, const char *col, + const char *ocr, const char *rank); + +bool OcrSrcCols(PGLOBAL g, PQRYRES qrp, const char *col, + const char *ocr, const char *rank); diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index 5bbc9effa92..ae6817344b8 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -75,7 +75,6 @@ #include "sql_string.h" -extern "C" char *GetMsgid(int id); extern "C" int trace; /***********************************************************************/ @@ -325,7 +324,7 @@ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) { char *colist, *tabname, *sql, buf[64]; LPCSTR ownp = NULL, qualp = NULL; - int rc, len, ncol = 0; + int len, ncol = 0; bool first = true; PTABLE tablep = To_Table; PCOL colp; @@ -342,7 +341,7 @@ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) for (colp = Columns; colp; colp = colp->GetNext()) if (!colp->IsSpecial()) { // Column name can be in UTF-8 encoding - rc= Decode(colp->GetName(), buf, sizeof(buf)); + /*rc=*/ Decode(colp->GetName(), buf, sizeof(buf)); if (Quote) { if (first) { @@ -377,7 +376,7 @@ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) } // endif cnt // Table name can be encoded in UTF-8 - rc = Decode(TableName, buf, sizeof(buf)); + /*rc = */Decode(TableName, buf, sizeof(buf)); // Put table name between identifier quotes in case in contains blanks tabname = (char*)PlugSubAlloc(g, NULL, strlen(buf) + 3); @@ -896,7 +895,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g) Value->SetValue_pval(To_Val, false); // Convert the inserted value if (Buf_Type == TYPE_DATE) { - struct tm *dbtime = ((DTVAL*)Value)->GetGmTime(); + struct tm tm, *dbtime = ((DTVAL*)Value)->GetGmTime(&tm); Sqlbuf->second = dbtime->tm_sec; Sqlbuf->minute = dbtime->tm_min; diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp index fccd8338d8a..9beca56e773 100644 --- a/storage/connect/tabpivot.cpp +++ b/storage/connect/tabpivot.cpp @@ -1,11 +1,11 @@ /************ TabPivot C++ Program Source Code File (.CPP) *************/ /* PROGRAM NAME: TABPIVOT */ /* ------------- */ -/* Version 1.3 */ +/* Version 1.6 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */ +/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -41,10 +41,11 @@ #include "global.h" #include "plgdbsem.h" #include "xtable.h" -#include "xindex.h" +#include "tabcol.h" #include "colblk.h" #include "tabmysql.h" #include "csort.h" +#include "tabutil.h" #include "tabpivot.h" #include "valblk.h" #include "ha_connect.h" @@ -52,8 +53,195 @@ extern "C" int trace; +/***********************************************************************/ +/* Make the Pivot table column list. */ +/***********************************************************************/ +PQRYRES PivotColumns(PGLOBAL g, const char *tab, const char *src, + const char *picol, const char *fncol, + const char *host, const char *db, + const char *user, const char *pwd, + int port) + { + PIVAID pvd(tab, src, picol, fncol, host, db, user, pwd, port); + + return pvd.MakePivotColumns(g); + } // end of PivotColumns + +/* --------------- Implementation of the PIVAID classe --------------- */ + +/***********************************************************************/ +/* PIVAID constructor. */ +/***********************************************************************/ +PIVAID::PIVAID(const char *tab, const char *src, const char *picol, + const char *fncol, const char *host, const char *db, + const char *user, const char *pwd, int port) + : CSORT(false) + { + Host = (char*)host; + User = (char*)user; + Pwd = (char*)pwd; + Qryp = NULL; + Database = (char*)db; + Tabname = (char*)tab; + Tabsrc = (char*)src; + Picol = (char*)picol; + Fncol = (char*)fncol; + Rblkp = NULL; + Port = (port) ? port : GetDefaultPort(); + } // end of PIVAID constructor + +/***********************************************************************/ +/* Make the Pivot table column list. */ +/***********************************************************************/ +PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) + { + char *query, *colname, buf[32]; + int ndif, nblin, w = 0; + PVAL valp; + PCOLRES *pcrp, crp, fncrp = NULL; + + if (!Tabsrc && Tabname) { + // Locate the query + query = (char*)PlugSubAlloc(g, NULL, strlen(Tabname) + 16); + sprintf(query, "SELECT * FROM %s", Tabname); + } else if (!Tabsrc) { + strcpy(g->Message, MSG(SRC_TABLE_UNDEF)); + return NULL; + } else + query = Tabsrc; + + // Open a MySQL connection for this table + if (Myc.Open(g, Host, Database, User, Pwd, Port)) + return NULL; + + // Send the source command to MySQL + if (Myc.ExecSQL(g, query, &w) == RC_FX) { + Myc.Close(); + return NULL; + } // endif Exec + + // We must have a storage query to get pivot column values + Qryp = Myc.GetResult(g); + Myc.Close(); + + if (!Fncol) { + for (crp = Qryp->Colresp; crp; crp = crp->Next) + if (!Picol || stricmp(Picol, crp->Name)) + Fncol = crp->Name; + + if (!Fncol) { + strcpy(g->Message, MSG(NO_DEF_FNCCOL)); + return NULL; + } // endif Fncol + + } // endif Fncol + + if (!Picol) { + // Find default Picol as the last one not equal to Fncol + for (crp = Qryp->Colresp; crp; crp = crp->Next) + if (stricmp(Fncol, crp->Name)) + Picol = crp->Name; + + if (!Picol) { + strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); + return NULL; + } // endif Picol + + } // endif picol + + // Prepare the column list + for (pcrp = &Qryp->Colresp; crp = *pcrp; ) + if (!stricmp(Picol, crp->Name)) { + Rblkp = crp->Kdata; + *pcrp = crp->Next; + } else if (!stricmp(Fncol, crp->Name)) { + fncrp = crp; + *pcrp = crp->Next; + } else + pcrp = &crp->Next; + + if (!Rblkp) { + strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); + return NULL; + } else if (!fncrp) { + strcpy(g->Message, MSG(NO_DEF_FNCCOL)); + return NULL; + } // endif + + // Before calling sort, initialize all + nblin = Qryp->Nblin; + + Index.Size = nblin * sizeof(int); + Index.Sub = TRUE; // Should be small enough + + if (!PlgDBalloc(g, NULL, Index)) + return NULL; + + Offset.Size = (nblin + 1) * sizeof(int); + Offset.Sub = TRUE; // Should be small enough + + if (!PlgDBalloc(g, NULL, Offset)) + return NULL; + + ndif = Qsort(g, nblin); + + if (ndif < 0) // error + return NULL; + + // Allocate the Value used to retieve column names + if (!(valp = AllocateValue(g, Rblkp->GetType(), + Rblkp->GetVlen(), + Rblkp->GetPrec()))) + return NULL; + + // Now make the functional columns + for (int i = 0; i < ndif; i++) { + if (i) { + crp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); + memcpy(crp, fncrp, sizeof(COLRES)); + } else + crp = fncrp; + + // Get the value that will be the generated column name + valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]); + colname = valp->GetCharString(buf); + crp->Name = (char*)PlugSubAlloc(g, NULL, strlen(colname) + 1); + strcpy(crp->Name, colname); + crp->Flag = 1; + + // Add this column + *pcrp = crp; + crp->Next = NULL; + pcrp = &crp->Next; + } // endfor i + + // We added ndif columns and removed 2 (picol and fncol) + Qryp->Nbcol += (ndif - 2); + return Qryp; + } // end of MakePivotColumns + +/***********************************************************************/ +/* PIVAID: Compare routine for sorting pivot column values. */ +/***********************************************************************/ +int PIVAID::Qcompare(int *i1, int *i2) + { + // TODO: the actual comparison between pivot column result values. + return Rblkp->CompVal(*i1, *i2); + } // end of Qcompare + /* --------------- Implementation of the PIVOT classes --------------- */ +/***********************************************************************/ +/* PIVOTDEF constructor. */ +/***********************************************************************/ + PIVOTDEF::PIVOTDEF(void) + { + Host = User = Pwd = DB = NULL; + Tabname = Tabsrc = Picol = Fncol = Function = NULL; + GBdone = Accept = false; + Port = 0; + } // end of PIVOTDEF constructor + /***********************************************************************/ /* DefineAM: define specific AM block values from PIVOT table. */ /***********************************************************************/ @@ -62,14 +250,18 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) char *p1, *p2; PHC hc = ((MYCAT*)Cat)->GetHandler(); - Host = Cat->GetStringCatInfo(g, Name, "Host", "localhost"); - User = Cat->GetStringCatInfo(g, Name, "User", "root"); - Pwd = Cat->GetStringCatInfo(g, Name, "Password", NULL); - DB = Cat->GetStringCatInfo(g, Name, "Database", (PSZ)hc->GetDBName(NULL)); - Tabsrc = Cat->GetStringCatInfo(g, Name, "SrcDef", NULL); - Tabname = Cat->GetStringCatInfo(g, Name, "Name", NULL); - Picol = Cat->GetStringCatInfo(g, Name, "PivotCol", NULL); - Fncol = Cat->GetStringCatInfo(g, Name, "FncCol", NULL); + if (PRXDEF::DefineAM(g, am, poff)) + return TRUE; + + Tabname = (char*)Tablep->GetName(); + DB = (char*)Tablep->GetQualifier(); + Tabsrc = (char*)Tablep->GetSrc(); + + Host = Cat->GetStringCatInfo(g, "Host", "localhost"); + User = Cat->GetStringCatInfo(g, "User", "*"); + Pwd = Cat->GetStringCatInfo(g, "Password", NULL); + Picol = Cat->GetStringCatInfo(g, "PivotCol", NULL); + Fncol = Cat->GetStringCatInfo(g, "FncCol", NULL); // If fncol is like avg(colname), separate Fncol and Function if (Fncol && (p1 = strchr(Fncol, '(')) && (p2 = strchr(p1, ')')) && @@ -78,11 +270,12 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Function = Fncol; Fncol = p1; } else - Function = Cat->GetStringCatInfo(g, Name, "Function", "SUM"); + Function = Cat->GetStringCatInfo(g, "Function", "SUM"); - GBdone = Cat->GetIntCatInfo(Name, "Groupby", 0) ? TRUE : FALSE; - Port = Cat->GetIntCatInfo(Name, "Port", 3306); - Desc = (*Tabname) ? Tabname : Tabsrc; + GBdone = Cat->GetBoolCatInfo("Groupby", false); + Accept = Cat->GetBoolCatInfo("Accept", false); + Port = Cat->GetIntCatInfo("Port", 3306); + Desc = (Tabsrc) ? Tabsrc : Tabname; return FALSE; } // end of DefineAM @@ -99,15 +292,13 @@ PTDB PIVOTDEF::GetTable(PGLOBAL g, MODE m) /***********************************************************************/ /* Implementation of the TDBPIVOT class. */ /***********************************************************************/ -TDBPIVOT::TDBPIVOT(PPIVOTDEF tdp) : TDBASE(tdp), CSORT(FALSE) +TDBPIVOT::TDBPIVOT(PPIVOTDEF tdp) : TDBPRX(tdp) { - Tqrp = NULL; Host = tdp->Host; Database = tdp->DB; User = tdp->User; Pwd = tdp->Pwd; Port = tdp->Port; - Qryp = NULL; Tabname = tdp->Tabname; // Name of source table Tabsrc = tdp->Tabsrc; // SQL description of source table Picol = tdp->Picol; // Pivot column name @@ -117,7 +308,9 @@ TDBPIVOT::TDBPIVOT(PPIVOTDEF tdp) : TDBASE(tdp), CSORT(FALSE) //Xresp = NULL; // To the pivot result column //Rblkp = NULL; // The value block of the pivot column Fcolp = NULL; // To the function column + Dcolp = NULL; // To the dump column GBdone = tdp->GBdone; + Accept = tdp->Accept; Mult = -1; // Estimated table size N = 0; // The current table index M = 0; // The occurence rank @@ -125,439 +318,225 @@ TDBPIVOT::TDBPIVOT(PPIVOTDEF tdp) : TDBASE(tdp), CSORT(FALSE) RowFlag = 0; // 0: Ok, 1: Same, 2: Skip } // end of TDBPIVOT constructor -#if 0 -TDBPIVOT::TDBPIVOT(PTDBPIVOT tdbp) : TDBASE(tdbp), CSORT(FALSE) - { - Tdbp = tdbp->Tdbp; - Sqlp = tdbp->Sqlp; - Qryp = tdbp->Qryp; - Tabname = tdbp->Tabname; - Tabsrc = tdbp->Tabsrc; - Picol = tdbp->Picol; - Fncol = tdbp->Fncol; - Function = tdbp->Function; - Xcolp = tdbp->Xcolp; - Xresp = tdbp->Xresp; - Rblkp = tdbp->Rblkp; - Fcolp = tdbp->Fcolp; - Mult = tdbp->Mult; - N = tdbp->N; - M = tdbp->M; - FileStatus = tdbp->FileStatus; - RowFlag = tdbp->RowFlag; - } // end of TDBPIVOT copy constructor - -// Is this really useful ??? -PTDB TDBPIVOT::CopyOne(PTABS t) - { - PTDB tp = new(t->G) TDBPIVOT(this); - - tp->SetColumns(Columns); - return tp; - } // end of CopyOne -#endif // 0 - -/***********************************************************************/ -/* Prepare the source table Query. */ -/***********************************************************************/ -PQRYRES TDBPIVOT::GetSourceTable(PGLOBAL g) - { - if (Qryp) - return Qryp; // Already done - - if (!Tabsrc && Tabname) { - char *def, *colist; - size_t len = 0; - PCOL colp; - PDBUSER dup = (PDBUSER)g->Activityp->Aptr; - - // Evaluate the length of the column list - for (colp = Columns; colp; colp = colp->GetNext()) - len += (strlen(colp->GetName()) + 2); - - *(colist = (char*)PlugSubAlloc(g, NULL, len)) = 0; - - // Locate the suballocated string (size is not known yet) - def = (char*)PlugSubAlloc(g, NULL, 0); - strcpy(def, "SELECT "); - - if (!Fncol) { - for (colp = Columns; colp; colp = colp->GetNext()) - if (!Picol || stricmp(Picol, colp->GetName())) - Fncol = colp->GetName(); - - if (!Fncol) { - strcpy(g->Message, MSG(NO_DEF_FNCCOL)); - return NULL; - } // endif Fncol - - } else if (!(ColDB(g, Fncol, 0))) { - // Function column not found in table - sprintf(g->Message, MSG(COL_ISNOT_TABLE), Fncol, Tabname); - return NULL; - } // endif Fcolp - - if (!Picol) { - // Find default Picol as the last one not equal to Fncol - for (colp = Columns; colp; colp = colp->GetNext()) - if (!Fncol || stricmp(Fncol, colp->GetName())) - Picol = colp->GetName(); - - if (!Picol) { - strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); - return NULL; - } // endif Picol - - } else if (!(ColDB(g, Picol, 0))) { - // Pivot column not found in table - sprintf(g->Message, MSG(COL_ISNOT_TABLE), Picol, Tabname); - return NULL; - } // endif Xcolp - - // Make the other column list - for (colp = Columns; colp; colp = colp->GetNext()) - if (stricmp(Picol, colp->GetName()) && - stricmp(Fncol, colp->GetName())) - strcat(strcat(colist, colp->GetName()), ", "); - - // Add the Pivot column at the end of the list - strcat(strcat(def, strcat(colist, Picol)), ", "); - - // Continue making the definition - if (!GBdone) { - // Make it suitable for Pivot by doing the group by - strcat(strcat(def, Function), "("); - strcat(strcat(strcat(def, Fncol), ") "), Fncol); - strcat(strcat(def, " FROM "), Tabname); - strcat(strcat(def, " GROUP BY "), colist); - } else // Gbdone - strcat(strcat(strcat(def, Fncol), " FROM "), Tabname); - - // Now we know how much was suballocated - Tabsrc = (char*)PlugSubAlloc(g, NULL, strlen(def)); - } else { - strcpy(g->Message, MSG(SRC_TABLE_UNDEF)); - return NULL; - } // endif Tabsrc - - int w; - - // Open a MySQL connection for this table - if (Myc.Open(g, Host, Database, User, Pwd, Port)) - return NULL; - - // Send the source command to MySQL - if (Myc.ExecSQL(g, Tabsrc, &w) == RC_FX) { - Myc.Close(); - return NULL; - } // endif Exec - - // We must have a storage query to get pivot column values - Qryp = Myc.GetResult(g); - Myc.Close(); - Tqrp = new(g) TDBQRS(Qryp); - Tqrp->OpenDB(g); - - if (MakePivotColumns(g) < 0) - return NULL; - - return Qryp; - } // end of GetSourceTable - -/***********************************************************************/ -/* Allocate PIVOT columns description block. */ -/***********************************************************************/ -int TDBPIVOT::MakePivotColumns(PGLOBAL g) - { - if (Mult < 0) { - int ndif, n = 0, nblin = Qryp->Nblin; - PVAL valp; - PCOL cp; - PSRCCOL colp; - PFNCCOL cfnp; - - // Allocate all the source columns - Tqrp->ColDB(g, NULL, 0); - Columns = NULL; // Discard dummy columns blocks - - for (cp = Tqrp->GetColumns(); cp; cp = cp->GetNext()) { - if (cp->InitValue(g)) - return -1; - - if (!stricmp(cp->GetName(), Picol)) { - Xcolp = (PQRSCOL)cp; - Xresp = Xcolp->GetCrp(); - Rblkp = Xresp->Kdata; - } else if (!stricmp(cp->GetName(), Fncol)) { - Fcolp = (PQRSCOL)cp; - } else - if ((colp = new(g) SRCCOL(cp, this, ++n))->Init(g, this)) - return -1; - - } // endfor cp - - if (!Xcolp) { - sprintf(g->Message, MSG(COL_ISNOT_TABLE), - Picol, Tabname ? Tabname : "TabSrc"); - return -1; - } else if (!Fcolp) { - sprintf(g->Message, MSG(COL_ISNOT_TABLE), - Fncol, Tabname ? Tabname : "TabSrc"); - return -1; - } // endif Fcolp - - // Before calling sort, initialize all - Index.Size = nblin * sizeof(int); - Index.Sub = TRUE; // Should be small enough - - if (!PlgDBalloc(g, NULL, Index)) - return -1; - - Offset.Size = (nblin + 1) * sizeof(int); - Offset.Sub = TRUE; // Should be small enough - - if (!PlgDBalloc(g, NULL, Offset)) - return -2; - - ndif = Qsort(g, nblin); - - if (ndif < 0) { // error - return -3; - } else - Ncol = ndif; - - // Now make the functional columns - for (int i = 0; i < Ncol; i++) { - // Allocate the Value used to retieve column names - if (!(valp = AllocateValue(g, Xcolp->GetResultType(), - Xcolp->GetLengthEx(), Xcolp->GetPrecision(), - Xcolp->GetDomain(), Xcolp->GetTo_Tdb()->GetCat()))) - return -4; - - // Get the value that will be the generated column name - valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]); - - // Copy the functional column with new Name and new Value - cfnp = (PFNCCOL)new(g) FNCCOL(Fcolp, this); - - // Initialize the generated column - if (cfnp->InitColumn(g, valp)) - return -5; - - } // endfor i - - // Fields must be updated for ha_connect -// if (UpdateTableFields(g, n + Ncol)) -// return -6; - - // This should be refined later - Mult = nblin; - } // endif Mult - - return Mult; - } // end of MakePivotColumns - -#if 0 -/***********************************************************************/ -/* Update fields in the MySQL table structure */ -/* Note: this does not work. Indeed the new rows are correctly made */ -/* but the final result still specify the unmodified table and the */ -/* returned table only contains the original column values. */ -/* In addition, a new query on the table, when it is into the cache, */ -/* specifies all the new columns and fails because they do not belong */ -/* to the original table. */ -/***********************************************************************/ -bool TDBPIVOT::UpdateTableFields(PGLOBAL g, int n) - { - uchar *trec, *srec, *tptr, *sptr; - int i = 0, k = 0; - uint len; - uint32 nmp, lwm; - size_t buffsize; - PCOL colp; - PHC hc = ((MYCAT*)((PIVOTDEF*)To_Def)->Cat)->GetHandler(); - TABLE *table = hc->GetTable(); - st_mem_root *tmr = &table->mem_root; - st_mem_root *smr = &table->s->mem_root; - Field* *field; - Field *fp, *tfncp, *sfncp; - Field* *ntf; - Field* *nsf; -//my_bitmap_map *org_bitmap; - const MY_BITMAP *map; - - // When sorting read_set selects all columns, so we use def_read_set - map= (const MY_BITMAP *)&table->def_read_set; - - // Find the function field - for (field= table->field; *field; field++) { - fp= *field; - - if (bitmap_is_set(map, fp->field_index)) - if (!stricmp(fp->field_name, Fncol)) { - tfncp = fp; - break; - } // endif Name - - } // endfor field - - for (field= table->s->field; *field; field++) { - fp= *field; - - if (bitmap_is_set(map, fp->field_index)) - if (!stricmp(fp->field_name, Fncol)) { - sfncp = fp; - break; - } // endif Name - - } // endfor field - - // Calculate the new buffer size - len = tfncp->max_data_length(); - buffsize = table->s->rec_buff_length + len * Ncol; - - // Allocate the new record space - if (!(tptr = trec = (uchar*)alloc_root(tmr, 2 * buffsize))) - return TRUE; - - if (!(sptr = srec = (uchar*)alloc_root(smr, 2 * buffsize))) - return TRUE; - - - // Allocate the array of all new table field pointers - if (!(ntf = (Field**)alloc_root(tmr, (uint)((n+1) * sizeof(Field*))))) - return TRUE; - - // Allocate the array of all new table share field pointers - if (!(nsf = (Field**)alloc_root(smr, (uint)((n+1) * sizeof(Field*))))) - return TRUE; - - // First fields are the the ones of the source columns - for (colp = Columns; colp; colp = colp->GetNext()) - if (colp->GetAmType() == TYPE_AM_SRC) { - for (field= table->field; *field; field++) { - fp= *field; - - if (bitmap_is_set(map, fp->field_index)) - if (!stricmp(colp->GetName(), fp->field_name)) { - ntf[i] = fp; - fp->field_index = i++; - fp->ptr = tptr; - tptr += fp->max_data_length(); - break; - } // endif Name - - } // endfor field - - for (field= table->s->field; *field; field++) { - fp= *field; - - if (bitmap_is_set(map, fp->field_index)) - if (!stricmp(colp->GetName(), fp->field_name)) { - nsf[k] = fp; - fp->field_index = k++; - fp->ptr = srec; - srec += fp->max_data_length(); - break; - } // endif Name - - } // endfor field - - } // endif AmType - - // Now add the pivot generated columns - for (colp = Columns; colp; colp = colp->GetNext()) - if (colp->GetAmType() == TYPE_AM_FNC) { - if ((fp = (Field*)memdup_root(tmr, (char*)tfncp, tfncp->size_of()))) { - ntf[i] = fp; - fp->ptr = tptr; - fp->field_name = colp->GetName(); - fp->field_index = i++; - fp->vcol_info = NULL; - fp->stored_in_db = TRUE; - tptr += len; - } else - return TRUE; - - if ((fp = (Field*)memdup_root(smr, (char*)sfncp, sfncp->size_of()))) { - nsf[i] = fp; - fp->ptr = sptr; - fp->field_name = colp->GetName(); - fp->field_index = k++; - fp->vcol_info = NULL; - fp->stored_in_db = TRUE; - sptr += len; - } else - return TRUE; - - } // endif AM_FNC - - // Mark end of the list - ntf[i] = NULL; - nsf[k] = NULL; - - // Update the table fields - nmp = (uint32)((1<field = ntf; - table->used_fields = i; - table->record[0] = trec; - table->record[1] = trec + buffsize; - *table->def_read_set.bitmap = nmp; - *table->def_read_set.last_word_ptr = nmp; - table->def_read_set.last_word_mask = lwm; - table->def_read_set.n_bits = i; - *table->read_set->bitmap = nmp; - *table->read_set->last_word_ptr = nmp; - table->read_set->last_word_mask = lwm; - table->read_set->n_bits = i; - table->write_set->n_bits = i; - *table->vcol_set->bitmap = 0; - table->vcol_set->n_bits = i; - - // and the share fields - table->s->field = nsf; - table->s->reclength = sptr - srec; - table->s->stored_rec_length = sptr - srec; - table->s->fields = k; - table->s->stored_fields = k; - table->s->rec_buff_length = buffsize; -//table->s->varchar_fields = ???; -//table->s->db_record_offset = ???; -//table->s->null_field_first = ???; - return FALSE; - } // end of UpdateTableFields -#endif // 0 - /***********************************************************************/ /* Allocate source column description block. */ /***********************************************************************/ PCOL TDBPIVOT::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) { - PCOL colp = NULL; + PCOL colp; -//if (stricmp(cdp->GetName(), Picol) && stricmp(cdp->GetName(), Fncol)) { - colp = new(g) COLBLK(cdp, this, n); + if (cdp->GetOffset()) { + colp = new(g) FNCCOL(cdp, this, cprec, n); -// if (((PSRCCOL)colp)->Init(g, this)) -// return NULL; + if (cdp->GetOffset() > 1) + Dcolp = colp; -//} else { -// sprintf(g->Message, MSG(NO_MORE_COL), cdp->GetName()); -// return NULL; -//} // endif Name - - if (cprec) { - colp->SetNext(cprec->GetNext()); - cprec->SetNext(colp); - } else { - colp->SetNext(Columns); - Columns = colp; - } // endif cprec + } else + colp = new(g) SRCCOL(cdp, this, cprec, n); return colp; } // end of MakeCol +/***********************************************************************/ +/* Find default fonction and pivot columns. */ +/***********************************************************************/ +bool TDBPIVOT::FindDefaultColumns(PGLOBAL g) + { + PCOLDEF cdp; + PTABDEF defp = Tdbp->GetDef(); + + if (!Fncol) { + for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext()) + if (!Picol || stricmp(Picol, cdp->GetName())) + Fncol = cdp->GetName(); + + if (!Fncol) { + strcpy(g->Message, MSG(NO_DEF_FNCCOL)); + return true; + } // endif Fncol + + } // endif Fncol + + if (!Picol) { + // Find default Picol as the last one not equal to Fncol + for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext()) + if (stricmp(Fncol, cdp->GetName())) + Picol = cdp->GetName(); + + if (!Picol) { + strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); + return true; + } // endif Picol + + } // endif Picol + + return false; + } // end of FindDefaultColumns + +/***********************************************************************/ +/* Prepare the source table Query. */ +/***********************************************************************/ +bool TDBPIVOT::GetSourceTable(PGLOBAL g) + { + if (Tdbp) + return false; // Already done + + if (!Tabsrc && Tabname) { + // Get the table description block of this table + if (!(Tdbp = GetSubTable(g, ((PPIVOTDEF)To_Def)->Tablep, true))) + return true; + + if (!GBdone) { + char *colist; + PCOLDEF cdp; + + if (FindDefaultColumns(g)) + return true; + + // Locate the suballocated colist (size is not known yet) + *(colist = (char*)PlugSubAlloc(g, NULL, 0)) = 0; + + // Make the column list + for (cdp = To_Def->GetCols(); cdp; cdp = cdp->GetNext()) + if (!cdp->GetOffset()) + strcat(strcat(colist, cdp->GetName()), ", "); + + // Add the Pivot column at the end of the list + strcat(colist, Picol); + + // Now we know how much was suballocated + PlugSubAlloc(g, NULL, strlen(colist)); + + // Locate the source string (size is not known yet) + Tabsrc = (char*)PlugSubAlloc(g, NULL, 0); + + // Start making the definition + strcat(strcat(strcpy(Tabsrc, "SELECT "), colist), ", "); + + // Make it suitable for Pivot by doing the group by + strcat(strcat(Tabsrc, Function), "("); + strcat(strcat(strcat(Tabsrc, Fncol), ") "), Fncol); + strcat(strcat(Tabsrc, " FROM "), Tabname); + strcat(strcat(Tabsrc, " GROUP BY "), colist); + + if (Tdbp->IsView()) // Until MariaDB bug is fixed + strcat(strcat(Tabsrc, " ORDER BY "), colist); + + // Now we know how much was suballocated + PlugSubAlloc(g, NULL, strlen(Tabsrc)); + } // endif !GBdone + + } else if (!Tabsrc) { + strcpy(g->Message, MSG(SRC_TABLE_UNDEF)); + return true; + } // endif + + if (Tabsrc) { + // Get the new table description block of this source table + PTABLE tablep = new(g) XTAB("whatever", Tabsrc); + + tablep->SetQualifier(Database); + + if (!(Tdbp = GetSubTable(g, tablep, true))) + return true; + + } // endif Tabsrc + + return false; + } // end of GetSourceTable + +/***********************************************************************/ +/* Make the required pivot columns. */ +/***********************************************************************/ +bool TDBPIVOT::MakePivotColumns(PGLOBAL g) + { + if (!Tdbp->IsView()) { + // This was not done yet if GBdone is true + if (FindDefaultColumns(g)) + return true; + + // Now it is time to allocate the pivot and function columns + if (!(Fcolp = Tdbp->ColDB(g, Fncol, 0))) { + // Function column not found in table + sprintf(g->Message, MSG(COL_ISNOT_TABLE), Fncol, Tabname); + return true; + } else if (Fcolp->InitValue(g)) + return true; + + if (!(Xcolp = Tdbp->ColDB(g, Picol, 0))) { + // Pivot column not found in table + sprintf(g->Message, MSG(COL_ISNOT_TABLE), Picol, Tabname); + return true; + } else if (Xcolp->InitValue(g)) + return true; + + // Check and initialize the subtable columns + for (PCOL cp = Columns; cp; cp = cp->GetNext()) + if (cp->GetAmType() == TYPE_AM_SRC) { + if (((PSRCCOL)cp)->Init(g)) + return TRUE; + + } else if (cp->GetAmType() == TYPE_AM_FNC) + if (((PFNCCOL)cp)->InitColumn(g)) + return TRUE; + + } // endif isview + + return false; + } // end of MakePivotColumns + +/***********************************************************************/ +/* Make the required pivot columns for an object view. */ +/***********************************************************************/ +bool TDBPIVOT::MakeViewColumns(PGLOBAL g) + { + if (Tdbp->IsView()) { + // Tdbp is a view ColDB cannot be used + PCOL colp, cp; + PTDBMY tdbp; + + if (Tdbp->GetAmType() != TYPE_AM_MYSQL) { + strcpy(g->Message, "View is not MySQL"); + return true; + } else + tdbp = (PTDBMY)Tdbp; + + if (!Fncol && !(Fncol = tdbp->FindFieldColumn(Picol))) { + strcpy(g->Message, MSG(NO_DEF_FNCCOL)); + return true; + } // endif Fncol + + if (!Picol && !(Picol = tdbp->FindFieldColumn(Fncol))) { + strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); + return true; + } // endif Picol + + // Now it is time to allocate the pivot and function columns + if (!(Fcolp = tdbp->MakeFieldColumn(g, Fncol))) + return true; + + if (!(Xcolp = tdbp->MakeFieldColumn(g, Picol))) + return true; + + // Check and initialize the subtable columns + for (cp = Columns; cp; cp = cp->GetNext()) + if (cp->GetAmType() == TYPE_AM_SRC) { + if ((colp = tdbp->MakeFieldColumn(g, cp->GetName()))) { + ((PSRCCOL)cp)->Colp = colp; + ((PSRCCOL)cp)->To_Val = colp->GetValue(); + cp->AddStatus(BUF_READ); // All is done here + } else + return true; + + } else if (cp->GetAmType() == TYPE_AM_FNC) + if (((PFNCCOL)cp)->InitColumn(g)) + return TRUE; + + } // endif isview + + return false; + } // end of MakeViewColumns + /***********************************************************************/ /* PIVOT GetMaxSize: returns the maximum number of rows in the table. */ /***********************************************************************/ @@ -569,7 +548,7 @@ int TDBPIVOT::GetMaxSize(PGLOBAL g) return MaxSize; #endif // 0 - return 0; + return 10; } // end of GetMaxSize /***********************************************************************/ @@ -586,8 +565,6 @@ int TDBPIVOT::RowNumber(PGLOBAL g, bool b) /***********************************************************************/ bool TDBPIVOT::OpenDB(PGLOBAL g) { -//PDBUSER dup = (PDBUSER)g->Activityp->Aptr; - if (Use == USE_OPEN) { /*******************************************************************/ /* Table already open, just replace it at its beginning. */ @@ -598,13 +575,6 @@ bool TDBPIVOT::OpenDB(PGLOBAL g) return FALSE; } // endif use - /*********************************************************************/ - /* Do it here if not done yet (should not be the case). */ - /*********************************************************************/ -//if (MakePivotColumns(g) < 0) - if (!(Qryp = GetSourceTable(g))) - return TRUE; - if (Mode != MODE_READ) { /*******************************************************************/ /* Currently PIVOT tables cannot be modified. */ @@ -621,7 +591,26 @@ bool TDBPIVOT::OpenDB(PGLOBAL g) return TRUE; } // endif To_Key_Col - return FALSE; + /*********************************************************************/ + /* Do it here if not done yet (should not be the case). */ + /*********************************************************************/ + if (GetSourceTable(g)) + return TRUE; + + // For tables, columns must be allocated before opening + if (MakePivotColumns(g)) + return TRUE; + + /*********************************************************************/ + /* Physically open the object table. */ + /*********************************************************************/ + if (Tdbp->OpenDB(g)) + return TRUE; + + /*********************************************************************/ + /* Make all required pivot columns for object views. */ + /*********************************************************************/ + return MakeViewColumns(g); } // end of OpenDB /***********************************************************************/ @@ -632,7 +621,6 @@ int TDBPIVOT::ReadDB(PGLOBAL g) int rc = RC_OK; bool newrow = FALSE; PCOL colp; - PVAL vp1, vp2; if (FileStatus == 2) return RC_EF; @@ -652,7 +640,7 @@ int TDBPIVOT::ReadDB(PGLOBAL g) /*********************************************************************/ do { if (RowFlag != 1) { - if ((rc = Tqrp->ReadDB(g)) != RC_OK) { + if ((rc = Tdbp->ReadDB(g)) != RC_OK) { if (FileStatus && rc == RC_EF) { // A prepared row remains to be sent FileStatus = 2; @@ -662,14 +650,16 @@ int TDBPIVOT::ReadDB(PGLOBAL g) break; } // endif rc - for (colp = Tqrp->GetColumns(); colp; colp = colp->GetNext()) + for (colp = Tdbp->GetColumns(); colp; colp = colp->GetNext()) colp->ReadColumn(g); for (colp = Columns; colp; colp = colp->GetNext()) if (colp->GetAmType() == TYPE_AM_SRC) if (FileStatus) { - if (((PSRCCOL)colp)->CompareColumn()) + if (((PSRCCOL)colp)->CompareLast()) { newrow = (RowFlag) ? TRUE : FALSE; + break; + } // endif CompareLast } else ((PSRCCOL)colp)->SetColumn(); @@ -683,21 +673,21 @@ int TDBPIVOT::ReadDB(PGLOBAL g) } else RowFlag = 2; - vp1 = Xcolp->GetValue(); - // Look for the column having this header for (colp = Columns; colp; colp = colp->GetNext()) if (colp->GetAmType() == TYPE_AM_FNC) { - vp2 = ((PFNCCOL)colp)->Hval; - - if (!vp1->CompareValue(vp2)) + if (((PFNCCOL)colp)->CompareColumn()) break; } // endif AmType - if (!colp) { - strcpy(g->Message, MSG(NO_MATCH_COL)); - return RC_FX; + if (!colp && !(colp = Dcolp)) { + if (!Accept) { + strcpy(g->Message, MSG(NO_MATCH_COL)); + return RC_FX; + } else + continue; + } // endif colp // Set the value of the matching column from the fonction value @@ -731,410 +721,18 @@ int TDBPIVOT::DeleteDB(PGLOBAL g, int irc) /***********************************************************************/ void TDBPIVOT::CloseDB(PGLOBAL g) { -//Tdbp->CloseDB(g); - } // end of CloseDB + if (Tdbp) + Tdbp->CloseDB(g); -/***********************************************************************/ -/* TDBPIVOT: Compare routine for sorting pivot column values. */ -/***********************************************************************/ -int TDBPIVOT::Qcompare(int *i1, int *i2) - { - // TODO: the actual comparison between pivot column result values. - return Rblkp->CompVal(*i1, *i2); - } // end of Qcompare + } // end of CloseDB // ------------------------ FNCCOL functions ---------------------------- /***********************************************************************/ /* FNCCOL public constructor. */ /***********************************************************************/ -FNCCOL::FNCCOL(PCOL col1, PTDBPIVOT tdbp) - : COLBLK(col1, tdbp) - { - Value = NULL; // We'll get a new one later - Hval = NULL; // The unconverted header value - } // end of FNCCOL constructor - -/***********************************************************************/ -/* FNCCOL initialization function. */ -/***********************************************************************/ -bool FNCCOL::InitColumn(PGLOBAL g, PVAL valp) -{ - char *p, buf[128]; - int len; - - // Must have its own value block - if (InitValue(g)) - return TRUE; - - // Convert header value to a null terminated character string - Hval = valp; - p = Hval->GetCharString(buf); - len = strlen(p) + 1; - - if (len > (signed)sizeof(buf)) { - strcpy(g->Message, MSG(COLNAM_TOO_LONG)); - return TRUE; - } // endif buf - - // Set the name of the functional pivot column - Name = (PSZ)PlugSubAlloc(g, NULL, len); - strcpy(Name, p); - AddStatus(BUF_READ); // All is done here - return FALSE; -} // end of InitColumn - -// ------------------------ SRCCOL functions ---------------------------- - -#if 0 -/***********************************************************************/ -/* SRCCOL public constructor. */ -/***********************************************************************/ -SRCCOL::SRCCOL(PCOLDEF cdp, PTDBPIVOT tdbp, int n) - : COLBLK(cdp, tdbp, n) - { - // Set additional SRC access method information for column. - Colp = NULL; - Cnval = NULL; - } // end of SRCCOL constructor -#endif // 0 - -/***********************************************************************/ -/* SRCCOL public constructor. */ -/***********************************************************************/ -SRCCOL::SRCCOL(PCOL cp, PTDBPIVOT tdbp, int n) - : COLBLK(cp, tdbp) - { - Index = n; - - // Set additional SRC access method information for column. - Colp = (PQRSCOL)cp; - - // Don't share Value with the source column so we can compare - Cnval = Value = NULL; - } // end of SRCCOL constructor - -#if 0 -/***********************************************************************/ -/* SRCCOL constructor used for copying columns. */ -/* tdbp is the pointer to the new table descriptor. */ -/***********************************************************************/ -SRCCOL::SRCCOL(SRCCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) - { - Colp = col1->Colp; - } // end of SRCCOL copy constructor -#endif // 0 - -/***********************************************************************/ -/* Initialize the column as pointing to the source column. */ -/***********************************************************************/ -bool SRCCOL::Init(PGLOBAL g, PTDBPIVOT tdbp) - { - // Currently we ignore the type of the create table column - bool conv = FALSE; - -#if 0 - if (!Colp) { - // Column was defined in the Create Table statement - if (!(Colp = tdbp->ColDB(g, Name, 0))) - return TRUE; - - // We can have a conversion problem converting from numeric to - // character because GetCharValue does not exist for numeric types. - conv = (IsTypeChar(Buf_Type) && IsTypeNum(Colp->GetResultType())); - } else -#endif // 0 - conv = FALSE; - - if (InitValue(g)) - return TRUE; - -//if (conv) -// Cnval = AllocateValue(g, Colp->GetValue()); -//else - Cnval = Value; - - AddStatus(BUF_READ); // All is done here - return FALSE; - } // end of SRCCOL constructor - -/***********************************************************************/ -/* SetColumn: have the column value set from the source column. */ -/***********************************************************************/ -void SRCCOL::SetColumn(void) - { -#if defined(_DEBUG) - Cnval->SetValue_pval(Colp->GetValue(), TRUE); -#else - Cnval->SetValue_pval(Colp->GetValue()); -#endif // _DEBUG - - if (Value != Cnval) - // Convert value - Value->SetValue_pval(Cnval); - - } // end of SetColumn - -/***********************************************************************/ -/* SetColumn: Compare column value with source column value. */ -/***********************************************************************/ -bool SRCCOL::CompareColumn(void) - { - // Compare the unconverted values - return Cnval->CompareValue(Colp->GetValue()); - } // end of CompareColumn - - -/* ------------------------------------------------------------------- */ - -/***********************************************************************/ -/* Implementation of the TDBQRS class. */ -/***********************************************************************/ -TDBQRS::TDBQRS(PTDBQRS tdbp) : TDBASE(tdbp) - { - Qrp = tdbp->Qrp; - CurPos = tdbp->CurPos; - } // end of TDBQRS copy constructor - -// Method -PTDB TDBQRS::CopyOne(PTABS t) - { - PTDB tp; - PQRSCOL cp1, cp2; - PGLOBAL g = t->G; // Is this really useful ??? - - tp = new(g) TDBQRS(this); - - for (cp1 = (PQRSCOL)Columns; cp1; cp1 = (PQRSCOL)cp1->GetNext()) { - cp2 = new(g) QRSCOL(cp1, tp); // Make a copy - NewPointer(t, cp1, cp2); - } // endfor cp1 - - return tp; - } // end of CopyOne - -#if 0 // The TDBASE functions return NULL when To_Def is NULL -/***********************************************************************/ -/* Return the pointer on the DB catalog this table belongs to. */ -/***********************************************************************/ -PCATLG TDBQRS::GetCat(void) - { - // To_Def is null for QRYRES tables - return NULL; - } // end of GetCat - -/***********************************************************************/ -/* Return the datapath of the DB this table belongs to. */ -/***********************************************************************/ -PSZ TDBQRS::GetPath(void) - { - // To_Def is null for QRYRES tables - return NULL; - } // end of GetPath -#endif // 0 - -/***********************************************************************/ -/* Initialize QRS column description block construction. */ -/* name is used to call columns by name. */ -/* num is used by LNA to construct columns by index number. */ -/* Note: name=Null and num=0 for constructing all columns (select *) */ -/***********************************************************************/ -PCOL TDBQRS::ColDB(PGLOBAL g, PSZ name, int num) - { - int i; - PCOLRES crp; - PCOL cp, colp = NULL, cprec = NULL; - - if (trace) - htrc("QRS ColDB: colname=%s tabname=%s num=%d\n", - SVP(name), Name, num); - - for (crp = Qrp->Colresp, i = 1; crp; crp = crp->Next, i++) - if ((!name && !num) || - (name && !stricmp(crp->Name, name)) || num == i) { - // Check for existence of desired column - // Also find where to insert the new block - for (cp = Columns; cp; cp = cp->GetNext()) - if (cp->GetIndex() < i) - cprec = cp; - else if (cp->GetIndex() == i) - break; - - if (trace) { - if (cp) - htrc("cp(%d).Name=%s cp=%p\n", i, cp->GetName(), cp); - else - htrc("cp(%d) cp=%p\n", i, cp); - } // endif trace - - // Now take care of Column Description Block - if (cp) - colp = cp; - else - colp = new(g) QRSCOL(g, crp, this, cprec, i); - - if (name || num) - break; - else - cprec = colp; - - } // endif Name - - return (colp); - } // end of ColDB - -/***********************************************************************/ -/* QRS GetMaxSize: returns maximum table size in number of lines. */ -/***********************************************************************/ -int TDBQRS::GetMaxSize(PGLOBAL g) - { - MaxSize = Qrp->Maxsize; - return MaxSize; - } // end of GetMaxSize - -/***********************************************************************/ -/* RowNumber: returns the current row ordinal number. */ -/***********************************************************************/ -int TDBQRS::RowNumber(PGLOBAL g, BOOL b) - { - return (CurPos + 1); - } // end of RowNumber - -/***********************************************************************/ -/* QRS Access Method opening routine. */ -/* New method now that this routine is called recursively (last table */ -/* first in reverse order): index blocks are immediately linked to */ -/* join block of next table if it exists or else are discarted. */ -/***********************************************************************/ -bool TDBQRS::OpenDB(PGLOBAL g) - { - if (trace) - htrc("QRS OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", - this, Tdb_No, Use, To_Key_Col, Mode); - - if (Mode != MODE_READ) { - sprintf(g->Message, MSG(BAD_QUERY_OPEN), Mode); - return TRUE; - } // endif Mode - - CurPos = -1; - - if (Use == USE_OPEN) { - /*******************************************************************/ - /* Table already open, just replace it at its beginning. */ - /*******************************************************************/ - if (To_Kindex) - /*****************************************************************/ - /* Table is to be accessed through a sorted index table. */ - /*****************************************************************/ - To_Kindex->Reset(); - - return FALSE; - } // endif use - - /*********************************************************************/ - /* Open (retrieve data from) the query if not already open. */ - /*********************************************************************/ - Use = USE_OPEN; // Do it now in case we are recursively called - - return FALSE; - } // end of OpenDB - -/***********************************************************************/ -/* GetRecpos: returns current position of next sequential read. */ -/***********************************************************************/ -int TDBQRS::GetRecpos(void) - { - return (CurPos); - } // end of GetRecpos - -/***********************************************************************/ -/* ReadDB: Data Base read routine for QRS access method. */ -/***********************************************************************/ -int TDBQRS::ReadDB(PGLOBAL g) - { - int rc = RC_OK; - - if (trace) - htrc("QRS ReadDB: R%d CurPos=%d key=%p link=%p Kindex=%p\n", - GetTdb_No(), CurPos, To_Key_Col, To_Link, To_Kindex); - - if (To_Kindex) { - /*******************************************************************/ - /* Reading is by an index table. */ - /*******************************************************************/ - int recpos = To_Kindex->Fetch(g); - - switch (recpos) { - case -1: // End of file reached - rc = RC_EF; - break; - case -2: // No match for join - rc = RC_NF; - break; - case -3: // Same record as last non null one - rc = RC_OK; - break; - default: - /***************************************************************/ - /* Set the file position according to record to read. */ - /***************************************************************/ - CurPos = recpos; - } // endswitch recpos - - if (trace) - htrc("Position is now %d\n", CurPos); - - } else - /*******************************************************************/ - /* !To_Kindex ---> sequential reading */ - /*******************************************************************/ - rc = (++CurPos < Qrp->Nblin) ? RC_OK : RC_EF; - - return rc; - } // end of ReadDB - -/***********************************************************************/ -/* Dummy WriteDB: just send back an error return. */ -/***********************************************************************/ -int TDBQRS::WriteDB(PGLOBAL g) - { - strcpy(g->Message, MSG(QRY_READ_ONLY)); - return RC_FX; - } // end of WriteDB - -/***********************************************************************/ -/* Dummy DeleteDB routine, just returns an error code. */ -/***********************************************************************/ -int TDBQRS::DeleteDB(PGLOBAL g, int irc) - { - strcpy(g->Message, MSG(NO_QRY_DELETE)); - return RC_FX; - } // end of DeleteDB - -/***********************************************************************/ -/* Data Base close routine for QRS access method. */ -/***********************************************************************/ -void TDBQRS::CloseDB(PGLOBAL g) - { - if (To_Kindex) { - To_Kindex->Close(); - To_Kindex = NULL; - } // endif - - if (trace) - htrc("Qryres CloseDB"); - -//Qryp->Sqlp->CloseDB(); - } // end of CloseDB - -// ------------------------ QRSCOL functions ---------------------------- - -/***********************************************************************/ -/* QRSCOL public constructor. */ -/***********************************************************************/ -QRSCOL::QRSCOL(PGLOBAL g, PCOLRES crp, PTDB tdbp, PCOL cprec, int i) - : COLBLK(NULL, tdbp, i) +FNCCOL::FNCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) + : COLBLK(cdp, tdbp, i) { if (cprec) { Next = cprec->GetNext(); @@ -1144,59 +742,75 @@ QRSCOL::QRSCOL(PGLOBAL g, PCOLRES crp, PTDB tdbp, PCOL cprec, int i) tdbp->SetColumns(this); } // endif cprec - // Set additional QRS access method information for column. - Crp = crp; - Name = Crp->Name; - Long = Crp->Clen; - Buf_Type = crp->Type; - strcpy(Format.Type, GetFormatType(Buf_Type)); - Format.Length = (SHORT)Long; - Format.Prec = (SHORT)Crp->Prec; - - if (trace) { - htrc("Making new QRSCOL C%d %s at %p\n", Index, Name, this); - htrc(" BufType=%d Long=%d length=%d clen=%d\n", - Buf_Type, Long, Format.Length, Crp->Clen); - } // endif trace - - } // end of QRSCOL constructor + Value = NULL; // We'll get a new one later + Hval = NULL; // The unconverted header value + Xcolp = NULL; + } // end of FNCCOL constructor /***********************************************************************/ -/* QRSCOL constructor used for copying columns. */ -/* tdbp is the pointer to the new table descriptor. */ +/* FNCCOL initialization function. */ /***********************************************************************/ -QRSCOL::QRSCOL(QRSCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) +bool FNCCOL::InitColumn(PGLOBAL g) +{ + // Must have its own value block + if (InitValue(g)) + return TRUE; + + // Make a value from the column name + Hval = AllocateValue(g, Name, TYPE_STRING); + Hval->SetPrec(1); // Case insensitive + + Xcolp = ((PTDBPIVOT)To_Tdb)->Xcolp; + AddStatus(BUF_READ); // All is done here + return FALSE; +} // end of InitColumn + +/***********************************************************************/ +/* CompareColumn: Compare column value with source column value. */ +/***********************************************************************/ +bool FNCCOL::CompareColumn(void) { - Crp = col1->Crp; - } // end of QRSCOL copy constructor + // Compare the unconverted values + return Hval->IsEqual(Xcolp->GetValue(), false); + } // end of CompareColumn + +// ------------------------ SRCCOL functions ---------------------------- /***********************************************************************/ -/* ReadColumn: what this routine does is to extract the RESCOL block */ -/* current value and convert it to the column buffer type. */ +/* SRCCOL public constructor. */ /***********************************************************************/ -void QRSCOL::ReadColumn(PGLOBAL g) +SRCCOL::SRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int n) + : PRXCOL(cdp, tdbp, cprec, n) { - PTDBQRS tdbp = (PTDBQRS)To_Tdb; - - if (trace) - htrc("QRS RC: col %s R%d type=%d CurPos=%d Len=%d\n", - Name, tdbp->GetTdb_No(), Buf_Type, tdbp->CurPos, Crp->Clen); - - if (Crp->Kdata) - Value->SetValue_pvblk(Crp->Kdata, tdbp->CurPos); - else - Value->Reset(); - - } // end of ReadColumn + } // end of SRCCOL constructor /***********************************************************************/ -/* Make file output of a Dos column descriptor block. */ +/* Initialize the column as pointing to the source column. */ /***********************************************************************/ -void QRSCOL::Print(PGLOBAL g, FILE *f, UINT n) +bool SRCCOL::Init(PGLOBAL g) { - COLBLK::Print(g, f, n); + if (PRXCOL::Init(g)) + return true; - fprintf(f, " Crp=%p\n", Crp); - } // end of Print + AddStatus(BUF_READ); // All is done here + return false; + } // end of SRCCOL constructor + +/***********************************************************************/ +/* SetColumn: have the column value set from the source column. */ +/***********************************************************************/ +void SRCCOL::SetColumn(void) + { + Value->SetValue_pval(To_Val); + } // end of SetColumn + +/***********************************************************************/ +/* SetColumn: Compare column value with source column value. */ +/***********************************************************************/ +bool SRCCOL::CompareLast(void) + { + // Compare the unconverted values + return !Value->IsEqual(To_Val, true); + } // end of CompareColumn /* --------------------- End of TabPivot/TabQrs ---------------------- */ diff --git a/storage/connect/tabpivot.h b/storage/connect/tabpivot.h index fb480b9abbf..0b5bf50d13b 100644 --- a/storage/connect/tabpivot.h +++ b/storage/connect/tabpivot.h @@ -1,15 +1,48 @@ /************** TabPivot H Declares Source Code File (.H) **************/ -/* Name: TABPIVOT.H Version 1.3 */ +/* Name: TABPIVOT.H Version 1.5 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */ +/* (C) Copyright to the author Olivier BERTRAND 2005-2013 */ /* */ /* This file contains the PIVOT classes declares. */ /***********************************************************************/ +typedef class PIVOTDEF *PPIVOTDEF; typedef class TDBPIVOT *PTDBPIVOT; typedef class FNCCOL *PFNCCOL; typedef class SRCCOL *PSRCCOL; -typedef class TDBQRS *PTDBQRS; -typedef class QRSCOL *PQRSCOL; + +/***********************************************************************/ +/* This class is used to generate PIVOT table column definitions. */ +/***********************************************************************/ +class PIVAID : public CSORT { + friend class FNCCOL; + friend class SRCCOL; + public: + // Constructor + PIVAID(const char *tab, const char *src, const char *picol, + const char *fncol, const char *host, const char *db, + const char *user, const char *pwd, int port); + + // Methods + PQRYRES MakePivotColumns(PGLOBAL g); + + // The sorting function + virtual int Qcompare(int *, int *); + + protected: + // Members + MYSQLC Myc; // MySQL connection class + char *Host; // Host machine to use + char *User; // User logon info + char *Pwd; // Password logon info + char *Database; // Database to be used by server + PQRYRES Qryp; // Points to Query result block + char *Tabname; // Name of source table + char *Tabsrc; // SQL of source table + char *Picol; // Pivot column name + char *Fncol; // Function column name + PVBLK Rblkp; // The value block of the pivot column + int Port; // MySQL port number + }; // end of class PIVAID /* -------------------------- PIVOT classes -------------------------- */ @@ -22,13 +55,11 @@ typedef class QRSCOL *PQRSCOL; /***********************************************************************/ /* PIVOT table. */ /***********************************************************************/ -//ass DllExport PIVOTDEF : public TABDEF {/* Logical table description */ -class PIVOTDEF : public TABDEF { /* Logical table description */ +class PIVOTDEF : public PRXDEF { /* Logical table description */ friend class TDBPIVOT; public: // Constructor - PIVOTDEF(void) {Pseudo = 3; - Tabname = Tabsrc = Picol = Fncol = Function = NULL;} + PIVOTDEF(void); // Implementation virtual const char *GetType(void) {return "PIVOT";} @@ -39,38 +70,33 @@ class PIVOTDEF : public TABDEF { /* Logical table description */ protected: // Members - char *Host; /* Host machine to use */ - char *User; /* User logon info */ - char *Pwd; /* Password logon info */ - char *DB; /* Database to be used by server */ - char *Tabname; /* Name of source table */ + char *Host; /* Host machine to use */ + char *User; /* User logon info */ + char *Pwd; /* Password logon info */ + char *DB; /* Database to be used by server */ + char *Tabname; /* Name of source table */ char *Tabsrc; /* The source table SQL description */ - char *Picol; /* The pivot column */ + char *Picol; /* The pivot column */ char *Fncol; /* The function column */ char *Function; /* The function applying to group by */ bool GBdone; /* True if tabname as group by format */ - int Port; /* MySQL port number */ + bool Accept; /* TRUE if no match is accepted */ + int Port; /* MySQL port number */ }; // end of PIVOTDEF /***********************************************************************/ /* This is the class declaration for the PIVOT table. */ /***********************************************************************/ -//ass DllExport TDBPIVOT : public TDBASE, public CSORT { -class TDBPIVOT : public TDBASE, public CSORT { +class TDBPIVOT : public TDBPRX { friend class FNCCOL; - friend class SRCCOL; public: // Constructor TDBPIVOT(PPIVOTDEF tdp); -//TDBPIVOT(PTDBPIVOT tdbp); // Implementation virtual AMT GetAmType(void) {return TYPE_AM_PIVOT;} -//virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBPIVOT(this);} -// void SetTdbp(PTDB tdbp) {Tdbp = tdbp;} // Methods -//virtual PTDB CopyOne(PTABS t); virtual int GetRecpos(void) {return N;} virtual void ResetDB(void) {N = 0;} virtual int RowNumber(PGLOBAL g, bool b = FALSE); @@ -84,40 +110,35 @@ class TDBPIVOT : public TDBASE, public CSORT { virtual int DeleteDB(PGLOBAL g, int irc); virtual void CloseDB(PGLOBAL g); - // The sorting function - virtual int Qcompare(int *, int *); - protected: - PQRYRES GetSourceTable(PGLOBAL g); - int MakePivotColumns(PGLOBAL g); - bool UpdateTableFields(PGLOBAL g, int n); + // Internal routines + bool FindDefaultColumns(PGLOBAL g); + bool GetSourceTable(PGLOBAL g); + bool MakePivotColumns(PGLOBAL g); + bool MakeViewColumns(PGLOBAL g); // Members - MYSQLC Myc; // MySQL connection class - PTDBQRS Tqrp; // To the source table result - char *Host; // Host machine to use - char *User; // User logon info - char *Pwd; // Password logon info - char *Database; // Database to be used by server - PQRYRES Qryp; // Points to Query result block - char *Tabname; // Name of source table - char *Tabsrc; // SQL of source table - char *Picol; // Pivot column name - char *Fncol; // Function column name - char *Function; // The function applying to group by - PQRSCOL Fcolp; // To the function column in source - PQRSCOL Xcolp; // To the pivot column in source - PCOLRES Xresp; // To the pivot result column -//PCOLRES To_Sort; // Saved Qryp To_Sort pointer - PVBLK Rblkp; // The value block of the pivot column - bool GBdone; // True when subtable is "Group by" - int Mult; // Multiplication factor - int Ncol; // The number of generated columns - int N; // The current table index - int M; // The occurence rank - int Port; // MySQL port number - BYTE FileStatus; // 0: First 1: Rows 2: End-of-File - BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip + char *Host; // Host machine to use + char *User; // User logon info + char *Pwd; // Password logon info + char *Database; // Database to be used by server + char *Tabname; // Name of source table + char *Tabsrc; // SQL of source table + char *Picol; // Pivot column name + char *Fncol; // Function column name + char *Function; // The function applying to group by + PCOL Fcolp; // To the function column in source + PCOL Xcolp; // To the pivot column in source + PCOL Dcolp; // To the dump column + bool GBdone; // True when subtable is "Group by" + bool Accept; // TRUE if no match is accepted + int Mult; // Multiplication factor + int Ncol; // The number of generated columns + int N; // The current table index + int M; // The occurence rank + int Port; // MySQL port number + BYTE FileStatus; // 0: First 1: Rows 2: End-of-File + BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip }; // end of class TDBPIVOT /***********************************************************************/ @@ -127,30 +148,30 @@ class FNCCOL : public COLBLK { friend class TDBPIVOT; public: // Constructor - FNCCOL(PCOL colp, PTDBPIVOT tdbp); + FNCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); // Implementation virtual int GetAmType(void) {return TYPE_AM_FNC;} // Methods virtual void Reset(void) {} - bool InitColumn(PGLOBAL g, PVAL valp); + bool InitColumn(PGLOBAL g); + bool CompareColumn(void); protected: // Member - PVAL Hval; // The original value used to generate the header + PVAL Hval; // The value containing the header + PCOL Xcolp; }; // end of class FNCCOL /***********************************************************************/ /* Class SRCCOL: for other source columns. */ /***********************************************************************/ -class SRCCOL : public COLBLK { +class SRCCOL : public PRXCOL { friend class TDBPIVOT; public: // Constructors -//SRCCOL(PCOLDEF cdp, PTDBPIVOT tdbp, int n); - SRCCOL(PCOL cp, PTDBPIVOT tdbp, int n); -//SRCCOL(SRCCOL *colp, PTDB tdbp); // Constructor used in copy process + SRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int n); // Implementation virtual int GetAmType(void) {return TYPE_AM_SRC;} @@ -158,84 +179,18 @@ class SRCCOL : public COLBLK { // Methods virtual void Reset(void) {} void SetColumn(void); - bool Init(PGLOBAL g, PTDBPIVOT tdbp); - bool CompareColumn(void); + bool Init(PGLOBAL g); + bool CompareLast(void); protected: // Default constructor not to be used SRCCOL(void) {} // Members - PQRSCOL Colp; - PVAL Cnval; }; // end of class SRCCOL -/***********************************************************************/ -/* TDBQRS: This is the Access Method class declaration for the Query */ -/* Result stored in memory in the current work area (volatil). */ -/***********************************************************************/ -class DllExport TDBQRS : public TDBASE { - friend class QRSCOL; - public: - // Constructor - TDBQRS(PQRYRES qrp) : TDBASE() {Qrp = qrp; CurPos = 0;} - TDBQRS(PTDBQRS tdbp); - - // Implementation - virtual AMT GetAmType(void) {return TYPE_AM_QRS;} - virtual PTDB Duplicate(PGLOBAL g) - {return (PTDB)new(g) TDBQRS(this);} - PQRYRES GetQrp(void) {return Qrp;} - - // Methods - virtual PTDB CopyOne(PTABS t); - virtual int RowNumber(PGLOBAL g, BOOL b = FALSE); - virtual int GetRecpos(void); -//virtual PCATLG GetCat(void); -//virtual PSZ GetPath(void); - virtual int GetBadLines(void) {return Qrp->BadLines;} - - // Database routines - virtual PCOL ColDB(PGLOBAL g, PSZ name, int num); - virtual int GetMaxSize(PGLOBAL g); - virtual bool OpenDB(PGLOBAL g); - virtual int ReadDB(PGLOBAL g); - virtual int WriteDB(PGLOBAL g); - virtual int DeleteDB(PGLOBAL g, int irc); - virtual void CloseDB(PGLOBAL g); - - private: - TDBQRS(void) : TDBASE() {} // Standard constructor not to be used - - protected: - // Members - PQRYRES Qrp; // Points to Query Result block - int CurPos; // Current line position - }; // end of class TDBQRS - -/***********************************************************************/ -/* Class QRSCOL: QRS access method column descriptor. */ -/***********************************************************************/ -class DllExport QRSCOL : public COLBLK { - friend class TDBQRS; - public: - // Constructors - QRSCOL(PGLOBAL g, PCOLRES crp, PTDB tdbp, PCOL cprec, int i); - QRSCOL(QRSCOL *colp, PTDB tdbp); // Constructor used in copy process - - // Implementation - virtual int GetAmType(void) {return TYPE_AM_QRS;} - PCOLRES GetCrp(void) {return Crp;} - void *GetQrsData(void) {return Crp->Kdata;} - - // Methods - virtual void ReadColumn(PGLOBAL g); - virtual void Print(PGLOBAL g, FILE *, UINT); - - protected: - QRSCOL(void) {} // Default constructor not to be used - - // Members - PCOLRES Crp; - }; // end of class QRSCOL - +PQRYRES PivotColumns(PGLOBAL g, const char *tab, const char *src, + const char *picol, const char *fncol, + const char *host, const char *db, + const char *user, const char *pwd, + int port); diff --git a/storage/connect/tabsys.cpp b/storage/connect/tabsys.cpp index 9f933e4e2b8..c5186f42666 100644 --- a/storage/connect/tabsys.cpp +++ b/storage/connect/tabsys.cpp @@ -41,9 +41,7 @@ #include "tabdos.h" #include "tabsys.h" #include "tabmul.h" -#if defined(UNIX) -#include "osutil.h" -#endif // UNIX +#include "inihandl.h" #define CSZ 36 // Column section name length #define CDZ 256 // Column definition length @@ -65,7 +63,6 @@ INIDEF::INIDEF(void) Pseudo = 3; Fn = NULL; Xname = NULL; - Subtype = '?'; Layout = '?'; Ln = 0; } // end of INIDEF constructor @@ -75,63 +72,23 @@ INIDEF::INIDEF(void) /***********************************************************************/ bool INIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - char buf[8], ds[2]; - void *memp = Cat->GetDescp(); - - if (!stricmp(am, "SYS")) - strcpy(ds, "T"); // SYS tables default to T(able) - else - strcpy(ds, "I"); // INI tables default to I(ni) + char buf[8]; Fn = Cat->GetStringCatInfo(g, "Filename", NULL); - Cat->GetCharCatInfo("Subtype", ds, buf, sizeof(buf)); - Subtype = toupper(*buf); Cat->GetCharCatInfo("Layout", "C", buf, sizeof(buf)); Layout = toupper(*buf); - switch (Subtype) { -#if 0 - case 'C': - case 'T': - // Restricted table - Xname = Cat->GetStringCatInfo(g, "Name", "?"); + if (Fn) { + char *p = (char*)PlugSubAlloc(g, NULL, _MAX_PATH); - if (!strcmp(Xname, "?")) - Xname = NULL; - - if (*Fn == '?') - Fn = Cat->GetStringCatInfo(g, "Database", "?"); - - if (*Fn != '?') { - char *p = (char*)PlugSubAlloc(g, memp, _MAX_PATH); - - if (!PlgSetXdbPath(g, Fn, NULL, p, _MAX_PATH, NULL, 0)) - Fn = p; - - } else - Fn = Cat->GetDescFile(); - - Ln = GetIniSize("Database", "Tabsize", "2K", Fn); - break; -#endif // 0 - case 'I': - if (*Fn != '?') { - char *p = (char*)PlugSubAlloc(g, memp, _MAX_PATH); - - PlugSetPath(p, Fn, GetPath()); - Fn = p; - } else { - strcpy(g->Message, MSG(MISSING_FNAME)); - return true; - } // endif Fn - - Ln = Cat->GetSizeCatInfo("Secsize", "8K"); - break; - default: - sprintf(g->Message, MSG(INV_SUBTYPE), buf); - return true; - } // endswitch Subtype + PlugSetPath(p, Fn, GetPath()); + Fn = p; + } else { + strcpy(g->Message, MSG(MISSING_FNAME)); + return true; + } // endif Fn + Ln = Cat->GetSizeCatInfo("Secsize", "8K"); Desc = Fn; return false; } // end of DefineAM @@ -143,17 +100,10 @@ PTDB INIDEF::GetTable(PGLOBAL g, MODE m) { PTDBASE tdbp; - switch (Subtype) { - case 'I': - if (Layout == 'C') - tdbp = new(g) TDBINI(this); - else - tdbp = new(g) TDBXIN(this); - - break; - default: - return NULL; - } // endswitch Subtype + if (Layout == 'C') + tdbp = new(g) TDBINI(this); + else + tdbp = new(g) TDBXIN(this); if (Multiple) tdbp = new(g) TDBMUL(tdbp); // No block optimization yet @@ -163,7 +113,6 @@ PTDB INIDEF::GetTable(PGLOBAL g, MODE m) /***********************************************************************/ /* DeleteTableFile: Delete INI table files using platform API. */ -/* SysTable and SysColumn tables are readonly and not erasable. */ /***********************************************************************/ bool INIDEF::DeleteTableFile(PGLOBAL g) { @@ -171,7 +120,7 @@ bool INIDEF::DeleteTableFile(PGLOBAL g) bool rc; // Delete the INI table file if not protected - if (Subtype == 'I' && !IsReadOnly()) { + if (!IsReadOnly()) { PlugSetPath(filename, Fn, GetPath()); #if defined(WIN32) rc = !DeleteFile(filename); @@ -274,12 +223,13 @@ bool TDBINI::OpenDB(PGLOBAL g) PINICOL colp; if (Use == USE_OPEN) { +#if 0 if (To_Kindex) /*****************************************************************/ /* Table is to be accessed through a sorted index table. */ /*****************************************************************/ To_Kindex->Reset(); - +#endif // 0 Section = NULL; N = 0; return false; @@ -313,6 +263,7 @@ int TDBINI::ReadDB(PGLOBAL g) /*********************************************************************/ /* Now start the pseudo reading process. */ /*********************************************************************/ +#if 0 // INI tables are not indexable if (To_Kindex) { /*******************************************************************/ /* Reading is by an index table. */ @@ -327,10 +278,11 @@ int TDBINI::ReadDB(PGLOBAL g) case -3: // Same record as last non null one return RC_OK; default: - Section = (char*)recpos; + Section = (char*)recpos; // No good on 64 bit machines } // endswitch recpos } else { +#endif // 0 if (!Section) Section = Seclist; else @@ -340,7 +292,7 @@ int TDBINI::ReadDB(PGLOBAL g) htrc("INI ReadDB: section=%s N=%d\n", Section, N); N++; - } // endif To_Kindex +//} // endif To_Kindex return (*Section) ? RC_OK : RC_EF; } // end of ReadDB @@ -706,6 +658,7 @@ int TDBXIN::ReadDB(PGLOBAL g) /*********************************************************************/ /* Now start the pseudo reading process. */ /*********************************************************************/ +#if 0 // XIN tables are not indexable if (To_Kindex) { /*******************************************************************/ /* Reading is by an index table. */ @@ -724,6 +677,7 @@ int TDBXIN::ReadDB(PGLOBAL g) } // endswitch recpos } else { +#endif // 0 do { if (!Keycur || !*Keycur) { if (!Section) @@ -742,7 +696,7 @@ int TDBXIN::ReadDB(PGLOBAL g) } while (!*Keycur); N++; - } // endif To_Kindex +//} // endif To_Kindex return RC_OK; } // end of ReadDB diff --git a/storage/connect/tabsys.h b/storage/connect/tabsys.h index ac8ae05aee9..2780eb3ca98 100644 --- a/storage/connect/tabsys.h +++ b/storage/connect/tabsys.h @@ -38,7 +38,6 @@ class DllExport INIDEF : public TABDEF { /* INI table description */ // Members char *Fn; /* Path/Name of corresponding file */ char *Xname; /* The eventual table name */ - char Subtype; /* I: INI, T: Table, C: Column */ char Layout; /* R: Row, C: Column */ int Ln; /* Length of section list buffer */ }; // end of INIDEF @@ -83,8 +82,8 @@ class TDBINI : public TDBASE { // Members char *Ifile; // The INI file char *Seclist; // The section list - char *Section; // The current section - int Seclen; // Length of seclist buffer + char *Section; // The current section + int Seclen; // Length of seclist buffer int N; // The current section index }; // end of class TDBINI diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index b194da3fc09..6b90b3861aa 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -1,7 +1,7 @@ /************* TabTbl C++ Program Source Code File (.CPP) **************/ /* PROGRAM NAME: TABTBL */ /* ------------- */ -/* Version 1.4 */ +/* Version 1.6 */ /* */ /* COPYRIGHT: */ /* ---------- */ @@ -70,13 +70,23 @@ #include "filamtxt.h" #include "tabcol.h" #include "tabdos.h" // TDBDOS and DOSCOL class dcls -#include "tabtbl.h" // TDBTBL and TBLCOL classes dcls +#include "tabtbl.h" #if defined(MYSQL_SUPPORT) #include "tabmysql.h" #endif // MYSQL_SUPPORT #include "ha_connect.h" #include "mycat.h" // For GetHandler +#if defined(WIN32) +#if defined(__BORLANDC__) +#define SYSEXIT void _USERENTRY +#else +#define SYSEXIT void +#endif +#else // !WIN32 +#define SYSEXIT void * +#endif // !WIN32 + extern "C" int trace; /* ---------------------------- Class TBLDEF ---------------------------- */ @@ -86,7 +96,10 @@ extern "C" int trace; /**************************************************************************/ TBLDEF::TBLDEF(void) { - To_Tables = NULL; +//To_Tables = NULL; + Accept = false; + Thread = false; + Maxerr = 0; Ntables = 0; Pseudo = 3; } // end of TBLDEF constructor @@ -96,22 +109,23 @@ TBLDEF::TBLDEF(void) /**************************************************************************/ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - char *tablist, *dbname; + char *tablist, *dbname, *def = NULL; Desc = "Table list table"; tablist = Cat->GetStringCatInfo(g, "Tablist", ""); - dbname = Cat->GetStringCatInfo(g, "Database", NULL); + dbname = Cat->GetStringCatInfo(g, "Dbname", "*"); + def = Cat->GetStringCatInfo(g, "Srcdef", NULL); Ntables = 0; if (*tablist) { - char *p, *pn, *pdb; - PTBL *ptbl = &To_Tables, tbl; + char *p, *pn, *pdb; + PTABLE tbl; for (pdb = tablist; ;) { if ((p = strchr(pdb, ','))) *p = 0; - // Analyze the table name, it has the format: + // Analyze the table name, it may have the format: // [dbname.]tabname if ((pn = strchr(pdb, '.'))) { *pn++ = 0; @@ -121,17 +135,18 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) } // endif p // Allocate the TBLIST block for that table - tbl = (PTBL)PlugSubAlloc(g, NULL, sizeof(TBLIST)); - tbl->Next = NULL; - tbl->Name = pn; - tbl->DB = pdb; + tbl = new(g) XTAB(pn, def); + tbl->SetQualifier(pdb); if (trace) - htrc("TBL: Name=%s db=%s\n", tbl->Name, SVP(tbl->DB)); + htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetQualifier()); // Link the blocks - *ptbl = tbl; - ptbl = &tbl->Next; + if (Tablep) + Tablep->Link(tbl); + else + Tablep = tbl; + Ntables++; if (p) @@ -142,8 +157,9 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) } // endfor pdb Maxerr = Cat->GetIntCatInfo("Maxerr", 0); - Accept = (Cat->GetBoolCatInfo("Accept", 0) != 0); - } // endif fsec || tablist + Accept = Cat->GetBoolCatInfo("Accept", false); + Thread = Cat->GetBoolCatInfo("Thread", false); + } // endif tablist return FALSE; } // end of DefineAM @@ -153,15 +169,13 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ PTDB TBLDEF::GetTable(PGLOBAL g, MODE m) { - PTDB tdbp; + if (Catfunc == FNC_COL) + return new(g) TDBTBC(this); + else if (Thread) + return new(g) TDBTBM(this); + else + return new(g) TDBTBL(this); - /*********************************************************************/ - /* Allocate a TDB of the proper type. */ - /* Column blocks will be allocated only when needed. */ - /*********************************************************************/ - tdbp = new(g) TDBTBL(this); - - return tdbp; } // end of GetTable /* ------------------------- Class TDBTBL ---------------------------- */ @@ -169,14 +183,14 @@ PTDB TBLDEF::GetTable(PGLOBAL g, MODE m) /***********************************************************************/ /* TDBTBL constructors. */ /***********************************************************************/ -TDBTBL::TDBTBL(PTBLDEF tdp) : TDBASE(tdp) +TDBTBL::TDBTBL(PTBLDEF tdp) : TDBPRX(tdp) { Tablist = NULL; CurTable = NULL; - Tdbp = NULL; +//Tdbp = NULL; Accept = tdp->Accept; Maxerr = tdp->Maxerr; - Nbf = 0; + Nbc = 0; Rows = 0; Crp = 0; // NTables = 0; @@ -188,7 +202,7 @@ TDBTBL::TDBTBL(PTBLDEF tdp) : TDBASE(tdp) /***********************************************************************/ PCOL TDBTBL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) { - return new(g) TBLCOL(cdp, this, cprec, n); + return new(g) PRXCOL(cdp, this, cprec, n); } // end of MakeCol /***********************************************************************/ @@ -212,126 +226,51 @@ PCOL TDBTBL::InsertSpecialColumn(PGLOBAL g, PCOL scp) return colp; } // end of InsertSpecialColumn -/***********************************************************************/ -/* Get the PTDB of a table of the list. */ -/***********************************************************************/ -PTDB TDBTBL::GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp) - { - char *db, key[256]; - uint k; - PTDB tdbp = NULL; - TABLE_SHARE *s; - PCATLG cat = To_Def->GetCat(); - PHC hc = ((MYCAT*)cat)->GetHandler(); - THD *thd = (hc->GetTable())->in_use; - - if (!thd) - return NULL; // Should not happen anymore - - if (tblp->DB) - db = tblp->DB; - else - db = (char*)hc->GetDBName(NULL); - - k = sprintf(key, "%s", db) + 1; - k += sprintf(key + k, "%s", tblp->Name); - key[++k] = 0; - - if (!(s = alloc_table_share(db, tblp->Name, key, ++k))) { - strcpy(g->Message, "Error allocating share\n"); - return NULL; - } // endif s - - if (!open_table_def(thd, s)) { - if (plugin_data(s->db_plugin, handlerton*) != connect_hton) { -#if defined(MYSQL_SUPPORT) - // Access sub-table via MySQL API - if (!(tdbp= cat->GetTable(g, tabp, MODE_READ, "MYSQL"))) { - sprintf(g->Message, "Cannot access %s.%s", db, tblp->Name); - return NULL; - } // endif Define - - if (tabp->GetQualifier()) - ((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier()); - -#else // !MYSQL_SUPPORT - sprintf(g->Message, "%s.%s is not a CONNECT table", - db, tblp->Name); - return NULL; -#endif // MYSQL_SUPPORT - } else { - // Sub-table is a CONNECT table - hc->tshp = s; - tdbp = cat->GetTable(g, tabp); - hc->tshp = NULL; - } // endif plugin - - } else - sprintf(g->Message, "Error %d opening share\n", s->error); - - if (trace && tdbp) - htrc("Subtable %s in %s\n", - tblp->Name, SVP(((PTDBASE)tdbp)->GetDef()->GetDB())); - - free_table_share(s); - return tdbp; - } // end of GetSubTable - /***********************************************************************/ /* Initializes the table table list. */ /***********************************************************************/ bool TDBTBL::InitTableList(PGLOBAL g) { - char *colname; - int n, colpos; - PTBL tblp; - PTABLE tabp; - PTDB tdbp; + int n; + uint sln; + char *scs; + PTABLE tp, tabp; PCOL colp; PTBLDEF tdp = (PTBLDEF)To_Def; + PCATLG cat = To_Def->GetCat(); + PHC hc = ((MYCAT*)cat)->GetHandler(); + scs = hc->get_table()->s->connect_string.str; + sln = hc->get_table()->s->connect_string.length; // PlugSetPath(filename, Tdbp->GetFile(g), Tdbp->GetPath()); - for (n = 0, tblp = tdp->GetTables(); tblp; tblp = tblp->Next) { - if (TestFil(g, To_Filter, tblp)) { - // Table or named view - tabp = new(g) XTAB(tblp->Name); - tabp->SetQualifier(tblp->DB); + for (n = 0, tp = tdp->Tablep; tp; tp = tp->GetNext()) { + if (TestFil(g, To_Filter, tp)) { + tabp = new(g) XTAB(tp); + + if (tabp->GetSrc()) { + // Table list is a list of connections + hc->get_table()->s->connect_string.str = (char*)tabp->GetName(); + hc->get_table()->s->connect_string.length = strlen(tabp->GetName()); + } // endif Src // Get the table description block of this table - if (!(tdbp = GetSubTable(g, tblp, tabp))) { - if (++Nbf > Maxerr) + if (!(Tdbp = GetSubTable(g, tabp))) { + if (++Nbc > Maxerr) return TRUE; // Error return else continue; // Skip this table - } // endif tdbp + } else + RemoveNext(tabp); // To avoid looping // We must allocate subtable columns before GetMaxSize is called // because some (PLG, ODBC?) need to have their columns attached. // Real initialization will be done later. - for (PCOL cp = Columns; cp; cp = cp->GetNext()) - if (!cp->IsSpecial()) { - colname = cp->GetName(); - colpos = ((PTBLCOL)cp)->Colnum; - - // We try first to get the column by name - if (!(colp = tdbp->ColDB(g, colname, 0)) && colpos) - // When unsuccessful, if a column number was specified - // try to get the column by its position in the table - colp = tdbp->ColDB(g, NULL, colpos); - - if (!colp) { - if (!Accept) { - sprintf(g->Message, MSG(NO_MATCHING_COL), - colname, tdbp->GetName()); - return TRUE; // Error return - } // endif !Accept - - } else // this is needed in particular by PLG tables - colp->SetColUse(cp->GetColUse()); - - } // endif !special + for (colp = Columns; colp; colp = colp->GetNext()) + if (!colp->IsSpecial()) + if (((PPRXCOL)colp)->Init(g) && !Accept) + return TRUE; if (Tablist) Tablist->Link(tabp); @@ -341,7 +280,10 @@ bool TDBTBL::InitTableList(PGLOBAL g) n++; } // endif filp - } // endfor tblp + } // endfor tp + + hc->get_table()->s->connect_string.str = scs; + hc->get_table()->s->connect_string.length = sln; //NumTables = n; To_Filter = NULL; // To avoid doing it several times @@ -351,7 +293,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) /***********************************************************************/ /* Test the tablename against the pseudo "local" filter. */ /***********************************************************************/ -bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTBL tblp) +bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTABLE tabp) { char *fil, op[8], tn[NAME_LEN]; bool neg; @@ -374,7 +316,7 @@ bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTBL tblp) if (sscanf(fil, "TABID = '%[^']'", tn) != 1) return TRUE; // ignore invalid filter - return !stricmp(tn, tblp->Name); + return !stricmp(tn, tabp->GetName()); } else if (!strcmp(op, "IN")) { char *p, *tnl = (char*)PlugSubAlloc(g, NULL, strlen(fil) - 10); int n; @@ -393,7 +335,7 @@ bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTBL tblp) if (sscanf(tnl, "'%[^']'", tn) != 1) return TRUE; // ignore invalid filter - else if (!stricmp(tn, tblp->Name)) + else if (!stricmp(tn, tabp->GetName())) return !neg; // Found tnl = p; @@ -405,85 +347,21 @@ bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTBL tblp) return TRUE; // invalid operator } // end of TestFil -/***********************************************************************/ -/* TBL GetProgMax: get the max value for progress information. */ -/***********************************************************************/ -int TDBTBL::GetProgMax(PGLOBAL g) - { - PTABLE tblp; - int n, pmx = 0; - - if (!Tablist && InitTableList(g)) - return -1; - - for (tblp = Tablist; tblp; tblp = tblp->GetNext()) - if ((n = tblp->GetTo_Tdb()->GetProgMax(g)) > 0) - pmx += n; - - return pmx; - } // end of GetProgMax - -/***********************************************************************/ -/* TBL GetProgCur: get the current value for progress information. */ -/***********************************************************************/ -int TDBTBL::GetProgCur(void) - { - return Crp + Tdbp->GetProgCur(); - } // end of GetProgCur - -#if 0 -/***********************************************************************/ -/* TBL Cardinality: returns table cardinality in number of rows. */ -/* This function can be called with a null argument to test the */ -/* availability of Cardinality implementation (1 yes, 0 no). */ -/* Can be used on Multiple FIX table only. */ -/***********************************************************************/ -int TDBTBL::Cardinality(PGLOBAL g) - { - if (!g) - return Tdbp->Cardinality(g); - - if (!Tablist && InitTableList(g)) - return -1; - - int n, card = 0; - - for (int i = 0; i < NumFiles; i++) { - Tdbp->SetFile(g, Filenames[i]); - Tdbp->ResetSize(); - - if ((n = Tdbp->Cardinality(g)) < 0) { -// strcpy(g->Message, MSG(BAD_CARDINALITY)); - return -1; - } // endif n - - card += n; - } // endfor i - - return card; - } // end of Cardinality -#endif // 0 - /***********************************************************************/ /* Sum up the sizes of all sub-tables. */ /***********************************************************************/ int TDBTBL::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { - PTABLE tblp; - int mxsz; + int mxsz; if (!Tablist && InitTableList(g)) return 0; // Cannot be calculated at this stage -// if (Use == USE_OPEN) { -// strcpy(g->Message, MSG(MAXSIZE_ERROR)); -// return -1; -// } else - MaxSize = 0; + MaxSize = 0; - for (tblp = Tablist; tblp; tblp = tblp->GetNext()) { - if ((mxsz = tblp->GetTo_Tdb()->GetMaxSize(g)) < 0) { + for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext()) { + if ((mxsz = tabp->GetTo_Tdb()->GetMaxSize(g)) < 0) { MaxSize = -1; return mxsz; } // endif mxsz @@ -505,8 +383,8 @@ void TDBTBL::ResetDB(void) if (colp->GetAmType() == TYPE_AM_TABID) colp->COLBLK::Reset(); - for (PTABLE tblp = Tablist; tblp; tblp = tblp->GetNext()) - ((PTDBASE)tblp->GetTo_Tdb())->ResetDB(); + for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext()) + ((PTDBASE)tabp->GetTo_Tdb())->ResetDB(); Tdbp = (PTDBASE)Tablist->GetTo_Tdb(); Crp = 0; @@ -538,23 +416,12 @@ bool TDBTBL::OpenDB(PGLOBAL g) return Tdbp->OpenDB(g); // Re-open fist table } // endif use -#if 0 - /*********************************************************************/ - /* Direct access needed for join or sorting. */ - /*********************************************************************/ - if (NeedIndexing(g)) { - // Direct access of TBL tables is not implemented yet - strcpy(g->Message, MSG(NO_MUL_DIR_ACC)); - return TRUE; - } // endif NeedIndexing -#endif // 0 - /*********************************************************************/ /* When GetMaxsize was called, To_Filter was not set yet. */ /*********************************************************************/ if (To_Filter && Tablist) { Tablist = NULL; - Nbf = 0; + Nbc = 0; } // endif To_Filter /*********************************************************************/ @@ -573,7 +440,7 @@ bool TDBTBL::OpenDB(PGLOBAL g) for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_TABID) cp->COLBLK::Reset(); - else if (((PTBLCOL)cp)->Init(g)) + else if (((PPRXCOL)cp)->Init(g) && !Accept) return TRUE; if (trace) @@ -627,7 +494,7 @@ int TDBTBL::ReadDB(PGLOBAL g) for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_TABID) cp->COLBLK::Reset(); - else if (((PTBLCOL)cp)->Init(g)) + else if (((PPRXCOL)cp)->Init(g) && !Accept) return RC_FX; if (trace) @@ -648,142 +515,6 @@ int TDBTBL::ReadDB(PGLOBAL g) return rc; } // end of ReadDB -/***********************************************************************/ -/* Data Base write routine for MUL access method. */ -/***********************************************************************/ -int TDBTBL::WriteDB(PGLOBAL g) - { - strcpy(g->Message, MSG(TABMUL_READONLY)); - return RC_FX; // NIY - } // end of WriteDB - -/***********************************************************************/ -/* Data Base delete line routine for MUL access method. */ -/***********************************************************************/ -int TDBTBL::DeleteDB(PGLOBAL g, int irc) - { - strcpy(g->Message, MSG(TABMUL_READONLY)); - return RC_FX; // NIY - } // end of DeleteDB - -/***********************************************************************/ -/* Data Base close routine for MUL access method. */ -/***********************************************************************/ -void TDBTBL::CloseDB(PGLOBAL g) - { - if (Tdbp) - Tdbp->CloseDB(g); - - } // end of CloseDB - -/* ---------------------------- TBLCOL ------------------------------- */ - -/***********************************************************************/ -/* TBLCOL public constructor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am) - : COLBLK(cdp, tdbp, i) - { - if (cprec) { - Next = cprec->GetNext(); - cprec->SetNext(this); - } else { - Next = tdbp->GetColumns(); - tdbp->SetColumns(this); - } // endif cprec - - // Set additional Dos access method information for column. - Long = cdp->GetLong(); // ??? -//strcpy(F_Date, cdp->F_Date); - Colp = NULL; - To_Val = NULL; - Pseudo = FALSE; - Colnum = cdp->GetOffset(); // If columns are retrieved by number - - if (trace) - htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); - - } // end of TBLCOL constructor - -#if 0 -/***********************************************************************/ -/* TBLCOL public constructor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(SPCBLK *scp, PTDB tdbp) : COLBLK(scp->GetName(), tdbp, 0) - { - // Set additional TBL access method information for pseudo column. - Is_Key = Was_Key = scp->IsKey(); - Long = scp->GetLength(); - Buf_Type = scp->GetResultType(); - *Format.Type = (Buf_Type == TYPE_INT) ? 'N' : 'C'; - Format.Length = Long; - Colp = NULL; - To_Val = NULL; - Pseudo = TRUE; - } // end of TBLCOL constructor - -/***********************************************************************/ -/* TBLCOL constructor used for copying columns. */ -/* tdbp is the pointer to the new table descriptor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(TBLCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) - { - Long = col1->Long; - Colp = col1->Colp; - To_Val = col1->To_Val; - Pseudo = col1->Pseudo; - } // end of TBLCOL copy constructor -#endif - -/***********************************************************************/ -/* TBLCOL initialization routine. */ -/* Look for the matching column in the current table. */ -/***********************************************************************/ -bool TBLCOL::Init(PGLOBAL g) - { - PTDBTBL tdbp = (PTDBTBL)To_Tdb; - - To_Val = NULL; - - if (!(Colp = tdbp->Tdbp->ColDB(g, Name, 0)) && Colnum) - Colp = tdbp->Tdbp->ColDB(g, NULL, Colnum); - - if (Colp) { - Colp->InitValue(g); // May not have been done elsewhere - To_Val = Colp->GetValue(); - } else if (!tdbp->Accept) { - sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tdbp->Tdbp->GetName()); - return TRUE; - } else { - if (Nullable) - Value->SetNull(true); - - Value->Reset(); - } // endif's - - return FALSE; - } // end of Init - -/***********************************************************************/ -/* ReadColumn: */ -/***********************************************************************/ -void TBLCOL::ReadColumn(PGLOBAL g) - { - if (trace) - htrc("TBL ReadColumn: name=%s\n", Name); - - if (Colp) { - Colp->ReadColumn(g); - Value->SetValue_pval(To_Val); - - // Set null when applicable - if (Nullable) - Value->SetNull(Value->IsNull()); - - } // endif Colp - - } // end of ReadColumn - /* ---------------------------- TBTBLK ------------------------------- */ /***********************************************************************/ @@ -798,4 +529,262 @@ void TBTBLK::ReadColumn(PGLOBAL g) } // end of ReadColumn +/* ------------------------- Class TDBTBM ---------------------------- */ + +/***********************************************************************/ +/* Thread routine that check and open one remote connection. */ +/***********************************************************************/ +pthread_handler_t ThreadOpen(void *p) + { + PTBMT cmp = (PTBMT)p; + + if (!my_thread_init()) { + set_current_thd(cmp->Thd); + + // Try to open the connection + if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) { + cmp->Ready = true; + } else + cmp->Rc = RC_FX; + + my_thread_end(); + } else + cmp->Rc = RC_FX; + + return NULL; + } // end of ThreadOpen + +/***********************************************************************/ +/* TDBTBM constructors. */ +/***********************************************************************/ +TDBTBM::TDBTBM(PTBLDEF tdp) : TDBTBL(tdp) + { + Tmp = NULL; // To data table TBMT structures + Cmp = NULL; // Current data table TBMT + Bmp = NULL; // To bad (unconnected) TBMT structures + Done = false; // TRUE after first GetAllResults + Nrc = 0; // Number of remote connections + Nlc = 0; // Number of local connections + } // end of TDBTBL standard constructor + +/***********************************************************************/ +/* Reset read/write position values. */ +/***********************************************************************/ +void TDBTBM::ResetDB(void) + { + for (PCOL colp = Columns; colp; colp = colp->GetNext()) + if (colp->GetAmType() == TYPE_AM_TABID) + colp->COLBLK::Reset(); + + for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext()) + ((PTDBASE)tabp->GetTo_Tdb())->ResetDB(); + + Tdbp = (PTDBASE)Tablist->GetTo_Tdb(); + Crp = 0; + } // end of ResetDB + +/***********************************************************************/ +/* Returns RowId if b is false or Rownum if b is true. */ +/***********************************************************************/ +int TDBTBM::RowNumber(PGLOBAL g, bool b) + { + return Tdbp->RowNumber(g) + ((b) ? 0 : Rows); + } // end of RowNumber + +/***********************************************************************/ +/* Initialyze table parallel processing. */ +/***********************************************************************/ +bool TDBTBM::OpenTables(PGLOBAL g) + { + int k; + THD *thd = current_thd; + PTABLE tabp, *ptabp = &Tablist; + PTBMT tp, *ptp = &Tmp; + + // Allocates the TBMT blocks for the tables + for (tabp = Tablist; tabp; tabp = tabp->Next) + if (tabp->GetTo_Tdb()->GetAmType() == TYPE_AM_MYSQL) { + // Remove remote table from the local list + *ptabp = tabp->Next; + + // Make the remote table block + tp = (PTBMT)PlugSubAlloc(g, NULL, sizeof(TBMT)); + memset(tp, 0, sizeof(TBMT)); + tp->G = g; + tp->Tap = tabp; + tp->Thd = thd; + + // Create the thread that will do the table opening. + pthread_attr_init(&tp->attr); +// pthread_attr_setdetachstate(&tp->attr, PTHREAD_CREATE_JOINABLE); + + if ((k = pthread_create(&tp->Tid, &tp->attr, ThreadOpen, tp))) { + sprintf(g->Message, "pthread_create error %d", k); + Nbc++; + continue; + } // endif k + + // Add it to the remote list + *ptp = tp; + ptp = &tp->Next; + Nrc++; // Number of remote connections + } else { + ptabp = &tabp->Next; + Nlc++; // Number of local connections + } // endif Type + + return false; + } // end of OpenTables + +/***********************************************************************/ +/* TBL Access Method opening routine. */ +/* Open first file, other will be opened sequencially when reading. */ +/***********************************************************************/ +bool TDBTBM::OpenDB(PGLOBAL g) + { + if (trace) + htrc("TBM OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", + this, Tdb_No, Use, To_Key_Col, Mode); + + if (Use == USE_OPEN) { + /*******************************************************************/ + /* Table already open, replace it at its beginning. */ + /*******************************************************************/ + ResetDB(); + return Tdbp->OpenDB(g); // Re-open fist table + } // endif use + +#if 0 + /*********************************************************************/ + /* When GetMaxsize was called, To_Filter was not set yet. */ + /*********************************************************************/ + if (To_Filter && Tablist) { + Tablist = NULL; + Nbc = 0; + } // endif To_Filter +#endif // 0 + + /*********************************************************************/ + /* Make the table list. */ + /*********************************************************************/ + if (/*!Tablist &&*/ InitTableList(g)) + return TRUE; + + /*********************************************************************/ + /* Open all remote tables of the list. */ + /*********************************************************************/ + if (OpenTables(g)) + return TRUE; + + /*********************************************************************/ + /* Proceed with local tables. */ + /*********************************************************************/ + if ((CurTable = Tablist)) { + Tdbp = (PTDBASE)CurTable->GetTo_Tdb(); + Tdbp->SetMode(Mode); + + // Check and initialize the subtable columns + for (PCOL cp = Columns; cp; cp = cp->GetNext()) + if (cp->GetAmType() == TYPE_AM_TABID) + cp->COLBLK::Reset(); + else if (((PPRXCOL)cp)->Init(g) && !Accept) + return TRUE; + + if (trace) + htrc("Opening subtable %s\n", Tdbp->GetName()); + + // Now we can safely open the table + if (Tdbp->OpenDB(g)) + return TRUE; + + } // endif *Tablist + + Use = USE_OPEN; + return FALSE; + } // end of OpenDB + +/***********************************************************************/ +/* ReadDB: Data Base read routine for MUL access method. */ +/***********************************************************************/ +int TDBTBM::ReadDB(PGLOBAL g) + { + int rc; + + if (!Done) { + // Get result from local tables + if ((rc = TDBTBL::ReadDB(g)) != RC_EF) + return rc; + else if ((rc = ReadNextRemote(g)) != RC_OK) + return rc; + + Done = true; + } // endif Done + + /*********************************************************************/ + /* Now start the reading process of remote tables. */ + /*********************************************************************/ + retry: + rc = Tdbp->ReadDB(g); + + if (rc == RC_EF) { + // Total number of rows met so far + Rows += Tdbp->RowNumber(g) - 1; + Crp += Tdbp->GetProgMax(g); + Cmp->Complete = true; + + if ((rc = ReadNextRemote(g)) == RC_OK) + goto retry; + + } else if (rc == RC_FX) + strcat(strcat(strcat(g->Message, " ("), Tdbp->GetName()), ")"); + + return rc; + } // end of ReadDB + +/***********************************************************************/ +/* ReadNext: Continue reading from next table. */ +/***********************************************************************/ +int TDBTBM::ReadNextRemote(PGLOBAL g) + { + bool b = false; + + if (Tdbp) + Tdbp->CloseDB(g); + + Cmp = NULL; + + retry: + // Search for a remote table having its result set + for (PTBMT tp = Tmp; tp; tp = tp->Next) + if (tp->Ready) { + if (!tp->Complete) + Cmp = tp; + + } else + b = true; + + if (!Cmp) { + if (b) { // more result to come +// sleep(20); + goto retry; + } else + return RC_EF; + + } // endif Curtable + + Tdbp = (PTDBASE)Cmp->Tap->GetTo_Tdb(); + + // Check and initialize the subtable columns + for (PCOL cp = Columns; cp; cp = cp->GetNext()) + if (cp->GetAmType() == TYPE_AM_TABID) + cp->COLBLK::Reset(); + else if (((PPRXCOL)cp)->Init(g) && !Accept) + return RC_FX; + + if (trace) + htrc("Reading subtable %s\n", Tdbp->GetName()); + + return RC_OK; + } // end of ReadNextRemote + /* ------------------------------------------------------------------- */ diff --git a/storage/connect/tabtbl.h b/storage/connect/tabtbl.h index 07a20bb2867..6b29e8eed6e 100644 --- a/storage/connect/tabtbl.h +++ b/storage/connect/tabtbl.h @@ -1,42 +1,51 @@ /*************** TabTbl H Declares Source Code File (.H) ***************/ -/* Name: TABTBL.H Version 1.2 */ +/* Name: TABTBL.H Version 1.3 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2008-2012 */ +/* (C) Copyright to the author Olivier BERTRAND 2008-2013 */ /* */ /* This file contains the TDBTBL classes declares. */ /***********************************************************************/ -//#include "osutil.h" #include "block.h" #include "colblk.h" +#include "tabutil.h" typedef class TBLDEF *PTBLDEF; typedef class TDBTBL *PTDBTBL; -typedef class TBLCOL *PTBLCOL; +typedef class TDBTBM *PTDBTBM; +typedef class MYSQLC *PMYC; /***********************************************************************/ -/* Defines the structure used for multiple tables. */ +/* Defines the structures used for distributed TBM tables. */ /***********************************************************************/ -typedef struct _tablist *PTBL; +typedef struct _TBMtable *PTBMT; -typedef struct _tablist { - PTBL Next; - char *Name; - char *DB; - } TBLIST; +typedef struct _TBMtable { + PTBMT Next; // Points to next data table struct + PTABLE Tap; // Points to the sub table + PGLOBAL G; // Needed in thread routine + bool Complete; // TRUE when all results are read + bool Ready; // TRUE when results are there + int Rows; // Total number of rows read so far + int ProgCur; // Current pos + int ProgMax; // Max pos + int Rc; // Return code + THD *Thd; + pthread_attr_t attr; // ??? + pthread_t Tid; // CheckOpen thread ID + } TBMT; /***********************************************************************/ /* TBL table. */ /***********************************************************************/ -class DllExport TBLDEF : public TABDEF { /* Logical table description */ +class DllExport TBLDEF : public PRXDEF { /* Logical table description */ friend class TDBTBL; + friend class TDBTBC; public: // Constructor TBLDEF(void); // Implementation virtual const char *GetType(void) {return "TBL";} - PTBL GetTables(void) {return To_Tables;} -//int GetNtables(void) {return Ntables;} // Methods virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); @@ -44,8 +53,8 @@ class DllExport TBLDEF : public TABDEF { /* Logical table description */ protected: // Members - PTBL To_Tables; /* To the list of tables */ bool Accept; /* TRUE if bad tables are accepted */ + bool Thread; /* Use thread for remote tables */ int Maxerr; /* Maximum number of bad tables */ int Ntables; /* Number of tables */ }; // end of TBLDEF @@ -53,90 +62,43 @@ class DllExport TBLDEF : public TABDEF { /* Logical table description */ /***********************************************************************/ /* This is the TBL Access Method class declaration. */ /***********************************************************************/ -class DllExport TDBTBL : public TDBASE { - friend class TBLCOL; +class DllExport TDBTBL : public TDBPRX { friend class TBTBLK; - friend class TDBPLG; public: // Constructor TDBTBL(PTBLDEF tdp = NULL); -//TDBTBL(PTDBTBL tdbp); // Implementation virtual AMT GetAmType(void) {return TYPE_AM_TBL;} -//virtual PTDB Duplicate(PGLOBAL g) -// {return (PTDB)new(g) TDBTBL(this);} // Methods virtual void ResetDB(void); -//virtual PTABLE GetTablist(void) {return (PSZ)Tablist;} -//virtual PTDB CopyOne(PTABS t); - virtual int GetRecpos(void) {return Rows;} - virtual int GetBadLines(void) {return (int)Nbf;} + virtual int GetRecpos(void) {return Rows;} + virtual int GetBadLines(void) {return (int)Nbc;} // Database routines virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual int GetMaxSize(PGLOBAL g); - virtual int GetProgMax(PGLOBAL g); - virtual int GetProgCur(void); virtual int RowNumber(PGLOBAL g, bool b = FALSE); virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL scp); virtual bool OpenDB(PGLOBAL g); virtual int ReadDB(PGLOBAL g); - virtual int WriteDB(PGLOBAL g); - virtual int DeleteDB(PGLOBAL g, int irc); - virtual void CloseDB(PGLOBAL g); protected: // Internal functions - PTDB GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp); bool InitTableList(PGLOBAL g); - bool TestFil(PGLOBAL g, PFIL filp, PTBL tblp); + bool TestFil(PGLOBAL g, PFIL filp, PTABLE tabp); // Members PTABLE Tablist; // Points to the table list PTABLE CurTable; // Points to the current table - PTDBASE Tdbp; // Current table PTDB bool Accept; // TRUE if bad tables are accepted int Maxerr; // Maximum number of bad tables - int Nbf; // Number of bad connections + int Nbc; // Number of bad connections int Rows; // Used for RowID int Crp; // Used for CurPos }; // end of class TDBTBL -/***********************************************************************/ -/* Class TBLCOL: TBL access method column descriptor. */ -/* This A.M. is used for TBL tables. */ -/***********************************************************************/ -class DllExport TBLCOL : public COLBLK { - friend class TDBTBL; - public: - // Constructors - TBLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "TBL"); - TBLCOL(TBLCOL *colp, PTDB tdbp); // Constructor used in copy process -//TBLCOL(SPCBLK *colp, PTDB tdbp); // Constructor used for pseudo columns - - // Implementation - virtual int GetAmType(void) {return TYPE_AM_TBL;} - - // Methods - virtual bool IsSpecial(void) {return Pseudo;} - virtual void ReadColumn(PGLOBAL g); -//virtual void WriteColumn(PGLOBAL g); -// void Print(PGLOBAL g, FILE *, UINT); - bool Init(PGLOBAL g); - - protected: - // Default constructor not to be used - TBLCOL(void) {} - - // Members - PCOL Colp; // Points to matching table column - PVAL To_Val; // To the matching column value - bool Pseudo; // TRUE for special columns - int Colnum; // Used when retrieving columns by number - }; // end of class TBLCOL - /***********************************************************************/ /* Class TBTBLK: TDBPLG TABID special column descriptor. */ /***********************************************************************/ @@ -160,3 +122,47 @@ class TBTBLK : public TIDBLK { protected: // Must not have additional members }; // end of class TBTBLK + +/***********************************************************************/ +/* This is the TBM Access Method class declaration. */ +/***********************************************************************/ +class DllExport TDBTBM : public TDBTBL { + friend class TBTBLK; + public: + // Constructor + TDBTBM(PTBLDEF tdp = NULL); + + // Implementation +//virtual AMT GetAmType(void) {return TYPE_AM_TBL;} + + // Methods + virtual void ResetDB(void); +//virtual int GetRecpos(void) {return Rows;} +//virtual int GetBadLines(void) {return (int)Nbc;} + + // Database routines +//virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); + virtual int GetMaxSize(PGLOBAL g) {return 10;} // Temporary + virtual int RowNumber(PGLOBAL g, bool b = FALSE); +//virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL scp); + virtual bool OpenDB(PGLOBAL g); + virtual int ReadDB(PGLOBAL g); + + protected: + // Internal functions +//bool InitTableList(PGLOBAL g); +//bool TestFil(PGLOBAL g, PFIL filp, PTABLE tabp); + bool OpenTables(PGLOBAL g); + int ReadNextRemote(PGLOBAL g); + + // Members + PTBMT Tmp; // To data table TBMT structures + PTBMT Cmp; // Current data table PLGF (to move to TDBTBL) + PTBMT Bmp; // To bad (unconnected) PLGF structures + bool Done; // TRUE after first GetAllResults + int Nrc; // Number of remote connections + int Nlc; // Number of local connections + }; // end of class TDBTBM + + +pthread_handler_t ThreadOpen(void *p); diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp new file mode 100644 index 00000000000..6e5f6784d3a --- /dev/null +++ b/storage/connect/tabutil.cpp @@ -0,0 +1,626 @@ +/************* Tabutil cpp Declares Source Code File (.CPP) ************/ +/* Name: TABUTIL.CPP Version 1.0 */ +/* */ +/* (C) Copyright to the author Olivier BERTRAND 2013 */ +/* */ +/* Utility function used by the PROXY, XCOL, OCCUR, and TBL tables. */ +/***********************************************************************/ + +/***********************************************************************/ +/* Include relevant section of system dependant header files. */ +/***********************************************************************/ +#include "my_global.h" +#include "sql_class.h" +#include "table.h" +#include "field.h" +#if defined(WIN32) +#include +#include +#if defined(__BORLANDC__) +#define __MFC_COMPAT__ // To define min/max as macro +#endif +//#include +#else +#if defined(UNIX) +#include +#include +#include +#include +#include +#include "osutil.h" +#else +//#include +#endif +//#include +#endif + +/***********************************************************************/ +/* Include application header files: */ +/***********************************************************************/ +#include "table.h" // MySQL table definitions +#include "global.h" +#include "plgdbsem.h" +#include "plgcnx.h" // For DB types +#include "myutil.h" +#include "mycat.h" +#include "valblk.h" +#include "resource.h" +#include "reldef.h" +#include "xtable.h" +#if defined(MYSQL_SUPPORT) +#include "tabmysql.h" +#endif // MYSQL_SUPPORT +#include "tabcol.h" +#include "tabutil.h" +#include "ha_connect.h" + +extern "C" int trace; + +/************************************************************************/ +/* Used by MYSQL tables to get MySQL parameters from the calling proxy */ +/* table (PROXY, TBL, XCL, or OCCUR) when used by one of these. */ +/************************************************************************/ +void Remove_tshp(PCATLG cat) +{ + ((MYCAT*)cat)->GetHandler()->tshp = NULL; +} // end of Remove_thsp + +/************************************************************************/ +/* GetTableShare: allocates and open a table share. */ +/************************************************************************/ +TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db, + const char *name, bool& mysql) +{ + char key[256]; + uint k; +//TABLE_LIST table_list; + TABLE_SHARE *s; + +//table_list.init_one_table(db, strlen(db), name, strlen(name), +// NULL, TL_IGNORE); + k = sprintf(key, "%s", db) + 1; + k += sprintf(key + k, "%s", name); + key[++k] = 0; + + if (!(s = alloc_table_share(db, name, key, ++k))) { + strcpy(g->Message, "Error allocating share\n"); + return NULL; + } // endif s + +// 1 2 4 8 +//flags = GTS_TABLE | GTS_VIEW | GTS_NOLOCK | GTS_FORCE_DISCOVERY; + + if (!open_table_def(thd, s, GTS_TABLE | GTS_VIEW)) { + if (!s->is_view) { + if (stricmp(plugin_name(s->db_plugin)->str, "connect")) { +#if defined(MYSQL_SUPPORT) + mysql = true; +#else // !MYSQL_SUPPORT + sprintf(g->Message, "%s.%s is not a CONNECT table", db, name); + return NULL; +#endif // MYSQL_SUPPORT + } else + mysql = false; + + } else { + mysql = true; + } // endif is_view + + } else { + sprintf(g->Message, "Error %d opening share\n", s->error); + free_table_share(s); + return NULL; + } // endif open_table_def + + return s; +} // end of GetTableShare + +/************************************************************************/ +/* TabColumns: constructs the result blocks containing all the columns */ +/* of the object table that will be retrieved by GetData commands. */ +/************************************************************************/ +PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, + const char *name, bool& info) + { + static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, + TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_SHORT, + TYPE_STRING, TYPE_STRING, TYPE_STRING}; + static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, + FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL, + FLD_REM, FLD_NO, FLD_CHARSET}; + static unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 256, 32, 32}; + char *fld, *fmt; + int i, n, ncol = sizeof(buftyp) / sizeof(int); + int len, type, prec; + bool mysql; + TABLE_SHARE *s = NULL; + Field* *field; + Field *fp; + PQRYRES qrp; + PCOLRES crp; + + if (!info) { + if (!(s = GetTableShare(g, thd, db, name, mysql))) { + return NULL; + } else if (s->is_view) { + strcpy(g->Message, "Use MYSQL type to see columns from a view"); + info = true; // To tell caller name is a view + free_table_share(s); + return NULL; + } else + n = s->fieldnames.count; + + } else { + n = 0; + length[0] = 128; + } // endif info + + /**********************************************************************/ + /* Allocate the structures used to refer to the result set. */ + /**********************************************************************/ + qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, + buftyp, fldtyp, length, true, true); + + // Some columns must be renamed + for (i = 0, crp = qrp->Colresp; crp; crp = crp->Next) + switch (++i) { + case 10: crp->Name = "Date_fmt"; break; + case 11: crp->Name = "Collation"; break; + } // endswitch i + + if (info) + return qrp; + + /**********************************************************************/ + /* Now get the results into blocks. */ + /**********************************************************************/ + for (i = 0, field= s->field; *field; i++, field++) { + fp= *field; + + // Get column name + crp = qrp->Colresp; // Column_Name + fld = (char *)fp->field_name; + crp->Kdata->SetValue(fld, i); + + if ((type = MYSQLtoPLG(fp->type())) == TYPE_ERROR) { + sprintf(g->Message, "Unsupported column type %s", GetTypeName(type)); + qrp = NULL; + break; + } // endif type + + crp = crp->Next; // Data_Type + crp->Kdata->SetValue(type, i); + crp = crp->Next; // Type_Name + crp->Kdata->SetValue(GetTypeName(type), i); + + if (type == TYPE_DATE) { + // When creating tables we do need info about date columns + if (mysql) { + fmt = MyDateFmt(fp->type()); + len = strlen(fmt); + } else { + fmt = (char*)fp->option_struct->dateformat; + len = fp->field_length; + } // endif mysql + + } else { + fmt = NULL; + len = fp->char_length(); + } // endif type + + crp = crp->Next; // Precision + crp->Kdata->SetValue(len, i); + + crp = crp->Next; // Length + len = fp->field_length; + crp->Kdata->SetValue(len, i); + + prec = (type == TYPE_FLOAT) ? fp->decimals() : 0; + crp = crp->Next; // Scale + crp->Kdata->SetValue(prec, i); + + crp = crp->Next; // Radix + crp->Kdata->SetValue(0, i); + + crp = crp->Next; // Nullable + crp->Kdata->SetValue((fp->null_ptr != 0) ? 1 : 0, i); + + crp = crp->Next; // Remark + fld = fp->comment.str; + crp->Kdata->SetValue(fld, fp->comment.length, i); + + crp = crp->Next; // New + crp->Kdata->SetValue((fmt) ? fmt : (char*) "", i); + + crp = crp->Next; // New (charset) + fld = (char *)fp->charset()->name; + crp->Kdata->SetValue(fld, i); + + // Add this item + qrp->Nblin++; + } // endfor field + + /**********************************************************************/ + /* Return the result pointer for use by GetData routines. */ + /**********************************************************************/ + if (s) + free_table_share(s); + + return qrp; + } // end of TabColumns + +/* -------------- Implementation of the PROXY classes ---------------- */ + +/***********************************************************************/ +/* PRXDEF constructor. */ +/***********************************************************************/ +PRXDEF::PRXDEF(void) + { + Tablep = NULL; + Pseudo = 3; +} // end of PRXDEF constructor + +/***********************************************************************/ +/* DefineAM: define specific AM block values from XCOL file. */ +/***********************************************************************/ +bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) + { + char *pn, *db, *tab, *def = NULL; + + db = Cat->GetStringCatInfo(g, "Dbname", "*"); + def = Cat->GetStringCatInfo(g, "Srcdef", NULL); + + if (!(tab = Cat->GetStringCatInfo(g, "Tabname", NULL))) { + if (!def) { + strcpy(g->Message, "Missing object table definition"); + return TRUE; + } else + tab = "Noname"; + + } else + // Analyze the table name, it may have the format: [dbname.]tabname + if ((pn = strchr(tab, '.'))) { + *pn++ = 0; + db = tab; + tab = pn; + } // endif pn + + Tablep = new(g) XTAB(tab, def); + Tablep->SetQualifier(db); + return FALSE; + } // end of DefineAM + +/***********************************************************************/ +/* GetTable: makes a new TDB of the proper type. */ +/***********************************************************************/ +PTDB PRXDEF::GetTable(PGLOBAL g, MODE mode) + { + if (Catfunc == FNC_COL) + return new(g) TDBTBC(this); + else + return new(g) TDBPRX(this); + + } // end of GetTable + +/* ------------------------------------------------------------------- */ + +/***********************************************************************/ +/* Implementation of the TDBPRX class. */ +/***********************************************************************/ +TDBPRX::TDBPRX(PPRXDEF tdp) : TDBASE(tdp) + { + Tdbp = NULL; // The object table + } // end of TDBPRX constructor + +/***********************************************************************/ +/* Get the PTDB of the sub-table. */ +/***********************************************************************/ +PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) + { + const char *sp = NULL; + char *db, *name; + bool mysql = true; + PTDB tdbp = NULL; + TABLE_SHARE *s = NULL; + Field* *fp = NULL; + PCATLG cat = To_Def->GetCat(); + PHC hc = ((MYCAT*)cat)->GetHandler(); + LPCSTR cdb, curdb = hc->GetDBName(NULL); + THD *thd = (hc->GetTable())->in_use; + + db = (char*)tabp->GetQualifier(); + name = (char*)tabp->GetName(); + + // Check for eventual loop + for (PTABLE tp = To_Table; tp; tp = tp->Next) { + cdb = (tp->Qualifier) ? tp->Qualifier : curdb; + + if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) { + sprintf(g->Message, "Table %s.%s pointing on itself", db, name); + return NULL; + } // endif + + } // endfor tp + + if (!tabp->GetSrc()) { + if (!(s = GetTableShare(g, thd, db, name, mysql))) + return NULL; + + if (s->is_view && !b) + s->field = hc->get_table()->s->field; + + hc->tshp = s; + } else if (b) { + // Don't use caller's columns + fp = hc->get_table()->field; + hc->get_table()->field = NULL; + + // Make caller use the source definition + sp = hc->get_table()->s->option_struct->srcdef; + hc->get_table()->s->option_struct->srcdef = tabp->GetSrc(); + } // endif srcdef + + if (mysql) { +#if defined(MYSQL_SUPPORT) + // Access sub-table via MySQL API + if (!(tdbp= cat->GetTable(g, tabp, MODE_READ, "MYPRX"))) { + sprintf(g->Message, "Cannot access %s.%s", db, name); + goto err; + } // endif Define + + if (db) + ((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier()); + +#else // !MYSQL_SUPPORT + sprintf(g->Message, "%s.%s is not a CONNECT table", + db, tblp->Name); + goto err; +#endif // MYSQL_SUPPORT + } else { + // Sub-table is a CONNECT table + tabp->Next = To_Table; // For loop checking + tdbp = cat->GetTable(g, tabp); + } // endif mysql + + if (s) { + if (s->is_view && !b) + s->field = NULL; + + hc->tshp = NULL; + } else if (b) { + // Restore s structure that can be in cache + hc->get_table()->field = fp; + hc->get_table()->s->option_struct->srcdef = sp; + } // endif s + + if (trace && tdbp) + htrc("Subtable %s in %s\n", + name, SVP(((PTDBASE)tdbp)->GetDef()->GetDB())); + + err: + if (s) + free_table_share(s); + + return (PTDBASE)tdbp; + } // end of GetSubTable + +/***********************************************************************/ +/* Initializes the table. */ +/***********************************************************************/ +bool TDBPRX::InitTable(PGLOBAL g) + { + if (!Tdbp) { + // Get the table description block of this table + if (!(Tdbp = GetSubTable(g, ((PPRXDEF)To_Def)->Tablep))) + return TRUE; + + } // endif Tdbp + + return FALSE; + } // end of InitTable + +/***********************************************************************/ +/* Allocate PRX column description block. */ +/***********************************************************************/ +PCOL TDBPRX::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) + { + return new(g) PRXCOL(cdp, this, cprec, n); + } // end of MakeCol + +/***********************************************************************/ +/* PRX GetMaxSize: returns the maximum number of rows in the table. */ +/***********************************************************************/ +int TDBPRX::GetMaxSize(PGLOBAL g) + { + if (MaxSize < 0) { + if (InitTable(g)) + return 0; + + MaxSize = Tdbp->GetMaxSize(g); + } // endif MaxSize + + return MaxSize; + } // end of GetMaxSize + +/***********************************************************************/ +/* In this sample, ROWID will be the (virtual) row number, */ +/* while ROWNUM will be the occurence rank in the multiple column. */ +/***********************************************************************/ +int TDBPRX::RowNumber(PGLOBAL g, bool b) + { + return Tdbp->RowNumber(g, b); + } // end of RowNumber + +/***********************************************************************/ +/* PROXY Access Method opening routine. */ +/***********************************************************************/ +bool TDBPRX::OpenDB(PGLOBAL g) + { + if (Use == USE_OPEN) { + /*******************************************************************/ + /* Table already open, just replace it at its beginning. */ + /*******************************************************************/ + return Tdbp->OpenDB(g); + } // endif use + + if (Mode != MODE_READ) { + /*******************************************************************/ + /* Currently XCOL tables cannot be modified. */ + /*******************************************************************/ + strcpy(g->Message, "PROXY tables are read only"); + return TRUE; + } // endif Mode + + if (InitTable(g)) + return TRUE; + + /*********************************************************************/ + /* Check and initialize the subtable columns. */ + /*********************************************************************/ + for (PCOL cp = Columns; cp; cp = cp->GetNext()) + if (((PPRXCOL)cp)->Init(g)) + return TRUE; + + /*********************************************************************/ + /* Physically open the object table. */ + /*********************************************************************/ + if (Tdbp->OpenDB(g)) + return TRUE; + + return FALSE; + } // end of OpenDB + +/***********************************************************************/ +/* Data Base read routine for PROY access method. */ +/***********************************************************************/ +int TDBPRX::ReadDB(PGLOBAL g) + { + /*********************************************************************/ + /* Now start the reading process. */ + /*********************************************************************/ + return Tdbp->ReadDB(g); + } // end of ReadDB + +/***********************************************************************/ +/* WriteDB: Data Base write routine for PROXY access methods. */ +/***********************************************************************/ +int TDBPRX::WriteDB(PGLOBAL g) + { + sprintf(g->Message, "%s tables are read only", To_Def->GetType()); + return RC_FX; + } // end of WriteDB + +/***********************************************************************/ +/* Data Base delete line routine for PROXY access methods. */ +/***********************************************************************/ +int TDBPRX::DeleteDB(PGLOBAL g, int irc) + { + sprintf(g->Message, "Delete not enabled for %s tables", + To_Def->GetType()); + return RC_FX; + } // end of DeleteDB + +/***********************************************************************/ +/* Used by the TBL tables. */ +/***********************************************************************/ +void TDBPRX::RemoveNext(PTABLE tp) + { + tp->Next = NULL; + } // end of RemoveNext + +/* ---------------------------- PRXCOL ------------------------------- */ + +/***********************************************************************/ +/* PRXCOL public constructor. */ +/***********************************************************************/ +PRXCOL::PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am) + : COLBLK(cdp, tdbp, i) + { + if (cprec) { + Next = cprec->GetNext(); + cprec->SetNext(this); + } else { + Next = tdbp->GetColumns(); + tdbp->SetColumns(this); + } // endif cprec + + // Set additional Dos access method information for column. + Long = cdp->GetLong(); // Useful ??? +//strcpy(F_Date, cdp->F_Date); + Colp = NULL; + To_Val = NULL; + Pseudo = FALSE; + Colnum = cdp->GetOffset(); // If columns are retrieved by number + + if (trace) + htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); + + } // end of PRXCOL constructor + +/***********************************************************************/ +/* PRXCOL initialization routine. */ +/* Look for the matching column in the object table. */ +/***********************************************************************/ +bool PRXCOL::Init(PGLOBAL g) + { + PTDBPRX tdbp = (PTDBPRX)To_Tdb; + + if (!(Colp = tdbp->Tdbp->ColDB(g, Name, 0)) && Colnum) + Colp = tdbp->Tdbp->ColDB(g, NULL, Colnum); + + if (Colp) { + // May not have been done elsewhere + Colp->InitValue(g); + To_Val = Colp->GetValue(); + + // this may be needed by some tables (which?) + Colp->SetColUse(ColUse); + } else { + sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tdbp->Tdbp->GetName()); + return TRUE; + } // endif Colp + + return FALSE; + } // end of Init + +/***********************************************************************/ +/* ReadColumn: */ +/***********************************************************************/ +void PRXCOL::ReadColumn(PGLOBAL g) + { + if (trace) + htrc("PRX ReadColumn: name=%s\n", Name); + + if (Colp) { + Colp->ReadColumn(g); + Value->SetValue_pval(To_Val); + + // Set null when applicable + if (Nullable) + Value->SetNull(Value->IsNull()); + + } // endif Colp + + } // end of ReadColumn + +/* ---------------------------TDBTBC class --------------------------- */ + +/***********************************************************************/ +/* TDBTBC class constructor. */ +/***********************************************************************/ +TDBTBC::TDBTBC(PPRXDEF tdp) : TDBCAT(tdp) + { + Db = (PSZ)tdp->Tablep->GetQualifier(); + Tab = (PSZ)tdp->Tablep->GetName(); + } // end of TDBTBC constructor + +/***********************************************************************/ +/* GetResult: Get the list the MYSQL table columns. */ +/***********************************************************************/ +PQRYRES TDBTBC::GetResult(PGLOBAL g) + { + bool b = false; + + return TabColumns(g, current_thd, Db, Tab, b); + } // end of GetResult + diff --git a/storage/connect/tabutil.h b/storage/connect/tabutil.h new file mode 100644 index 00000000000..ddf6c2eb601 --- /dev/null +++ b/storage/connect/tabutil.h @@ -0,0 +1,141 @@ +// TABUTIL.H Olivier Bertrand 2013 +// Defines the TAB catalog tables + +#ifndef TABUTIL +#define TABUTIL 1 + +//#include "tabtbl.h" + +#define TYPE_AM_PRX (AMT)129 + +typedef class PRXDEF *PPRXDEF; +typedef class TDBPRX *PTDBPRX; +typedef class XXLCOL *PXXLCOL; +typedef class PRXCOL *PPRXCOL; +typedef class TBCDEF *PTBCDEF; +typedef class TDBTBC *PTDBTBC; + +TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db, + const char *name, bool& mysql); +PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, + const char *name, bool& info); + +void Remove_tshp(PCATLG cat); + +/* -------------------------- PROXY classes -------------------------- */ + +/***********************************************************************/ +/* PROXY: table based on another table. Can be used to have a */ +/* different view on an existing table. */ +/* However, its real use is to be the base of TBL and PRX tables. */ +/***********************************************************************/ + +/***********************************************************************/ +/* PRX table. */ +/***********************************************************************/ +class DllExport PRXDEF : public TABDEF { /* Logical table description */ + friend class TDBPRX; + friend class TDBTBC; + public: + // Constructor + PRXDEF(void); + + // Implementation + virtual const char *GetType(void) {return "PRX";} + + // Methods + virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); + virtual PTDB GetTable(PGLOBAL g, MODE mode); + + protected: + // Members + PTABLE Tablep; /* The object table */ + }; // end of PRXDEF + +/***********************************************************************/ +/* This is the class declaration for the XCSV table. */ +/***********************************************************************/ +class DllExport TDBPRX : public TDBASE { +//friend class MULINDX; + friend class PRXDEF; + friend class PRXCOL; + public: + // Constructor + TDBPRX(PPRXDEF tdp); + + // Implementation + virtual AMT GetAmType(void) {return TYPE_AM_PRX;} + + // Methods + virtual int GetRecpos(void) {return Tdbp->GetRecpos();} + virtual void ResetDB(void) {Tdbp->ResetDB();} + virtual int RowNumber(PGLOBAL g, bool b = FALSE); + + // Database routines + virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); + virtual bool InitTable(PGLOBAL g); + virtual int GetMaxSize(PGLOBAL g); + virtual bool OpenDB(PGLOBAL g); + virtual int ReadDB(PGLOBAL g); + virtual int WriteDB(PGLOBAL g); + virtual int DeleteDB(PGLOBAL g, int irc); + virtual void CloseDB(PGLOBAL g) {if (Tdbp) Tdbp->CloseDB(g);} + PTDBASE GetSubTable(PGLOBAL g, PTABLE tabp, bool b = false); + void RemoveNext(PTABLE tp); + + protected: + // Members + PTDBASE Tdbp; // The object table + }; // end of class TDBPRX + +/***********************************************************************/ +/* Class PRXCOL: PRX access method column descriptor. */ +/* This A.M. is used for PRX tables. */ +/***********************************************************************/ +class DllExport PRXCOL : public COLBLK { + friend class TDBPRX; + friend class TDBTBL; + friend class TDBOCCUR; + public: + // Constructors + PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "PRX"); + + // Implementation + virtual int GetAmType(void) {return TYPE_AM_PRX;} + + // Methods + virtual bool IsSpecial(void) {return Pseudo;} + virtual void ReadColumn(PGLOBAL g); + bool Init(PGLOBAL g); + + protected: + // Default constructor not to be used + PRXCOL(void) {} + + // Members + PCOL Colp; // Points to matching table column + PVAL To_Val; // To the matching column value + bool Pseudo; // TRUE for special columns + int Colnum; // Used when retrieving columns by number + }; // end of class PRXCOL + +/***********************************************************************/ +/* This is the class declaration for the TBC column catalog table. */ +/***********************************************************************/ +class TDBTBC : public TDBCAT { + public: + // Constructors + TDBTBC(PPRXDEF tdp); +//TDBTBC(PTBLDEF tdp); +//TDBTBC(PXCLDEF tdp); + + protected: + // Specific routines + virtual PQRYRES GetResult(PGLOBAL g); + + // Members + PSZ Db; // Database of the table + PSZ Tab; // Table name + }; // end of class TDBMCL + +#endif // TABUTIL diff --git a/storage/connect/tabvct.cpp b/storage/connect/tabvct.cpp index 7a16d2baf0c..8c2474d61a2 100644 --- a/storage/connect/tabvct.cpp +++ b/storage/connect/tabvct.cpp @@ -49,7 +49,6 @@ #include #include #include -//#define strerror(X) _strerror(X) #define NO_ERROR 0 #else #include diff --git a/storage/connect/tabwmi.cpp b/storage/connect/tabwmi.cpp index d89d61dc11c..dbd4330a2f9 100644 --- a/storage/connect/tabwmi.cpp +++ b/storage/connect/tabwmi.cpp @@ -135,14 +135,12 @@ PWMIUT InitWMI(PGLOBAL g, char *nsp, char *classname) /***********************************************************************/ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info) { - static int dbtype[] = {DB_CHAR, DB_SHORT, DB_CHAR, - DB_INT, DB_INT, DB_SHORT}; static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT}; static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, FLD_LENGTH, FLD_SCALE}; static unsigned int len, length[] = {0, 6, 8, 10, 10, 6}; - int i = 0, n = 0, ncol = sizeof(dbtype) / sizeof(int); + int i = 0, n = 0, ncol = sizeof(buftyp) / sizeof(int); int lng, typ, prec; LONG low, upp; BSTR propname; @@ -213,7 +211,7 @@ PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info) /* Allocate the structures used to refer to the result set. */ /*********************************************************************/ qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, - dbtype, buftyp, fldtyp, length, true, true); + buftyp, fldtyp, length, true, true); if (info) return qrp; diff --git a/storage/connect/tabxcl.cpp b/storage/connect/tabxcl.cpp new file mode 100644 index 00000000000..96da0571271 --- /dev/null +++ b/storage/connect/tabxcl.cpp @@ -0,0 +1,283 @@ +/************* TabXcl CPP Declares Source Code File (.CPP) *************/ +/* Name: TABXCL.CPP Version 1.0 */ +/* */ +/* (C) Copyright to the author Olivier BERTRAND 2013 */ +/* */ +/* XCOL: Table having one column containing several values */ +/* comma separated. When creating the table, the name of the X */ +/* column is given by the Name option. */ +/* This first version has one limitation: */ +/* - The X column has the same length than in the physical file. */ +/* This tables produces as many rows for a physical row than the */ +/* number of items in the X column (eventually 0). */ +/***********************************************************************/ + +/***********************************************************************/ +/* Include relevant section of system dependant header files. */ +/***********************************************************************/ +#include "my_global.h" +#if defined(WIN32) +#include +#include +#if defined(__BORLANDC__) +#define __MFC_COMPAT__ // To define min/max as macro +#endif +//#include +#else +#if defined(UNIX) +#include +#include +#include +#include +#include +#include "osutil.h" +#else +//#include +#endif +//#include +#endif + +/***********************************************************************/ +/* Include application header files: */ +/***********************************************************************/ +#include "table.h" // MySQL table definitions +#include "global.h" +#include "plgdbsem.h" +#include "plgcnx.h" // For DB types +#include "resource.h" +#include "reldef.h" +#include "filamtxt.h" +#include "tabdos.h" +#include "tabcol.h" +#include "tabxcl.h" +#include "xtable.h" +#if defined(MYSQL_SUPPORT) +#include "tabmysql.h" +#endif // MYSQL_SUPPORT +#include "ha_connect.h" +#include "mycat.h" + +extern "C" int trace; + +/* -------------- Implementation of the XCOL classes ---------------- */ + +/***********************************************************************/ +/* XCLDEF constructor. */ +/***********************************************************************/ +XCLDEF::XCLDEF(void) + { + Xcol = NULL; + Sep = ','; + Mult = 10; +} // end of XCLDEF constructor + +/***********************************************************************/ +/* DefineAM: define specific AM block values from XCOL table. */ +/***********************************************************************/ +bool XCLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) + { + char buf[8]; + + Xcol = Cat->GetStringCatInfo(g, "Colname", ""); + Cat->GetCharCatInfo("Separator", ",", buf, sizeof(buf)); + Sep = (strlen(buf) == 2 && buf[0] == '\\' && buf[1] == 't') ? '\t' : *buf; + Mult = Cat->GetIntCatInfo("Mult", 10); + return PRXDEF::DefineAM(g, am, poff); + } // end of DefineAM + +/***********************************************************************/ +/* GetTable: makes a new TDB of the proper type. */ +/***********************************************************************/ +PTDB XCLDEF::GetTable(PGLOBAL g, MODE mode) + { + if (Catfunc == FNC_COL) + return new(g) TDBTBC(this); + else + return new(g) TDBXCL(this); + + } // end of GetTable + +/* ------------------------------------------------------------------- */ + +/***********************************************************************/ +/* Implementation of the TDBXCL class. */ +/***********************************************************************/ +TDBXCL::TDBXCL(PXCLDEF tdp) : TDBPRX(tdp) + { + Xcolumn = tdp->Xcol; // CSV column name + Xcolp = NULL; // To the XCLCOL column + Mult = tdp->Mult; // Multiplication factor + N = 0; // The current table index + M = 0; // The occurence rank + RowFlag = 0; // 0: Ok, 1: Same, 2: Skip + New = TRUE; // TRUE for new line + Sep = tdp->Sep; // The Xcol separator + } // end of TDBXCL constructor + +/***********************************************************************/ +/* Allocate XCL column description block. */ +/***********************************************************************/ +PCOL TDBXCL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) + { + PCOL colp; + + if (!stricmp(cdp->GetName(), Xcolumn)) { + Xcolp = new(g) XCLCOL(g, cdp, this, cprec, n); + colp = Xcolp; + } else + colp = new(g) PRXCOL(cdp, this, cprec, n); + + return colp; + } // end of MakeCol + +/***********************************************************************/ +/* XCL GetMaxSize: returns the maximum number of rows in the table. */ +/***********************************************************************/ +int TDBXCL::GetMaxSize(PGLOBAL g) + { + if (MaxSize < 0) { + if (InitTable(g)) + return 0; + + MaxSize = Mult * Tdbp->GetMaxSize(g); + } // endif MaxSize + + return MaxSize; + } // end of GetMaxSize + +/***********************************************************************/ +/* For this table type, ROWID is the (virtual) row number, */ +/* while ROWNUM is be the occurence rank in the multiple column. */ +/***********************************************************************/ +int TDBXCL::RowNumber(PGLOBAL g, bool b) + { + return (b) ? M : N; + } // end of RowNumber + +/***********************************************************************/ +/* XCL Access Method opening routine. */ +/***********************************************************************/ +bool TDBXCL::OpenDB(PGLOBAL g) + { + if (Use == USE_OPEN) { + /*******************************************************************/ + /* Table already open, just replace it at its beginning. */ + /*******************************************************************/ + M = N = 0; + RowFlag = 0; + New = TRUE; + return Tdbp->OpenDB(g); + } // endif use + + if (Mode != MODE_READ) { + /*******************************************************************/ + /* Currently XCOL tables cannot be modified. */ + /*******************************************************************/ + strcpy(g->Message, "XCOL tables are read only"); + return TRUE; + } // endif Mode + + if (InitTable(g)) + return TRUE; + + /*********************************************************************/ + /* Check and initialize the subtable columns. */ + /*********************************************************************/ + for (PCOL cp = Columns; cp; cp = cp->GetNext()) + if (((PXCLCOL)cp)->Init(g)) + return TRUE; + + /*********************************************************************/ + /* Physically open the object table. */ + /*********************************************************************/ + if (Tdbp->OpenDB(g)) + return TRUE; + + return FALSE; + } // end of OpenDB + +/***********************************************************************/ +/* Data Base read routine for XCL access method. */ +/***********************************************************************/ +int TDBXCL::ReadDB(PGLOBAL g) + { + int rc = RC_OK; + + /*********************************************************************/ + /* Now start the multi reading process. */ + /*********************************************************************/ + do { + if (RowFlag != 1) { + if ((rc = Tdbp->ReadDB(g)) != RC_OK) + break; + + New = TRUE; + M = 1; + } else { + New = FALSE; + M++; + } // endif RowFlag + + if (Xcolp) { + RowFlag = 0; + Xcolp->ReadColumn(g); + } // endif Xcolp + + N++; + } while (RowFlag == 2); + + return rc; + } // end of ReadDB + + +// ------------------------ XCLCOL functions ---------------------------- + +/***********************************************************************/ +/* XCLCOL public constructor. */ +/***********************************************************************/ +XCLCOL::XCLCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) + : PRXCOL(cdp, tdbp, cprec, i, "XCL") + { + // Set additional XXL access method information for column. + Cbuf = (char*)PlugSubAlloc(g, NULL, Long + 1); + Cp = NULL; // Pointer to current position in Cbuf + Sep = ((PTDBXCL)tdbp)->Sep; + AddStatus(BUF_READ); // Only evaluated from TDBXCL::ReadDB + } // end of XCLCOL constructor + +/***********************************************************************/ +/* What this routine does is to get the comma-separated string */ +/* from the source table column, extract the single values and */ +/* set the flag for the table ReadDB function. */ +/***********************************************************************/ +void XCLCOL::ReadColumn(PGLOBAL g) + { + if (((PTDBXCL)To_Tdb)->New) { + Colp->ReadColumn(g); + strcpy(Cbuf, To_Val->GetCharValue()); + Cp = Cbuf; + } // endif New + + if (*Cp) { + PSZ p; + + // Trim left + for (p = Cp; *p == ' '; p++) ; + + if ((Cp = strchr(Cp, Sep))) + // Separator is found + *Cp++ = '\0'; + + Value->SetValue_psz(p); + } else if (Nullable) { + Value->Reset(); + Value->SetNull(true); + } else + // Skip that row + ((PTDBXCL)To_Tdb)->RowFlag = 2; + + if (Cp && *Cp) + // More to come from the same row + ((PTDBXCL)To_Tdb)->RowFlag = 1; + + } // end of ReadColumn diff --git a/storage/connect/tabxcl.h b/storage/connect/tabxcl.h new file mode 100644 index 00000000000..28fbf85d509 --- /dev/null +++ b/storage/connect/tabxcl.h @@ -0,0 +1,104 @@ +// TABXCL.H Olivier Bertrand 2013 +// Defines the XCOL tables + +#include "tabutil.h" + +#define TYPE_AM_XCOL (AMT)124 + +typedef class XCLDEF *PXCLDEF; +typedef class TDBXCL *PTDBXCL; +typedef class XCLCOL *PXCLCOL; + +/* -------------------------- XCOL classes --------------------------- */ + +/***********************************************************************/ +/* XCOL: table having one column containing several values comma */ +/* (or any other character) separated. When creating the table, the */ +/* name of the X column is given by the NAME option. */ +/* This sample has a limitation: */ +/* - The X column has the same length than in the physical file. */ +/* This tables produces as many rows for a physical row than the */ +/* number of items in the X column (eventually 0). */ +/***********************************************************************/ + +/***********************************************************************/ +/* XCL table. */ +/***********************************************************************/ +class XCLDEF : public PRXDEF { /* Logical table description */ + friend class TDBXCL; + public: + // Constructor + XCLDEF(void); + + // Implementation + virtual const char *GetType(void) {return "XCL";} + + // Methods + virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); + virtual PTDB GetTable(PGLOBAL g, MODE mode); + + protected: + // Members + char *Xcol; /* The column containing separated fields */ + char Sep; /* The field separator, defaults to comma */ + int Mult; /* Multiplication factor */ + }; // end of XCLDEF + +/***********************************************************************/ +/* This is the class declaration for the XCOL table. */ +/***********************************************************************/ +class TDBXCL : public TDBPRX { + friend class XCLDEF; + friend class PRXCOL; + friend class XCLCOL; + public: + // Constructor + TDBXCL(PXCLDEF tdp); + + // Implementation + virtual AMT GetAmType(void) {return TYPE_AM_XCOL;} + + // Methods + virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} + virtual int RowNumber(PGLOBAL g, bool b = FALSE); + + // Database routines + virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); + virtual int GetMaxSize(PGLOBAL g); + virtual bool OpenDB(PGLOBAL g); + virtual int ReadDB(PGLOBAL g); + + protected: + // Members + char *Xcolumn; // Multiple column name + PXCLCOL Xcolp; // To the XCVCOL column + int Mult; // Multiplication factor + int N; // The current table index + int M; // The occurence rank + BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip + bool New; // TRUE for new line + char Sep; // The Xcol separator + }; // end of class TDBXCL + +/***********************************************************************/ +/* Class XCLCOL: for the multiple CSV column. */ +/***********************************************************************/ +class XCLCOL : public PRXCOL { + friend class TDBXCL; + public: + // Constructors + XCLCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); + + // Methods + virtual void Reset(void) {} // Evaluated only by TDBXCL + virtual void ReadColumn(PGLOBAL g); + + protected: + // Default constructor not to be used + XCLCOL(void) {} + + // Members + char *Cbuf; // The column buffer + char *Cp; // Pointer to current position + char Sep; // The separator + }; // end of class XCLCOL diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index 9b8db7abbab..69ad6711638 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -547,6 +547,7 @@ bool TDBXML::Initialize(PGLOBAL g) else Nlist = TabNode->GetChildElements(g); + Docp->SetNofree(true); // For libxml2 #if defined(WIN32) } catch(_com_error e) { // We come here if a DOM command threw an error diff --git a/storage/connect/user_connect.cc b/storage/connect/user_connect.cc index 3fd3ac43e32..d85f11d1950 100644 --- a/storage/connect/user_connect.cc +++ b/storage/connect/user_connect.cc @@ -43,6 +43,7 @@ #include "osutil.h" #include "global.h" #include "plgdbsem.h" +#include "connect.h" #include "user_connect.h" #include "mycat.h" @@ -54,11 +55,6 @@ extern int xtrace; /****************************************************************************/ PCONNECT user_connect::to_users= NULL; -/****************************************************************************/ -/* CONNECT functions called externally. */ -/****************************************************************************/ -PGLOBAL CntExit(PGLOBAL g); - /* -------------------------- class user_connect -------------------------- */ /****************************************************************************/ diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp index a56841d8980..cee4571bc0d 100644 --- a/storage/connect/valblk.cpp +++ b/storage/connect/valblk.cpp @@ -266,7 +266,7 @@ char TYPBLK::GetTypedValue(PVAL valp) {return valp->GetTinyValue();} /***********************************************************************/ -/* Set one value in a block. */ +/* Set one value in a block from a zero terminated string. */ /***********************************************************************/ template void TYPBLK::SetValue(PSZ p, int n) @@ -294,6 +294,22 @@ double TYPBLK::GetTypedValue(PSZ p) {return atof(p);} template <> char TYPBLK::GetTypedValue(PSZ p) {return (char)atoi(p);} +/***********************************************************************/ +/* Set one value in a block from an array of characters. */ +/***********************************************************************/ +template +void TYPBLK::SetValue(char *sp, uint len, int n) + { + PGLOBAL& g = Global; + PSZ spz = (PSZ)PlugSubAlloc(g, NULL, 0); // Temporary + + if (sp) + memcpy(spz, sp, len); + + spz[len] = 0; + SetValue(spz, n); + } // end of SetValue + /***********************************************************************/ /* Set one value in a block from a value in another block. */ /***********************************************************************/ @@ -552,11 +568,19 @@ void CHRBLK::SetValue(PVAL valp, int n) } // end of SetValue /***********************************************************************/ -/* Set one value in a block. */ +/* Set one value in a block from a zero terminated string. */ /***********************************************************************/ void CHRBLK::SetValue(PSZ sp, int n) { - size_t len = (sp) ? strlen(sp) : 0; + uint len = (sp) ? strlen(sp) : 0; + SetValue(sp, len, n); + } // end of SetValue + +/***********************************************************************/ +/* Set one value in a block from an array of characters. */ +/***********************************************************************/ +void CHRBLK::SetValue(char *sp, uint len, int n) + { char *p = Chrp + n * Long; #if defined(_DEBUG) || defined(DEBTRACE) @@ -568,15 +592,16 @@ void CHRBLK::SetValue(PSZ sp, int n) #endif if (sp) - strncpy(p, sp, Long); - else - *p = '\0'; + memcpy(p, sp, Long); - if (Blanks) + if (Blanks) { // Suppress eventual ending zero and right fill with blanks for (register int i = len; i < Long; i++) p[i] = ' '; + } else if ((signed)len < Long) + p[len] = 0; + SetNull(n, false); } // end of SetValue @@ -629,8 +654,11 @@ void CHRBLK::SetValues(PVBLK pv, int k, int n) /***********************************************************************/ void CHRBLK::Move(int i, int j) { - memcpy(Chrp + j * Long, Chrp + i * Long, Long); - MoveNull(i, j); + if (i != j) { + memcpy(Chrp + j * Long, Chrp + i * Long, Long); + MoveNull(i, j); + } // endif i + } // end of Move /***********************************************************************/ @@ -801,12 +829,33 @@ void STRBLK::SetValue(PVAL valp, int n) } // end of SetValue /***********************************************************************/ -/* Set one value in a block. */ +/* Set one value in a block from a zero terminated string. */ /***********************************************************************/ void STRBLK::SetValue(PSZ p, int n) { - Strp[n] = (PSZ)PlugSubAlloc(Global, NULL, strlen(p) + 1); - strcpy(Strp[n], p); + if (p) { + Strp[n] = (PSZ)PlugSubAlloc(Global, NULL, strlen(p) + 1); + strcpy(Strp[n], p); + } else + Strp[n] = NULL; + + } // end of SetValue + +/***********************************************************************/ +/* Set one value in a block from an array of characters. */ +/***********************************************************************/ +void STRBLK::SetValue(char *sp, uint len, int n) + { + PSZ p; + + if (sp) { + p = (PSZ)PlugSubAlloc(Global, NULL, len + 1); + memcpy(p, sp, len); + p[len] = 0; + } else + p = NULL; + + Strp[n] = p; } // end of SetValue /***********************************************************************/ diff --git a/storage/connect/valblk.h b/storage/connect/valblk.h index 9a85577a104..d9286b72f9f 100644 --- a/storage/connect/valblk.h +++ b/storage/connect/valblk.h @@ -36,6 +36,7 @@ class VALBLK : public BLOCK { void *GetValPointer(void) {return Blkp;} void SetValPointer(void *mp) {Blkp = mp;} int GetType(void) {return Type;} + int GetPrec(void) {return Prec;} void SetCheck(bool b) {Check = b;} void MoveNull(int i, int j) {if (To_Nulls) To_Nulls[j] = To_Nulls[j];} @@ -64,6 +65,7 @@ class VALBLK : public BLOCK { virtual void SetValue(double fval, int n) {assert(false);} virtual void SetValue(char cval, int n) {assert(false);} virtual void SetValue(PSZ sp, int n) {assert(false);} + virtual void SetValue(char *sp, uint len, int n) {assert(false);} virtual void SetValue(PVAL valp, int n) = 0; virtual void SetValue(PVBLK pv, int n1, int n2) = 0; #if 0 @@ -109,7 +111,7 @@ class TYPBLK : public VALBLK { // Implementation virtual void Init(PGLOBAL g, bool check); - virtual int GetVlen(void) {return sizeof(int);} + virtual int GetVlen(void) {return sizeof(TYPE);} //virtual PSZ GetCharValue(int n); virtual short GetShortValue(int n) {return (short)Typp[n];} virtual int GetIntValue(int n) {return (int)Typp[n];} @@ -120,6 +122,7 @@ class TYPBLK : public VALBLK { // Methods virtual void SetValue(PSZ sp, int n); + virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(short sval, int n) {Typp[n] = (TYPE)sval; SetNull(n, false);} virtual void SetValue(int lval, int n) @@ -175,6 +178,7 @@ class CHRBLK : public VALBLK { // Methods virtual void SetValue(PSZ sp, int n); + virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVBLK pv, int n1, int n2); //virtual void SetValues(PVBLK pv, int k, int n); @@ -221,6 +225,7 @@ class STRBLK : public VALBLK { // Methods virtual void SetValue(PSZ sp, int n); + virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(PVAL valp, int n); virtual void SetValue(PVBLK pv, int n1, int n2); //virtual void SetValues(PVBLK pv, int k, int n); diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 9053658b461..e75a6e41557 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -88,12 +88,13 @@ PSZ strlwr(PSZ s); } #endif // !WIN32 +#ifdef NOT_USED /***********************************************************************/ /* Returns the bitmap representing the conditions that must not be */ /* met when returning from TestValue for a given operator. */ /* Bit one is EQ, bit 2 is LT, and bit 3 is GT. */ /***********************************************************************/ -BYTE OpBmp(PGLOBAL g, OPVAL opc) +static BYTE OpBmp(PGLOBAL g, OPVAL opc) { BYTE bt; @@ -113,6 +114,7 @@ BYTE OpBmp(PGLOBAL g, OPVAL opc) return bt; } // end of OpBmp +#endif /***********************************************************************/ /* GetTypeName: returns the PlugDB internal type name. */ @@ -154,46 +156,6 @@ int GetTypeSize(int type, int len) return len; } // end of GetTypeSize -/***********************************************************************/ -/* GetPLGType: returns the PlugDB type corresponding to a DB type. */ -/***********************************************************************/ -int GetPLGType(int type) - { - int tp; - - switch (type) { - case DB_CHAR: - case DB_STRING: tp = TYPE_STRING; break; - case DB_SHORT: tp = TYPE_SHORT; break; - case DB_INT: tp = TYPE_INT; break; - case DB_DOUBLE: tp = TYPE_FLOAT; break; - case DB_DATE: tp = TYPE_DATE; break; - default: tp = TYPE_ERROR; - } // endswitch type - - return tp; - } // end of GetPLGType - -/***********************************************************************/ -/* GetDBType: returns the DB type corresponding to a PlugDB type. */ -/***********************************************************************/ -int GetDBType(int type) - { - int tp; - - switch (type) { - case TYPE_STRING: tp = DB_CHAR; break; - case TYPE_SHORT: tp = DB_SHORT; break; - case TYPE_INT: tp = DB_INT; break; - case TYPE_BIGINT: - case TYPE_FLOAT: tp = DB_DOUBLE; break; - case TYPE_DATE: tp = DB_DATE; break; - default: tp = DB_ERROR; - } // endswitch type - - return tp; - } // end of GetPLGType - /***********************************************************************/ /* GetFormatType: returns the FORMAT character(s) according to type. */ /***********************************************************************/ @@ -606,7 +568,7 @@ void TYPVAL::SetValue_char(char *p, int n) if (minus && Tval) Tval = - Tval; - if (trace) + if (trace > 1) htrc(strcat(strcat(strcpy(buf, " setting %s to: "), Fmt), "\n"), GetTypeName(Type), Tval); @@ -616,19 +578,25 @@ void TYPVAL::SetValue_char(char *p, int n) template <> void TYPVAL::SetValue_char(char *p, int n) { - char *p2, buf[32]; + if (p) { + char *p2, buf[32]; - for (p2 = p + n; p < p2 && *p == ' '; p++) ; + for (p2 = p + n; p < p2 && *p == ' '; p++) ; - n = min(p2 - p, 31); - memcpy(buf, p, n); - buf[n] = '\0'; - Tval = atof(buf); + n = min(p2 - p, 31); + memcpy(buf, p, n); + buf[n] = '\0'; + Tval = atof(buf); - if (trace) - htrc(" setting double: '%s' -> %lf\n", buf, Tval); + if (trace > 1) + htrc(" setting double: '%s' -> %lf\n", buf, Tval); + + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p - Null = false; } // end of SetValue /***********************************************************************/ @@ -637,8 +605,14 @@ void TYPVAL::SetValue_char(char *p, int n) template void TYPVAL::SetValue_psz(PSZ s) { - Tval = GetTypedValue(s); - Null = false; + if (s) { + Tval = GetTypedValue(s); + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p + } // end of SetValue template <> @@ -933,17 +907,23 @@ bool TYPVAL::SetValue_pval(PVAL valp, bool chktype) /***********************************************************************/ void TYPVAL::SetValue_char(char *p, int n) { - n = min(n, Len); - strncpy(Strp, p, n); + if (p) { + n = min(n, Len); + strncpy(Strp, p, n); - for (p = Strp + n - 1; (*p == ' ' || *p == '\0') && p >= Strp; p--) ; + for (p = Strp + n - 1; (*p == ' ' || *p == '\0') && p >= Strp; p--) ; - *(++p) = '\0'; + *(++p) = '\0'; - if (trace) - htrc(" Setting string to: '%s'\n", Strp); + if (trace > 1) + htrc(" Setting string to: '%s'\n", Strp); + + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif p - Null = false; } // end of SetValue_char /***********************************************************************/ @@ -951,8 +931,14 @@ void TYPVAL::SetValue_char(char *p, int n) /***********************************************************************/ void TYPVAL::SetValue_psz(PSZ s) { - strncpy(Strp, s, Len); - Null = false; + if (s) { + strncpy(Strp, s, Len); + Null = false; + } else { + Reset(); + Null = Nullable; + } // endif s + } // end of SetValue_psz /***********************************************************************/ @@ -1048,7 +1034,6 @@ void TYPVAL::SetValue(char c) void TYPVAL::SetBinValue(void *p) { SetValue_char((char *)p, Len); - Null = false; } // end of SetBinValue /***********************************************************************/ @@ -1143,10 +1128,13 @@ bool TYPVAL::IsEqual(PVAL vp, bool chktype) return false; else if (Null || vp->IsNull()) return false; - else if (Ci || vp->IsCi()) - return !stricmp(Strp, vp->GetCharValue()); + + char buf[32]; + + if (Ci || vp->IsCi()) + return !stricmp(Strp, vp->GetCharString(buf)); else // (!Ci) - return !strcmp(Strp, vp->GetCharValue()); + return !strcmp(Strp, vp->GetCharString(buf)); } // end of IsEqual @@ -1261,9 +1249,6 @@ void DTVAL::SetTimeShift(void) /* though the gmtime C function. The purpose of this function is to */ /* extend the range of valid dates by accepting negative time values. */ /***********************************************************************/ -#define MYSQL_SERVER 1 -#include "tztime.h" -#include "sql_priv.h" #include "sql_class.h" #include "sql_time.h" @@ -1282,15 +1267,14 @@ static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime) static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm) { MYSQL_TIME ltime; - current_thd->variables.time_zone->gmt_sec_to_TIME(<ime, (my_time_t) *timep); + thd_gmt_sec_to_TIME(current_thd, <ime, (my_time_t) *timep); TIME_to_localtime(tm, <ime); return tm; } -struct tm *DTVAL::GetGmTime(void) +struct tm *DTVAL::GetGmTime(struct tm *tm_buffer) { - static struct tm tm_static; /* TODO: Move as a parameter to GetGmTime() */ struct tm *datm; time_t t = (time_t)Tval; @@ -1300,13 +1284,13 @@ struct tm *DTVAL::GetGmTime(void) for (n = 0; t < 0; n += 4) t += FOURYEARS; - datm = gmtime_mysql(&t, &tm_static); + datm = gmtime_mysql(&t, tm_buffer); if (datm) datm->tm_year -= n; } else - datm = gmtime_mysql(&t, &tm_static); + datm = gmtime_mysql(&t, tm_buffer); return datm; } // end of GetGmTime @@ -1332,7 +1316,7 @@ bool DTVAL::MakeTime(struct tm *ptm) int n, y = ptm->tm_year; time_t t = mktime_mysql(ptm); - if (trace) + if (trace > 1) htrc("MakeTime from (%d,%d,%d,%d,%d,%d)\n", ptm->tm_year, ptm->tm_mon, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); @@ -1355,7 +1339,7 @@ bool DTVAL::MakeTime(struct tm *ptm) } Tval= (int) t; - if (trace) + if (trace > 1) htrc("MakeTime Ival=%d\n", Tval); return false; @@ -1375,7 +1359,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) datm.tm_mon=0; datm.tm_year=70; - if (trace) + if (trace > 1) htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n", val[0], val[1], val[2], val[3], val[4], val[5], nval); @@ -1439,7 +1423,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) } // endfor i - if (trace) + if (trace > 1) htrc("MakeDate datm=(%d,%d,%d,%d,%d,%d)\n", datm.tm_year, datm.tm_mon, datm.tm_mday, datm.tm_hour, datm.tm_min, datm.tm_sec); @@ -1500,7 +1484,7 @@ void DTVAL::SetValue_char(char *p, int n) ndv = ExtractDate(Sdate, Pdtp, DefYear, dval); MakeDate(NULL, dval, ndv); - if (trace) + if (trace > 1) htrc(" setting date: '%s' -> %d\n", Sdate, Tval); Null = false; @@ -1524,7 +1508,7 @@ void DTVAL::SetValue_psz(PSZ p) ndv = ExtractDate(Sdate, Pdtp, DefYear, dval); MakeDate(NULL, dval, ndv); - if (trace) + if (trace > 1) htrc(" setting date: '%s' -> %d\n", Sdate, Tval); Null = false; @@ -1556,7 +1540,7 @@ char *DTVAL::GetCharString(char *p) { if (Pdtp) { size_t n = 0; - struct tm *ptm = GetGmTime(); + struct tm tm, *ptm= GetGmTime(&tm); if (ptm) n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm); @@ -1582,7 +1566,7 @@ char *DTVAL::ShowValue(char *buf, int len) if (Pdtp) { char *p; size_t m, n = 0; - struct tm *ptm = GetGmTime(); + struct tm tm, *ptm = GetGmTime(&tm); if (Len < len) { p = buf; @@ -1612,7 +1596,7 @@ char *DTVAL::ShowValue(char *buf, int len) bool DTVAL::GetTmMember(OPVAL op, int& mval) { bool rc = false; - struct tm *ptm = GetGmTime(); + struct tm tm, *ptm = GetGmTime(&tm); switch (op) { case OP_MDAY: mval = ptm->tm_mday; break; @@ -1640,7 +1624,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) { // w is the start of the week SUN=0, MON=1, etc. int m, n, w = nval % 7; - struct tm *ptm = GetGmTime(); + struct tm tm, *ptm = GetGmTime(&tm); // Which day is January 4th of this year? m = (367 + ptm->tm_wday - ptm->tm_yday) % 7; @@ -1664,7 +1648,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) bool DTVAL::FormatValue(PVAL vp, char *fmt) { char *buf = (char*)vp->GetTo_Val(); // Should be big enough - struct tm *ptm = GetGmTime(); + struct tm tm, *ptm = GetGmTime(&tm); if (trace) htrc("FormatValue: ptm=%p len=%d\n", ptm, vp->GetValLen()); diff --git a/storage/connect/value.h b/storage/connect/value.h index 0f7b795c252..62b4ea4617a 100644 --- a/storage/connect/value.h +++ b/storage/connect/value.h @@ -38,7 +38,6 @@ typedef struct _datpar *PDTP; // For DTVAL /***********************************************************************/ /* Utilities used to test types and to allocated values. */ /***********************************************************************/ -int GetPLGType(int); PVAL AllocateValue(PGLOBAL, void *, short); // Exported functions @@ -50,7 +49,6 @@ DllExport int TranslateSQLType(int stp, int prec, int& len); #endif DllExport char *GetFormatType(int); DllExport int GetFormatType(char); -DllExport int GetDBType(int); DllExport bool IsTypeChar(int type); DllExport bool IsTypeNum(int type); DllExport int ConvertType(int, int, CONV, bool match = false); @@ -82,12 +80,12 @@ class DllExport VALUE : public BLOCK { virtual longlong GetBigintValue(void) = 0; virtual double GetFloatValue(void) = 0; virtual void *GetTo_Val(void) = 0; + virtual void SetPrec(int prec) {Prec = prec;} bool IsNull(void) {return Null;} void SetNull(bool b) {Null = b;} void SetNullable(bool b) {Nullable = b;} int GetType(void) {return Type;} int GetClen(void) {return Clen;} - void SetPrec(int prec) {Prec = prec;} void SetGlobal(PGLOBAL g) {Global = g;} // Methods @@ -217,6 +215,7 @@ class DllExport TYPVAL: public VALUE { virtual longlong GetBigintValue(void) {return atoll(Strp);} virtual double GetFloatValue(void) {return atof(Strp);} virtual void *GetTo_Val(void) {return Strp;} + virtual void SetPrec(int prec) {Ci = prec != 0;} // Methods virtual bool SetValue_pval(PVAL valp, bool chktype); @@ -289,7 +288,7 @@ class DllExport DTVAL : public TYPVAL { bool MakeDate(PGLOBAL g, int *val, int nval); bool WeekNum(PGLOBAL g, int& nval); - struct tm *GetGmTime(void); + struct tm *GetGmTime(struct tm *); protected: // Default constructor not to be used diff --git a/storage/connect/xindex.cpp b/storage/connect/xindex.cpp index 68a6bba47ec..4a0067e30be 100755 --- a/storage/connect/xindex.cpp +++ b/storage/connect/xindex.cpp @@ -2368,7 +2368,6 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) } // endif Mode #else // UNIX - int rc = 0; int oflag = O_LARGEFILE; // Enable file size > 2G mode_t pmod = 0; @@ -2394,7 +2393,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) Hfile= global_open(g, MSGID_OPEN_ERROR_AND_STRERROR, filename, oflag, pmod); if (Hfile == INVALID_HANDLE_VALUE) { - rc = errno; + /*rc = errno;*/ #if defined(TRACE) printf("Open: %s\n", g->Message); #endif // TRACE diff --git a/storage/connect/xobject.h b/storage/connect/xobject.h index c77fb703823..79325f155cf 100644 --- a/storage/connect/xobject.h +++ b/storage/connect/xobject.h @@ -71,7 +71,6 @@ class DllExport XOBJECT : public BLOCK { virtual bool VerifyColumn(PTBX txp) {return false;} virtual bool VerifyTdb(PTDB& tdbp) {return false;} virtual bool IsColInside(PCOL colp) {return false;} - virtual void MarkCol(ushort) {} protected: PVAL Value; // The current value of the object. diff --git a/storage/connect/xtable.h b/storage/connect/xtable.h index 8475c46d52d..7ef2d26136c 100644 --- a/storage/connect/xtable.h +++ b/storage/connect/xtable.h @@ -173,6 +173,7 @@ class DllExport TDBASE : public TDB { virtual int GetRecpos(void) = 0; virtual bool SetRecpos(PGLOBAL g, int recpos); virtual bool IsReadOnly(void) {return Read_Only;} + virtual bool IsView(void) {return FALSE;} virtual CHARSET_INFO *data_charset() { /* diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index 7cd7e82f69e..035af2d348e 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -587,7 +587,7 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num) buf_len= min(table->s->connect_string.length, FEDERATED_QUERY_BUFFER_SIZE-1); strmake(buf, table->s->connect_string.str, buf_len); - my_error(error_num, MYF(0), buf); + my_error(error_num, MYF(0), buf, 14); DBUG_RETURN(error_num); } @@ -3220,7 +3220,7 @@ int ha_federated::stash_remote_error() if (!mysql) DBUG_RETURN(remote_error_number); remote_error_number= mysql_errno(mysql); - strmake(remote_error_buf, mysql_error(mysql), sizeof(remote_error_buf)-1); + strmake_buf(remote_error_buf, mysql_error(mysql)); if (remote_error_number == ER_DUP_ENTRY || remote_error_number == ER_DUP_KEY) DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index c3f5e6add73..a7f2d887952 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -527,7 +527,7 @@ static int parse_url_error(FEDERATEDX_SHARE *share, TABLE_SHARE *table_s, buf_len= min(table_s->connect_string.length, FEDERATEDX_QUERY_BUFFER_SIZE-1); strmake(buf, table_s->connect_string.str, buf_len); - my_error(error_num, MYF(0), buf); + my_error(error_num, MYF(0), buf, 14); DBUG_RETURN(error_num); } @@ -587,9 +587,8 @@ int get_connection(MEM_ROOT *mem_root, FEDERATEDX_SHARE *share) DBUG_RETURN(0); error: - sprintf(error_buffer, "server name: '%s' doesn't exist!", - share->connection_string); - my_error(error_num, MYF(0), error_buffer); + my_printf_error(error_num, "server name: '%s' doesn't exist!", + MYF(0), share->connection_string); DBUG_RETURN(error_num); } @@ -3423,7 +3422,7 @@ int ha_federatedx::stash_remote_error() if (!io) DBUG_RETURN(remote_error_number); remote_error_number= io->error_code(); - strmake(remote_error_buf, io->error_str(), sizeof(remote_error_buf)-1); + strmake_buf(remote_error_buf, io->error_str()); if (remote_error_number == ER_DUP_ENTRY || remote_error_number == ER_DUP_KEY) DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index acf592a6756..1a085275ea1 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -3455,12 +3455,23 @@ os_aio_array_create( if (!os_aio_linux_create_io_ctx(n/n_segments, &array->aio_ctx[i])) { /* If something bad happened during aio setup - we should call it a day and return right away. - We don't care about any leaks because a failure - to initialize the io subsystem means that the - server (or atleast the innodb storage engine) - is not going to startup. */ - return(NULL); + we disable linux native aio. + The disadvantage will be a small memory leak + at shutdown but that's ok compared to a crash + or a not working server. + This frequently happens when running the test suite + with many threads on a system with low fs.aio-max-nr! + */ + + fprintf(stderr, + " InnoDB: Warning: Linux Native AIO disabled " + "because os_aio_linux_create_io_ctx() " + "failed. To get rid of this warning you can " + "try increasing system " + "fs.aio-max-nr to 1048576 or larger or " + "setting innodb_use_native_aio = 0 in my.cnf\n"); + srv_use_native_aio = FALSE; + goto skip_native_aio; } } diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 27dafc30e07..afc0559858a 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1308,8 +1308,9 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) old_proc_info= thd_proc_info(thd, "Checking status"); thd_progress_init(thd, 3); - (void) maria_chk_status(¶m, file); // Not fatal - error= maria_chk_size(¶m, file); + error= maria_chk_status(¶m, file); // Not fatal + if (maria_chk_size(¶m, file)) + error= 1; if (!error) error|= maria_chk_del(¶m, file, param.testflag); thd_proc_info(thd, "Checking keys"); @@ -1673,6 +1674,11 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) } } thd_proc_info(thd, "Saving state"); + if (optimize_done && !error && !(param->testflag & T_NO_CREATE_RENAME_LSN)) + { + /* Set trid (needed if the table was moved from another system) */ + share->state.create_trid= trnman_get_min_safe_trid(); + } mysql_mutex_lock(&share->intern_lock); if (!error) { @@ -1688,6 +1694,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) */ if (file->state != &share->state.state) *file->state= share->state.state; + if (share->base.auto_key) _ma_update_auto_increment_key(param, file, 1); if (optimize_done) @@ -1695,6 +1702,9 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) UPDATE_TIME | UPDATE_OPEN_COUNT | (local_testflag & T_STATISTICS ? UPDATE_STAT : 0)); + /* File is repaired; Mark the file as moved to this system */ + (void) _ma_set_uuid(share, 0); + info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | HA_STATUS_CONST); if (rows != file->state->records && !(param->testflag & T_VERY_SILENT)) @@ -2415,7 +2425,9 @@ int ha_maria::remember_rnd_pos() int ha_maria::restart_rnd_next(uchar *buf) { - (*file->s->scan_restore_pos)(file, remember_pos); + int error; + if ((error= (*file->s->scan_restore_pos)(file, remember_pos))) + return error; return rnd_next(buf); } @@ -2648,23 +2660,6 @@ int ha_maria::external_lock(THD *thd, int lock_type) /* Transactional table */ if (lock_type != F_UNLCK) { - if (!file->s->lock_key_trees) // If we don't use versioning - { - /* - We come here in the following cases: - - The table is a temporary table - - It's a table which is crash safe but not yet versioned, for - example a table with fulltext or rtree keys - - Set the current state to point to save_state so that the - block_format code don't count the same record twice. - Copy also the current state. This may have been wrong if the - same file was used several times in the last statement - */ - file->state= file->state_start; - *file->state= file->s->state.state; - } - if (file->trn) { /* This can only happen with tables created with clone() */ diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index 16657ba80ae..03fd0200d18 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -4007,6 +4007,8 @@ static int delete_dir_entry(uchar *buff, uint block_size, uint record_number, uint length, empty_space; uchar *dir; DBUG_ENTER("delete_dir_entry"); + DBUG_PRINT("enter", ("record_number: %u number_of_records: %u", + record_number, number_of_records)); #ifdef SANITY_CHECKS if (record_number >= number_of_records || @@ -4023,7 +4025,8 @@ static int delete_dir_entry(uchar *buff, uint block_size, uint record_number, check_directory(buff, block_size, 0, (uint) -1); empty_space= uint2korr(buff + EMPTY_SPACE_OFFSET); dir= dir_entry_pos(buff, block_size, record_number); - length= uint2korr(dir + 2); + length= uint2korr(dir + 2); /* Length of entry we just deleted */ + DBUG_ASSERT(uint2korr(dir) != 0 && length < block_size); if (record_number == number_of_records - 1) { @@ -5240,11 +5243,6 @@ void _ma_scan_end_block_record(MARIA_HA *info) For the moment we can only remember one position, but this is good enough for MySQL usage - @Warning - When this function is called, we assume that the thread is not deleting - or updating the current row before ma_scan_restore_block_record() - is called! - @return @retval 0 ok @retval HA_ERR_WRONG_IN_RECORD Could not allocate memory to hold position @@ -5264,15 +5262,18 @@ int _ma_scan_remember_block_record(MARIA_HA *info, info->scan_save->bitmap_buff= ((uchar*) info->scan_save + ALIGN_SIZE(sizeof(*info->scan_save))); } - /* Point to the last read row */ - *lastpos= info->cur_row.nextpos - 1; - info->scan.dir+= DIR_ENTRY_SIZE; + /* For checking if pages have changed since we last read it */ + info->scan.row_changes= info->row_changes; /* Remember used bitmap and used head page */ bitmap_buff= info->scan_save->bitmap_buff; memcpy(info->scan_save, &info->scan, sizeof(*info->scan_save)); info->scan_save->bitmap_buff= bitmap_buff; memcpy(bitmap_buff, info->scan.bitmap_buff, info->s->block_size * 2); + + /* Point to the last read row */ + *lastpos= info->cur_row.nextpos - 1; + info->scan_save->dir+= DIR_ENTRY_SIZE; DBUG_RETURN(0); } @@ -5280,15 +5281,22 @@ int _ma_scan_remember_block_record(MARIA_HA *info, /** @brief restore scan block it's original values + @return + 0 ok + # error + @note In theory we could swap bitmap buffers instead of copy them. For the moment we don't do that because there are variables pointing inside the buffers and it's a bit of hassle to either make them relative or repoint them. + + If the data file has changed, we will re-read the new block record + to ensure that when we continue scanning we can ignore any deleted rows. */ -void _ma_scan_restore_block_record(MARIA_HA *info, - MARIA_RECORD_POS lastpos) +int _ma_scan_restore_block_record(MARIA_HA *info, + MARIA_RECORD_POS lastpos) { uchar *bitmap_buff; DBUG_ENTER("_ma_scan_restore_block_record"); @@ -5299,7 +5307,26 @@ void _ma_scan_restore_block_record(MARIA_HA *info, info->scan.bitmap_buff= bitmap_buff; memcpy(bitmap_buff, info->scan_save->bitmap_buff, info->s->block_size * 2); - DBUG_VOID_RETURN; + if (info->scan.row_changes != info->row_changes) + { + /* + Table has been changed. We have to re-read the current page block as + data may have changed on it that we have to see. + */ + if (!(pagecache_read(info->s->pagecache, + &info->dfile, + ma_recordpos_to_page(info->scan.row_base_page), + 0, info->scan.page_buff, + info->s->page_type, + PAGECACHE_LOCK_LEFT_UNLOCKED, 0))) + DBUG_RETURN(my_errno); + info->scan.number_of_rows= + (uint) (uchar) info->scan.page_buff[DIR_COUNT_OFFSET]; + info->scan.dir_end= (info->scan.page_buff + info->s->block_size - + PAGE_SUFFIX_SIZE - + info->scan.number_of_rows * DIR_ENTRY_SIZE); + } + DBUG_RETURN(0); } @@ -5326,7 +5353,7 @@ void _ma_scan_restore_block_record(MARIA_HA *info, RETURN 0 ok - # Error code + # Error code (Normally HA_ERR_END_OF_FILE) */ int _ma_scan_block_record(MARIA_HA *info, uchar *record, @@ -5345,6 +5372,12 @@ restart_record_read: uchar *data, *end_of_data; int error; + /* Ensure that scan.dir and record_pos are in sync */ + DBUG_ASSERT(info->scan.dir == dir_entry_pos(info->scan.page_buff, + share->block_size, + record_pos)); + + /* Search for a valid directory entry (not 0) */ while (!(offset= uint2korr(info->scan.dir))) { info->scan.dir-= DIR_ENTRY_SIZE; @@ -5357,13 +5390,19 @@ restart_record_read: } #endif } + /* + This should always be true as the directory should always start with + a valid entry. + */ + DBUG_ASSERT(info->scan.dir >= info->scan.dir_end); + /* found row */ info->cur_row.lastpos= info->scan.row_base_page + record_pos; info->cur_row.nextpos= record_pos + 1; data= info->scan.page_buff + offset; length= uint2korr(info->scan.dir + 2); end_of_data= data + length; - info->scan.dir-= DIR_ENTRY_SIZE; /* Point to previous row */ + info->scan.dir-= DIR_ENTRY_SIZE; /* Point to next row to process */ #ifdef SANITY_CHECKS if (end_of_data > info->scan.dir_end || offset < PAGE_HEADER_SIZE || length < share->base.min_block_length) @@ -6937,6 +6976,7 @@ my_bool _ma_apply_undo_row_insert(MARIA_HA *info, LSN undo_lsn, res= 0; end: + /* The following is true only if _ma_bitmap_flushable() was called earlier */ if (info->non_flushable_state) _ma_bitmap_flushable(info, -1); _ma_unpin_all_pages_and_finalize_row(info, lsn); @@ -6946,6 +6986,11 @@ err: DBUG_ASSERT(!maria_assert_if_crashed_table); res= 1; _ma_mark_file_crashed(share); + /* + Don't write a new LSN on the used pages. Not important as the file is + marked as crashed and need to be repaired before it can be used. + */ + lsn= LSN_IMPOSSIBLE; goto end; } diff --git a/storage/maria/ma_blockrec.h b/storage/maria/ma_blockrec.h index 45f5613bb60..40ca2591236 100644 --- a/storage/maria/ma_blockrec.h +++ b/storage/maria/ma_blockrec.h @@ -167,8 +167,8 @@ my_bool _ma_scan_init_block_record(MARIA_HA *info); void _ma_scan_end_block_record(MARIA_HA *info); int _ma_scan_remember_block_record(MARIA_HA *info, MARIA_RECORD_POS *lastpos); -void _ma_scan_restore_block_record(MARIA_HA *info, - MARIA_RECORD_POS lastpos); +int _ma_scan_restore_block_record(MARIA_HA *info, + MARIA_RECORD_POS lastpos); MARIA_RECORD_POS _ma_write_init_block_record(MARIA_HA *info, const uchar *record); diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 6bcb9c21a71..fdb2bae3d8c 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -140,13 +140,22 @@ void maria_chk_init_for_check(HA_CHECK *param, MARIA_HA *info) Set up transaction handler so that we can see all rows. When rows is read we will check the found id against param->max_tried */ - if (param->max_trid == 0) + if (!info->s->base.born_transactional) + { + /* + There are no trids. Howver we want to set max_trid to make test of + create_trid simpler. + */ + param->max_trid= ~(TrID) 0; + } + else if (param->max_trid == 0) { if (!ma_control_file_inited()) param->max_trid= 0; /* Give warning for first trid found */ else param->max_trid= max_trid_in_system(); } + maria_ignore_trids(info); } @@ -179,6 +188,13 @@ int maria_chk_status(HA_CHECK *param, MARIA_HA *info) if (param->testflag & T_UPDATE_STATE) param->warning_printed=save; } + if (share->state.create_trid > param->max_trid) + { + _ma_check_print_warning(param, + "Table create_trd (%llu) > current max_transaction id (%llu). Table needs to be repaired or zerofilled to be usable", + share->state.create_trid, param->max_trid); + return 1; + } return 0; } @@ -2424,11 +2440,10 @@ static void restore_table_state_after_repair(MARIA_HA *info, { maria_versioning(info, info->s->have_versioning); info->s->lock_key_trees= org_share->lock_key_trees; + DBUG_ASSERT(!info->s->have_versioning || info->s->lock_key_trees); } - - /** @brief Drop all indexes @@ -3553,7 +3568,10 @@ int maria_zerofill(HA_CHECK *param, MARIA_HA *info, const char *name) /* Ensure state is later flushed to disk, if within maria_chk */ info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); - /* Reset create_trid to make file comparable */ + /* + Reset create_trid to make file comparable and to ensure that new + trid's in the file starts from 0. + */ share->state.create_trid= 0; } if (reenable_logging) diff --git a/storage/maria/ma_delete.c b/storage/maria/ma_delete.c index 5b8d0e01677..22f7341098d 100644 --- a/storage/maria/ma_delete.c +++ b/storage/maria/ma_delete.c @@ -112,6 +112,7 @@ int maria_delete(MARIA_HA *info,const uchar *record) info->state->checksum-= info->cur_row.checksum; info->state->records--; info->update= HA_STATE_CHANGED+HA_STATE_DELETED+HA_STATE_ROW_CHANGED; + info->row_changes++; share->state.changed|= (STATE_NOT_OPTIMIZED_ROWS | STATE_NOT_MOVABLE | STATE_NOT_ZEROFILLED); info->state->changed=1; diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index 5233e57594c..f0ade217341 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -7472,9 +7472,8 @@ static void translog_force_current_buffer_to_finish() struct st_translog_buffer *old_buffer= log_descriptor.bc.buffer; uchar *data= log_descriptor.bc.ptr - log_descriptor.bc.current_page_fill; uint16 left= TRANSLOG_PAGE_SIZE - log_descriptor.bc.current_page_fill; - uint16 current_page_fill, write_counter, previous_offset; + uint16 UNINIT_VAR(current_page_fill), write_counter, previous_offset; DBUG_ENTER("translog_force_current_buffer_to_finish"); - LINT_INIT(current_page_fill); DBUG_PRINT("enter", ("Buffer #%u 0x%lx " "Buffer addr: (%lu,0x%lx) " diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 88422e3dc5f..d2ae10ccb18 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -437,15 +437,23 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) share->open_count_not_zero_on_open= 1; /* + A transactional table is not usable on this system if: + - share->state.create_trid > trnman_get_max_trid() + - Critical as trid as stored releativel to create_trid. + - uuid is different + + STATE_NOT_MOVABLE is reset when a table is zerofilled + (has no LSN's and no trids) + We can ignore testing uuid if STATE_NOT_MOVABLE is set, as in this - case the uuid will be set in _ma_mark_file_changed() + case the uuid will be set in _ma_mark_file_changed(). */ - if ((share->state.changed & STATE_NOT_MOVABLE) && - share->base.born_transactional && - ((!(open_flags & HA_OPEN_IGNORE_MOVED_STATE) && - memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE)) || - (share->state.create_trid > trnman_get_max_trid() && - !maria_in_recovery))) + if (share->base.born_transactional && + ((share->state.create_trid > trnman_get_max_trid() && + !maria_in_recovery) || + ((share->state.changed & STATE_NOT_MOVABLE) && + ((!(open_flags & HA_OPEN_IGNORE_MOVED_STATE) && + memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE)))))) { DBUG_PRINT("warning", ("table is moved from another system. uuid_diff: %d create_trid: %lu max_trid: %lu", memcmp(share->base.uuid, maria_uuid, @@ -756,7 +764,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) HA_ERR_CRASHED_ON_REPAIR : HA_ERR_CRASHED_ON_USAGE); goto err; } - else + else if (!(open_flags & HA_OPEN_FOR_REPAIR)) { /* create_rename_lsn != LSN_NEEDS_NEW_STATE_LSNS */ share->state.changed|= STATE_NOT_MOVABLE; @@ -894,8 +902,10 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) &share->keyinfo[i].root_lock); mysql_rwlock_init(key_SHARE_mmap_lock, &share->mmap_lock); - share->row_is_visible= _ma_row_visible_always; - share->lock.get_status= _ma_reset_update_flag; + share->row_is_visible= _ma_row_visible_always; + share->lock.get_status= _ma_reset_update_flag; + share->lock.start_trans= _ma_start_trans; + if (!thr_lock_inited) { /* Probably a single threaded program; Don't use concurrent inserts */ diff --git a/storage/maria/ma_pagecrc.c b/storage/maria/ma_pagecrc.c index 58e3b4b203d..a79f34016c1 100644 --- a/storage/maria/ma_pagecrc.c +++ b/storage/maria/ma_pagecrc.c @@ -358,8 +358,7 @@ my_bool maria_flush_log_for_page(uchar *page, MARIA_SHARE *share= (MARIA_SHARE*) data_ptr; DBUG_ENTER("maria_flush_log_for_page"); /* share is 0 here only in unittest */ - DBUG_ASSERT(!share || (share->page_type == PAGECACHE_LSN_PAGE && - share->now_transactional)); + DBUG_ASSERT(!share || share->page_type == PAGECACHE_LSN_PAGE); lsn= lsn_korr(page); if (translog_flush(lsn)) DBUG_RETURN(1); diff --git a/storage/maria/ma_recovery.c b/storage/maria/ma_recovery.c index aeeda26b791..bd2bde1c89a 100644 --- a/storage/maria/ma_recovery.c +++ b/storage/maria/ma_recovery.c @@ -3304,7 +3304,7 @@ static LSN parse_checkpoint_record(LSN lsn) first_log_write_lsn= lsn_korr(ptr); ptr+= LSN_STORE_SIZE; name_len= strlen((char *)ptr) + 1; - strmake(name, (char *)ptr, sizeof(name)-1); + strmake_buf(name, (char *)ptr); ptr+= name_len; if (new_table(sid, name, first_log_write_lsn)) return LSN_ERROR; diff --git a/storage/maria/ma_scan.c b/storage/maria/ma_scan.c index cbac463a2c8..ad526211615 100644 --- a/storage/maria/ma_scan.c +++ b/storage/maria/ma_scan.c @@ -68,7 +68,8 @@ int _ma_def_scan_remember_pos(MARIA_HA *info, MARIA_RECORD_POS *lastpos) } -void _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos) +int _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos) { info->cur_row.nextpos= lastpos; + return 0; } diff --git a/storage/maria/ma_search.c b/storage/maria/ma_search.c index ccb4bf77717..d38bc7af26c 100644 --- a/storage/maria/ma_search.c +++ b/storage/maria/ma_search.c @@ -424,9 +424,9 @@ int _ma_prefix_search(const MARIA_KEY *key, const MARIA_PAGE *ma_page, flag is the value returned by ha_key_cmp and as treated as final */ int flag=0, my_flag=-1; - uint nod_flag, length, len, matched, cmplen, kseg_len; - uint page_flag, prefix_len,suffix_len; - int key_len_skip, seg_len_pack, key_len_left; + uint nod_flag, UNINIT_VAR(length), len, matched, cmplen, kseg_len; + uint page_flag, UNINIT_VAR(prefix_len),suffix_len; + int key_len_skip, UNINIT_VAR(seg_len_pack), key_len_left; uchar *end, *vseg, *UNINIT_VAR(saved_vseg), *UNINIT_VAR(saved_from); uchar *page; uchar tt_buff[MARIA_MAX_KEY_BUFF+2], *t_buff=tt_buff+2; @@ -439,10 +439,6 @@ int _ma_prefix_search(const MARIA_KEY *key, const MARIA_PAGE *ma_page, const uchar *sort_order= keyinfo->seg->charset->sort_order; DBUG_ENTER("_ma_prefix_search"); - LINT_INIT(seg_len_pack); - LINT_INIT(prefix_len); - LINT_INIT(length); - t_buff[0]=0; /* Avoid bugs */ page_flag= ma_page->flag; nod_flag= ma_page->node; diff --git a/storage/maria/ma_state.c b/storage/maria/ma_state.c index 1f4a7504c56..f130da21d07 100644 --- a/storage/maria/ma_state.c +++ b/storage/maria/ma_state.c @@ -59,6 +59,8 @@ my_bool _ma_setup_live_state(MARIA_HA *info) MARIA_STATE_HISTORY *history; DBUG_ENTER("_ma_setup_live_state"); + DBUG_ASSERT(share->lock_key_trees); + if (maria_create_trn_hook(info)) DBUG_RETURN(1); @@ -377,6 +379,17 @@ void _ma_reset_update_flag(void *param, info->state->changed= 0; } +my_bool _ma_start_trans(void* param) +{ + MARIA_HA *info=(MARIA_HA*) param; + if (!info->s->lock_key_trees) + { + info->state= info->state_start; + *info->state= info->s->state.state; + } + return 0; +} + /** @brief Check if should allow concurrent inserts @@ -622,6 +635,22 @@ my_bool _ma_block_start_trans(void* param) */ return _ma_setup_live_state(info); } + else + { + /* + We come here in the following cases: + - The table is a temporary table + - It's a table which is crash safe but not yet versioned, for + example a table with fulltext or rtree keys + + Set the current state to point to save_state so that the + block_format code don't count the same record twice. + Copy also the current state. This may have been wrong if the + same file was used several times in the last statement + */ + info->state= info->state_start; + *info->state= info->s->state.state; + } /* Info->trn is set if this table is already handled and we are @@ -668,9 +697,11 @@ my_bool _ma_block_start_trans_no_versioning(void* param) { MARIA_HA *info=(MARIA_HA*) param; DBUG_ENTER("_ma_block_get_status_no_version"); - DBUG_ASSERT(info->s->base.born_transactional); + DBUG_ASSERT(info->s->base.born_transactional && !info->s->lock_key_trees); info->state->changed= 0; /* from _ma_reset_update_flag() */ + info->state= info->state_start; + *info->state= info->s->state.state; if (!info->trn) { /* @@ -689,18 +720,22 @@ my_bool _ma_block_start_trans_no_versioning(void* param) void maria_versioning(MARIA_HA *info, my_bool versioning) { + MARIA_SHARE *share= info->s; /* For now, this is a hack */ - if (info->s->have_versioning) + if (share->have_versioning) { enum thr_lock_type save_lock_type; - /* Assume is a non threaded application (for now) */ - info->s->lock_key_trees= 0; + share->lock_key_trees= versioning; /* Set up info->lock.type temporary for _ma_block_get_status() */ save_lock_type= info->lock.type; info->lock.type= versioning ? TL_WRITE_CONCURRENT_INSERT : TL_WRITE; _ma_block_get_status((void*) info, versioning); info->lock.type= save_lock_type; - info->state= info->state_start= &info->s->state.common; + if (versioning) + info->state= &share->state.common; + else + info->state= &share->state.state; /* Change global values by default */ + info->state_start= info->state; /* Initial values */ } } diff --git a/storage/maria/ma_state.h b/storage/maria/ma_state.h index 03ce5c2ea8c..2903986e32a 100644 --- a/storage/maria/ma_state.h +++ b/storage/maria/ma_state.h @@ -66,6 +66,7 @@ void _ma_update_status_with_lock(MARIA_HA *info); void _ma_restore_status(void *param); void _ma_copy_status(void* to, void *from); void _ma_reset_update_flag(void *param, my_bool concurrent_insert); +my_bool _ma_start_trans(void* param); my_bool _ma_check_status(void *param); void _ma_block_get_status(void* param, my_bool concurrent_insert); void _ma_block_update_status(void *param); diff --git a/storage/maria/ma_test1.c b/storage/maria/ma_test1.c index 945654a0bbe..5a655d4412a 100644 --- a/storage/maria/ma_test1.c +++ b/storage/maria/ma_test1.c @@ -55,7 +55,6 @@ static void create_key(uchar *key,uint rownr); static void create_record(uchar *record,uint rownr); static void update_record(uchar *record); - /* These are here only for testing of recovery with undo. We are not including maria_def.h here as this test is also to be an example of @@ -506,6 +505,7 @@ end: break; } printf("Dying on request without maria_commit()/maria_close()\n"); + sf_leaking_memory= 1; exit(0); } @@ -514,6 +514,7 @@ end: if (maria_close(file)) goto err; maria_end(); + my_uuid_end(); my_end(MY_CHECK_ERROR); return (0); diff --git a/storage/maria/ma_test2.c b/storage/maria/ma_test2.c index ea1978b4ee5..a3b7a2a9e98 100644 --- a/storage/maria/ma_test2.c +++ b/storage/maria/ma_test2.c @@ -971,6 +971,7 @@ end: break; } printf("Dying on request without maria_commit()/maria_close()\n"); + sf_leaking_memory= 1; /* no memory leak reports here */ exit(0); } if (maria_commit(file)) @@ -1017,6 +1018,7 @@ reads: %10lu\n", } maria_end(); my_free(blob_buffer); + my_uuid_end(); my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO); return(0); err: @@ -1029,6 +1031,8 @@ err2: maria_close(file); } maria_end(); + my_uuid_end(); + my_end(0); return(1); } /* main */ diff --git a/storage/maria/ma_update.c b/storage/maria/ma_update.c index 0a726c1b7f9..e0e804ca655 100644 --- a/storage/maria/ma_update.c +++ b/storage/maria/ma_update.c @@ -173,6 +173,7 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec, uchar *newrec) We can't yet have HA_STATE_AKTIV here, as block_record dosn't support it */ info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | key_changed); + info->row_changes++; share->state.changed|= STATE_NOT_MOVABLE | STATE_NOT_ZEROFILLED; info->state->changed= 1; diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index 5d440a40dc0..4ce9fb1bc82 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -297,6 +297,7 @@ int maria_write(MARIA_HA *info, uchar *record) info->state->records++; info->update= (HA_STATE_CHANGED | HA_STATE_AKTIV | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED); + info->row_changes++; share->state.changed|= STATE_NOT_MOVABLE | STATE_NOT_ZEROFILLED; info->state->changed= 1; diff --git a/storage/maria/maria_chk.c b/storage/maria/maria_chk.c index 8a7ba30eb08..065063fcb07 100644 --- a/storage/maria/maria_chk.c +++ b/storage/maria/maria_chk.c @@ -88,9 +88,22 @@ static int sort_record_index(MARIA_SORT_PARAM *sort_param, MARIA_PAGE *page, uint sortkey, File new_file, my_bool update_index); static my_bool write_log_record(HA_CHECK *param); +static void my_exit(int exit_code) __attribute__ ((noreturn)); HA_CHECK check_param; +/* Free memory and exit */ + +static void my_exit(int exit_code) +{ + free_tmpdir(&maria_chk_tmpdir); + free_defaults(default_argv); + my_end(check_param.testflag & T_INFO ? + MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); + exit(exit_code); +} + + /* Main program */ int main(int argc, char **argv) @@ -178,12 +191,8 @@ end: printf("\nTotal of all %d Aria-files:\nData records: %9s Deleted blocks: %9s\n",check_param.total_files,llstr(check_param.total_records,buff), llstr(check_param.total_deleted,buff2)); } - free_defaults(default_argv); - free_tmpdir(&maria_chk_tmpdir); maria_end(); - my_end(check_param.testflag & T_INFO ? - MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); - exit(error); + my_exit(error); #ifndef _lint return 0; /* No compiler warning */ #endif @@ -257,10 +266,10 @@ static struct my_option my_long_options[] = "Restart with -r if there are any errors in the table. States will be updated as with --update-state.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"HELP", 'H', - "Display this help and exit.", + "Print all argument options sorted alphabetically and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"help", '?', - "Display this help and exit.", + "Print all options by groups and exit. See also --HELP", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"information", 'i', "Print statistics information about table that is checked.", @@ -410,7 +419,7 @@ static struct my_option my_long_options[] = (char**) &maria_stats_method_str, (char**) &maria_stats_method_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { "zerofill", 'z', - "Fill empty space in data and index files with zeroes,", + "Fill empty space in data and index files with zeroes. This makes the data file movable between different servers.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, { "zerofill-keep-lsn", OPT_ZEROFILL_KEEP_LSN, "Like --zerofill but does not zero out LSN of data/index pages;" @@ -422,7 +431,7 @@ static struct my_option my_long_options[] = static void print_version(void) { - printf("%s Ver 1.1 for %s at %s\n", my_progname, SYSTEM_TYPE, + printf("%s Ver 1.2 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); } @@ -441,8 +450,8 @@ static void usage(void) -#, --debug=... Output debug log. Often this is 'd:t:o,filename'.\n"); #endif printf("\ - -H, --HELP Display this help and exit.\n\ - -?, --help Display this help and exit.\n\ + -H, --HELP Print all argument options sorted alphabetically.\n\ + -?, --help Print all options by groups\n\ --datadir=path Path for control file (and logs if --logdir not used)\n\ --logdir=path Path for log files\n\ --ignore-control-file Don't open the control file. Only use this if you\n\ @@ -566,7 +575,9 @@ Recover (repair)/ options (When using '--recover' or '--safe-recover'):\n\ (It may be VERY slow to do a sort the first time!).\n\ -b, --block-search=#\n\ Find a record, a block at given offset belongs to.\n\ - -z, --zerofill Fill empty space in data and index files with zeroes\n\ + -z, --zerofill Fill empty space in data and index files with zeroes.\n\ + This makes the data file movable between different \n\ + servers.\n\ --zerofill-keep-lsn Like --zerofill but does not zero out LSN of\n\ data/index pages."); @@ -790,7 +801,7 @@ get_one_option(int optid, fprintf(stderr, "The value of the sort key is bigger than max key: %d.\n", MARIA_MAX_KEY); - exit(1); + my_exit(1); } } break; @@ -818,7 +829,7 @@ get_one_option(int optid, break; case 'V': print_version(); - exit(0); + my_exit(0); case OPT_CORRECT_CHECKSUM: if (argument == disabled_my_option) check_param.testflag&= ~T_CALC_CHECKSUM; @@ -833,7 +844,7 @@ get_one_option(int optid, if ((method=find_type(argument, &maria_stats_method_typelib, 2)) <= 0) { fprintf(stderr, "Invalid value of stats_method: %s.\n", argument); - exit(1); + my_exit(1); } switch (method-1) { case 0: @@ -869,10 +880,11 @@ get_one_option(int optid, break; case 'H': my_print_help(my_long_options); - exit(0); + my_print_variables(my_long_options); + my_exit(0); case '?': usage(); - exit(0); + my_exit(0); } return 0; } @@ -889,7 +901,7 @@ static void get_options(register int *argc,register char ***argv) check_param.testflag|=T_WRITE_LOOP; if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) - exit(ho_error); + my_exit(ho_error); /* If using repair, then update checksum if one uses --update-state */ if ((check_param.testflag & T_UPDATE_STATE) && @@ -899,7 +911,7 @@ static void get_options(register int *argc,register char ***argv) if (*argc == 0) { usage(); - exit(-1); + my_exit(-1); } if ((check_param.testflag & T_UNPACK) && @@ -907,7 +919,7 @@ static void get_options(register int *argc,register char ***argv) { fprintf(stderr, "%s: --unpack can't be used with --quick or --sort-records\n", my_progname_short); - exit(1); + my_exit(1); } if ((check_param.testflag & T_READONLY) && (check_param.testflag & @@ -916,7 +928,7 @@ static void get_options(register int *argc,register char ***argv) { fprintf(stderr, "%s: Can't use --readonly when repairing or sorting\n", my_progname_short); - exit(1); + my_exit(1); } if (!opt_debug) @@ -924,20 +936,26 @@ static void get_options(register int *argc,register char ***argv) DEBUGGER_OFF; /* Speed up things a bit */ } if (init_tmpdir(&maria_chk_tmpdir, opt_tmpdir)) - exit(1); + my_exit(1); check_param.tmpdir=&maria_chk_tmpdir; if (set_collation_name) if (!(set_collation= get_charset_by_name(set_collation_name, MYF(MY_WME)))) - exit(1); + my_exit(1); if (maria_data_root != default_log_dir && opt_log_dir == default_log_dir) { /* --datadir was used and --log-dir was not. Set log-dir to datadir */ opt_log_dir= maria_data_root; } + + /* If we are using zerofill, then we don't need to read the control file */ + if ((check_param.testflag & (T_ZEROFILL_KEEP_LSN | T_ZEROFILL)) && + !(check_param.testflag & ~(T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_STATISTICS | T_CHECK | T_FAST | T_CHECK_ONLY_CHANGED))) + opt_ignore_control_file= 1; + return; } /* get options */ @@ -1220,8 +1238,11 @@ static int maria_chk(HA_CHECK *param, char *filename) ((param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX | T_ZEROFILL | T_ZEROFILL_KEEP_LSN)) != (T_ZEROFILL | T_ZEROFILL_KEEP_LSN))) + { share->state.create_rename_lsn= share->state.is_of_horizon= share->state.skip_redo_lsn= LSN_NEEDS_NEW_STATE_LSNS; + share->state.create_trid= 0; + } } if (!error && (param->testflag & T_REP_ANY)) { @@ -1508,6 +1529,8 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name) LSN_IN_PARTS(share->state.create_rename_lsn), LSN_IN_PARTS(share->state.is_of_horizon), LSN_IN_PARTS(share->state.skip_redo_lsn)); + printf("create_trid: %s\n", + llstr(share->state.create_trid, llbuff)); } compile_time_assert((MY_UUID_STRING_LENGTH + 1) <= sizeof(buff)); buff[MY_UUID_STRING_LENGTH]= 0; diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 460806a66dd..0180356056b 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -389,7 +389,7 @@ typedef struct st_maria_share /* End scan */ void (*scan_end)(MARIA_HA *); int (*scan_remember_pos)(MARIA_HA *, MARIA_RECORD_POS*); - void (*scan_restore_pos)(MARIA_HA *, MARIA_RECORD_POS); + int (*scan_restore_pos)(MARIA_HA *, MARIA_RECORD_POS); /* Pre-write of row (some handlers may do the actual write here) */ MARIA_RECORD_POS (*write_record_init)(MARIA_HA *, const uchar *); /* Write record (or accept write_record_init) */ @@ -564,6 +564,7 @@ typedef struct st_maria_block_scan ulonglong bits; uint number_of_rows, bit_pos; MARIA_RECORD_POS row_base_page; + ulonglong row_changes; } MARIA_BLOCK_SCAN; //typedef ICP_RESULT (*index_cond_func_t)(void *param); @@ -606,6 +607,7 @@ struct st_maria_handler int (*read_record)(MARIA_HA *, uchar*, MARIA_RECORD_POS); invalidator_by_filename invalidator; /* query cache invalidator */ ulonglong last_auto_increment; /* auto value at start of statement */ + ulonglong row_changes; /* Incremented for each change */ ulong this_unique; /* uniq filenumber or thread */ ulong last_unique; /* last unique number */ ulong this_loop; /* counter for this open */ @@ -1299,7 +1301,7 @@ my_bool _ma_check_status(void *param); void _ma_restore_status(void *param); void _ma_reset_status(MARIA_HA *maria); int _ma_def_scan_remember_pos(MARIA_HA *info, MARIA_RECORD_POS *lastpos); -void _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos); +int _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos); #include "ma_commit.h" diff --git a/storage/maria/unittest/ma_test_recovery.expected b/storage/maria/unittest/ma_test_recovery.expected index 6a6051735c5..6aaff86e6cf 100644 --- a/storage/maria/unittest/ma_test_recovery.expected +++ b/storage/maria/unittest/ma_test_recovery.expected @@ -69,8 +69,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -78,8 +78,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -87,8 +87,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -98,8 +98,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -107,8 +107,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -116,8 +116,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -166,8 +166,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -175,8 +175,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -184,8 +184,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -195,8 +195,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -204,8 +204,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -213,8 +213,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -263,8 +263,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -272,8 +272,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -281,8 +281,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -292,8 +292,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -301,8 +301,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -310,8 +310,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -360,8 +360,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -369,8 +369,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -378,8 +378,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -389,8 +389,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -398,8 +398,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -407,8 +407,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -457,8 +457,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -466,8 +466,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -475,8 +475,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -486,8 +486,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -495,8 +495,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -504,8 +504,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -554,8 +554,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -563,8 +563,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -572,8 +572,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -583,8 +583,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -592,8 +592,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -601,8 +601,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -651,8 +651,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -660,8 +660,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -669,8 +669,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -680,8 +680,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -689,8 +689,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -698,8 +698,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -748,8 +748,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -757,8 +757,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -766,8 +766,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -777,8 +777,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -786,8 +786,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -795,8 +795,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -845,8 +845,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -854,8 +854,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -863,8 +863,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -874,8 +874,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -883,8 +883,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -892,8 +892,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -942,8 +942,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -951,8 +951,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -960,8 +960,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -971,8 +971,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -980,8 +980,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -989,8 +989,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1039,8 +1039,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1048,8 +1048,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1057,8 +1057,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1068,8 +1068,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1077,8 +1077,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1086,8 +1086,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1136,8 +1136,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1145,8 +1145,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1154,8 +1154,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1165,8 +1165,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1174,8 +1174,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1183,8 +1183,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1233,8 +1233,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1242,8 +1242,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1251,8 +1251,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1262,8 +1262,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1271,8 +1271,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1280,8 +1280,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1330,8 +1330,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1339,8 +1339,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1348,8 +1348,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1359,8 +1359,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1368,8 +1368,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1377,8 +1377,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1427,8 +1427,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1436,8 +1436,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1445,8 +1445,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1456,8 +1456,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1465,8 +1465,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1474,8 +1474,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1524,8 +1524,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1533,8 +1533,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1542,8 +1542,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1553,8 +1553,8 @@ Dying on request without maria_commit()/maria_close() applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1562,8 +1562,8 @@ testing idempotency applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= @@ -1571,8 +1571,8 @@ testing applying of CLRs to recreate table applying log Differences in aria_chk -dvv, recovery not yet perfect ! ========DIFF START======= -6c6 -< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled +7c7 +< Status: checked,analyzed,optimized keys,sorted index pages,zerofilled,movable --- > Status: changed ========DIFF END======= diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 2b422608597..b99cf9f647e 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1126,9 +1126,9 @@ int ha_myisam::repair(THD *thd, HA_CHECK ¶m, bool do_optimize) else { thd_proc_info(thd, "Repair by sorting"); + DEBUG_SYNC(thd, "myisam_before_repair_by_sort"); error = mi_repair_by_sort(¶m, file, fixed_name, test(param.testflag & T_QUICK)); - DEBUG_SYNC(thd, "myisam_after_repair_by_sort"); } if (error && file->create_unique_index_by_sort && share->state.dupp_key != MAX_KEY) diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index 60ea7757827..011df5e8eb9 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -85,9 +85,10 @@ int mi_write(MI_INFO *info, uchar *record) /* Calculate and check all unique constraints */ for (i=0 ; i < share->state.header.uniques ; i++) { - if (mi_check_unique(info,share->uniqueinfo+i,record, - mi_unique_hash(share->uniqueinfo+i,record), - HA_OFFSET_ERROR)) + MI_UNIQUEDEF *def= share->uniqueinfo + i; + if (mi_is_key_active(share->state.key_map, def->key) && + mi_check_unique(info, def, record, mi_unique_hash(def, record), + HA_OFFSET_ERROR)) goto err2; } diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 1985a53acf8..74be8b99d87 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -2144,7 +2144,8 @@ static my_off_t write_huff_tree(HUFF_TREE *huff_tree, uint trees) */ if (!(packed_tree=(uint*) my_alloca(sizeof(uint)*length*2))) { - my_error(EE_OUTOFMEMORY,MYF(ME_BELL),sizeof(uint)*length*2); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_FATALERROR), + sizeof(uint)*length*2); return 0; } diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 41bba55c397..69f84a9805a 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1447,7 +1447,7 @@ static void split_file_name(const char *file_name, char buff[FN_REFLEN]; db->length= 0; - strmake(buff, file_name, sizeof(buff)-1); + strmake_buf(buff, file_name); dir_length= dirname_length(buff); if (dir_length > 1) { diff --git a/storage/perfschema/gen_pfs_lex_token.THIS b/storage/perfschema/gen_pfs_lex_token.THIS deleted file mode 100644 index b5165266759..00000000000 Binary files a/storage/perfschema/gen_pfs_lex_token.THIS and /dev/null differ diff --git a/storage/perfschema/ha_perfschema.cc b/storage/perfschema/ha_perfschema.cc index c6c967ceb9d..aca5ad8c731 100644 --- a/storage/perfschema/ha_perfschema.cc +++ b/storage/perfschema/ha_perfschema.cc @@ -18,11 +18,9 @@ Performance schema storage engine (implementation). */ -#include "my_global.h" +#include "sql_plugin.h" #include "my_pthread.h" #include "my_atomic.h" -#include "sql_plugin.h" -#include "mysql/plugin.h" #include "ha_perfschema.h" #include "pfs_engine_table.h" #include "pfs_column_values.h" diff --git a/storage/perfschema/pfs_engine_table.cc b/storage/perfschema/pfs_engine_table.cc index 304e837fa84..c3f29787951 100644 --- a/storage/perfschema/pfs_engine_table.cc +++ b/storage/perfschema/pfs_engine_table.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -514,7 +514,7 @@ void PFS_engine_table::set_field_enum(Field *f, ulonglong value) void PFS_engine_table::set_field_timestamp(Field *f, ulonglong value) { - DBUG_ASSERT(f->real_type() == MYSQL_TYPE_TIMESTAMP); + DBUG_ASSERT(is_timestamp_type(f->real_type())); Field_timestamp *f2= (Field_timestamp*) f; f2->store_TIME((long)(value / 1000000), (value % 1000000)); } @@ -715,7 +715,7 @@ bool pfs_show_status(handlerton *hton, THD *thd, uint buflen; const char *name; int i; - uint size; + size_t size; DBUG_ENTER("pfs_show_status"); @@ -729,7 +729,7 @@ bool pfs_show_status(handlerton *hton, THD *thd, if (stat != HA_ENGINE_STATUS) DBUG_RETURN(false); - uint total_memory= 0; + size_t total_memory= 0; for (i=0; /* empty */; i++) { @@ -1345,7 +1345,7 @@ bool pfs_show_status(handlerton *hton, THD *thd, break; } - buflen= int10_to_str(size, buf, 10) - buf; + buflen= longlong10_to_str(size, buf, 10) - buf; if (print(thd, PERFORMANCE_SCHEMA_str.str, PERFORMANCE_SCHEMA_str.length, name, strlen(name), diff --git a/storage/perfschema/pfs_global.cc b/storage/perfschema/pfs_global.cc index 6c3b79a3e1f..2351b829894 100644 --- a/storage/perfschema/pfs_global.cc +++ b/storage/perfschema/pfs_global.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -33,7 +33,7 @@ #endif bool pfs_initialized= false; -ulonglong pfs_allocated_memory= 0; +size_t pfs_allocated_memory= 0; /** Memory allocation for the performance schema. diff --git a/storage/perfschema/pfs_global.h b/storage/perfschema/pfs_global.h index 693153cb097..a0e6c97a406 100644 --- a/storage/perfschema/pfs_global.h +++ b/storage/perfschema/pfs_global.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 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 @@ -23,8 +23,9 @@ /** True when the performance schema is initialized. */ extern bool pfs_initialized; + /** Total memory allocated by the performance schema, in bytes. */ -extern ulonglong pfs_allocated_memory; +extern size_t pfs_allocated_memory; void *pfs_malloc(size_t size, myf flags); diff --git a/storage/sphinx/CMakeLists.txt b/storage/sphinx/CMakeLists.txt index 933f7e32c31..2e10da7903a 100644 --- a/storage/sphinx/CMakeLists.txt +++ b/storage/sphinx/CMakeLists.txt @@ -4,3 +4,12 @@ IF(MSVC) LINK_LIBRARIES(ws2_32) ENDIF(MSVC) MYSQL_ADD_PLUGIN(sphinx ha_sphinx.cc STORAGE_ENGINE) + +IF(NOT WITHOUT_SPHINX_STORAGE_ENGINE) + ADD_LIBRARY(snippets_udf MODULE snippets_udf.cc) + TARGET_LINK_LIBRARIES(snippets_udf mysys) # my_error + ADD_DEPENDENCIES(snippets_udf GenError) # uses generated error constants + SET_TARGET_PROPERTIES(snippets_udf PROPERTIES OUTPUT_NAME sphinx PREFIX "") + INSTALL(TARGETS snippets_udf COMPONENT Server DESTINATION ${INSTALL_PLUGINDIR}) +ENDIF() + diff --git a/storage/sphinx/snippets_udf.cc b/storage/sphinx/snippets_udf.cc index 85fb66ab793..5318592ab5f 100644 --- a/storage/sphinx/snippets_udf.cc +++ b/storage/sphinx/snippets_udf.cc @@ -1,5 +1,5 @@ // -// $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $ +// $Id: snippets_udf.cc 3508 2012-11-05 11:48:48Z kevg $ // // @@ -17,12 +17,19 @@ #include #include +#ifndef __WIN__ #include #include +#else +#include +#endif #include -#if MYSQL_VERSION_ID>50100 +#if MYSQL_VERSION_ID>=50515 +#include "sql_class.h" +#include "sql_array.h" +#elif MYSQL_VERSION_ID>50100 #include "mysql_priv.h" #include #else @@ -84,9 +91,9 @@ void sphUnalignedWrite ( void * pPtr, const T & tVal ) #define SafeDeleteArray(_arg) { if ( _arg ) delete [] ( _arg ); (_arg) = NULL; } #define Min(a,b) ((a)<(b)?(a):(b)) - +#ifndef __WIN__ typedef unsigned int DWORD; - +#endif inline DWORD sphF2DW ( float f ) { union { float f; uint32 d; } u; u.f = f; return u.d; } static char * sphDup ( const char * sSrc, int iLen=-1 ) @@ -158,7 +165,7 @@ enum SEARCHD_COMMAND_EXCERPT = 1, - VER_COMMAND_EXCERPT = 0x103, + VER_COMMAND_EXCERPT = 0x104, }; /// known answers @@ -380,23 +387,44 @@ int CSphUrl::Connect() else { int tmp_errno; + bool bError = false; + +#if MYSQL_VERSION_ID>=50515 + struct addrinfo *hp = NULL; + tmp_errno = getaddrinfo ( m_sHost, NULL, NULL, &hp ); + if ( !tmp_errno || !hp || !hp->ai_addr ) + { + bError = true; + if ( hp ) + freeaddrinfo ( hp ); + } +#else struct hostent tmp_hostent, *hp; char buff2 [ GETHOSTBYNAME_BUFF_SIZE ]; - hp = my_gethostbyname_r ( m_sHost, &tmp_hostent, buff2, sizeof(buff2), &tmp_errno ); if ( !hp ) { my_gethostbyname_r_free(); + bError = true; + } +#endif + if ( bError ) + { char sError[256]; - snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", m_sHost ); + my_snprintf ( sError, sizeof(sError), "failed to resolve searchd host (name=%s)", m_sHost ); my_error ( ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), sError ); return -1; } +#if MYSQL_VERSION_ID>=50515 + memcpy ( &sin.sin_addr, hp->ai_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->ai_addrlen ) ); + freeaddrinfo ( hp ); +#else memcpy ( &sin.sin_addr, hp->h_addr, Min ( sizeof(sin.sin_addr), (size_t)hp->h_length ) ); my_gethostbyname_r_free(); +#endif } } else { @@ -534,12 +562,16 @@ CSphResponse::Read ( int iSocket, int iClientVersion ) } /// udf - +#ifdef _MSC_VER +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif extern "C" { - my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessage ); - void sphinx_snippets_deinit ( UDF_INIT * pUDF ); - char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsigned long * pLength, char * pIsNull, char * sError ); + DLLEXPORT my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessage ); + DLLEXPORT void sphinx_snippets_deinit ( UDF_INIT * pUDF ); + DLLEXPORT char * sphinx_snippets ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sResult, unsigned long * pLength, char * pIsNull, char * sError ); }; #define MAX_MESSAGE_LENGTH 255 @@ -608,7 +640,7 @@ struct CSphSnippets } #define STRING CHECK_TYPE(STRING_RESULT) -#define INT CHECK_TYPE(INT_RESULT); int iValue = *(long long *)pArgs->args[i] +#define INT CHECK_TYPE(INT_RESULT); int iValue =(int) *(long long *)pArgs->args[i] my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessage ) { @@ -662,6 +694,7 @@ my_bool sphinx_snippets_init ( UDF_INIT * pUDF, UDF_ARGS * pArgs, char * sMessag KEYWORD("load_files") { INT; if ( iValue ) pOpts->m_iFlags |= 128; } KEYWORD("allow_empty") { INT; if ( iValue ) pOpts->m_iFlags |= 256; } KEYWORD("emit_zones") { INT; if ( iValue ) pOpts->m_iFlags |= 512; } + KEYWORD("load_files_scattered") { INT; if ( iValue ) pOpts->m_iFlags |= 1024; } else { snprintf ( sMessage, MAX_MESSAGE_LENGTH, "unrecognized argument: %.*s", @@ -787,5 +820,5 @@ void sphinx_snippets_deinit ( UDF_INIT * pUDF ) } // -// $Id: snippets_udf.cc 3087 2012-01-30 23:07:35Z shodan $ +// $Id: snippets_udf.cc 3508 2012-11-05 11:48:48Z kevg $ // diff --git a/storage/spider/CMakeLists.txt b/storage/spider/CMakeLists.txt new file mode 100644 index 00000000000..2e6046f6a29 --- /dev/null +++ b/storage/spider/CMakeLists.txt @@ -0,0 +1,45 @@ +SET(SPIDER_SOURCES + spd_param.cc spd_sys_table.cc spd_trx.cc spd_db_conn.cc spd_conn.cc + spd_table.cc spd_direct_sql.cc spd_udf.cc spd_ping_table.cc + spd_copy_tables.cc spd_i_s.cc spd_malloc.cc ha_spider.cc spd_udf.def + spd_db_mysql.cc spd_db_handlersocket.cc spd_db_oracle.cc + hs_client/config.cpp hs_client/escape.cpp hs_client/fatal.cpp + hs_client/hstcpcli.cpp hs_client/socket.cpp hs_client/string_util.cpp +) + +IF(DEFINED ENV{ORACLE_HOME}) + SET(ORACLE_HOME $ENV{ORACLE_HOME}) + FIND_PATH(ORACLE_INCLUDE_DIR oci.h PATHS ${ORACLE_HOME}/rdbms/public) + SET(ORACLE_OCI_LIB_NAME clntsh) + SET(ORACLE_LIB_DIR ${ORACLE_HOME}/lib) + FIND_LIBRARY(ORACLE_OCI_LIBRARY NAMES ${ORACLE_OCI_LIB_NAME} PATHS ${ORACLE_LIB_DIR}) +ENDIF() + +IF(EXISTS ${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake) + SET(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR /Zi") + SET(CMAKE_C_FLAGS_DEBUG + "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX -DUSE_SYMDIR /Zi") + SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /MAP /MAPINFO:EXPORTS") + INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake") + + INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/sql + ${CMAKE_SOURCE_DIR}/regex) + + MYSQL_STORAGE_ENGINE(SPIDER) +ELSE() + INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/storage/spider/hs_client + ${ORACLE_INCLUDE_DIR}) + + SET(SPIDER_DEB_FILES "usr/lib/mysql/plugin/ha_spider.so" PARENT_SCOPE) + MYSQL_ADD_PLUGIN(spider ${SPIDER_SOURCES} STORAGE_ENGINE MODULE_ONLY MODULE_OUTPUT_NAME "ha_spider") +ENDIF() + +IF(ORACLE_INCLUDE_DIR AND ORACLE_OCI_LIBRARY) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_ORACLE_OCI -DLINUX -D_GNU_SOURCE -D_REENTRANT") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_ORACLE_OCI -DLINUX -D_GNU_SOURCE -D_REENTRANT") + TARGET_LINK_LIBRARIES (spider ${ORACLE_OCI_LIBRARY}) +ENDIF() diff --git a/storage/spider/Makefile.am b/storage/spider/Makefile.am new file mode 100644 index 00000000000..3847b3f2332 --- /dev/null +++ b/storage/spider/Makefile.am @@ -0,0 +1,89 @@ +HAVE_HANDLERSOCKET = "-DHAVE_HANDLERSOCKET" + +pkgplugindir = $(pkglibdir)/plugin +INCLUDES = -I$(SPD_MYSQL_INC)$(top_srcdir)/include \ + -I$(SPD_MYSQL_INC)$(top_srcdir)/regex \ + -I$(SPD_MYSQL_INC)$(top_srcdir)/sql \ + -I$(SPD_MYSQL_INC)$(top_srcdir)/extra/yassl/include \ + -I./hs_client \ + $(MYSQL_INCLUDE_PATH) \ + $(HANDLERSOCKET_INCLUDE_PATH) + +noinst_HEADERS = ha_spider.h spd_conn.h spd_db_conn.h \ + spd_db_include.h spd_err.h spd_sys_table.h \ + spd_table.h spd_trx.h spd_include.h spd_param.h \ + spd_direct_sql.h spd_udf.h spd_ping_table.h \ + spd_copy_tables.h spd_malloc.h \ + spd_db_mysql.h spd_db_handlersocket.h \ + hs_client/allocator.hpp hs_client/config.hpp \ + hs_client/mutex.hpp hs_client/string_util.hpp \ + hs_client/auto_addrinfo.hpp hs_client/escape.hpp \ + hs_client/socket.hpp hs_client/thread.hpp \ + hs_client/auto_file.hpp hs_client/fatal.hpp \ + hs_client/string_buffer.hpp hs_client/util.hpp \ + hs_client/auto_ptrcontainer.hpp \ + hs_client/hstcpcli.hpp hs_client/string_ref.hpp \ + hs_client/hs_compat.h + +lib_LTLIBRARIES = $(PLUGIN_SPIDER_LTLIBRARIES_TARGET) +EXTRA_LTLIBRARIES = ha_spider.la +pkgplugin_LTLIBRARIES = @plugin_spider_shared_target@ +ha_spider_la_LDFLAGS = -shared -module -rpath $(pkgplugindir) +ha_spider_la_CXXFLAGS = $(AM_CXXFLAGS) -DMYSQL_DYNAMIC_PLUGIN \ + $(HAVE_HANDLERSOCKET) +ha_spider_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN \ + $(HAVE_HANDLERSOCKET) +ha_spider_la_SOURCES = \ + spd_param.cc \ + spd_sys_table.cc \ + spd_trx.cc \ + spd_db_conn.cc \ + spd_conn.cc \ + spd_table.cc \ + spd_direct_sql.cc \ + spd_udf.cc \ + spd_ping_table.cc \ + spd_copy_tables.cc \ + spd_i_s.cc \ + spd_malloc.cc \ + ha_spider.cc \ + spd_db_mysql.cc \ + spd_db_handlersocket.cc \ + hs_client/config.cpp \ + hs_client/escape.cpp \ + hs_client/fatal.cpp \ + hs_client/hstcpcli.cpp \ + hs_client/socket.cpp \ + hs_client/string_util.cpp + +lib_LIBRARIES = $(PLUGIN_SPIDER_LIBRARIES_TARGET) +EXTRA_LIBRARIES = libspider.a +noinst_LIBRARIES = @plugin_spider_static_target@ +libspider_a_CXXFLAGS = $(AM_CXXFLAGS) $(HAVE_HANDLERSOCKET) +libspider_a_CFLAGS = $(AM_CFLAGS) $(HAVE_HANDLERSOCKET) +libspider_a_SOURCES = \ + spd_param.cc \ + spd_sys_table.cc \ + spd_trx.cc \ + spd_db_conn.cc \ + spd_conn.cc \ + spd_table.cc \ + spd_direct_sql.cc \ + spd_udf.cc \ + spd_ping_table.cc \ + spd_copy_tables.cc \ + spd_i_s.cc \ + spd_malloc.cc \ + ha_spider.cc \ + spd_db_mysql.cc \ + spd_db_handlersocket.cc \ + hs_client/config.cpp \ + hs_client/escape.cpp \ + hs_client/fatal.cpp \ + hs_client/hstcpcli.cpp \ + hs_client/socket.cpp \ + hs_client/string_util.cpp + +EXTRA_DIST = plug.in +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/storage/spider/configure.in b/storage/spider/configure.in new file mode 100644 index 00000000000..6f103aed871 --- /dev/null +++ b/storage/spider/configure.in @@ -0,0 +1,95 @@ +AC_INIT([spider_engine], [1.0], [kentokushiba@gmail.com]) +AC_CONFIG_HEADERS([config.h]) +AM_INIT_AUTOMAKE + +AC_PROG_CC +AC_PROG_CXX +AC_PROG_LIBTOOL + +AC_TYPE_SIZE_T + +AC_DEFUN([MYSQL_PATH_TEST],[ + AC_MSG_CHECKING([mysql source path]) + AC_ARG_WITH([mysql], + [AS_HELP_STRING([--with-mysql=PATH],[mysql source directory PATH])], + [ + if test \ + -f $withval/include/mysql/plugin.h -a \ + -f $withval/include/mysql.h -a \ + -f $withval/include/errmsg.h -a \ + \( -f $withval/sql/mysql_priv.h -o -f $withval/sql/sql_priv.h \) ; + then + SPD_MYSQL_INC="$withval/" + AC_MSG_RESULT([yes]) + plugin_spider_shared_target="" + AC_SUBST(plugin_spider_shared_target) + plugin_spider_static_target="" + AC_SUBST(plugin_spider_static_target) + PLUGIN_SPIDER_LTLIBRARIES_TARGET="ha_spider.la" + AC_SUBST(PLUGIN_SPIDER_LTLIBRARIES_TARGET) + PLUGIN_SPIDER_LIBRARIES_TARGET="libspider.a" + AC_SUBST(PLUGIN_SPIDER_LIBRARIES_TARGET) + LIBTOOL="$LIBTOOL --preserve-dup-deps" + AC_SUBST(LIBTOOL) + else + AC_MSG_ERROR([Can't find header files. Please check --with-mysql=PATH option]) + fi + ], + [ + if test \ + -f ../../include/mysql/plugin.h -a \ + -f ../../include/mysql.h -a \ + -f ../../include/errmsg.h -a \ + \( -f ../../sql/mysql_priv.h -o ../../sql/sql_priv.h \) ; + then + SPD_MYSQL_INC="../../" + AC_MSG_RESULT([no]) + else + AC_MSG_ERROR([Can't find header files. Please set --with-mysql=PATH option]) + fi + ] + ) +]) + +MYSQL_PATH_TEST +AC_SUBST(SPD_MYSQL_INC) + +AC_DEFUN([MYSQL_INCLUDE_PATH_TEST],[ + AC_MSG_CHECKING([mysql include path]) + AC_ARG_WITH([mysql-include], + [AS_HELP_STRING([--with-mysql-include=PATH],[mysql include directory PATH])], + [ + if test \ + -f $withval/mysql_version.h -a \ + -f $withval/my_config.h ; + then + MYSQL_INCLUDE_PATH="-I $withval/" + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR([Can't find "my_config.h". Please check --with-mysql-include=PATH option]) + fi + ], + [ + if test \ + -f ../../include/mysql_version.h -a \ + -f ../../include/my_config.h ; + then + MYSQL_INCLUDE_PATH="-I ../../include/" + AC_MSG_RESULT([no]) + else + AC_MSG_ERROR([Can't find "my_config.h". Please set --with-mysql-include=PATH option]) + fi + ] + ) +]) + +MYSQL_INCLUDE_PATH_TEST +AC_SUBST(MYSQL_INCLUDE_PATH) + +CXXFLAGS="$CXXFLAGS -fno-implicit-templates -fno-exceptions -fno-rtti" + + +AC_CHECK_FUNCS([memset strchr strncasecmp]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc new file mode 100644 index 00000000000..f2b79424ba0 --- /dev/null +++ b/storage/spider/ha_spider.cc @@ -0,0 +1,13545 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#ifdef USE_PRAGMA_IMPLEMENTATION +#pragma implementation +#endif + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "key.h" +#endif +#include "ha_partition.h" +#include "spd_param.h" +#include "spd_err.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_table.h" +#include "spd_sys_table.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_db_conn.h" +#include "spd_ping_table.h" +#include "spd_malloc.h" + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 +#define SPIDER_CAN_BG_SEARCH (1LL << 37) +#define SPIDER_CAN_BG_INSERT (1LL << 38) +#define SPIDER_CAN_BG_UPDATE (1LL << 39) +#else +#define SPIDER_CAN_BG_SEARCH (LL(1) << 37) +#define SPIDER_CAN_BG_INSERT (LL(1) << 38) +#define SPIDER_CAN_BG_UPDATE (LL(1) << 39) +#endif + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +ha_spider::ha_spider( +) : handler(spider_hton_ptr, NULL) +{ + DBUG_ENTER("ha_spider::ha_spider"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 139); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + share = NULL; + trx = NULL; + conns = NULL; + need_mons = NULL; + condition = NULL; + blob_buff = NULL; + conn_keys = NULL; + spider_thread_id = 0; + trx_conn_adjustment = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + trx_hs_r_conn_adjustment = 0; + trx_hs_w_conn_adjustment = 0; +#endif + search_link_query_id = 0; + searched_bitmap = NULL; +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_handler_share = NULL; + pt_handler_share_creator = NULL; +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL + multi_range_keys = NULL; +#endif + append_tblnm_alias = NULL; + is_clone = FALSE; + clone_bitmap_init = FALSE; + pt_clone_source_handler = NULL; + pt_clone_last_searcher = NULL; + ft_handler = NULL; + ft_first = NULL; + ft_current = NULL; + ft_count = 0; + ft_init_without_index_init = FALSE; + sql_kinds = 0; + error_mode = 0; + use_spatial_index = FALSE; + use_pre_call = FALSE; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + hs_pushed_ret_fields_num = MAX_FIELDS; + hs_pushed_ret_fields = NULL; + hs_pushed_ret_fields_size = 0; + hs_increment = FALSE; + hs_decrement = FALSE; + hs_pushed_strref_num = 0; +#endif + direct_update_fields = NULL; +#endif +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + info_limit = 9223372036854775807LL; +#endif +#ifdef HA_CAN_BULK_ACCESS + is_bulk_access_clone = FALSE; + synced_from_clone_source = FALSE; + bulk_access_started = FALSE; + bulk_access_executing = FALSE; + bulk_access_pre_called = FALSE; + bulk_access_link_first = NULL; +/* + init_ha_mem_root = FALSE; +*/ +#endif + result_link_idx = 0; + result_list.have_sql_kind_backup = FALSE; + result_list.sqls = NULL; + result_list.insert_sqls = NULL; + result_list.update_sqls = NULL; + result_list.tmp_sqls = NULL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_result_buf = NULL; +#endif + result_list.tmp_tables_created = FALSE; + result_list.bgs_working = FALSE; + result_list.direct_order_limit = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_has_result = FALSE; +#endif + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + result_list.tmp_pos_row_first = NULL; + DBUG_VOID_RETURN; +} + +ha_spider::ha_spider( + handlerton *hton, + TABLE_SHARE *table_arg +) : handler(hton, table_arg) +{ + DBUG_ENTER("ha_spider::ha_spider"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 0); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + share = NULL; + trx = NULL; + conns = NULL; + need_mons = NULL; + condition = NULL; + blob_buff = NULL; + conn_keys = NULL; + spider_thread_id = 0; + trx_conn_adjustment = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + trx_hs_r_conn_adjustment = 0; + trx_hs_w_conn_adjustment = 0; +#endif + search_link_query_id = 0; + searched_bitmap = NULL; +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_handler_share = NULL; + pt_handler_share_creator = NULL; +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL + multi_range_keys = NULL; +#endif + append_tblnm_alias = NULL; + is_clone = FALSE; + clone_bitmap_init = FALSE; + pt_clone_source_handler = NULL; + pt_clone_last_searcher = NULL; + ft_handler = NULL; + ft_first = NULL; + ft_current = NULL; + ft_count = 0; + ft_init_without_index_init = FALSE; + sql_kinds = 0; + error_mode = 0; + use_spatial_index = FALSE; + use_pre_call = FALSE; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + hs_pushed_ret_fields_num = MAX_FIELDS; + hs_pushed_ret_fields = NULL; + hs_pushed_ret_fields_size = 0; + hs_increment = FALSE; + hs_decrement = FALSE; + hs_pushed_strref_num = 0; +#endif + direct_update_fields = NULL; +#endif +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + info_limit = 9223372036854775807LL; +#endif +#ifdef HA_CAN_BULK_ACCESS + is_bulk_access_clone = FALSE; + synced_from_clone_source = FALSE; + bulk_access_started = FALSE; + bulk_access_executing = FALSE; + bulk_access_pre_called = FALSE; + bulk_access_link_first = NULL; +/* + init_ha_mem_root = FALSE; +*/ +#endif + result_link_idx = 0; + result_list.have_sql_kind_backup = FALSE; + result_list.sqls = NULL; + result_list.insert_sqls = NULL; + result_list.update_sqls = NULL; + result_list.tmp_sqls = NULL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_result_buf = NULL; +#endif + result_list.tmp_tables_created = FALSE; + result_list.bgs_working = FALSE; + result_list.direct_order_limit = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_has_result = FALSE; +#endif + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + result_list.tmp_pos_row_first = NULL; + ref_length = sizeof(SPIDER_POSITION); + DBUG_VOID_RETURN; +} + +ha_spider::~ha_spider() +{ + DBUG_ENTER("ha_spider::~ha_spider"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +handler *ha_spider::clone( + const char *name, + MEM_ROOT *mem_root +) { + ha_spider *spider; + DBUG_ENTER("ha_spider::clone"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + !(spider = (ha_spider *) + get_new_handler(table->s, mem_root, spider_hton_ptr)) || + !(spider->ref = (uchar*) alloc_root(mem_root, ALIGN_SIZE(ref_length) * 2)) + ) + DBUG_RETURN(NULL); + spider->is_clone = TRUE; + spider->pt_clone_source_handler = this; + if (spider->ha_open(table, name, table->db_stat, + HA_OPEN_IGNORE_IF_LOCKED)) + DBUG_RETURN(NULL); + spider->sync_from_clone_source_base(this); + + DBUG_RETURN((handler *) spider); +} + +static const char *ha_spider_exts[] = { + NullS +}; + +const char **ha_spider::bas_ext() const +{ + return ha_spider_exts; +} + +int ha_spider::open( + const char* name, + int mode, + uint test_if_locked +) { + THD *thd = ha_thd(); + int error_num, roop_count; + int init_sql_alloc_size; +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_SHARE *partition_share; + uchar *idx_read_bitmap, *idx_write_bitmap, + *rnd_read_bitmap, *rnd_write_bitmap; + uint part_num; + bool create_pt_handler_share = FALSE, pt_handler_mutex = FALSE, + may_be_clone = FALSE; + ha_spider **pt_handler_share_handlers; +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value; +#endif + DBUG_ENTER("ha_spider::open"); + DBUG_PRINT("info",("spider this=%p", this)); + + dup_key_idx = (uint) -1; + conn_kinds = SPIDER_CONN_KIND_MYSQL; + if (!spider_get_share(name, table, thd, this, &error_num)) + goto error_get_share; + thr_lock_data_init(&share->lock,&lock,NULL); + +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_share = share->partition_share; + table->file->get_no_parts("", &part_num); + if (partition_share) + { + pt_handler_mutex = TRUE; + pthread_mutex_lock(&partition_share->pt_handler_mutex); +/* + if ( + !partition_share->partition_handler_share || + partition_share->partition_handler_share->table != table + ) + create_pt_handler_share = TRUE; +*/ +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value = my_calc_hash(&partition_share->pt_handler_hash, + (uchar*) &table, sizeof(TABLE *)); + if (!(partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE*) + my_hash_search_using_hash_value(&partition_share->pt_handler_hash, + hash_value, (uchar*) &table, sizeof(TABLE *)))) +#else + if (!(partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE*) + my_hash_search(&partition_share->pt_handler_hash, (uchar*) &table, + sizeof(TABLE *)))) +#endif + { + create_pt_handler_share = TRUE; + } + } + + if (create_pt_handler_share) + { + if (!(searched_bitmap = (uchar *) + spider_bulk_malloc(spider_current_trx, 15, MYF(MY_WME), + &searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &partition_handler_share, sizeof(SPIDER_PARTITION_HANDLER_SHARE), + &idx_read_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &idx_write_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &rnd_read_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &rnd_write_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &pt_handler_share_handlers, sizeof(ha_spider *) * part_num, + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_searched_bitmap_alloc; + } + DBUG_PRINT("info",("spider create partition_handler_share")); + partition_handler_share->use_count = 1; +/* + if (partition_handler_share->use_count < part_num) + partition_share->partition_handler_share = partition_handler_share; +*/ + DBUG_PRINT("info",("spider table=%p", table)); + partition_handler_share->table = table; + partition_handler_share->searched_bitmap = NULL; + partition_handler_share->idx_read_bitmap = idx_read_bitmap; + partition_handler_share->idx_write_bitmap = idx_write_bitmap; + partition_handler_share->rnd_read_bitmap = rnd_read_bitmap; + partition_handler_share->rnd_write_bitmap = rnd_write_bitmap; + partition_handler_share->between_flg = FALSE; + partition_handler_share->idx_bitmap_is_set = FALSE; + partition_handler_share->rnd_bitmap_is_set = FALSE; + partition_handler_share->table_hash_value = hash_value; + partition_handler_share->creator = this; + pt_handler_share_creator = this; + if (part_num) + { + partition_handler_share->handlers = (void **) pt_handler_share_handlers; + partition_handler_share->handlers[0] = this; + } else + partition_handler_share->handlers = NULL; + uint old_elements = partition_share->pt_handler_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&partition_share->pt_handler_hash, + hash_value, (uchar*) partition_handler_share)) +#else + if (my_hash_insert(&partition_share->pt_handler_hash, + (uchar*) partition_handler_share)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_hash_insert; + } + if (partition_share->pt_handler_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + partition_share->pt_handler_hash, + (partition_share->pt_handler_hash.array.max_element - old_elements) * + partition_share->pt_handler_hash.array.size_of_element); + } + pthread_mutex_unlock(&partition_share->pt_handler_mutex); + pt_handler_mutex = FALSE; + } else { +#endif + if (!(searched_bitmap = (uchar *) + spider_bulk_malloc(spider_current_trx, 16, MYF(MY_WME), + &searched_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + &position_bitmap, sizeof(uchar) * no_bytes_in_map(table->read_set), + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_searched_bitmap_alloc; + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (partition_share) + { + DBUG_PRINT("info",("spider copy partition_handler_share")); +/* + partition_handler_share = (SPIDER_PARTITION_HANDLER_SHARE *) + partition_share->partition_handler_share; +*/ + if (part_num) + { + if (partition_handler_share->use_count >= part_num) + may_be_clone = TRUE; + else { + partition_handler_share->handlers[ + partition_handler_share->use_count] = this; + partition_handler_share->use_count++; + } + } +/* + if (partition_handler_share->use_count == part_num) + partition_share->partition_handler_share = NULL; +*/ + pthread_mutex_unlock(&partition_share->pt_handler_mutex); + pt_handler_mutex = FALSE; + } + } +#endif + + init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + + result_list.table = table; + result_list.first = NULL; + result_list.last = NULL; + result_list.current = NULL; + result_list.record_num = 0; + if ( + !(result_list.sqls = new spider_string[share->link_count]) || + !(result_list.insert_sqls = new spider_string[share->link_count]) || + !(result_list.update_sqls = new spider_string[share->link_count]) || + !(result_list.tmp_sqls = new spider_string[share->link_count]) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + result_list.sqls[roop_count].init_calc_mem(80); + result_list.insert_sqls[roop_count].init_calc_mem(81); + result_list.update_sqls[roop_count].init_calc_mem(82); + result_list.tmp_sqls[roop_count].init_calc_mem(83); + uint all_link_idx = conn_link_idx[roop_count]; + uint dbton_id = share->sql_dbton_ids[all_link_idx]; + if (share->dbton_share[dbton_id]->need_change_db_table_name()) + { + if ( + result_list.sqls[roop_count].real_alloc(init_sql_alloc_size) || + result_list.insert_sqls[roop_count].real_alloc(init_sql_alloc_size) || + result_list.update_sqls[roop_count].real_alloc(init_sql_alloc_size) || + result_list.tmp_sqls[roop_count].real_alloc(init_sql_alloc_size) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_result_list; + } + } + result_list.sqls[roop_count].set_charset(share->access_charset); + result_list.insert_sqls[roop_count].set_charset(share->access_charset); + result_list.update_sqls[roop_count].set_charset(share->access_charset); + result_list.tmp_sqls[roop_count].set_charset(share->access_charset); + } + + DBUG_PRINT("info",("spider blob_fields=%d", table_share->blob_fields)); + if (table_share->blob_fields) + { + if (!(blob_buff = new spider_string[table_share->fields])) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_blob_buff; + } + for (roop_count = 0; roop_count < (int) table_share->fields; roop_count++) + { + blob_buff[roop_count].init_calc_mem(84); + blob_buff[roop_count].set_charset(table->field[roop_count]->charset()); + } + } + +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (may_be_clone && thd_sql_command(thd) != SQLCOM_ALTER_TABLE) + is_clone = TRUE; +#endif + if (is_clone) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (part_num) + { + for (roop_count = 0; roop_count < (int) part_num; roop_count++) + { + if (((ha_spider *) partition_handler_share->handlers[roop_count])-> + share == share) + { + pt_clone_source_handler = + (ha_spider *) partition_handler_share->handlers[roop_count]; + break; + } + } + } +#endif + + sql_command = pt_clone_source_handler->sql_command; + result_list.lock_type = pt_clone_source_handler->result_list.lock_type; + lock_mode = pt_clone_source_handler->lock_mode; + + if (!pt_clone_source_handler->clone_bitmap_init) + { + pt_clone_source_handler->set_select_column_mode(); + pt_clone_source_handler->clone_bitmap_init = TRUE; + } + set_clone_searched_bitmap(); + position_bitmap_init = FALSE; + } +#ifdef HA_CAN_BULK_ACCESS + external_lock_cnt = 0; +#endif + + if (reset()) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_reset; + } + + DBUG_RETURN(0); + +error_reset: + delete [] blob_buff; + blob_buff = NULL; +error_init_blob_buff: +error_init_result_list: +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + partition_handler_share && + pt_handler_share_creator == this + ) { + partition_share = share->partition_share; + if (!pt_handler_mutex) + pthread_mutex_lock(&partition_share->pt_handler_mutex); +/* + if (partition_share->partition_handler_share == partition_handler_share) + partition_share->partition_handler_share = NULL; +*/ +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&partition_share->pt_handler_hash, + partition_handler_share->table_hash_value, + (uchar*) partition_handler_share); +#else + my_hash_delete(&partition_share->pt_handler_hash, + (uchar*) partition_handler_share); +#endif + pthread_mutex_unlock(&partition_share->pt_handler_mutex); + pt_handler_mutex = FALSE; + } +error_hash_insert: + partition_handler_share = NULL; + pt_handler_share_creator = NULL; +#endif + if (searched_bitmap) + { + spider_free(spider_current_trx, searched_bitmap, MYF(0)); + searched_bitmap = NULL; + } +error_searched_bitmap_alloc: + if (pt_handler_mutex) + pthread_mutex_unlock(&partition_share->pt_handler_mutex); + spider_free_share(share); + share = NULL; +error_get_share: + if (conn_keys) + { + spider_free(spider_current_trx, conn_keys, MYF(0)); + conn_keys = NULL; + } + DBUG_RETURN(error_num); +} + +int ha_spider::close() +{ + int error_num = 0, roop_count, error_num2; + THD *thd = ha_thd(); +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_SHARE *partition_share; +#endif + backup_error_status(); + DBUG_ENTER("ha_spider::close"); + DBUG_PRINT("info",("spider this=%p", this)); + +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_keys) + { + DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); + spider_free(spider_current_trx, multi_range_keys, MYF(0)); + multi_range_keys = NULL; + } +#endif +#ifdef HA_CAN_BULK_ACCESS + if (bulk_access_link_first) + { + do { + DBUG_PRINT("info",("spider bulk_access_link->spider=%p", + bulk_access_link_first->spider)); + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + bulk_access_link_first->spider->dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &bulk_access_link_first->spider->dbton_handler)); + bulk_access_link_current = bulk_access_link_first->next; + delete_bulk_access_link(bulk_access_link_first); + bulk_access_link_first = bulk_access_link_current; + } while (bulk_access_link_first); + } +#endif + if (is_clone) + { + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if ((error_num2 = close_opened_handler(roop_count, FALSE))) + { + if (check_error_mode(error_num2)) + error_num = error_num2; + } + } + } + for (roop_count = share->use_dbton_count - 1; roop_count >= 0; roop_count--) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if (dbton_handler[dbton_id]) + { + delete dbton_handler[dbton_id]; + dbton_handler[dbton_id] = NULL; + } + } + + if (!thd || !*thd_ha_data(thd, spider_hton_ptr)) + { + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + conns[roop_count] = NULL; + } + + if (ft_first) + { + st_spider_ft_info *tmp_ft_info; + do { + tmp_ft_info = ft_first->next; + spider_free(spider_current_trx, ft_first, MYF(0)); + ft_first = tmp_ft_info; + } while (ft_first); + } + + spider_db_free_result(this, TRUE); + if (conn_keys) + { + spider_free(spider_current_trx, conn_keys, MYF(0)); + conn_keys = NULL; + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + partition_handler_share && + pt_handler_share_creator == this + ) { + partition_share = share->partition_share; + pthread_mutex_lock(&partition_share->pt_handler_mutex); +/* + if (partition_share->partition_handler_share == partition_handler_share) + partition_share->partition_handler_share = NULL; +*/ +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&partition_share->pt_handler_hash, + partition_handler_share->table_hash_value, + (uchar*) partition_handler_share); +#else + my_hash_delete(&partition_share->pt_handler_hash, + (uchar*) partition_handler_share); +#endif + pthread_mutex_unlock(&partition_share->pt_handler_mutex); + } + partition_handler_share = NULL; + pt_handler_share_creator = NULL; +#endif + if (searched_bitmap) + { + spider_free(spider_current_trx, searched_bitmap, MYF(0)); + searched_bitmap = NULL; + } + if (blob_buff) + { + delete [] blob_buff; + blob_buff = NULL; + } + if (result_list.sqls) + { + delete [] result_list.sqls; + result_list.sqls = NULL; + } + if (result_list.insert_sqls) + { + delete [] result_list.insert_sqls; + result_list.insert_sqls = NULL; + } + if (result_list.update_sqls) + { + delete [] result_list.update_sqls; + result_list.update_sqls = NULL; + } + if (result_list.tmp_sqls) + { + delete [] result_list.tmp_sqls; + result_list.tmp_sqls = NULL; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (result_list.hs_result_buf) + { + delete result_list.hs_result_buf; + result_list.hs_result_buf = NULL; + } +#endif + + spider_free_share(share); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (hs_pushed_ret_fields) + { + spider_free(spider_current_trx, hs_pushed_ret_fields, MYF(0)); + hs_pushed_ret_fields = NULL; + hs_pushed_ret_fields_size = 0; + } +#endif +#endif +#ifdef HA_CAN_BULK_ACCESS +/* + if (init_ha_mem_root) + { + free_root(&ha_mem_root, MYF(0)); + init_ha_mem_root = FALSE; + } +*/ +#endif + is_clone = FALSE; + pt_clone_source_handler = NULL; + share = NULL; + trx = NULL; + conns = NULL; + + DBUG_RETURN(error_num); +} + +int ha_spider::check_access_kind( + THD *thd, + bool write_request +) { + int error_num, roop_count; + DBUG_ENTER("ha_spider::check_access_kind"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_command = thd_sql_command(thd); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; + maybe_do_hs_direct_update = FALSE; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + memset(do_hs_direct_update, 0, share->link_bitmap_size); +#endif +#endif + conn_kinds = 0; + switch (sql_command) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + case SQLCOM_HS_READ: + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if (!write_request) + { + DBUG_PRINT("info",("spider spider_use_hs_read=%d", + spider_param_use_hs_read(thd, share->use_hs_reads[roop_count]))); + DBUG_PRINT("info",("spider use_hs_reads[%d]=%ld", roop_count, + share->use_hs_reads[roop_count])); + if (spider_param_use_hs_read(thd, share->use_hs_reads[roop_count])) + { + DBUG_PRINT("info",("spider set %d to HS_READ", roop_count)); + conn_kinds |= SPIDER_CONN_KIND_HS_READ; + conn_kind[roop_count] = SPIDER_CONN_KIND_HS_READ; + } else { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + } else if (share->hs_write_to_reads[roop_count]) + { + DBUG_PRINT("info",("spider spider_use_hs_write=%d", + spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))); + DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count, + share->use_hs_writes[roop_count])); + if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])) + { + DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count)); + conn_kinds |= SPIDER_CONN_KIND_HS_READ; + conn_kind[roop_count] = SPIDER_CONN_KIND_HS_READ; + } else { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + } else { + DBUG_PRINT("info",("spider spider_use_hs_write=%d", + spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))); + DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count, + share->use_hs_writes[roop_count])); + if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])) + { + DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count)); + conn_kinds |= SPIDER_CONN_KIND_HS_WRITE; + conn_kind[roop_count] = SPIDER_CONN_KIND_HS_WRITE; + } else { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + } + } + break; + case SQLCOM_HS_UPDATE: + case SQLCOM_HS_DELETE: +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = TRUE; + maybe_do_hs_direct_update = TRUE; +#endif + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])) + { + DBUG_PRINT("info",("spider do_hs_direct_update[%d]=TRUE", + roop_count)); + spider_set_bit(do_hs_direct_update, roop_count); + } else { + maybe_do_hs_direct_update = FALSE; + } +#endif + } + break; + case SQLCOM_HS_INSERT: + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + DBUG_PRINT("info",("spider spider_use_hs_write=%d", + spider_param_use_hs_write(thd, share->use_hs_writes[roop_count]))); + DBUG_PRINT("info",("spider use_hs_write[%d]=%ld", roop_count, + share->use_hs_writes[roop_count])); + if (spider_param_use_hs_write(thd, share->use_hs_writes[roop_count])) + { + DBUG_PRINT("info",("spider set %d to HS_WRITE", roop_count)); + conn_kinds |= SPIDER_CONN_KIND_HS_WRITE; + conn_kind[roop_count] = SPIDER_CONN_KIND_HS_WRITE; + } else { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + } + break; +#endif + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = TRUE; +#endif + default: + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + break; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_strs_pos(SPIDER_SQL_TYPE_UPDATE_HS))) + { + DBUG_RETURN(error_num); + } +#endif + if ((error_num = spider_check_trx_and_get_conn(thd, this, TRUE))) + { + DBUG_RETURN(error_num); + } + DBUG_PRINT("info",("spider sql_command=%u", sql_command)); + DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id)); + if ( +#ifdef HS_HAS_SQLCOM + sql_command == SQLCOM_HS_UPDATE || +#endif + sql_command == SQLCOM_UPDATE || + sql_command == SQLCOM_UPDATE_MULTI + ) + update_request = TRUE; + else + update_request = FALSE; + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::additional_lock( + THD *thd, + enum thr_lock_type lock_type +) { + DBUG_ENTER("ha_spider::additional_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + if (bulk_access_executing) + { + if (is_bulk_access_clone) + { + DBUG_RETURN(check_access_kind(thd, (lock_type >= TL_WRITE_ALLOW_WRITE))); + } else if (bulk_access_link_exec_tgt->called) + { + DBUG_RETURN(bulk_access_link_exec_tgt->spider->check_access_kind( + thd, (lock_type >= TL_WRITE_ALLOW_WRITE))); + } + } + DBUG_RETURN(check_access_kind(thd, (lock_type >= TL_WRITE_ALLOW_WRITE))); +} +#endif + +THR_LOCK_DATA **ha_spider::store_lock( + THD *thd, + THR_LOCK_DATA **to, + enum thr_lock_type lock_type +) { + int error_num, roop_count; + DBUG_ENTER("ha_spider::store_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + if (lock_type == TL_IGNORE) + { + *to++ = &lock; + DBUG_RETURN(to); + } + if ((error_num = check_access_kind(thd, + (lock_type >= TL_WRITE_ALLOW_WRITE)))) + { + store_error_num = error_num; + DBUG_RETURN(to); + } + DBUG_PRINT("info",("spider sql_command=%u", sql_command)); + DBUG_PRINT("info",("spider lock_type=%d", lock_type)); + DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id)); + if (sql_command == SQLCOM_ALTER_TABLE) + { + if (trx->query_id != thd->query_id) + { + spider_free_trx_alter_table(trx); + trx->query_id = thd->query_id; + trx->tmp_flg = FALSE; + } + if (!(SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash, + (uchar*) share->table_name, share->table_name_length)) + { + if (spider_create_trx_alter_table(trx, share, FALSE)) + { + store_error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(to); + } + } + } + + this->lock_type = lock_type; + selupd_lock_mode = spider_param_selupd_lock_mode(thd, + share->selupd_lock_mode); + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE + ) { + SPIDER_SET_CONNS_PARAM(semi_trx_chk, FALSE, conns, share->link_statuses, + conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY); + } + switch (sql_command) + { + case SQLCOM_SELECT: + case SQLCOM_HA_READ: +#ifdef HS_HAS_SQLCOM + case SQLCOM_HS_READ: +#endif + if (lock_type == TL_READ_WITH_SHARED_LOCKS) + lock_mode = 1; + else if (lock_type <= TL_READ_NO_INSERT) + { + lock_mode = 0; + SPIDER_SET_CONNS_PARAM(semi_trx_isolation_chk, TRUE, conns, + share->link_statuses, conn_link_idx, (int) share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + } else + lock_mode = -1; + SPIDER_SET_CONNS_PARAM(semi_trx_chk, TRUE, conns, share->link_statuses, + conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY); + break; + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: +#ifdef HS_HAS_SQLCOM + case SQLCOM_HS_UPDATE: +#endif + case SQLCOM_CREATE_TABLE: + case SQLCOM_INSERT: + case SQLCOM_INSERT_SELECT: + case SQLCOM_DELETE: + case SQLCOM_LOAD: + case SQLCOM_REPLACE: + case SQLCOM_REPLACE_SELECT: + case SQLCOM_DELETE_MULTI: +#ifdef HS_HAS_SQLCOM + case SQLCOM_HS_INSERT: + case SQLCOM_HS_DELETE: +#endif + if (lock_type >= TL_READ && lock_type <= TL_READ_NO_INSERT) + { + lock_mode = selupd_lock_mode; + SPIDER_SET_CONNS_PARAM(semi_trx_isolation_chk, TRUE, conns, + share->link_statuses, conn_link_idx, (int) share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + } else + lock_mode = -1; + SPIDER_SET_CONNS_PARAM(semi_trx_chk, TRUE, conns, share->link_statuses, + conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY); + break; + default: + lock_mode = -1; + } + switch (lock_type) + { + case TL_READ_HIGH_PRIORITY: + high_priority = TRUE; + break; + case TL_WRITE_DELAYED: + insert_delayed = TRUE; + break; + case TL_WRITE_LOW_PRIORITY: + low_priority = TRUE; + break; + default: + break; + } + + if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) + { + if ( + sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_ALTER_TABLE || + sql_command == SQLCOM_SHOW_CREATE + ) { + if ( + lock_type == TL_READ_NO_INSERT && + !thd->in_lock_tables + ) + lock_type = TL_READ; + if ( + lock_type >= TL_WRITE_CONCURRENT_INSERT && lock_type <= TL_WRITE && + !thd->in_lock_tables && !thd_tablespace_op(thd) + ) + lock_type = TL_WRITE_ALLOW_WRITE; + } else if ( + sql_command == SQLCOM_LOCK_TABLES || + (spider_param_lock_exchange(thd) == 1 && share->semi_table_lock)) + { + if ( + ( + this->lock_type == TL_READ || + this->lock_type == TL_READ_NO_INSERT || + this->lock_type == TL_WRITE_LOW_PRIORITY || + this->lock_type == TL_WRITE + ) && + !spider_param_local_lock_table(thd) + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + SPIDER_CONN *conn = conns[roop_count]; + int appended = 0; + if ((error_num = dbton_handler[conn->dbton_id]-> + append_lock_tables_list(conn, roop_count, &appended))) + { + store_error_num = error_num; + DBUG_RETURN(to); + } + if (appended) + { + conn->table_lock = 2; + } + } + } + } else { + if ( + this->lock_type == TL_READ || + this->lock_type == TL_READ_NO_INSERT || + this->lock_type == TL_WRITE_LOW_PRIORITY || + this->lock_type == TL_WRITE + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ( + conns[roop_count] && + conns[roop_count]->table_lock != 1 && + spider_param_semi_table_lock(thd, share->semi_table_lock) && + !spider_param_local_lock_table(thd) + ) { + SPIDER_CONN *conn = conns[roop_count]; + int appended = 0; + if ((error_num = dbton_handler[conn->dbton_id]-> + append_lock_tables_list(conn, roop_count, &appended))) + { + store_error_num = error_num; + DBUG_RETURN(to); + } + if (appended) + { + conn->table_lock = 3; + } + } + } + } + if ( + lock_type == TL_READ_NO_INSERT && + !thd->in_lock_tables + ) + lock_type = TL_READ; + if ( + lock_type >= TL_WRITE_CONCURRENT_INSERT && lock_type <= TL_WRITE && + !thd->in_lock_tables && !thd_tablespace_op(thd) + ) + lock_type = TL_WRITE_ALLOW_WRITE; + } + lock.type = lock_type; + } + *to++ = &lock; + DBUG_RETURN(to); +} + +int ha_spider::external_lock( + THD *thd, + int lock_type +) { + int error_num, roop_count; + bool sync_trx_isolation = spider_param_sync_trx_isolation(thd); + backup_error_status(); + DBUG_ENTER("ha_spider::external_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider lock_type=%x", lock_type)); +#if MYSQL_VERSION_ID < 50500 + DBUG_PRINT("info",("spider thd->options=%x", (int) thd->options)); +#endif +#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC + info_auto_called = FALSE; +#endif + + sql_command = thd_sql_command(thd); + if (sql_command == SQLCOM_BEGIN) + sql_command = SQLCOM_UNLOCK_TABLES; + if ( + sql_command == SQLCOM_UNLOCK_TABLES && + (error_num = spider_check_trx_and_get_conn(thd, this, + FALSE)) + ) { + DBUG_RETURN(error_num); + } + + DBUG_PRINT("info",("spider sql_command=%d", sql_command)); + DBUG_ASSERT(trx == spider_get_trx(thd, TRUE, &error_num)); +#ifdef HA_CAN_BULK_ACCESS + external_lock_cnt++; +#endif + if (store_error_num) + DBUG_RETURN(store_error_num); + if ( + lock_type == F_UNLCK && + sql_command != SQLCOM_UNLOCK_TABLES + ) + DBUG_RETURN(0); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((conn_kinds & SPIDER_CONN_KIND_MYSQL)) + { +#endif + if ( + /* SQLCOM_RENAME_TABLE and SQLCOM_DROP_DB don't come here */ + sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_ALTER_TABLE + ) { + if (trx->locked_connections) + { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM); + } + DBUG_RETURN(0); + } + if (!conns[search_link_idx]) + { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if (sql_command == SQLCOM_TRUNCATE) + DBUG_RETURN(0); + else if (sql_command != SQLCOM_UNLOCK_TABLES) + { + if ( + (!conns[roop_count]->join_trx && + (error_num = spider_internal_start_trx(this, conns[roop_count], + roop_count))) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + result_list.lock_type = lock_type; + reset_first_link_idx(); + if ( + conns[roop_count]->semi_trx_isolation == -2 && + conns[roop_count]->semi_trx_isolation_chk == TRUE && + sync_trx_isolation && + spider_param_semi_trx_isolation(trx->thd) >= 0 + ) { +/* + if (conns[roop_count]->trx_isolation != + spider_param_semi_trx_isolation(trx->thd)) + { +*/ + spider_conn_queue_semi_trx_isolation(conns[roop_count], + spider_param_semi_trx_isolation(trx->thd)); +/* + } + conns[roop_count]->semi_trx_isolation = + spider_param_semi_trx_isolation(trx->thd); + conns[roop_count]->trx_isolation = + thd_tx_isolation(conns[roop_count]->thd); + DBUG_PRINT("info",("spider conn=%p", conns[roop_count])); + DBUG_PRINT("info",("spider conn->trx_isolation=%d", + conns[roop_count]->trx_isolation)); +*/ + } else { + if (sync_trx_isolation) + { + if ((error_num = spider_check_and_set_trx_isolation( + conns[roop_count], &need_mons[roop_count]))) + { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + } + conns[roop_count]->semi_trx_isolation = -1; + } + } + if (conns[roop_count]->table_lock >= 2) + { + if ( + conns[roop_count]->db_conn->have_lock_table_list() && + (error_num = spider_db_lock_tables(this, roop_count)) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + conns[roop_count]->table_lock = 0; + DBUG_RETURN(check_error_mode(error_num)); + } + if (conns[roop_count]->table_lock == 2) + conns[roop_count]->table_lock = 1; + } else if (sql_command == SQLCOM_UNLOCK_TABLES || + spider_param_internal_unlock(thd) == 1) + { + if (conns[roop_count]->table_lock == 1) + { + conns[roop_count]->table_lock = 0; + if (!conns[roop_count]->trx_start) + conns[roop_count]->disable_reconnect = FALSE; + if ((error_num = spider_db_unlock_tables(this, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + } + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + result_list.lock_type = lock_type; + reset_first_link_idx(); + trans_register_ha(trx->thd, FALSE, spider_hton_ptr); + if (thd_test_options(trx->thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + trans_register_ha(trx->thd, TRUE, spider_hton_ptr); + } + if ((conn_kinds & SPIDER_CONN_KIND_HS_READ)) + { + SPIDER_CONN *hs_conn; + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + hs_conn = hs_r_conns[roop_count]; + if ( + hs_conn && + hs_conn->hsc_query_id != thd->query_id && + hs_conn->hs_pre_age == hs_conn->hs_age + ) { + double interval = spider_param_hs_ping_interval(thd); + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, hs_conn->ping_time))); + DBUG_PRINT("info", ("spider interval=%f", interval)); + if ( + hs_conn->server_lost || + difftime(tmp_time, hs_conn->ping_time) >= interval + ) { + DBUG_PRINT("info", ("spider hsr[%d] need reconnect", roop_count)); + hs_conn->hs_pre_age++; + hs_conn->ping_time = tmp_time; + } + hs_conn->hsc_query_id = thd->query_id; + } + } + } + if ( +#if defined(HS_HAS_SQLCOM) && defined(HANDLER_HAS_DIRECT_UPDATE_ROWS) + ( +#endif + conn_kinds & SPIDER_CONN_KIND_HS_WRITE +#if defined(HS_HAS_SQLCOM) && defined(HANDLER_HAS_DIRECT_UPDATE_ROWS) + ) || + ( + do_direct_update && + ( + sql_command == SQLCOM_HS_UPDATE || + sql_command == SQLCOM_HS_DELETE + ) + ) +#endif + ) { + SPIDER_CONN *hs_conn; + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + hs_conn = hs_w_conns[roop_count]; + if ( + hs_conn && + hs_conn->hsc_query_id != thd->query_id && + hs_conn->hs_pre_age == hs_conn->hs_age + ) { + double interval = spider_param_hs_ping_interval(thd); + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, hs_conn->ping_time))); + DBUG_PRINT("info", ("spider interval=%f", interval)); + if ( + hs_conn->server_lost || + difftime(tmp_time, hs_conn->ping_time) >= interval + ) { + DBUG_PRINT("info", ("spider hsw[%d] need reconnect", roop_count)); + hs_conn->hs_pre_age++; + hs_conn->ping_time = tmp_time; + } + hs_conn->hsc_query_id = thd->query_id; + } + } + } +#endif + DBUG_RETURN(0); +} + +int ha_spider::reset() +{ + int error_num = 0, error_num2, roop_count; + THD *thd = ha_thd(); + SPIDER_TRX *tmp_trx, *trx_bak; + SPIDER_CONDITION *tmp_cond; +/* + char first_byte, first_byte_bak; +*/ + backup_error_status(); + DBUG_ENTER("ha_spider::reset"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + SPIDER_BULK_ACCESS_LINK *tmp_bulk_access_link = bulk_access_link_first; + while (tmp_bulk_access_link) + { + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + tmp_bulk_access_link->spider->dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &tmp_bulk_access_link->spider->dbton_handler)); + if (!tmp_bulk_access_link->used) + break; + if ((error_num2 = tmp_bulk_access_link->spider->ha_reset())) + error_num = error_num2; + tmp_bulk_access_link->used = FALSE; + tmp_bulk_access_link = tmp_bulk_access_link->next; + } + synced_from_clone_source = FALSE; + bulk_access_started = FALSE; + bulk_access_executing = FALSE; + bulk_access_pre_called = FALSE; + if ( + bulk_access_link_first && + !spider_param_bulk_access_free(share->bulk_access_free) + ) { + do { + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + bulk_access_link_first->spider->dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &bulk_access_link_first->spider->dbton_handler)); + bulk_access_link_current = bulk_access_link_first->next; + delete_bulk_access_link(bulk_access_link_first); + bulk_access_link_first = bulk_access_link_current; + } while (bulk_access_link_first); + } +#endif + store_error_num = 0; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + partition_handler_share && + partition_handler_share->searched_bitmap + ) { + if (!is_clone) + partition_handler_share->searched_bitmap = NULL; + partition_handler_share->between_flg = FALSE; + partition_handler_share->idx_bitmap_is_set = FALSE; + partition_handler_share->rnd_bitmap_is_set = FALSE; + } +#endif + if (!(tmp_trx = spider_get_trx(thd, TRUE, &error_num2))) + { + DBUG_PRINT("info",("spider get trx error")); + if (check_error_mode(error_num2)) + error_num = error_num2; + } + if (share) + { + trx_bak = trx; + trx = tmp_trx; + if ((error_num2 = spider_db_free_result(this, FALSE))) + error_num = error_num2; + trx = trx_bak; +/* + int semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, + share->semi_table_lock_conn); + if (semi_table_lock_conn) + first_byte = '0' + + spider_param_semi_table_lock(thd, share->semi_table_lock); + else + first_byte = '0'; + DBUG_PRINT("info",("spider semi_table_lock_conn = %d", + semi_table_lock_conn)); + DBUG_PRINT("info",("spider semi_table_lock = %d", + spider_param_semi_table_lock(thd, share->semi_table_lock))); + DBUG_PRINT("info",("spider first_byte = %d", first_byte)); + if (tmp_trx->spider_thread_id != spider_thread_id || + (tmp_trx->trx_conn_adjustment != trx_conn_adjustment && + tmp_trx->trx_conn_adjustment - 1 != trx_conn_adjustment) || + first_byte != *conn_keys[0] + ) { + DBUG_PRINT("info",(first_byte != *conn_keys[0] ? + "spider change conn type" : tmp_trx != trx ? "spider change thd" : + "spider next trx")); + trx = tmp_trx; + spider_thread_id = tmp_trx->spider_thread_id; + trx_conn_adjustment = tmp_trx->trx_conn_adjustment; + + first_byte_bak = *conn_keys[0]; + *conn_keys[0] = first_byte; + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + *conn_keys[roop_count] = first_byte; + if ( + !(conns[roop_count] = + spider_get_conn(share, roop_count, conn_keys[roop_count], trx, + this, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, &error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + *conn_keys[0] = first_byte_bak; + conns[0] = NULL; + DBUG_RETURN(error_num); + } + } + } +*/ + memset(need_mons, 0, sizeof(int) * share->link_count); + rm_bulk_tmp_table(); + for (roop_count = share->link_count - 1; roop_count >= 0; roop_count--) + { + result_list.update_sqls[roop_count].length(0); + + if ((error_num2 = close_opened_handler(roop_count, TRUE))) + { + if (check_error_mode(error_num2)) + error_num = error_num2; + } + + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + result_list.bulk_update_mode = 0; + result_list.bulk_update_size = 0; + result_list.bulk_update_start = SPD_BU_NOT_START; + for (roop_count = 0; roop_count < (int) share->use_dbton_count; + roop_count++) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if ((error_num2 = dbton_handler[dbton_id]->reset())) + { + if (check_error_mode(error_num2)) + error_num = error_num2; + } + } + } + quick_mode = FALSE; + keyread = FALSE; + ignore_dup_key = FALSE; + write_can_replace = FALSE; + insert_with_update = FALSE; + low_priority = FALSE; + high_priority = FALSE; + insert_delayed = FALSE; + use_pre_call = FALSE; + bulk_insert = FALSE; + clone_bitmap_init = FALSE; + result_list.tmp_table_join = FALSE; + result_list.use_union = FALSE; + pt_clone_last_searcher = NULL; + conn_kinds = SPIDER_CONN_KIND_MYSQL; + while (condition) + { + tmp_cond = condition->next; + spider_free(spider_current_trx, condition, MYF(0)); + condition = tmp_cond; + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_keys) + { + DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); + spider_free(spider_current_trx, multi_range_keys, MYF(0)); + multi_range_keys = NULL; + } +#endif + ft_handler = NULL; + ft_current = NULL; + ft_count = 0; + ft_init_without_index_init = FALSE; + sql_kinds = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + hs_pushed_ret_fields_num = MAX_FIELDS; + hs_increment = FALSE; + hs_decrement = FALSE; +#endif +#endif +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + direct_update_fields = NULL; +#endif +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + info_limit = 9223372036854775807LL; +#endif + result_list.have_sql_kind_backup = FALSE; + result_list.direct_order_limit = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num2 = reset_hs_strs(SPIDER_SQL_TYPE_UPDATE_HS))) + error_num = error_num2; +#endif + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + use_spatial_index = FALSE; + error_mode = 0; +#ifdef HA_CAN_BULK_ACCESS +#ifndef DBUG_OFF + if (bulk_access_link_first) + { + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + bulk_access_link_first->spider->dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &bulk_access_link_first->spider->dbton_handler)); + } +#endif +#endif + DBUG_RETURN(error_num); +} + +int ha_spider::extra( + enum ha_extra_function operation +) { + int error_num; + DBUG_ENTER("ha_spider::extra"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider operation=%d", (int) operation)); + switch (operation) + { + case HA_EXTRA_QUICK: + quick_mode = TRUE; + break; + case HA_EXTRA_KEYREAD: + if (!is_clone) + { + keyread = TRUE; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (update_request) + { + if (check_partitioned()) + keyread = FALSE; + } +#endif + } + break; + case HA_EXTRA_NO_KEYREAD: + keyread = FALSE; + break; + case HA_EXTRA_IGNORE_DUP_KEY: + ignore_dup_key = TRUE; + break; + case HA_EXTRA_NO_IGNORE_DUP_KEY: + ignore_dup_key = FALSE; + break; + case HA_EXTRA_WRITE_CAN_REPLACE: + write_can_replace = TRUE; + break; + case HA_EXTRA_WRITE_CANNOT_REPLACE: + write_can_replace = FALSE; + break; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + case HA_EXTRA_INSERT_WITH_UPDATE: + insert_with_update = TRUE; + check_insert_dup_update_pushdown(); + break; +#endif + case HA_EXTRA_ATTACH_CHILDREN: + DBUG_PRINT("info",("spider HA_EXTRA_ATTACH_CHILDREN")); + if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) + DBUG_RETURN(error_num); + break; +#if MYSQL_VERSION_ID < 50500 +#else + case HA_EXTRA_ADD_CHILDREN_LIST: + DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST")); + if (!(trx = spider_get_trx(ha_thd(), TRUE, &error_num))) + DBUG_RETURN(error_num); + break; +#endif + default: + break; + } + DBUG_RETURN(0); +} + +int ha_spider::index_init( + uint idx, + bool sorted +) { + int error_num; + DBUG_ENTER("ha_spider::index_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider idx=%u", idx)); +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_index_init( + idx, sorted)); + } + } +#endif + pushed_pos = NULL; + active_index = idx; + result_list.sorted = sorted; + spider_set_result_list_param(this); + mrr_with_cnt = FALSE; + init_index_handler = FALSE; + use_spatial_index = FALSE; + + if (result_list.lock_type == F_WRLCK) + { + pk_update = FALSE; + check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT); + + if ( + update_request && + share->have_recovery_link && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set)); + } + } + + if (!is_clone) + set_select_column_mode(); + + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_sql(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif + result_list.check_direct_order_limit = FALSE; + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_index_init( + uint idx, + bool sorted +) { + DBUG_ENTER("ha_spider::pre_index_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_index_init(idx, sorted)); +} +#endif + +int ha_spider::index_end() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::index_end"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + error_num = bulk_access_link_exec_tgt->spider->ha_index_end(); + if (error_num) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); + } + } +#endif + active_index = MAX_KEY; +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + info_limit = 9223372036854775807LL; +#endif + if ( + (error_num = drop_tmp_tables()) || + (error_num = check_and_end_bulk_update( + SPD_BU_START_BY_INDEX_OR_RND_INIT)) || + (error_num = spider_trx_check_link_idx_failed(this)) + ) + DBUG_RETURN(check_error_mode(error_num)); + result_list.use_union = FALSE; + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_index_end() +{ + DBUG_ENTER("ha_spider::pre_index_end"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_index_end()); +} +#endif + +int ha_spider::index_read_map_internal( + uchar *buf, + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag +) { + int error_num, roop_count; + key_range start_key; + SPIDER_CONN *conn; + backup_error_status(); + DBUG_ENTER("ha_spider::index_read_map_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (do_direct_update) + { + direct_update_kinds = SPIDER_SQL_KIND_SQL; + memset(do_hs_direct_update, 0, share->link_bitmap_size); + } +#endif +#endif + if ( + find_flag >= HA_READ_MBR_CONTAIN && + find_flag <= HA_READ_MBR_EQUAL + ) + use_spatial_index = TRUE; + + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + spider_db_free_one_result_for_start_next(this); + spider_set_result_list_param(this); + check_direct_order_limit(); + start_key.key = key; + start_key.keypart_map = keypart_map; + start_key.flag = find_flag; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = FALSE; + result_list.sorted = TRUE; + result_list.key_info = &table->key_info[active_index]; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + DBUG_PRINT("info",("spider result_list.internal_limit=%lld", + result_list.internal_limit)); + DBUG_PRINT("info",("spider result_list.split_read=%lld", + result_list.split_read)); + DBUG_PRINT("info",("spider result_list.limit_num=%lld", + result_list.limit_num)); + if ( + (error_num = spider_db_append_key_where( + &start_key, NULL, this)) + ) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider result_list.internal_limit=%lld", + result_list.internal_limit)); + DBUG_PRINT("info",("spider result_list.split_read=%lld", + result_list.split_read)); + DBUG_PRINT("info",("spider result_list.limit_num=%lld", + result_list.limit_num)); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + if ((error_num = append_limit_hs_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_HS))) + { + DBUG_RETURN(error_num); + } + } +#endif + + int roop_start, roop_end, lock_mode, link_ok; + lock_mode = spider_conn_lock_mode(this); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if ( + is_bulk_access_clone && + !bulk_access_executing && + conn_kind[roop_count] != SPIDER_CONN_KIND_MYSQL + ) { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (buf && (error_num = spider_db_fetch(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::pre_index_read_map( + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag, + bool use_parallel +) { +#ifdef HA_CAN_BULK_ACCESS + int error_num; +#endif + DBUG_ENTER("ha_spider::pre_index_read_map"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + if (bulk_access_started) + { + error_num = bulk_access_link_current->spider->pre_index_read_map(key, + keypart_map, find_flag, TRUE); + bulk_access_link_current->spider->bulk_access_pre_called = TRUE; + bulk_access_link_current->called = TRUE; + DBUG_RETURN(error_num); + } else if ( + bulk_access_executing && !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + DBUG_RETURN(bulk_access_link_exec_tgt->spider->pre_index_read_map(key, + keypart_map, find_flag, TRUE)); + } +#endif + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + index_read_map_internal(NULL, key, keypart_map, find_flag); +#ifdef HA_CAN_BULK_ACCESS + if ( + !store_error_num && + bulk_access_executing && + is_bulk_access_clone && + !bulk_access_pre_called + ) { + bulk_req_exec(); + } +#endif + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::index_read_map( + uchar *buf, + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag +) { + int error_num; + DBUG_ENTER("ha_spider::index_read_map"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if (is_bulk_access_clone) + { + if (bulk_access_pre_called) + { + SPIDER_CONN *conn; + int roop_count, roop_start, roop_end, tmp_lock_mode, link_ok, + tmp_error_num; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + } +#endif + if ((tmp_error_num = spider_db_bulk_store_result(this, conn, + roop_count, (roop_count != link_ok)))) + { + store_error_num = tmp_error_num; + } else { + result_link_idx = link_ok; + } + } + use_pre_call = TRUE; + bulk_access_pre_called = FALSE; + } else { + /* do access normally */ + } + } else if (bulk_access_link_exec_tgt->called) + { + DBUG_RETURN(bulk_access_link_exec_tgt->spider->index_read_map(buf, key, + keypart_map, find_flag)); + } + } +#endif + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + if ( + result_list.sorted && + result_list.desc_flg + ) { + DBUG_RETURN(index_prev(buf)); + } + DBUG_RETURN(index_next(buf)); + } + DBUG_RETURN(index_read_map_internal(buf, key, keypart_map, find_flag)); +} + +int ha_spider::index_read_last_map_internal( + uchar *buf, + const uchar *key, + key_part_map keypart_map +) { + int error_num; + key_range start_key; + SPIDER_CONN *conn; + backup_error_status(); + DBUG_ENTER("ha_spider::index_read_last_map_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } +/* + spider_db_free_one_result_for_start_next(this); +*/ + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ( + result_list.hs_has_result || +#endif + result_list.current +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) +#endif + && + (error_num = spider_db_free_result(this, FALSE)) + ) + DBUG_RETURN(error_num); + + check_direct_order_limit(); + start_key.key = key; + start_key.keypart_map = keypart_map; + start_key.flag = HA_READ_KEY_EXACT; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = TRUE; + result_list.sorted = TRUE; + result_list.key_info = &table->key_info[active_index]; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if ( + (error_num = spider_db_append_key_where( + &start_key, NULL, this)) + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (buf && (error_num = spider_db_fetch(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::pre_index_read_last_map( + const uchar *key, + key_part_map keypart_map, + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_index_read_last_map"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + index_read_last_map_internal(NULL, key, keypart_map); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::index_read_last_map( + uchar *buf, + const uchar *key, + key_part_map keypart_map +) { + int error_num; + DBUG_ENTER("ha_spider::index_read_last_map"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + DBUG_RETURN(index_prev(buf)); + } + DBUG_RETURN(index_read_last_map_internal(buf, key, keypart_map)); +} + +int ha_spider::index_next( + uchar *buf +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::index_next"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + error_num = bulk_access_link_exec_tgt->spider->index_next(buf); + if (error_num) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); + } + } +#endif + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_prev(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::index_prev( + uchar *buf +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::index_prev"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + error_num = bulk_access_link_exec_tgt->spider->index_prev(buf); + if (error_num) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); + } + } +#endif + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_prev(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::index_first_internal( + uchar *buf +) { + int error_num; + SPIDER_CONN *conn; + backup_error_status(); + DBUG_ENTER("ha_spider::index_first_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_has_result || +#endif + sql_is_empty(SPIDER_SQL_TYPE_HANDLER) || + sql_is_empty(SPIDER_SQL_TYPE_SELECT_SQL) + ) { +/* + spider_db_free_one_result_for_start_next(this); +*/ + if ((error_num = spider_db_free_result(this, FALSE))) + DBUG_RETURN(error_num); + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + + check_direct_order_limit(); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = FALSE; + result_list.sorted = TRUE; + result_list.key_info = &table->key_info[active_index]; + result_list.key_order = 0; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if ( + (error_num = spider_db_append_key_where( + NULL, NULL, this)) + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + } + + if (buf) + { + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_last(buf, this, search_link_idx, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_first(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + } + DBUG_RETURN(0); +} + +int ha_spider::pre_index_first( + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_index_first"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + index_first_internal(NULL); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::index_first( + uchar *buf +) { + int error_num; + DBUG_ENTER("ha_spider::index_first"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + DBUG_RETURN(index_next(buf)); + } + DBUG_RETURN(index_first_internal(buf)); +} + +int ha_spider::index_last_internal( + uchar *buf +) { + int error_num; + SPIDER_CONN *conn; + backup_error_status(); + DBUG_ENTER("ha_spider::index_last_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + result_list.hs_has_result || +#endif + sql_is_empty(SPIDER_SQL_TYPE_HANDLER) || + sql_is_empty(SPIDER_SQL_TYPE_SELECT_SQL) + ) { +/* + spider_db_free_one_result_for_start_next(this); +*/ + if ((error_num = spider_db_free_result(this, FALSE))) + DBUG_RETURN(error_num); + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + + check_direct_order_limit(); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = TRUE; + result_list.sorted = TRUE; + result_list.key_info = &table->key_info[active_index]; + result_list.key_order = 0; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if ( + (error_num = spider_db_append_key_where( + NULL, NULL, this)) + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + } + + if (buf) + { + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_first(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_last(buf, this, search_link_idx, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + } + DBUG_RETURN(0); +} + +int ha_spider::pre_index_last( + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_index_last"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + index_last_internal(NULL); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::index_last( + uchar *buf +) { + int error_num; + DBUG_ENTER("ha_spider::index_last"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + DBUG_RETURN(index_prev(buf)); + } + DBUG_RETURN(index_last_internal(buf)); +} + +int ha_spider::index_next_same( + uchar *buf, + const uchar *key, + uint keylen +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::index_next_same"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } +#ifdef HA_CAN_BULK_ACCESS + DBUG_ASSERT(!bulk_access_started); + if (bulk_access_executing) + { + if ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + error_num = bulk_access_link_exec_tgt->spider->index_next_same(buf, key, + keylen); + if (error_num) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); + } + } +#endif + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_prev(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_next(buf, this, search_link_idx, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::read_range_first_internal( + uchar *buf, + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted +) { + int error_num; + SPIDER_CONN *conn; + backup_error_status(); + DBUG_ENTER("ha_spider::read_range_first_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if ( + start_key && + start_key->flag >= HA_READ_MBR_CONTAIN && + start_key->flag <= HA_READ_MBR_EQUAL + ) + use_spatial_index = TRUE; + + if (end_key) + { + key_compare_result_on_equal = + ((end_key->flag == HA_READ_BEFORE_KEY) ? 1 : + (end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0); + } + range_key_part = table->key_info[active_index].key_part; + + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + spider_db_free_one_result_for_start_next(this); + check_direct_order_limit(); + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = FALSE; + result_list.sorted = sorted; + result_list.key_info = &table->key_info[active_index]; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if ( + (error_num = spider_db_append_key_where( + start_key, eq_range ? NULL : end_key, this)) + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (buf && (error_num = spider_db_fetch(buf, this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::pre_read_range_first( + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted, + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_read_range_first"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + read_range_first_internal(NULL, start_key, end_key, eq_range, sorted); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::read_range_first( + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted +) { + int error_num; + DBUG_ENTER("ha_spider::read_range_first"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + DBUG_RETURN(read_range_next()); + } + DBUG_RETURN(read_range_first_internal(table->record[0], start_key, end_key, + eq_range, sorted)); +} + +int ha_spider::read_range_next() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::read_range_next"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( + result_list.sorted && + result_list.desc_flg + ) { + if ((error_num = spider_db_seek_prev(table->record[0], this, table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_next(table->record[0], this, search_link_idx, + table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +ha_rows ha_spider::multi_range_read_info_const( + uint keyno, + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint *bufsz, + uint *flags, + Cost_estimate *cost +) +#else +ha_rows ha_spider::multi_range_read_info_const( + uint keyno, + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint *bufsz, + uint *flags, + COST_VECT *cost +) +#endif +{ + DBUG_ENTER("ha_spider::multi_range_read_info_const"); + DBUG_PRINT("info",("spider this=%p", this)); + ha_rows rows = + handler::multi_range_read_info_const( + keyno, + seq, + seq_init_param, + n_ranges, + bufsz, + flags, + cost + ); + *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + DBUG_PRINT("info",("spider rows=%llu", rows)); + DBUG_RETURN(rows); +} + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +ha_rows ha_spider::multi_range_read_info( + uint keyno, + uint n_ranges, + uint keys, + uint key_parts, + uint *bufsz, + uint *flags, + Cost_estimate *cost +) +#else +ha_rows ha_spider::multi_range_read_info( + uint keyno, + uint n_ranges, + uint keys, + uint key_parts, + uint *bufsz, + uint *flags, + COST_VECT *cost +) +#endif +{ + DBUG_ENTER("ha_spider::multi_range_read_info"); + DBUG_PRINT("info",("spider this=%p", this)); + ha_rows rows = + handler::multi_range_read_info( + keyno, + n_ranges, + keys, + key_parts, + bufsz, + flags, + cost + ); + *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + DBUG_PRINT("info",("spider rows=%llu", rows)); + DBUG_RETURN(rows); +} + +int ha_spider::multi_range_read_init( + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint mode, + HANDLER_BUFFER *buf +) { + bka_mode = spider_param_bka_mode(trx->thd, share->bka_mode); + backup_error_status(); + DBUG_ENTER("ha_spider::multi_range_read_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider n_ranges=%u", n_ranges)); + multi_range_num = n_ranges; + DBUG_RETURN( + handler::multi_range_read_init( + seq, + seq_init_param, + n_ranges, + mode, + buf + ) + ); +} + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +int ha_spider::multi_range_read_next( + range_id_t *range_info +) +#else +int ha_spider::multi_range_read_next( + char **range_info +) +#endif +{ + int error_num; + DBUG_ENTER("ha_spider::multi_range_read_next"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!mrr_have_range) + { + error_num = multi_range_read_next_first(range_info); + mrr_have_range = TRUE; + } else + error_num = multi_range_read_next_next(range_info); + DBUG_RETURN(error_num); +} +#endif + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +int ha_spider::multi_range_read_next_first( + range_id_t *range_info +) +#else +int ha_spider::multi_range_read_next_first( + char **range_info +) +#endif +#else +int ha_spider::read_multi_range_first_internal( + uchar *buf, + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer +) +#endif +{ + int error_num, roop_count; + SPIDER_CONN *conn; +#ifdef HA_MRR_USE_DEFAULT_IMPL + int range_res; + backup_error_status(); + DBUG_ENTER("ha_spider::multi_range_read_next_first"); +#else + bka_mode = spider_param_bka_mode(trx->thd, share->bka_mode); + backup_error_status(); + DBUG_ENTER("ha_spider::read_multi_range_first_internal"); +#endif + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if ((error_num = index_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + multi_range_sorted = sorted; + multi_range_buffer = buffer; +#endif + + spider_db_free_one_result_for_start_next(this); + check_direct_order_limit(); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif + result_list.desc_flg = FALSE; +#ifdef HA_MRR_USE_DEFAULT_IMPL + result_list.sorted = mrr_is_output_sorted; +#else + result_list.sorted = sorted; +#endif + result_list.key_info = &table->key_info[active_index]; + if ( + result_list.multi_split_read <= 1 || + (sql_kinds & SPIDER_SQL_KIND_HANDLER) + ) { + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!(range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range))) +#else + for ( + multi_range_curr = ranges, + multi_range_end = ranges + range_count; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res1=%d", range_res)); +#endif + result_list.limit_num = + result_list.internal_limit - result_list.record_num >= + result_list.split_read ? + result_list.split_read : + result_list.internal_limit - result_list.record_num; + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + test(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) +#else + (error_num = spider_db_append_key_where( + &multi_range_curr->start_key, + test(multi_range_curr->range_flag & EQ_RANGE) ? + NULL : &multi_range_curr->end_key, this)) +#endif + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset + result_list.record_num, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset + result_list.record_num, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)); + if ( + error_num && + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = (char *) mrr_cur_range.ptr; +#else + *found_range_p = multi_range_curr; +#endif + DBUG_RETURN(0); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } + if (!error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } + } + if (!error_num) + { + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + error_num = spider_db_store_result(this, roop_count, table); + if ( + error_num && + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (error_num) + { + if ( + error_num != HA_ERR_END_OF_FILE && + check_error_mode(error_num) + ) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + } else { +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (!(error_num = spider_db_fetch(table->record[0], this, table))) +#else + if (!buf || !(error_num = spider_db_fetch(buf, this, table))) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = (char *) mrr_cur_range.ptr; +#else + *found_range_p = multi_range_curr; +#endif + DBUG_RETURN(0); + } + if ( + error_num != HA_ERR_END_OF_FILE && + check_error_mode(error_num) + ) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + } + set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res2=%d", range_res)); +#endif + if (error_num) + DBUG_RETURN(check_error_mode_eof(error_num)); + } else { + bool tmp_high_priority = high_priority; + bool have_multi_range; +#ifdef HA_MRR_USE_DEFAULT_IMPL + have_second_range = FALSE; +#endif + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + mrr_with_cnt = TRUE; + multi_range_cnt = 0; + multi_range_hit_point = 0; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_keys) + { + DBUG_PRINT("info",("spider free multi_range_keys=%p", multi_range_keys)); + spider_free(spider_current_trx, multi_range_keys, MYF(0)); + } +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + if (!(multi_range_keys = (range_id_t *) + spider_malloc(spider_current_trx, 1, sizeof(range_id_t) * + (multi_range_num < result_list.multi_split_read ? + multi_range_num : result_list.multi_split_read), MYF(MY_WME))) + ) +#else + if (!(multi_range_keys = (char **) + spider_malloc(spider_current_trx, 1, sizeof(char *) * + (multi_range_num < result_list.multi_split_read ? + multi_range_num : result_list.multi_split_read), MYF(MY_WME))) + ) +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys)); +#else + multi_range_ranges = ranges; +#endif + error_num = 0; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if ((range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range))) + { + DBUG_PRINT("info",("spider range_res3=%d", range_res)); + DBUG_PRINT("info",("spider result_list.finish_flg = TRUE")); + result_list.finish_flg = TRUE; + if (result_list.current) + { + DBUG_PRINT("info",("spider result_list.current->finish_flg = TRUE")); + result_list.current->finish_flg = TRUE; + } + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + DBUG_PRINT("info",("spider range_res4=%d", range_res)); +#else + multi_range_curr = ranges; + multi_range_end = ranges + range_count; +#endif + result_list.tmp_table_join = FALSE; + memset(result_list.tmp_table_join_first, 0, share->link_bitmap_size); + do + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + if ((range_res = mrr_funcs.next(mrr_iter, &mrr_second_range))) +#else + if (multi_range_curr + 1 >= multi_range_end) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + have_second_range = FALSE; +#endif + have_multi_range = FALSE; + } else { +#ifdef HA_MRR_USE_DEFAULT_IMPL + have_second_range = TRUE; +#endif + have_multi_range = TRUE; + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res5=%d", range_res)); +#endif + result_list.tmp_reuse_sql = FALSE; + if (bka_mode && + have_multi_range && +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + !(sql_kinds & SPIDER_SQL_KIND_HS) && +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL + test(mrr_cur_range.range_flag & EQ_RANGE) +#else + test(multi_range_curr->range_flag & EQ_RANGE) +#endif + ) { + if ( + result_list.tmp_table_join && +#ifdef HA_MRR_USE_DEFAULT_IMPL + result_list.tmp_table_join_key_part_map == + mrr_cur_range.start_key.keypart_map +#else + result_list.tmp_table_join_key_part_map == + multi_range_curr->start_key.keypart_map +#endif + ) { + /* reuse tmp_sql */ + result_list.tmp_reuse_sql = TRUE; + } else { + /* create tmp_sql */ + result_list.tmp_table_join = TRUE; +#ifdef HA_MRR_USE_DEFAULT_IMPL + result_list.tmp_table_join_key_part_map = + mrr_cur_range.start_key.keypart_map; +#else + result_list.tmp_table_join_key_part_map = + multi_range_curr->start_key.keypart_map; +#endif + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + if ((sql_kinds & SPIDER_SQL_KIND_SQL)) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + result_list.sql_kind_backup[roop_count] = sql_kind[roop_count]; + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + } + result_list.sql_kinds_backup = sql_kinds; + sql_kinds = SPIDER_SQL_KIND_SQL; + result_list.have_sql_kind_backup = TRUE; + } + } + memset(result_list.tmp_table_join_first, 0xFF, + share->link_bitmap_size); + } else { + result_list.tmp_table_join = FALSE; + if (result_list.have_sql_kind_backup) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + sql_kind[roop_count] = + result_list.sql_kind_backup[roop_count]; + } + sql_kinds = result_list.sql_kinds_backup; + result_list.have_sql_kind_backup = FALSE; + } + } + result_list.tmp_table_join_break_after_get_next = FALSE; + + if (result_list.tmp_table_join) + { + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_tmp_table_and_sql_for_bka( +#ifdef HA_MRR_USE_DEFAULT_IMPL + &mrr_cur_range.start_key +#else + &multi_range_curr->start_key +#endif + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_tmp_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + +#ifdef HA_MRR_USE_DEFAULT_IMPL + do +#else + for ( + ; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + !test(mrr_cur_range.range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + mrr_cur_range.start_key.keypart_map +#else + !test(multi_range_curr->range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + multi_range_curr->start_key.keypart_map +#endif + ) { + result_list.tmp_table_join_break_after_get_next = TRUE; + break; + } + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; +#else + multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; +#endif +#endif + if ((error_num = append_multi_range_cnt_sql_part( + SPIDER_SQL_TYPE_TMP_SQL, multi_range_cnt, TRUE))) + DBUG_RETURN(error_num); + if ((error_num = append_key_column_values_sql_part( +#ifdef HA_MRR_USE_DEFAULT_IMPL + &mrr_cur_range.start_key, +#else + &multi_range_curr->start_key, +#endif + SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + + if ((error_num = + append_values_connector_sql_part(SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + multi_range_cnt++; + if (multi_range_cnt >= (uint) result_list.multi_split_read) + break; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_cnt == 1) + { + if (have_multi_range) + { + memcpy(&mrr_cur_range, &mrr_second_range, + sizeof(KEY_MULTI_RANGE)); + have_second_range = FALSE; + range_res = 0; + } else { + range_res = 1; + } + } else { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res6=%d", range_res)); + } +#endif + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!range_res); +#endif + if ((error_num = + append_values_terminator_sql_part(SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + result_list.use_union = FALSE; + + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } else { + result_list.limit_num = result_list.internal_limit; + if ((error_num = append_union_all_start_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + +#ifdef HA_MRR_USE_DEFAULT_IMPL + do +#else + for ( + ; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res7=%d", range_res)); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; +#else + multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; +#endif +#endif + if ((error_num = spider_db_append_select(this))) + DBUG_RETURN(error_num); + if ((error_num = append_multi_range_cnt_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE))) + DBUG_RETURN(error_num); + if ((error_num = spider_db_append_select_columns(this))) + DBUG_RETURN(error_num); + high_priority = FALSE; + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + test(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) +#else + (error_num = spider_db_append_key_where( + &multi_range_curr->start_key, + test(multi_range_curr->range_flag & EQ_RANGE) ? + NULL : &multi_range_curr->end_key, this)) +#endif + ) + DBUG_RETURN(error_num); + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + 0, + result_list.internal_offset + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + if ((error_num = append_union_all_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + multi_range_cnt++; + if (multi_range_cnt >= (uint) result_list.multi_split_read) + break; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_cnt == 1) + { + if (have_multi_range) + { + memcpy(&mrr_cur_range, &mrr_second_range, + sizeof(KEY_MULTI_RANGE)); + have_second_range = FALSE; + range_res = 0; + } else { + range_res = 1; + } + } else { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res8=%d", range_res)); + } +#endif + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!range_res); +#endif + high_priority = tmp_high_priority; + if ((error_num = append_union_all_end_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + result_list.use_union = TRUE; + + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + sql_type &= ~SPIDER_SQL_TYPE_TMP_SQL; + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + if ( + result_list.tmp_table_join && + spider_bit_is_set(result_list.tmp_table_join_first, roop_count) + ) { + spider_clear_bit(result_list.tmp_table_join_first, roop_count); + spider_set_bit(result_list.tmp_table_created, roop_count); + result_list.tmp_tables_created = TRUE; + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_TMP_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + spider_db_discard_multiple_result(this, roop_count, conn); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (error_num) + { + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + if (multi_range_cnt >= (uint) result_list.multi_split_read) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res9=%d", range_res)); +#else + multi_range_curr++; +#endif + } + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + error_num = 0; + } else + DBUG_RETURN(error_num); + } else { +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (!(error_num = spider_db_fetch(table->record[0], this, table))) +#else + if (!buf || !(error_num = spider_db_fetch(buf, this, table))) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + if (multi_range_cnt >= (uint) result_list.multi_split_read) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res10=%d", range_res)); +#else + multi_range_curr++; +#endif + } + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + error_num = 0; + } else + DBUG_RETURN(error_num); + } + multi_range_cnt = 0; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + multi_range_ranges = multi_range_curr; +#endif + } while (!error_num); + } + DBUG_RETURN(0); +} + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else +int ha_spider::pre_read_multi_range_first( + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer, + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_read_multi_range_first"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + read_multi_range_first_internal(NULL, found_range_p, ranges, + range_count, sorted, buffer); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::read_multi_range_first( + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer +) { + int error_num; + DBUG_ENTER("ha_spider::read_multi_range_first"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + DBUG_RETURN(read_multi_range_next(found_range_p)); + } + DBUG_RETURN(read_multi_range_first_internal(table->record[0], found_range_p, + ranges, range_count, sorted, buffer)); +} +#endif + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +int ha_spider::multi_range_read_next_next( + range_id_t *range_info +) +#else +int ha_spider::multi_range_read_next_next( + char **range_info +) +#endif +#else +int ha_spider::read_multi_range_next( + KEY_MULTI_RANGE **found_range_p +) +#endif +{ + int error_num, roop_count; + SPIDER_CONN *conn; +#ifdef HA_MRR_USE_DEFAULT_IMPL + int range_res; + backup_error_status(); + DBUG_ENTER("ha_spider::multi_range_read_next_next"); +#else + backup_error_status(); + DBUG_ENTER("ha_spider::read_multi_range_next"); +#endif + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if ( + result_list.multi_split_read <= 1 || + (sql_kinds & SPIDER_SQL_KIND_HANDLER) + ) { + if (!(error_num = spider_db_seek_next(table->record[0], this, + search_link_idx, table))) + DBUG_RETURN(0); +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res1=%d", range_res)); +#else + multi_range_curr++; +#endif + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if ( + error_num != HA_ERR_END_OF_FILE || +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) + DBUG_RETURN(error_num); + spider_db_free_one_result_for_start_next(this); + spider_first_split_read_param(this); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + if (result_list.current) + { + DBUG_PRINT("info",("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + } + result_list.record_num = 0; +#ifdef HA_MRR_USE_DEFAULT_IMPL + do +#else + for ( + ; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res2=%d", range_res)); +#endif + set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + set_where_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); + result_list.limit_num = + result_list.internal_limit - result_list.record_num >= + result_list.split_read ? + result_list.split_read : + result_list.internal_limit - result_list.record_num; + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + test(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) +#else + (error_num = spider_db_append_key_where( + &multi_range_curr->start_key, + test(multi_range_curr->range_flag & EQ_RANGE) ? + NULL : &multi_range_curr->end_key, this)) +#endif + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset + result_list.record_num, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset + result_list.record_num, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)); + if ( + error_num && + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } + if (!error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + } + } + if (!error_num) + { + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + error_num = spider_db_store_result(this, roop_count, table); + if ( + error_num && + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (error_num) + { + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + result_list.current = result_list.current->prev; + } + } else + DBUG_RETURN(error_num); + } else { + if (!(error_num = spider_db_fetch(table->record[0], this, table))) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = (char *) mrr_cur_range.ptr; +#else + *found_range_p = multi_range_curr; +#endif + DBUG_RETURN(0); + } + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + result_list.current = result_list.current->prev; + } + } else + DBUG_RETURN(error_num); + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res3=%d", range_res)); +#endif + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!range_res); +#endif + if (error_num) + DBUG_RETURN(check_error_mode_eof(error_num)); + } else { + if (!(error_num = spider_db_seek_next(table->record[0], this, + search_link_idx, table))) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } + + if (!result_list.tmp_table_join_break_after_get_next) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res4=%d", range_res)); +#else + if (multi_range_curr < multi_range_end) + multi_range_curr++; +#endif + } else { + result_list.tmp_table_join_break_after_get_next = FALSE; +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = 0; +#endif + } + + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if ( + error_num != HA_ERR_END_OF_FILE || +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) + DBUG_RETURN(error_num); + spider_db_free_one_result_for_start_next(this); + spider_first_split_read_param(this); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + if (result_list.current) + { + DBUG_PRINT("info",("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + } + result_list.record_num = 0; + + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + multi_range_ranges = multi_range_curr; +#endif + + bool tmp_high_priority = high_priority; + bool have_multi_range; + multi_range_cnt = 0; + error_num = 0; + do + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + if ( + !have_second_range && + (range_res = mrr_funcs.next(mrr_iter, &mrr_second_range)) + ) +#else + if (multi_range_curr + 1 >= multi_range_end) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + have_second_range = FALSE; +#endif + have_multi_range = FALSE; + } else { +#ifdef HA_MRR_USE_DEFAULT_IMPL + have_second_range = TRUE; +#endif + have_multi_range = TRUE; + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + DBUG_PRINT("info",("spider range_res5=%d", range_res)); +#endif + result_list.tmp_reuse_sql = FALSE; + if (bka_mode && + have_multi_range && +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + !(sql_kinds & SPIDER_SQL_KIND_HS) && +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL + test(mrr_cur_range.range_flag & EQ_RANGE) +#else + test(multi_range_curr->range_flag & EQ_RANGE) +#endif + ) { + if ( + result_list.tmp_table_join && +#ifdef HA_MRR_USE_DEFAULT_IMPL + result_list.tmp_table_join_key_part_map == + mrr_cur_range.start_key.keypart_map +#else + result_list.tmp_table_join_key_part_map == + multi_range_curr->start_key.keypart_map +#endif + ) { + /* reuse tmp_sql */ + result_list.tmp_reuse_sql = TRUE; + } else { + /* create tmp_sql */ + result_list.tmp_table_join = TRUE; +#ifdef HA_MRR_USE_DEFAULT_IMPL + result_list.tmp_table_join_key_part_map = + mrr_cur_range.start_key.keypart_map; +#else + result_list.tmp_table_join_key_part_map = + multi_range_curr->start_key.keypart_map; +#endif + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + if ((sql_kinds & SPIDER_SQL_KIND_SQL)) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + result_list.sql_kind_backup[roop_count] = sql_kind[roop_count]; + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + } + result_list.sql_kinds_backup = sql_kinds; + sql_kinds = SPIDER_SQL_KIND_SQL; + result_list.have_sql_kind_backup = TRUE; + } + } + memset(result_list.tmp_table_join_first, 0xFF, + share->link_bitmap_size); + } else { + result_list.tmp_table_join = FALSE; + if (result_list.have_sql_kind_backup) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + sql_kind[roop_count] = + result_list.sql_kind_backup[roop_count]; + } + sql_kinds = result_list.sql_kinds_backup; + result_list.have_sql_kind_backup = FALSE; + } + } + + if (result_list.tmp_table_join) + { + result_list.limit_num = + result_list.internal_limit - result_list.record_num >= + result_list.split_read ? + result_list.split_read : + result_list.internal_limit - result_list.record_num; + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_tmp_table_and_sql_for_bka( +#ifdef HA_MRR_USE_DEFAULT_IMPL + &mrr_cur_range.start_key +#else + &multi_range_curr->start_key +#endif + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_tmp_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + +#ifdef HA_MRR_USE_DEFAULT_IMPL + do +#else + for ( + ; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + !test(mrr_cur_range.range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + mrr_cur_range.start_key.keypart_map +#else + !test(multi_range_curr->range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + multi_range_curr->start_key.keypart_map +#endif + ) { + result_list.tmp_table_join_break_after_get_next = TRUE; + break; + } + +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; +#else + multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; +#endif +#endif + if ((error_num = append_multi_range_cnt_sql_part( + SPIDER_SQL_TYPE_TMP_SQL, multi_range_cnt, TRUE))) + DBUG_RETURN(error_num); + if ((error_num = append_key_column_values_sql_part( +#ifdef HA_MRR_USE_DEFAULT_IMPL + &mrr_cur_range.start_key, +#else + &multi_range_curr->start_key, +#endif + SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + + if ((error_num = + append_values_connector_sql_part(SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + multi_range_cnt++; + if (multi_range_cnt >= (uint) result_list.multi_split_read) + break; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_cnt == 1) + { + if (have_multi_range) + { + memcpy(&mrr_cur_range, &mrr_second_range, + sizeof(KEY_MULTI_RANGE)); + have_second_range = FALSE; + range_res = 0; + } else { + range_res = 1; + } + } else { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res6=%d", range_res)); + } +#endif + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!range_res); +#endif + if ((error_num = + append_values_terminator_sql_part(SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + result_list.use_union = FALSE; + + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } else { + result_list.limit_num = + result_list.internal_limit - result_list.record_num; + if ((error_num = + append_union_all_start_sql_part(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); +#ifdef HA_MRR_USE_DEFAULT_IMPL + do +#else + for ( + ; + multi_range_curr < multi_range_end; + multi_range_curr++ + ) +#endif + { +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; +#else + multi_range_keys[multi_range_cnt] = (char *) mrr_cur_range.ptr; +#endif +#endif + if ((error_num = spider_db_append_select(this))) + DBUG_RETURN(error_num); + if ((error_num = append_multi_range_cnt_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt, TRUE))) + DBUG_RETURN(error_num); + if ((error_num = spider_db_append_select_columns(this))) + DBUG_RETURN(error_num); + high_priority = FALSE; + if ( + share->key_hint && + (error_num = append_hint_after_table_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + test(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) +#else + (error_num = spider_db_append_key_where( + &multi_range_curr->start_key, + test(multi_range_curr->range_flag & EQ_RANGE) ? + NULL : &multi_range_curr->end_key, this)) +#endif + ) + DBUG_RETURN(error_num); + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + 0, + result_list.internal_offset + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + if ((error_num = + append_union_all_sql_part(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + multi_range_cnt++; + if (multi_range_cnt >= (uint) result_list.multi_split_read) + break; +#ifdef HA_MRR_USE_DEFAULT_IMPL + if (multi_range_cnt == 1) + { + if (have_multi_range) + { + memcpy(&mrr_cur_range, &mrr_second_range, + sizeof(KEY_MULTI_RANGE)); + have_second_range = FALSE; + range_res = 0; + } else { + range_res = 1; + } + } else { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res7=%d", range_res)); + } +#endif + } +#ifdef HA_MRR_USE_DEFAULT_IMPL + while (!range_res); +#endif + high_priority = tmp_high_priority; + if ((error_num = + append_union_all_end_sql_part(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + result_list.use_union = TRUE; + + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + if ((error_num = append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + } else { +#endif + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = conns[roop_count]; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + conn = hs_r_conns[roop_count]; + else + conn = hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + sql_type &= ~SPIDER_SQL_TYPE_TMP_SQL; + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(trx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } else { +#endif + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + if ( + result_list.tmp_table_join && + spider_bit_is_set(result_list.tmp_table_join_first, roop_count) + ) { + spider_clear_bit(result_list.tmp_table_join_first, roop_count); + spider_set_bit(result_list.tmp_table_created, roop_count); + result_list.tmp_tables_created = TRUE; + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_TMP_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + spider_db_discard_multiple_result(this, roop_count, conn); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + break; + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + if (error_num) + { + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + if (multi_range_cnt >= (uint) result_list.multi_split_read) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res8=%d", range_res)); +#else + multi_range_curr++; +#endif + } + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + error_num = 0; + } else + DBUG_RETURN(error_num); + } else { + if (!(error_num = spider_db_fetch(table->record[0], this, table))) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + *range_info = multi_range_keys[multi_range_hit_point]; +#else + *found_range_p = &multi_range_ranges[multi_range_hit_point]; +#endif + DBUG_RETURN(0); + } + if ( + error_num != HA_ERR_END_OF_FILE && + !check_error_mode(error_num) + ) + error_num = HA_ERR_END_OF_FILE; + if (error_num == HA_ERR_END_OF_FILE) + { + if (multi_range_cnt >= (uint) result_list.multi_split_read) + { +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res9=%d", range_res)); +#else + multi_range_curr++; +#endif + } + if ( +#ifdef HA_MRR_USE_DEFAULT_IMPL + range_res +#else + multi_range_curr == multi_range_end +#endif + ) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (result_list.current) + { + DBUG_PRINT("info", + ("spider result_list.current->finish_flg = FALSE")); + result_list.current->finish_flg = FALSE; + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + error_num = 0; + } else + DBUG_RETURN(error_num); + } + multi_range_cnt = 0; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + (error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)) + ) + DBUG_RETURN(error_num); +#endif +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + multi_range_ranges = multi_range_curr; +#endif + } while (!error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::rnd_init( + bool scan +) { + int error_num; + DBUG_ENTER("ha_spider::rnd_init"); + DBUG_PRINT("info",("spider this=%p", this)); + pushed_pos = NULL; + if (result_list.lock_type == F_WRLCK) + check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT); + + rnd_scan_and_first = scan; + if ( + scan && + sql_command != SQLCOM_ALTER_TABLE + ) { + spider_set_result_list_param(this); + pk_update = FALSE; + if ( + result_list.current && + !result_list.low_mem_read + ) { + result_list.current = result_list.first; + spider_db_set_pos_to_first_row(&result_list); + rnd_scan_and_first = FALSE; + } else { + spider_db_free_one_result_for_start_next(this); + if ( + result_list.current && + result_list.low_mem_read + ) { + int roop_start, roop_end, roop_count, tmp_lock_mode; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (conns[roop_count] && result_list.bgs_working) + spider_bg_conn_break(conns[roop_count], this); +#endif + if (quick_targets[roop_count]) + { + DBUG_ASSERT(quick_targets[roop_count] == + conns[roop_count]->quick_target); + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", + conns[roop_count])); + conns[roop_count]->quick_target = NULL; + quick_targets[roop_count] = NULL; + } + } + result_list.record_num = 0; + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.quick_phase = 0; +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list.bgs_phase = 0; +#endif + } + + mrr_with_cnt = FALSE; + use_spatial_index = FALSE; + + if ( + update_request && + share->have_recovery_link && + result_list.lock_type == F_WRLCK && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set)); + } + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif + set_select_column_mode(); + result_list.keyread = FALSE; + + init_rnd_handler = FALSE; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + (error_num = reset_hs_sql(SPIDER_SQL_TYPE_SELECT_HS)) || + (error_num = reset_hs_keys(SPIDER_SQL_TYPE_SELECT_HS)) + ) + DBUG_RETURN(error_num); +#endif + result_list.check_direct_order_limit = FALSE; + } + } + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_rnd_init( + bool scan +) { + DBUG_ENTER("ha_spider::pre_rnd_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_rnd_init(scan)); +} +#endif + +int ha_spider::rnd_end() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::rnd_end"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + info_limit = 9223372036854775807LL; +#endif + if ( + (error_num = check_and_end_bulk_update( + SPD_BU_START_BY_INDEX_OR_RND_INIT)) || + (error_num = spider_trx_check_link_idx_failed(this)) + ) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_rnd_end() +{ + DBUG_ENTER("ha_spider::pre_rnd_end"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_rnd_end()); +} +#endif + +int ha_spider::rnd_next_internal( + uchar *buf +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::rnd_next_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + /* do not copy table data at alter table */ + if (sql_command == SQLCOM_ALTER_TABLE) + DBUG_RETURN(HA_ERR_END_OF_FILE); + + if (rnd_scan_and_first) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & SPIDER_SQL_KIND_HS) + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +#endif + if ((error_num = rnd_handler_init())) + DBUG_RETURN(check_error_mode_eof(error_num)); + check_direct_order_limit(); +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(TRUE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + + /* append condition pushdown */ + if (spider_db_append_condition(this, NULL, 0, FALSE)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + set_order_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + if ( + result_list.direct_order_limit && + (error_num = append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + result_list.desc_flg = FALSE; + result_list.sorted = FALSE; + result_list.key_info = NULL; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + SPIDER_CONN *conn = conns[roop_count]; + ulong sql_type; + if (sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, + roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + rnd_scan_and_first = FALSE; + } + if (buf && (error_num = spider_db_seek_next(buf, this, search_link_idx, + table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::pre_rnd_next( + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + rnd_next_internal(NULL); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::rnd_next( + uchar *buf +) { + int error_num; + DBUG_ENTER("ha_spider::rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + } + DBUG_RETURN(rnd_next_internal(buf)); +} + +void ha_spider::position( + const uchar *record +) { + DBUG_ENTER("ha_spider::position"); + DBUG_PRINT("info",("spider this=%p", this)); + if (pushed_pos) + { + DBUG_PRINT("info",("spider pushed_pos=%p", pushed_pos)); + memcpy(ref, pushed_pos, ref_length); + DBUG_VOID_RETURN; + } + if (pt_clone_last_searcher) + { + /* sercher is cloned handler */ + DBUG_PRINT("info",("spider cloned handler access")); + pt_clone_last_searcher->position(record); + memcpy(ref, pt_clone_last_searcher->ref, ref_length); + } else { + memset(ref, '0', sizeof(SPIDER_POSITION)); + DBUG_PRINT("info",("spider self position")); + DBUG_PRINT("info", + ("spider current_row_num=%lld", result_list.current_row_num)); + if (!position_bitmap_init) + { + if (select_column_mode) + { + int roop_count; + for (roop_count = 0; + roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + { + position_bitmap[roop_count] = + searched_bitmap[roop_count] | + ((uchar *) table->read_set->bitmap)[roop_count] | + ((uchar *) table->write_set->bitmap)[roop_count]; + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + DBUG_PRINT("info",("spider position_bitmap=%d", + position_bitmap[roop_count])); + DBUG_PRINT("info",("spider searched_bitmap=%d", + searched_bitmap[roop_count])); + DBUG_PRINT("info",("spider read_set=%d", + ((uchar *) table->read_set->bitmap)[roop_count])); + DBUG_PRINT("info",("spider write_set=%d", + ((uchar *) table->write_set->bitmap)[roop_count])); + } + } + position_bitmap_init = TRUE; + } + spider_db_create_position(this, (SPIDER_POSITION *) ref); + } + DBUG_VOID_RETURN; +} + +int ha_spider::rnd_pos( + uchar *buf, + uchar *pos +) { + DBUG_ENTER("ha_spider::rnd_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + DBUG_PRINT("info",("spider pos=%p", pos)); + DBUG_PRINT("info",("spider buf=%p", buf)); + pushed_pos_buf = *((SPIDER_POSITION *) pos); + pushed_pos = &pushed_pos_buf; + DBUG_RETURN(spider_db_seek_tmp(buf, &pushed_pos_buf, this, table)); +} + +int ha_spider::cmp_ref( + const uchar *ref1, + const uchar *ref2 +) { + int ret = 0; + DBUG_ENTER("ha_spider::cmp_ref"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider ref1=%p", ref1)); + DBUG_PRINT("info",("spider ref2=%p", ref2)); + if (table_share->primary_key < MAX_KEY) + { + uchar table_key[MAX_KEY_LENGTH]; + KEY *key_info = &table->key_info[table_share->primary_key]; + DBUG_PRINT("info",("spider cmp by primary key")); + rnd_pos(table->record[0], (uchar *) ref2); + key_copy( + table_key, + table->record[0], + key_info, + key_info->key_length); + rnd_pos(table->record[0], (uchar *) ref1); + ret = key_cmp(key_info->key_part, table_key, key_info->key_length); + } else { + Field **field; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(table->record[1], table->record[0]); + DBUG_PRINT("info",("spider cmp by all rows")); + rnd_pos(table->record[1], (uchar *) ref2); + rnd_pos(table->record[0], (uchar *) ref1); + for ( + field = table->field; + *field; + field++ + ) { + if ((ret = (*field)->cmp_binary_offset(ptr_diff))) + { + DBUG_PRINT("info",("spider different at %s", (*field)->field_name)); + break; + } + } + } + DBUG_PRINT("info",("spider ret=%d", ret)); + DBUG_RETURN(ret); +} + +float spider_ft_find_relevance( + FT_INFO *handler, + uchar *record, + uint length +) { + DBUG_ENTER("spider_ft_find_relevance"); + st_spider_ft_info *info = (st_spider_ft_info*) handler; + DBUG_PRINT("info",("spider info=%p", info)); + DBUG_PRINT("info",("spider score=%f", info->score)); + DBUG_RETURN(info->score); +} + +float spider_ft_get_relevance( + FT_INFO *handler +) { + DBUG_ENTER("spider_ft_get_relevance"); + st_spider_ft_info *info = (st_spider_ft_info*) handler; + DBUG_PRINT("info",("spider info=%p", info)); + DBUG_PRINT("info",("spider score=%f", info->score)); + DBUG_RETURN(info->score); +} + +void spider_ft_close_search( + FT_INFO *handler +) { + DBUG_ENTER("spider_ft_close_search"); + DBUG_VOID_RETURN; +} + +_ft_vft spider_ft_vft = { + NULL, // spider_ft_read_next + spider_ft_find_relevance, + spider_ft_close_search, + spider_ft_get_relevance, + NULL // spider_ft_reinit_search +}; + +int ha_spider::ft_init() +{ + int roop_count, error_num; + DBUG_ENTER("ha_spider::ft_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (store_error_num) + DBUG_RETURN(store_error_num); + if (active_index == MAX_KEY && inited == NONE) + { + st_spider_ft_info *ft_info = ft_first; + ft_init_without_index_init = TRUE; + ft_init_idx = MAX_KEY; + while (TRUE) + { + if (ft_info->used_in_where) + { + ft_init_idx = ft_info->inx; + if ((error_num = index_init(ft_init_idx, FALSE))) + DBUG_RETURN(error_num); + active_index = MAX_KEY; + break; + } + if (ft_info == ft_current) + break; + ft_info = ft_info->next; + } + if (ft_init_idx == MAX_KEY) + { + if ((error_num = rnd_init(TRUE))) + DBUG_RETURN(error_num); + } + } else { + ft_init_idx = active_index; + ft_init_without_index_init = FALSE; + } + + ft_init_and_first = TRUE; + + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + sql_kinds = SPIDER_SQL_KIND_SQL; + DBUG_RETURN(0); +} + +void ha_spider::ft_end() +{ + DBUG_ENTER("ha_spider::ft_end"); + DBUG_PRINT("info",("spider this=%p", this)); + ft_handler = NULL; + ft_current = NULL; + ft_count = 0; + if (ft_init_without_index_init) + { + if (ft_init_idx == MAX_KEY) + store_error_num = rnd_end(); + else + store_error_num = index_end(); + } + ft_init_without_index_init = FALSE; + DBUG_VOID_RETURN; +} + +FT_INFO *ha_spider::ft_init_ext( + uint flags, + uint inx, + String *key +) { + st_spider_ft_info *tmp_ft_info; + backup_error_status(); + DBUG_ENTER("ha_spider::ft_init_ext"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider flags=%u", flags)); + DBUG_PRINT("info",("spider inx=%u", inx)); + DBUG_PRINT("info",("spider key=%s", key->c_ptr_safe())); + tmp_ft_info = ft_current; + if (ft_current) + ft_current = ft_current->next; + else + ft_current = ft_first; + + if (!ft_current) + { + if (!(ft_current = (st_spider_ft_info *) + spider_malloc(spider_current_trx, 2, sizeof(st_spider_ft_info), + MYF(MY_WME | MY_ZEROFILL)))) + { + store_error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + if (tmp_ft_info) + tmp_ft_info->next = ft_current; + else + ft_first = ft_current; + } + + ft_current->please = &spider_ft_vft; + ft_current->file = this; + ft_current->used_in_where = (flags & FT_SORTED); + ft_current->target = ft_count; + ft_current->flags = flags; + ft_current->inx = inx; + ft_current->key = key; + + ft_count++; + DBUG_RETURN((FT_INFO *) ft_current); +} + +int ha_spider::ft_read_internal( + uchar *buf +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::ft_read_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if (ft_init_and_first) + { + ft_init_and_first = FALSE; + spider_db_free_one_result_for_start_next(this); + check_direct_order_limit(); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + check_select_column(FALSE); +#endif + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + if ( + (error_num = spider_db_append_select(this)) || + (error_num = spider_db_append_select_columns(this)) + ) + DBUG_RETURN(error_num); + uint tmp_active_index = active_index; + active_index = ft_init_idx; + if ( + ft_init_idx < MAX_KEY && + share->key_hint && + (error_num = + append_hint_after_table_sql_part(SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + active_index = tmp_active_index; + DBUG_RETURN(error_num); + } + active_index = tmp_active_index; + set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + result_list.desc_flg = FALSE; + result_list.sorted = TRUE; + if (ft_init_idx == MAX_KEY) + result_list.key_info = NULL; + else + result_list.key_info = &table->key_info[ft_init_idx]; + result_list.key_order = 0; + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + if ( + (error_num = spider_db_append_match_where(this)) || + ( + result_list.direct_order_limit && + (error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part(NULL, 0, + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + ) + DBUG_RETURN(error_num); + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ( + (error_num = append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = append_limit_sql_part( + result_list.internal_offset, + result_list.limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_RETURN(error_num); + } + } + + int roop_start, roop_end, roop_count, tmp_lock_mode, link_ok; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + link_ok = search_link_idx; + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_bg_conn_search(this, roop_count, roop_start, + TRUE, FALSE, (roop_count != link_ok)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { +#endif + uint dbton_id = share->use_sql_dbton_ids[roop_count]; + spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; + SPIDER_CONN *conn = conns[roop_count]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(this, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_SELECT_SQL, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(this, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + result_link_idx = link_ok; + } else { + spider_db_discard_result(this, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + } + + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = this; + } + if (buf && (error_num = spider_db_seek_next(buf, this, search_link_idx, + table))) + DBUG_RETURN(check_error_mode_eof(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::pre_ft_read( + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_ft_read"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + ft_read_internal(NULL); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::ft_read( + uchar *buf +) { + int error_num; + DBUG_ENTER("ha_spider::ft_read"); + DBUG_PRINT("info",("spider this=%p", this)); + if (use_pre_call) + { + if (store_error_num) + { + if (store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(store_error_num); + } + if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) + DBUG_RETURN(error_num); + use_pre_call = FALSE; + } + DBUG_RETURN(ft_read_internal(buf)); +} + +int ha_spider::info( + uint flag +) { + int error_num; + THD *thd = ha_thd(); + double sts_interval = spider_param_sts_interval(thd, share->sts_interval); + int sts_mode = spider_param_sts_mode(thd, share->sts_mode); +#ifdef WITH_PARTITION_STORAGE_ENGINE + int sts_sync = spider_param_sts_sync(thd, share->sts_sync); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + int sts_bg_mode = spider_param_sts_bg_mode(thd, share->sts_bg_mode); +#endif + SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL; + set_error_mode(); + backup_error_status(); + DBUG_ENTER("ha_spider::info"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider flag=%x", flag)); + sql_command = thd_sql_command(thd); + if ( + sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_ALTER_TABLE || + sql_command == SQLCOM_SHOW_CREATE + ) { + if (flag & HA_STATUS_AUTO) + { + if (share->auto_increment_value) + stats.auto_increment_value = share->auto_increment_value; + else + stats.auto_increment_value = 1; + } + DBUG_RETURN(0); + } + + if (flag & + (HA_STATUS_TIME | HA_STATUS_CONST | HA_STATUS_VARIABLE | HA_STATUS_AUTO)) + { + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, share->sts_get_time))); + DBUG_PRINT("info", + ("spider sts_interval=%f", sts_interval)); + int tmp_auto_increment_mode = 0; + if (flag & HA_STATUS_AUTO) + { + tmp_auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); +#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC + info_auto_called = TRUE; +#endif + } + if (!share->sts_init) + { + pthread_mutex_lock(&share->sts_mutex); + if (share->sts_init) + pthread_mutex_unlock(&share->sts_mutex); + else { + if ((spider_init_error_table = + spider_get_init_error_table(trx, share, FALSE))) + { + DBUG_PRINT("info",("spider diff=%f", + difftime(tmp_time, spider_init_error_table->init_error_time))); + if (difftime(tmp_time, + spider_init_error_table->init_error_time) < + spider_param_table_init_error_interval()) + { + pthread_mutex_unlock(&share->sts_mutex); + if (spider_init_error_table->init_error_with_message) + my_message(spider_init_error_table->init_error, + spider_init_error_table->init_error_msg, MYF(0)); + DBUG_RETURN(check_error_mode(spider_init_error_table->init_error)); + } + } + pthread_mutex_unlock(&share->sts_mutex); + sts_interval = 0; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (tmp_auto_increment_mode == 1) + sts_sync = 0; +#endif + } + } + if (flag & HA_STATUS_AUTO) + { + if ( + share->partition_share && + tmp_auto_increment_mode == 1 && + !share->auto_increment_init + ) { + sts_interval = 0; +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync = 0; +#endif + } + } + if (difftime(tmp_time, share->sts_get_time) >= sts_interval) + { + if ( + sts_interval == 0 || + !pthread_mutex_trylock(&share->sts_mutex) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (sts_interval == 0 || sts_bg_mode == 0) + { +#endif + if (sts_interval == 0) + pthread_mutex_lock(&share->sts_mutex); + if (difftime(tmp_time, share->sts_get_time) >= sts_interval) + { + if ( + (error_num = spider_check_trx_and_get_conn(ha_thd(), this, + FALSE)) || + (error_num = spider_get_sts(share, search_link_idx, tmp_time, + this, sts_interval, sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync, +#endif + share->sts_init ? 2 : 1, + flag | (share->sts_init ? 0 : HA_STATUS_AUTO))) + ) { + pthread_mutex_unlock(&share->sts_mutex); + if ( + share->monitoring_kind[search_link_idx] && + need_mons[search_link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[search_link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[search_link_idx], + NULL, + 0, + share->monitoring_kind[search_link_idx], + share->monitoring_limit[search_link_idx], + TRUE + ); + } + if (!share->sts_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(trx, share, TRUE)) + ) { + spider_init_error_table->init_error = error_num; +/* + if (!thd->is_error()) + my_error(error_num, MYF(0), ""); +*/ + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(spider_init_error_table->init_error_msg, + thd->main_da.message()); +#else + strmov(spider_init_error_table->init_error_msg, + thd->stmt_da->message()); +#endif + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + } + DBUG_RETURN(check_error_mode(error_num)); + } + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } else { + /* background */ + if (!share->bg_sts_init || share->bg_sts_thd_wait) + { + share->bg_sts_thd_wait = FALSE; + share->bg_sts_try_time = tmp_time; + share->bg_sts_interval = sts_interval; + share->bg_sts_mode = sts_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->bg_sts_sync = sts_sync; +#endif + if (!share->bg_sts_init) + { + if ((error_num = spider_create_sts_thread(share))) + { + pthread_mutex_unlock(&share->sts_mutex); + DBUG_RETURN(error_num); + } + } else + pthread_cond_signal(&share->bg_sts_cond); + } + } +#endif + pthread_mutex_unlock(&share->sts_mutex); + } + } + if (flag & HA_STATUS_CONST) + { + if ((error_num = check_crd())) + DBUG_RETURN(error_num); + spider_db_set_cardinarity(this, table); + } + + if (flag & HA_STATUS_TIME) + stats.update_time = (ulong) share->update_time; + if (flag & (HA_STATUS_CONST | HA_STATUS_VARIABLE)) + { + stats.max_data_file_length = share->max_data_file_length; + stats.create_time = (ulong) share->create_time; + stats.block_size = spider_param_block_size(thd); + } + if (flag & HA_STATUS_VARIABLE) + { + stats.data_file_length = share->data_file_length; + stats.index_file_length = share->index_file_length; + stats.records = share->records; + stats.mean_rec_length = share->mean_rec_length; + stats.check_time = (ulong) share->check_time; + if (stats.records <= 1 /* && (flag & HA_STATUS_NO_LOCK) */ ) + stats.records = 2; + } + if (flag & HA_STATUS_AUTO) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (share->partition_share && table->next_number_field) + { + ulonglong first_value, nb_reserved_values; + if ( + tmp_auto_increment_mode == 0 && + !( + table->next_number_field->val_int() != 0 || + (table->auto_increment_field_not_null && + thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + ) + ) { + get_auto_increment(0, 0, 0, &first_value, &nb_reserved_values); + share->auto_increment_value = first_value; + share->auto_increment_lclval = first_value; + share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + stats.auto_increment_value = first_value; + } else if (tmp_auto_increment_mode == 1 && !share->auto_increment_init) + { + share->auto_increment_lclval = share->auto_increment_value; + share->auto_increment_init = TRUE; + stats.auto_increment_value = share->auto_increment_value; + } else { + stats.auto_increment_value = share->auto_increment_value; + } + } else { +#endif + stats.auto_increment_value = share->auto_increment_value; +#ifdef WITH_PARTITION_STORAGE_ENGINE + } +#endif + } + } + if (flag & HA_STATUS_ERRKEY) + errkey = dup_key_idx; + DBUG_RETURN(0); +} + +ha_rows ha_spider::records_in_range( + uint inx, + key_range *start_key, + key_range *end_key +) { + int error_num; + THD *thd = ha_thd(); + double crd_interval = spider_param_crd_interval(thd, share->crd_interval); + int crd_mode = spider_param_crd_mode(thd, share->crd_mode); + int crd_type = spider_param_crd_type(thd, share->crd_type); +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync = spider_param_crd_sync(thd, share->crd_sync); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode); +#endif + SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL; + uint dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::records_in_range"); + DBUG_PRINT("info",("spider this=%p", this)); + time_t tmp_time = (time_t) time((time_t*) 0); + if (!share->crd_init) + { + pthread_mutex_lock(&share->crd_mutex); + if (share->crd_init) + pthread_mutex_unlock(&share->crd_mutex); + else { + if ((spider_init_error_table = + spider_get_init_error_table(trx, share, FALSE))) + { + DBUG_PRINT("info",("spider diff=%f", + difftime(tmp_time, spider_init_error_table->init_error_time))); + if (difftime(tmp_time, + spider_init_error_table->init_error_time) < + spider_param_table_init_error_interval()) + { + pthread_mutex_unlock(&share->crd_mutex); + if (spider_init_error_table->init_error_with_message) + my_message(spider_init_error_table->init_error, + spider_init_error_table->init_error_msg, MYF(0)); + if (check_error_mode(spider_init_error_table->init_error)) + my_errno = spider_init_error_table->init_error; + DBUG_RETURN(HA_POS_ERROR); + } + } + pthread_mutex_unlock(&share->crd_mutex); + if (crd_mode == 3) + crd_mode = 1; + crd_interval = 0; + } + } + dbton_id = share->sql_dbton_ids[search_link_idx]; + dbton_hdl = dbton_handler[dbton_id]; + crd_mode = dbton_hdl->crd_mode_exchange(crd_mode); + if (crd_mode == 1 || crd_mode == 2) + { + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, share->crd_get_time))); + DBUG_PRINT("info", + ("spider crd_interval=%f", crd_interval)); + if (difftime(tmp_time, share->crd_get_time) >= crd_interval) + { + if ( + crd_interval == 0 || + !pthread_mutex_trylock(&share->crd_mutex) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (crd_interval == 0 || crd_bg_mode == 0) + { +#endif + if (crd_interval == 0) + pthread_mutex_lock(&share->crd_mutex); + if (difftime(tmp_time, share->crd_get_time) >= crd_interval) + { + if ((error_num = spider_get_crd(share, search_link_idx, tmp_time, + this, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + share->crd_init ? 2 : 1))) + { + pthread_mutex_unlock(&share->crd_mutex); + if ( + share->monitoring_kind[search_link_idx] && + need_mons[search_link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[search_link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[search_link_idx], + NULL, + 0, + share->monitoring_kind[search_link_idx], + share->monitoring_limit[search_link_idx], + TRUE + ); + } + if (!share->crd_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(trx, share, TRUE)) + ) { + spider_init_error_table->init_error = error_num; +/* + if (!thd->is_error()) + my_error(error_num, MYF(0), ""); +*/ + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(spider_init_error_table->init_error_msg, + thd->main_da.message()); +#else + strmov(spider_init_error_table->init_error_msg, + thd->stmt_da->message()); +#endif + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + } + if (check_error_mode(error_num)) + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } else { + /* background */ + if (!share->bg_crd_init || share->bg_crd_thd_wait) + { + share->bg_crd_thd_wait = FALSE; + share->bg_crd_try_time = tmp_time; + share->bg_crd_interval = crd_interval; + share->bg_crd_mode = crd_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->bg_crd_sync = crd_sync; +#endif + if (!share->bg_crd_init) + { + if ((error_num = spider_create_crd_thread(share))) + { + pthread_mutex_unlock(&share->crd_mutex); + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + } else + pthread_cond_signal(&share->bg_crd_cond); + } + } +#endif + pthread_mutex_unlock(&share->crd_mutex); + } + } + + KEY *key_info = &table->key_info[inx]; + key_part_map full_key_part_map = + make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + key_part_map end_key_part_map; + key_part_map tgt_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + double rows = (double) share->records; + double weight, rate; + DBUG_PRINT("info",("spider rows1=%f", rows)); + if (start_key) + start_key_part_map = start_key->keypart_map & full_key_part_map; + else + start_key_part_map = 0; + if (end_key) + end_key_part_map = end_key->keypart_map & full_key_part_map; + else + end_key_part_map = 0; + + if (!start_key_part_map && !end_key_part_map) + { + DBUG_RETURN(HA_POS_ERROR); + } + else if (start_key_part_map >= end_key_part_map) + { + tgt_key_part_map = start_key_part_map; + } else { + tgt_key_part_map = end_key_part_map; + } + + if (crd_type == 0) + weight = spider_param_crd_weight(thd, share->crd_weight); + else + weight = 1; + + for ( + key_part = key_info->key_part; + tgt_key_part_map > 1; + tgt_key_part_map >>= 1, + key_part++ + ) { + field = key_part->field; + if ((rate = + ((double) share->cardinality[field->field_index]) / weight) >= 1 + ) { + if ((rows = rows / rate) < 2) + { + DBUG_PRINT("info",("spider rows2=%f then ret 2", rows)); + DBUG_RETURN((ha_rows) 2); + } + } + if (crd_type == 1) + weight += spider_param_crd_weight(thd, share->crd_weight); + else if (crd_type == 2) + weight *= spider_param_crd_weight(thd, share->crd_weight); + } + field = key_part->field; + if ( + start_key_part_map >= end_key_part_map && + start_key->flag == HA_READ_KEY_EXACT + ) { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight) >= 1) + rows = rows / rate; + } else if (start_key_part_map == end_key_part_map) + { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight / 4) >= 1) + rows = rows / rate; + } else { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight / 16) >= 1) + rows = rows / rate; + } + if (rows < 2) + { + DBUG_PRINT("info",("spider rows3=%f then ret 2", rows)); + DBUG_RETURN((ha_rows) 2); + } + DBUG_PRINT("info",("spider rows4=%f", rows)); + DBUG_RETURN((ha_rows) rows); + } else if (crd_mode == 3) + { + result_list.key_info = &table->key_info[inx]; + DBUG_RETURN(spider_db_explain_select(start_key, end_key, this, + search_link_idx)); + } + DBUG_RETURN((ha_rows) spider_param_crd_weight(thd, share->crd_weight)); +} + +int ha_spider::check_crd() +{ + int error_num; + THD *thd = ha_thd(); + double crd_interval = spider_param_crd_interval(thd, share->crd_interval); + int crd_mode = spider_param_crd_mode(thd, share->crd_mode); +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync = spider_param_crd_sync(thd, share->crd_sync); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode); +#endif + SPIDER_INIT_ERROR_TABLE *spider_init_error_table = NULL; + uint dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::check_crd"); + DBUG_PRINT("info",("spider this=%p", this)); + time_t tmp_time = (time_t) time((time_t*) 0); + if (!share->crd_init) + { + pthread_mutex_lock(&share->crd_mutex); + if (share->crd_init) + pthread_mutex_unlock(&share->crd_mutex); + else { + if ((spider_init_error_table = + spider_get_init_error_table(trx, share, FALSE))) + { + DBUG_PRINT("info",("spider diff=%f", + difftime(tmp_time, spider_init_error_table->init_error_time))); + if (difftime(tmp_time, + spider_init_error_table->init_error_time) < + spider_param_table_init_error_interval()) + { + pthread_mutex_unlock(&share->crd_mutex); + if (spider_init_error_table->init_error_with_message) + my_message(spider_init_error_table->init_error, + spider_init_error_table->init_error_msg, MYF(0)); + DBUG_RETURN(check_error_mode(spider_init_error_table->init_error)); + } + } + pthread_mutex_unlock(&share->crd_mutex); + crd_interval = 0; + } + } + if (crd_mode == 3) + crd_mode = 1; + dbton_id = share->sql_dbton_ids[search_link_idx]; + dbton_hdl = dbton_handler[dbton_id]; + crd_mode = dbton_hdl->crd_mode_exchange(crd_mode); + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, share->crd_get_time))); + DBUG_PRINT("info", + ("spider crd_interval=%f", crd_interval)); + if (difftime(tmp_time, share->crd_get_time) >= crd_interval) + { + if ( + crd_interval == 0 || + !pthread_mutex_trylock(&share->crd_mutex) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (crd_interval == 0 || crd_bg_mode == 0) + { +#endif + if (crd_interval == 0) + pthread_mutex_lock(&share->crd_mutex); + if (difftime(tmp_time, share->crd_get_time) >= crd_interval) + { + if ((error_num = spider_get_crd(share, search_link_idx, tmp_time, + this, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + share->crd_init ? 2 : 1))) + { + pthread_mutex_unlock(&share->crd_mutex); + if ( + share->monitoring_kind[search_link_idx] && + need_mons[search_link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[search_link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[search_link_idx], + NULL, + 0, + share->monitoring_kind[search_link_idx], + share->monitoring_limit[search_link_idx], + TRUE + ); + } + if (!share->crd_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(trx, share, TRUE)) + ) { + spider_init_error_table->init_error = error_num; + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(spider_init_error_table->init_error_msg, + thd->main_da.message()); +#else + strmov(spider_init_error_table->init_error_msg, + thd->stmt_da->message()); +#endif + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + } + DBUG_RETURN(check_error_mode(error_num)); + } + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } else { + /* background */ + if (!share->bg_crd_init || share->bg_crd_thd_wait) + { + share->bg_crd_thd_wait = FALSE; + share->bg_crd_try_time = tmp_time; + share->bg_crd_interval = crd_interval; + share->bg_crd_mode = crd_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->bg_crd_sync = crd_sync; +#endif + if (!share->bg_crd_init) + { + if ((error_num = spider_create_crd_thread(share))) + { + pthread_mutex_unlock(&share->crd_mutex); + DBUG_RETURN(error_num); + } + } else + pthread_cond_signal(&share->bg_crd_cond); + } + } +#endif + pthread_mutex_unlock(&share->crd_mutex); + } + } + DBUG_RETURN(0); +} + +ha_rows ha_spider::records() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::records"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_show_records(this, search_link_idx))) + { + check_error_mode(error_num); + DBUG_RETURN(HA_POS_ERROR); + } + DBUG_RETURN(share->records); +} + +const char *ha_spider::table_type() const +{ + DBUG_ENTER("ha_spider::table_type"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN("SPIDER"); +} + +ulonglong ha_spider::table_flags() const +{ + DBUG_ENTER("ha_spider::table_flags"); + DBUG_PRINT("info",("spider this=%p", this)); + ulonglong flags = + HA_REC_NOT_IN_SEQ | + HA_CAN_GEOMETRY | + HA_NULL_IN_KEY | + HA_CAN_INDEX_BLOBS | + HA_AUTO_PART_KEY | + HA_CAN_RTREEKEYS | + HA_PRIMARY_KEY_REQUIRED_FOR_DELETE | + /* HA_NO_PREFIX_CHAR_KEYS | */ + HA_CAN_FULLTEXT | + HA_CAN_SQL_HANDLER | + HA_FILE_BASED | + HA_CAN_INSERT_DELAYED | + HA_CAN_BIT_FIELD | + HA_NO_COPY_ON_ALTER | + HA_BINLOG_ROW_CAPABLE | + HA_BINLOG_STMT_CAPABLE | + HA_HAS_RECORDS | + HA_PARTIAL_COLUMN_READ | +#ifdef HA_CAN_BULK_ACCESS + (support_bulk_access_hs() ? HA_CAN_BULK_ACCESS : 0) | +#endif + SPIDER_CAN_BG_SEARCH | + SPIDER_CAN_BG_INSERT | + SPIDER_CAN_BG_UPDATE | + (share ? share->additional_table_flags : 0) + ; + DBUG_RETURN(flags); +} + +const char *ha_spider::index_type( + uint key_number +) { + KEY *key_info = &table->s->key_info[key_number]; + DBUG_ENTER("ha_spider::index_type"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider flags=%ld", key_info->flags)); + DBUG_PRINT("info",("spider algorithm=%d", key_info->algorithm)); + DBUG_RETURN( + (key_info->flags & HA_FULLTEXT) ? "FULLTEXT" : + (key_info->flags & HA_SPATIAL) ? "SPATIAL" : + (key_info->algorithm == HA_KEY_ALG_HASH) ? "HASH" : + (key_info->algorithm == HA_KEY_ALG_RTREE) ? "RTREE" : + "BTREE" + ); +} + +ulong ha_spider::index_flags( + uint idx, + uint part, + bool all_parts +) const { + DBUG_ENTER("ha_spider::index_flags"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN( + (table_share->key_info[idx].algorithm == HA_KEY_ALG_FULLTEXT) ? + 0 : + (table_share->key_info[idx].algorithm == HA_KEY_ALG_HASH) ? + HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR : + HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE | + HA_KEYREAD_ONLY + ); +} + +uint ha_spider::max_supported_record_length() const +{ + DBUG_ENTER("ha_spider::max_supported_record_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_MAX_REC_LENGTH); +} + +uint ha_spider::max_supported_keys() const +{ + DBUG_ENTER("ha_spider::max_supported_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(MAX_KEY); +} + +uint ha_spider::max_supported_key_parts() const +{ + DBUG_ENTER("ha_spider::max_supported_key_parts"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(MAX_REF_PARTS); +} + +uint ha_spider::max_supported_key_length() const +{ + DBUG_ENTER("ha_spider::max_supported_key_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(SPIDER_MAX_KEY_LENGTH); +} + +uint ha_spider::max_supported_key_part_length() const +{ + DBUG_ENTER("ha_spider::max_supported_key_part_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(SPIDER_MAX_KEY_LENGTH); +} + +uint8 ha_spider::table_cache_type() +{ + DBUG_ENTER("ha_spider::table_cache_type"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_CACHE_TBL_NOCACHE); +} + +#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC +bool ha_spider::need_info_for_auto_inc() +{ + THD *thd = ha_thd(); + DBUG_ENTER("ha_spider::need_info_for_auto_inc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider return=%s", ( + !spider_param_auto_increment_mode(thd, share->auto_increment_mode) && + !info_auto_called + ) ? "TRUE" : "FALSE")); + DBUG_RETURN(( + !spider_param_auto_increment_mode(thd, share->auto_increment_mode) && + !info_auto_called + )); +} +#endif + + +int ha_spider::update_auto_increment() +{ + int error_num; + THD *thd = ha_thd(); + int auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + bool lock_here = FALSE; + backup_error_status(); + DBUG_ENTER("ha_spider::update_auto_increment"); + DBUG_PRINT("info",("spider this=%p", this)); + force_auto_increment = TRUE; +/* + if ( + next_insert_id >= auto_inc_interval_for_cur_row.maximum() && + trx->thd->auto_inc_intervals_forced.get_current() + ) { + force_auto_increment = TRUE; + DBUG_PRINT("info",("spider force_auto_increment=TRUE")); + } else { + force_auto_increment = FALSE; + DBUG_PRINT("info",("spider force_auto_increment=FALSE")); + } +*/ + if ( + auto_increment_mode == 1 && + !( + table->next_number_field->val_int() != 0 || + (table->auto_increment_field_not_null && + thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + ) + ) { + lock_here = TRUE; + pthread_mutex_lock(&share->auto_increment_mutex); + next_insert_id = share->auto_increment_value; + } + if ((error_num = handler::update_auto_increment())) + { + if (lock_here) + pthread_mutex_unlock(&share->auto_increment_mutex); + DBUG_RETURN(check_error_mode(error_num)); + } + if (lock_here) + { + if (insert_id_for_cur_row) + { + share->auto_increment_lclval = insert_id_for_cur_row + 1; + share->auto_increment_value = next_insert_id; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->auto_increment_lclval)); + } + pthread_mutex_unlock(&share->auto_increment_mutex); + } + if (!store_last_insert_id) + { + store_last_insert_id = table->next_number_field->val_int(); + } + DBUG_RETURN(0); +} + +void ha_spider::get_auto_increment( + ulonglong offset, + ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values +) { + THD *thd = ha_thd(); + int auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + DBUG_ENTER("ha_spider::get_auto_increment"); + DBUG_PRINT("info",("spider this=%p", this)); + *nb_reserved_values = ULONGLONG_MAX; + if (auto_increment_mode == 0) + { + /* strict mode */ + int error_num; + extra(HA_EXTRA_KEYREAD); + if (index_init(table_share->next_number_index, TRUE)) + goto error_index_init; + result_list.internal_limit = 1; + if (table_share->next_number_keypart) + { + uchar key[MAX_KEY_LENGTH]; + key_copy(key, table->record[0], + &table->key_info[table_share->next_number_index], + table_share->next_number_key_offset); + error_num = index_read_last_map(table->record[1], key, + make_prev_keypart_map(table_share->next_number_keypart)); + } else + error_num = index_last(table->record[1]); + + if (error_num) + *first_value = 1; + else + *first_value = ((ulonglong) table->next_number_field-> + val_int_offset(table_share->rec_buff_length) + 1); + index_end(); + extra(HA_EXTRA_NO_KEYREAD); + DBUG_VOID_RETURN; + +error_index_init: + extra(HA_EXTRA_NO_KEYREAD); + *first_value = ~(ulonglong)0; + DBUG_VOID_RETURN; + } else { + if (auto_increment_mode != 1) + pthread_mutex_lock(&share->auto_increment_mutex); + DBUG_PRINT("info",("spider before auto_increment_lclval=%llu", + share->auto_increment_lclval)); + *first_value = share->auto_increment_lclval; + share->auto_increment_lclval += nb_desired_values * increment; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->auto_increment_lclval)); + if (auto_increment_mode != 1) + pthread_mutex_unlock(&share->auto_increment_mutex); + } + DBUG_VOID_RETURN; +} + +int ha_spider::reset_auto_increment( + ulonglong value +) { + DBUG_ENTER("ha_spider::reset_auto_increment"); + DBUG_PRINT("info",("spider this=%p", this)); + if (table->next_number_field) + { + pthread_mutex_lock(&share->auto_increment_mutex); + share->auto_increment_lclval = value; + share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + pthread_mutex_unlock(&share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + +void ha_spider::release_auto_increment() +{ + DBUG_ENTER("ha_spider::release_auto_increment"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +void ha_spider::start_bulk_insert( + ha_rows rows +) { + DBUG_ENTER("ha_spider::start_bulk_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + bulk_insert = TRUE; + bulk_size = -1; + store_last_insert_id = 0; + DBUG_VOID_RETURN; +} + +int ha_spider::end_bulk_insert() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::end_bulk_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + bulk_insert = FALSE; + if (bulk_size == -1) + DBUG_RETURN(0); + if ((error_num = spider_db_bulk_insert(this, table, TRUE))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::write_row( + uchar *buf +) { + int error_num; + THD *thd = ha_thd(); + int auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + bool auto_increment_flag = + table->next_number_field && buf == table->record[0]; + backup_error_status(); + DBUG_ENTER("ha_spider::write_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && + ( + ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) || + bulk_access_pre_called + ) + ) { + ulonglong option_backup = 0; + if (is_bulk_access_clone) + { + bulk_access_pre_called = FALSE; + DBUG_RETURN(spider_db_bulk_bulk_insert(this)); + } +#if MYSQL_VERSION_ID < 50500 + option_backup = thd->options; + thd->options &= ~OPTION_BIN_LOG; +#else + option_backup = thd->variables.option_bits; + thd->variables.option_bits &= ~OPTION_BIN_LOG; +#endif + error_num = bulk_access_link_exec_tgt->spider->ha_write_row(buf); +#if MYSQL_VERSION_ID < 50500 + thd->options = option_backup; +#else + thd->variables.option_bits = option_backup; +#endif + DBUG_RETURN(error_num); + } +#endif + ha_statistic_increment(&SSV::ha_write_count); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#else + if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) + table->timestamp_field->set_time(); +#endif + if (!bulk_insert) + store_last_insert_id = 0; + if (auto_increment_flag) + { + if (auto_increment_mode == 3) + { + if (!table->auto_increment_field_not_null) + { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + table->next_number_field->store((longlong) 0, TRUE); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + force_auto_increment = FALSE; + table->file->insert_id_for_cur_row = 0; + } + } else if (auto_increment_mode == 2) + { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + table->next_number_field->store((longlong) 0, TRUE); + table->auto_increment_field_not_null = FALSE; +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + force_auto_increment = FALSE; + table->file->insert_id_for_cur_row = 0; + } else { + if (!share->auto_increment_init) + { + pthread_mutex_lock(&share->auto_increment_mutex); + if (!share->auto_increment_init) + { + info(HA_STATUS_AUTO); + share->auto_increment_lclval = stats.auto_increment_value; + share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + } + pthread_mutex_unlock(&share->auto_increment_mutex); + } + if ((error_num = update_auto_increment())) + DBUG_RETURN(error_num); + } + } + if (!bulk_insert || bulk_size < 0) + { + direct_dup_insert = + spider_param_direct_dup_insert(trx->thd, share->direct_dup_insert); + DBUG_PRINT("info",("spider direct_dup_insert=%d", direct_dup_insert)); + if ((error_num = spider_db_bulk_insert_init(this, table))) + DBUG_RETURN(check_error_mode(error_num)); + if (bulk_insert) + bulk_size = + insert_with_update || (!direct_dup_insert && ignore_dup_key) ? + 0 : spider_param_bulk_size(trx->thd, share->bulk_size); + else + bulk_size = 0; + } + if ((error_num = spider_db_bulk_insert(this, table, FALSE))) + DBUG_RETURN(check_error_mode(error_num)); + +#ifdef HA_CAN_BULK_ACCESS + /* bulk access disabled case (like using partitioning) */ + if (bulk_access_executing && is_bulk_access_clone) + { + bulk_req_exec(); + DBUG_RETURN(spider_db_bulk_bulk_insert(this)); + } +#endif + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_write_row( + uchar *buf +) { + int error_num; + ulonglong option_backup = 0; + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::pre_write_row"); + DBUG_PRINT("info",("spider this=%p", this)); +#if MYSQL_VERSION_ID < 50500 + option_backup = thd->options; + thd->options &= ~OPTION_BIN_LOG; +#else + option_backup = thd->variables.option_bits; + thd->variables.option_bits &= ~OPTION_BIN_LOG; +#endif + error_num = bulk_access_link_current->spider->ha_write_row(buf); + bulk_access_link_current->spider->bulk_access_pre_called = TRUE; + bulk_access_link_current->called = TRUE; +#if MYSQL_VERSION_ID < 50500 + thd->options = option_backup; +#else + thd->variables.option_bits = option_backup; +#endif + DBUG_RETURN(error_num); +} +#endif + +bool ha_spider::start_bulk_update( +) { + DBUG_ENTER("ha_spider::start_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(check_and_start_bulk_update(SPD_BU_START_BY_BULK_INIT)); +} + +int ha_spider::exec_bulk_update( + uint *dup_key_found +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::exec_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + *dup_key_found = 0; + if ((error_num = spider_db_bulk_update_end(this, dup_key_found))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +void ha_spider::end_bulk_update( +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::end_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = check_and_end_bulk_update(SPD_BU_START_BY_BULK_INIT))) + { + if (check_error_mode(error_num)) + my_errno = error_num; + } + DBUG_VOID_RETURN; +} + +int ha_spider::bulk_update_row( + const uchar *old_data, + uchar *new_data, + uint *dup_key_found +) { + DBUG_ENTER("ha_spider::bulk_update_row"); + DBUG_PRINT("info",("spider this=%p", this)); + *dup_key_found = 0; + DBUG_RETURN(update_row(old_data, new_data)); +} + +int ha_spider::update_row( + const uchar *old_data, + uchar *new_data +) { + int error_num; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::update_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + ulonglong option_backup = 0; +#if MYSQL_VERSION_ID < 50500 + option_backup = thd->options; + thd->options &= ~OPTION_BIN_LOG; +#else + option_backup = thd->variables.option_bits; + thd->variables.option_bits &= ~OPTION_BIN_LOG; +#endif + error_num = bulk_access_link_exec_tgt->spider->ha_update_row( + old_data, new_data); +#if MYSQL_VERSION_ID < 50500 + thd->options = option_backup; +#else + thd->variables.option_bits = option_backup; +#endif + DBUG_RETURN(error_num); + } +#endif + ha_statistic_increment(&SSV::ha_update_count); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#endif +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#else + if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) + table->timestamp_field->set_time(); +#endif + if ((error_num = spider_db_update(this, table, old_data))) + DBUG_RETURN(check_error_mode(error_num)); + if (table->found_next_number_field && + new_data == table->record[0] && + !table->s->next_number_keypart + ) { + pthread_mutex_lock(&share->auto_increment_mutex); + if (!share->auto_increment_init) + { + info(HA_STATUS_AUTO); + share->auto_increment_lclval = stats.auto_increment_value; + share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + } + ulonglong tmp_auto_increment; + if (((Field_num *) table->found_next_number_field)->unsigned_flag) + { + tmp_auto_increment = + (ulonglong) table->found_next_number_field->val_int(); + } else { + longlong tmp_auto_increment2 = + table->found_next_number_field->val_int(); + if (tmp_auto_increment2 > 0) + tmp_auto_increment = tmp_auto_increment2; + else + tmp_auto_increment = 0; + } + if (tmp_auto_increment >= share->auto_increment_lclval) + { + share->auto_increment_lclval = tmp_auto_increment + 1; + share->auto_increment_value = tmp_auto_increment + 1; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->auto_increment_lclval)); + } + pthread_mutex_unlock(&share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int ha_spider::direct_update_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data +) { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::direct_update_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && + ( + ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) || + bulk_access_pre_called + ) + ) { + if (is_bulk_access_clone) + { + DBUG_PRINT("info",("spider return pre_direct_init_result %d", + pre_direct_init_result)); + DBUG_RETURN(pre_direct_init_result); + } + DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_update_rows_init( + mode, ranges, range_count, sorted, new_data)); + } +#endif + if (!condition) + cond_check = FALSE; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + if ( + !range_count && + direct_update_fields + ) { + if ( +#if MYSQL_VERSION_ID < 50500 + !thd->variables.engine_condition_pushdown || +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + !select_lex || + select_lex->table_list.elements != 1 || + check_update_columns_sql_part() || + spider_db_append_condition(this, NULL, 0, TRUE) + ) { + DBUG_PRINT("info",("spider FALSE by condition")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + if (select_lex->order_list.elements) + { + ORDER *order; + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if (check_item_type_sql((*order->item))) + { + DBUG_PRINT("info",("spider FALSE by order")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + result_list.direct_order_limit = TRUE; + } + + trx->direct_update_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); + } + + DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); + DBUG_PRINT("info",("spider mode=%u", mode)); + DBUG_PRINT("info",("spider maybe_do_hs_direct_update=%s", + maybe_do_hs_direct_update ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider sql_command=%u", sql_command)); + DBUG_PRINT("info",("spider hs_pushed_ret_fields_num=%zu", + hs_pushed_ret_fields_num)); + DBUG_PRINT("info",("spider do_direct_update=%s", + do_direct_update ? "TRUE" : "FALSE")); + if ( + ( + !offset_limit +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + || (mode == 2 && maybe_do_hs_direct_update) +#endif + ) && +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + sql_command == SQLCOM_HS_UPDATE && + hs_pushed_ret_fields_num < MAX_FIELDS && +#endif + do_direct_update + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + DBUG_PRINT("info",("spider pk_update=%s", pk_update ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider start_key=%p", &ranges->start_key)); + if (pk_update && spider_check_hs_pk_update(this, &ranges->start_key)) + { + DBUG_PRINT("info",("spider FALSE by pk_update")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } +#endif + trx->direct_update_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); + } + DBUG_PRINT("info",("spider FALSE by default")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_direct_update_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data +) { + int error_num; + DBUG_ENTER("ha_spider::pre_direct_update_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (bulk_access_started) + { + error_num = bulk_access_link_current->spider-> + ha_pre_direct_update_rows_init( + mode, ranges, range_count, sorted, new_data); + bulk_access_link_current->spider->bulk_access_pre_called = TRUE; + bulk_access_link_current->called = TRUE; + DBUG_RETURN(error_num); + } + pre_direct_init_result = direct_update_rows_init( + mode, ranges, range_count, sorted, new_data); + DBUG_RETURN(pre_direct_init_result); +} +#endif + +int ha_spider::direct_update_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data, + uint *update_rows +) { + int error_num; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::direct_update_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && + ( + ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) || + bulk_access_pre_called + ) + ) { + if (is_bulk_access_clone) + { + bulk_access_pre_called = FALSE; + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + } + DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_update_rows( + ranges, range_count, sorted, new_data, update_rows)); + } +#endif + if ( + (active_index != MAX_KEY && (error_num = index_handler_init())) || + (active_index == MAX_KEY && (error_num = rnd_handler_init())) || + (error_num = spider_db_direct_update(this, table, ranges, range_count, + update_rows)) + ) + DBUG_RETURN(check_error_mode(error_num)); + +#ifdef HA_CAN_BULK_ACCESS + if (bulk_access_executing && is_bulk_access_clone) + { + bulk_req_exec(); + DBUG_RETURN(spider_db_bulk_direct_update(this, update_rows)); + } +#endif + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_direct_update_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data, + uint *update_rows +) { + DBUG_ENTER("ha_spider::pre_direct_update_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_direct_update_rows(ranges, + range_count, sorted, new_data, update_rows)); +} +#endif +#endif + +bool ha_spider::start_bulk_delete( +) { + DBUG_ENTER("ha_spider::start_bulk_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(check_and_start_bulk_update(SPD_BU_START_BY_BULK_INIT)); +} + +int ha_spider::end_bulk_delete( +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::end_bulk_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = check_and_end_bulk_update(SPD_BU_START_BY_BULK_INIT))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::delete_row( + const uchar *buf +) { + THD *thd = ha_thd(); + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::delete_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) { + ulonglong option_backup = 0; +#if MYSQL_VERSION_ID < 50500 + option_backup = thd->options; + thd->options &= ~OPTION_BIN_LOG; +#else + option_backup = thd->variables.option_bits; + thd->variables.option_bits &= ~OPTION_BIN_LOG; +#endif + error_num = bulk_access_link_exec_tgt->spider->ha_delete_row(buf); +#if MYSQL_VERSION_ID < 50500 + thd->options = option_backup; +#else + thd->variables.option_bits = option_backup; +#endif + DBUG_RETURN(error_num); + } +#endif + ha_statistic_increment(&SSV::ha_delete_count); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#endif + if ((error_num = spider_db_delete(this, table, buf))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int ha_spider::direct_delete_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted +) { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::direct_delete_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && + ( + ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) || + bulk_access_pre_called + ) + ) { + if (is_bulk_access_clone) + { + DBUG_RETURN(pre_direct_init_result); + } + DBUG_RETURN(bulk_access_link_exec_tgt->spider->direct_delete_rows_init( + mode, ranges, range_count, sorted)); + } +#endif + if (!condition) + cond_check = FALSE; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + if (!range_count) + { + if ( +#if MYSQL_VERSION_ID < 50500 + !thd->variables.engine_condition_pushdown || +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + !select_lex || + select_lex->table_list.elements != 1 || + spider_db_append_condition(this, NULL, 0, TRUE) + ) { + DBUG_PRINT("info",("spider FALSE by condition")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + if (select_lex->order_list.elements) + { + ORDER *order; + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if (check_item_type_sql((*order->item))) + { + DBUG_PRINT("info",("spider FALSE by order")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + result_list.direct_order_limit = TRUE; + } + + trx->direct_delete_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); + } + + if ( + ( + !offset_limit +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + || (mode == 2 && maybe_do_hs_direct_update) +#endif + ) && +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + sql_command == SQLCOM_HS_DELETE && +#endif + do_direct_update + ) { + trx->direct_delete_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); + } + DBUG_PRINT("info",("spider FALSE by default")); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_direct_delete_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted +) { + int error_num; + DBUG_ENTER("ha_spider::pre_direct_delete_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (bulk_access_started) + { + error_num = bulk_access_link_current->spider-> + ha_pre_direct_delete_rows_init( + mode, ranges, range_count, sorted); + bulk_access_link_current->spider->bulk_access_pre_called = TRUE; + bulk_access_link_current->called = TRUE; + DBUG_RETURN(error_num); + } + pre_direct_init_result = direct_delete_rows_init( + mode, ranges, range_count, sorted); + DBUG_RETURN(pre_direct_init_result); +} +#endif + +int ha_spider::direct_delete_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uint *delete_rows +) { + int error_num; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::direct_delete_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HA_CAN_BULK_ACCESS + if ( + bulk_access_executing && + ( + ( + !is_bulk_access_clone && + bulk_access_link_exec_tgt->called + ) || + bulk_access_pre_called + ) + ) { + if (is_bulk_access_clone) + { + bulk_access_pre_called = FALSE; + DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows)); + } + DBUG_RETURN(bulk_access_link_exec_tgt->spider->ha_direct_delete_rows( + ranges, range_count, sorted, delete_rows)); + } +#endif + if ( + (active_index != MAX_KEY && (error_num = index_handler_init())) || + (active_index == MAX_KEY && (error_num = rnd_handler_init())) || + (error_num = spider_db_direct_delete(this, table, ranges, range_count, + delete_rows)) + ) + DBUG_RETURN(check_error_mode(error_num)); + +#ifdef HA_CAN_BULK_ACCESS + if (bulk_access_executing && is_bulk_access_clone) + { + bulk_req_exec(); + DBUG_RETURN(spider_db_bulk_direct_update(this, delete_rows)); + } +#endif + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int ha_spider::pre_direct_delete_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uint *delete_rows +) { + DBUG_ENTER("ha_spider::pre_direct_delete_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(bulk_access_link_current->spider->ha_direct_delete_rows( + ranges, range_count, sorted, delete_rows)); +} +#endif +#endif + +int ha_spider::delete_all_rows() +{ + int error_num, roop_count; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::delete_all_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#endif + sql_kinds = SPIDER_SQL_KIND_SQL; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + if ((error_num = spider_db_delete_all_rows(this))) + DBUG_RETURN(check_error_mode(error_num)); + if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field) + { + DBUG_PRINT("info",("spider reset auto increment")); + pthread_mutex_lock(&share->auto_increment_mutex); + share->auto_increment_lclval = 1; + share->auto_increment_init = FALSE; + share->auto_increment_value = 1; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + pthread_mutex_unlock(&share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + +int ha_spider::truncate() +{ + int error_num, roop_count; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::truncate"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_read_only_mode(thd, share->read_only_mode)) + { + my_printf_error(ER_SPIDER_READ_ONLY_NUM, ER_SPIDER_READ_ONLY_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + DBUG_RETURN(ER_SPIDER_READ_ONLY_NUM); + } + sql_command = SQLCOM_TRUNCATE; + if ((error_num = spider_check_trx_and_get_conn(thd, this, FALSE))) + { + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = FALSE; +#endif + sql_kinds = SPIDER_SQL_KIND_SQL; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + if ((error_num = spider_db_delete_all_rows(this))) + DBUG_RETURN(check_error_mode(error_num)); + if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field) + { + DBUG_PRINT("info",("spider reset auto increment")); + pthread_mutex_lock(&share->auto_increment_mutex); + share->auto_increment_lclval = 1; + share->auto_increment_init = FALSE; + share->auto_increment_value = 1; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->auto_increment_lclval)); + pthread_mutex_unlock(&share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +void ha_spider::bulk_req_exec() +{ + int need_mon; + SPIDER_CONN *conn = trx->bulk_access_conn_first; + DBUG_ENTER("ha_spider::bulk_req_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider trx=%p", trx)); + DBUG_PRINT("info",("spider first_conn=%p", conn)); + while (conn) + { + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->bulk_access_requests=%u", + conn->bulk_access_requests)); + if (conn->bulk_access_requests) + { + spider_bg_conn_wait(conn); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + /* currently only used for HS */ + conn->bulk_access_error_num = 0; + if (spider_db_query( + conn, + NULL, + 0, + -1, + &need_mon) + ) { + conn->bulk_access_error_num = spider_db_errorno(conn); + } +/* + conn->bulk_access_sended += conn->bulk_access_requests; +*/ + conn->bulk_access_requests = 0; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + conn = conn->bulk_access_next; + } + trx->bulk_access_conn_first = NULL; + DBUG_VOID_RETURN; +} +#endif + +double ha_spider::scan_time() +{ + DBUG_ENTER("ha_spider::scan_time"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider scan_time = %.6f", + share->scan_rate * share->records * share->mean_rec_length + 2)); + DBUG_RETURN(share->scan_rate * share->records * share->mean_rec_length + 2); +} + +double ha_spider::read_time( + uint index, + uint ranges, + ha_rows rows +) { + DBUG_ENTER("ha_spider::read_time"); + DBUG_PRINT("info",("spider this=%p", this)); + if (keyread) + { + DBUG_PRINT("info",("spider read_time(keyread) = %.6f", + share->read_rate * table->s->key_info[index].key_length * + rows / 2 + 2)); + DBUG_RETURN(share->read_rate * table->s->key_info[index].key_length * + rows / 2 + 2); + } else { + DBUG_PRINT("info",("spider read_time = %.6f", + share->read_rate * share->mean_rec_length * rows + 2)); + DBUG_RETURN(share->read_rate * share->mean_rec_length * rows + 2); + } +} + +const key_map *ha_spider::keys_to_use_for_scanning() +{ + DBUG_ENTER("ha_spider::keys_to_use_for_scanning"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(&key_map_full); +} + +ha_rows ha_spider::estimate_rows_upper_bound() +{ + DBUG_ENTER("ha_spider::estimate_rows_upper_bound"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_POS_ERROR); +} + +bool ha_spider::get_error_message( + int error, + String *buf +) { + DBUG_ENTER("ha_spider::get_error_message"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (error) + { + case ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM: + if (buf->reserve(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_LEN)) + DBUG_RETURN(TRUE); + buf->q_append(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_LEN); + break; + default: + if (buf->reserve(ER_SPIDER_UNKNOWN_LEN)) + DBUG_RETURN(TRUE); + buf->q_append(ER_SPIDER_UNKNOWN_STR, ER_SPIDER_UNKNOWN_LEN); + break; + } + DBUG_RETURN(FALSE); +} + +int ha_spider::create( + const char *name, + TABLE *form, + HA_CREATE_INFO *info +) { + int error_num; + SPIDER_SHARE tmp_share; + THD *thd = ha_thd(); + uint sql_command = thd_sql_command(thd), roop_count; + SPIDER_TRX *trx; + TABLE *table_tables = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool need_lock = FALSE; + DBUG_ENTER("ha_spider::create"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider name=%s", name)); + DBUG_PRINT("info", + ("spider form->s->connect_string=%s", form->s->connect_string.str)); + DBUG_PRINT("info", + ("spider info->connect_string=%s", info->connect_string.str)); + if ( + sql_command == SQLCOM_CREATE_INDEX || + sql_command == SQLCOM_DROP_INDEX + ) + DBUG_RETURN(0); + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + goto error_get_trx; + if ( + trx->locked_connections && + sql_command == SQLCOM_ALTER_TABLE + ) { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM; + goto error_alter_before_unlock; + } + memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); + tmp_share.table_name = (char*) name; + tmp_share.table_name_length = strlen(name); + if (form->s->keys > 0 && + !(tmp_share.key_hint = new spider_string[form->s->keys]) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + for (roop_count = 0; roop_count < form->s->keys; roop_count++) + tmp_share.key_hint[roop_count].init_calc_mem(85); + DBUG_PRINT("info",("spider tmp_share.key_hint=%p", tmp_share.key_hint)); + if ((error_num = spider_parse_connect_info(&tmp_share, form->s, +#ifdef WITH_PARTITION_STORAGE_ENGINE + form->part_info, +#endif + 1))) + goto error; + DBUG_PRINT("info",("spider tmp_table=%d", form->s->tmp_table)); + if ( + (sql_command == SQLCOM_CREATE_TABLE && + !(info->options & HA_LEX_CREATE_TMP_TABLE)) + ) { + if ( + !(table_tables = spider_open_sys_table( + current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, + &error_num)) + ) { + goto error; + } + if ( + (error_num = spider_insert_tables(table_tables, &tmp_share)) + ) { + goto error; + } + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } else if ( + sql_command == SQLCOM_ALTER_TABLE + ) { + SPIDER_ALTER_TABLE *alter_table; + if (trx->query_id != thd->query_id) + { + spider_free_trx_alter_table(trx); + trx->query_id = thd->query_id; + } +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + tmp_share.table_name_hash_value = my_calc_hash(&trx->trx_alter_table_hash, + (uchar*) tmp_share.table_name, tmp_share.table_name_length);; + if (!(alter_table = + (SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value( + &trx->trx_alter_table_hash, tmp_share.table_name_hash_value, + (uchar*) tmp_share.table_name, tmp_share.table_name_length))) +#else + if (!(alter_table = + (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash, + (uchar*) tmp_share.table_name, tmp_share.table_name_length))) +#endif + { + if ((error_num = spider_create_trx_alter_table(trx, &tmp_share, TRUE))) + goto error; + } + trx->tmp_flg = TRUE; + + DBUG_PRINT("info", + ("spider alter_info.flags=%u", thd->lex->alter_info.flags)); + if ( + (thd->lex->alter_info.flags & + ( + ALTER_ADD_PARTITION | ALTER_DROP_PARTITION | + ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION | + ALTER_TABLE_REORG | ALTER_REBUILD_PARTITION + ) + ) && + memcmp(name + strlen(name) - 5, "#TMP#", 5) + ) { + need_lock = TRUE; + if ( + !(table_tables = spider_open_sys_table( + current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) { + goto error; + } + if ( + (error_num = spider_insert_tables(table_tables, &tmp_share)) + ) { + goto error; + } + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, TRUE); + table_tables = NULL; + } + } + + spider_free_share_alloc(&tmp_share); + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, need_lock); + spider_free_share_alloc(&tmp_share); +error_alter_before_unlock: +error_get_trx: + DBUG_RETURN(error_num); +} + +void ha_spider::update_create_info( + HA_CREATE_INFO* create_info +) { + DBUG_ENTER("ha_spider::update_create_info"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!create_info->connect_string.str) + { + create_info->connect_string.str = table->s->connect_string.str; + create_info->connect_string.length = table->s->connect_string.length; + } + DBUG_PRINT("info", + ("spider create_info->connect_string=%s", + create_info->connect_string.str)); + DBUG_VOID_RETURN; +} + +int ha_spider::rename_table( + const char *from, + const char *to +) { + int error_num, roop_count, old_link_count, from_len = strlen(from); + THD *thd = ha_thd(); + uint sql_command = thd_sql_command(thd); + SPIDER_TRX *trx; + TABLE *table_tables = NULL; + SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool need_lock = FALSE; + DBUG_ENTER("ha_spider::rename_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider from=%s", from)); + DBUG_PRINT("info",("spider to=%s", to)); + if ( + sql_command == SQLCOM_CREATE_INDEX || + sql_command == SQLCOM_DROP_INDEX + ) + DBUG_RETURN(0); + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + goto error; + if ( + trx->locked_connections && + /* SQLCOM_RENAME_TABLE doesn't come here */ + sql_command == SQLCOM_ALTER_TABLE + ) { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM; + goto error; + } + if ( + sql_command == SQLCOM_RENAME_TABLE || + (sql_command == SQLCOM_ALTER_TABLE && !trx->tmp_flg) || + !(alter_table_from = + (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash, + (uchar*) from, from_len)) + ) { + if ( + !(table_tables = spider_open_sys_table( + current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, + &error_num)) + ) { + goto error; + } + if ( + (error_num = spider_update_tables_name( + table_tables, from, to, &old_link_count)) + ) { + goto error; + } + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + + /* release table mon list */ + for (roop_count = 0; roop_count < old_link_count; roop_count++) + spider_release_ping_table_mon_list(from, from_len, roop_count); + } else if (sql_command == SQLCOM_ALTER_TABLE) + { + int to_len = strlen(to); + DBUG_PRINT("info",("spider alter_table_from=%p", alter_table_from)); + if ((alter_table_to = + (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash, + (uchar*) to, to_len)) + ) { + DBUG_PRINT("info",("spider copy link_statuses")); + uint all_link_count = alter_table_from->all_link_count; + if (all_link_count > alter_table_to->all_link_count) + all_link_count = alter_table_to->all_link_count; + for (roop_count = 0; roop_count < (int) all_link_count; roop_count++) + { + if (alter_table_from->tmp_link_statuses[roop_count] <= + SPIDER_LINK_STATUS_NO_CHANGE) + alter_table_from->tmp_link_statuses[roop_count] = + alter_table_to->tmp_link_statuses[roop_count]; + } + } + + DBUG_PRINT("info", + ("spider alter_info.flags=%u", thd->lex->alter_info.flags)); + if ( + (thd->lex->alter_info.flags & + ( + ALTER_ADD_PARTITION | ALTER_DROP_PARTITION | + ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION | + ALTER_TABLE_REORG | ALTER_REBUILD_PARTITION + ) + ) + ) + need_lock = TRUE; + + if ( + !(table_tables = spider_open_sys_table( + current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock, + &error_num)) + ) { + goto error; + } + + if (alter_table_from->now_create) + { + SPIDER_SHARE tmp_share; + tmp_share.table_name = (char*) to; + tmp_share.table_name_length = to_len; + tmp_share.priority = alter_table_from->tmp_priority; + tmp_share.link_count = alter_table_from->link_count; + tmp_share.all_link_count = alter_table_from->all_link_count; + memcpy(&tmp_share.alter_table, alter_table_from, + sizeof(*alter_table_from)); + if ( + (error_num = spider_insert_tables(table_tables, &tmp_share)) + ) { + goto error; + } + } else { + if ( + (error_num = spider_update_tables_priority( + table_tables, alter_table_from, to, &old_link_count)) + ) { + goto error; + } + } + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + + if (!alter_table_from->now_create) + { + /* release table mon list */ + for (roop_count = 0; roop_count < (int) alter_table_from->all_link_count; + roop_count++) + spider_release_ping_table_mon_list(from, from_len, roop_count); + for (roop_count = 0; roop_count < old_link_count; roop_count++) + spider_release_ping_table_mon_list(to, to_len, roop_count); + } +/* + spider_free_trx_alter_table_alloc(trx, alter_table_from); +*/ + } + + spider_delete_init_error_table(from); + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int ha_spider::delete_table( + const char *name +) { + int error_num; + THD *thd = ha_thd(); + SPIDER_TRX *trx; + TABLE *table_tables = NULL; + uint sql_command = thd_sql_command(thd); + SPIDER_ALTER_TABLE *alter_table; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool need_lock = FALSE; + DBUG_ENTER("ha_spider::delete_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider name=%s", name)); + if ( + sql_command == SQLCOM_CREATE_INDEX || + sql_command == SQLCOM_DROP_INDEX + ) + DBUG_RETURN(0); + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + goto error; + if ( + trx->locked_connections && + /* SQLCOM_DROP_DB doesn't come here */ + ( + sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_ALTER_TABLE + ) + ) { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + error_num = ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM; + goto error; + } + if (sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_DROP_DB || + sql_command == SQLCOM_ALTER_TABLE || + sql_command == SQLCOM_CREATE_TABLE) + { + int roop_count, old_link_count = 0, name_len = strlen(name); + if ( + sql_command == SQLCOM_ALTER_TABLE && + (alter_table = + (SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash, + (uchar*) name, name_len)) && + alter_table->now_create + ) + DBUG_RETURN(0); + + DBUG_PRINT("info", + ("spider alter_info.flags=%u", thd->lex->alter_info.flags)); + if ( + sql_command == SQLCOM_ALTER_TABLE && + (thd->lex->alter_info.flags & + ( + ALTER_ADD_PARTITION | ALTER_DROP_PARTITION | + ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION | + ALTER_TABLE_REORG | ALTER_REBUILD_PARTITION + ) + ) + ) + need_lock = TRUE; + + if ( + !(table_tables = spider_open_sys_table( + current_thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock, + &error_num)) + ) { + goto error; + } + if ( + (error_num = spider_delete_tables( + table_tables, name, &old_link_count)) + ) { + goto error; + } + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + + /* release table mon list */ + for (roop_count = 0; roop_count < old_link_count; roop_count++) + spider_release_ping_table_mon_list(name, name_len, roop_count); + } + + spider_delete_init_error_table(name); + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(current_thd, table_tables, + &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +bool ha_spider::is_crashed() const +{ + DBUG_ENTER("ha_spider::is_crashed"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool ha_spider::auto_repair() const +{ + DBUG_ENTER("ha_spider::auto_repair"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int ha_spider::disable_indexes( + uint mode +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::disable_indexes"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_disable_keys(this))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::enable_indexes( + uint mode +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::enable_indexes"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_enable_keys(this))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + + +int ha_spider::check( + THD* thd, + HA_CHECK_OPT* check_opt +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::check"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_check_table(this, check_opt))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::repair( + THD* thd, + HA_CHECK_OPT* check_opt +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::repair"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_repair_table(this, check_opt))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +bool ha_spider::check_and_repair( + THD *thd +) { + HA_CHECK_OPT check_opt; + DBUG_ENTER("ha_spider::check_and_repair"); + DBUG_PRINT("info",("spider this=%p", this)); + check_opt.init(); + check_opt.flags = T_MEDIUM; + if (spider_db_check_table(this, &check_opt)) + { + check_opt.flags = T_QUICK; + if (spider_db_repair_table(this, &check_opt)) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +int ha_spider::analyze( + THD* thd, + HA_CHECK_OPT* check_opt +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::analyze"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_analyze_table(this))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::optimize( + THD* thd, + HA_CHECK_OPT* check_opt +) { + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::optimize"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_optimize_table(this))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +bool ha_spider::is_fatal_error( + int error_num, + uint flags +) { + DBUG_ENTER("ha_spider::is_fatal_error"); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + DBUG_PRINT("info",("spider flags=%u", flags)); + if ( + !handler::is_fatal_error(error_num, flags) + ) { + DBUG_PRINT("info",("spider FALSE")); + DBUG_RETURN(FALSE); + } + DBUG_PRINT("info",("spider TRUE")); + DBUG_RETURN(TRUE); +} + +Field *ha_spider::get_top_table_field( + uint16 field_index +) { + Field *field; + DBUG_ENTER("ha_spider::get_top_table_field"); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + DBUG_RETURN(pt_clone_source_handler->get_top_table_field(field_index)); + } +#endif + DBUG_PRINT("info",("spider field_index=%u", field_index)); +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + if (set_top_table_fields) + { + field = top_table->field[field_index]; + } else { +#endif + field = table->field[field_index]; +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + } +#endif + DBUG_PRINT("info",("spider out field=%p", field)); + DBUG_RETURN(field); +} + +Field *ha_spider::field_exchange( + Field *field +) { + DBUG_ENTER("ha_spider::field_exchange"); +#ifdef HA_CAN_BULK_ACCESS + if (is_bulk_access_clone) + { + DBUG_RETURN(pt_clone_source_handler->field_exchange(field)); + } +#endif + DBUG_PRINT("info",("spider in field=%p", field)); +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + if (set_top_table_fields) + { + if (field->table != top_table) + DBUG_RETURN(NULL); + if (!(field = top_table_field[field->field_index])) + DBUG_RETURN(NULL); + } else { +#endif + if (field->table != table) + DBUG_RETURN(NULL); +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + } +#endif + DBUG_PRINT("info",("spider out field=%p", field)); + DBUG_RETURN(field); +} + +const COND *ha_spider::cond_push( + const COND *cond +) { + DBUG_ENTER("ha_spider::cond_push"); + cond_check = FALSE; + if (cond) + { + SPIDER_CONDITION *tmp_cond; + if (!(tmp_cond = (SPIDER_CONDITION *) + spider_malloc(spider_current_trx, 3, sizeof(*tmp_cond), MYF(MY_WME))) + ) + DBUG_RETURN(cond); + tmp_cond->cond = (COND *) cond; + tmp_cond->next = condition; + condition = tmp_cond; + } + DBUG_RETURN(NULL); +} + +void ha_spider::cond_pop() +{ + DBUG_ENTER("ha_spider::cond_pop"); + if (condition) + { + SPIDER_CONDITION *tmp_cond = condition->next; + spider_free(spider_current_trx, condition, MYF(0)); + condition = tmp_cond; + } + DBUG_VOID_RETURN; +} + +int ha_spider::info_push( + uint info_type, + void *info +) { + int error_num = 0; + DBUG_ENTER("ha_spider::info_push"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef HA_CAN_BULK_ACCESS + if ( + info_type != INFO_KIND_BULK_ACCESS_BEGIN && + info_type != INFO_KIND_BULK_ACCESS_CURRENT && + info_type != INFO_KIND_BULK_ACCESS_END && + info_type != INFO_KIND_HS_RET_FIELDS + ) { + if (!is_bulk_access_clone) + { + if ( + bulk_access_executing && + bulk_access_link_exec_tgt->called + ) { + DBUG_RETURN(bulk_access_link_exec_tgt->spider->info_push(info_type, + info)); + } else if (bulk_access_started) + { + DBUG_RETURN(bulk_access_link_current->spider->info_push(info_type, + info)); + } + } + } +#endif + +#if defined(HANDLER_HAS_DIRECT_UPDATE_ROWS) || defined(HA_CAN_BULK_ACCESS) + switch (info_type) + { +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + case INFO_KIND_HS_RET_FIELDS: + { + DBUG_PRINT("info",("spider INFO_KIND_HS_RET_FIELDS")); + size_t roop_count; + Field *field; + SPIDER_HS_UINT32_INFO *tmp_info = (SPIDER_HS_UINT32_INFO *) info; + hs_pushed_ret_fields_num = tmp_info->info_size; + if (hs_pushed_ret_fields_size < hs_pushed_ret_fields_num) + { + if (hs_pushed_ret_fields) + spider_free(spider_current_trx, hs_pushed_ret_fields, MYF(0)); + if (!(hs_pushed_ret_fields = (uint32 *) + spider_bulk_malloc(spider_current_trx, 17, MYF(MY_WME), + &hs_pushed_ret_fields, sizeof(uint32) * hs_pushed_ret_fields_num, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + hs_pushed_ret_fields_size = hs_pushed_ret_fields_num; + } + memcpy(hs_pushed_ret_fields, tmp_info->info, + sizeof(uint32) * hs_pushed_ret_fields_num); + bitmap_clear_all(table->read_set); + bitmap_clear_all(table->write_set); + hs_pushed_lcl_fields_num = 0; + for (roop_count = 0; roop_count < hs_pushed_ret_fields_num; roop_count++) + { + field = get_top_table_field(hs_pushed_ret_fields[roop_count]); + if ((field = field_exchange(field))) + { + if (!bitmap_is_set(table->read_set, field->field_index)) + { + ++hs_pushed_lcl_fields_num; + bitmap_set_bit(table->read_set, field->field_index); + bitmap_set_bit(table->write_set, field->field_index); + } + } + } + } + break; + case INFO_KIND_HS_APPEND_STRING_REF: + { + DBUG_PRINT("info",("spider INFO_KIND_HS_APPEND_STRING_REF")); +#ifndef DBUG_OFF + SPIDER_HS_STRING_REF *tmp_ref = (SPIDER_HS_STRING_REF*) info; + char print_buf[MAX_FIELD_WIDTH]; + if (tmp_ref->size() < MAX_FIELD_WIDTH) + { + memcpy(print_buf, tmp_ref->begin(), tmp_ref->size()); + print_buf[tmp_ref->size()] = '\0'; + DBUG_PRINT("info",("spider info=%s", print_buf)); + } +#endif + Field *field; + if (hs_pushed_ret_fields) + { + field = get_top_table_field( + hs_pushed_ret_fields[hs_pushed_strref_num]); + } else { + field = get_top_table_field( + pt_clone_source_handler->hs_pushed_ret_fields[hs_pushed_strref_num]); + } + if (!field_exchange(field)) + { + hs_pushed_strref_num++; + break; + } + hs_pushed_strref_num++; + if ((error_num = push_back_hs_upds(*((SPIDER_HS_STRING_REF*) info)))) + { + DBUG_RETURN(error_num); + } + break; + } + case INFO_KIND_HS_CLEAR_STRING_REF: + DBUG_PRINT("info",("spider INFO_KIND_HS_CLEAR_STRING_REF")); + hs_pushed_strref_num = 0; + if ((error_num = reset_hs_upds(SPIDER_SQL_TYPE_UPDATE_HS))) + { + DBUG_RETURN(error_num); + } + break; + case INFO_KIND_HS_INCREMENT_BEGIN: + DBUG_PRINT("info",("spider INFO_KIND_HS_INCREMENT_BEGIN")); + hs_increment = TRUE; + break; + case INFO_KIND_HS_INCREMENT_END: + DBUG_PRINT("info",("spider INFO_KIND_HS_INCREMENT_END")); + hs_increment = FALSE; + break; + case INFO_KIND_HS_DECREMENT_BEGIN: + DBUG_PRINT("info",("spider INFO_KIND_HS_DECREMENT_BEGIN")); + hs_decrement = TRUE; + break; + case INFO_KIND_HS_DECREMENT_END: + DBUG_PRINT("info",("spider INFO_KIND_HS_DECREMENT_END")); + hs_decrement = FALSE; + break; +#endif + case INFO_KIND_UPDATE_FIELDS: + DBUG_PRINT("info",("spider INFO_KIND_UPDATE_FIELDS")); + direct_update_fields = (List *) info; + break; + case INFO_KIND_UPDATE_VALUES: + DBUG_PRINT("info",("spider INFO_KIND_UPDATE_VALUES")); + direct_update_values = (List *) info; + break; +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + case INFO_KIND_FORCE_LIMIT_BEGIN: + DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_BEGIN")); + info_limit = *((longlong *) info); + trx->direct_aggregate_count++; + break; + case INFO_KIND_FORCE_LIMIT_END: + DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_END")); + info_limit = 9223372036854775807LL; + break; +#endif +#endif +#ifdef HA_CAN_BULK_ACCESS + case INFO_KIND_BULK_ACCESS_BEGIN: + DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_BEGIN")); + if (bulk_access_started) + { + if (!bulk_access_link_current->next) + { + if (!(bulk_access_link_current->next = create_bulk_access_link())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + bulk_access_link_current->next->sequence_num = + bulk_access_link_current->sequence_num + 1; + } + bulk_access_link_current = bulk_access_link_current->next; + } else { + if (!bulk_access_link_first) + { + if (!(bulk_access_link_first = create_bulk_access_link())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + bulk_access_link_first->sequence_num = 0; + } + bulk_access_link_current = bulk_access_link_first; + bulk_access_started = TRUE; + bulk_access_executing = FALSE; + } + if ( + (error_num = bulk_access_link_current->spider-> + sync_from_clone_source(this)) || + (error_num = bulk_access_link_current->spider-> + check_access_kind(trx->thd, (lock_type >= TL_WRITE_ALLOW_WRITE))) + ) { + DBUG_RETURN(error_num); + } + memset( + bulk_access_link_current->spider->result_list.hs_r_bulk_open_index, 0, + share->link_bitmap_size); + memset( + bulk_access_link_current->spider->result_list.hs_w_bulk_open_index, 0, + share->link_bitmap_size); +/* +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = bulk_access_link_current->spider->reset_hs_strs_pos( + SPIDER_SQL_TYPE_UPDATE_HS))) + { + DBUG_RETURN(error_num); + } +#endif +*/ + bulk_access_link_current->spider->bulk_access_executing = FALSE; + bulk_access_link_current->spider->bulk_access_pre_called = FALSE; + bulk_access_link_current->used = TRUE; + bulk_access_link_current->called = FALSE; + *((void **) info) = bulk_access_link_current; + break; + case INFO_KIND_BULK_ACCESS_CURRENT: + DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_CURRENT")); + bulk_access_executing = TRUE; + bulk_access_link_exec_tgt = (SPIDER_BULK_ACCESS_LINK *) info; + if (bulk_access_link_exec_tgt->spider->pt_clone_source_handler != this) + { + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider pt_clone_source_handler=%p", + bulk_access_link_exec_tgt->spider->pt_clone_source_handler)); + /* partitioned */ + uint sequence_num = bulk_access_link_exec_tgt->sequence_num; + for ( + bulk_access_link_exec_tgt = bulk_access_link_first; + bulk_access_link_exec_tgt; + bulk_access_link_exec_tgt = bulk_access_link_exec_tgt->next + ) { + if (bulk_access_link_exec_tgt->sequence_num >= sequence_num) + { + DBUG_ASSERT( + bulk_access_link_exec_tgt->sequence_num == sequence_num); + break; + } + } + } + bulk_access_link_exec_tgt->spider->bulk_access_executing = TRUE; + break; + case INFO_KIND_BULK_ACCESS_END: + DBUG_PRINT("info",("spider INFO_KIND_BULK_ACCESS_END")); + bulk_access_started = FALSE; + break; +#endif + default: + break; + } +#endif + DBUG_RETURN(error_num); +} + +TABLE *ha_spider::get_table() +{ + DBUG_ENTER("ha_spider::get_table"); + DBUG_RETURN(table); +} + +void ha_spider::set_searched_bitmap() +{ + int roop_count; + DBUG_ENTER("ha_spider::set_searched_bitmap"); + for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + { + searched_bitmap[roop_count] = + ((uchar *) table->read_set->bitmap)[roop_count] | + ((uchar *) table->write_set->bitmap)[roop_count]; + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + DBUG_PRINT("info",("spider searched_bitmap=%d", + searched_bitmap[roop_count])); + DBUG_PRINT("info",("spider read_set=%d", + ((uchar *) table->read_set->bitmap)[roop_count])); + DBUG_PRINT("info",("spider write_set=%d", + ((uchar *) table->write_set->bitmap)[roop_count])); + } + if (sql_command == SQLCOM_UPDATE || sql_command == SQLCOM_UPDATE_MULTI) + { + DBUG_PRINT("info",("spider update option start")); + Item *item; + List_iterator_fast fi(table->pos_in_table_list->select_lex-> + item_list); + while ((item = fi++)) + { + if (item->type() == Item::FIELD_ITEM) + { + Field *field = ((Item_field *)item)->field; + if (!(field = field_exchange(field))) + { + DBUG_PRINT("info",("spider field is for different table")); + continue; + } + spider_set_bit(searched_bitmap, field->field_index); + DBUG_PRINT("info",("spider set searched_bitmap=%u", + field->field_index)); + } else { + DBUG_PRINT("info",("spider item type is not field")); + } + } + } + DBUG_VOID_RETURN; +} + +void ha_spider::set_clone_searched_bitmap() +{ + DBUG_ENTER("ha_spider::set_clone_searched_bitmap"); + memcpy(searched_bitmap, pt_clone_source_handler->searched_bitmap, + (table_share->fields + 7) / 8); + DBUG_VOID_RETURN; +} + +void ha_spider::set_select_column_mode() +{ + int roop_count; + KEY *key_info; + KEY_PART_INFO *key_part; + Field *field; + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::set_select_column_mode"); + position_bitmap_init = FALSE; +#ifndef DBUG_OFF + for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + DBUG_PRINT("info", ("spider bitmap is %x", + ((uchar *) table->read_set->bitmap)[roop_count])); +#endif + select_column_mode = spider_param_select_column_mode(thd, + share->select_column_mode); + if (select_column_mode) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + partition_handler_share && + partition_handler_share->searched_bitmap + ) { + if (partition_handler_share->searched_bitmap != searched_bitmap) + memcpy(searched_bitmap, partition_handler_share->searched_bitmap, + (table_share->fields + 7) / 8); + partition_handler_share->between_flg = FALSE; + DBUG_PRINT("info",("spider copy searched_bitmap")); + } else { +#endif + set_searched_bitmap(); + if (result_list.lock_type == F_WRLCK && sql_command != SQLCOM_SELECT) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + uint part_num = 0; + if (update_request) + part_num = check_partitioned(); +#endif + if ( +#ifdef WITH_PARTITION_STORAGE_ENGINE + part_num || +#endif + table_share->primary_key == MAX_KEY + ) { + /* need all columns */ + for (roop_count = 0; roop_count < (int) table_share->fields; + roop_count++) + spider_set_bit(searched_bitmap, roop_count); + } else { + /* need primary key columns */ + key_info = &table_share->key_info[table_share->primary_key]; + key_part = key_info->key_part; + for (roop_count = 0; roop_count < (int) key_info->key_parts; + roop_count++) + { + field = key_part[roop_count].field; + spider_set_bit(searched_bitmap, field->field_index); + } + } +#ifndef DBUG_OFF + for (roop_count = 0; + roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + DBUG_PRINT("info", ("spider change bitmap is %x", + searched_bitmap[roop_count])); +#endif + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (partition_handler_share) + { + partition_handler_share->searched_bitmap = searched_bitmap; + partition_handler_share->between_flg = TRUE; + DBUG_PRINT("info",("spider set searched_bitmap")); + } + } +#endif + } + DBUG_VOID_RETURN; +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +void ha_spider::check_select_column(bool rnd) +{ + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::check_select_column"); + select_column_mode = spider_param_select_column_mode(thd, + share->select_column_mode); + if (select_column_mode && partition_handler_share) + { + if (!rnd) + { + if (partition_handler_share->between_flg) + { + memcpy(partition_handler_share->idx_read_bitmap, + table->read_set->bitmap, (table_share->fields + 7) / 8); + memcpy(partition_handler_share->idx_write_bitmap, + table->write_set->bitmap, (table_share->fields + 7) / 8); + partition_handler_share->between_flg = FALSE; + partition_handler_share->idx_bitmap_is_set = TRUE; + DBUG_PRINT("info",("spider set idx_bitmap")); + } else if (partition_handler_share->idx_bitmap_is_set) + { + memcpy(table->read_set->bitmap, + partition_handler_share->idx_read_bitmap, + (table_share->fields + 7) / 8); + memcpy(table->write_set->bitmap, + partition_handler_share->idx_write_bitmap, + (table_share->fields + 7) / 8); + DBUG_PRINT("info",("spider copy idx_bitmap")); + } + } else { + if ( + !partition_handler_share->rnd_bitmap_is_set && + ( + partition_handler_share->between_flg || + partition_handler_share->idx_bitmap_is_set + ) + ) { + memcpy(partition_handler_share->rnd_read_bitmap, + table->read_set->bitmap, (table_share->fields + 7) / 8); + memcpy(partition_handler_share->rnd_write_bitmap, + table->write_set->bitmap, (table_share->fields + 7) / 8); + partition_handler_share->between_flg = FALSE; + partition_handler_share->rnd_bitmap_is_set = TRUE; + DBUG_PRINT("info",("spider set rnd_bitmap")); + } else if (partition_handler_share->rnd_bitmap_is_set) + { + memcpy(table->read_set->bitmap, + partition_handler_share->rnd_read_bitmap, + (table_share->fields + 7) / 8); + memcpy(table->write_set->bitmap, + partition_handler_share->rnd_write_bitmap, + (table_share->fields + 7) / 8); + DBUG_PRINT("info",("spider copy rnd_bitmap")); + } + } + } + DBUG_VOID_RETURN; +} +#endif + +bool ha_spider::check_and_start_bulk_update( + spider_bulk_upd_start bulk_upd_start +) { + DBUG_ENTER("ha_spider::check_and_start_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider bulk_update_start=%d", + result_list.bulk_update_start)); + if ( + result_list.bulk_update_start == SPD_BU_NOT_START || + ( + !result_list.bulk_update_mode && + bulk_upd_start == SPD_BU_START_BY_BULK_INIT + ) + ) { + THD *thd = ha_thd(); + int bulk_update_mode = spider_param_bulk_update_mode(thd, + share->bulk_update_mode); + longlong split_read = spider_split_read_param(this); + result_list.bulk_update_size = spider_param_bulk_update_size(thd, + share->bulk_update_size); +#ifndef WITHOUT_SPIDER_BG_SEARCH + int bgs_mode = spider_param_bgs_mode(thd, share->bgs_mode); +#endif + if (!support_bulk_update_sql()) + { + result_list.bulk_update_mode = 0; + } else if ( +#ifndef WITHOUT_SPIDER_BG_SEARCH + bgs_mode || +#endif + split_read != 9223372036854775807LL + ) + result_list.bulk_update_mode = 2; + else { + if (result_list.bulk_update_start == SPD_BU_NOT_START) + result_list.bulk_update_mode = bulk_update_mode; + else + result_list.bulk_update_mode = 1; + } + result_list.bulk_update_start = bulk_upd_start; + DBUG_RETURN(FALSE); + } + DBUG_RETURN(TRUE); +} + +int ha_spider::check_and_end_bulk_update( + spider_bulk_upd_start bulk_upd_start +) { + int error_num = 0; + uint dup_key_found = 0; + DBUG_ENTER("ha_spider::check_and_end_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider bulk_update_start=%d", + result_list.bulk_update_start)); + DBUG_PRINT("info",("spider bulk_update_mode=%d", + result_list.bulk_update_mode)); + if (result_list.bulk_update_start == bulk_upd_start) + { + if (result_list.bulk_update_mode) + error_num = spider_db_bulk_update_end(this, &dup_key_found); + result_list.bulk_update_size = 0; + result_list.bulk_update_mode = 0; + result_list.bulk_update_start = SPD_BU_NOT_START; + } + DBUG_RETURN(error_num); +} + +uint ha_spider::check_partitioned() +{ + uint part_num; + DBUG_ENTER("ha_spider::check_partitioned"); + DBUG_PRINT("info",("spider this=%p", this)); + table->file->get_no_parts("", &part_num); + if (part_num) + DBUG_RETURN(part_num); + + TABLE_LIST *tmp_table_list = table->pos_in_table_list; + while ((tmp_table_list = tmp_table_list->parent_l)) + { + tmp_table_list->table->file->get_no_parts("", &part_num); + if (part_num) + DBUG_RETURN(part_num); + } + DBUG_RETURN(0); +} + +void ha_spider::check_direct_order_limit() +{ + int roop_count; + DBUG_ENTER("ha_spider::check_direct_order_limit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!result_list.check_direct_order_limit) + { + if (spider_check_direct_order_limit(this)) + { + result_list.direct_order_limit = TRUE; + sql_kinds = SPIDER_SQL_KIND_SQL; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + sql_kind[roop_count] = SPIDER_SQL_KIND_SQL; + } else + result_list.direct_order_limit = FALSE; + result_list.check_direct_order_limit = TRUE; + } + DBUG_VOID_RETURN; +} + +int ha_spider::drop_tmp_tables() +{ + int error_num = 0, tmp_error_num, need_mon; + DBUG_ENTER("ha_spider::drop_tmp_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if (result_list.tmp_tables_created) + { + int roop_start, roop_end, roop_count, tmp_lock_mode; + tmp_lock_mode = spider_conn_lock_mode(this); + if (tmp_lock_mode) + { + /* "for update" or "lock in share mode" */ + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if (spider_bit_is_set(result_list.tmp_table_created, roop_count)) + { + uint dbton_id = share->use_sql_dbton_ids[roop_count]; + spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; + SPIDER_CONN *conn = conns[roop_count]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((tmp_error_num = spider_db_set_names(this, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + tmp_error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + error_num = tmp_error_num; + } + if (!tmp_error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + tmp_error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + tmp_error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + error_num = tmp_error_num; + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + spider_clear_bit(result_list.tmp_table_created, roop_count); + } + } + result_list.tmp_tables_created = FALSE; + } + DBUG_RETURN(error_num); +} + +bool ha_spider::handler_opened( + int link_idx, + uint tgt_conn_kind +) { + DBUG_ENTER("ha_spider::handler_opened"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + DBUG_PRINT("info",("spider tgt_conn_kind=%u", tgt_conn_kind)); + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ( + tgt_conn_kind == SPIDER_CONN_KIND_MYSQL && +#endif + spider_bit_is_set(m_handler_opened, link_idx) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + ( + tgt_conn_kind == SPIDER_CONN_KIND_HS_READ && + spider_bit_is_set(r_handler_opened, link_idx) + ) || + ( + tgt_conn_kind == SPIDER_CONN_KIND_HS_WRITE && + spider_bit_is_set(w_handler_opened, link_idx) + ) +#endif + ) { + DBUG_PRINT("info",("spider TRUE")); + DBUG_RETURN(TRUE); + } + DBUG_PRINT("info",("spider FALSE")); + DBUG_RETURN(FALSE); +} + +void ha_spider::set_handler_opened( + int link_idx +) { + DBUG_ENTER("ha_spider::set_handler_opened"); + DBUG_PRINT("info",("spider this=%p", this)); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) +#endif + spider_set_bit(m_handler_opened, link_idx); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else if (conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) + spider_set_bit(r_handler_opened, link_idx); + else + spider_set_bit(w_handler_opened, link_idx); +#endif + DBUG_VOID_RETURN; +} + +void ha_spider::clear_handler_opened( + int link_idx, + uint tgt_conn_kind +) { + DBUG_ENTER("ha_spider::clear_handler_opened"); + DBUG_PRINT("info",("spider this=%p", this)); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (tgt_conn_kind == SPIDER_CONN_KIND_MYSQL) +#endif + spider_clear_bit(m_handler_opened, link_idx); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else if (tgt_conn_kind == SPIDER_CONN_KIND_HS_READ) + spider_clear_bit(r_handler_opened, link_idx); + else + spider_clear_bit(w_handler_opened, link_idx); +#endif + DBUG_VOID_RETURN; +} + +int ha_spider::close_opened_handler( + int link_idx, + bool release_conn +) { + int error_num = 0, error_num2; + DBUG_ENTER("ha_spider::close_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + + if (spider_bit_is_set(m_handler_opened, link_idx)) + { + if ((error_num2 = spider_db_close_handler(this, + conns[link_idx], link_idx, SPIDER_CONN_KIND_MYSQL)) + ) { + if ( + share->monitoring_kind[link_idx] && + need_mons[link_idx] + ) { + error_num2 = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + error_num = error_num2; + } + spider_clear_bit(m_handler_opened, link_idx); + if (release_conn) + { + spider_free_conn_from_trx(trx, conns[link_idx], FALSE, FALSE, NULL); + conns[link_idx] = NULL; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider_bit_is_set(r_handler_opened, link_idx)) + { + if ((error_num2 = spider_db_close_handler(this, + hs_r_conns[link_idx], link_idx, SPIDER_CONN_KIND_HS_READ)) + ) { + if ( + share->monitoring_kind[link_idx] && + need_mons[link_idx] + ) { + error_num2 = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + error_num = error_num2; + } + spider_clear_bit(r_handler_opened, link_idx); + if (release_conn) + { + if ( + !hs_r_conns[link_idx]->opened_handlers && + trx->trx_hs_r_conn_adjustment == trx_hs_r_conn_adjustment && + spider_param_hs_r_conn_recycle_mode(trx->thd) != 2 + ) { + trx->trx_hs_r_conn_adjustment++; + } + spider_free_conn_from_trx(trx, hs_r_conns[link_idx], FALSE, FALSE, NULL); + hs_r_conns[link_idx] = NULL; + } + } + if (spider_bit_is_set(w_handler_opened, link_idx)) + { + if ((error_num2 = spider_db_close_handler(this, + hs_w_conns[link_idx], link_idx, SPIDER_CONN_KIND_HS_WRITE)) + ) { + if ( + share->monitoring_kind[link_idx] && + need_mons[link_idx] + ) { + error_num2 = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + error_num = error_num2; + } + spider_clear_bit(w_handler_opened, link_idx); + if (release_conn) + { + if ( + !hs_w_conns[link_idx]->opened_handlers && + trx->trx_hs_w_conn_adjustment == trx_hs_w_conn_adjustment && + spider_param_hs_w_conn_recycle_mode(trx->thd) != 2 + ) { + trx->trx_hs_w_conn_adjustment++; + } + spider_free_conn_from_trx(trx, hs_w_conns[link_idx], FALSE, FALSE, NULL); + hs_w_conns[link_idx] = NULL; + } + } +#endif + DBUG_RETURN(error_num); +} + +int ha_spider::index_handler_init() +{ + int lock_mode, error_num; + int roop_start, roop_end, roop_count; + DBUG_ENTER("ha_spider::index_handler_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!init_index_handler) + { + init_index_handler = TRUE; + lock_mode = spider_conn_lock_mode(this); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + sql_kinds = 0; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + direct_update_kinds = 0; +#endif + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ( + spider_conn_use_handler(this, lock_mode, roop_count) && + spider_conn_need_open_handler(this, active_index, roop_count) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint tmp_conn_kind1; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + do_direct_update && + spider_bit_is_set(do_hs_direct_update, roop_count) + ) { + tmp_conn_kind1 = SPIDER_CONN_KIND_HS_WRITE; + } else { +#endif + tmp_conn_kind1 = conn_kind[roop_count]; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + } +#endif +#endif + if ((error_num = spider_db_open_handler(this, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (tmp_conn_kind1 == SPIDER_CONN_KIND_MYSQL ? +#endif + conns[roop_count] +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + : tmp_conn_kind1 == SPIDER_CONN_KIND_HS_READ ? + hs_r_conns[roop_count] : hs_w_conns[roop_count] + ) +#endif + , roop_count)) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + uint tmp_conn_kind2 = conn_kind[roop_count]; + conn_kind[roop_count] = tmp_conn_kind1; +#endif +#endif + set_handler_opened(roop_count); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + conn_kind[roop_count] = tmp_conn_kind2; +#endif +#endif + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + DBUG_PRINT("info",("spider SPIDER_SQL_KIND_HANDLER")); + result_list.semi_split_read = 1; + result_list.semi_split_read_limit = 9223372036854775807LL; + if (select_limit == 9223372036854775807LL) + { + DBUG_PRINT("info",("spider set limit to 1")); + result_list.semi_split_read_base = 1; + result_list.split_read = 1; + } else { + DBUG_PRINT("info",("spider set limit to %lld", select_limit)); + result_list.semi_split_read_base = select_limit; + result_list.split_read = select_limit; + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::rnd_handler_init() +{ + int error_num, lock_mode; + int roop_start, roop_end, roop_count; + DBUG_ENTER("ha_spider::rnd_handler_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!init_rnd_handler) + { + init_rnd_handler = TRUE; + lock_mode = spider_conn_lock_mode(this); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + roop_start = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = share->link_count; + } else { + roop_start = search_link_idx; + roop_end = search_link_idx + 1; + } + sql_kinds = 0; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + direct_update_kinds = 0; +#endif + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ( + spider_conn_use_handler(this, lock_mode, roop_count) && + spider_conn_need_open_handler(this, MAX_KEY, roop_count) + ) { + if ((error_num = spider_db_open_handler(this, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL ? +#endif + conns[roop_count] +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + : conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ ? + hs_r_conns[roop_count] : hs_w_conns[roop_count] + ) +#endif + , roop_count)) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + set_handler_opened(roop_count); + } + } + if (sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + DBUG_PRINT("info",("spider SPIDER_SQL_KIND_HANDLER")); + result_list.semi_split_read = 1; + result_list.semi_split_read_limit = 9223372036854775807LL; + if (select_limit == 9223372036854775807LL) + { + DBUG_PRINT("info",("spider set limit to 1")); + result_list.semi_split_read_base = 1; + result_list.split_read = 1; + } else { + DBUG_PRINT("info",("spider set limit to %lld", select_limit)); + result_list.semi_split_read_base = select_limit; + result_list.split_read = select_limit; + } + } + } + DBUG_RETURN(0); +} + +void ha_spider::set_error_mode() +{ + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::set_error_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (thd_sql_command(thd)) + { + case SQLCOM_SELECT: + case SQLCOM_SHOW_DATABASES: + case SQLCOM_SHOW_TABLES: + case SQLCOM_SHOW_FIELDS: + case SQLCOM_SHOW_KEYS: + case SQLCOM_SHOW_VARIABLES: + case SQLCOM_SHOW_STATUS: + case SQLCOM_SHOW_ENGINE_LOGS: + case SQLCOM_SHOW_ENGINE_STATUS: + case SQLCOM_SHOW_ENGINE_MUTEX: + case SQLCOM_SHOW_PROCESSLIST: + case SQLCOM_SHOW_MASTER_STAT: + case SQLCOM_SHOW_SLAVE_STAT: + case SQLCOM_SHOW_GRANTS: + case SQLCOM_SHOW_CREATE: + case SQLCOM_SHOW_CHARSETS: + case SQLCOM_SHOW_COLLATIONS: + case SQLCOM_SHOW_CREATE_DB: + case SQLCOM_SHOW_TABLE_STATUS: + case SQLCOM_SHOW_TRIGGERS: + case SQLCOM_CHANGE_DB: + case SQLCOM_HA_OPEN: + case SQLCOM_HA_CLOSE: + case SQLCOM_HA_READ: + case SQLCOM_SHOW_SLAVE_HOSTS: + case SQLCOM_SHOW_BINLOG_EVENTS: + case SQLCOM_SHOW_WARNS: + case SQLCOM_EMPTY_QUERY: + case SQLCOM_SHOW_ERRORS: + case SQLCOM_SHOW_STORAGE_ENGINES: + case SQLCOM_SHOW_PRIVILEGES: + case SQLCOM_HELP: + case SQLCOM_SHOW_CREATE_PROC: + case SQLCOM_SHOW_CREATE_FUNC: + case SQLCOM_SHOW_STATUS_PROC: + case SQLCOM_SHOW_STATUS_FUNC: + case SQLCOM_SHOW_PROC_CODE: + case SQLCOM_SHOW_FUNC_CODE: + case SQLCOM_SHOW_AUTHORS: + case SQLCOM_SHOW_PLUGINS: + case SQLCOM_SHOW_CONTRIBUTORS: + case SQLCOM_SHOW_CREATE_EVENT: + case SQLCOM_SHOW_EVENTS: + case SQLCOM_SHOW_CREATE_TRIGGER: + case SQLCOM_SHOW_PROFILE: + case SQLCOM_SHOW_PROFILES: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + case SQLCOM_HS_READ: +#endif + error_mode = spider_param_error_read_mode(thd, share->error_read_mode); + DBUG_PRINT("info",("spider read error_mode=%d", error_mode)); + break; + default: + error_mode = spider_param_error_write_mode(thd, share->error_write_mode); + DBUG_PRINT("info",("spider write error_mode=%d", error_mode)); + break; + } + DBUG_VOID_RETURN; +} + +void ha_spider::backup_error_status() +{ + THD *thd = ha_thd(); + DBUG_ENTER("ha_spider::backup_error_status"); + if (thd) + da_status = thd->is_error(); + DBUG_VOID_RETURN; +} + +int ha_spider::check_error_mode( + int error_num +) { + THD *thd = ha_thd(); + DBUG_ENTER("ha_spider::check_error_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + if (!thd || !error_mode) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider error reset")); + SPIDER_RESTORE_DASTATUS; + DBUG_RETURN(0); +} + +int ha_spider::check_error_mode_eof( + int error_num +) { + DBUG_ENTER("ha_spider::check_error_mode_eof"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + if (error_num == HA_ERR_END_OF_FILE) + DBUG_RETURN(HA_ERR_END_OF_FILE); + if (check_error_mode(error_num)) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider result_list.finish_flg = TRUE")); + result_list.finish_flg = TRUE; + if (result_list.current) + { + DBUG_PRINT("info",("spider result_list.current->finish_flg = TRUE")); + result_list.current->finish_flg = TRUE; + } + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); +} + +void ha_spider::check_pre_call( + bool use_parallel +) { + DBUG_ENTER("ha_spider::check_pre_call"); + DBUG_PRINT("info",("spider this=%p", this)); + use_pre_call = use_parallel; + if (!use_pre_call) + { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + if ( + select_lex && + (!select_lex->explicit_limit || !select_limit) + ) { + use_pre_call = TRUE; + } + } + DBUG_VOID_RETURN; +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +void ha_spider::check_insert_dup_update_pushdown() +{ + THD *thd = trx->thd; + DBUG_ENTER("ha_spider::check_insert_dup_update_pushdown"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!spider_param_direct_dup_insert(thd, share->direct_dup_insert)) + { + DBUG_PRINT("info",("spider FALSE by direct_dup_insert")); + DBUG_VOID_RETURN; + } + direct_update_fields = &thd->lex->update_list; + direct_update_values = &thd->lex->value_list; + if (!append_dup_update_pushdown_sql_part(NULL, 0)) + { + result_list.insert_dup_update_pushdown = TRUE; + } + DBUG_VOID_RETURN; +} +#endif + +#ifdef HA_CAN_BULK_ACCESS +SPIDER_BULK_ACCESS_LINK *ha_spider::create_bulk_access_link() +{ + uchar *ref; + ha_spider *spider; + SPIDER_BULK_ACCESS_LINK *bulk_access_link; + DBUG_ENTER("ha_spider::create_bulk_access_link"); + DBUG_PRINT("info",("spider this=%p", this)); +/* + if (!init_ha_mem_root) + { + SPD_INIT_ALLOC_ROOT(&ha_mem_root, sizeof(ha_spider) * 16, + sizeof(ha_spider) * 16, MYF(MY_WME)); + init_ha_mem_root = TRUE; + } +*/ + if (!(bulk_access_link = (SPIDER_BULK_ACCESS_LINK *) + spider_bulk_malloc(spider_current_trx, 168, MYF(MY_WME), + &bulk_access_link, sizeof(SPIDER_BULK_ACCESS_LINK), + &ref, ALIGN_SIZE(ref_length) * 2, + NullS)) + ) { + goto error_bulk_malloc; + } + SPD_INIT_ALLOC_ROOT(&bulk_access_link->mem_root, sizeof(ha_spider), 0, + MYF(MY_WME)); +/* + if (!(spider = new ha_spider(spider_hton_ptr, table_share))) + if (!(spider = (ha_spider *) spider_create_handler( + spider_hton_ptr, table_share, &ha_mem_root))) +*/ + if (!(spider = (ha_spider *) spider_create_handler( + spider_hton_ptr, table_share, &bulk_access_link->mem_root))) + { + goto error_new_spider; + } + DBUG_PRINT("info",("spider spider=%p", spider)); + bulk_access_link->spider = spider; + spider->ref = ref; + bulk_access_link->next = NULL; + spider->is_clone = TRUE; + spider->is_bulk_access_clone = TRUE; + spider->pt_clone_source_handler = this; + if (spider->ha_open(table, share->table_name, table->db_stat, + HA_OPEN_IGNORE_IF_LOCKED)) + { + goto error_ha_open; + } + DBUG_RETURN(bulk_access_link); + +error_ha_open: + delete spider; +error_new_spider: + free_root(&bulk_access_link->mem_root, MYF(0)); + spider_free(spider_current_trx, bulk_access_link, MYF(0)); +error_bulk_malloc: + DBUG_RETURN(NULL); +} + +void ha_spider::delete_bulk_access_link( + SPIDER_BULK_ACCESS_LINK *bulk_access_link +) { + ha_spider *spider = bulk_access_link->spider; + DBUG_ENTER("ha_spider::delete_bulk_access_link"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider spider=%p", spider)); + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + spider->dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &spider->dbton_handler)); + spider->close(); + delete spider; + free_root(&bulk_access_link->mem_root, MYF(0)); + spider_free(spider_current_trx, bulk_access_link, MYF(0)); + DBUG_VOID_RETURN; +} + +int ha_spider::sync_from_clone_source( + ha_spider *spider +) { + int error_num; + DBUG_ENTER("ha_spider::sync_from_clone_source"); + sync_from_clone_source_base(spider); + if (!synced_from_clone_source) + { + DBUG_PRINT("info",("spider synced from clone source all")); + trx = spider->trx; + sql_command = spider->sql_command; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = spider->do_direct_update; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + memcpy(do_hs_direct_update, spider->do_hs_direct_update, + share->link_bitmap_size); +#endif +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + conn_kinds = spider->conn_kinds; + memcpy(conn_kind, spider->conn_kind, sizeof(uint) * share->link_count); +#endif + result_list.lock_type = spider->result_list.lock_type; + lock_type = spider->lock_type; + selupd_lock_mode = spider->selupd_lock_mode; + update_request = spider->update_request; + lock_mode = spider->lock_mode; + high_priority = spider->high_priority; + insert_delayed = spider->insert_delayed; + low_priority = spider->low_priority; + memcpy(conns, spider->conns, + sizeof(SPIDER_CONN *) * share->link_count); + memcpy(hs_r_conns, spider->hs_r_conns, + sizeof(SPIDER_CONN *) * share->link_count); + memcpy(hs_w_conns, spider->hs_w_conns, + sizeof(SPIDER_CONN *) * share->link_count); + spider_thread_id = spider->spider_thread_id; + trx_conn_adjustment = spider->trx_conn_adjustment; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + trx_hs_r_conn_adjustment = spider->trx_hs_r_conn_adjustment; + trx_hs_w_conn_adjustment = spider->trx_hs_w_conn_adjustment; +#endif + search_link_idx = spider->search_link_idx; + external_lock_cnt = spider->external_lock_cnt; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl, *dbton_hdl2; + for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++) + { + dbton_id = share->use_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + dbton_hdl2 = spider->dbton_handler[dbton_id]; + dbton_hdl->sync_from_clone_source(dbton_hdl2); + } + synced_from_clone_source = TRUE; + } else if (external_lock_cnt != spider->external_lock_cnt) + { + DBUG_PRINT("info",("spider synced from clone source")); + sql_command = spider->sql_command; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + do_direct_update = spider->do_direct_update; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + memcpy(do_hs_direct_update, spider->do_hs_direct_update, + share->link_bitmap_size); +#endif +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + conn_kinds = spider->conn_kinds; + memcpy(conn_kind, spider->conn_kind, sizeof(uint) * share->link_count); +#endif + result_list.lock_type = spider->result_list.lock_type; + lock_type = spider->lock_type; + selupd_lock_mode = spider->selupd_lock_mode; + update_request = spider->update_request; + lock_mode = spider->lock_mode; + high_priority = spider->high_priority; + insert_delayed = spider->insert_delayed; + low_priority = spider->low_priority; + + if ((error_num = spider_check_trx_and_get_conn(spider->trx->thd, + this, TRUE))) + { + DBUG_RETURN(error_num); + } + external_lock_cnt = spider->external_lock_cnt; + } + + if (spider->hs_pushed_ret_fields_num < MAX_FIELDS) + { + SPIDER_HS_UINT32_INFO tmp_info; + tmp_info.info_size = spider->hs_pushed_ret_fields_num; + tmp_info.info = spider->hs_pushed_ret_fields; + if ((error_num = info_push(INFO_KIND_HS_RET_FIELDS, &tmp_info))) + { + DBUG_RETURN(error_num); + } + } + DBUG_PRINT("info",("spider bulk_access_link->spider->dbton_handler=%p", + dbton_handler)); + DBUG_PRINT("info",("spider ptr bulk_access_link->spider->dbton_handler=%p", + &dbton_handler)); + DBUG_RETURN(0); +} +#endif + +void ha_spider::sync_from_clone_source_base( + ha_spider *spider +) { + uint roop_count2, dbton_id; + spider_db_handler *dbton_hdl, *dbton_hdl2; + DBUG_ENTER("ha_spider::sync_from_clone_source_base"); + for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++) + { + dbton_id = share->use_dbton_ids[roop_count2]; + dbton_hdl = dbton_handler[dbton_id]; + dbton_hdl2 = spider->dbton_handler[dbton_id]; + dbton_hdl->first_link_idx = dbton_hdl2->first_link_idx; + } + DBUG_VOID_RETURN; +} + +void ha_spider::set_first_link_idx() +{ + int roop_count, all_link_idx; + uint roop_count2, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_first_link_idx"); + for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++) + { + dbton_id = share->use_dbton_ids[roop_count2]; + dbton_hdl = dbton_handler[dbton_id]; + dbton_hdl->first_link_idx = -1; + } + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + all_link_idx = conn_link_idx[roop_count]; + dbton_id = share->sql_dbton_ids[all_link_idx]; + if (dbton_id < SPIDER_DBTON_SIZE) + { + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx == -1) + { + dbton_hdl->first_link_idx = roop_count; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + dbton_id = share->hs_dbton_ids[all_link_idx]; + if (dbton_id < SPIDER_DBTON_SIZE) + { + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx == -1) + { + dbton_hdl->first_link_idx = roop_count; + } + } +#endif + } + DBUG_VOID_RETURN; +} + +void ha_spider::reset_first_link_idx() +{ + int all_link_idx; + uint roop_count2, dbton_id; + spider_db_handler *dbton_hdl; + int lock_mode = spider_conn_lock_mode(this); + DBUG_ENTER("ha_spider::reset_first_link_idx"); + if (!lock_mode) + { + DBUG_PRINT("info",("spider use only search_link_idx")); + for (roop_count2 = 0; roop_count2 < share->use_dbton_count; roop_count2++) + { + dbton_id = share->use_dbton_ids[roop_count2]; + dbton_hdl = dbton_handler[dbton_id]; + dbton_hdl->first_link_idx = -1; + } + all_link_idx = conn_link_idx[search_link_idx]; + dbton_id = share->sql_dbton_ids[all_link_idx]; + if (dbton_id < SPIDER_DBTON_SIZE) + { + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx == -1) + { + dbton_hdl->first_link_idx = search_link_idx; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + dbton_id = share->hs_dbton_ids[all_link_idx]; + if (dbton_id < SPIDER_DBTON_SIZE) + { + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx == -1) + { + dbton_hdl->first_link_idx = search_link_idx; + } + } +#endif + } + DBUG_VOID_RETURN; +} + +int ha_spider::reset_sql_sql( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_sql_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_sql(sql_type))) + { + DBUG_RETURN(error_num); + } + } + + if (sql_type & SPIDER_SQL_TYPE_BULK_UPDATE_SQL) + { + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + result_list.update_sqls[roop_count].length(0); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::reset_hs_sql( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_hs_sql"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_sql(sql_type))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reset_hs_keys( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_hs_keys"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_keys(sql_type))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reset_hs_upds( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_hs_upds"); + for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++) + { + dbton_id = share->use_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_upds(sql_type))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reset_hs_strs( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_hs_strs"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_strs(sql_type))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reset_hs_strs_pos( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::reset_hs_strs_pos"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->reset_strs_pos(sql_type))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::push_back_hs_upds( + SPIDER_HS_STRING_REF &info +) { + int error_num; + uint roop_count, dbton_id; + DBUG_ENTER("ha_spider::push_back_hs_upds"); + for (roop_count = 0; roop_count < share->use_dbton_count; roop_count++) + { + dbton_id = share->use_dbton_ids[roop_count]; + if ((error_num = dbton_handler[dbton_id]->push_back_upds(info))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + +int ha_spider::append_tmp_table_and_sql_for_bka( + const key_range *start_key +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_tmp_table_and_sql_for_bka"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_tmp_table_and_sql_for_bka(start_key)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reuse_tmp_table_and_sql_for_bka() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::reuse_tmp_table_and_sql_for_bka"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->reuse_tmp_table_and_sql_for_bka()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_insert_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_insert_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_insert_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_update_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_update_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_update_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int ha_spider::append_increment_update_set_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_increment_update_set_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_increment_update_set_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif +#endif + +int ha_spider::append_update_set_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_update_set_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_update_set_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int ha_spider::append_direct_update_set_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_direct_update_set_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_direct_update_set_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::append_direct_update_set_hs_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_direct_update_set_hs_part"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_direct_update_set_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif +#endif + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::append_dup_update_pushdown_sql_part( + const char *alias, + uint alias_length +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_dup_update_pushdown_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_dup_update_pushdown_part( + alias, alias_length)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_update_columns_sql_part( + const char *alias, + uint alias_length +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_update_columns_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_update_columns_part( + alias, alias_length)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::check_update_columns_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::check_update_columns_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->check_update_columns_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + +int ha_spider::append_delete_sql_part() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_delete_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_delete_part()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_select_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_select_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_select_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_table_select_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_table_select_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_table_select_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_key_select_sql_part( + ulong sql_type, + uint idx +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_select_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_key_select_part(sql_type, idx)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_minimum_select_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_minimum_select_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_minimum_select_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_from_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_from_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_from_part(sql_type, + dbton_hdl->first_link_idx)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_hint_after_table_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_hint_after_table_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_hint_after_table_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +void ha_spider::set_where_pos_sql( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_where_pos_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->set_where_pos(sql_type); + } + DBUG_VOID_RETURN; +} + +void ha_spider::set_where_to_pos_sql( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_where_to_pos_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->set_where_to_pos(sql_type); + } + DBUG_VOID_RETURN; +} + +int ha_spider::check_item_type_sql( + Item *item +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::check_item_type_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->check_item_type(item)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_values_connector_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_values_connector_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = + dbton_hdl->append_values_connector_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_values_terminator_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_values_terminator_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = + dbton_hdl->append_values_terminator_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_key_column_values_sql_part( + const key_range *start_key, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_column_values_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = + dbton_hdl->append_key_column_values_part(start_key, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_key_where_sql_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_where_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_key_where_part(start_key, end_key, + sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::append_key_where_hs_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_where_hs_part"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_key_where_part(start_key, end_key, + sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + +int ha_spider::append_match_where_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_match_where_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_match_where_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_condition_sql_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_condition_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_condition_part(alias, alias_length, + sql_type, test_flg)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_match_select_sql_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_match_select_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_match_select_part(sql_type, + alias, alias_length)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +void ha_spider::set_order_pos_sql( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_order_pos_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->set_order_pos(sql_type); + } + DBUG_VOID_RETURN; +} + +void ha_spider::set_order_to_pos_sql( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_order_to_pos_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->set_order_to_pos(sql_type); + } + DBUG_VOID_RETURN; +} + +int ha_spider::append_key_order_for_merge_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_order_for_merge_with_alias_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_key_order_for_merge_with_alias_part( + alias, alias_length, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_key_order_for_direct_order_limit_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_order_for_direct_order_limit_with_alias_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = + dbton_hdl->append_key_order_for_direct_order_limit_with_alias_part( + alias, alias_length, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_key_order_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_key_order_with_alias_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_key_order_with_alias_part( + alias, alias_length, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_limit_sql_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_limit_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_limit_part(offset, limit, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::append_limit_hs_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_limit_hs_part"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_limit_part(offset, limit, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + +int ha_spider::reappend_limit_sql_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::reappend_limit_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->reappend_limit_part(offset, limit, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_insert_terminator_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_insert_terminator_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_insert_terminator_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_insert_values_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_insert_values_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_insert_values_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int ha_spider::append_insert_values_hs_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_insert_values_hs_part"); + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_insert_values_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + +int ha_spider::append_into_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_into_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_into_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +void ha_spider::set_insert_to_pos_sql( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_insert_to_pos_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->set_insert_to_pos(sql_type); + } + DBUG_VOID_RETURN; +} + +bool ha_spider::is_bulk_insert_exec_period( + bool bulk_end +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::is_bulk_insert_exec_period"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kinds & SPIDER_SQL_KIND_SQL) + { +#endif + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->is_bulk_insert_exec_period(bulk_end) + ) { + DBUG_RETURN(TRUE); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (sql_kinds & SPIDER_SQL_KIND_HS) + { + for (roop_count = 0; roop_count < share->use_hs_dbton_count; roop_count++) + { + dbton_id = share->use_hs_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->is_bulk_insert_exec_period(bulk_end) + ) { + DBUG_RETURN(TRUE); + } + } + } +#endif + DBUG_RETURN(FALSE); +} + +int ha_spider::append_select_lock_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_select_lock_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_select_lock_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_union_all_start_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_union_all_start_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_union_all_start_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_union_all_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_union_all_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_union_all_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_union_all_end_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_union_all_end_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_union_all_end_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_multi_range_cnt_sql_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_multi_range_cnt_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_multi_range_cnt_part( + sql_type, multi_range_cnt, with_comma)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_delete_all_rows_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_delete_all_rows_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_delete_all_rows_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_update_sql( + const TABLE *table, + my_ptrdiff_t ptr_diff, + bool bulk +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_update"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_update(table, ptr_diff)) + ) { + DBUG_RETURN(error_num); + } + } + if (!bulk) + { + DBUG_RETURN(0); + } + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->need_copy_for_update(roop_count) + ) { + if ((error_num = dbton_hdl->append_update(table, ptr_diff, roop_count))) + { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_delete_sql( + const TABLE *table, + my_ptrdiff_t ptr_diff, + bool bulk +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_delete"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_delete(table, ptr_diff)) + ) { + DBUG_RETURN(error_num); + } + } + if (!bulk) + { + DBUG_RETURN(0); + } + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, -1, share->link_count, SPIDER_LINK_STATUS_RECOVERY); + roop_count < share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->need_copy_for_update(roop_count) + ) { + if ((error_num = dbton_hdl->append_delete(table, ptr_diff, roop_count))) + { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +bool ha_spider::sql_is_filled_up( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::sql_is_filled_up"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->sql_is_filled_up(sql_type) + ) { + DBUG_RETURN(TRUE); + } + } + DBUG_RETURN(FALSE); +} + +bool ha_spider::sql_is_empty( + ulong sql_type +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::sql_is_empty"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + !dbton_hdl->sql_is_empty(sql_type) + ) { + DBUG_RETURN(FALSE); + } + } + DBUG_RETURN(TRUE); +} + +bool ha_spider::support_multi_split_read_sql() +{ + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::support_multi_split_read_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + !dbton_hdl->support_multi_split_read() + ) { + DBUG_RETURN(FALSE); + } + } + DBUG_RETURN(TRUE); +} + +bool ha_spider::support_bulk_update_sql() +{ + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::support_bulk_update_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + !dbton_hdl->support_bulk_update() + ) { + DBUG_RETURN(FALSE); + } + } + DBUG_RETURN(TRUE); +} + +int ha_spider::bulk_tmp_table_insert() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::bulk_tmp_table_insert"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->bulk_tmp_table_insert()) + ) { + DBUG_RETURN(error_num); + } + } + + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + if (tmp_table[roop_count]) + { + dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->bulk_tmp_table_insert(roop_count)) + ) { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::bulk_tmp_table_end_bulk_insert() +{ + int error_num = 0, error_num2; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::bulk_tmp_table_end_bulk_insert"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num2 = dbton_hdl->bulk_tmp_table_end_bulk_insert()) + ) { + error_num = error_num2; + } + } + + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + if (tmp_table[roop_count]) + { + if ( + (error_num2 = tmp_table[roop_count]->file->ha_end_bulk_insert()) + ) { + error_num = error_num2; + } + } + } + DBUG_RETURN(error_num); +} + +int ha_spider::bulk_tmp_table_rnd_init() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_init"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->bulk_tmp_table_rnd_init()) + ) { + goto error_1; + } + } + + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + if (tmp_table[roop_count]) + { + tmp_table[roop_count]->file->extra(HA_EXTRA_CACHE); + if ( + (error_num = tmp_table[roop_count]->file->ha_rnd_init(TRUE)) + ) + goto error_2; + } + } + DBUG_RETURN(0); + +error_2: + for (; roop_count > 0; roop_count--) + { + if (tmp_table[roop_count - 1]) + { + tmp_table[roop_count - 1]->file->ha_rnd_end(); + } + } + roop_count = share->use_sql_dbton_count; +error_1: + for (; roop_count > 0; roop_count--) + { + dbton_id = share->use_sql_dbton_ids[roop_count - 1]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->bulk_tmp_table_rnd_end(); + } + DBUG_RETURN(error_num); +} + +int ha_spider::bulk_tmp_table_rnd_next() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_next"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->bulk_tmp_table_rnd_next()) + ) { + DBUG_RETURN(error_num); + } + } + + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + if (tmp_table[roop_count]) + { + if ( +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + !(error_num = tmp_table[roop_count]->file->ha_rnd_next( + tmp_table[roop_count]->record[0])) +#else + !(error_num = tmp_table[roop_count]->file->rnd_next( + tmp_table[roop_count]->record[0])) +#endif + ) { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::bulk_tmp_table_rnd_end() +{ + int error_num = 0, error_num2; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_end"); + for (roop_count = share->link_count; roop_count > 0; roop_count--) + { + if (tmp_table[roop_count - 1]) + { + if ((error_num2 = tmp_table[roop_count - 1]->file->ha_rnd_end())) + { + error_num = error_num2; + } + } + } + + for (roop_count = share->use_sql_dbton_count; roop_count > 0; roop_count--) + { + dbton_id = share->use_sql_dbton_ids[roop_count - 1]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num2 = dbton_hdl->bulk_tmp_table_rnd_end()) + ) { + error_num = error_num2; + } + } + DBUG_RETURN(error_num); +} + +int ha_spider::mk_bulk_tmp_table_and_bulk_start() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + TABLE **tmp_table = result_list.upd_tmp_tbls; + DBUG_ENTER("ha_spider::mk_bulk_tmp_table_and_bulk_start"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + { + if (dbton_hdl->bulk_tmp_table_created()) + { + DBUG_RETURN(0); + } else { + break; + } + } + } + + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->mk_bulk_tmp_table_and_bulk_start()) + ) { + goto error_1; + } + } + + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + dbton_id = share->sql_dbton_ids[conn_link_idx[roop_count]]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + dbton_hdl->need_copy_for_update(roop_count) + ) { + if ( + !tmp_table[roop_count] && + !(tmp_table[roop_count] = spider_mk_sys_tmp_table( + trx->thd, table, &result_list.upd_tmp_tbl_prms[roop_count], "a", + result_list.update_sqls[roop_count].charset())) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_2; + } + tmp_table[roop_count]->file->extra(HA_EXTRA_WRITE_CACHE); + tmp_table[roop_count]->file->ha_start_bulk_insert((ha_rows) 0); + } + } + DBUG_RETURN(0); + +error_2: + for (; roop_count > 0; roop_count--) + { + if (tmp_table[roop_count - 1]) + { + tmp_table[roop_count - 1]->file->ha_end_bulk_insert(); + spider_rm_sys_tmp_table(trx->thd, tmp_table[roop_count - 1], + &result_list.upd_tmp_tbl_prms[roop_count - 1]); + tmp_table[roop_count - 1] = NULL; + } + } + roop_count = share->use_sql_dbton_count; +error_1: + for (; roop_count > 0; roop_count--) + { + dbton_id = share->use_sql_dbton_ids[roop_count - 1]; + if (dbton_hdl->first_link_idx >= 0) + { + dbton_handler[dbton_id]->bulk_tmp_table_end_bulk_insert(); + dbton_handler[dbton_id]->rm_bulk_tmp_table(); + } + } + DBUG_RETURN(error_num); +} + +void ha_spider::rm_bulk_tmp_table() +{ + uint roop_count, dbton_id; + TABLE **tmp_table = result_list.upd_tmp_tbls; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::bulk_tmp_table_rnd_end"); + for (roop_count = share->link_count; roop_count > 0; roop_count--) + { + if (tmp_table[roop_count - 1]) + { + spider_rm_sys_tmp_table(trx->thd, tmp_table[roop_count - 1], + &result_list.upd_tmp_tbl_prms[roop_count - 1]); + tmp_table[roop_count - 1] = NULL; + } + } + + for (roop_count = share->use_sql_dbton_count; roop_count > 0; roop_count--) + { + dbton_id = share->use_sql_dbton_ids[roop_count - 1]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + dbton_hdl->rm_bulk_tmp_table(); + } + DBUG_VOID_RETURN; +} + +bool ha_spider::bulk_tmp_table_created() +{ + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::bulk_tmp_table_created"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if (dbton_hdl->first_link_idx >= 0) + { + if (dbton_hdl->bulk_tmp_table_created()) + { + DBUG_RETURN(TRUE); + } + } + } + DBUG_RETURN(FALSE); +} + +int ha_spider::print_item_type( + Item *item, + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::print_item_type"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = spider_db_print_item_type(item, this, str, + alias, alias_length, dbton_id)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +bool ha_spider::support_use_handler_sql( + int use_handler +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::support_use_handler_sql"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + !dbton_hdl->support_use_handler(use_handler) + ) { + DBUG_RETURN(FALSE); + } + } + DBUG_RETURN(TRUE); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +bool ha_spider::support_bulk_access_hs() const +{ + uint roop_count; + DBUG_ENTER("ha_spider::support_bulk_access_hs"); + if (!share) + DBUG_RETURN(FALSE); + for (roop_count = 0; roop_count < share->all_link_count; roop_count++) + { + if (share->hs_dbton_ids[roop_count] == SPIDER_DBTON_SIZE) + DBUG_RETURN(FALSE); + } + DBUG_RETURN(TRUE); +} +#endif diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h new file mode 100644 index 00000000000..d2f479f8d90 --- /dev/null +++ b/storage/spider/ha_spider.h @@ -0,0 +1,1014 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#ifdef USE_PRAGMA_INTERFACE +#pragma interface +#endif + +#define SPIDER_CONNECT_INFO_MAX_LEN 64 +#define SPIDER_CONNECT_INFO_PATH_MAX_LEN FN_REFLEN +#define SPIDER_LONGLONG_LEN 20 +#define SPIDER_MAX_KEY_LENGTH 16384 + +#define SPIDER_SET_CONNS_PARAM(param_name, param_val, conns, link_statuses, conn_link_idx, link_count, link_status) \ + for ( \ + roop_count = spider_conn_link_idx_next(link_statuses, \ + conn_link_idx, -1, link_count, link_status); \ + roop_count < link_count; \ + roop_count = spider_conn_link_idx_next(link_statuses, \ + conn_link_idx, roop_count, link_count, link_status) \ + ) { \ + if (conns[roop_count]) \ + conns[roop_count]->param_name = param_val; \ + } + +class ha_spider; +struct st_spider_ft_info +{ + struct _ft_vft *please; + st_spider_ft_info *next; + ha_spider *file; + uint target; + bool used_in_where; + float score; + uint flags; + uint inx; + String *key; +}; + +class ha_spider: public handler +{ +public: + THR_LOCK_DATA lock; + SPIDER_SHARE *share; + SPIDER_TRX *trx; + ulonglong spider_thread_id; + ulonglong trx_conn_adjustment; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ulonglong trx_hs_r_conn_adjustment; + ulonglong trx_hs_w_conn_adjustment; +#endif + uint mem_calc_id; + const char *mem_calc_func_name; + const char *mem_calc_file_name; + ulong mem_calc_line_no; + uint sql_kinds; + uint *sql_kind; + ulonglong *connection_ids; + uint conn_kinds; + uint *conn_kind; + char *conn_keys_first_ptr; + char **conn_keys; + SPIDER_CONN **conns; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char **hs_r_conn_keys; + SPIDER_CONN **hs_r_conns; + ulonglong *hs_r_conn_ages; + char **hs_w_conn_keys; + SPIDER_CONN **hs_w_conns; + ulonglong *hs_w_conn_ages; +#endif + /* for active-standby mode */ + uint *conn_link_idx; + uchar *conn_can_fo; + void **quick_targets; + int *need_mons; + query_id_t search_link_query_id; + int search_link_idx; + int result_link_idx; + SPIDER_RESULT_LIST result_list; + SPIDER_CONDITION *condition; + spider_string *blob_buff; + uchar *searched_bitmap; + bool position_bitmap_init; + uchar *position_bitmap; + SPIDER_POSITION *pushed_pos; + SPIDER_POSITION pushed_pos_buf; +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share; + ha_spider *pt_handler_share_creator; +#endif +#ifdef HA_CAN_BULK_ACCESS + int pre_direct_init_result; + bool is_bulk_access_clone; + bool synced_from_clone_source; + bool bulk_access_started; + bool bulk_access_executing; + bool bulk_access_pre_called; + SPIDER_BULK_ACCESS_LINK *bulk_access_link_first; + SPIDER_BULK_ACCESS_LINK *bulk_access_link_current; + SPIDER_BULK_ACCESS_LINK *bulk_access_link_exec_tgt; +/* + bool init_ha_mem_root; + MEM_ROOT ha_mem_root; +*/ + ulonglong external_lock_cnt; +#endif + bool is_clone; + bool clone_bitmap_init; + ha_spider *pt_clone_source_handler; + ha_spider *pt_clone_last_searcher; + + bool init_index_handler; + bool init_rnd_handler; + + bool da_status; + bool use_spatial_index; + + /* for mrr */ + bool mrr_with_cnt; + uint multi_range_cnt; + uint multi_range_hit_point; +#ifdef HA_MRR_USE_DEFAULT_IMPL + int multi_range_num; + bool have_second_range; + KEY_MULTI_RANGE mrr_second_range; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + range_id_t *multi_range_keys; +#else + char **multi_range_keys; +#endif +#else + KEY_MULTI_RANGE *multi_range_ranges; +#endif + + char *append_tblnm_alias; + uint append_tblnm_alias_length; + + ha_spider *next; + + bool rnd_scan_and_first; + bool quick_mode; + bool keyread; + bool ignore_dup_key; + bool write_can_replace; + bool insert_with_update; + bool low_priority; + bool high_priority; + bool insert_delayed; + bool use_pre_call; + enum thr_lock_type lock_type; + int lock_mode; + uint sql_command; + int selupd_lock_mode; + bool bulk_insert; +#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC + bool info_auto_called; +#endif + int bulk_size; + int direct_dup_insert; + int store_error_num; + uint dup_key_idx; + int select_column_mode; + bool update_request; + bool pk_update; + bool force_auto_increment; + int bka_mode; + bool cond_check; + int cond_check_error; + int error_mode; + ulonglong store_last_insert_id; + + ulonglong *db_request_id; + uchar *db_request_phase; + uchar *m_handler_opened; + uint *m_handler_id; + char **m_handler_cid; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uchar *r_handler_opened; + uint *r_handler_id; + uint *r_handler_index; + uchar *w_handler_opened; + uint *w_handler_id; + uint *w_handler_index; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + uchar *do_hs_direct_update; + uint32 **hs_r_ret_fields; + uint32 **hs_w_ret_fields; + size_t *hs_r_ret_fields_num; + size_t *hs_w_ret_fields_num; + uint32 *hs_pushed_ret_fields; + size_t hs_pushed_ret_fields_num; + size_t hs_pushed_ret_fields_size; + size_t hs_pushed_lcl_fields_num; + uchar *tmp_column_bitmap; + bool hs_increment; + bool hs_decrement; + uint32 hs_pushed_strref_num; +#endif +#endif +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + bool do_direct_update; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + bool maybe_do_hs_direct_update; +#endif + uint direct_update_kinds; + List *direct_update_fields; + List *direct_update_values; +#endif +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + longlong info_limit; +#endif + + /* for fulltext search */ + bool ft_init_and_first; + uint ft_init_idx; + uint ft_count; + bool ft_init_without_index_init; + st_spider_ft_info *ft_first; + st_spider_ft_info *ft_current; + + /* for dbton */ + spider_db_handler **dbton_handler; + + ha_spider(); + ha_spider( + handlerton *hton, + TABLE_SHARE *table_arg + ); + virtual ~ha_spider(); + handler *clone( + const char *name, + MEM_ROOT *mem_root + ); + const char **bas_ext() const; + int open( + const char* name, + int mode, + uint test_if_locked + ); + int close(); + int check_access_kind( + THD *thd, + bool write_request + ); +#ifdef HA_CAN_BULK_ACCESS + int additional_lock( + THD *thd, + enum thr_lock_type lock_type + ); +#endif + THR_LOCK_DATA **store_lock( + THD *thd, + THR_LOCK_DATA **to, + enum thr_lock_type lock_type + ); + int external_lock( + THD *thd, + int lock_type + ); + int reset(); + int extra( + enum ha_extra_function operation + ); + int index_init( + uint idx, + bool sorted + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_index_init( + uint idx, + bool sorted + ); +#endif + int index_end(); +#ifdef HA_CAN_BULK_ACCESS + int pre_index_end(); +#endif + int index_read_map( + uchar *buf, + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag + ); + int index_read_last_map( + uchar *buf, + const uchar *key, + key_part_map keypart_map + ); + int index_next( + uchar *buf + ); + int index_prev( + uchar *buf + ); + int index_first( + uchar *buf + ); + int index_last( + uchar *buf + ); + int index_next_same( + uchar *buf, + const uchar *key, + uint keylen + ); + int read_range_first( + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted + ); + int read_range_next(); +#ifdef HA_MRR_USE_DEFAULT_IMPL +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + ha_rows multi_range_read_info_const( + uint keyno, + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint *bufsz, + uint *flags, + Cost_estimate *cost + ); + ha_rows multi_range_read_info( + uint keyno, + uint n_ranges, + uint keys, + uint key_parts, + uint *bufsz, + uint *flags, + Cost_estimate *cost + ); +#else + ha_rows multi_range_read_info_const( + uint keyno, + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint *bufsz, + uint *flags, + COST_VECT *cost + ); + ha_rows multi_range_read_info( + uint keyno, + uint n_ranges, + uint keys, + uint key_parts, + uint *bufsz, + uint *flags, + COST_VECT *cost + ); +#endif + int multi_range_read_init( + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint mode, + HANDLER_BUFFER *buf + ); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + int multi_range_read_next( + range_id_t *range_info + ); + int multi_range_read_next_first( + range_id_t *range_info + ); + int multi_range_read_next_next( + range_id_t *range_info + ); +#else + int multi_range_read_next( + char **range_info + ); + int multi_range_read_next_first( + char **range_info + ); + int multi_range_read_next_next( + char **range_info + ); +#endif +#else + int read_multi_range_first( + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer + ); + int read_multi_range_next( + KEY_MULTI_RANGE **found_range_p + ); +#endif + int rnd_init( + bool scan + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_rnd_init( + bool scan + ); +#endif + int rnd_end(); +#ifdef HA_CAN_BULK_ACCESS + int pre_rnd_end(); +#endif + int rnd_next( + uchar *buf + ); + void position( + const uchar *record + ); + int rnd_pos( + uchar *buf, + uchar *pos + ); + int cmp_ref( + const uchar *ref1, + const uchar *ref2 + ); + int ft_init(); + void ft_end(); + FT_INFO *ft_init_ext( + uint flags, + uint inx, + String *key + ); + int ft_read( + uchar *buf + ); + int pre_index_read_map( + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag, + bool use_parallel + ); + int pre_index_first(bool use_parallel); + int pre_index_last(bool use_parallel); + int pre_index_read_last_map( + const uchar *key, + key_part_map keypart_map, + bool use_parallel + ); +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + int pre_read_multi_range_first( + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer, + bool use_parallel + ); +#endif + int pre_read_range_first( + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted, + bool use_parallel + ); + int pre_ft_read(bool use_parallel); + int pre_rnd_next(bool use_parallel); + int info( + uint flag + ); + ha_rows records_in_range( + uint inx, + key_range *start_key, + key_range *end_key + ); + int check_crd(); + ha_rows records(); + const char *table_type() const; + ulonglong table_flags() const; + const char *index_type( + uint key_number + ); + ulong index_flags( + uint idx, + uint part, + bool all_parts + ) const; + uint max_supported_record_length() const; + uint max_supported_keys() const; + uint max_supported_key_parts() const; + uint max_supported_key_length() const; + uint max_supported_key_part_length() const; + uint8 table_cache_type(); +#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC + bool need_info_for_auto_inc(); +#endif + int update_auto_increment(); + void get_auto_increment( + ulonglong offset, + ulonglong increment, + ulonglong nb_desired_values, + ulonglong *first_value, + ulonglong *nb_reserved_values + ); + int reset_auto_increment( + ulonglong value + ); + void release_auto_increment(); + void start_bulk_insert( + ha_rows rows + ); + int end_bulk_insert(); + int write_row( + uchar *buf + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_write_row( + uchar *buf + ); +#endif + bool start_bulk_update(); + int exec_bulk_update( + uint *dup_key_found + ); + void end_bulk_update(); + int bulk_update_row( + const uchar *old_data, + uchar *new_data, + uint *dup_key_found + ); + int update_row( + const uchar *old_data, + uchar *new_data + ); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int direct_update_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_direct_update_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data + ); +#endif + int direct_update_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data, + uint *update_rows + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_direct_update_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uchar *new_data, + uint *update_rows + ); +#endif +#endif + bool start_bulk_delete(); + int end_bulk_delete(); + int delete_row( + const uchar *buf + ); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int direct_delete_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_direct_delete_rows_init( + uint mode, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted + ); +#endif + int direct_delete_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uint *delete_rows + ); +#ifdef HA_CAN_BULK_ACCESS + int pre_direct_delete_rows( + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + uint *delete_rows + ); +#endif +#endif + int delete_all_rows(); + int truncate(); + double scan_time(); + double read_time( + uint index, + uint ranges, + ha_rows rows + ); +#ifdef HA_CAN_BULK_ACCESS + void bulk_req_exec(); +#endif + const key_map *keys_to_use_for_scanning(); + ha_rows estimate_rows_upper_bound(); + bool get_error_message( + int error, + String *buf + ); + int create( + const char *name, + TABLE *form, + HA_CREATE_INFO *info + ); + void update_create_info( + HA_CREATE_INFO* create_info + ); + int rename_table( + const char *from, + const char *to + ); + int delete_table( + const char *name + ); + bool is_crashed() const; + bool auto_repair() const; + int disable_indexes( + uint mode + ); + int enable_indexes( + uint mode + ); + int check( + THD* thd, + HA_CHECK_OPT* check_opt + ); + int repair( + THD* thd, + HA_CHECK_OPT* check_opt + ); + bool check_and_repair( + THD *thd + ); + int analyze( + THD* thd, + HA_CHECK_OPT* check_opt + ); + int optimize( + THD* thd, + HA_CHECK_OPT* check_opt + ); + bool is_fatal_error( + int error_num, + uint flags + ); + Field *get_top_table_field( + uint16 field_index + ); + Field *field_exchange( + Field *field + ); + const COND *cond_push( + const COND* cond + ); + void cond_pop(); + int info_push( + uint info_type, + void *info + ); + TABLE *get_table(); + void set_searched_bitmap(); + void set_clone_searched_bitmap(); + void set_select_column_mode(); +#ifdef WITH_PARTITION_STORAGE_ENGINE + void check_select_column(bool rnd); +#endif + bool check_and_start_bulk_update( + spider_bulk_upd_start bulk_upd_start + ); + int check_and_end_bulk_update( + spider_bulk_upd_start bulk_upd_start + ); + uint check_partitioned(); + void check_direct_order_limit(); + int drop_tmp_tables(); + bool handler_opened( + int link_idx, + uint tgt_conn_kind + ); + void set_handler_opened( + int link_idx + ); + void clear_handler_opened( + int link_idx, + uint tgt_conn_kind + ); + int close_opened_handler( + int link_idx, + bool release_conn + ); + int index_handler_init(); + int rnd_handler_init(); + void set_error_mode(); + void backup_error_status(); + int check_error_mode( + int error_num + ); + int check_error_mode_eof( + int error_num + ); + int index_read_map_internal( + uchar *buf, + const uchar *key, + key_part_map keypart_map, + enum ha_rkey_function find_flag + ); + int index_read_last_map_internal( + uchar *buf, + const uchar *key, + key_part_map keypart_map + ); + int index_first_internal(uchar *buf); + int index_last_internal(uchar *buf); + int read_range_first_internal( + uchar *buf, + const key_range *start_key, + const key_range *end_key, + bool eq_range, + bool sorted + ); +#ifdef HA_MRR_USE_DEFAULT_IMPL +#else + int read_multi_range_first_internal( + uchar *buf, + KEY_MULTI_RANGE **found_range_p, + KEY_MULTI_RANGE *ranges, + uint range_count, + bool sorted, + HANDLER_BUFFER *buffer + ); +#endif + int ft_read_internal(uchar *buf); + int rnd_next_internal(uchar *buf); + void check_pre_call( + bool use_parallel + ); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + void check_insert_dup_update_pushdown(); +#endif +#ifdef HA_CAN_BULK_ACCESS + SPIDER_BULK_ACCESS_LINK *create_bulk_access_link(); + void delete_bulk_access_link( + SPIDER_BULK_ACCESS_LINK *bulk_access_link + ); + int sync_from_clone_source( + ha_spider *spider + ); +#endif + void sync_from_clone_source_base( + ha_spider *spider + ); + void set_first_link_idx(); + void reset_first_link_idx(); + int reset_sql_sql( + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int reset_hs_sql( + ulong sql_type + ); + int reset_hs_keys( + ulong sql_type + ); + int reset_hs_upds( + ulong sql_type + ); + int reset_hs_strs( + ulong sql_type + ); + int reset_hs_strs_pos( + ulong sql_type + ); + int push_back_hs_upds( + SPIDER_HS_STRING_REF &info + ); +#endif + int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_tmp_table_and_sql_for_bka(); + int append_insert_sql_part(); + int append_update_sql_part(); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_increment_update_set_sql_part(); +#endif +#endif + int append_update_set_sql_part(); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_direct_update_set_sql_part(); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_direct_update_set_hs_part(); +#endif +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_dup_update_pushdown_sql_part( + const char *alias, + uint alias_length + ); + int append_update_columns_sql_part( + const char *alias, + uint alias_length + ); + int check_update_columns_sql_part(); +#endif + int append_delete_sql_part(); + int append_select_sql_part( + ulong sql_type + ); + int append_table_select_sql_part( + ulong sql_type + ); + int append_key_select_sql_part( + ulong sql_type, + uint idx + ); + int append_minimum_select_sql_part( + ulong sql_type + ); + int append_from_sql_part( + ulong sql_type + ); + int append_hint_after_table_sql_part( + ulong sql_type + ); + void set_where_pos_sql( + ulong sql_type + ); + void set_where_to_pos_sql( + ulong sql_type + ); + int check_item_type_sql( + Item *item + ); + int append_values_connector_sql_part( + ulong sql_type + ); + int append_values_terminator_sql_part( + ulong sql_type + ); + int append_key_column_values_sql_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_where_sql_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_key_where_hs_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ); +#endif + int append_match_where_sql_part( + ulong sql_type + ); + int append_condition_sql_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg + ); + int append_match_select_sql_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + void set_order_pos_sql( + ulong sql_type + ); + void set_order_to_pos_sql( + ulong sql_type + ); + int append_key_order_for_merge_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_direct_order_limit_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_with_alias_sql_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_limit_sql_part( + longlong offset, + longlong limit, + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_limit_hs_part( + longlong offset, + longlong limit, + ulong sql_type + ); +#endif + int reappend_limit_sql_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int append_insert_terminator_sql_part( + ulong sql_type + ); + int append_insert_values_sql_part( + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_insert_values_hs_part( + ulong sql_type + ); +#endif + int append_into_sql_part( + ulong sql_type + ); + void set_insert_to_pos_sql( + ulong sql_type + ); + bool is_bulk_insert_exec_period( + bool bulk_end + ); + int append_select_lock_sql_part( + ulong sql_type + ); + int append_union_all_start_sql_part( + ulong sql_type + ); + int append_union_all_sql_part( + ulong sql_type + ); + int append_union_all_end_sql_part( + ulong sql_type + ); + int append_multi_range_cnt_sql_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma + ); + int append_delete_all_rows_sql_part( + ulong sql_type + ); + int append_update_sql( + const TABLE *table, + my_ptrdiff_t ptr_diff, + bool bulk + ); + int append_delete_sql( + const TABLE *table, + my_ptrdiff_t ptr_diff, + bool bulk + ); + bool sql_is_filled_up( + ulong sql_type + ); + bool sql_is_empty( + ulong sql_type + ); + bool support_multi_split_read_sql(); + bool support_bulk_update_sql(); + int bulk_tmp_table_insert(); + int bulk_tmp_table_end_bulk_insert(); + int bulk_tmp_table_rnd_init(); + int bulk_tmp_table_rnd_next(); + int bulk_tmp_table_rnd_end(); + int mk_bulk_tmp_table_and_bulk_start(); + void rm_bulk_tmp_table(); + bool bulk_tmp_table_created(); + int print_item_type( + Item *item, + spider_string *str, + const char *alias, + uint alias_length + ); + bool support_use_handler_sql( + int use_handler + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + bool support_bulk_access_hs() const; +#endif +}; diff --git a/storage/spider/hs_client/allocator.hpp b/storage/spider/hs_client/allocator.hpp new file mode 100644 index 00000000000..b54c7430d30 --- /dev/null +++ b/storage/spider/hs_client/allocator.hpp @@ -0,0 +1,43 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_ALLOCATOR_HPP +#define DENA_ALLOCATOR_HPP + +#if 0 +extern "C" { +#include +}; +#define DENA_MALLOC(x) tlsf_malloc(x) +#define DENA_REALLOC(x, y) tlsf_realloc(x, y) +#define DENA_FREE(x) tlsf_free(x) +#define DENA_NEWCHAR(x) static_cast(tlsf_malloc(x)) +#define DENA_DELETE(x) tlsf_free(x) +#endif + +#if 1 +#define DENA_MALLOC(x) malloc(x) +#define DENA_REALLOC(x, y) realloc(x, y) +#define DENA_FREE(x) free(x) +#define DENA_NEWCHAR(x) (new char[x]) +#define DENA_DELETE(x) (delete [] x) +#endif + +#if 1 +#define DENA_ALLOCA_ALLOCATE(typ, len) \ + static_cast(alloca((len) * sizeof(typ))) +#define DENA_ALLOCA_FREE(x) +#else +#define DENA_ALLOCA_ALLOCATE(typ, len) \ + static_cast(malloc((len) * sizeof(typ))) +#define DENA_ALLOCA_FREE(x) free(x) +#endif + +#endif + diff --git a/storage/spider/hs_client/auto_addrinfo.hpp b/storage/spider/hs_client/auto_addrinfo.hpp new file mode 100644 index 00000000000..5262ad11d4a --- /dev/null +++ b/storage/spider/hs_client/auto_addrinfo.hpp @@ -0,0 +1,49 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_AUTO_ADDRINFO_HPP +#define DENA_AUTO_ADDRINFO_HPP + +#ifndef __WIN__ +#include +#endif + +#include "util.hpp" + +namespace dena { + +struct auto_addrinfo : private noncopyable { + auto_addrinfo() : addr(0) { } + ~auto_addrinfo() { + reset(); + } + void reset(addrinfo *a = 0) { + if (addr != 0) { + freeaddrinfo(addr); + } + addr = a; + } + const addrinfo *get() const { return addr; } + int resolve(const char *node, const char *service, int flags = 0, + int family = AF_UNSPEC, int socktype = SOCK_STREAM, int protocol = 0) { + reset(); + addrinfo hints; + hints.ai_flags = flags; + hints.ai_family = family; + hints.ai_socktype = socktype; + hints.ai_protocol = protocol; + return getaddrinfo(node, service, &hints, &addr); + } + private: + addrinfo *addr; +}; + +}; + +#endif + diff --git a/storage/spider/hs_client/auto_file.hpp b/storage/spider/hs_client/auto_file.hpp new file mode 100644 index 00000000000..ddd1f8c9196 --- /dev/null +++ b/storage/spider/hs_client/auto_file.hpp @@ -0,0 +1,67 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_AUTO_FILE_HPP +#define DENA_AUTO_FILE_HPP + +/* +#ifndef __WIN__ +#include +#endif +*/ + +#include "util.hpp" + +namespace dena { + +struct auto_file : private noncopyable { + auto_file() : fd(-1) { } + ~auto_file() { + reset(); + } + int get() const { return fd; } + int close() { + if (fd < 0) { + return 0; + } + const int r = ::close(fd); + fd = -1; + return r; + } + void reset(int x = -1) { + if (fd >= 0) { + this->close(); + } + fd = x; + } + private: + int fd; +}; + +/* +struct auto_dir : private noncopyable { + auto_dir() : dp(0) { } + ~auto_dir() { + reset(); + } + DIR *get() const { return dp; } + void reset(DIR *d = 0) { + if (dp != 0) { + closedir(dp); + } + dp = d; + } + private: + DIR *dp; +}; +*/ + +}; + +#endif + diff --git a/storage/spider/hs_client/auto_ptrcontainer.hpp b/storage/spider/hs_client/auto_ptrcontainer.hpp new file mode 100644 index 00000000000..3629f19c8ea --- /dev/null +++ b/storage/spider/hs_client/auto_ptrcontainer.hpp @@ -0,0 +1,70 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_AUTO_PTRCONTAINER_HPP +#define DENA_AUTO_PTRCONTAINER_HPP + +namespace dena { + +/* +template +struct auto_ptrcontainer { + typedef Tcnt container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::pointer pointer; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + typedef typename container_type::difference_type difference_type; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + typedef typename container_type::reverse_iterator reverse_iterator; + typedef typename container_type::const_reverse_iterator + const_reverse_iterator; + iterator begin() { return cnt.begin(); } + const_iterator begin() const { return cnt.begin(); } + iterator end() { return cnt.end(); } + const_iterator end() const { return cnt.end(); } + reverse_iterator rbegin() { return cnt.rbegin(); } + reverse_iterator rend() { return cnt.rend(); } + const_reverse_iterator rbegin() const { return cnt.rbegin(); } + const_reverse_iterator rend() const { return cnt.rend(); } + size_type size() const { return cnt.size(); } + size_type max_size() const { return cnt.max_size(); } + bool empty() const { return cnt.empty(); } + reference front() { return cnt.front(); } + const_reference front() const { cnt.front(); } + reference back() { return cnt.back(); } + const_reference back() const { cnt.back(); } + void swap(auto_ptrcontainer& x) { cnt.swap(x.cnt); } + ~auto_ptrcontainer() { + for (iterator i = begin(); i != end(); ++i) { + delete *i; + } + } + template void push_back_ptr(Tap& ap) { + cnt.push_back(ap.get()); + ap.release(); + } + void erase_ptr(iterator i) { + delete *i; + cnt.erase(i); + } + reference operator [](size_type n) { return cnt[n]; } + const_reference operator [](size_type n) const { return cnt[n]; } + void clear() { cnt.clear(); } + private: + Tcnt cnt; +}; +*/ + +}; + +#endif + diff --git a/storage/spider/hs_client/config.cpp b/storage/spider/hs_client/config.cpp new file mode 100644 index 00000000000..8f6447829e1 --- /dev/null +++ b/storage/spider/hs_client/config.cpp @@ -0,0 +1,291 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "config.hpp" + +namespace dena { + +unsigned int verbose_level = 0; + +uchar * +conf_get_key( + conf_param *param, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + *length = param->key.length(); + return (uchar*) param->key.ptr(); +} + +config::config() +{ + if (my_hash_init(&conf_hash, &my_charset_bin, 32, 0, 0, + (my_hash_get_key) conf_get_key, 0, 0)) + init = FALSE; + else + init = TRUE; + return; +} + +config::~config() +{ + if (init) + { + conf_param *param; + while ((param = (conf_param *) my_hash_element(&conf_hash, 0))) + { + my_hash_delete(&conf_hash, (uchar*) param); + delete param; + } + my_hash_free(&conf_hash); + } +} + +conf_param * +config::find(const String& key) const +{ + if (init) + return (conf_param *) my_hash_search(&conf_hash, (const uchar*) key.ptr(), + key.length()); + else + return NULL; +} + +conf_param * +config::find(const char *key) const +{ + if (init) + return (conf_param *) my_hash_search(&conf_hash, (const uchar*) key, + strlen(key)); + else + return NULL; +} + +String +config::get_str(const String& key, const String& def) const +{ + DENA_VERBOSE(30, list_all_params()); + conf_param *param = find(key); + if (!param) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key.ptr(), + def.ptr())); + return def; + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", key.ptr(), + param->val.ptr())); + return param->val; +} + +String +config::get_str(const char *key, const char *def) const +{ + DENA_VERBOSE(30, list_all_params()); + conf_param *param = find(key); + if (!param) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(default)\n", key, def)); + return String(def, strlen(def), &my_charset_bin); + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", + key, param->val.ptr())); + return param->val; +} + +long long +config::get_int(const String& key, long long def) const +{ + int err; + DENA_VERBOSE(30, list_all_params()); + conf_param *param = find(key); + if (!param) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key.ptr(), + def)); + return def; + } + const long long r = my_strtoll10(param->val.ptr(), (char**) NULL, &err); + if (err) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(err)\n", key.ptr(), + def)); + return def; + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key.ptr(), r)); + return r; +} + +long long +config::get_int(const char *key, long long def) const +{ + int err; + DENA_VERBOSE(30, list_all_params()); + conf_param *param = find(key); + if (!param) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(default)\n", key, def)); + return def; + } + const long long r = my_strtoll10(param->val.ptr(), (char**) NULL, &err); + if (err) { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld(err)\n", key, def)); + return def; + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%lld\n", key, r)); + return r; +} + +bool +config::replace(const char *key, const char *val) +{ + uint32 val_len = strlen(val); + conf_param *param = find(key); + if (!param) { + /* create */ + if (!(param = new conf_param())) + return TRUE; + uint32 key_len = strlen(key); + if ( + param->key.reserve(key_len + 1) || + param->val.reserve(val_len + 1) + ) { + delete param; + return TRUE; + } + param->key.q_append(key, key_len); + param->val.q_append(val, val_len); + param->key.c_ptr_safe(); + param->val.c_ptr_safe(); + if (my_hash_insert(&conf_hash, (uchar*) param)) + { + delete param; + return TRUE; + } + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(create)\n", + param->key.ptr(), param->val.ptr())); + return FALSE; + } + /* replace */ + param->val.length(0); + if (param->val.reserve(val_len + 1)) + return TRUE; + param->val.q_append(val, val_len); + param->val.c_ptr_safe(); + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s(replace)\n", + param->key.ptr(), param->val.ptr())); + return FALSE; +} + +bool +config::replace(const char *key, long long val) +{ + char val_str[22]; + sprintf(val_str, "%lld", val); + return replace(key, val_str); +} + +bool +config::compare(const char *key, const char *val) +{ + conf_param *param = find(key); + if (!param) + return FALSE; + return !strcmp(param->val.ptr(), val); +} + +void +config::list_all_params() const +{ + conf_param *param; + DENA_VERBOSE(10, fprintf(stderr, "list_all_params start\n")); + for(ulong i = 0; i < conf_hash.records; i++) + { + if ((param = (conf_param *) my_hash_element((HASH *) &conf_hash, i))) + { + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", + param->key.ptr(), param->val.ptr())); + } + } + DENA_VERBOSE(10, fprintf(stderr, "list_all_params end\n")); +} + +config& +config::operator =(const config& x) +{ + DENA_VERBOSE(10, fprintf(stderr, "config operator = start")); + if (this != &x && init && x.init) { + conf_param *param, *new_param; + for(ulong i = 0; i < x.conf_hash.records; i++) + { + if ( + (param = (conf_param *) my_hash_element((HASH *) &x.conf_hash, i)) && + (new_param = new conf_param()) + ) { + if ( + !new_param->key.copy(param->key) && + !new_param->val.copy(param->val) + ) { + new_param->key.c_ptr_safe(); + new_param->val.c_ptr_safe(); + DENA_VERBOSE(10, fprintf(stderr, "CONFIG: %s=%s\n", + new_param->key.ptr(), new_param->val.ptr())); + if (my_hash_insert(&conf_hash, (uchar*) new_param)) + delete new_param; + } else + delete new_param; + } + } + } + DENA_VERBOSE(10, fprintf(stderr, "config operator = end %p", this)); + return *this; +} + +void +parse_args(int argc, char **argv, config& conf) +{ + conf_param *param; + for (int i = 1; i < argc; ++i) { + const char *const arg = argv[i]; + const char *const eq = strchr(arg, '='); + if (eq == 0) { + continue; + } + if (!(param = new conf_param())) + continue; + uint32 key_len = eq - arg; + uint32 val_len = strlen(eq + 1); + if ( + param->key.reserve(key_len + 1) || + param->val.reserve(val_len + 1) + ) { + delete param; + continue; + } + param->key.q_append(arg, key_len); + param->val.q_append(eq + 1, val_len); + param->key.c_ptr_safe(); + param->val.c_ptr_safe(); + if (my_hash_insert(&conf.conf_hash, (uchar*) param)) + { + delete param; + continue; + } + } + param = conf.find("verbose"); + if (param) { + verbose_level = atoi(param->val.c_ptr()); + } +} + +}; + diff --git a/storage/spider/hs_client/config.hpp b/storage/spider/hs_client/config.hpp new file mode 100644 index 00000000000..2880f2f5a33 --- /dev/null +++ b/storage/spider/hs_client/config.hpp @@ -0,0 +1,81 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_CONFIG_HPP +#define DENA_CONFIG_HPP + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#endif + +#define DENA_VERBOSE(lv, x) if (dena::verbose_level >= (lv)) { (x); } + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +#define INFO_KIND_HS_RET_FIELDS 1 +#define INFO_KIND_HS_APPEND_STRING_REF 3 +#define INFO_KIND_HS_CLEAR_STRING_REF 4 +#define INFO_KIND_HS_INCREMENT_BEGIN 5 +#define INFO_KIND_HS_INCREMENT_END 6 +#define INFO_KIND_HS_DECREMENT_BEGIN 7 +#define INFO_KIND_HS_DECREMENT_END 8 +#endif + +namespace dena { + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +struct uint32_info { + size_t info_size; + uint32 *info; +}; +#endif + +struct conf_param { + String key; + String val; +}; + +uchar *conf_get_key( + conf_param *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +struct config { + bool init; + HASH conf_hash; + config(); + ~config(); + conf_param *find(const String& key) const; + conf_param *find(const char *key) const; + String get_str(const String& key, const String& def = + String("", &my_charset_bin)) const; + String get_str(const char *key, const char *def = "") const; + long long get_int(const String& key, long long def = 0) const; + long long get_int(const char *key, long long def = 0) const; + bool replace(const char *key, const char *val); + bool replace(const char *key, long long val); + bool compare(const char *key, const char *val); + void list_all_params() const; + config& operator =(const config& x); +}; + +void parse_args(int argc, char **argv, config& conf); + +extern unsigned int verbose_level; + +}; + +#endif + diff --git a/storage/spider/hs_client/escape.cpp b/storage/spider/hs_client/escape.cpp new file mode 100644 index 00000000000..d382dfbc07e --- /dev/null +++ b/storage/spider/hs_client/escape.cpp @@ -0,0 +1,127 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#include "mysql_version.h" +#include "hs_compat.h" +#include "escape.hpp" +#include "string_buffer.hpp" +#include "fatal.hpp" +#include "string_util.hpp" + +#define DBG_OP(x) +#define DBG_BUF(x) + +namespace dena { + +enum special_char_t { + special_char_escape_prefix = 0x01, /* SOH */ + special_char_noescape_min = 0x10, /* DLE */ + special_char_escape_shift = 0x40, /* '@' */ +}; + +void +escape_string(char *& wp, const char *start, const char *finish) +{ + while (start != finish) { + const unsigned char c = *start; + if (c >= special_char_noescape_min) { + wp[0] = c; /* no need to escape */ + } else { + wp[0] = special_char_escape_prefix; + ++wp; + wp[0] = c + special_char_escape_shift; + } + ++start; + ++wp; + } +} + +void +escape_string(string_buffer& ar, const char *start, const char *finish) +{ + const size_t buflen = (finish - start) * 2; + char *const wp_begin = ar.make_space(buflen); + char *wp = wp_begin; + escape_string(wp, start, finish); + ar.space_wrote(wp - wp_begin); +} + +bool +unescape_string(char *& wp, const char *start, const char *finish) +{ + /* works even if wp == start */ + while (start != finish) { + const unsigned char c = *start; + if (c != special_char_escape_prefix) { + wp[0] = c; + } else if (start + 1 != finish) { + ++start; + const unsigned char cn = *start; + if (cn < special_char_escape_shift) { + return false; + } + wp[0] = cn - special_char_escape_shift; + } else { + return false; + } + ++start; + ++wp; + } + return true; +} + +bool +unescape_string(string_buffer& ar, const char *start, const char *finish) +{ + const size_t buflen = finish - start; + char *const wp_begin = ar.make_space(buflen); + char *wp = wp_begin; + const bool r = unescape_string(wp, start, finish); + ar.space_wrote(wp - wp_begin); + return r; +} + +uint32 +read_ui32(char *& start, char *finish) +{ + char *const n_begin = start; + read_token(start, finish); + char *const n_end = start; + uint32 v = 0; + for (char *p = n_begin; p != n_end; ++p) { + const char ch = p[0]; + if (ch >= '0' && ch <= '9') { + v *= 10; + v += (ch - '0'); + } + } + return v; +} + +void +write_ui32(string_buffer& buf, uint32 v) +{ + char *wp = buf.make_space(12); + int len = snprintf(wp, 12, "%u", v); + if (len > 0) { + buf.space_wrote(len); + } +} + +void +write_ui64(string_buffer& buf, uint64 v) +{ + char *wp = buf.make_space(22); + int len = snprintf(wp, 22, "%llu", static_cast(v)); + if (len > 0) { + buf.space_wrote(len); + } +} + +}; + diff --git a/storage/spider/hs_client/escape.hpp b/storage/spider/hs_client/escape.hpp new file mode 100644 index 00000000000..4c23e16701c --- /dev/null +++ b/storage/spider/hs_client/escape.hpp @@ -0,0 +1,64 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#include "string_buffer.hpp" +#include "string_ref.hpp" +#include "string_util.hpp" + +#ifndef DENA_ESCAPE_HPP +#define DENA_ESCAPE_HPP + +namespace dena { + +void escape_string(char *& wp, const char *start, const char *finish); +void escape_string(string_buffer& ar, const char *start, const char *finish); +bool unescape_string(char *& wp, const char *start, const char *finish); + /* unescaped_string() works even if wp == start */ +bool unescape_string(string_buffer& ar, const char *start, const char *finish); + +uint32 read_ui32(char *& start, char *finish); +void write_ui32(string_buffer& buf, uint32 v); +void write_ui64(string_buffer& buf, uint64 v); + +inline bool +is_null_expression(const char *start, const char *finish) +{ + return (finish == start + 1 && start[0] == 0); +} + +inline void +read_token(char *& start, char *finish) +{ + char *const p = memchr_char(start, '\t', finish - start); + if (p == 0) { + start = finish; + } else { + start = p; + } +} + +inline void +skip_token_delim_fold(char *& start, char *finish) +{ + while (start != finish && start[0] == '\t') { + ++start; + } +} + +inline void +skip_one(char *& start, char *finish) +{ + if (start != finish) { + ++start; + } +} + +}; + +#endif + diff --git a/storage/spider/hs_client/fatal.cpp b/storage/spider/hs_client/fatal.cpp new file mode 100644 index 00000000000..b26fb50f4fb --- /dev/null +++ b/storage/spider/hs_client/fatal.cpp @@ -0,0 +1,68 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "fatal.hpp" + +namespace dena { + +/* +const int opt_syslog = LOG_ERR | LOG_PID | LOG_CONS; +*/ + +void +fatal_exit(const String& message) +{ + fprintf(stderr, "FATAL_EXIT: %s\n", message.ptr()); +/* + syslog(opt_syslog, "FATAL_EXIT: %s", message.ptr()); +*/ + _exit(1); +} + +void +fatal_exit(const char *message) +{ + fprintf(stderr, "FATAL_EXIT: %s\n", message); +/* + syslog(opt_syslog, "FATAL_EXIT: %s", message); +*/ + _exit(1); +} + +void +fatal_abort(const String& message) +{ + fprintf(stderr, "FATAL_COREDUMP: %s\n", message.ptr()); +/* + syslog(opt_syslog, "FATAL_COREDUMP: %s", message.ptr()); +*/ + abort(); +} + +void +fatal_abort(const char *message) +{ + fprintf(stderr, "FATAL_COREDUMP: %s\n", message); +/* + syslog(opt_syslog, "FATAL_COREDUMP: %s", message); +*/ + abort(); +} + +}; + diff --git a/storage/spider/hs_client/fatal.hpp b/storage/spider/hs_client/fatal.hpp new file mode 100644 index 00000000000..a75c56bddad --- /dev/null +++ b/storage/spider/hs_client/fatal.hpp @@ -0,0 +1,33 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_FATAL_HPP +#define DENA_FATAL_HPP + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#endif + +namespace dena { + +void fatal_exit(const String& message); +void fatal_exit(const char *message); +void fatal_abort(const String& message); +void fatal_abort(const char *message); + +}; + +#endif + diff --git a/storage/spider/hs_client/hs_compat.h b/storage/spider/hs_client/hs_compat.h new file mode 100644 index 00000000000..920b4efa508 --- /dev/null +++ b/storage/spider/hs_client/hs_compat.h @@ -0,0 +1,31 @@ +/* Copyright (C) 2013 Kentoku Shiba + + 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 HS_COMPAT_H +#define HS_COMPAT_H + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ + my_init_dynamic_array2(A, B, C, D, E, F) +#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ + init_alloc_root(A, B, C, D) +#else +#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ + my_init_dynamic_array2(A, B, C, D, E) +#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ + init_alloc_root(A, B, C) +#endif + +#endif diff --git a/storage/spider/hs_client/hstcpcli.cpp b/storage/spider/hs_client/hstcpcli.cpp new file mode 100644 index 00000000000..6ff9ed84a81 --- /dev/null +++ b/storage/spider/hs_client/hstcpcli.cpp @@ -0,0 +1,643 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#include "mysql_version.h" +#include "hs_compat.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#endif + +#include "hstcpcli.hpp" +#include "auto_file.hpp" +#include "string_util.hpp" +#include "auto_addrinfo.hpp" +#include "escape.hpp" +#include "util.hpp" + +/* TODO */ +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(MSG_NOSIGNAL) +#define MSG_NOSIGNAL 0 +#endif + +#define DBG(x) + +namespace dena { + +hstresult::hstresult() +{ + SPD_INIT_DYNAMIC_ARRAY2(&flds, sizeof(string_ref), NULL, 16, 16, + MYF(MY_WME)); +} + +hstresult::~hstresult() +{ + delete_dynamic(&flds); +} + +struct hstcpcli : public hstcpcli_i, private noncopyable { + hstcpcli(const socket_args& args); + virtual ~hstcpcli(); + virtual void close(); + virtual int reconnect(); + virtual bool stable_point(); + virtual void request_buf_open_index(size_t pst_id, const char *dbn, + const char *tbl, const char *idx, const char *retflds, const char *filflds); + virtual void request_buf_auth(const char *secret, const char *typ); + virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op, + const string_ref *kvs, size_t kvslen, uint32 limit, uint32 skip, + const string_ref& mod_op, const string_ref *mvs, size_t mvslen, + const hstcpcli_filter *fils, size_t filslen, int invalues_keypart, + const string_ref *invalues, size_t invalueslen); + virtual size_t request_buf_append(const char *start, const char *finish); + virtual void request_reset(); + virtual int request_send(); + virtual int response_recv(size_t& num_flds_r); + virtual int get_result(hstresult& result); + virtual const string_ref *get_next_row(); + virtual const string_ref *get_next_row_from_result(hstresult& result); + virtual void response_buf_remove(); + virtual int get_error_code(); + virtual String& get_error(); + virtual void clear_error(); + virtual int set_timeout(int send_timeout, int recv_timeout); + virtual size_t get_num_req_bufd() { return num_req_bufd; } + virtual size_t get_num_req_sent() { return num_req_sent; } + virtual size_t get_num_req_rcvd() { return num_req_rcvd; } + virtual size_t get_response_end_offset() { return response_end_offset; } + virtual const char *get_readbuf_begin() { return readbuf.begin(); } + virtual const char *get_readbuf_end() { return readbuf.end(); } + virtual void write_error_to_log(const char *func_name, const char *file_name, + ulong line_no); + private: + int read_more(); + int set_error(int code, const String& str); + int set_error(int code, const char *str); + private: + auto_file fd; + socket_args sargs; + string_buffer readbuf; + string_buffer writebuf; + size_t response_end_offset; /* incl newline */ + size_t cur_row_offset; + size_t num_flds; + size_t num_req_bufd; /* buffered but not yet sent */ + size_t num_req_sent; /* sent but not yet received */ + size_t num_req_rcvd; /* received but not yet removed */ + int error_code; + String error_str; + DYNAMIC_ARRAY flds; + int errno_buf; +}; + +hstcpcli::hstcpcli(const socket_args& args) + : sargs(args), response_end_offset(0), cur_row_offset(0), num_flds(0), + num_req_bufd(0), num_req_sent(0), num_req_rcvd(0), error_code(0), errno_buf(0) +{ + String err; + SPD_INIT_DYNAMIC_ARRAY2(&flds, sizeof(string_ref), NULL, 16, 16, MYF(MY_WME)); + if (socket_connect(fd, sargs, err) != 0) { + set_error(-1, err); + } +} + +hstcpcli::~hstcpcli() +{ + delete_dynamic(&flds); +} + +void +hstcpcli::close() +{ + fd.close(); + readbuf.clear(); + writebuf.clear(); + response_end_offset = 0; + cur_row_offset = 0; + num_flds = 0; + num_req_bufd = 0; + num_req_sent = 0; + num_req_rcvd = 0; +} + +int +hstcpcli::reconnect() +{ + clear_error(); + close(); + String err; + if (socket_connect(fd, sargs, err) != 0) { + set_error(-1, err); + } + return error_code; +} + +int +hstcpcli::set_timeout(int send_timeout, int recv_timeout) +{ + String err; + sargs.send_timeout = send_timeout; + sargs.recv_timeout = recv_timeout; + if (socket_set_timeout(fd, sargs, err) != 0) { + set_error(-1, err); + } + return error_code; +} + +bool +hstcpcli::stable_point() +{ + /* returns true if cli can send a new request */ + return fd.get() >= 0 && num_req_bufd == 0 && num_req_sent == 0 && + num_req_rcvd == 0 && response_end_offset == 0; +} + +int +hstcpcli::get_error_code() +{ + return error_code; +} + +String& +hstcpcli::get_error() +{ + return error_str; +} + +int +hstcpcli::read_more() +{ + const size_t block_size = 4096; // FIXME + char *const wp = readbuf.make_space(block_size); + int rlen; + errno = 0; + while ((rlen = read(fd.get(), wp, block_size)) <= 0) { + errno_buf = errno; + if (rlen < 0) { + if (errno == EINTR || errno == EAGAIN) + { + errno = 0; + continue; + } + error_str = String("read: failed", &my_charset_bin); + } else { + error_str = String("read: eof", &my_charset_bin); + } + return rlen; + } + readbuf.space_wrote(rlen); + return rlen; +} + +void +hstcpcli::clear_error() +{ + DBG(fprintf(stderr, "CLEAR_ERROR: %d\n", error_code)); + error_code = 0; + error_str.length(0); +} + +int +hstcpcli::set_error(int code, const String& str) +{ + DBG(fprintf(stderr, "SET_ERROR: %d\n", code)); + error_code = code; + error_str = str; + return error_code; +} + +int +hstcpcli::set_error(int code, const char *str) +{ + uint32 str_len = strlen(str); + DBG(fprintf(stderr, "SET_ERROR: %d\n", code)); + error_code = code; + error_str.length(0); + if (error_str.reserve(str_len + 1)) + return 0; + error_str.q_append(str, str_len); + error_str.c_ptr_safe(); + return error_code; +} + +void +hstcpcli::request_buf_open_index(size_t pst_id, const char *dbn, + const char *tbl, const char *idx, const char *retflds, const char *filflds) +{ +/* + if (num_req_sent > 0 || num_req_rcvd > 0) { +*/ + if (num_req_rcvd > 0) { + close(); + set_error(-1, "request_buf_open_index: protocol out of sync"); + return; + } + const string_ref dbn_ref(dbn, strlen(dbn)); + const string_ref tbl_ref(tbl, strlen(tbl)); + const string_ref idx_ref(idx, strlen(idx)); + const string_ref rfs_ref(retflds, strlen(retflds)); + writebuf.append_literal("P\t"); + append_uint32(writebuf, pst_id); // FIXME size_t ? + writebuf.append_literal("\t"); + writebuf.append(dbn_ref.begin(), dbn_ref.end()); + writebuf.append_literal("\t"); + writebuf.append(tbl_ref.begin(), tbl_ref.end()); + writebuf.append_literal("\t"); + writebuf.append(idx_ref.begin(), idx_ref.end()); + writebuf.append_literal("\t"); + writebuf.append(rfs_ref.begin(), rfs_ref.end()); + if (filflds != 0) { + const string_ref fls_ref(filflds, strlen(filflds)); + writebuf.append_literal("\t"); + writebuf.append(fls_ref.begin(), fls_ref.end()); + } + writebuf.append_literal("\n"); + ++num_req_bufd; +} + +void +hstcpcli::request_buf_auth(const char *secret, const char *typ) +{ +/* + if (num_req_sent > 0 || num_req_rcvd > 0) { +*/ + if (num_req_rcvd > 0) { + close(); + set_error(-1, "request_buf_auth: protocol out of sync"); + return; + } + if (typ == 0) { + typ = "1"; + } + const string_ref typ_ref(typ, strlen(typ)); + const string_ref secret_ref(secret, strlen(secret)); + writebuf.append_literal("A\t"); + writebuf.append(typ_ref.begin(), typ_ref.end()); + writebuf.append_literal("\t"); + writebuf.append(secret_ref.begin(), secret_ref.end()); + writebuf.append_literal("\n"); + ++num_req_bufd; +} + +namespace { + +void +append_delim_value(string_buffer& buf, const char *start, const char *finish) +{ + if (start == 0) { + /* null */ + const char t[] = "\t\0"; + buf.append(t, t + 2); + } else { + /* non-null */ + buf.append_literal("\t"); + escape_string(buf, start, finish); + } +} + +}; + +void +hstcpcli::request_buf_exec_generic(size_t pst_id, const string_ref& op, + const string_ref *kvs, size_t kvslen, uint32 limit, uint32 skip, + const string_ref& mod_op, const string_ref *mvs, size_t mvslen, + const hstcpcli_filter *fils, size_t filslen, int invalues_keypart, + const string_ref *invalues, size_t invalueslen) +{ +/* + if (num_req_sent > 0 || num_req_rcvd > 0) { +*/ + if (num_req_rcvd > 0) { + close(); + set_error(-1, "request_buf_exec_generic: protocol out of sync"); + return; + } + append_uint32(writebuf, pst_id); // FIXME size_t ? + writebuf.append_literal("\t"); + writebuf.append(op.begin(), op.end()); + writebuf.append_literal("\t"); + append_uint32(writebuf, kvslen); // FIXME size_t ? + for (size_t i = 0; i < kvslen; ++i) { + const string_ref& kv = kvs[i]; + append_delim_value(writebuf, kv.begin(), kv.end()); + } + if (limit != 0 || skip != 0 || invalues_keypart >= 0 || + mod_op.size() != 0 || filslen != 0) { + /* has more option */ + writebuf.append_literal("\t"); + append_uint32(writebuf, limit); // FIXME size_t ? + if (skip != 0 || invalues_keypart >= 0 || + mod_op.size() != 0 || filslen != 0) { + writebuf.append_literal("\t"); + append_uint32(writebuf, skip); // FIXME size_t ? + } + if (invalues_keypart >= 0) { + writebuf.append_literal("\t@\t"); + append_uint32(writebuf, invalues_keypart); + writebuf.append_literal("\t"); + append_uint32(writebuf, invalueslen); + for (size_t i = 0; i < invalueslen; ++i) { + const string_ref& s = invalues[i]; + append_delim_value(writebuf, s.begin(), s.end()); + } + } + for (size_t i = 0; i < filslen; ++i) { + const hstcpcli_filter& f = fils[i]; + writebuf.append_literal("\t"); + writebuf.append(f.filter_type.begin(), f.filter_type.end()); + writebuf.append_literal("\t"); + writebuf.append(f.op.begin(), f.op.end()); + writebuf.append_literal("\t"); + append_uint32(writebuf, f.ff_offset); + append_delim_value(writebuf, f.val.begin(), f.val.end()); + } + if (mod_op.size() != 0) { + writebuf.append_literal("\t"); + writebuf.append(mod_op.begin(), mod_op.end()); + for (size_t i = 0; i < mvslen; ++i) { + const string_ref& mv = mvs[i]; + append_delim_value(writebuf, mv.begin(), mv.end()); + } + } + } + writebuf.append_literal("\n"); + ++num_req_bufd; +} + +size_t +hstcpcli::request_buf_append(const char *start, const char *finish) +{ +/* + if (num_req_sent > 0 || num_req_rcvd > 0) { +*/ + if (num_req_rcvd > 0) { + close(); + set_error(-1, "request_buf_append: protocol out of sync"); + return 0; + } + const char *nl = start; + size_t num_req = 0; + while ((nl = memchr_char(nl, '\n', finish - nl))) { + if (nl == finish) + break; + num_req++; + nl++; + } + num_req++; + writebuf.append(start, finish); + if (*(finish - 1) != '\n') + writebuf.append_literal("\n"); + num_req_bufd += num_req; + return num_req; +} + +void +hstcpcli::request_reset() +{ + if (num_req_bufd) { + writebuf.erase_front(writebuf.size()); + num_req_bufd = 0; + } +} + +int +hstcpcli::request_send() +{ + if (error_code < 0) { + return error_code; + } + clear_error(); + if (fd.get() < 0) { + close(); + return set_error(-1, "write: closed"); + } +/* + if (num_req_bufd == 0 || num_req_sent > 0 || num_req_rcvd > 0) { +*/ + if (num_req_bufd == 0 || num_req_rcvd > 0) { + close(); + return set_error(-1, "request_send: protocol out of sync"); + } + const size_t wrlen = writebuf.size(); + const ssize_t r = send(fd.get(), writebuf.begin(), wrlen, MSG_NOSIGNAL); + if (r <= 0) { + close(); + return set_error(-1, r < 0 ? "write: failed" : "write: eof"); + } + writebuf.erase_front(r); + if (static_cast(r) != wrlen) { + close(); + return set_error(-1, "write: incomplete"); + } + num_req_sent += num_req_bufd; + num_req_bufd = 0; + DBG(fprintf(stderr, "REQSEND 0\n")); + return 0; +} + +int +hstcpcli::response_recv(size_t& num_flds_r) +{ + if (error_code < 0) { + return error_code; + } + clear_error(); + if (num_req_bufd > 0 || num_req_sent == 0 || num_req_rcvd > 0 || + response_end_offset != 0) { + close(); + return set_error(-1, "response_recv: protocol out of sync"); + } + cur_row_offset = 0; + num_flds_r = num_flds = 0; + if (fd.get() < 0) { + return set_error(-1, "read: closed"); + } + size_t offset = 0; + while (true) { + const char *const lbegin = readbuf.begin() + offset; + const char *const lend = readbuf.end(); + if (lbegin < lend) + { + const char *const nl = memchr_char(lbegin, '\n', lend - lbegin); + if (nl != 0) { + offset += (nl + 1) - lbegin; + break; + } + offset += lend - lbegin; + } + if (read_more() <= 0) { + close(); + error_code = -1; + return error_code; + } + } + response_end_offset = offset; + --num_req_sent; + ++num_req_rcvd; + char *start = readbuf.begin(); + char *const finish = start + response_end_offset - 1; + const size_t resp_code = read_ui32(start, finish); + skip_one(start, finish); + num_flds_r = num_flds = read_ui32(start, finish); + if (resp_code != 0) { + skip_one(start, finish); + char *const err_begin = start; + read_token(start, finish); + char *const err_end = start; + String e = String(err_begin, err_end - err_begin, &my_charset_bin); + if (!e.length()) { + e = String("unknown_error", &my_charset_bin); + } + return set_error(resp_code, e); + } + cur_row_offset = start - readbuf.begin(); + DBG(fprintf(stderr, "[%s] ro=%zu eol=%zu\n", + String(readbuf.begin(), readbuf.begin() + response_end_offset) + .c_str(), + cur_row_offset, response_end_offset)); + DBG(fprintf(stderr, "RES 0\n")); + if (flds.max_element < num_flds) + { + if (allocate_dynamic(&flds, num_flds)) + return set_error(-1, "out of memory"); + } + flds.elements = num_flds; + return 0; +} + +int +hstcpcli::get_result(hstresult& result) +{ +/* + readbuf.swap(result.readbuf); +*/ + char *const wp = result.readbuf.make_space(response_end_offset); + memcpy(wp, readbuf.begin(), response_end_offset); + result.readbuf.space_wrote(response_end_offset); + result.response_end_offset = response_end_offset; + result.num_flds = num_flds; + result.cur_row_offset = cur_row_offset; + if (result.flds.max_element < num_flds) + { + if (allocate_dynamic(&result.flds, num_flds)) + return set_error(-1, "out of memory"); + } + result.flds.elements = num_flds; + return 0; +} + +const string_ref * +hstcpcli::get_next_row() +{ + if (num_flds == 0 || flds.elements < num_flds) { + DBG(fprintf(stderr, "GNR NF 0\n")); + return 0; + } + char *start = readbuf.begin() + cur_row_offset; + char *const finish = readbuf.begin() + response_end_offset - 1; + if (start >= finish) { /* start[0] == nl */ + DBG(fprintf(stderr, "GNR FIN 0 %p %p\n", start, finish)); + return 0; + } + for (size_t i = 0; i < num_flds; ++i) { + skip_one(start, finish); + char *const fld_begin = start; + read_token(start, finish); + char *const fld_end = start; + char *wp = fld_begin; + if (is_null_expression(fld_begin, fld_end)) { + /* null */ + ((string_ref *) flds.buffer)[i] = string_ref(); + } else { + unescape_string(wp, fld_begin, fld_end); /* in-place */ + ((string_ref *) flds.buffer)[i] = string_ref(fld_begin, wp); + } + } + cur_row_offset = start - readbuf.begin(); + return (string_ref *) flds.buffer; +} + +const string_ref * +hstcpcli::get_next_row_from_result(hstresult& result) +{ + if (result.num_flds == 0 || result.flds.elements < result.num_flds) { + DBG(fprintf(stderr, "GNR NF 0\n")); + return 0; + } + char *start = result.readbuf.begin() + result.cur_row_offset; + char *const finish = result.readbuf.begin() + result.response_end_offset - 1; + if (start >= finish) { /* start[0] == nl */ + DBG(fprintf(stderr, "GNR FIN 0 %p %p\n", start, finish)); + return 0; + } + for (size_t i = 0; i < result.num_flds; ++i) { + skip_one(start, finish); + char *const fld_begin = start; + read_token(start, finish); + char *const fld_end = start; + char *wp = fld_begin; + if (is_null_expression(fld_begin, fld_end)) { + /* null */ + ((string_ref *) result.flds.buffer)[i] = string_ref(); + } else { + unescape_string(wp, fld_begin, fld_end); /* in-place */ + ((string_ref *) result.flds.buffer)[i] = string_ref(fld_begin, wp); + } + } + result.cur_row_offset = start - result.readbuf.begin(); + return (string_ref *) result.flds.buffer; +} + +void +hstcpcli::response_buf_remove() +{ + if (response_end_offset == 0) { + close(); + set_error(-1, "response_buf_remove: protocol out of sync"); + return; + } + readbuf.erase_front(response_end_offset); + response_end_offset = 0; + --num_req_rcvd; + cur_row_offset = 0; + num_flds = 0; +} + +void +hstcpcli::write_error_to_log( + const char *func_name, + const char *file_name, + ulong line_no +) { + if (errno_buf) { + time_t cur_time = (time_t) time((time_t*) 0); + struct tm lt; + struct tm *l_time = localtime_r(&cur_time, <); + fprintf(stderr, + "%04d%02d%02d %02d:%02d:%02d [ERROR] hstcpcli: [%d][%s]" + " [%s][%s][%lu] errno=%d\n", + l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday, + l_time->tm_hour, l_time->tm_min, l_time->tm_sec, + error_code, error_str.c_ptr_safe(), + func_name, file_name, line_no, errno_buf); + } +} + +hstcpcli_ptr +hstcpcli_i::create(const socket_args& args) +{ + return hstcpcli_ptr(new hstcpcli(args)); +} + +}; + diff --git a/storage/spider/hs_client/hstcpcli.hpp b/storage/spider/hs_client/hstcpcli.hpp new file mode 100644 index 00000000000..2c43f4230c4 --- /dev/null +++ b/storage/spider/hs_client/hstcpcli.hpp @@ -0,0 +1,93 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_HSTCPCLI_HPP +#define DENA_HSTCPCLI_HPP + +#define HANDLERSOCKET_MYSQL_UTIL 1 + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "config.hpp" +#include "socket.hpp" +#include "string_ref.hpp" +#include "string_buffer.hpp" + +namespace dena { + +struct hstcpcli_filter { + string_ref filter_type; + string_ref op; + size_t ff_offset; + string_ref val; + hstcpcli_filter() : ff_offset(0) { } +}; + +struct hstcpcli_i; +typedef hstcpcli_i *hstcpcli_ptr; + +struct hstresult { + hstresult(); + virtual ~hstresult(); + string_buffer readbuf; + size_t response_end_offset; + size_t num_flds; + size_t cur_row_offset; + DYNAMIC_ARRAY flds; +}; + +struct hstcpcli_i { + virtual ~hstcpcli_i() { } + virtual void close() = 0; + virtual int reconnect() = 0; + virtual bool stable_point() = 0; + virtual void request_buf_auth(const char *secret, const char *typ) = 0; + virtual void request_buf_open_index(size_t pst_id, const char *dbn, + const char *tbl, const char *idx, const char *retflds, + const char *filflds = 0) = 0; + virtual void request_buf_exec_generic(size_t pst_id, const string_ref& op, + const string_ref *kvs, size_t kvslen, uint32 limit, uint32 skip, + const string_ref& mod_op, const string_ref *mvs, size_t mvslen, + const hstcpcli_filter *fils = 0, size_t filslen = 0, + int invalues_keypart = -1, const string_ref *invalues = 0, + size_t invalueslen = 0) = 0; // FIXME: too long + virtual size_t request_buf_append(const char *start, const char *finish) = 0; + virtual void request_reset() = 0; + virtual int request_send() = 0; + virtual int response_recv(size_t& num_flds_r) = 0; + virtual int get_result(hstresult& result) = 0; + virtual const string_ref *get_next_row() = 0; + virtual const string_ref *get_next_row_from_result(hstresult& result) = 0; + virtual void response_buf_remove() = 0; + virtual int get_error_code() = 0; + virtual String& get_error() = 0; + virtual void clear_error() = 0; + virtual int set_timeout(int send_timeout, int recv_timeout) = 0; + virtual size_t get_num_req_bufd() = 0; + virtual size_t get_num_req_sent() = 0; + virtual size_t get_num_req_rcvd() = 0; + virtual size_t get_response_end_offset() = 0; + virtual const char *get_readbuf_begin() = 0; + virtual const char *get_readbuf_end() = 0; + virtual void write_error_to_log(const char *func_name, const char *file_name, + ulong line_no) = 0; + static hstcpcli_ptr create(const socket_args& args); +}; + +}; + +#endif + diff --git a/storage/spider/hs_client/mutex.hpp b/storage/spider/hs_client/mutex.hpp new file mode 100644 index 00000000000..8e331fb6ab2 --- /dev/null +++ b/storage/spider/hs_client/mutex.hpp @@ -0,0 +1,48 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_MUTEX_HPP +#define DENA_MUTEX_HPP + +#include "fatal.hpp" +#include "util.hpp" + +namespace dena { + +struct condition; + +struct mutex : private noncopyable { + friend struct condition; + mutex() { + if (pthread_mutex_init(&mtx, 0) != 0) { + fatal_abort("pthread_mutex_init"); + } + } + ~mutex() { + if (pthread_mutex_destroy(&mtx) != 0) { + fatal_abort("pthread_mutex_destroy"); + } + } + void lock() const { + if (pthread_mutex_lock(&mtx) != 0) { + fatal_abort("pthread_mutex_lock"); + } + } + void unlock() const { + if (pthread_mutex_unlock(&mtx) != 0) { + fatal_abort("pthread_mutex_unlock"); + } + } + private: + mutable pthread_mutex_t mtx; +}; + +}; + +#endif + diff --git a/storage/spider/hs_client/socket.cpp b/storage/spider/hs_client/socket.cpp new file mode 100644 index 00000000000..6515987124c --- /dev/null +++ b/storage/spider/hs_client/socket.cpp @@ -0,0 +1,310 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef __WIN__ +#include +#endif + +#include "mysql_version.h" +#include "hs_compat.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#include +#endif +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "socket.hpp" +#include "string_util.hpp" +#include "fatal.hpp" + +/* +struct sockaddr_un { + short sun_family; + char sun_path[108]; +}; +*/ + +namespace dena { + +void +ignore_sigpipe() +{ +#if defined(SIGPIPE) && !defined(__WIN__) + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { + fatal_abort("SIGPIPE SIG_IGN"); + } +#endif +} + +void +socket_args::set(const config& conf) +{ + timeout = (int) conf.get_int("timeout", 600); + listen_backlog = (int) conf.get_int("listen_backlog", 256); + String node = conf.get_str("host", ""); + String port = conf.get_str("port", ""); + if (node.length() || port.length()) { + if (family == AF_UNIX || !strcmp(node.c_ptr(), "/")) { + set_unix_domain(port.c_ptr()); + } else { + const char *nd = !node.length() ? 0 : node.c_ptr(); + if (resolve(nd, port.c_ptr()) != 0) { + String message("getaddrinfo failed: ", &my_charset_bin); + message.reserve(node.length() + sizeof(":") - 1 + port.length()); + message.append(node); + message.q_append(":", sizeof(":") - 1); + message.append(port); + fatal_exit(message); + } + } + } + sndbuf = (int) conf.get_int("sndbuf", 0); + rcvbuf = (int) conf.get_int("rcvbuf", 0); +} + +void +socket_args::set_unix_domain(const char *path) +{ +#ifndef __WIN__ + family = AF_UNIX; + addr = sockaddr_storage(); + addrlen = sizeof(sockaddr_un); + sockaddr_un *const ap = reinterpret_cast(&addr); + ap->sun_family = AF_UNIX; + strncpy(ap->sun_path, path, sizeof(ap->sun_path) - 1); +#endif +} + +int +socket_args::resolve(const char *node, const char *service) +{ + const int flags = (node == 0) ? AI_PASSIVE : 0; + auto_addrinfo ai; + addr = sockaddr_storage(); + addrlen = 0; + const int r = ai.resolve(node, service, flags, family, socktype, protocol); + if (r != 0) { + return r; + } + memcpy(&addr, ai.get()->ai_addr, ai.get()->ai_addrlen); + addrlen = ai.get()->ai_addrlen; + return 0; +} + +int +socket_set_timeout(auto_file& fd, const socket_args& args, String& err_r) +{ + if (!args.nonblocking) { +#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) + if (args.recv_timeout != 0) { +#ifndef __WIN__ + struct timeval tv; + tv.tv_sec = args.recv_timeout; + tv.tv_usec = 0; +#else + int tv = args.recv_timeout * 1000; +#endif + if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVTIMEO, +#ifndef __WIN__ + (const void *) &tv, +#else + (const char *) &tv, +#endif + sizeof(tv)) != 0) { + return errno_string("setsockopt SO_RCVTIMEO", errno, err_r); + } + } + if (args.send_timeout != 0) { +#ifndef __WIN__ + struct timeval tv; + tv.tv_sec = args.send_timeout; + tv.tv_usec = 0; +#else + int tv = args.send_timeout * 1000; +#endif + if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDTIMEO, +#ifndef __WIN__ + (const void *) &tv, +#else + (const char *) &tv, +#endif + sizeof(tv)) != 0) { + return errno_string("setsockopt SO_SNDTIMEO", errno, err_r); + } + } +#endif + } + return 0; +} + +int +socket_set_options(auto_file& fd, const socket_args& args, String& err_r) +{ + if (args.timeout != 0 && !args.nonblocking) { +#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) +#ifndef __WIN__ + struct timeval tv; + tv.tv_sec = args.timeout; + tv.tv_usec = 0; +#else + int tv = args.timeout * 1000; +#endif + if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVTIMEO, +#ifndef __WIN__ + (const void *) &tv, +#else + (const char *) &tv, +#endif + sizeof(tv)) != 0) { + return errno_string("setsockopt SO_RCVTIMEO", errno, err_r); + } +#ifndef __WIN__ + tv.tv_sec = args.timeout; + tv.tv_usec = 0; +#else + tv = args.timeout * 1000; +#endif + if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDTIMEO, +#ifndef __WIN__ + (const void *) &tv, +#else + (const char *) &tv, +#endif + sizeof(tv)) != 0) { + return errno_string("setsockopt SO_RCVTIMEO", errno, err_r); + } +#endif + } +#ifndef __WIN__ + if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) { + return errno_string("fcntl O_NONBLOCK", errno, err_r); + } +#endif + if (args.sndbuf != 0) { + const int v = args.sndbuf; + if (setsockopt(fd.get(), SOL_SOCKET, SO_SNDBUF, +#ifndef __WIN__ + (const void *) &v, +#else + (const char *) &v, +#endif + sizeof(v)) != 0) { + return errno_string("setsockopt SO_SNDBUF", errno, err_r); + } + } + if (args.rcvbuf != 0) { + const int v = args.rcvbuf; + if (setsockopt(fd.get(), SOL_SOCKET, SO_RCVBUF, +#ifndef __WIN__ + (const void *) &v, +#else + (const char *) &v, +#endif + sizeof(v)) != 0) { + return errno_string("setsockopt SO_RCVBUF", errno, err_r); + } + } + return 0; +} + +int +socket_open(auto_file& fd, const socket_args& args, String& err_r) +{ + fd.reset(socket(args.family, args.socktype, args.protocol)); + if (fd.get() < 0) { + return errno_string("socket", errno, err_r); + } + return socket_set_options(fd, args, err_r); +} + +int +socket_connect(auto_file& fd, const socket_args& args, String& err_r) +{ + int r = 0; + if ((r = socket_open(fd, args, err_r)) != 0) { + return r; + } + if (connect(fd.get(), reinterpret_cast(&args.addr), + args.addrlen) != 0) { + if (!args.nonblocking +#ifndef __WIN__ + || errno != EINPROGRESS +#endif + ) { + return errno_string("connect", errno, err_r); + } + } + return 0; +} + +int +socket_bind(auto_file& fd, const socket_args& args, String& err_r) +{ + fd.reset(socket(args.family, args.socktype, args.protocol)); + if (fd.get() < 0) { + return errno_string("socket", errno, err_r); + } + if (args.reuseaddr) { +#ifndef __WIN__ + if (args.family == AF_UNIX) { + const sockaddr_un *const ap = + reinterpret_cast(&args.addr); + if (unlink(ap->sun_path) != 0 && errno != ENOENT) { + return errno_string("unlink uds", errno, err_r); + } + } else { +#endif + int v = 1; + if (setsockopt(fd.get(), SOL_SOCKET, SO_REUSEADDR, +#ifndef __WIN__ + (const void *) &v, +#else + (const char *) &v, +#endif + sizeof(v)) != 0) { + return errno_string("setsockopt SO_REUSEADDR", errno, err_r); + } +#ifndef __WIN__ + } +#endif + } + if (bind(fd.get(), reinterpret_cast(&args.addr), + args.addrlen) != 0) { + return errno_string("bind", errno, err_r); + } + if (listen(fd.get(), args.listen_backlog) != 0) { + return errno_string("listen", errno, err_r); + } +#ifndef __WIN__ + if (args.nonblocking && fcntl(fd.get(), F_SETFL, O_NONBLOCK) != 0) { + return errno_string("fcntl O_NONBLOCK", errno, err_r); + } +#endif + return 0; +} + +int +socket_accept(int listen_fd, auto_file& fd, const socket_args& args, + sockaddr_storage& addr_r, socklen_t& addrlen_r, String& err_r) +{ + fd.reset(accept(listen_fd, reinterpret_cast(&addr_r), + &addrlen_r)); + if (fd.get() < 0) { + return errno_string("accept", errno, err_r); + } + return socket_set_options(fd, args, err_r); +} + +}; + diff --git a/storage/spider/hs_client/socket.hpp b/storage/spider/hs_client/socket.hpp new file mode 100644 index 00000000000..a3e6527a46d --- /dev/null +++ b/storage/spider/hs_client/socket.hpp @@ -0,0 +1,62 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_SOCKET_HPP +#define DENA_SOCKET_HPP + +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "auto_addrinfo.hpp" +#include "auto_file.hpp" +#include "config.hpp" + +namespace dena { + +struct socket_args { + sockaddr_storage addr; + socklen_t addrlen; + int family; + int socktype; + int protocol; + int timeout; + int send_timeout; + int recv_timeout; + int listen_backlog; + bool reuseaddr; + bool nonblocking; + bool use_epoll; + int sndbuf; + int rcvbuf; + socket_args() : addr(), addrlen(0), family(AF_INET), socktype(SOCK_STREAM), + protocol(0), timeout(600), send_timeout(600), recv_timeout(600), + listen_backlog(256), reuseaddr(true), nonblocking(false), use_epoll(false), + sndbuf(0), rcvbuf(0) { } + void set(const config& conf); + void set_unix_domain(const char *path); + int resolve(const char *node, const char *service); +}; + +void ignore_sigpipe(); +int socket_set_timeout(auto_file& fd, const socket_args& args, String& err_r); +int socket_bind(auto_file& fd, const socket_args& args, String& err_r); +int socket_connect(auto_file& fd, const socket_args& args, String& err_r); +int socket_accept(int listen_fd, auto_file& fd, const socket_args& args, + sockaddr_storage& addr_r, socklen_t& addrlen_r, String& err_r); + +}; + +#endif + diff --git a/storage/spider/hs_client/string_buffer.hpp b/storage/spider/hs_client/string_buffer.hpp new file mode 100644 index 00000000000..c9a6074819b --- /dev/null +++ b/storage/spider/hs_client/string_buffer.hpp @@ -0,0 +1,146 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_STRING_BUFFER_HPP +#define DENA_STRING_BUFFER_HPP + +/* +#include +#include +*/ + +#include "util.hpp" +#include "allocator.hpp" +#include "fatal.hpp" + +namespace dena { + +struct string_buffer : private noncopyable { + string_buffer() : buffer(0), begin_offset(0), end_offset(0), alloc_size(0) { } + ~string_buffer() { + real_free(); + } + void real_free() { + if (alloc_size) { + DENA_FREE(buffer); + buffer = 0; + begin_offset = 0; + end_offset = 0; + alloc_size = 0; + } + } + size_t real_size() { + return alloc_size; + } + const char *begin() const { + return buffer + begin_offset; + } + const char *end() const { + return buffer + end_offset; + } + char *begin() { + return buffer + begin_offset; + } + char *end() { + return buffer + end_offset; + } + size_t size() const { + return end_offset - begin_offset; + } + void clear() { + begin_offset = end_offset = 0; + } + void resize(size_t len) { + if (size() < len) { + reserve(len); + memset(buffer + end_offset, 0, len - size()); + } + end_offset = begin_offset + len; + } + void reserve(size_t len) { + if (alloc_size >= begin_offset + len) { + return; + } + size_t asz = alloc_size; + while (asz < begin_offset + len) { + if (asz == 0) { + asz = 16; + } + const size_t asz_n = asz << 1; + if (asz_n < asz) { + fatal_abort("string_buffer::resize() overflow"); + } + asz = asz_n; + } + void *const p = DENA_REALLOC(buffer, asz); + if (p == 0) { + fatal_abort("string_buffer::resize() realloc"); + } + buffer = static_cast(p); + alloc_size = asz; + } + void erase_front(size_t len) { + if (len >= size()) { + clear(); + } else { + begin_offset += len; + } + } + char *make_space(size_t len) { + reserve(size() + len); + return buffer + end_offset; + } + void space_wrote(size_t len) { + len = len < alloc_size - end_offset ? len : alloc_size - end_offset; + end_offset += len; + } + template + void append_literal(const char (& str)[N]) { + append(str, str + N - 1); + } + void append(const char *start, const char *finish) { + const size_t len = finish - start; + reserve(size() + len); + memcpy(buffer + end_offset, start, len); + end_offset += len; + } + void append_2(const char *s1, const char *f1, const char *s2, + const char *f2) { + const size_t l1 = f1 - s1; + const size_t l2 = f2 - s2; + reserve(end_offset + l1 + l2); + memcpy(buffer + end_offset, s1, l1); + memcpy(buffer + end_offset + l1, s2, l2); + end_offset += l1 + l2; + } + void swap(string_buffer& sb) { + char *tmp_buffer = buffer; + size_t tmp_begin_offset = begin_offset; + size_t tmp_end_offset = end_offset; + size_t tmp_alloc_size = alloc_size; + buffer = sb.buffer; + begin_offset = sb.begin_offset; + end_offset = sb.end_offset; + alloc_size = sb.alloc_size; + sb.buffer = tmp_buffer; + sb.begin_offset = tmp_begin_offset; + sb.end_offset = tmp_end_offset; + sb.alloc_size = tmp_alloc_size; + } + private: + char *buffer; + size_t begin_offset; + size_t end_offset; + size_t alloc_size; +}; + +}; + +#endif + diff --git a/storage/spider/hs_client/string_ref.hpp b/storage/spider/hs_client/string_ref.hpp new file mode 100644 index 00000000000..028c4146c73 --- /dev/null +++ b/storage/spider/hs_client/string_ref.hpp @@ -0,0 +1,106 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_STRING_REF_HPP +#define DENA_STRING_REF_HPP + +namespace dena { + +struct string_wref { + typedef char value_type; + char *begin() const { return start; } + char *end() const { return start + length; } + size_t size() const { return length; } + private: + char *start; + size_t length; + public: + string_wref(char *s = 0, size_t len = 0) : start(s), length(len) { } +}; + +struct string_ref { + typedef const char value_type; + const char *begin() const { return start; } + const char *end() const { return start + length; } + size_t size() const { return length; } + void set(const char *s, size_t len) { start = s; length = len; } + void set(const char *s, const char *f) { start = s; length = f - s; } + private: + const char *start; + size_t length; + public: + string_ref(const char *s = 0, size_t len = 0) : start(s), length(len) { } + string_ref(const char *s, const char *f) : start(s), length(f - s) { } + string_ref(const string_wref& w) : start(w.begin()), length(w.size()) { } +}; + +template inline bool +operator ==(const string_ref& x, const char (& y)[N]) { + return (x.size() == N - 1) && (::memcmp(x.begin(), y, N - 1) == 0); +} + +inline bool +operator ==(const string_ref& x, const string_ref& y) { + return (x.size() == y.size()) && + (::memcmp(x.begin(), y.begin(), x.size()) == 0); +} + +inline bool +operator !=(const string_ref& x, const string_ref& y) { + return (x.size() != y.size()) || + (::memcmp(x.begin(), y.begin(), x.size()) != 0); +} + +struct string_ref_list_wrap { + string_ref_list_wrap() { + if (SPD_INIT_DYNAMIC_ARRAY2(&string_ref_list, sizeof(string_ref), + NULL, 16, 16, MYF(MY_WME))) + string_ref_list_init = FALSE; + else + string_ref_list_init = TRUE; + } + virtual ~string_ref_list_wrap() { + if (string_ref_list_init) delete_dynamic(&string_ref_list); } + void clear() { + if (string_ref_list_init) string_ref_list.elements = 0; } + void push_back(string_ref &e) { + if (string_ref_list_init) insert_dynamic(&string_ref_list, (uchar*) &e); + return; } + size_t size() { + return string_ref_list_init ? string_ref_list.elements : 0; } + bool resize(size_t new_size) { + if (string_ref_list_init) { + if (string_ref_list.max_element < new_size && allocate_dynamic( + &string_ref_list, new_size)) return TRUE; + string_ref_list.elements = new_size; + return FALSE; + } + return TRUE; + } + bool empty() { + return string_ref_list_init ? string_ref_list.elements ? + FALSE : TRUE : TRUE; } + string_ref &operator [](size_t n) { + return ((string_ref *) (string_ref_list.buffer + + string_ref_list.size_of_element * n))[0]; } + bool string_ref_list_init; + DYNAMIC_ARRAY string_ref_list; +}; + +inline String * +q_append_str(String *str, const char *p) { + uint32 p_len = strlen(p); + if (str->reserve(p_len)) return NULL; + str->q_append(p, p_len); return str; +} + +}; + +#endif + diff --git a/storage/spider/hs_client/string_util.cpp b/storage/spider/hs_client/string_util.cpp new file mode 100644 index 00000000000..133143165c2 --- /dev/null +++ b/storage/spider/hs_client/string_util.cpp @@ -0,0 +1,206 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#include "mysql_version.h" +#include "hs_compat.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#endif + +#include "string_util.hpp" + +namespace dena { + +string_wref +get_token(char *& wp, char *wp_end, char delim) +{ + char *const wp_begin = wp; + char *const p = memchr_char(wp_begin, delim, wp_end - wp_begin); + if (p == 0) { + wp = wp_end; + return string_wref(wp_begin, wp_end - wp_begin); + } + wp = p + 1; + return string_wref(wp_begin, p - wp_begin); +} + +uint32 +atoi_uint32_nocheck(const char *start, const char *finish) +{ + uint32 v = 0; + for (; start != finish; ++start) { + const char c = *start; + if (c < '0' || c > '9') { + break; + } + v *= 10; + v += (uint32) (c - '0'); + } + return v; +} + +long long +atoll_nocheck(const char *start, const char *finish) +{ + long long v = 0; + bool negative = false; + if (start != finish) { + if (start[0] == '-') { + ++start; + negative = true; + } else if (start[0] == '+') { + ++start; + } + } + for (; start != finish; ++start) { + const char c = *start; + if (c < '0' || c > '9') { + break; + } + v *= 10; + if (negative) { + v -= (long long) (c - '0'); + } else { + v += (long long) (c - '0'); + } + } + return v; +} + +void +append_uint32(string_buffer& buf, uint32 v) +{ + char *const wp = buf.make_space(64); + const int len = snprintf(wp, 64, "%lu", static_cast(v)); + if (len > 0) { + buf.space_wrote(len); + } +} + +/* +String * +to_stdstring(uint32 v) +{ + char buf[64]; + int str_len; + String *str; + str_len = snprintf(buf, sizeof(buf), "%lu", static_cast(v)); + if ((str = new String(str_len + 1))) + str->q_append(buf, str_len); + return str; +} +*/ + +int +errno_string(const char *s, int en, String& err_r) +{ + char buf[64]; + int str_len; + str_len = snprintf(buf, sizeof(buf), "%s: %d", s, en); + if (!err_r.reserve(str_len + 1)) + err_r.q_append(buf, str_len); + return en; +} + +size_t +split(char delim, const string_ref& buf, string_ref *parts, + size_t parts_len) +{ + size_t i = 0; + const char *start = buf.begin(); + const char *const finish = buf.end(); + for (i = 0; i < parts_len; ++i) { + const char *const p = memchr_char(start, delim, finish - start); + if (p == 0) { + parts[i] = string_ref(start, finish - start); + ++i; + break; + } + parts[i] = string_ref(start, p - start); + start = p + 1; + } + const size_t r = i; + for (; i < parts_len; ++i) { + parts[i] = string_ref(); + } + return r; +} + +size_t +split(char delim, const string_wref& buf, string_wref *parts, + size_t parts_len) +{ + size_t i = 0; + char *start = buf.begin(); + char *const finish = buf.end(); + for (i = 0; i < parts_len; ++i) { + char *const p = memchr_char(start, delim, finish - start); + if (p == 0) { + parts[i] = string_wref(start, finish - start); + ++i; + break; + } + parts[i] = string_wref(start, p - start); + start = p + 1; + } + const size_t r = i; + for (; i < parts_len; ++i) { + parts[i] = string_wref(); + } + return r; +} + +size_t +split(char delim, const string_ref& buf, DYNAMIC_ARRAY& parts_r) +{ + size_t i = 0; + const char *start = buf.begin(); + const char *finish = buf.end(); + while (true) { + const char *p = memchr_char(start, delim, finish - start); + if (p == 0) { + string_ref param(start, finish - start); + insert_dynamic(&parts_r, (uchar *) ¶m); + break; + } + string_ref param(start, p - start); + insert_dynamic(&parts_r, (uchar *) ¶m); + start = p + 1; + } + const size_t r = i; + return r; +} + +size_t +split(char delim, const string_wref& buf, DYNAMIC_ARRAY& parts_r) +{ + size_t i = 0; + char *start = buf.begin(); + char *finish = buf.end(); + while (true) { + char *p = memchr_char(start, delim, finish - start); + if (p == 0) { + string_wref param(start, finish - start); + insert_dynamic(&parts_r, (uchar *) ¶m); + break; + } + string_wref param(start, p - start); + insert_dynamic(&parts_r, (uchar *) ¶m); + start = p + 1; + } + const size_t r = i; + return r; +} + +}; + diff --git a/storage/spider/hs_client/string_util.hpp b/storage/spider/hs_client/string_util.hpp new file mode 100644 index 00000000000..b886addecfb --- /dev/null +++ b/storage/spider/hs_client/string_util.hpp @@ -0,0 +1,51 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_STRING_UTIL_HPP +#define DENA_STRING_UTIL_HPP + +#include "string_buffer.hpp" +#include "string_ref.hpp" + +namespace dena { + +inline const char * +memchr_char(const char *s, int c, size_t n) +{ + return static_cast(memchr(s, c, n)); +} + +inline char * +memchr_char(char *s, int c, size_t n) +{ + return static_cast(memchr(s, c, n)); +} + +string_wref get_token(char *& wp, char *wp_end, char delim); +uint32 atoi_uint32_nocheck(const char *start, const char *finish); +/* +String *to_stdstring(uint32 v); +*/ +void append_uint32(string_buffer& buf, uint32 v); +long long atoll_nocheck(const char *start, const char *finish); + +int errno_string(const char *s, int en, String& err_r); + +size_t split(char delim, const string_ref& buf, string_ref *parts, + size_t parts_len); +size_t split(char delim, const string_wref& buf, string_wref *parts, + size_t parts_len); +size_t split(char delim, const string_ref& buf, + DYNAMIC_ARRAY& parts_r); +size_t split(char delim, const string_wref& buf, + DYNAMIC_ARRAY& parts_r); +}; + +#endif + diff --git a/storage/spider/hs_client/thread.hpp b/storage/spider/hs_client/thread.hpp new file mode 100644 index 00000000000..79fba706a42 --- /dev/null +++ b/storage/spider/hs_client/thread.hpp @@ -0,0 +1,84 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010-2011 DeNA Co.,Ltd.. All rights reserved. + * Copyright (C) 2011 Kentoku SHIBA + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_THREAD_HPP +#define DENA_THREAD_HPP + +#include "fatal.hpp" + +namespace dena { + +/* +template +struct thread : private noncopyable { + template thread(const Ta& arg, size_t stack_sz = 256 * 1024) + : obj(arg), thr(0), need_join(false), stack_size(stack_sz) { } + template thread(const Ta0& a0, + volatile Ta1& a1, size_t stack_sz = 256 * 1024) + : obj(a0, a1), thr(0), need_join(false), stack_size(stack_sz) { } + ~thread() { + join(); + } + void start() { + if (!start_nothrow()) { + fatal_abort("thread::start"); + } + } + bool start_nothrow() { + if (need_join) { + return need_join; + } + void *const arg = this; + pthread_attr_t attr; + if (pthread_attr_init(&attr) != 0) { + fatal_abort("pthread_attr_init"); + } + if (pthread_attr_setstacksize(&attr, stack_size) != 0) { + fatal_abort("pthread_attr_setstacksize"); + } + const int r = pthread_create(&thr, &attr, thread_main, arg); + if (pthread_attr_destroy(&attr) != 0) { + fatal_abort("pthread_attr_destroy"); + } + if (r != 0) { + return need_join; + } + need_join = true; + return need_join; + } + void join() { + if (!need_join) { + return; + } + int e = 0; + if ((e = pthread_join(thr, 0)) != 0) { + fatal_abort("pthread_join"); + } + need_join = false; + } + T& operator *() { return obj; } + T *operator ->() { return &obj; } + private: + static void *thread_main(void *arg) { + thread *p = static_cast(arg); + p->obj(); + return 0; + } + private: + T obj; + pthread_t thr; + bool need_join; + size_t stack_size; +}; +*/ + +}; + +#endif + diff --git a/storage/spider/hs_client/util.hpp b/storage/spider/hs_client/util.hpp new file mode 100644 index 00000000000..93d78cc7dc0 --- /dev/null +++ b/storage/spider/hs_client/util.hpp @@ -0,0 +1,25 @@ + +// vim:sw=2:ai + +/* + * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. + * See COPYRIGHT.txt for details. + */ + +#ifndef DENA_UTIL_HPP +#define DENA_UTIL_HPP + +namespace dena { + +/* boost::noncopyable */ +struct noncopyable { + noncopyable() { } + private: + noncopyable(const noncopyable&); + noncopyable& operator =(const noncopyable&); +}; + +}; + +#endif + diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child3_1.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child3_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child3_2.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child3_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_child3_3.inc b/storage/spider/mysql-test/spider/bg/include/deinit_child3_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_master_1.inc b/storage/spider/mysql-test/spider/bg/include/deinit_master_1.inc new file mode 100644 index 00000000000..c19e376d10a --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/deinit_master_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/bg/include/deinit_slave1_1.inc b/storage/spider/mysql-test/spider/bg/include/deinit_slave1_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_1.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_2.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_2.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_2.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_3.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_3.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_3.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/bg/include/ha_deinit_master_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_1.inc new file mode 100644 index 00000000000..59c0175d349 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_1.inc @@ -0,0 +1,8 @@ +let $CHILD2_1_HA_AS_DROP_TABLES= + $CHILD2_1_DROP_TABLES; +let $CHILD2_1_HA_AS_CREATE_TABLES= + $CHILD2_1_CREATE_TABLES; +let $CHILD2_1_HA_AS_DROP_TABLES2= + $CHILD2_1_DROP_TABLES2; +let $CHILD2_1_HA_AS_CREATE_TABLES2= + $CHILD2_1_CREATE_TABLES2; diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_2.inc new file mode 100644 index 00000000000..90d27ed704d --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_2.inc @@ -0,0 +1,4 @@ +let $CHILD2_2_HA_DROP_TABLES= + $CHILD2_2_DROP_TABLES; +let $CHILD2_2_HA_CREATE_TABLES= + $CHILD2_2_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_3.inc new file mode 100644 index 00000000000..11abf112b1f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child2_3.inc @@ -0,0 +1,4 @@ +let $CHILD2_3_HA_DROP_TABLES= + $CHILD2_3_DROP_TABLES; +let $CHILD2_3_HA_CREATE_TABLES= + $CHILD2_3_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child3_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_1.inc new file mode 100644 index 00000000000..56de7df4e52 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_1.inc @@ -0,0 +1,140 @@ +--let $CHILD3_1_ENGINE_TYPE=Spider +--let $CHILD3_1_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_1_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_1_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_1_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child3_2.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_2.inc new file mode 100644 index 00000000000..fdb3a84cca7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_2.inc @@ -0,0 +1,140 @@ +--let $CHILD3_2_ENGINE_TYPE=Spider +--let $CHILD3_2_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_2_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_2_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_2_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_2_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_2_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_2_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_2_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_2_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_2_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_2_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_child3_3.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_3.inc new file mode 100644 index 00000000000..d08ff4d0d34 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_child3_3.inc @@ -0,0 +1,140 @@ +--let $CHILD3_3_ENGINE_TYPE=Spider +--let $CHILD3_3_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_3_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_3_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_3_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_3_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_3_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_3_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_3_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_3_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_3_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_3_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/bg/include/ha_init_master_1.inc b/storage/spider/mysql-test/spider/bg/include/ha_init_master_1.inc new file mode 100644 index 00000000000..78797d80ce7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/ha_init_master_1.inc @@ -0,0 +1,105 @@ +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $MASTER_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $MASTER_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $MASTER_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $MASTER_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $MASTER_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +let $MASTER_1_COPY_TABLES_2_1= + SELECT spider_copy_tables('ta_l', '0', '1'); + +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $MASTER_1_COMMENT_HA_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_COMMENT_HA_AS_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $MASTER_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $MASTER_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +let $MASTER_1_COPY_TABLES_P_2_1= + SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +let $MASTER_1_CHECK_HA_STATUS= + SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +let $MASTER_1_CHANGE_HA_MON= + SELECT spider_flush_table_mon_cache(); diff --git a/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/hs_deinit_master_1.inc b/storage/spider/mysql-test/spider/bg/include/hs_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/hs_init_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/hs_init_child2_1.inc new file mode 100644 index 00000000000..2ea1c0c9cd6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/hs_init_child2_1.inc @@ -0,0 +1,24 @@ +let $CHILD2_1_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r; +let $CHILD2_1_HS_CREATE_TABLES= + CREATE TABLE hs_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r ORDER BY a; +let $CHILD2_1_HS_DROP_TABLES2= + DROP TABLE IF EXISTS hs_r2; +let $CHILD2_1_HS_CREATE_TABLES2= + CREATE TABLE hs_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r2 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/bg/include/hs_init_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/hs_init_child2_2.inc new file mode 100644 index 00000000000..7c69d73ced6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/hs_init_child2_2.inc @@ -0,0 +1,12 @@ +let $CHILD2_2_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r3; +let $CHILD2_2_HS_CREATE_TABLES= + CREATE TABLE hs_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r3 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/bg/include/hs_init_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/hs_init_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/hs_init_master_1.inc b/storage/spider/mysql-test/spider/bg/include/hs_init_master_1.inc new file mode 100644 index 00000000000..a43e995647e --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/hs_init_master_1.inc @@ -0,0 +1,12 @@ +let $MASTER_1_HS_COMMENT_TMP= + COMMENT=''; +let $MASTER_1_HS_COMMENT_2_1= + COMMENT='srv "s_2_1", table "hs_r", uhr "1", uhw "1", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT", hwr "0"'; +let $MASTER_1_HS_COMMENT_P_2_1= + COMMENT='uhr "1", uhw "1", hwr "0"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) + COMMENT='srv "s_2_1", table "hs_r2", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", table "hs_r3", hrp "$CHILD2_2_HSRPORT", hwp "$CHILD2_2_HSWPORT"' + ); diff --git a/storage/spider/mysql-test/spider/bg/include/init_child2_1.inc b/storage/spider/mysql-test/spider/bg/include/init_child2_1.inc new file mode 100644 index 00000000000..6e25765f25e --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/init_child2_1.inc @@ -0,0 +1,175 @@ +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r; +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +let $CHILD2_1_DROP_TABLES2= + DROP TABLE IF EXISTS ta_r2; +let $CHILD2_1_CREATE_TABLES2= + CREATE TABLE ta_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r2 ORDER BY a; +let $CHILD2_1_DROP_TABLES3= + DROP TABLE IF EXISTS ta_r_no_idx; +let $CHILD2_1_CREATE_TABLES3= + CREATE TABLE ta_r_no_idx ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES3= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_no_idx ORDER BY a; +let $CHILD2_1_DROP_TABLES4= + DROP TABLE IF EXISTS ta_r_auto_inc; +let $CHILD2_1_CREATE_TABLES4= + CREATE TABLE ta_r_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES4= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_auto_inc + ORDER BY a; +let $CHILD2_1_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_1_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES5= + SELECT a, b, c FROM ta_r_int ORDER BY a; +let $CHILD2_1_DROP_TABLES6= + DROP TABLE IF EXISTS ta_r_3; +let $CHILD2_1_CREATE_TABLES6= + CREATE TABLE ta_r_3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES6= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_3 ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r; +let $CHILD2_1_CREATE_FT_TABLES= + CREATE TABLE ft_r ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES2= + DROP TABLE IF EXISTS ft_r2; +let $CHILD2_1_CREATE_FT_TABLES2= + CREATE TABLE ft_r2 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES2= + SELECT a, b, c, d FROM ft_r2 ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r; +let $CHILD2_1_CREATE_GM_TABLES= + CREATE TABLE gm_r ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES2= + DROP TABLE IF EXISTS gm_r2; +let $CHILD2_1_CREATE_GM_TABLES2= + CREATE TABLE gm_r2 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES2= + SELECT a, b, c FROM gm_r2 ORDER BY a; +let $CHILD2_1_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_LOCK_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_2; +let $CHILD2_1_CREATE_LOCK_TABLES2= + CREATE TABLE t2_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_1 ORDER BY id; +let $CHILD2_1_DROP_TEXT_PK_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_PK_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY (a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET2; +let $CHILD2_1_SELECT_TEXT_PK_TABLES1= + SELECT a FROM t1 ORDER BY a; +let $CHILD2_1_DROP_TEXT_KEY_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_KEY_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TEXT_KEY_TABLES1= + SELECT a, b FROM t1 ORDER BY a, b; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_1_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_1_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 2; diff --git a/storage/spider/mysql-test/spider/bg/include/init_child2_2.inc b/storage/spider/mysql-test/spider/bg/include/init_child2_2.inc new file mode 100644 index 00000000000..3524fc4a2b7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/init_child2_2.inc @@ -0,0 +1,80 @@ +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS ta_r3; +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE ta_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_2_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r3 ORDER BY a; +let $CHILD2_2_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r3; +let $CHILD2_2_CREATE_FT_TABLES= + CREATE TABLE ft_r3 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_2_FT_ENGINE $CHILD2_2_FT_CHARSET; +let $CHILD2_2_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r3 ORDER BY a; +let $CHILD2_2_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r3; +let $CHILD2_2_CREATE_GM_TABLES= + CREATE TABLE gm_r3 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_2_GM_ENGINE $CHILD2_2_GM_CHARSET; +let $CHILD2_2_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r3 ORDER BY a; +let $CHILD2_2_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_LOCK_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_1; +let $CHILD2_2_CREATE_LOCK_TABLES2= + CREATE TABLE t2_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_2 ORDER BY id; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_2_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_2_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 3; diff --git a/storage/spider/mysql-test/spider/bg/include/init_child2_3.inc b/storage/spider/mysql-test/spider/bg/include/init_child2_3.inc new file mode 100644 index 00000000000..d857a787ac0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/init_child2_3.inc @@ -0,0 +1,11 @@ +let $CHILD2_3_DROP_TABLES= + DROP TABLE IF EXISTS ta_r4; +let $CHILD2_3_CREATE_TABLES= + CREATE TABLE ta_r4 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_3_ENGINE $CHILD2_3_CHARSET; +let $CHILD2_3_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r4 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/bg/include/init_child3_1.inc b/storage/spider/mysql-test/spider/bg/include/init_child3_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/init_child3_2.inc b/storage/spider/mysql-test/spider/bg/include/init_child3_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/init_child3_3.inc b/storage/spider/mysql-test/spider/bg/include/init_child3_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/bg/include/init_master_1.inc b/storage/spider/mysql-test/spider/bg/include/init_master_1.inc new file mode 100644 index 00000000000..d6e302a6e1f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/init_master_1.inc @@ -0,0 +1,194 @@ +--source ../../include/init_spider.inc +SET spider_internal_sql_log_off= 0; +SET spider_bgs_mode= 1; +SET spider_bgs_first_read= 2; +SET spider_bgs_second_read= 2; +SET spider_split_read= 2; +SET spider_conn_recycle_mode= 2; +SET spider_multi_split_read= 1; +SET spider_reset_sql_alloc= 0; +SET spider_bulk_update_size= 40; +SET spider_direct_order_limit= 10000; +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password "", prt "2000000"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password "", prt "2000000"'; +} +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1", table "ta_r2", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT2_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ta_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT3_P_2_1= + COMMENT='table "ta_r_int"' + PARTITION BY LIST(MOD(a, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='srv "s_2_1", priority "1000"', + PARTITION pt2 VALUES IN (1) + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT2_FT_P_2_1= + COMMENT='table "ft_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ft_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_GM_2_1= + COMMENT='srv "s_2_1", table "gm_r"'; +let $MASTER_1_COMMENT2_GM_P_2_1= + COMMENT='table "gm_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "gm_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_LOCK1= + COMMENT 'tbl "t1_1 t1_2", srv "s_2_1 s_2_2"'; +let $MASTER_1_COMMENT_LOCK2= + COMMENT 'tbl "t2_1 t2_2", srv "s_2_2 s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_1= + COMMENT 'aim "1", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_P_1= + COMMENT 'aim "1"' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='tbl "t1_1", srv "s_2_1"', + PARTITION pt2 VALUES IN (1) + COMMENT='tbl "t1_2", srv "s_2_2"' + ); +let $MASTER_1_COMMENT_READONLY1_1= + COMMENT 'read_only_mode "1", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_ERROR_MODE1_1= + COMMENT 'erm "1", ewm "1", tbl "ter1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_PK1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_KEY1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_update'; +let $MASTER_1_CHECK_DIRECT_DELETE_STATUS= + SHOW STATUS LIKE 'Spider_direct_delete'; +let $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS= + SHOW STATUS LIKE 'Spider_direct_order_limit'; +let $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_aggregate'; +let $MASTER_1_AUTO_INCREMENT_INCREMENT1= + SET SESSION AUTO_INCREMENT_INCREMENT = 1 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_INCREMENT2= + SET SESSION AUTO_INCREMENT_INCREMENT = 777 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET1= + SET SESSION AUTO_INCREMENT_OFFSET = 1 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET2= + SET SESSION AUTO_INCREMENT_OFFSET = 777 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET3= + SET SESSION AUTO_INCREMENT_OFFSET = 1; +let $MASTER_1_AUTO_INCREMENT_OFFSET4= + SET SESSION AUTO_INCREMENT_OFFSET = 777; diff --git a/storage/spider/mysql-test/spider/bg/include/init_slave1_1.inc b/storage/spider/mysql-test/spider/bg/include/init_slave1_1.inc new file mode 100644 index 00000000000..87c05f1f690 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/include/init_slave1_1.inc @@ -0,0 +1,10 @@ +let $SLAVE1_1_COMMENT_INCREMENT1_1= + COMMENT ''; +let $SLAVE1_1_COMMENT_INCREMENT1_P_1= + COMMENT '' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='', + PARTITION pt2 VALUES IN (1) + COMMENT='' + ); diff --git a/storage/spider/mysql-test/spider/bg/my.cnf b/storage/spider/mysql-test/spider/bg/my.cnf new file mode 100644 index 00000000000..7f9d7c44c05 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/my.cnf @@ -0,0 +1,176 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld.1.1] +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[mysqld.2.1] +loose_handlersocket_port= 20002 +loose_handlersocket_port_wr= 20003 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.2] +loose_handlersocket_port= 20004 +loose_handlersocket_port_wr= 20005 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.3] + +[mysqld.3.1] +loose_partition= 1 + +[mysqld.3.2] +loose_partition= 1 + +[mysqld.3.3] +loose_partition= 1 + +[mysqld.4.1] +loose_partition= 1 + + +[ENV] +USE_GEOMETRY_TEST= 1 +USE_FULLTEXT_TEST= 1 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 1 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +SLAVE1_1_MYPORT= @mysqld.4.1.port +SLAVE1_1_MYSOCK= @mysqld.4.1.socket +SLAVE1_1_ENGINE_TYPE= MyISAM +SLAVE1_1_ENGINE= ENGINE=MyISAM +SLAVE1_1_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.2.1.port +CHILD2_1_HSRPORT= 20002 +CHILD2_1_HSWPORT= 20003 +CHILD2_1_MYSOCK= @mysqld.2.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_2_MYPORT= @mysqld.2.2.port +CHILD2_2_HSRPORT= 20004 +CHILD2_2_HSWPORT= 20005 +CHILD2_2_MYSOCK= @mysqld.2.2.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_3_MYPORT= @mysqld.2.3.port +CHILD2_3_MYSOCK= @mysqld.2.3.socket +CHILD2_3_ENGINE_TYPE= InnoDB +CHILD2_3_ENGINE= ENGINE=InnoDB +CHILD2_3_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_FT_MYPORT= @mysqld.1.1.port +CHILD2_1_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.2.2.port +CHILD2_2_FT_MYSOCK= @mysqld.2.2.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.2.1.port +CHILD2_1_GM_MYSOCK= @mysqld.2.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.2.2.port +CHILD2_2_GM_MYSOCK= @mysqld.2.2.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP3= 1 +OUTPUT_CHILD_GROUP3= 0 +CHILD3_1_MYPORT= @mysqld.3.1.port +CHILD3_1_MYSOCK= @mysqld.3.1.socket +CHILD3_1_ENGINE_TYPE= InnoDB +CHILD3_1_ENGINE= ENGINE=InnoDB +CHILD3_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_2_MYPORT= @mysqld.3.2.port +CHILD3_2_MYSOCK= @mysqld.3.2.socket +CHILD3_2_ENGINE_TYPE= InnoDB +CHILD3_2_ENGINE= ENGINE=InnoDB +CHILD3_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_3_MYPORT= @mysqld.3.3.port +CHILD3_3_MYSOCK= @mysqld.3.3.socket +CHILD3_3_ENGINE_TYPE= InnoDB +CHILD3_3_ENGINE= ENGINE=InnoDB +CHILD3_3_CHARSET= DEFAULT CHARSET=utf8 + +STR_SEMICOLON= ; + +#The followings are setted in include/init_xxx.inc files +#MASTER_1_COMMENT_2_1 +#MASTER_1_COMMENT2_2_1 +#MASTER_1_COMMENT3_2_1 +#MASTER_1_COMMENT4_2_1 +#MASTER_1_COMMENT5_2_1 +#MASTER_1_COMMENT_P_2_1 +#CHILD2_1_DROP_TABLES +#CHILD2_1_CREATE_TABLES +#CHILD2_1_SELECT_TABLES +#CHILD2_1_DROP_TABLES2 +#CHILD2_1_CREATE_TABLES2 +#CHILD2_1_SELECT_TABLES2 +#CHILD2_1_DROP_TABLES3 +#CHILD2_1_CREATE_TABLES3 +#CHILD2_1_SELECT_TABLES3 +#CHILD2_1_DROP_TABLES4 +#CHILD2_1_CREATE_TABLES4 +#CHILD2_1_SELECT_TABLES4 +#CHILD2_1_DROP_TABLES5 +#CHILD2_1_CREATE_TABLES5 +#CHILD2_1_SELECT_TABLES5 +#CHILD2_1_DROP_TABLES6 +#CHILD2_1_CREATE_TABLES6 +#CHILD2_1_SELECT_TABLES6 +#CHILD2_2_DROP_TABLES +#CHILD2_2_CREATE_TABLES +#CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/bg/r/basic_sql.result b/storage/spider/mysql-test/spider/bg/r/basic_sql.result new file mode 100644 index 00000000000..e6202327ef6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/basic_sql.result @@ -0,0 +1,701 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'f', '2008-07-01 10:21:39'), +(2, 'g', '2000-02-01 00:00:00'), +(3, 'j', '2007-05-04 20:03:11'), +(4, 'i', '2003-10-30 05:01:03'), +(5, 'h', '2001-10-31 23:59:59'); +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l +Warnings: +Warning 1062 Duplicate entry '1' for key 'PRIMARY' +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +Warning 1062 Duplicate entry '3' for key 'PRIMARY' +Warning 1062 Duplicate entry '4' for key 'PRIMARY' +Warning 1062 Duplicate entry '5' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create table with partition and select test +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create no index table +DROP TABLE IF EXISTS ta_l_no_idx; +CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table shared mode +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table for update +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table join +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table straight_join +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_small_result +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_big_result +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_buffer_result +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_cache +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_no_cache +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_calc_found_rows +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +SELECT found_rows(); +found_rows() +5 + +select high_priority +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select distinct +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select count +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select using index and pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using index pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +insert select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 + +insert low_priority +TRUNCATE TABLE ta_l; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert high_priority +TRUNCATE TABLE ta_l; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert ignore +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +Warnings: +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (insert) +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (update) +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2005-08-08 11:11:11 + +replace +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2008-02-02 02:02:02 + +replace select +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace select a +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace low_priority +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 g 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 h 2010-04-04 04:04:04 +2 g 2009-03-03 03:03:03 + +update join +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update partition pushdown +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 e 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update partition index pushdown +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete all +DELETE FROM ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE IGNORE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE QUICK FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete partition index pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +truncate +TRUNCATE TABLE ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/direct_aggregate.result b/storage/spider/mysql-test/spider/bg/r/direct_aggregate.result new file mode 100644 index 00000000000..7bf1cb4aea7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_aggregate.result @@ -0,0 +1,132 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_aggregating test +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/direct_update.result b/storage/spider/mysql-test/spider/bg/r/direct_update.result new file mode 100644 index 00000000000..135734641c1 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_update.result @@ -0,0 +1,226 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_updating test +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l2 SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l2 SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l2 WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l2 WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/function.result b/storage/spider/mysql-test/spider/bg/r/function.result new file mode 100644 index 00000000000..764c774514b --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/function.result @@ -0,0 +1,149 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +in() +CREATE TABLE t1 ( +a VARCHAR(255), +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1 +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-08-01 10:21:39 +2 b 1999-01-01 00:00:00 +3 e 2006-06-04 20:03:11 +4 d 2002-11-30 05:01:03 +5 c 2000-12-31 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-11-01 10:21:39 +2 b 1999-04-01 00:00:00 +3 e 2006-09-04 20:03:11 +4 d 2003-02-28 05:01:03 +5 c 2001-03-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-01 10:21:39 +2 b 1999-03-01 00:00:00 +3 e 2006-08-04 20:03:11 +4 d 2003-01-28 05:01:03 +5 c 2001-02-28 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-08 10:21:39 +2 b 1999-03-08 00:00:00 +3 e 2006-08-11 20:03:11 +4 d 2003-02-04 05:01:03 +5 c 2001-03-07 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 10:21:39 +2 b 1999-03-07 00:00:00 +3 e 2006-08-10 20:03:11 +4 d 2003-02-03 05:01:03 +5 c 2001-03-06 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:21:39 +2 b 1999-03-07 01:00:00 +3 e 2006-08-10 21:03:11 +4 d 2003-02-03 06:01:03 +5 c 2001-03-07 00:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:39 +2 b 1999-03-07 00:59:00 +3 e 2006-08-10 21:02:11 +4 d 2003-02-03 06:00:03 +5 c 2001-03-07 00:58:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:40 +2 b 1999-03-07 00:59:01 +3 e 2006-08-10 21:02:12 +4 d 2003-02-03 06:00:04 +5 c 2001-03-07 00:59:00 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/ha.result b/storage/spider/mysql-test/spider/bg/r/ha.result new file mode 100644 index 00000000000..e05ecb32e1b --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/ha.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +test select 1 +SELECT 1; +1 +1 + +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 0 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote2.ta_r3' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 2 +SELECT spider_copy_tables('ta_l', '0', '1'); +spider_copy_tables('ta_l', '0', '1') +1 +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote3.ta_r4' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 2 +SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +spider_copy_tables('ta_l2#P#pt2', '0', '1') +1 +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +active standby test +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 3 +auto_test_local ta_l 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r2' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 3 +auto_test_local ta_l2#P#pt2 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +auto_test_local ta_l2#P#pt2 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 3 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result b/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result new file mode 100644 index 00000000000..a570e542771 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result @@ -0,0 +1,371 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +3.1 +auto_increment +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +778 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT id FROM t1 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3109 +3886 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT id FROM t2 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3108 +3109 +3885 +3886 +4662 +5439 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +auto_increment with partition +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +778 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT id FROM t1 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3109 +3886 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT id FROM t2 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3108 +3109 +3885 +3886 +4662 +5439 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/spider_fixes.result b/storage/spider/mysql-test/spider/bg/r/spider_fixes.result new file mode 100644 index 00000000000..aedde01e178 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider_fixes.result @@ -0,0 +1,692 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +2.13 +select table with "order by desc" and "<" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 +2 b 2000-01-01 00:00:00 + +select table with "order by desc" and "<=" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +5 c 2001-12-31 23:59:59 +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 + +2.14 +update table with range scan and split_read +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-02-02 00:00:00 +3 e 2000-02-02 00:00:00 +4 d 2000-02-02 00:00:00 +5 c 2000-02-02 00:00:00 + +2.15 +select table with range scan +TRUNCATE TABLE ta_l; +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a int(11) NOT NULL DEFAULT '0', +b char(1) DEFAULT NULL, +c datetime DEFAULT NULL, +PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +CREATE TABLE ta_l_auto_inc ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tc_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END;; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 s 2008-12-31 20:59:59 + +2.17 +engine-condition-pushdown with "or" and joining +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +partition with sort +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +2.23 +partition update with moving partition +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); +UPDATE ta_l2 SET a = 4 WHERE a = 3; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 B 2010-09-26 00:00:00 +index merge +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 +index merge with partition +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT NOT NULL, +b INT DEFAULT 10, +c INT DEFAULT 11, +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +UPDATE ta_l_int SET c = 4 WHERE b = 2; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +1 2 4 +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +17 2 4 + +2.25 +direct order limit +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 0 +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +a b c +1 2 4 +2 3 4 +4 5 6 +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 0 + +2.26 +lock tables +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1 +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 + +auto_increment with partition +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 + +read only +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1 +SELECT id FROM t1 ORDER BY id; +id +1000 +1554 +3108 +4662 +5000 +6216 +10000 +INSERT INTO t1 (id) VALUES (1); +ERROR HY000: Table 'auto_test_local.t1' is read only +UPDATE t1 SET id = 4 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1; +ERROR HY000: Table 'auto_test_local.t1' is read only +TRUNCATE t1; +ERROR HY000: Table 'auto_test_local.t1' is read only + +2.27 +error mode +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1 +SELECT id FROM t1 ORDER BY id; +id +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +INSERT INTO t1 (id) VALUES (1); +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +DELETE FROM t1; +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +TRUNCATE t1; +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist + +3.0 +is null +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a VARCHAR(255), +b VARCHAR(255), +c VARCHAR(255), +KEY idx1(a,b), +KEY idx2(b), +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1 +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +select a from t1 where a is null order by a limit 30; +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +select b from t1 where b is null order by b limit 30; +b +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +direct_order_limit +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +a b c +10 74 74 +10 42 42 +10 234 234 +10 202 202 +10 170 170 +select a, c from t1 where a = '10' order by b desc limit 5; +a c +10 74 +10 42 +10 234 +10 202 +10 170 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/r/vp_fixes.result b/storage/spider/mysql-test/spider/bg/r/vp_fixes.result new file mode 100644 index 00000000000..15dd29aa4d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/vp_fixes.result @@ -0,0 +1,80 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +0.9 +create different primary key table +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT AUTO_INCREMENT, +c INT DEFAULT 11, +PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT DEFAULT 12, +c INT DEFAULT 11, +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/bg/suite.opt b/storage/spider/mysql-test/spider/bg/suite.opt new file mode 100644 index 00000000000..48457b17309 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/suite.opt @@ -0,0 +1 @@ +--loose-innodb diff --git a/storage/spider/mysql-test/spider/bg/suite.pm b/storage/spider/mysql-test/spider/bg/suite.pm new file mode 100644 index 00000000000..5569c57bec9 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/suite.pm @@ -0,0 +1,9 @@ +package My::Suite::Spider; + +@ISA = qw(My::Suite); + +return "No Spider engine" unless $ENV{HA_SPIDER_SO}; +return "Not run for embedded server" if $::opt_embedded_server; + +bless { }; + diff --git a/storage/spider/mysql-test/spider/bg/t/basic_sql.test b/storage/spider/mysql-test/spider/bg/t/basic_sql.test new file mode 100644 index 00000000000..2264b0e4e37 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/basic_sql.test @@ -0,0 +1,3189 @@ +# This test tests by executing basic SQL +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'f', '2008-07-01 10:21:39'), + (2, 'g', '2000-02-01 00:00:00'), + (3, 'j', '2007-05-04 20:03:11'), + (4, 'i', '2003-10-30 05:01:03'), + (5, 'h', '2001-10-31 23:59:59'); +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT IGNORE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + REPLACE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%replace %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table with partition and select test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + } + --enable_query_log + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo create no index table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES3; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_no_idx; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_NEEDPK) +{ + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + } +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES3; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; + +--echo +--echo select table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table shared mode +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table for update +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table straight_join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_small_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_big_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_buffer_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_no_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_calc_found_rows +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT found_rows(); + +--echo +--echo select high_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select distinct +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select count +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT count(*) FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join not use index +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using index and pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select partition using pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo select partition using index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.a > 0 AND a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo insert +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select a +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert low_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert high_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (insert) +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (update) +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update index pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update partition pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo update partition index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete all +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE IGNORE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE QUICK FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete partition pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete partition index pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo truncate +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'truncate %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/bg/t/connect_child2_1.inc new file mode 100644 index 00000000000..cd9b0c9ca9b --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child2_1.inc @@ -0,0 +1 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/bg/t/connect_child2_2.inc new file mode 100644 index 00000000000..e145f66b630 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child2_2.inc @@ -0,0 +1 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child2_3.inc b/storage/spider/mysql-test/spider/bg/t/connect_child2_3.inc new file mode 100644 index 00000000000..d356348d8ea --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child2_3.inc @@ -0,0 +1 @@ +--connect (child2_3, localhost, root, , , $CHILD2_3_MYPORT, $CHILD2_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child3_1.inc b/storage/spider/mysql-test/spider/bg/t/connect_child3_1.inc new file mode 100644 index 00000000000..03e5c188c89 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child3_1.inc @@ -0,0 +1 @@ +--connect (child3_1, localhost, root, , , $CHILD3_1_MYPORT, $CHILD3_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child3_2.inc b/storage/spider/mysql-test/spider/bg/t/connect_child3_2.inc new file mode 100644 index 00000000000..d62a7ada824 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child3_2.inc @@ -0,0 +1 @@ +--connect (child3_2, localhost, root, , , $CHILD3_2_MYPORT, $CHILD3_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_child3_3.inc b/storage/spider/mysql-test/spider/bg/t/connect_child3_3.inc new file mode 100644 index 00000000000..fb49f5bfdac --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_child3_3.inc @@ -0,0 +1 @@ +--connect (child3_3, localhost, root, , , $CHILD3_3_MYPORT, $CHILD3_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_master_1.inc b/storage/spider/mysql-test/spider/bg/t/connect_master_1.inc new file mode 100644 index 00000000000..0c129ce5775 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_master_1.inc @@ -0,0 +1 @@ +--connect (master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/connect_slave1_1.inc b/storage/spider/mysql-test/spider/bg/t/connect_slave1_1.inc new file mode 100644 index 00000000000..45a822743e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/connect_slave1_1.inc @@ -0,0 +1 @@ +--connect (slave1_1, localhost, root, , , $SLAVE1_1_MYPORT, $SLAVE1_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/bg/t/direct_aggregate.test b/storage/spider/mysql-test/spider/bg/t/direct_aggregate.test new file mode 100644 index 00000000000..59c45f3f190 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_aggregate.test @@ -0,0 +1,316 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_aggregating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT COUNT(*) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l WHERE a < 5; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/direct_update.test b/storage/spider/mysql-test/spider/bg/t/direct_update.test new file mode 100644 index 00000000000..1c3ce91ff3f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_update.test @@ -0,0 +1,354 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_updating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key +DELETE FROM ta_l WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update all rows with function + UPDATE ta_l2 SET c = ADDDATE(c, 1); + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key + UPDATE ta_l2 SET b = 'x' WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by a column without index + UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key with order and limit + UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key with order and limit + DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by a column without index + DELETE FROM ta_l2 WHERE b = 'c'; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key + DELETE FROM ta_l2 WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/function.test b/storage/spider/mysql-test/spider/bg/t/function.test new file mode 100644 index 00000000000..2b1b53c8a4f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/function.test @@ -0,0 +1,276 @@ +# This test tests for using functions +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo in() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_PK_TABLES1; + echo CHILD2_1_CREATE_TEXT_PK_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_PK_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_PK_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET3 $MASTER_1_COMMENT_TEXT_PK1_1; +--enable_query_log +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a in ('15', '120'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo date_sub() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/ha.test b/storage/spider/mysql-test/spider/bg/t/ha.test new file mode 100644 index 00000000000..319b1793753 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/ha.test @@ -0,0 +1,1794 @@ +# This test tests for ha features +--let $SKIP_REASON= +if ($USE_HA_TEST) +{ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source ha_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + } + if ($USE_CHILD_GROUP3) + { + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + } + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + --connection child2_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + SELECT 1; + --connection child3_2 + SELECT 1; + --connection child3_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_2_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_CREATE_TABLES; + } + eval $CHILD2_2_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_RECOVERY_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_COPY_TABLES_2_1; +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_3_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_CREATE_TABLES; + } + eval $CHILD2_3_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_RECOVERY_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_COPY_TABLES_P_2_1; + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo active standby test +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_AS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES2; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES2; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES2; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_AS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; +} +--disable_query_log +--disable_result_log +--source ha_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +} +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/ha_test_deinit.inc b/storage/spider/mysql-test/spider/bg/t/ha_test_deinit.inc new file mode 100644 index 00000000000..53d0409d066 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/ha_test_deinit.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_deinit_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_deinit_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_deinit_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_deinit_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/bg/t/ha_test_init.inc b/storage/spider/mysql-test/spider/bg/t/ha_test_init.inc new file mode 100644 index 00000000000..70576ab16dc --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/ha_test_init.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_init_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_init_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_init_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_init_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/bg/t/have_engine.inc b/storage/spider/mysql-test/spider/bg/t/have_engine.inc new file mode 100644 index 00000000000..64bef7499cb --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/have_engine.inc @@ -0,0 +1,7 @@ +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + SELECT engine, support FROM information_schema.engines; + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" +} diff --git a/storage/spider/mysql-test/spider/bg/t/have_func.inc b/storage/spider/mysql-test/spider/bg/t/have_func.inc new file mode 100644 index 00000000000..e0823e73fc8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/have_func.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM mysql.func WHERE name = '$TEST_FUNC_NAME'`) +{ + SELECT name FROM mysql.func; + --let $SKIP_REASON= "Need $TEST_FUNC_NAME function" +} diff --git a/storage/spider/mysql-test/spider/bg/t/have_partition.inc b/storage/spider/mysql-test/spider/bg/t/have_partition.inc new file mode 100644 index 00000000000..573c76ab43b --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/have_partition.inc @@ -0,0 +1,7 @@ +let $HAVE_PARTITION= 0; +if (`SELECT count(*) FROM information_schema.plugins WHERE + plugin_status = 'ACTIVE' AND + plugin_name = 'partition'`) +{ + let $HAVE_PARTITION= 1; +} diff --git a/storage/spider/mysql-test/spider/bg/t/have_trigger.inc b/storage/spider/mysql-test/spider/bg/t/have_trigger.inc new file mode 100644 index 00000000000..10c0871dd5f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/have_trigger.inc @@ -0,0 +1,2 @@ +let $HAVE_TRIGGER= `SELECT COUNT(*) FROM information_schema.tables + WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'TRIGGERS'`; diff --git a/storage/spider/mysql-test/spider/bg/t/hs_test_deinit.inc b/storage/spider/mysql-test/spider/bg/t/hs_test_deinit.inc new file mode 100644 index 00000000000..7ec2e981fd2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/hs_test_deinit.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_deinit_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/bg/t/hs_test_init.inc b/storage/spider/mysql-test/spider/bg/t/hs_test_init.inc new file mode 100644 index 00000000000..831bf479524 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/hs_test_init.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_init_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/bg/t/slave_test_deinit.inc b/storage/spider/mysql-test/spider/bg/t/slave_test_deinit.inc new file mode 100644 index 00000000000..e9d99b7a960 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/slave_test_deinit.inc @@ -0,0 +1,6 @@ +# get connection and exist engine test +--echo for slave1_1 +--connection slave1_1 +STOP SLAVE; +--source ../include/deinit_slave1_1.inc +--disconnect slave1_1 diff --git a/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc b/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc new file mode 100644 index 00000000000..739d88970c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc @@ -0,0 +1,44 @@ +# get connection and exist engine test +--echo for slave1_1 +--source connect_slave1_1.inc +--connection slave1_1 +SET SESSION sql_log_bin= 0; +--let $SLAVE1_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $SLAVE1_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_slave1_1.inc +--source have_engine.inc +--let $SLAVE1_1_SLAVE_STATUS=`SHOW SLAVE STATUS` +if (!$SLAVE1_1_SLAVE_STATUS) +{ + eval CHANGE MASTER TO + MASTER_HOST = '127.0.0.1', + MASTER_USER = 'root', + MASTER_PASSWORD = '', + MASTER_PORT = $MASTER_1_MYPORT + ; +} +START SLAVE; +--connection master_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--connection slave1_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} diff --git a/storage/spider/mysql-test/spider/bg/t/spider3_fixes.test b/storage/spider/mysql-test/spider/bg/t/spider3_fixes.test new file mode 100644 index 00000000000..4139f3af955 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider3_fixes.test @@ -0,0 +1,570 @@ +# This test tests for Spider 3.0's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo 3.1 +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +SET INSERT_ID=5000; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + TRUNCATE TABLE t1; + TRUNCATE TABLE t2; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + SET INSERT_ID=5000; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/spider_fixes.test b/storage/spider/mysql-test/spider/bg/t/spider_fixes.test new file mode 100644 index 00000000000..b9ff61abcb4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider_fixes.test @@ -0,0 +1,1967 @@ +# This test tests for Spider's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 2.13 +--echo select table with "order by desc" and "<" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table with "order by desc" and "<=" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.14 +--echo update table with range scan and split_read +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo 2.15 +--echo select table with range scan +TRUNCATE TABLE ta_l; +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES6; + echo CHILD2_1_CREATE_TABLES6; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES6; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES6; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.16 +--echo auto_increment insert with trigger +if ($HAVE_TRIGGER) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_CREATE_TABLES4; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES4; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES4; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; + eval CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; + echo CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE2 MASTER_1_CHARSET2; + eval CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; + --enable_query_log + --eval CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + INSERT INTO ta_l_auto_inc (a, b, c) VALUES + (NULL, 's', '2008-12-31 20:59:59'); + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES4; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +} + +--echo +--echo 2.17 +--echo engine-condition-pushdown with "or" and joining +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo partition with sort +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 + ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.23 +--echo partition update with moving partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); + UPDATE ta_l2 SET a = 4 WHERE a = 3; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo index merge +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo index merge with partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l_int; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_2_DROP_TABLES5; + echo CHILD2_2_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES5; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES5; + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1; + eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_P_2_1; + --enable_query_log + INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); + INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) + WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.24 +--echo index scan update without PK +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +if (!$MASTER_1_NEEDPK) +{ + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +--enable_query_log +SELECT a, b, c FROM ta_l_int ORDER BY a; +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l_int SET c = 4 WHERE b = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; + + +--echo +--echo 2.25 +--echo direct order limit +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; + + +--echo +--echo 2.26 +--echo lock tables +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_LOCK_TABLES1; + echo CHILD2_1_DROP_LOCK_TABLES2; + echo CHILD2_1_CREATE_LOCK_TABLES1; + echo CHILD2_1_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_LOCK_TABLES1; + eval $CHILD2_1_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_LOCK_TABLES1; + eval $CHILD2_1_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_LOCK_TABLES1; + echo CHILD2_2_DROP_LOCK_TABLES2; + echo CHILD2_2_CREATE_LOCK_TABLES1; + echo CHILD2_2_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_LOCK_TABLES1; + eval $CHILD2_2_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_LOCK_TABLES1; + eval $CHILD2_2_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1; +eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2; +eval CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK2; +--enable_query_log +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + + +--echo +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + SET INSERT_ID=5000; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo read only +let $MASTER_1_ENGINE_IS_SPIDER= + `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'Spider' OR + '$MASTER_1_HIDDEN_ENGINE_TYPE' = 'Spider', 1, 0)`; +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_READONLY1_1; + --let $MIN_VAL= `SELECT MIN(id) FROM t1` + --enable_query_log + SELECT id FROM t1 ORDER BY id; + --error 12518 + INSERT INTO t1 (id) VALUES (1); + --error 12518 + eval UPDATE t1 SET id = 4 WHERE id = $MIN_VAL; + --error 12518 + eval DELETE FROM t1 WHERE id = $MIN_VAL; + --error 12518 + DELETE FROM t1; + --error 12518 + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 2.27 +--echo error mode +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_ERROR_MODE1_1; + --enable_query_log + SELECT id FROM t1 ORDER BY id; + INSERT INTO t1 (id) VALUES (1); + DELETE FROM t1; + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 3.0 +--echo is null +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_KEY_TABLES1; + echo CHILD2_1_CREATE_TEXT_KEY_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_KEY_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_KEY_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_TEXT_KEY1_1; +--enable_query_log +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a is null order by a limit 30; +select b from t1 where b is null order by b limit 30; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo direct_order_limit +--connection master_1 +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +select a, c from t1 where a = '10' order by b desc limit 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bg/t/test_deinit.inc b/storage/spider/mysql-test/spider/bg/t/test_deinit.inc new file mode 100644 index 00000000000..989bde26d3c --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/test_deinit.inc @@ -0,0 +1,37 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/deinit_master_1.inc +--disconnect master_1 +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/deinit_child2_1.inc + --disconnect child2_1 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --echo child2_3 + --connection child2_3 + --source ../include/deinit_child2_3.inc + --disconnect child2_3 +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/deinit_child3_1.inc + --disconnect child3_1 + --echo child3_2 + --connection child3_2 + --source ../include/deinit_child3_2.inc + --disconnect child3_2 + --echo child3_3 + --connection child3_3 + --source ../include/deinit_child3_3.inc + --disconnect child3_3 +} diff --git a/storage/spider/mysql-test/spider/bg/t/test_init.inc b/storage/spider/mysql-test/spider/bg/t/test_init.inc new file mode 100644 index 00000000000..f2cd6c0269f --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/test_init.inc @@ -0,0 +1,74 @@ +# get connection and exist engine test +--echo for master_1 +--source connect_master_1.inc +--connection master_1 +CALL mtr.add_suppression("unknown variable"); +SET SESSION sql_log_bin= 0; +--let $MASTER_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $MASTER_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_master_1.inc +--source have_engine.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --source connect_child2_1.inc + --connection child2_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE + --source ../include/init_child2_1.inc + --source have_engine.inc + --echo child2_2 + --source connect_child2_2.inc + --connection child2_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE + --source ../include/init_child2_2.inc + --source have_engine.inc + --echo child2_3 + --source connect_child2_3.inc + --connection child2_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE + --source ../include/init_child2_3.inc + --source have_engine.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --source connect_child3_1.inc + --connection child3_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE + --source ../include/init_child3_1.inc + --source have_engine.inc + --echo child3_2 + --source connect_child3_2.inc + --connection child3_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE + --source ../include/init_child3_2.inc + --source have_engine.inc + --echo child3_3 + --source connect_child3_3.inc + --connection child3_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE + --source ../include/init_child3_3.inc + --source have_engine.inc +} diff --git a/storage/spider/mysql-test/spider/bg/t/vp_fixes.test b/storage/spider/mysql-test/spider/bg/t/vp_fixes.test new file mode 100644 index 00000000000..46e7b0afc36 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/vp_fixes.test @@ -0,0 +1,358 @@ +# This test tests for VP's bug fixes +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 0.9 +--echo create different primary key table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--let $MASTER_1_IS_VP= `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'VP', 1, 0)` +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo create un-correspond primary key table +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child3_1.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child3_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child3_2.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child3_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_child3_3.inc b/storage/spider/mysql-test/spider/handler/include/deinit_child3_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_master_1.inc b/storage/spider/mysql-test/spider/handler/include/deinit_master_1.inc new file mode 100644 index 00000000000..c19e376d10a --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/deinit_master_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/handler/include/deinit_slave1_1.inc b/storage/spider/mysql-test/spider/handler/include/deinit_slave1_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_1.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_2.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_2.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_2.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_3.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_3.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_3.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/handler/include/ha_deinit_master_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_1.inc new file mode 100644 index 00000000000..59c0175d349 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_1.inc @@ -0,0 +1,8 @@ +let $CHILD2_1_HA_AS_DROP_TABLES= + $CHILD2_1_DROP_TABLES; +let $CHILD2_1_HA_AS_CREATE_TABLES= + $CHILD2_1_CREATE_TABLES; +let $CHILD2_1_HA_AS_DROP_TABLES2= + $CHILD2_1_DROP_TABLES2; +let $CHILD2_1_HA_AS_CREATE_TABLES2= + $CHILD2_1_CREATE_TABLES2; diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_2.inc new file mode 100644 index 00000000000..90d27ed704d --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_2.inc @@ -0,0 +1,4 @@ +let $CHILD2_2_HA_DROP_TABLES= + $CHILD2_2_DROP_TABLES; +let $CHILD2_2_HA_CREATE_TABLES= + $CHILD2_2_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_3.inc new file mode 100644 index 00000000000..11abf112b1f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child2_3.inc @@ -0,0 +1,4 @@ +let $CHILD2_3_HA_DROP_TABLES= + $CHILD2_3_DROP_TABLES; +let $CHILD2_3_HA_CREATE_TABLES= + $CHILD2_3_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child3_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_1.inc new file mode 100644 index 00000000000..56de7df4e52 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_1.inc @@ -0,0 +1,140 @@ +--let $CHILD3_1_ENGINE_TYPE=Spider +--let $CHILD3_1_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_1_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_1_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_1_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child3_2.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_2.inc new file mode 100644 index 00000000000..fdb3a84cca7 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_2.inc @@ -0,0 +1,140 @@ +--let $CHILD3_2_ENGINE_TYPE=Spider +--let $CHILD3_2_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_2_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_2_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_2_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_2_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_2_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_2_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_2_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_2_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_2_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_2_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_child3_3.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_3.inc new file mode 100644 index 00000000000..d08ff4d0d34 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_child3_3.inc @@ -0,0 +1,140 @@ +--let $CHILD3_3_ENGINE_TYPE=Spider +--let $CHILD3_3_ENGINE=ENGINE=Spider +--source ../../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_3_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_3_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_3_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_3_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_3_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_3_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_3_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_3_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_3_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_3_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/handler/include/ha_init_master_1.inc b/storage/spider/mysql-test/spider/handler/include/ha_init_master_1.inc new file mode 100644 index 00000000000..78797d80ce7 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/ha_init_master_1.inc @@ -0,0 +1,105 @@ +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $MASTER_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $MASTER_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $MASTER_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $MASTER_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $MASTER_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +let $MASTER_1_COPY_TABLES_2_1= + SELECT spider_copy_tables('ta_l', '0', '1'); + +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $MASTER_1_COMMENT_HA_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_COMMENT_HA_AS_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $MASTER_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $MASTER_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +let $MASTER_1_COPY_TABLES_P_2_1= + SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +let $MASTER_1_CHECK_HA_STATUS= + SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +let $MASTER_1_CHANGE_HA_MON= + SELECT spider_flush_table_mon_cache(); diff --git a/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/hs_deinit_master_1.inc b/storage/spider/mysql-test/spider/handler/include/hs_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/hs_init_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/hs_init_child2_1.inc new file mode 100644 index 00000000000..2ea1c0c9cd6 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/hs_init_child2_1.inc @@ -0,0 +1,24 @@ +let $CHILD2_1_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r; +let $CHILD2_1_HS_CREATE_TABLES= + CREATE TABLE hs_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r ORDER BY a; +let $CHILD2_1_HS_DROP_TABLES2= + DROP TABLE IF EXISTS hs_r2; +let $CHILD2_1_HS_CREATE_TABLES2= + CREATE TABLE hs_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r2 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/handler/include/hs_init_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/hs_init_child2_2.inc new file mode 100644 index 00000000000..7c69d73ced6 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/hs_init_child2_2.inc @@ -0,0 +1,12 @@ +let $CHILD2_2_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r3; +let $CHILD2_2_HS_CREATE_TABLES= + CREATE TABLE hs_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r3 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/handler/include/hs_init_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/hs_init_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/hs_init_master_1.inc b/storage/spider/mysql-test/spider/handler/include/hs_init_master_1.inc new file mode 100644 index 00000000000..0ff5e2a10d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/hs_init_master_1.inc @@ -0,0 +1,12 @@ +let $MASTER_1_HS_COMMENT_TMP= + COMMENT=''; +let $MASTER_1_HS_COMMENT_2_1= + COMMENT='srv "s_2_1", table "hs_r", uhr "1", uhw "1", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"'; +let $MASTER_1_HS_COMMENT_P_2_1= + COMMENT='uhr "1", uhw "1"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) + COMMENT='srv "s_2_1", table "hs_r2", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", table "hs_r3", hrp "$CHILD2_2_HSRPORT", hwp "$CHILD2_2_HSWPORT"' + ); diff --git a/storage/spider/mysql-test/spider/handler/include/init_child2_1.inc b/storage/spider/mysql-test/spider/handler/include/init_child2_1.inc new file mode 100644 index 00000000000..7773f0e2dde --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/init_child2_1.inc @@ -0,0 +1,176 @@ +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r; +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +let $CHILD2_1_DROP_TABLES2= + DROP TABLE IF EXISTS ta_r2; +let $CHILD2_1_CREATE_TABLES2= + CREATE TABLE ta_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r2 ORDER BY a; +let $CHILD2_1_DROP_TABLES3= + DROP TABLE IF EXISTS ta_r_no_idx; +let $CHILD2_1_CREATE_TABLES3= + CREATE TABLE ta_r_no_idx ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES3= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_no_idx ORDER BY a; +let $CHILD2_1_DROP_TABLES4= + DROP TABLE IF EXISTS ta_r_auto_inc; +let $CHILD2_1_CREATE_TABLES4= + CREATE TABLE ta_r_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES4= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_auto_inc + ORDER BY a; +let $CHILD2_1_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_1_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES5= + SELECT a, b, c FROM ta_r_int ORDER BY a; +let $CHILD2_1_DROP_TABLES6= + DROP TABLE IF EXISTS ta_r_3; +let $CHILD2_1_CREATE_TABLES6= + CREATE TABLE ta_r_3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES6= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_3 ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r; +let $CHILD2_1_CREATE_FT_TABLES= + CREATE TABLE ft_r ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES2= + DROP TABLE IF EXISTS ft_r2; +let $CHILD2_1_CREATE_FT_TABLES2= + CREATE TABLE ft_r2 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES2= + SELECT a, b, c, d FROM ft_r2 ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r; +let $CHILD2_1_CREATE_GM_TABLES= + CREATE TABLE gm_r ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES2= + DROP TABLE IF EXISTS gm_r2; +let $CHILD2_1_CREATE_GM_TABLES2= + CREATE TABLE gm_r2 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES2= + SELECT a, b, c FROM gm_r2 ORDER BY a; +let $CHILD2_1_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_LOCK_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_2; +let $CHILD2_1_CREATE_LOCK_TABLES2= + CREATE TABLE t2_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_1 ORDER BY id; +let $CHILD2_1_DROP_TEXT_PK_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_PK_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY (a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET2; +let $CHILD2_1_SELECT_TEXT_PK_TABLES1= + SELECT a FROM t1 ORDER BY a; +let $CHILD2_1_DROP_TEXT_KEY_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_KEY_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TEXT_KEY_TABLES1= + SELECT a, b FROM t1 ORDER BY a, b; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_1_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_1_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 2; diff --git a/storage/spider/mysql-test/spider/handler/include/init_child2_2.inc b/storage/spider/mysql-test/spider/handler/include/init_child2_2.inc new file mode 100644 index 00000000000..3524fc4a2b7 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/init_child2_2.inc @@ -0,0 +1,80 @@ +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS ta_r3; +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE ta_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_2_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r3 ORDER BY a; +let $CHILD2_2_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r3; +let $CHILD2_2_CREATE_FT_TABLES= + CREATE TABLE ft_r3 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_2_FT_ENGINE $CHILD2_2_FT_CHARSET; +let $CHILD2_2_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r3 ORDER BY a; +let $CHILD2_2_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r3; +let $CHILD2_2_CREATE_GM_TABLES= + CREATE TABLE gm_r3 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_2_GM_ENGINE $CHILD2_2_GM_CHARSET; +let $CHILD2_2_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r3 ORDER BY a; +let $CHILD2_2_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_LOCK_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_1; +let $CHILD2_2_CREATE_LOCK_TABLES2= + CREATE TABLE t2_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_2 ORDER BY id; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_2_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_2_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 3; diff --git a/storage/spider/mysql-test/spider/handler/include/init_child2_3.inc b/storage/spider/mysql-test/spider/handler/include/init_child2_3.inc new file mode 100644 index 00000000000..d857a787ac0 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/init_child2_3.inc @@ -0,0 +1,11 @@ +let $CHILD2_3_DROP_TABLES= + DROP TABLE IF EXISTS ta_r4; +let $CHILD2_3_CREATE_TABLES= + CREATE TABLE ta_r4 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_3_ENGINE $CHILD2_3_CHARSET; +let $CHILD2_3_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r4 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/handler/include/init_child3_1.inc b/storage/spider/mysql-test/spider/handler/include/init_child3_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/init_child3_2.inc b/storage/spider/mysql-test/spider/handler/include/init_child3_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/init_child3_3.inc b/storage/spider/mysql-test/spider/handler/include/init_child3_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/handler/include/init_master_1.inc b/storage/spider/mysql-test/spider/handler/include/init_master_1.inc new file mode 100644 index 00000000000..9c487bc73fe --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/init_master_1.inc @@ -0,0 +1,186 @@ +--source ../../include/init_spider.inc +SET spider_internal_sql_log_off= 0; +SET spider_use_handler= 3; +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password "", prt "2000000"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password "", prt "2000000"'; +} +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1", table "ta_r2", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT2_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ta_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT3_P_2_1= + COMMENT='table "ta_r_int"' + PARTITION BY LIST(MOD(a, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='srv "s_2_1", priority "1000"', + PARTITION pt2 VALUES IN (1) + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT2_FT_P_2_1= + COMMENT='table "ft_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ft_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_GM_2_1= + COMMENT='srv "s_2_1", table "gm_r"'; +let $MASTER_1_COMMENT2_GM_P_2_1= + COMMENT='table "gm_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "gm_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_LOCK1= + COMMENT 'tbl "t1_1 t1_2", srv "s_2_1 s_2_2"'; +let $MASTER_1_COMMENT_LOCK2= + COMMENT 'tbl "t2_1 t2_2", srv "s_2_2 s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_1= + COMMENT 'aim "2", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_P_1= + COMMENT 'aim "2"' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='tbl "t1_1", srv "s_2_1"', + PARTITION pt2 VALUES IN (1) + COMMENT='tbl "t1_2", srv "s_2_2"' + ); +let $MASTER_1_COMMENT_READONLY1_1= + COMMENT 'read_only_mode "1", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_ERROR_MODE1_1= + COMMENT 'erm "1", ewm "1", tbl "ter1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_PK1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_KEY1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_update'; +let $MASTER_1_CHECK_DIRECT_DELETE_STATUS= + SHOW STATUS LIKE 'Spider_direct_delete'; +let $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS= + SHOW STATUS LIKE 'Spider_direct_order_limit'; +let $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_aggregate'; +let $MASTER_1_AUTO_INCREMENT_INCREMENT1= + SET SESSION AUTO_INCREMENT_INCREMENT = 1 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_INCREMENT2= + SET SESSION AUTO_INCREMENT_INCREMENT = 777 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET1= + SET SESSION AUTO_INCREMENT_OFFSET = 1 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET2= + SET SESSION AUTO_INCREMENT_OFFSET = 777 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET3= + SET SESSION AUTO_INCREMENT_OFFSET = 1; +let $MASTER_1_AUTO_INCREMENT_OFFSET4= + SET SESSION AUTO_INCREMENT_OFFSET = 777; diff --git a/storage/spider/mysql-test/spider/handler/include/init_slave1_1.inc b/storage/spider/mysql-test/spider/handler/include/init_slave1_1.inc new file mode 100644 index 00000000000..87c05f1f690 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/include/init_slave1_1.inc @@ -0,0 +1,10 @@ +let $SLAVE1_1_COMMENT_INCREMENT1_1= + COMMENT ''; +let $SLAVE1_1_COMMENT_INCREMENT1_P_1= + COMMENT '' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='', + PARTITION pt2 VALUES IN (1) + COMMENT='' + ); diff --git a/storage/spider/mysql-test/spider/handler/my.cnf b/storage/spider/mysql-test/spider/handler/my.cnf new file mode 100644 index 00000000000..6b79d0a8f87 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/my.cnf @@ -0,0 +1,176 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld.1.1] +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 0 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[mysqld.2.1] +loose_handlersocket_port= 20002 +loose_handlersocket_port_wr= 20003 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 0 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.2] +loose_handlersocket_port= 20004 +loose_handlersocket_port_wr= 20005 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 0 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.3] + +[mysqld.3.1] +loose_partition= 1 + +[mysqld.3.2] +loose_partition= 1 + +[mysqld.3.3] +loose_partition= 1 + +[mysqld.4.1] +loose_partition= 1 + + +[ENV] +USE_GEOMETRY_TEST= 1 +USE_FULLTEXT_TEST= 1 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 1 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +SLAVE1_1_MYPORT= @mysqld.4.1.port +SLAVE1_1_MYSOCK= @mysqld.4.1.socket +SLAVE1_1_ENGINE_TYPE= MyISAM +SLAVE1_1_ENGINE= ENGINE=MyISAM +SLAVE1_1_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.2.1.port +CHILD2_1_HSRPORT= 20002 +CHILD2_1_HSWPORT= 20003 +CHILD2_1_MYSOCK= @mysqld.2.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_2_MYPORT= @mysqld.2.2.port +CHILD2_2_HSRPORT= 20004 +CHILD2_2_HSWPORT= 20005 +CHILD2_2_MYSOCK= @mysqld.2.2.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_3_MYPORT= @mysqld.2.3.port +CHILD2_3_MYSOCK= @mysqld.2.3.socket +CHILD2_3_ENGINE_TYPE= InnoDB +CHILD2_3_ENGINE= ENGINE=InnoDB +CHILD2_3_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_FT_MYPORT= @mysqld.1.1.port +CHILD2_1_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.2.2.port +CHILD2_2_FT_MYSOCK= @mysqld.2.2.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.2.1.port +CHILD2_1_GM_MYSOCK= @mysqld.2.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.2.2.port +CHILD2_2_GM_MYSOCK= @mysqld.2.2.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP3= 1 +OUTPUT_CHILD_GROUP3= 0 +CHILD3_1_MYPORT= @mysqld.3.1.port +CHILD3_1_MYSOCK= @mysqld.3.1.socket +CHILD3_1_ENGINE_TYPE= InnoDB +CHILD3_1_ENGINE= ENGINE=InnoDB +CHILD3_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_2_MYPORT= @mysqld.3.2.port +CHILD3_2_MYSOCK= @mysqld.3.2.socket +CHILD3_2_ENGINE_TYPE= InnoDB +CHILD3_2_ENGINE= ENGINE=InnoDB +CHILD3_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_3_MYPORT= @mysqld.3.3.port +CHILD3_3_MYSOCK= @mysqld.3.3.socket +CHILD3_3_ENGINE_TYPE= InnoDB +CHILD3_3_ENGINE= ENGINE=InnoDB +CHILD3_3_CHARSET= DEFAULT CHARSET=utf8 + +STR_SEMICOLON= ; + +#The followings are setted in include/init_xxx.inc files +#MASTER_1_COMMENT_2_1 +#MASTER_1_COMMENT2_2_1 +#MASTER_1_COMMENT3_2_1 +#MASTER_1_COMMENT4_2_1 +#MASTER_1_COMMENT5_2_1 +#MASTER_1_COMMENT_P_2_1 +#CHILD2_1_DROP_TABLES +#CHILD2_1_CREATE_TABLES +#CHILD2_1_SELECT_TABLES +#CHILD2_1_DROP_TABLES2 +#CHILD2_1_CREATE_TABLES2 +#CHILD2_1_SELECT_TABLES2 +#CHILD2_1_DROP_TABLES3 +#CHILD2_1_CREATE_TABLES3 +#CHILD2_1_SELECT_TABLES3 +#CHILD2_1_DROP_TABLES4 +#CHILD2_1_CREATE_TABLES4 +#CHILD2_1_SELECT_TABLES4 +#CHILD2_1_DROP_TABLES5 +#CHILD2_1_CREATE_TABLES5 +#CHILD2_1_SELECT_TABLES5 +#CHILD2_1_DROP_TABLES6 +#CHILD2_1_CREATE_TABLES6 +#CHILD2_1_SELECT_TABLES6 +#CHILD2_2_DROP_TABLES +#CHILD2_2_CREATE_TABLES +#CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/handler/r/basic_sql.result b/storage/spider/mysql-test/spider/handler/r/basic_sql.result new file mode 100644 index 00000000000..da24c08e9fd --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/basic_sql.result @@ -0,0 +1,693 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'f', '2008-07-01 10:21:39'), +(2, 'g', '2000-02-01 00:00:00'), +(3, 'j', '2007-05-04 20:03:11'), +(4, 'i', '2003-10-30 05:01:03'), +(5, 'h', '2001-10-31 23:59:59'); +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create table with partition and select test +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create no index table +DROP TABLE IF EXISTS ta_l_no_idx; +CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table shared mode +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table for update +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table join +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table straight_join +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_small_result +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_big_result +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_buffer_result +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_cache +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_no_cache +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_calc_found_rows +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +SELECT found_rows(); +found_rows() +5 + +select high_priority +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select distinct +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select count +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select using index and pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using index pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +insert select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 + +insert low_priority +TRUNCATE TABLE ta_l; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert high_priority +TRUNCATE TABLE ta_l; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert ignore +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (insert) +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (update) +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2005-08-08 11:11:11 + +replace +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2008-02-02 02:02:02 + +replace select +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace select a +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace low_priority +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 g 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 h 2010-04-04 04:04:04 +2 g 2009-03-03 03:03:03 + +update join +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update partition pushdown +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 e 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update partition index pushdown +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete all +DELETE FROM ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE IGNORE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE QUICK FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete partition index pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +truncate +TRUNCATE TABLE ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/direct_aggregate.result b/storage/spider/mysql-test/spider/handler/r/direct_aggregate.result new file mode 100644 index 00000000000..0e845fabda1 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/direct_aggregate.result @@ -0,0 +1,132 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_aggregating test +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 2 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 4 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 5 + +handler with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 5 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 7 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 9 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 11 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 13 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 15 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/direct_update.result b/storage/spider/mysql-test/spider/handler/r/direct_update.result new file mode 100644 index 00000000000..ea3a23eb8b8 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/direct_update.result @@ -0,0 +1,242 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_updating test +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 0 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 2 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 3 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 4 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 2 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 3 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +handler with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 4 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l2 SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 6 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l2 SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 7 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 9 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +Spider_direct_update 10 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 4 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l2 WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 6 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l2 WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +Spider_direct_delete 7 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/function.result b/storage/spider/mysql-test/spider/handler/r/function.result new file mode 100644 index 00000000000..764c774514b --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/function.result @@ -0,0 +1,149 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +in() +CREATE TABLE t1 ( +a VARCHAR(255), +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1 +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-08-01 10:21:39 +2 b 1999-01-01 00:00:00 +3 e 2006-06-04 20:03:11 +4 d 2002-11-30 05:01:03 +5 c 2000-12-31 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-11-01 10:21:39 +2 b 1999-04-01 00:00:00 +3 e 2006-09-04 20:03:11 +4 d 2003-02-28 05:01:03 +5 c 2001-03-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-01 10:21:39 +2 b 1999-03-01 00:00:00 +3 e 2006-08-04 20:03:11 +4 d 2003-01-28 05:01:03 +5 c 2001-02-28 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-08 10:21:39 +2 b 1999-03-08 00:00:00 +3 e 2006-08-11 20:03:11 +4 d 2003-02-04 05:01:03 +5 c 2001-03-07 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 10:21:39 +2 b 1999-03-07 00:00:00 +3 e 2006-08-10 20:03:11 +4 d 2003-02-03 05:01:03 +5 c 2001-03-06 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:21:39 +2 b 1999-03-07 01:00:00 +3 e 2006-08-10 21:03:11 +4 d 2003-02-03 06:01:03 +5 c 2001-03-07 00:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:39 +2 b 1999-03-07 00:59:00 +3 e 2006-08-10 21:02:11 +4 d 2003-02-03 06:00:03 +5 c 2001-03-07 00:58:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:40 +2 b 1999-03-07 00:59:01 +3 e 2006-08-10 21:02:12 +4 d 2003-02-03 06:00:04 +5 c 2001-03-07 00:59:00 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/ha.result b/storage/spider/mysql-test/spider/handler/r/ha.result new file mode 100644 index 00000000000..e05ecb32e1b --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/ha.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +test select 1 +SELECT 1; +1 +1 + +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 0 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote2.ta_r3' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 2 +SELECT spider_copy_tables('ta_l', '0', '1'); +spider_copy_tables('ta_l', '0', '1') +1 +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote3.ta_r4' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 2 +SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +spider_copy_tables('ta_l2#P#pt2', '0', '1') +1 +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +active standby test +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 3 +auto_test_local ta_l 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r2' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 3 +auto_test_local ta_l2#P#pt2 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +auto_test_local ta_l2#P#pt2 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 3 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/spider3_fixes.result b/storage/spider/mysql-test/spider/handler/r/spider3_fixes.result new file mode 100644 index 00000000000..6de174e1a2d --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/spider3_fixes.result @@ -0,0 +1,403 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +3.1 +auto_increment +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t2; +MAX(id) +6 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT MAX(id) FROM t1; +MAX(id) +10 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +14 +SELECT MAX(id) FROM t2; +MAX(id) +14 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +34 +SELECT id FROM t2 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +34 +38 +42 +46 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t2 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +34 +SELECT MAX(id) FROM t1; +MAX(id) +34 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +38 +SELECT MAX(id) FROM t2; +MAX(id) +38 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +42 +SELECT MAX(id) FROM t1; +MAX(id) +42 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +46 +SELECT MAX(id) FROM t2; +MAX(id) +46 +SELECT id FROM t1 ORDER BY id; +id +2 +34 +777 +1554 +2331 +10000 +auto_increment with partition +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SELECT MAX(id) FROM t2; +MAX(id) +3 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +7 +SELECT MAX(id) FROM t1; +MAX(id) +7 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t2; +MAX(id) +7 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t2 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +18 +19 +22 +23 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT id FROM t2 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT MAX(id) FROM t1; +MAX(id) +18 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +19 +SELECT MAX(id) FROM t2; +MAX(id) +19 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +22 +SELECT MAX(id) FROM t1; +MAX(id) +22 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +26 +SELECT MAX(id) FROM t2; +MAX(id) +26 +SELECT id FROM t1 ORDER BY id; +id +2 +18 +777 +1554 +2331 +10000 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/spider_fixes.result b/storage/spider/mysql-test/spider/handler/r/spider_fixes.result new file mode 100644 index 00000000000..9fd24bcc43f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/spider_fixes.result @@ -0,0 +1,699 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +2.13 +select table with "order by desc" and "<" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 +2 b 2000-01-01 00:00:00 + +select table with "order by desc" and "<=" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +5 c 2001-12-31 23:59:59 +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 + +2.14 +update table with range scan and split_read +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-02-02 00:00:00 +3 e 2000-02-02 00:00:00 +4 d 2000-02-02 00:00:00 +5 c 2000-02-02 00:00:00 + +2.15 +select table with range scan +TRUNCATE TABLE ta_l; +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a int(11) NOT NULL DEFAULT '0', +b char(1) DEFAULT NULL, +c datetime DEFAULT NULL, +PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +CREATE TABLE ta_l_auto_inc ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tc_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END;; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 s 2008-12-31 20:59:59 + +2.17 +engine-condition-pushdown with "or" and joining +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +partition with sort +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +2.23 +partition update with moving partition +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); +UPDATE ta_l2 SET a = 4 WHERE a = 3; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 B 2010-09-26 00:00:00 +index merge +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 +index merge with partition +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT NOT NULL, +b INT DEFAULT 10, +c INT DEFAULT 11, +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +UPDATE ta_l_int SET c = 4 WHERE b = 2; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +1 2 4 +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +17 2 4 + +2.25 +direct order limit +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 2 +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +a b c +1 2 4 +2 3 4 +4 5 6 +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 3 + +2.26 +lock tables +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1 +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t1; +MAX(id) +6 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT MAX(id) FROM t1; +MAX(id) +10 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +14 +SELECT MAX(id) FROM t1; +MAX(id) +14 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +34 +SELECT MAX(id) FROM t1; +MAX(id) +34 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +38 +SELECT MAX(id) FROM t1; +MAX(id) +38 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +42 +SELECT MAX(id) FROM t1; +MAX(id) +42 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +34 +777 +1000 +1554 +2331 +10000 + +auto_increment with partition +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SELECT MAX(id) FROM t1; +MAX(id) +3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t1; +MAX(id) +6 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +7 +SELECT MAX(id) FROM t1; +MAX(id) +7 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT MAX(id) FROM t1; +MAX(id) +18 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +22 +SELECT MAX(id) FROM t1; +MAX(id) +22 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +26 +SELECT MAX(id) FROM t1; +MAX(id) +26 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +10 +18 +777 +1000 +1554 +2331 +10000 + +read only +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +INSERT INTO t1 (id) VALUES (1); +ERROR HY000: Table 'auto_test_local.t1' is read only +UPDATE t1 SET id = 4 WHERE id = 2; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 2; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1; +ERROR HY000: Table 'auto_test_local.t1' is read only +TRUNCATE t1; +ERROR HY000: Table 'auto_test_local.t1' is read only + +2.27 +error mode +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1 +SELECT id FROM t1 ORDER BY id; +id +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +INSERT INTO t1 (id) VALUES (1); +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +DELETE FROM t1; +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +TRUNCATE t1; +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist + +3.0 +is null +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a VARCHAR(255), +b VARCHAR(255), +c VARCHAR(255), +KEY idx1(a,b), +KEY idx2(b), +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1 +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +select a from t1 where a is null order by a limit 30; +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +select b from t1 where b is null order by b limit 30; +b +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +direct_order_limit +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +a b c +10 74 74 +10 42 42 +10 234 234 +10 202 202 +10 170 170 +select a, c from t1 where a = '10' order by b desc limit 5; +a c +10 74 +10 42 +10 234 +10 202 +10 170 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/r/vp_fixes.result b/storage/spider/mysql-test/spider/handler/r/vp_fixes.result new file mode 100644 index 00000000000..15dd29aa4d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/r/vp_fixes.result @@ -0,0 +1,80 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +0.9 +create different primary key table +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT AUTO_INCREMENT, +c INT DEFAULT 11, +PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT DEFAULT 12, +c INT DEFAULT 11, +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/handler/t/basic_sql.test b/storage/spider/mysql-test/spider/handler/t/basic_sql.test new file mode 100644 index 00000000000..2264b0e4e37 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/basic_sql.test @@ -0,0 +1,3189 @@ +# This test tests by executing basic SQL +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'f', '2008-07-01 10:21:39'), + (2, 'g', '2000-02-01 00:00:00'), + (3, 'j', '2007-05-04 20:03:11'), + (4, 'i', '2003-10-30 05:01:03'), + (5, 'h', '2001-10-31 23:59:59'); +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT IGNORE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + REPLACE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%replace %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table with partition and select test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + } + --enable_query_log + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo create no index table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES3; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_no_idx; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_NEEDPK) +{ + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + } +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES3; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; + +--echo +--echo select table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table shared mode +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table for update +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table straight_join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_small_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_big_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_buffer_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_no_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_calc_found_rows +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT found_rows(); + +--echo +--echo select high_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select distinct +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select count +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT count(*) FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join not use index +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using index and pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select partition using pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo select partition using index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.a > 0 AND a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo insert +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select a +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert low_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert high_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (insert) +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (update) +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update index pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update partition pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo update partition index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete all +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE IGNORE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE QUICK FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete partition pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete partition index pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo truncate +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'truncate %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/handler/t/connect_child2_1.inc new file mode 100644 index 00000000000..cd9b0c9ca9b --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child2_1.inc @@ -0,0 +1 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/handler/t/connect_child2_2.inc new file mode 100644 index 00000000000..e145f66b630 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child2_2.inc @@ -0,0 +1 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child2_3.inc b/storage/spider/mysql-test/spider/handler/t/connect_child2_3.inc new file mode 100644 index 00000000000..d356348d8ea --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child2_3.inc @@ -0,0 +1 @@ +--connect (child2_3, localhost, root, , , $CHILD2_3_MYPORT, $CHILD2_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child3_1.inc b/storage/spider/mysql-test/spider/handler/t/connect_child3_1.inc new file mode 100644 index 00000000000..03e5c188c89 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child3_1.inc @@ -0,0 +1 @@ +--connect (child3_1, localhost, root, , , $CHILD3_1_MYPORT, $CHILD3_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child3_2.inc b/storage/spider/mysql-test/spider/handler/t/connect_child3_2.inc new file mode 100644 index 00000000000..d62a7ada824 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child3_2.inc @@ -0,0 +1 @@ +--connect (child3_2, localhost, root, , , $CHILD3_2_MYPORT, $CHILD3_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_child3_3.inc b/storage/spider/mysql-test/spider/handler/t/connect_child3_3.inc new file mode 100644 index 00000000000..fb49f5bfdac --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_child3_3.inc @@ -0,0 +1 @@ +--connect (child3_3, localhost, root, , , $CHILD3_3_MYPORT, $CHILD3_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_master_1.inc b/storage/spider/mysql-test/spider/handler/t/connect_master_1.inc new file mode 100644 index 00000000000..0c129ce5775 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_master_1.inc @@ -0,0 +1 @@ +--connect (master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/connect_slave1_1.inc b/storage/spider/mysql-test/spider/handler/t/connect_slave1_1.inc new file mode 100644 index 00000000000..45a822743e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/connect_slave1_1.inc @@ -0,0 +1 @@ +--connect (slave1_1, localhost, root, , , $SLAVE1_1_MYPORT, $SLAVE1_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/handler/t/direct_aggregate.test b/storage/spider/mysql-test/spider/handler/t/direct_aggregate.test new file mode 100644 index 00000000000..59c45f3f190 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/direct_aggregate.test @@ -0,0 +1,316 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_aggregating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT COUNT(*) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l WHERE a < 5; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/direct_update.test b/storage/spider/mysql-test/spider/handler/t/direct_update.test new file mode 100644 index 00000000000..1c3ce91ff3f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/direct_update.test @@ -0,0 +1,354 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_updating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key +DELETE FROM ta_l WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update all rows with function + UPDATE ta_l2 SET c = ADDDATE(c, 1); + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key + UPDATE ta_l2 SET b = 'x' WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by a column without index + UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key with order and limit + UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key with order and limit + DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by a column without index + DELETE FROM ta_l2 WHERE b = 'c'; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key + DELETE FROM ta_l2 WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/function.test b/storage/spider/mysql-test/spider/handler/t/function.test new file mode 100644 index 00000000000..2b1b53c8a4f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/function.test @@ -0,0 +1,276 @@ +# This test tests for using functions +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo in() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_PK_TABLES1; + echo CHILD2_1_CREATE_TEXT_PK_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_PK_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_PK_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET3 $MASTER_1_COMMENT_TEXT_PK1_1; +--enable_query_log +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a in ('15', '120'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo date_sub() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/ha.test b/storage/spider/mysql-test/spider/handler/t/ha.test new file mode 100644 index 00000000000..319b1793753 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/ha.test @@ -0,0 +1,1794 @@ +# This test tests for ha features +--let $SKIP_REASON= +if ($USE_HA_TEST) +{ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source ha_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + } + if ($USE_CHILD_GROUP3) + { + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + } + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + --connection child2_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + SELECT 1; + --connection child3_2 + SELECT 1; + --connection child3_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_2_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_CREATE_TABLES; + } + eval $CHILD2_2_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_RECOVERY_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_COPY_TABLES_2_1; +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_3_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_CREATE_TABLES; + } + eval $CHILD2_3_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_RECOVERY_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_COPY_TABLES_P_2_1; + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo active standby test +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_AS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES2; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES2; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES2; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_AS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; +} +--disable_query_log +--disable_result_log +--source ha_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +} +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/ha_test_deinit.inc b/storage/spider/mysql-test/spider/handler/t/ha_test_deinit.inc new file mode 100644 index 00000000000..53d0409d066 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/ha_test_deinit.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_deinit_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_deinit_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_deinit_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_deinit_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/handler/t/ha_test_init.inc b/storage/spider/mysql-test/spider/handler/t/ha_test_init.inc new file mode 100644 index 00000000000..70576ab16dc --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/ha_test_init.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_init_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_init_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_init_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_init_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/handler/t/have_engine.inc b/storage/spider/mysql-test/spider/handler/t/have_engine.inc new file mode 100644 index 00000000000..64bef7499cb --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/have_engine.inc @@ -0,0 +1,7 @@ +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + SELECT engine, support FROM information_schema.engines; + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" +} diff --git a/storage/spider/mysql-test/spider/handler/t/have_func.inc b/storage/spider/mysql-test/spider/handler/t/have_func.inc new file mode 100644 index 00000000000..e0823e73fc8 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/have_func.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM mysql.func WHERE name = '$TEST_FUNC_NAME'`) +{ + SELECT name FROM mysql.func; + --let $SKIP_REASON= "Need $TEST_FUNC_NAME function" +} diff --git a/storage/spider/mysql-test/spider/handler/t/have_partition.inc b/storage/spider/mysql-test/spider/handler/t/have_partition.inc new file mode 100644 index 00000000000..573c76ab43b --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/have_partition.inc @@ -0,0 +1,7 @@ +let $HAVE_PARTITION= 0; +if (`SELECT count(*) FROM information_schema.plugins WHERE + plugin_status = 'ACTIVE' AND + plugin_name = 'partition'`) +{ + let $HAVE_PARTITION= 1; +} diff --git a/storage/spider/mysql-test/spider/handler/t/have_trigger.inc b/storage/spider/mysql-test/spider/handler/t/have_trigger.inc new file mode 100644 index 00000000000..10c0871dd5f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/have_trigger.inc @@ -0,0 +1,2 @@ +let $HAVE_TRIGGER= `SELECT COUNT(*) FROM information_schema.tables + WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'TRIGGERS'`; diff --git a/storage/spider/mysql-test/spider/handler/t/hs_test_deinit.inc b/storage/spider/mysql-test/spider/handler/t/hs_test_deinit.inc new file mode 100644 index 00000000000..7ec2e981fd2 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/hs_test_deinit.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_deinit_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/handler/t/hs_test_init.inc b/storage/spider/mysql-test/spider/handler/t/hs_test_init.inc new file mode 100644 index 00000000000..831bf479524 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/hs_test_init.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_init_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/handler/t/slave_test_deinit.inc b/storage/spider/mysql-test/spider/handler/t/slave_test_deinit.inc new file mode 100644 index 00000000000..e9d99b7a960 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/slave_test_deinit.inc @@ -0,0 +1,6 @@ +# get connection and exist engine test +--echo for slave1_1 +--connection slave1_1 +STOP SLAVE; +--source ../include/deinit_slave1_1.inc +--disconnect slave1_1 diff --git a/storage/spider/mysql-test/spider/handler/t/slave_test_init.inc b/storage/spider/mysql-test/spider/handler/t/slave_test_init.inc new file mode 100644 index 00000000000..739d88970c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/slave_test_init.inc @@ -0,0 +1,44 @@ +# get connection and exist engine test +--echo for slave1_1 +--source connect_slave1_1.inc +--connection slave1_1 +SET SESSION sql_log_bin= 0; +--let $SLAVE1_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $SLAVE1_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_slave1_1.inc +--source have_engine.inc +--let $SLAVE1_1_SLAVE_STATUS=`SHOW SLAVE STATUS` +if (!$SLAVE1_1_SLAVE_STATUS) +{ + eval CHANGE MASTER TO + MASTER_HOST = '127.0.0.1', + MASTER_USER = 'root', + MASTER_PASSWORD = '', + MASTER_PORT = $MASTER_1_MYPORT + ; +} +START SLAVE; +--connection master_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--connection slave1_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} diff --git a/storage/spider/mysql-test/spider/handler/t/spider3_fixes.test b/storage/spider/mysql-test/spider/handler/t/spider3_fixes.test new file mode 100644 index 00000000000..4139f3af955 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/spider3_fixes.test @@ -0,0 +1,570 @@ +# This test tests for Spider 3.0's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo 3.1 +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +SET INSERT_ID=5000; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + TRUNCATE TABLE t1; + TRUNCATE TABLE t2; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + SET INSERT_ID=5000; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/spider_fixes.test b/storage/spider/mysql-test/spider/handler/t/spider_fixes.test new file mode 100644 index 00000000000..b9ff61abcb4 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/spider_fixes.test @@ -0,0 +1,1967 @@ +# This test tests for Spider's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 2.13 +--echo select table with "order by desc" and "<" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table with "order by desc" and "<=" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.14 +--echo update table with range scan and split_read +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo 2.15 +--echo select table with range scan +TRUNCATE TABLE ta_l; +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES6; + echo CHILD2_1_CREATE_TABLES6; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES6; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES6; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.16 +--echo auto_increment insert with trigger +if ($HAVE_TRIGGER) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_CREATE_TABLES4; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES4; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES4; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; + eval CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; + echo CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE2 MASTER_1_CHARSET2; + eval CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; + --enable_query_log + --eval CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + INSERT INTO ta_l_auto_inc (a, b, c) VALUES + (NULL, 's', '2008-12-31 20:59:59'); + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES4; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +} + +--echo +--echo 2.17 +--echo engine-condition-pushdown with "or" and joining +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo partition with sort +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 + ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.23 +--echo partition update with moving partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); + UPDATE ta_l2 SET a = 4 WHERE a = 3; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo index merge +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo index merge with partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l_int; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_2_DROP_TABLES5; + echo CHILD2_2_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES5; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES5; + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1; + eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_P_2_1; + --enable_query_log + INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); + INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) + WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.24 +--echo index scan update without PK +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +if (!$MASTER_1_NEEDPK) +{ + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +--enable_query_log +SELECT a, b, c FROM ta_l_int ORDER BY a; +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l_int SET c = 4 WHERE b = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; + + +--echo +--echo 2.25 +--echo direct order limit +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; + + +--echo +--echo 2.26 +--echo lock tables +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_LOCK_TABLES1; + echo CHILD2_1_DROP_LOCK_TABLES2; + echo CHILD2_1_CREATE_LOCK_TABLES1; + echo CHILD2_1_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_LOCK_TABLES1; + eval $CHILD2_1_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_LOCK_TABLES1; + eval $CHILD2_1_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_LOCK_TABLES1; + echo CHILD2_2_DROP_LOCK_TABLES2; + echo CHILD2_2_CREATE_LOCK_TABLES1; + echo CHILD2_2_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_LOCK_TABLES1; + eval $CHILD2_2_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_LOCK_TABLES1; + eval $CHILD2_2_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1; +eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2; +eval CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK2; +--enable_query_log +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + + +--echo +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + SET INSERT_ID=5000; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo read only +let $MASTER_1_ENGINE_IS_SPIDER= + `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'Spider' OR + '$MASTER_1_HIDDEN_ENGINE_TYPE' = 'Spider', 1, 0)`; +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_READONLY1_1; + --let $MIN_VAL= `SELECT MIN(id) FROM t1` + --enable_query_log + SELECT id FROM t1 ORDER BY id; + --error 12518 + INSERT INTO t1 (id) VALUES (1); + --error 12518 + eval UPDATE t1 SET id = 4 WHERE id = $MIN_VAL; + --error 12518 + eval DELETE FROM t1 WHERE id = $MIN_VAL; + --error 12518 + DELETE FROM t1; + --error 12518 + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 2.27 +--echo error mode +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_ERROR_MODE1_1; + --enable_query_log + SELECT id FROM t1 ORDER BY id; + INSERT INTO t1 (id) VALUES (1); + DELETE FROM t1; + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 3.0 +--echo is null +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_KEY_TABLES1; + echo CHILD2_1_CREATE_TEXT_KEY_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_KEY_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_KEY_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_TEXT_KEY1_1; +--enable_query_log +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a is null order by a limit 30; +select b from t1 where b is null order by b limit 30; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo direct_order_limit +--connection master_1 +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +select a, c from t1 where a = '10' order by b desc limit 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/handler/t/test_deinit.inc b/storage/spider/mysql-test/spider/handler/t/test_deinit.inc new file mode 100644 index 00000000000..989bde26d3c --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/test_deinit.inc @@ -0,0 +1,37 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/deinit_master_1.inc +--disconnect master_1 +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/deinit_child2_1.inc + --disconnect child2_1 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --echo child2_3 + --connection child2_3 + --source ../include/deinit_child2_3.inc + --disconnect child2_3 +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/deinit_child3_1.inc + --disconnect child3_1 + --echo child3_2 + --connection child3_2 + --source ../include/deinit_child3_2.inc + --disconnect child3_2 + --echo child3_3 + --connection child3_3 + --source ../include/deinit_child3_3.inc + --disconnect child3_3 +} diff --git a/storage/spider/mysql-test/spider/handler/t/test_init.inc b/storage/spider/mysql-test/spider/handler/t/test_init.inc new file mode 100644 index 00000000000..f2cd6c0269f --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/test_init.inc @@ -0,0 +1,74 @@ +# get connection and exist engine test +--echo for master_1 +--source connect_master_1.inc +--connection master_1 +CALL mtr.add_suppression("unknown variable"); +SET SESSION sql_log_bin= 0; +--let $MASTER_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $MASTER_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_master_1.inc +--source have_engine.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --source connect_child2_1.inc + --connection child2_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE + --source ../include/init_child2_1.inc + --source have_engine.inc + --echo child2_2 + --source connect_child2_2.inc + --connection child2_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE + --source ../include/init_child2_2.inc + --source have_engine.inc + --echo child2_3 + --source connect_child2_3.inc + --connection child2_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE + --source ../include/init_child2_3.inc + --source have_engine.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --source connect_child3_1.inc + --connection child3_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE + --source ../include/init_child3_1.inc + --source have_engine.inc + --echo child3_2 + --source connect_child3_2.inc + --connection child3_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE + --source ../include/init_child3_2.inc + --source have_engine.inc + --echo child3_3 + --source connect_child3_3.inc + --connection child3_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE + --source ../include/init_child3_3.inc + --source have_engine.inc +} diff --git a/storage/spider/mysql-test/spider/handler/t/vp_fixes.test b/storage/spider/mysql-test/spider/handler/t/vp_fixes.test new file mode 100644 index 00000000000..46e7b0afc36 --- /dev/null +++ b/storage/spider/mysql-test/spider/handler/t/vp_fixes.test @@ -0,0 +1,358 @@ +# This test tests for VP's bug fixes +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 0.9 +--echo create different primary key table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--let $MASTER_1_IS_VP= `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'VP', 1, 0)` +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo create un-correspond primary key table +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/include/deinit_child2_1.inc b/storage/spider/mysql-test/spider/include/deinit_child2_1.inc new file mode 100644 index 00000000000..cee137a6aeb --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child2_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD2_1_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_child2_2.inc b/storage/spider/mysql-test/spider/include/deinit_child2_2.inc new file mode 100644 index 00000000000..a1f9fe3fb19 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child2_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD2_2_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_child2_3.inc b/storage/spider/mysql-test/spider/include/deinit_child2_3.inc new file mode 100644 index 00000000000..f996a40e786 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child2_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD2_3_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_child3_1.inc b/storage/spider/mysql-test/spider/include/deinit_child3_1.inc new file mode 100644 index 00000000000..e0e3a4c41f4 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_1_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_child3_2.inc b/storage/spider/mysql-test/spider/include/deinit_child3_2.inc new file mode 100644 index 00000000000..82eb70d331f --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_2_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_child3_3.inc b/storage/spider/mysql-test/spider/include/deinit_child3_3.inc new file mode 100644 index 00000000000..3741ef76c3c --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_3_ENGINE +--source ../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_engine.inc b/storage/spider/mysql-test/spider/include/deinit_engine.inc new file mode 100644 index 00000000000..f3b6b3189f5 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_engine.inc @@ -0,0 +1,4 @@ +if ($INIT_TEST_ENGINE) +{ + --echo Deinit $TEST_ENGINE_TYPE engine +} diff --git a/storage/spider/mysql-test/spider/include/deinit_handlersocket.inc b/storage/spider/mysql-test/spider/include/deinit_handlersocket.inc new file mode 100644 index 00000000000..3ebf80ef675 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_handlersocket.inc @@ -0,0 +1 @@ +UNINSTALL PLUGIN handlersocket; diff --git a/storage/spider/mysql-test/spider/include/deinit_innodb_plugin.inc b/storage/spider/mysql-test/spider/include/deinit_innodb_plugin.inc new file mode 100644 index 00000000000..d1013fe86d6 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_innodb_plugin.inc @@ -0,0 +1 @@ +UNINSTALL PLUGIN InnoDB; diff --git a/storage/spider/mysql-test/spider/include/deinit_master_1.inc b/storage/spider/mysql-test/spider/include/deinit_master_1.inc new file mode 100644 index 00000000000..482c8013734 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_master_1.inc @@ -0,0 +1 @@ +--source ../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/include/deinit_slave1_1.inc b/storage/spider/mysql-test/spider/include/deinit_slave1_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/deinit_spider.inc b/storage/spider/mysql-test/spider/include/deinit_spider.inc new file mode 100644 index 00000000000..c9c414eb56e --- /dev/null +++ b/storage/spider/mysql-test/spider/include/deinit_spider.inc @@ -0,0 +1,17 @@ +DROP FUNCTION spider_direct_sql; +DROP FUNCTION spider_bg_direct_sql; +DROP FUNCTION spider_ping_table; +DROP FUNCTION spider_copy_tables; +DROP FUNCTION spider_flush_table_mon_cache; +UNINSTALL PLUGIN spider; +DROP TABLE IF EXISTS mysql.spider_xa; +DROP TABLE IF EXISTS mysql.spider_xa_member; +DROP TABLE IF EXISTS mysql.spider_tables; +DROP TABLE IF EXISTS mysql.spider_link_mon_servers; +DROP TABLE IF EXISTS mysql.spider_link_failed_log; +DROP SERVER s_2_1; +DROP SERVER s_2_2; +DROP SERVER s_2_3; +DROP SERVER s_3_1; +DROP SERVER s_3_2; +DROP SERVER s_3_3; diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child2_1.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child2_2.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child2_3.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child3_1.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child3_1.inc new file mode 100644 index 00000000000..f5f7db7e3fa --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_deinit_child3_1.inc @@ -0,0 +1 @@ +--source ../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child3_2.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child3_2.inc new file mode 100644 index 00000000000..f5f7db7e3fa --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_deinit_child3_2.inc @@ -0,0 +1 @@ +--source ../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_child3_3.inc b/storage/spider/mysql-test/spider/include/ha_deinit_child3_3.inc new file mode 100644 index 00000000000..f5f7db7e3fa --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_deinit_child3_3.inc @@ -0,0 +1 @@ +--source ../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/include/ha_deinit_master_1.inc b/storage/spider/mysql-test/spider/include/ha_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/ha_init_child2_1.inc b/storage/spider/mysql-test/spider/include/ha_init_child2_1.inc new file mode 100644 index 00000000000..59c0175d349 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child2_1.inc @@ -0,0 +1,8 @@ +let $CHILD2_1_HA_AS_DROP_TABLES= + $CHILD2_1_DROP_TABLES; +let $CHILD2_1_HA_AS_CREATE_TABLES= + $CHILD2_1_CREATE_TABLES; +let $CHILD2_1_HA_AS_DROP_TABLES2= + $CHILD2_1_DROP_TABLES2; +let $CHILD2_1_HA_AS_CREATE_TABLES2= + $CHILD2_1_CREATE_TABLES2; diff --git a/storage/spider/mysql-test/spider/include/ha_init_child2_2.inc b/storage/spider/mysql-test/spider/include/ha_init_child2_2.inc new file mode 100644 index 00000000000..90d27ed704d --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child2_2.inc @@ -0,0 +1,4 @@ +let $CHILD2_2_HA_DROP_TABLES= + $CHILD2_2_DROP_TABLES; +let $CHILD2_2_HA_CREATE_TABLES= + $CHILD2_2_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/include/ha_init_child2_3.inc b/storage/spider/mysql-test/spider/include/ha_init_child2_3.inc new file mode 100644 index 00000000000..11abf112b1f --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child2_3.inc @@ -0,0 +1,4 @@ +let $CHILD2_3_HA_DROP_TABLES= + $CHILD2_3_DROP_TABLES; +let $CHILD2_3_HA_CREATE_TABLES= + $CHILD2_3_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/include/ha_init_child3_1.inc b/storage/spider/mysql-test/spider/include/ha_init_child3_1.inc new file mode 100644 index 00000000000..67f6676a07a --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child3_1.inc @@ -0,0 +1,140 @@ +--let $CHILD3_1_ENGINE_TYPE=Spider +--let $CHILD3_1_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_1_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_1_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_1_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/include/ha_init_child3_2.inc b/storage/spider/mysql-test/spider/include/ha_init_child3_2.inc new file mode 100644 index 00000000000..9b61a2e2b73 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child3_2.inc @@ -0,0 +1,140 @@ +--let $CHILD3_2_ENGINE_TYPE=Spider +--let $CHILD3_2_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_2_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_2_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_2_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_2_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_2_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_2_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_2_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_2_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_2_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_2_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/include/ha_init_child3_3.inc b/storage/spider/mysql-test/spider/include/ha_init_child3_3.inc new file mode 100644 index 00000000000..5724a50b3d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_child3_3.inc @@ -0,0 +1,140 @@ +--let $CHILD3_3_ENGINE_TYPE=Spider +--let $CHILD3_3_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_3_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_3_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_3_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_3_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_3_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_3_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_3_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_3_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_3_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_3_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/include/ha_init_master_1.inc b/storage/spider/mysql-test/spider/include/ha_init_master_1.inc new file mode 100644 index 00000000000..78797d80ce7 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/ha_init_master_1.inc @@ -0,0 +1,105 @@ +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $MASTER_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $MASTER_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $MASTER_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $MASTER_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $MASTER_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +let $MASTER_1_COPY_TABLES_2_1= + SELECT spider_copy_tables('ta_l', '0', '1'); + +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $MASTER_1_COMMENT_HA_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_COMMENT_HA_AS_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $MASTER_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $MASTER_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +let $MASTER_1_COPY_TABLES_P_2_1= + SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +let $MASTER_1_CHECK_HA_STATUS= + SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +let $MASTER_1_CHANGE_HA_MON= + SELECT spider_flush_table_mon_cache(); diff --git a/storage/spider/mysql-test/spider/include/hs_deinit_child2_1.inc b/storage/spider/mysql-test/spider/include/hs_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/hs_deinit_child2_2.inc b/storage/spider/mysql-test/spider/include/hs_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/hs_deinit_child2_3.inc b/storage/spider/mysql-test/spider/include/hs_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/hs_deinit_master_1.inc b/storage/spider/mysql-test/spider/include/hs_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/hs_init_child2_1.inc b/storage/spider/mysql-test/spider/include/hs_init_child2_1.inc new file mode 100644 index 00000000000..2ea1c0c9cd6 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/hs_init_child2_1.inc @@ -0,0 +1,24 @@ +let $CHILD2_1_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r; +let $CHILD2_1_HS_CREATE_TABLES= + CREATE TABLE hs_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r ORDER BY a; +let $CHILD2_1_HS_DROP_TABLES2= + DROP TABLE IF EXISTS hs_r2; +let $CHILD2_1_HS_CREATE_TABLES2= + CREATE TABLE hs_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_HS_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r2 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/include/hs_init_child2_2.inc b/storage/spider/mysql-test/spider/include/hs_init_child2_2.inc new file mode 100644 index 00000000000..7c69d73ced6 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/hs_init_child2_2.inc @@ -0,0 +1,12 @@ +let $CHILD2_2_HS_DROP_TABLES= + DROP TABLE IF EXISTS hs_r3; +let $CHILD2_2_HS_CREATE_TABLES= + CREATE TABLE hs_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + d INT DEFAULT 11, + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_HS_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s'), d FROM hs_r3 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/include/hs_init_child2_3.inc b/storage/spider/mysql-test/spider/include/hs_init_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/include/hs_init_master_1.inc b/storage/spider/mysql-test/spider/include/hs_init_master_1.inc new file mode 100644 index 00000000000..0ff5e2a10d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/hs_init_master_1.inc @@ -0,0 +1,12 @@ +let $MASTER_1_HS_COMMENT_TMP= + COMMENT=''; +let $MASTER_1_HS_COMMENT_2_1= + COMMENT='srv "s_2_1", table "hs_r", uhr "1", uhw "1", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"'; +let $MASTER_1_HS_COMMENT_P_2_1= + COMMENT='uhr "1", uhw "1"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) + COMMENT='srv "s_2_1", table "hs_r2", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", table "hs_r3", hrp "$CHILD2_2_HSRPORT", hwp "$CHILD2_2_HSWPORT"' + ); diff --git a/storage/spider/mysql-test/spider/include/init_child2_1.inc b/storage/spider/mysql-test/spider/include/init_child2_1.inc new file mode 100644 index 00000000000..ff4e1666ee1 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child2_1.inc @@ -0,0 +1,178 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD2_1_ENGINE= $INIT_TEST_ENGINE +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r; +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +let $CHILD2_1_DROP_TABLES2= + DROP TABLE IF EXISTS ta_r2; +let $CHILD2_1_CREATE_TABLES2= + CREATE TABLE ta_r2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES2= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r2 ORDER BY a; +let $CHILD2_1_DROP_TABLES3= + DROP TABLE IF EXISTS ta_r_no_idx; +let $CHILD2_1_CREATE_TABLES3= + CREATE TABLE ta_r_no_idx ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES3= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_no_idx ORDER BY a; +let $CHILD2_1_DROP_TABLES4= + DROP TABLE IF EXISTS ta_r_auto_inc; +let $CHILD2_1_CREATE_TABLES4= + CREATE TABLE ta_r_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES4= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_auto_inc + ORDER BY a; +let $CHILD2_1_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_1_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES5= + SELECT a, b, c FROM ta_r_int ORDER BY a; +let $CHILD2_1_DROP_TABLES6= + DROP TABLE IF EXISTS ta_r_3; +let $CHILD2_1_CREATE_TABLES6= + CREATE TABLE ta_r_3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TABLES6= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_3 ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r; +let $CHILD2_1_CREATE_FT_TABLES= + CREATE TABLE ft_r ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r ORDER BY a; +let $CHILD2_1_DROP_FT_TABLES2= + DROP TABLE IF EXISTS ft_r2; +let $CHILD2_1_CREATE_FT_TABLES2= + CREATE TABLE ft_r2 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_1_FT_ENGINE $CHILD2_1_FT_CHARSET; +let $CHILD2_1_SELECT_FT_TABLES2= + SELECT a, b, c, d FROM ft_r2 ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r; +let $CHILD2_1_CREATE_GM_TABLES= + CREATE TABLE gm_r ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r ORDER BY a; +let $CHILD2_1_DROP_GM_TABLES2= + DROP TABLE IF EXISTS gm_r2; +let $CHILD2_1_CREATE_GM_TABLES2= + CREATE TABLE gm_r2 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_1_GM_ENGINE $CHILD2_1_GM_CHARSET; +let $CHILD2_1_SELECT_GM_TABLES2= + SELECT a, b, c FROM gm_r2 ORDER BY a; +let $CHILD2_1_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_LOCK_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_2; +let $CHILD2_1_CREATE_LOCK_TABLES2= + CREATE TABLE t2_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_1; +let $CHILD2_1_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_1 ORDER BY id; +let $CHILD2_1_DROP_TEXT_PK_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_PK_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY (a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET2; +let $CHILD2_1_SELECT_TEXT_PK_TABLES1= + SELECT a FROM t1 ORDER BY a; +let $CHILD2_1_DROP_TEXT_KEY_TABLES1= + DROP TABLE IF EXISTS t1; +let $CHILD2_1_CREATE_TEXT_KEY_TABLES1= + CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +let $CHILD2_1_SELECT_TEXT_KEY_TABLES1= + SELECT a, b FROM t1 ORDER BY a, b; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_1_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_1_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_1_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 2; diff --git a/storage/spider/mysql-test/spider/include/init_child2_2.inc b/storage/spider/mysql-test/spider/include/init_child2_2.inc new file mode 100644 index 00000000000..b20783cc42b --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child2_2.inc @@ -0,0 +1,83 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD2_2_ENGINE= $INIT_TEST_ENGINE +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS ta_r3; +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE ta_r3 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_TABLES5= + DROP TABLE IF EXISTS ta_r_int; +let $CHILD2_2_CREATE_TABLES5= + CREATE TABLE ta_r_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r3 ORDER BY a; +let $CHILD2_2_DROP_FT_TABLES= + DROP TABLE IF EXISTS ft_r3; +let $CHILD2_2_CREATE_FT_TABLES= + CREATE TABLE ft_r3 ( + a INT DEFAULT 0, + b TEXT, + c TEXT, + d TEXT, + PRIMARY KEY(a), + FULLTEXT INDEX ft_idx1(b), + FULLTEXT INDEX ft_idx2(c) + ) $CHILD2_2_FT_ENGINE $CHILD2_2_FT_CHARSET; +let $CHILD2_2_SELECT_FT_TABLES= + SELECT a, b, c, d FROM ft_r3 ORDER BY a; +let $CHILD2_2_DROP_GM_TABLES= + DROP TABLE IF EXISTS gm_r3; +let $CHILD2_2_CREATE_GM_TABLES= + CREATE TABLE gm_r3 ( + a INT DEFAULT 0, + b GEOMETRY NOT NULL, + c GEOMETRY NOT NULL, + PRIMARY KEY(a), + SPATIAL INDEX sp_idx1(b), + SPATIAL INDEX sp_idx2(c) + ) $CHILD2_2_GM_ENGINE $CHILD2_2_GM_CHARSET; +let $CHILD2_2_SELECT_GM_TABLES= + SELECT a, b, c FROM gm_r3 ORDER BY a; +let $CHILD2_2_DROP_LOCK_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_LOCK_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_LOCK_TABLES2= + DROP TABLE IF EXISTS t2_1; +let $CHILD2_2_CREATE_LOCK_TABLES2= + CREATE TABLE t2_1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_DROP_INCREMENT_TABLES1= + DROP TABLE IF EXISTS t1_2; +let $CHILD2_2_CREATE_INCREMENT_TABLES1= + CREATE TABLE t1_2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +let $CHILD2_2_SELECT_INCREMENT_TABLES1= + SELECT id FROM t1_2 ORDER BY id; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT1= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 1; +let $CHILD2_2_AUTO_INCREMENT_INCREMENT2= + SET GLOBAL AUTO_INCREMENT_INCREMENT = 4; +let $CHILD2_2_AUTO_INCREMENT_OFFSET1= + SET GLOBAL AUTO_INCREMENT_OFFSET = 1; +let $CHILD2_2_AUTO_INCREMENT_OFFSET2= + SET GLOBAL AUTO_INCREMENT_OFFSET = 3; diff --git a/storage/spider/mysql-test/spider/include/init_child2_3.inc b/storage/spider/mysql-test/spider/include/init_child2_3.inc new file mode 100644 index 00000000000..4e8d289bdc9 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child2_3.inc @@ -0,0 +1,14 @@ +--let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD2_3_ENGINE= $INIT_TEST_ENGINE +let $CHILD2_3_DROP_TABLES= + DROP TABLE IF EXISTS ta_r4; +let $CHILD2_3_CREATE_TABLES= + CREATE TABLE ta_r4 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD2_3_ENGINE $CHILD2_3_CHARSET; +let $CHILD2_3_SELECT_TABLES= + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r4 ORDER BY a; diff --git a/storage/spider/mysql-test/spider/include/init_child3_1.inc b/storage/spider/mysql-test/spider/include/init_child3_1.inc new file mode 100644 index 00000000000..7e4c05d9500 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD3_1_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/include/init_child3_2.inc b/storage/spider/mysql-test/spider/include/init_child3_2.inc new file mode 100644 index 00000000000..246a7985984 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD3_2_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/include/init_child3_3.inc b/storage/spider/mysql-test/spider/include/init_child3_3.inc new file mode 100644 index 00000000000..a0e5fdf6981 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--source ../include/init_engine.inc +--let $INIT_CHILD3_3_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/include/init_engine.inc b/storage/spider/mysql-test/spider/include/init_engine.inc new file mode 100644 index 00000000000..820a598f54e --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_engine.inc @@ -0,0 +1,10 @@ +let $INIT_TEST_ENGINE=0; +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + if (!$SKIP_REASON) + { + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" + } +} diff --git a/storage/spider/mysql-test/spider/include/init_master_1.inc b/storage/spider/mysql-test/spider/include/init_master_1.inc new file mode 100644 index 00000000000..93947a8d454 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_master_1.inc @@ -0,0 +1,186 @@ +--source ../include/init_spider.inc +SET spider_direct_order_limit= 10000; +SET spider_init_sql_alloc_size= 1; +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "ta_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password "", prt "2000000"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT2_2_1= + COMMENT='database "auto_test_remote", table "ta_r_no_idx"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password "", prt "2000000"'; +} +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1", table "ta_r2", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT2_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ta_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT3_2_1= + COMMENT='database "auto_test_remote", table "ta_r_auto_inc"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT3_P_2_1= + COMMENT='table "ta_r_int"' + PARTITION BY LIST(MOD(a, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='srv "s_2_1", priority "1000"', + PARTITION pt2 VALUES IN (1) + COMMENT='srv "s_2_2", priority "1000001"' + ); +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT4_2_1= + COMMENT='database "auto_test_remote", table "ta_r_int"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT5_2_1= + COMMENT='database "auto_test_remote", table "ta_r_3"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", port "$CHILD2_1_MYPORT", user "root", + password ""'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "auto_test_remote", table "ft_r"' + CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root", + password ""'; +} +let $MASTER_1_COMMENT2_FT_P_2_1= + COMMENT='table "ft_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ft_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_GM_2_1= + COMMENT='srv "s_2_1", table "gm_r"'; +let $MASTER_1_COMMENT2_GM_P_2_1= + COMMENT='table "gm_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "gm_r2", priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001"' + ); +let $MASTER_1_COMMENT_LOCK1= + COMMENT 'tbl "t1_1 t1_2", srv "s_2_1 s_2_2"'; +let $MASTER_1_COMMENT_LOCK2= + COMMENT 'tbl "t2_1 t2_2", srv "s_2_2 s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_1= + COMMENT 'aim "0", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_INCREMENT1_P_1= + COMMENT 'aim "0"' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='tbl "t1_1", srv "s_2_1"', + PARTITION pt2 VALUES IN (1) + COMMENT='tbl "t1_2", srv "s_2_2"' + ); +let $MASTER_1_COMMENT_READONLY1_1= + COMMENT 'read_only_mode "1", tbl "t1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_ERROR_MODE1_1= + COMMENT 'erm "1", ewm "1", tbl "ter1_1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_PK1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_COMMENT_TEXT_KEY1_1= + COMMENT 'tbl "t1", srv "s_2_1"'; +let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_update'; +let $MASTER_1_CHECK_DIRECT_DELETE_STATUS= + SHOW STATUS LIKE 'Spider_direct_delete'; +let $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS= + SHOW STATUS LIKE 'Spider_direct_order_limit'; +let $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS= + SHOW STATUS LIKE 'Spider_direct_aggregate'; +let $MASTER_1_AUTO_INCREMENT_INCREMENT1= + SET SESSION AUTO_INCREMENT_INCREMENT = 1 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_INCREMENT2= + SET SESSION AUTO_INCREMENT_INCREMENT = 777 $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET1= + SET SESSION AUTO_INCREMENT_OFFSET = 1 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 1', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET2= + SET SESSION AUTO_INCREMENT_OFFSET = 777 $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', + 'srv "s_2_1"') $STR_SEMICOLON + SELECT spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', + 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET3= + SET SESSION AUTO_INCREMENT_OFFSET = 1; +let $MASTER_1_AUTO_INCREMENT_OFFSET4= + SET SESSION AUTO_INCREMENT_OFFSET = 777; diff --git a/storage/spider/mysql-test/spider/include/init_slave1_1.inc b/storage/spider/mysql-test/spider/include/init_slave1_1.inc new file mode 100644 index 00000000000..87c05f1f690 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_slave1_1.inc @@ -0,0 +1,10 @@ +let $SLAVE1_1_COMMENT_INCREMENT1_1= + COMMENT ''; +let $SLAVE1_1_COMMENT_INCREMENT1_P_1= + COMMENT '' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='', + PARTITION pt2 VALUES IN (1) + COMMENT='' + ); diff --git a/storage/spider/mysql-test/spider/include/init_spider.inc b/storage/spider/mysql-test/spider/include/init_spider.inc new file mode 100644 index 00000000000..90c4b7d7084 --- /dev/null +++ b/storage/spider/mysql-test/spider/include/init_spider.inc @@ -0,0 +1,339 @@ +let $VERSION_COMPILE_OS_WIN= + `SELECT IF(@@version_compile_os like 'Win%', 1, 0)`; +if ($VERSION_COMPILE_OS_WIN) +{ + INSTALL PLUGIN spider SONAME 'ha_spider.dll'; + CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.dll'; + CREATE AGGREGATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.dll'; + CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.dll'; + CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.dll'; + CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.dll'; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote', + USER 'root', + PASSWORD '', + PORT $CHILD2_1_MYPORT + ); + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote2', + USER 'root', + PASSWORD '', + PORT $CHILD2_2_MYPORT + ); + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote3', + USER 'root', + PASSWORD '', + PORT $CHILD2_3_MYPORT + ); + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_1_MYPORT + ); + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_2_MYPORT + ); + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD2_3_MYPORT + ); +} +if (!$VERSION_COMPILE_OS_WIN) +{ + INSTALL PLUGIN spider SONAME 'ha_spider.so'; + CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so'; + CREATE AGGREGATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; + CREATE FUNCTION spider_ping_table RETURNS INT SONAME 'ha_spider.so'; + CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so'; + CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so'; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote', + USER 'root', + PASSWORD '', + SOCKET '$CHILD2_1_MYSOCK' + ); + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote2', + USER 'root', + PASSWORD '', + SOCKET '$CHILD2_2_MYSOCK' + ); + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_remote3', + USER 'root', + PASSWORD '', + SOCKET '$CHILD2_3_MYSOCK' + ); + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_1_MYSOCK' + ); + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_2_MYSOCK' + ); + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_3_MYSOCK' + ); +} + +let $PLUGIN_VERSION= + `SELECT SUBSTRING_INDEX(plugin_version, '.', 1) + FROM information_schema.plugins + WHERE plugin_name = 'SPIDER'`; +if (`SELECT IF($PLUGIN_VERSION = 1, 1, 0)`) +{ + DROP TABLE IF EXISTS mysql.spider_xa; + CREATE TABLE mysql.spider_xa( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + status char(8) not null default '', + PRIMARY KEY (data, format_id, gtrid_length), + KEY idx1 (status) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_xa_member; + CREATE TABLE mysql.spider_xa_member( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + scheme char(64) not null default '', + host char(64) not null default '', + port char(5) not null default '', + socket char(64) not null default '', + username char(64) not null default '', + password char(64) not null default '', + PRIMARY KEY (data, format_id, gtrid_length, host, port, socket) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_tables; + CREATE TABLE mysql.spider_tables( + db_name char(64) not null default '', + table_name char(64) not null default '', + priority bigint not null default 0, + server char(64) default null, + scheme char(64) default null, + host char(64) default null, + port char(5) default null, + socket char(64) default null, + username char(64) default null, + password char(64) default null, + tgt_db_name char(64) default null, + tgt_table_name char(64) default null, + PRIMARY KEY (db_name, table_name), + KEY idx1 (priority) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +} +if (`SELECT IF($PLUGIN_VERSION = 2, 1, 0)`) +{ + DROP TABLE IF EXISTS mysql.spider_xa; + CREATE TABLE mysql.spider_xa( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + status char(8) not null default '', + PRIMARY KEY (data, format_id, gtrid_length), + KEY idx1 (status) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_xa_member; + CREATE TABLE mysql.spider_xa_member( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + scheme char(64) not null default '', + host char(64) not null default '', + port char(5) not null default '', + socket char(64) not null default '', + username char(64) not null default '', + password char(64) not null default '', + ssl_ca char(64) default null, + ssl_capath char(64) default null, + ssl_cert char(64) default null, + ssl_cipher char(64) default null, + ssl_key char(64) default null, + ssl_verify_server_cert tinyint not null default 0, + default_file char(64) default null, + default_group char(64) default null, + PRIMARY KEY (data, format_id, gtrid_length, host, port, socket) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_tables; + CREATE TABLE mysql.spider_tables( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id int not null default 0, + priority bigint not null default 0, + server char(64) default null, + scheme char(64) default null, + host char(64) default null, + port char(5) default null, + socket char(64) default null, + username char(64) default null, + password char(64) default null, + ssl_ca char(64) default null, + ssl_capath char(64) default null, + ssl_cert char(64) default null, + ssl_cipher char(64) default null, + ssl_key char(64) default null, + ssl_verify_server_cert tinyint not null default 0, + default_file char(64) default null, + default_group char(64) default null, + tgt_db_name char(64) default null, + tgt_table_name char(64) default null, + link_status tinyint not null default 1, + PRIMARY KEY (db_name, table_name, link_id), + KEY idx1 (priority) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_link_mon_servers; + CREATE TABLE mysql.spider_link_mon_servers( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id char(5) not null default '', + sid int not null default 0, + server char(64) default null, + scheme char(64) default null, + host char(64) default null, + port char(5) default null, + socket char(64) default null, + username char(64) default null, + password char(64) default null, + ssl_ca char(64) default null, + ssl_capath char(64) default null, + ssl_cert char(64) default null, + ssl_cipher char(64) default null, + ssl_key char(64) default null, + ssl_verify_server_cert tinyint not null default 0, + default_file char(64) default null, + default_group char(64) default null, + PRIMARY KEY (db_name, table_name, link_id, sid) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_link_failed_log; + CREATE TABLE mysql.spider_link_failed_log( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id int not null default 0, + failed_time timestamp not null default current_timestamp + ) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +} +if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`) +{ + DROP TABLE IF EXISTS mysql.spider_xa; + CREATE TABLE mysql.spider_xa( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + status char(8) not null default '', + PRIMARY KEY (data, format_id, gtrid_length), + KEY idx1 (status) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_xa_member; + CREATE TABLE mysql.spider_xa_member( + format_id int not null default 0, + gtrid_length int not null default 0, + bqual_length int not null default 0, + data char(128) charset binary not null default '', + scheme char(64) not null default '', + host char(64) not null default '', + port char(5) not null default '', + socket text not null default '', + username char(64) not null default '', + password char(64) not null default '', + ssl_ca text default null, + ssl_capath text default null, + ssl_cert text default null, + ssl_cipher char(64) default null, + ssl_key text default null, + ssl_verify_server_cert tinyint not null default 0, + default_file text default null, + default_group char(64) default null, + KEY idx1 (data, format_id, gtrid_length, host) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_tables; + CREATE TABLE mysql.spider_tables( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id int not null default 0, + priority bigint not null default 0, + server char(64) default null, + scheme char(64) default null, + host char(64) default null, + port char(5) default null, + socket text default null, + username char(64) default null, + password char(64) default null, + ssl_ca text default null, + ssl_capath text default null, + ssl_cert text default null, + ssl_cipher char(64) default null, + ssl_key text default null, + ssl_verify_server_cert tinyint not null default 0, + default_file text default null, + default_group char(64) default null, + tgt_db_name char(64) default null, + tgt_table_name char(64) default null, + link_status tinyint not null default 1, + PRIMARY KEY (db_name, table_name, link_id), + KEY idx1 (priority) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_link_mon_servers; + CREATE TABLE mysql.spider_link_mon_servers( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id char(5) not null default '', + sid int not null default 0, + server char(64) default null, + scheme char(64) default null, + host char(64) default null, + port char(5) default null, + socket text default null, + username char(64) default null, + password char(64) default null, + ssl_ca text default null, + ssl_capath text default null, + ssl_cert text default null, + ssl_cipher char(64) default null, + ssl_key text default null, + ssl_verify_server_cert tinyint not null default 0, + default_file text default null, + default_group char(64) default null, + PRIMARY KEY (db_name, table_name, link_id, sid) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + DROP TABLE IF EXISTS mysql.spider_link_failed_log; + CREATE TABLE mysql.spider_link_failed_log( + db_name char(64) not null default '', + table_name char(64) not null default '', + link_id int not null default 0, + failed_time timestamp not null default current_timestamp + ) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +} + +SET spider_internal_sql_log_off= 0; diff --git a/storage/spider/mysql-test/spider/my.cnf b/storage/spider/mysql-test/spider/my.cnf new file mode 100644 index 00000000000..deca681c3a3 --- /dev/null +++ b/storage/spider/mysql-test/spider/my.cnf @@ -0,0 +1,177 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld.1.1] +log-bin= master-bin +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[mysqld.2.1] +loose_handlersocket_port= 20002 +loose_handlersocket_port_wr= 20003 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.2] +loose_handlersocket_port= 20004 +loose_handlersocket_port_wr= 20005 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[mysqld.2.3] + +[mysqld.3.1] +loose_partition= 1 + +[mysqld.3.2] +loose_partition= 1 + +[mysqld.3.3] +loose_partition= 1 + +[mysqld.4.1] +loose_partition= 1 + + +[ENV] +USE_GEOMETRY_TEST= 1 +USE_FULLTEXT_TEST= 1 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 1 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +SLAVE1_1_MYPORT= @mysqld.4.1.port +SLAVE1_1_MYSOCK= @mysqld.4.1.socket +SLAVE1_1_ENGINE_TYPE= MyISAM +SLAVE1_1_ENGINE= ENGINE=MyISAM +SLAVE1_1_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.2.1.port +CHILD2_1_HSRPORT= 20002 +CHILD2_1_HSWPORT= 20003 +CHILD2_1_MYSOCK= @mysqld.2.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_2_MYPORT= @mysqld.2.2.port +CHILD2_2_HSRPORT= 20004 +CHILD2_2_HSWPORT= 20005 +CHILD2_2_MYSOCK= @mysqld.2.2.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_3_MYPORT= @mysqld.2.3.port +CHILD2_3_MYSOCK= @mysqld.2.3.socket +CHILD2_3_ENGINE_TYPE= InnoDB +CHILD2_3_ENGINE= ENGINE=InnoDB +CHILD2_3_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_FT_MYPORT= @mysqld.2.1.port +CHILD2_1_FT_MYSOCK= @mysqld.2.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.2.2.port +CHILD2_2_FT_MYSOCK= @mysqld.2.2.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.2.1.port +CHILD2_1_GM_MYSOCK= @mysqld.2.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.2.2.port +CHILD2_2_GM_MYSOCK= @mysqld.2.2.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP3= 1 +OUTPUT_CHILD_GROUP3= 0 +CHILD3_1_MYPORT= @mysqld.3.1.port +CHILD3_1_MYSOCK= @mysqld.3.1.socket +CHILD3_1_ENGINE_TYPE= InnoDB +CHILD3_1_ENGINE= ENGINE=InnoDB +CHILD3_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_2_MYPORT= @mysqld.3.2.port +CHILD3_2_MYSOCK= @mysqld.3.2.socket +CHILD3_2_ENGINE_TYPE= InnoDB +CHILD3_2_ENGINE= ENGINE=InnoDB +CHILD3_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_3_MYPORT= @mysqld.3.3.port +CHILD3_3_MYSOCK= @mysqld.3.3.socket +CHILD3_3_ENGINE_TYPE= InnoDB +CHILD3_3_ENGINE= ENGINE=InnoDB +CHILD3_3_CHARSET= DEFAULT CHARSET=utf8 + +STR_SEMICOLON= ; + +#The followings are setted in include/init_xxx.inc files +#MASTER_1_COMMENT_2_1 +#MASTER_1_COMMENT2_2_1 +#MASTER_1_COMMENT3_2_1 +#MASTER_1_COMMENT4_2_1 +#MASTER_1_COMMENT5_2_1 +#MASTER_1_COMMENT_P_2_1 +#CHILD2_1_DROP_TABLES +#CHILD2_1_CREATE_TABLES +#CHILD2_1_SELECT_TABLES +#CHILD2_1_DROP_TABLES2 +#CHILD2_1_CREATE_TABLES2 +#CHILD2_1_SELECT_TABLES2 +#CHILD2_1_DROP_TABLES3 +#CHILD2_1_CREATE_TABLES3 +#CHILD2_1_SELECT_TABLES3 +#CHILD2_1_DROP_TABLES4 +#CHILD2_1_CREATE_TABLES4 +#CHILD2_1_SELECT_TABLES4 +#CHILD2_1_DROP_TABLES5 +#CHILD2_1_CREATE_TABLES5 +#CHILD2_1_SELECT_TABLES5 +#CHILD2_1_DROP_TABLES6 +#CHILD2_1_CREATE_TABLES6 +#CHILD2_1_SELECT_TABLES6 +#CHILD2_2_DROP_TABLES +#CHILD2_2_CREATE_TABLES +#CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child3_1.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_1.inc new file mode 100644 index 00000000000..9b6a9851ccb --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_1_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child3_2.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_2.inc new file mode 100644 index 00000000000..ac0bcdaa938 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_2_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_child3_3.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_3.inc new file mode 100644 index 00000000000..c93a9822d90 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/deinit_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_3_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_master_1.inc new file mode 100644 index 00000000000..c19e376d10a --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/deinit_master_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/deinit_slave1_1.inc b/storage/spider/mysql-test/spider/oracle/include/deinit_slave1_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_1.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_2.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_2.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_2.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_3.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_3.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_3.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_1.inc new file mode 100644 index 00000000000..59c0175d349 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_1.inc @@ -0,0 +1,8 @@ +let $CHILD2_1_HA_AS_DROP_TABLES= + $CHILD2_1_DROP_TABLES; +let $CHILD2_1_HA_AS_CREATE_TABLES= + $CHILD2_1_CREATE_TABLES; +let $CHILD2_1_HA_AS_DROP_TABLES2= + $CHILD2_1_DROP_TABLES2; +let $CHILD2_1_HA_AS_CREATE_TABLES2= + $CHILD2_1_CREATE_TABLES2; diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_2.inc new file mode 100644 index 00000000000..90d27ed704d --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_2.inc @@ -0,0 +1,4 @@ +let $CHILD2_2_HA_DROP_TABLES= + $CHILD2_2_DROP_TABLES; +let $CHILD2_2_HA_CREATE_TABLES= + $CHILD2_2_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_3.inc new file mode 100644 index 00000000000..11abf112b1f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child2_3.inc @@ -0,0 +1,4 @@ +let $CHILD2_3_HA_DROP_TABLES= + $CHILD2_3_DROP_TABLES; +let $CHILD2_3_HA_CREATE_TABLES= + $CHILD2_3_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_1.inc new file mode 100644 index 00000000000..67f6676a07a --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_1.inc @@ -0,0 +1,140 @@ +--let $CHILD3_1_ENGINE_TYPE=Spider +--let $CHILD3_1_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_1_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_1_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_1_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_2.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_2.inc new file mode 100644 index 00000000000..9b61a2e2b73 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_2.inc @@ -0,0 +1,140 @@ +--let $CHILD3_2_ENGINE_TYPE=Spider +--let $CHILD3_2_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_2_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_2_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_2_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_2_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_2_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_2_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_2_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_2_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_2_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_2_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_3.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_3.inc new file mode 100644 index 00000000000..5724a50b3d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_child3_3.inc @@ -0,0 +1,140 @@ +--let $CHILD3_3_ENGINE_TYPE=Spider +--let $CHILD3_3_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_3_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_3_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_3_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_3_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_3_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_3_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_3_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_3_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_3_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_3_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle/include/ha_init_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/ha_init_master_1.inc new file mode 100644 index 00000000000..8ace39ab641 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/ha_init_master_1.inc @@ -0,0 +1,109 @@ +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $MASTER_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $MASTER_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $MASTER_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE", lst "0 2"'; +let $MASTER_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE", lst "0 1"'; +let $MASTER_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE", lst "1 0"'; +let $MASTER_1_COPY_TABLES_2_1= + SELECT spider_copy_tables('ta_l', '0', '1'); + +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE"'; +} +let $MASTER_1_COMMENT_HA_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_COMMENT_HA_AS_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $MASTER_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $MASTER_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +let $MASTER_1_COPY_TABLES_P_2_1= + SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +let $MASTER_1_CHECK_HA_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +let $MASTER_1_CHANGE_HA_MON= + SELECT spider_flush_table_mon_cache(); diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/hs_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_1.inc new file mode 100644 index 00000000000..e0467b92307 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_1.inc @@ -0,0 +1,24 @@ +let $CHILD2_1_HS_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "hs_r" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_hs_r" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_DROP_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_CREATE_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "hs_r2" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_hs_r2" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_SELECT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r2" ORDER BY "a"', '', 'srv "s_2_1"'); diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_2.inc new file mode 100644 index 00000000000..0466acbc66b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_2.inc @@ -0,0 +1,12 @@ +let $CHILD2_2_HS_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_HS_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "hs_r3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_2_hs_r3" PRIMARY KEY("a") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_HS_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r3" ORDER BY "a"', '', 'srv "s_2_2"'); diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/hs_init_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle/include/hs_init_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/hs_init_master_1.inc new file mode 100644 index 00000000000..0ff5e2a10d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/hs_init_master_1.inc @@ -0,0 +1,12 @@ +let $MASTER_1_HS_COMMENT_TMP= + COMMENT=''; +let $MASTER_1_HS_COMMENT_2_1= + COMMENT='srv "s_2_1", table "hs_r", uhr "1", uhw "1", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"'; +let $MASTER_1_HS_COMMENT_P_2_1= + COMMENT='uhr "1", uhw "1"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) + COMMENT='srv "s_2_1", table "hs_r2", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", table "hs_r3", hrp "$CHILD2_2_HSRPORT", hwp "$CHILD2_2_HSWPORT"' + ); diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child2_1.inc b/storage/spider/mysql-test/spider/oracle/include/init_child2_1.inc new file mode 100644 index 00000000000..18dcc7159cc --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child2_1.inc @@ -0,0 +1,192 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_1"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_1"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r" PRIMARY KEY("a") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1" ON "ta_r"("b")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "ta_r2" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r2" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES3= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_no_idx"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES3= + SELECT spider_direct_sql('CREATE TABLE "ta_r_no_idx" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\') + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES3= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_no_idx" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES4= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_auto_inc"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES4= + SELECT spider_direct_sql('CREATE TABLE "ta_r_auto_inc" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r_auto_inc" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES4= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_auto_inc" + ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES5= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "s_2_1_ta_r_int"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES5= + SELECT spider_direct_sql('CREATE TABLE "s_2_1_ta_r_int" ( + "a" INT DEFAULT 3, + "b" INT DEFAULT 10, + "c" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_ta_r_int" PRIMARY KEY("a") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_s_2_1_ta_r_int" ON "s_2_1_ta_r_int"("b")', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_s_2_1_ta_r_int" ON "s_2_1_ta_r_int"("c")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES5= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "s_2_1_ta_r_int" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES6= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES6= + SELECT spider_direct_sql('CREATE TABLE "ta_r_3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\') + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES6= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_3" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_FT_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_FT_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ft_r" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_1_ft_r" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_FT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_FT_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_FT_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "ft_r2" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_1_ft_r2" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_FT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_GM_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_GM_TABLES= + SELECT spider_direct_sql('CREATE TABLE "gm_r" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_1_gm_r" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_GM_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_GM_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_GM_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "gm_r2" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_1_gm_r2" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_GM_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_LOCK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_LOCK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t1_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_LOCK_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t2_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_LOCK_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "t2_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t2_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_INCREMENT_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_INCREMENT_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t1_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_INCREMENT_TABLES1= + SELECT spider_direct_sql('SELECT "id" FROM "t1_1" ORDER BY "id"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TEXT_PK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TEXT_PK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1" ( + "a" VARCHAR(255), + CONSTRAINT "pk_s_2_1_t1" PRIMARY KEY ("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TEXT_PK_TABLES1= + SELECT spider_direct_sql('SELECT "a" FROM "t1" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1" ( + "a" VARCHAR(255), + "b" VARCHAR(255), + "c" VARCHAR(255), + CONSTRAINT "pk_s_2_1_t1" PRIMARY KEY ("c") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_t1" ON "t1"("a","b")', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_t1" ON "t1"("b")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "t1" ORDER BY "c"', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_INCREMENT1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_INCREMENT2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_OFFSET1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_OFFSET2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"'); diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child2_2.inc b/storage/spider/mysql-test/spider/oracle/include/init_child2_2.inc new file mode 100644 index 00000000000..117040dcca6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child2_2.inc @@ -0,0 +1,94 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_2"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_2"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_2_ta_r3" PRIMARY KEY("a") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_TABLES5= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "s_2_2_ta_r_int"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_TABLES5= + SELECT spider_direct_sql('CREATE TABLE "s_2_2_ta_r_int" ( + "a" INT DEFAULT 3, + "b" INT DEFAULT 10, + "c" INT DEFAULT 11, + CONSTRAINT "pk_s_2_2_ta_r_int" PRIMARY KEY("a") + )', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_s_2_2_ta_r_int" ON "s_2_2_ta_r_int"("b")', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_s_2_2_ta_r_int" ON "s_2_2_ta_r_int"("c")', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_FT_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_FT_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ft_r3" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_2_ft_r3" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_FT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_GM_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_GM_TABLES= + SELECT spider_direct_sql('CREATE TABLE "gm_r3" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_2_gm_r3" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_GM_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_LOCK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_LOCK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t1_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_LOCK_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t2_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_LOCK_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "t2_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t2_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_INCREMENT_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_INCREMENT_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t1_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_INCREMENT_TABLES1= + SELECT spider_direct_sql('SELECT "id" FROM "t1_2" ORDER BY "id"', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_INCREMENT1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_INCREMENT2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_OFFSET1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_OFFSET2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child2_3.inc b/storage/spider/mysql-test/spider/oracle/include/init_child2_3.inc new file mode 100644 index 00000000000..5c06a9f6a73 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child2_3.inc @@ -0,0 +1,15 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_3"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_3"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_3"'); +let $CHILD2_3_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r4"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_3"'); +let $CHILD2_3_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r4" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_3_ta_r4" PRIMARY KEY("a") + )', '', 'srv "s_2_3"'); +let $CHILD2_3_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r4" ORDER BY "a"', '', 'srv "s_2_3"'); diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child3_1.inc b/storage/spider/mysql-test/spider/oracle/include/init_child3_1.inc new file mode 100644 index 00000000000..f70afeb58de --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_1_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child3_2.inc b/storage/spider/mysql-test/spider/oracle/include/init_child3_2.inc new file mode 100644 index 00000000000..e84567f2243 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_2_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle/include/init_child3_3.inc b/storage/spider/mysql-test/spider/oracle/include/init_child3_3.inc new file mode 100644 index 00000000000..d3f31049ff6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_3_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle/include/init_master_1.inc b/storage/spider/mysql-test/spider/oracle/include/init_master_1.inc new file mode 100644 index 00000000000..8e79b984364 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_master_1.inc @@ -0,0 +1,149 @@ +--source ../include/init_spider.inc +SET spider_direct_order_limit= 10000; +SET spider_init_sql_alloc_size= 1; +SET spider_conn_recycle_mode= 2; +let $MASTER_1_COMMENT_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r", wrapper "oracle", + pk_name "pk_s_2_1_ta_r"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD"'; +let $MASTER_1_COMMENT2_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_no_idx", wrapper "oracle", + pk_name "pk_s_2_1_ta_r_no_idx"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", prt "2000000"'; +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1", table "ta_r2", + priority "1000", pk_name "pk_s_2_1_ta_r2"', + PARTITION pt2 COMMENT='srv "s_2_2", priority "1000001", + pk_name "pk_s_2_2_ta_r3"' + ); +let $MASTER_1_COMMENT2_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ta_r2", priority "1000", pk_name "pk_s_2_1_ta_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ta_r3"' + ); +let $MASTER_1_COMMENT3_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_auto_inc", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_auto_inc"'; +let $MASTER_1_COMMENT3_P_2_1= + COMMENT='table "s_2_1_ta_r_int"' + PARTITION BY LIST(MOD(a, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='srv "s_2_1", priority "1000", pk_name "pk_s_2_1_ta_r_int"', + PARTITION pt2 VALUES IN (1) + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ta_r_int", + table "s_2_2_ta_r_int"' + ); +let $MASTER_1_COMMENT4_2_1= + COMMENT='database "$ORACLE_DATABASE", table "s_2_1_ta_r_int", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_int"'; +let $MASTER_1_COMMENT5_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_3", wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_3"'; +let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ft_r", wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ft_r"'; +let $MASTER_1_COMMENT2_FT_P_2_1= + COMMENT='table "ft_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ft_r2", priority "1000", pk_name "pk_s_2_1_ft_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ft_r3"' + ); +let $MASTER_1_COMMENT_GM_2_1= + COMMENT='srv "s_2_1", table "gm_r", pk_name "pk_s_2_1_gm_r"'; +let $MASTER_1_COMMENT2_GM_P_2_1= + COMMENT='table "gm_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "gm_r2", priority "1000", pk_name "pk_s_2_1_gm_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_gm_r3"' + ); +let $MASTER_1_COMMENT_LOCK1= + COMMENT 'tbl "t1_1 t1_2", srv "s_2_1 s_2_2", + pk_name "pk_s_2_1_t1_1 pk_s_2_2_t1_2"'; +let $MASTER_1_COMMENT_LOCK2= + COMMENT 'tbl "t2_1 t2_2", srv "s_2_2 s_2_1", + pk_name "pk_s_2_2_t2_1 pk_s_2_1_t2_2"'; +let $MASTER_1_COMMENT_INCREMENT1_1= + COMMENT 'aim "0", tbl "t1_1", srv "s_2_1", pk_name "pk_s_2_1_t1_1"'; +let $MASTER_1_COMMENT_INCREMENT1_P_1= + COMMENT 'aim "0"' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='tbl "t1_1", srv "s_2_1", pk_name "pk_s_2_1_t1_1"', + PARTITION pt2 VALUES IN (1) + COMMENT='tbl "t1_2", srv "s_2_2", pk_name "pk_s_2_2_t1_2"' + ); +let $MASTER_1_COMMENT_READONLY1_1= + COMMENT 'read_only_mode "1", tbl "t1_1", srv "s_2_1", + pk_name "pk_s_2_1_t1_1"'; +let $MASTER_1_COMMENT_ERROR_MODE1_1= + COMMENT 'erm "1", ewm "1", tbl "ter1_1", srv "s_2_1", + pk_name "pk_s_2_1_ter1_1"'; +let $MASTER_1_COMMENT_TEXT_PK1_1= + COMMENT 'tbl "t1", srv "s_2_1", pk_name "pk_s_2_1_t1"'; +let $MASTER_1_COMMENT_TEXT_KEY1_1= + COMMENT 'tbl "t1", srv "s_2_1", pk_name "pk_s_2_1_t1"'; +let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +let $MASTER_1_CHECK_DIRECT_DELETE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +let $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +let $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +let $MASTER_1_AUTO_INCREMENT_INCREMENT1= + SET SESSION AUTO_INCREMENT_INCREMENT = 1 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_INCREMENT2= + SET SESSION AUTO_INCREMENT_INCREMENT = 777 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET1= + SET SESSION AUTO_INCREMENT_OFFSET = 1 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET2= + SET SESSION AUTO_INCREMENT_OFFSET = 777 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET3= + SET SESSION AUTO_INCREMENT_OFFSET = 1; +let $MASTER_1_AUTO_INCREMENT_OFFSET4= + SET SESSION AUTO_INCREMENT_OFFSET = 777; diff --git a/storage/spider/mysql-test/spider/oracle/include/init_slave1_1.inc b/storage/spider/mysql-test/spider/oracle/include/init_slave1_1.inc new file mode 100644 index 00000000000..87c05f1f690 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_slave1_1.inc @@ -0,0 +1,10 @@ +let $SLAVE1_1_COMMENT_INCREMENT1_1= + COMMENT ''; +let $SLAVE1_1_COMMENT_INCREMENT1_P_1= + COMMENT '' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='', + PARTITION pt2 VALUES IN (1) + COMMENT='' + ); diff --git a/storage/spider/mysql-test/spider/oracle/include/init_spider.inc b/storage/spider/mysql-test/spider/oracle/include/init_spider.inc new file mode 100644 index 00000000000..ff9ac9aee29 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/include/init_spider.inc @@ -0,0 +1,105 @@ +--source ../../include/init_spider.inc +let $VERSION_COMPILE_OS_WIN= + `SELECT IF(@@version_compile_os like 'Win%', 1, 0)`; +if ($VERSION_COMPILE_OS_WIN) +{ + eval DROP SERVER s_2_1; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_2; + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_3; + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_3_1; + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_1_MYPORT + ); + eval DROP SERVER s_3_2; + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_2_MYPORT + ); + eval DROP SERVER s_3_3; + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD2_3_MYPORT + ); +} +if (!$VERSION_COMPILE_OS_WIN) +{ + eval DROP SERVER s_2_1; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_2; + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_3; + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_3_1; + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_1_MYSOCK' + ); + eval DROP SERVER s_3_2; + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_2_MYSOCK' + ); + eval DROP SERVER s_3_3; + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_3_MYSOCK' + ); +} diff --git a/storage/spider/mysql-test/spider/oracle/my.cnf b/storage/spider/mysql-test/spider/oracle/my.cnf new file mode 100644 index 00000000000..e24985bb8d4 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/my.cnf @@ -0,0 +1,146 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld.1.1] +log-bin= master-bin +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[mysqld.3.1] +loose_partition= 1 + +[mysqld.3.2] +loose_partition= 1 + +[mysqld.3.3] +loose_partition= 1 + +[mysqld.4.1] +loose_partition= 1 + + +[ENV] +USE_GEOMETRY_TEST= 0 +USE_FULLTEXT_TEST= 0 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 0 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +SLAVE1_1_MYPORT= @mysqld.4.1.port +SLAVE1_1_MYSOCK= @mysqld.4.1.socket +SLAVE1_1_ENGINE_TYPE= MyISAM +SLAVE1_1_ENGINE= ENGINE=MyISAM +SLAVE1_1_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.1.1.port +CHILD2_1_MYSOCK= @mysqld.1.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_2_MYPORT= @mysqld.1.1.port +CHILD2_2_MYSOCK= @mysqld.1.1.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_3_MYPORT= @mysqld.1.1.port +CHILD2_3_MYSOCK= @mysqld.1.1.socket +CHILD2_3_ENGINE_TYPE= InnoDB +CHILD2_3_ENGINE= ENGINE=InnoDB +CHILD2_3_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_FT_MYPORT= @mysqld.1.1.port +CHILD2_1_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.1.1.port +CHILD2_2_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.1.1.port +CHILD2_1_GM_MYSOCK= @mysqld.1.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.1.1.port +CHILD2_2_GM_MYSOCK= @mysqld.1.1.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP3= 1 +OUTPUT_CHILD_GROUP3= 0 +CHILD3_1_MYPORT= @mysqld.3.1.port +CHILD3_1_MYSOCK= @mysqld.3.1.socket +CHILD3_1_ENGINE_TYPE= InnoDB +CHILD3_1_ENGINE= ENGINE=InnoDB +CHILD3_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_2_MYPORT= @mysqld.3.2.port +CHILD3_2_MYSOCK= @mysqld.3.2.socket +CHILD3_2_ENGINE_TYPE= InnoDB +CHILD3_2_ENGINE= ENGINE=InnoDB +CHILD3_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_3_MYPORT= @mysqld.3.3.port +CHILD3_3_MYSOCK= @mysqld.3.3.socket +CHILD3_3_ENGINE_TYPE= InnoDB +CHILD3_3_ENGINE= ENGINE=InnoDB +CHILD3_3_CHARSET= DEFAULT CHARSET=utf8 +ORACLE_HOST= xe +ORACLE_PORT= 1521 +ORACLE_USER= system +ORACLE_PASSWORD= oracle +ORACLE_DATABASE= SYSTEM + +STR_SEMICOLON= ; + +#The followings are setted in include/init_xxx.inc files +#MASTER_1_COMMENT_2_1 +#MASTER_1_COMMENT2_2_1 +#MASTER_1_COMMENT3_2_1 +#MASTER_1_COMMENT4_2_1 +#MASTER_1_COMMENT5_2_1 +#MASTER_1_COMMENT_P_2_1 +#CHILD2_1_DROP_TABLES +#CHILD2_1_CREATE_TABLES +#CHILD2_1_SELECT_TABLES +#CHILD2_1_DROP_TABLES2 +#CHILD2_1_CREATE_TABLES2 +#CHILD2_1_SELECT_TABLES2 +#CHILD2_1_DROP_TABLES3 +#CHILD2_1_CREATE_TABLES3 +#CHILD2_1_SELECT_TABLES3 +#CHILD2_1_DROP_TABLES4 +#CHILD2_1_CREATE_TABLES4 +#CHILD2_1_SELECT_TABLES4 +#CHILD2_1_DROP_TABLES5 +#CHILD2_1_CREATE_TABLES5 +#CHILD2_1_SELECT_TABLES5 +#CHILD2_1_DROP_TABLES6 +#CHILD2_1_CREATE_TABLES6 +#CHILD2_1_SELECT_TABLES6 +#CHILD2_2_DROP_TABLES +#CHILD2_2_CREATE_TABLES +#CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/oracle/r/basic_sql.result b/storage/spider/mysql-test/spider/oracle/r/basic_sql.result new file mode 100644 index 00000000000..e6202327ef6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/basic_sql.result @@ -0,0 +1,701 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'f', '2008-07-01 10:21:39'), +(2, 'g', '2000-02-01 00:00:00'), +(3, 'j', '2007-05-04 20:03:11'), +(4, 'i', '2003-10-30 05:01:03'), +(5, 'h', '2001-10-31 23:59:59'); +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l +Warnings: +Warning 1062 Duplicate entry '1' for key 'PRIMARY' +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +Warning 1062 Duplicate entry '3' for key 'PRIMARY' +Warning 1062 Duplicate entry '4' for key 'PRIMARY' +Warning 1062 Duplicate entry '5' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create table with partition and select test +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create no index table +DROP TABLE IF EXISTS ta_l_no_idx; +CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table shared mode +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table for update +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table join +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table straight_join +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_small_result +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_big_result +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_buffer_result +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_cache +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_no_cache +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_calc_found_rows +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +SELECT found_rows(); +found_rows() +5 + +select high_priority +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select distinct +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select count +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select using index and pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using index pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +insert select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 + +insert low_priority +TRUNCATE TABLE ta_l; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert high_priority +TRUNCATE TABLE ta_l; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert ignore +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +Warnings: +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (insert) +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (update) +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2005-08-08 11:11:11 + +replace +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2008-02-02 02:02:02 + +replace select +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace select a +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace low_priority +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 g 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 h 2010-04-04 04:04:04 +2 g 2009-03-03 03:03:03 + +update join +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update partition pushdown +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 e 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update partition index pushdown +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete all +DELETE FROM ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE IGNORE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE QUICK FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete partition index pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +truncate +TRUNCATE TABLE ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/direct_aggregate.result b/storage/spider/mysql-test/spider/oracle/r/direct_aggregate.result new file mode 100644 index 00000000000..26860959718 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/direct_aggregate.result @@ -0,0 +1,132 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_aggregating test +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/direct_update.result b/storage/spider/mysql-test/spider/oracle/r/direct_update.result new file mode 100644 index 00000000000..db6066a6e46 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/direct_update.result @@ -0,0 +1,226 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_updating test +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-03 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l2 SET c = ADDDATE(c, 1); +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l2 SET b = 'x' WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-03 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l2 WHERE b = 'c'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l2 WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/function.result b/storage/spider/mysql-test/spider/oracle/r/function.result new file mode 100644 index 00000000000..764c774514b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/function.result @@ -0,0 +1,149 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +in() +CREATE TABLE t1 ( +a VARCHAR(255), +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1 +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-08-01 10:21:39 +2 b 1999-01-01 00:00:00 +3 e 2006-06-04 20:03:11 +4 d 2002-11-30 05:01:03 +5 c 2000-12-31 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-11-01 10:21:39 +2 b 1999-04-01 00:00:00 +3 e 2006-09-04 20:03:11 +4 d 2003-02-28 05:01:03 +5 c 2001-03-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-01 10:21:39 +2 b 1999-03-01 00:00:00 +3 e 2006-08-04 20:03:11 +4 d 2003-01-28 05:01:03 +5 c 2001-02-28 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-08 10:21:39 +2 b 1999-03-08 00:00:00 +3 e 2006-08-11 20:03:11 +4 d 2003-02-04 05:01:03 +5 c 2001-03-07 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 10:21:39 +2 b 1999-03-07 00:00:00 +3 e 2006-08-10 20:03:11 +4 d 2003-02-03 05:01:03 +5 c 2001-03-06 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:21:39 +2 b 1999-03-07 01:00:00 +3 e 2006-08-10 21:03:11 +4 d 2003-02-03 06:01:03 +5 c 2001-03-07 00:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:39 +2 b 1999-03-07 00:59:00 +3 e 2006-08-10 21:02:11 +4 d 2003-02-03 06:00:03 +5 c 2001-03-07 00:58:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:40 +2 b 1999-03-07 00:59:01 +3 e 2006-08-10 21:02:12 +4 d 2003-02-03 06:00:04 +5 c 2001-03-07 00:59:00 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/ha.result b/storage/spider/mysql-test/spider/oracle/r/ha.result new file mode 100644 index 00000000000..95b428eb1ff --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/ha.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +test select 1 +SELECT 1; +1 +1 + +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 0 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r3' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", + database "SYSTEM", lst "0 2"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 2 +SELECT spider_copy_tables('ta_l', '0', '1'); +spider_copy_tables('ta_l', '0', '1') +1 +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", + database "SYSTEM", lst "0 1"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r4' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 2 +SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +spider_copy_tables('ta_l2#P#pt2', '0', '1') +1 +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +active standby test +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 3 +auto_test_local ta_l 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", alc "1", + database "SYSTEM", lst "1 0"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r2' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 3 +auto_test_local ta_l2#P#pt2 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +auto_test_local ta_l2#P#pt2 0 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 3 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/spider3_fixes.result b/storage/spider/mysql-test/spider/oracle/r/spider3_fixes.result new file mode 100644 index 00000000000..eb0c18da831 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/spider3_fixes.result @@ -0,0 +1,343 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +3.1 +auto_increment +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT MAX(id) FROM t1; +MAX(id) +1555 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2332 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +1555 +2331 +2332 +3109 +3886 +4663 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5439 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +1555 +2331 +2332 +3109 +3886 +4663 +5439 +6216 +6993 +7770 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 +auto_increment with partition +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +778 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT id FROM t1 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3109 +3886 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT id FROM t2 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3108 +3109 +3885 +3886 +4662 +5439 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/spider_fixes.result b/storage/spider/mysql-test/spider/oracle/r/spider_fixes.result new file mode 100644 index 00000000000..43f0709e2e3 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/spider_fixes.result @@ -0,0 +1,670 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +2.13 +select table with "order by desc" and "<" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 +2 b 2000-01-01 00:00:00 + +select table with "order by desc" and "<=" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +5 c 2001-12-31 23:59:59 +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 + +2.14 +update table with range scan and split_read +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-02-02 00:00:00 +3 e 2000-02-02 00:00:00 +4 d 2000-02-02 00:00:00 +5 c 2000-02-02 00:00:00 + +2.15 +select table with range scan +TRUNCATE TABLE ta_l; +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a int(11) NOT NULL DEFAULT '0', +b char(1) DEFAULT NULL, +c datetime DEFAULT NULL, +PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +CREATE TABLE ta_l_auto_inc ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tc_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END;; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 s 2008-12-31 20:59:59 + +2.17 +engine-condition-pushdown with "or" and joining +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +partition with sort +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +2.23 +partition update with moving partition +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); +UPDATE ta_l2 SET a = 4 WHERE a = 3; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 B 2010-09-26 00:00:00 +index merge +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 +index merge with partition +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT NOT NULL, +b INT DEFAULT 10, +c INT DEFAULT 11, +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +UPDATE ta_l_int SET c = 4 WHERE b = 2; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +0 2 4 +1 2 4 +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 + +2.25 +direct order limit +SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +Variable_name Value +Spider_direct_order_limit 0 +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +a b c +2 3 4 +4 5 6 +6 7 8 +SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +Variable_name Value +Spider_direct_order_limit 0 + +2.26 +lock tables +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1 +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 + +auto_increment with partition +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 + +read only +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1 +SELECT id FROM t1 ORDER BY id; +id +1000 +1554 +3108 +4662 +5000 +6216 +10000 +INSERT INTO t1 (id) VALUES (1); +ERROR HY000: Table 'auto_test_local.t1' is read only +UPDATE t1 SET id = 4 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1; +ERROR HY000: Table 'auto_test_local.t1' is read only +TRUNCATE t1; +ERROR HY000: Table 'auto_test_local.t1' is read only + +2.27 +error mode +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1 +SELECT id FROM t1 ORDER BY id; +id +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +INSERT INTO t1 (id) VALUES (1); +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +DELETE FROM t1; +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +TRUNCATE t1; +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error + +3.0 +is null +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a VARCHAR(255), +b VARCHAR(255), +c VARCHAR(255), +KEY idx1(a,b), +KEY idx2(b), +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1 +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +select a from t1 where a is null order by a limit 30; +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +select b from t1 where b is null order by b limit 30; +b +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +direct_order_limit +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +a b c +10 74 74 +10 42 42 +10 234 234 +10 202 202 +10 170 170 +select a, c from t1 where a = '10' order by b desc limit 5; +a c +10 74 +10 42 +10 234 +10 202 +10 170 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/r/vp_fixes.result b/storage/spider/mysql-test/spider/oracle/r/vp_fixes.result new file mode 100644 index 00000000000..15dd29aa4d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/r/vp_fixes.result @@ -0,0 +1,80 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +0.9 +create different primary key table +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT AUTO_INCREMENT, +c INT DEFAULT 11, +PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT DEFAULT 12, +c INT DEFAULT 11, +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/basic_sql.test b/storage/spider/mysql-test/spider/oracle/t/basic_sql.test new file mode 100644 index 00000000000..2264b0e4e37 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/basic_sql.test @@ -0,0 +1,3189 @@ +# This test tests by executing basic SQL +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'f', '2008-07-01 10:21:39'), + (2, 'g', '2000-02-01 00:00:00'), + (3, 'j', '2007-05-04 20:03:11'), + (4, 'i', '2003-10-30 05:01:03'), + (5, 'h', '2001-10-31 23:59:59'); +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT IGNORE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + REPLACE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%replace %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table with partition and select test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + } + --enable_query_log + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo create no index table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES3; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_no_idx; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_NEEDPK) +{ + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + } +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES3; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; + +--echo +--echo select table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table shared mode +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table for update +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table straight_join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_small_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_big_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_buffer_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_no_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_calc_found_rows +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT found_rows(); + +--echo +--echo select high_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select distinct +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select count +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT count(*) FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join not use index +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using index and pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select partition using pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo select partition using index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.a > 0 AND a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo insert +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select a +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert low_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert high_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (insert) +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (update) +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update index pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update partition pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo update partition index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete all +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE IGNORE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE QUICK FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete partition pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete partition index pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo truncate +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'truncate %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child2_1.inc new file mode 100644 index 00000000000..cd9b0c9ca9b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child2_1.inc @@ -0,0 +1 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child2_2.inc new file mode 100644 index 00000000000..e145f66b630 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child2_2.inc @@ -0,0 +1 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child2_3.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child2_3.inc new file mode 100644 index 00000000000..d356348d8ea --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child2_3.inc @@ -0,0 +1 @@ +--connect (child2_3, localhost, root, , , $CHILD2_3_MYPORT, $CHILD2_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child3_1.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child3_1.inc new file mode 100644 index 00000000000..03e5c188c89 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child3_1.inc @@ -0,0 +1 @@ +--connect (child3_1, localhost, root, , , $CHILD3_1_MYPORT, $CHILD3_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child3_2.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child3_2.inc new file mode 100644 index 00000000000..d62a7ada824 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child3_2.inc @@ -0,0 +1 @@ +--connect (child3_2, localhost, root, , , $CHILD3_2_MYPORT, $CHILD3_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_child3_3.inc b/storage/spider/mysql-test/spider/oracle/t/connect_child3_3.inc new file mode 100644 index 00000000000..fb49f5bfdac --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_child3_3.inc @@ -0,0 +1 @@ +--connect (child3_3, localhost, root, , , $CHILD3_3_MYPORT, $CHILD3_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_master_1.inc b/storage/spider/mysql-test/spider/oracle/t/connect_master_1.inc new file mode 100644 index 00000000000..0c129ce5775 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_master_1.inc @@ -0,0 +1 @@ +--connect (master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/connect_slave1_1.inc b/storage/spider/mysql-test/spider/oracle/t/connect_slave1_1.inc new file mode 100644 index 00000000000..45a822743e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/connect_slave1_1.inc @@ -0,0 +1 @@ +--connect (slave1_1, localhost, root, , , $SLAVE1_1_MYPORT, $SLAVE1_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle/t/direct_aggregate.test b/storage/spider/mysql-test/spider/oracle/t/direct_aggregate.test new file mode 100644 index 00000000000..59c45f3f190 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/direct_aggregate.test @@ -0,0 +1,316 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_aggregating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT COUNT(*) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l WHERE a < 5; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/direct_update.test b/storage/spider/mysql-test/spider/oracle/t/direct_update.test new file mode 100644 index 00000000000..1c3ce91ff3f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/direct_update.test @@ -0,0 +1,354 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_updating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key +DELETE FROM ta_l WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update all rows with function + UPDATE ta_l2 SET c = ADDDATE(c, 1); + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key + UPDATE ta_l2 SET b = 'x' WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by a column without index + UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key with order and limit + UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key with order and limit + DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by a column without index + DELETE FROM ta_l2 WHERE b = 'c'; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key + DELETE FROM ta_l2 WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/function.test b/storage/spider/mysql-test/spider/oracle/t/function.test new file mode 100644 index 00000000000..2b1b53c8a4f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/function.test @@ -0,0 +1,276 @@ +# This test tests for using functions +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo in() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_PK_TABLES1; + echo CHILD2_1_CREATE_TEXT_PK_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_PK_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_PK_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET3 $MASTER_1_COMMENT_TEXT_PK1_1; +--enable_query_log +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a in ('15', '120'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo date_sub() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/ha.test b/storage/spider/mysql-test/spider/oracle/t/ha.test new file mode 100644 index 00000000000..319b1793753 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/ha.test @@ -0,0 +1,1794 @@ +# This test tests for ha features +--let $SKIP_REASON= +if ($USE_HA_TEST) +{ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source ha_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + } + if ($USE_CHILD_GROUP3) + { + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + } + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + --connection child2_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + SELECT 1; + --connection child3_2 + SELECT 1; + --connection child3_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_2_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_CREATE_TABLES; + } + eval $CHILD2_2_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_RECOVERY_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_COPY_TABLES_2_1; +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_3_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_CREATE_TABLES; + } + eval $CHILD2_3_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_RECOVERY_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_COPY_TABLES_P_2_1; + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo active standby test +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_AS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES2; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES2; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES2; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_AS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; +} +--disable_query_log +--disable_result_log +--source ha_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +} +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/ha_test_deinit.inc b/storage/spider/mysql-test/spider/oracle/t/ha_test_deinit.inc new file mode 100644 index 00000000000..53d0409d066 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/ha_test_deinit.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_deinit_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_deinit_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_deinit_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_deinit_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle/t/ha_test_init.inc b/storage/spider/mysql-test/spider/oracle/t/ha_test_init.inc new file mode 100644 index 00000000000..70576ab16dc --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/ha_test_init.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_init_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_init_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_init_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_init_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle/t/have_engine.inc b/storage/spider/mysql-test/spider/oracle/t/have_engine.inc new file mode 100644 index 00000000000..64bef7499cb --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/have_engine.inc @@ -0,0 +1,7 @@ +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + SELECT engine, support FROM information_schema.engines; + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" +} diff --git a/storage/spider/mysql-test/spider/oracle/t/have_func.inc b/storage/spider/mysql-test/spider/oracle/t/have_func.inc new file mode 100644 index 00000000000..e0823e73fc8 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/have_func.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM mysql.func WHERE name = '$TEST_FUNC_NAME'`) +{ + SELECT name FROM mysql.func; + --let $SKIP_REASON= "Need $TEST_FUNC_NAME function" +} diff --git a/storage/spider/mysql-test/spider/oracle/t/have_partition.inc b/storage/spider/mysql-test/spider/oracle/t/have_partition.inc new file mode 100644 index 00000000000..573c76ab43b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/have_partition.inc @@ -0,0 +1,7 @@ +let $HAVE_PARTITION= 0; +if (`SELECT count(*) FROM information_schema.plugins WHERE + plugin_status = 'ACTIVE' AND + plugin_name = 'partition'`) +{ + let $HAVE_PARTITION= 1; +} diff --git a/storage/spider/mysql-test/spider/oracle/t/have_trigger.inc b/storage/spider/mysql-test/spider/oracle/t/have_trigger.inc new file mode 100644 index 00000000000..10c0871dd5f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/have_trigger.inc @@ -0,0 +1,2 @@ +let $HAVE_TRIGGER= `SELECT COUNT(*) FROM information_schema.tables + WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'TRIGGERS'`; diff --git a/storage/spider/mysql-test/spider/oracle/t/hs_test_deinit.inc b/storage/spider/mysql-test/spider/oracle/t/hs_test_deinit.inc new file mode 100644 index 00000000000..7ec2e981fd2 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/hs_test_deinit.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_deinit_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle/t/hs_test_init.inc b/storage/spider/mysql-test/spider/oracle/t/hs_test_init.inc new file mode 100644 index 00000000000..831bf479524 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/hs_test_init.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_init_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle/t/slave_test_deinit.inc b/storage/spider/mysql-test/spider/oracle/t/slave_test_deinit.inc new file mode 100644 index 00000000000..e9d99b7a960 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/slave_test_deinit.inc @@ -0,0 +1,6 @@ +# get connection and exist engine test +--echo for slave1_1 +--connection slave1_1 +STOP SLAVE; +--source ../include/deinit_slave1_1.inc +--disconnect slave1_1 diff --git a/storage/spider/mysql-test/spider/oracle/t/slave_test_init.inc b/storage/spider/mysql-test/spider/oracle/t/slave_test_init.inc new file mode 100644 index 00000000000..739d88970c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/slave_test_init.inc @@ -0,0 +1,44 @@ +# get connection and exist engine test +--echo for slave1_1 +--source connect_slave1_1.inc +--connection slave1_1 +SET SESSION sql_log_bin= 0; +--let $SLAVE1_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $SLAVE1_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_slave1_1.inc +--source have_engine.inc +--let $SLAVE1_1_SLAVE_STATUS=`SHOW SLAVE STATUS` +if (!$SLAVE1_1_SLAVE_STATUS) +{ + eval CHANGE MASTER TO + MASTER_HOST = '127.0.0.1', + MASTER_USER = 'root', + MASTER_PASSWORD = '', + MASTER_PORT = $MASTER_1_MYPORT + ; +} +START SLAVE; +--connection master_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--connection slave1_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} diff --git a/storage/spider/mysql-test/spider/oracle/t/spider3_fixes.test b/storage/spider/mysql-test/spider/oracle/t/spider3_fixes.test new file mode 100644 index 00000000000..4139f3af955 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/spider3_fixes.test @@ -0,0 +1,570 @@ +# This test tests for Spider 3.0's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo 3.1 +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +SET INSERT_ID=5000; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + TRUNCATE TABLE t1; + TRUNCATE TABLE t2; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + SET INSERT_ID=5000; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/spider_fixes.test b/storage/spider/mysql-test/spider/oracle/t/spider_fixes.test new file mode 100644 index 00000000000..b9ff61abcb4 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/spider_fixes.test @@ -0,0 +1,1967 @@ +# This test tests for Spider's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 2.13 +--echo select table with "order by desc" and "<" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table with "order by desc" and "<=" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.14 +--echo update table with range scan and split_read +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo 2.15 +--echo select table with range scan +TRUNCATE TABLE ta_l; +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES6; + echo CHILD2_1_CREATE_TABLES6; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES6; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES6; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.16 +--echo auto_increment insert with trigger +if ($HAVE_TRIGGER) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_CREATE_TABLES4; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES4; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES4; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; + eval CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; + echo CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE2 MASTER_1_CHARSET2; + eval CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; + --enable_query_log + --eval CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + INSERT INTO ta_l_auto_inc (a, b, c) VALUES + (NULL, 's', '2008-12-31 20:59:59'); + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES4; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +} + +--echo +--echo 2.17 +--echo engine-condition-pushdown with "or" and joining +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo partition with sort +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 + ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.23 +--echo partition update with moving partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); + UPDATE ta_l2 SET a = 4 WHERE a = 3; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo index merge +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo index merge with partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l_int; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_2_DROP_TABLES5; + echo CHILD2_2_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES5; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES5; + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1; + eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_P_2_1; + --enable_query_log + INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); + INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) + WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.24 +--echo index scan update without PK +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +if (!$MASTER_1_NEEDPK) +{ + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +--enable_query_log +SELECT a, b, c FROM ta_l_int ORDER BY a; +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l_int SET c = 4 WHERE b = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; + + +--echo +--echo 2.25 +--echo direct order limit +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; + + +--echo +--echo 2.26 +--echo lock tables +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_LOCK_TABLES1; + echo CHILD2_1_DROP_LOCK_TABLES2; + echo CHILD2_1_CREATE_LOCK_TABLES1; + echo CHILD2_1_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_LOCK_TABLES1; + eval $CHILD2_1_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_LOCK_TABLES1; + eval $CHILD2_1_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_LOCK_TABLES1; + echo CHILD2_2_DROP_LOCK_TABLES2; + echo CHILD2_2_CREATE_LOCK_TABLES1; + echo CHILD2_2_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_LOCK_TABLES1; + eval $CHILD2_2_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_LOCK_TABLES1; + eval $CHILD2_2_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1; +eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2; +eval CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK2; +--enable_query_log +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + + +--echo +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + SET INSERT_ID=5000; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo read only +let $MASTER_1_ENGINE_IS_SPIDER= + `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'Spider' OR + '$MASTER_1_HIDDEN_ENGINE_TYPE' = 'Spider', 1, 0)`; +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_READONLY1_1; + --let $MIN_VAL= `SELECT MIN(id) FROM t1` + --enable_query_log + SELECT id FROM t1 ORDER BY id; + --error 12518 + INSERT INTO t1 (id) VALUES (1); + --error 12518 + eval UPDATE t1 SET id = 4 WHERE id = $MIN_VAL; + --error 12518 + eval DELETE FROM t1 WHERE id = $MIN_VAL; + --error 12518 + DELETE FROM t1; + --error 12518 + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 2.27 +--echo error mode +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_ERROR_MODE1_1; + --enable_query_log + SELECT id FROM t1 ORDER BY id; + INSERT INTO t1 (id) VALUES (1); + DELETE FROM t1; + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 3.0 +--echo is null +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_KEY_TABLES1; + echo CHILD2_1_CREATE_TEXT_KEY_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_KEY_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_KEY_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_TEXT_KEY1_1; +--enable_query_log +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a is null order by a limit 30; +select b from t1 where b is null order by b limit 30; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo direct_order_limit +--connection master_1 +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +select a, c from t1 where a = '10' order by b desc limit 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle/t/test_deinit.inc b/storage/spider/mysql-test/spider/oracle/t/test_deinit.inc new file mode 100644 index 00000000000..989bde26d3c --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/test_deinit.inc @@ -0,0 +1,37 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/deinit_master_1.inc +--disconnect master_1 +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/deinit_child2_1.inc + --disconnect child2_1 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --echo child2_3 + --connection child2_3 + --source ../include/deinit_child2_3.inc + --disconnect child2_3 +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/deinit_child3_1.inc + --disconnect child3_1 + --echo child3_2 + --connection child3_2 + --source ../include/deinit_child3_2.inc + --disconnect child3_2 + --echo child3_3 + --connection child3_3 + --source ../include/deinit_child3_3.inc + --disconnect child3_3 +} diff --git a/storage/spider/mysql-test/spider/oracle/t/test_init.inc b/storage/spider/mysql-test/spider/oracle/t/test_init.inc new file mode 100644 index 00000000000..f2cd6c0269f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/test_init.inc @@ -0,0 +1,74 @@ +# get connection and exist engine test +--echo for master_1 +--source connect_master_1.inc +--connection master_1 +CALL mtr.add_suppression("unknown variable"); +SET SESSION sql_log_bin= 0; +--let $MASTER_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $MASTER_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_master_1.inc +--source have_engine.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --source connect_child2_1.inc + --connection child2_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE + --source ../include/init_child2_1.inc + --source have_engine.inc + --echo child2_2 + --source connect_child2_2.inc + --connection child2_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE + --source ../include/init_child2_2.inc + --source have_engine.inc + --echo child2_3 + --source connect_child2_3.inc + --connection child2_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE + --source ../include/init_child2_3.inc + --source have_engine.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --source connect_child3_1.inc + --connection child3_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE + --source ../include/init_child3_1.inc + --source have_engine.inc + --echo child3_2 + --source connect_child3_2.inc + --connection child3_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE + --source ../include/init_child3_2.inc + --source have_engine.inc + --echo child3_3 + --source connect_child3_3.inc + --connection child3_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE + --source ../include/init_child3_3.inc + --source have_engine.inc +} diff --git a/storage/spider/mysql-test/spider/oracle/t/vp_fixes.test b/storage/spider/mysql-test/spider/oracle/t/vp_fixes.test new file mode 100644 index 00000000000..46e7b0afc36 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle/t/vp_fixes.test @@ -0,0 +1,358 @@ +# This test tests for VP's bug fixes +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 0.9 +--echo create different primary key table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--let $MASTER_1_IS_VP= `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'VP', 1, 0)` +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo create un-correspond primary key table +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_1.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_1.inc new file mode 100644 index 00000000000..9b6a9851ccb --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_1_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_2.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_2.inc new file mode 100644 index 00000000000..ac0bcdaa938 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_2_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_3.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_3.inc new file mode 100644 index 00000000000..c93a9822d90 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/deinit_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--let $INIT_TEST_ENGINE= $INIT_CHILD3_3_ENGINE +--source ../../include/deinit_engine.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_master_1.inc new file mode 100644 index 00000000000..c19e376d10a --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/deinit_master_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/deinit_slave1_1.inc b/storage/spider/mysql-test/spider/oracle2/include/deinit_slave1_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_1.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_1.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_2.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_2.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_2.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_3.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_3.inc new file mode 100644 index 00000000000..8fd2ff8a777 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_3.inc @@ -0,0 +1 @@ +--source ../../include/deinit_spider.inc diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_1.inc new file mode 100644 index 00000000000..59c0175d349 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_1.inc @@ -0,0 +1,8 @@ +let $CHILD2_1_HA_AS_DROP_TABLES= + $CHILD2_1_DROP_TABLES; +let $CHILD2_1_HA_AS_CREATE_TABLES= + $CHILD2_1_CREATE_TABLES; +let $CHILD2_1_HA_AS_DROP_TABLES2= + $CHILD2_1_DROP_TABLES2; +let $CHILD2_1_HA_AS_CREATE_TABLES2= + $CHILD2_1_CREATE_TABLES2; diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_2.inc new file mode 100644 index 00000000000..90d27ed704d --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_2.inc @@ -0,0 +1,4 @@ +let $CHILD2_2_HA_DROP_TABLES= + $CHILD2_2_DROP_TABLES; +let $CHILD2_2_HA_CREATE_TABLES= + $CHILD2_2_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_3.inc new file mode 100644 index 00000000000..11abf112b1f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_3.inc @@ -0,0 +1,4 @@ +let $CHILD2_3_HA_DROP_TABLES= + $CHILD2_3_DROP_TABLES; +let $CHILD2_3_HA_CREATE_TABLES= + $CHILD2_3_CREATE_TABLES; diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_1.inc new file mode 100644 index 00000000000..67f6676a07a --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_1.inc @@ -0,0 +1,140 @@ +--let $CHILD3_1_ENGINE_TYPE=Spider +--let $CHILD3_1_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_1_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_1_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_1_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_1_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_1_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_1_ENGINE $CHILD3_1_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_2.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_2.inc new file mode 100644 index 00000000000..9b61a2e2b73 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_2.inc @@ -0,0 +1,140 @@ +--let $CHILD3_2_ENGINE_TYPE=Spider +--let $CHILD3_2_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_2_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_2_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_2_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_2_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_2_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_2_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_2_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_2_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_2_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_2_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_2_ENGINE $CHILD3_2_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_2_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_2_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_2_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_3.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_3.inc new file mode 100644 index 00000000000..5724a50b3d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_3.inc @@ -0,0 +1,140 @@ +--let $CHILD3_3_ENGINE_TYPE=Spider +--let $CHILD3_3_ENGINE=ENGINE=Spider +--source ../include/init_spider.inc +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $CHILD3_3_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $CHILD3_3_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $CHILD3_3_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +let $CHILD3_3_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +let $CHILD3_3_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; + +let $CHILD3_3_DROP_TABLES_HA_2_1= + DROP TABLE IF EXISTS ta_l; +if ($VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $CHILD3_3_CREATE_TABLES_HA_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", + database "auto_test_remote auto_test_remote2"'; + let $CHILD3_3_CREATE_TABLES_HA_AS_2_1= + CREATE TABLE ta_l ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3"' + CONNECTION='host "localhost", user "root", password "", + msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2"'; +} +let $CHILD3_3_DROP_TABLES_HA_P_2_1= + DROP TABLE IF EXISTS ta_l2; +let $CHILD3_3_CREATE_TABLES_HA_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1= + CREATE TABLE ta_l2 ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $CHILD3_3_ENGINE $CHILD3_3_CHARSET + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $CHILD3_3_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $CHILD3_3_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $CHILD3_3_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); diff --git a/storage/spider/mysql-test/spider/oracle2/include/ha_init_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/ha_init_master_1.inc new file mode 100644 index 00000000000..8ace39ab641 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/ha_init_master_1.inc @@ -0,0 +1,109 @@ +eval INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server, scheme, host, port, socket, + username, password, ssl_ca, ssl_capath, ssl_cert, ssl_cipher, ssl_key, + ssl_verify_server_cert, default_file, default_group) VALUES +('%auto_test_local%', '%ta_l%', '%', $CHILD3_1_SERVER_ID, 's_3_1', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_2_SERVER_ID, 's_3_2', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), +('%auto_test_local%', '%ta_l%', '%', $CHILD3_3_SERVER_ID, 's_3_3', NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL); +let $MASTER_1_CHECK_LINK_STATUS= + SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables + ORDER BY db_name, table_name, link_id; +let $MASTER_1_CHECK_LINK_FAILED_LOG= + SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +let $MASTER_1_SET_RECOVERY_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE", lst "0 2"'; +let $MASTER_1_SET_OK_STATUS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE", lst "0 1"'; +let $MASTER_1_SET_OK_STATUS_AS_2_1= + ALTER TABLE ta_l + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE", lst "1 0"'; +let $MASTER_1_COPY_TABLES_2_1= + SELECT spider_copy_tables('ta_l', '0', '1'); + +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='port "$CHILD2_1_MYPORT $CHILD2_2_MYPORT", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_HA_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", + database "$ORACLE_DATABASE"'; + let $MASTER_1_COMMENT_HA_AS_2_1= + COMMENT='socket "$CHILD2_1_MYSOCK $CHILD2_2_MYSOCK", table "ta_r ta_r3", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1", + database "$ORACLE_DATABASE"'; +} +let $MASTER_1_COMMENT_HA_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_COMMENT_HA_AS_P_2_1= + COMMENT='msi "$CHILD3_1_SERVER_ID", mkd "2", alc "1"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001"' + ); +let $MASTER_1_SET_RECOVERY_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +let $MASTER_1_SET_OK_STATUS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +let $MASTER_1_SET_OK_STATUS_AS_P_2_1= + ALTER TABLE ta_l2 + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', + PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +let $MASTER_1_COPY_TABLES_P_2_1= + SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +let $MASTER_1_CHECK_HA_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +let $MASTER_1_CHANGE_HA_MON= + SELECT spider_flush_table_mon_cache(); diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_2.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_deinit_master_1.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_1.inc new file mode 100644 index 00000000000..e0467b92307 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_1.inc @@ -0,0 +1,24 @@ +let $CHILD2_1_HS_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "hs_r" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_hs_r" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_DROP_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_CREATE_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "hs_r2" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_hs_r2" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_HS_SELECT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r2" ORDER BY "a"', '', 'srv "s_2_1"'); diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_2.inc new file mode 100644 index 00000000000..0466acbc66b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_2.inc @@ -0,0 +1,12 @@ +let $CHILD2_2_HS_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "hs_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_HS_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "hs_r3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + "d" INT DEFAULT 11, + CONSTRAINT "pk_s_2_2_hs_r3" PRIMARY KEY("a") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_HS_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\'), "d" FROM "hs_r3" ORDER BY "a"', '', 'srv "s_2_2"'); diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_3.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/storage/spider/mysql-test/spider/oracle2/include/hs_init_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/hs_init_master_1.inc new file mode 100644 index 00000000000..0ff5e2a10d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/hs_init_master_1.inc @@ -0,0 +1,12 @@ +let $MASTER_1_HS_COMMENT_TMP= + COMMENT=''; +let $MASTER_1_HS_COMMENT_2_1= + COMMENT='srv "s_2_1", table "hs_r", uhr "1", uhw "1", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"'; +let $MASTER_1_HS_COMMENT_P_2_1= + COMMENT='uhr "1", uhw "1"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) + COMMENT='srv "s_2_1", table "hs_r2", hrp "$CHILD2_1_HSRPORT", hwp "$CHILD2_1_HSWPORT"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", table "hs_r3", hrp "$CHILD2_2_HSRPORT", hwp "$CHILD2_2_HSWPORT"' + ); diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child2_1.inc new file mode 100644 index 00000000000..18dcc7159cc --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child2_1.inc @@ -0,0 +1,192 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_1"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_1"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r" PRIMARY KEY("a") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1" ON "ta_r"("b")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "ta_r2" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r2" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES3= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_no_idx"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES3= + SELECT spider_direct_sql('CREATE TABLE "ta_r_no_idx" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\') + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES3= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_no_idx" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES4= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_auto_inc"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES4= + SELECT spider_direct_sql('CREATE TABLE "ta_r_auto_inc" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_1_ta_r_auto_inc" PRIMARY KEY("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES4= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_auto_inc" + ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES5= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "s_2_1_ta_r_int"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES5= + SELECT spider_direct_sql('CREATE TABLE "s_2_1_ta_r_int" ( + "a" INT DEFAULT 3, + "b" INT DEFAULT 10, + "c" INT DEFAULT 11, + CONSTRAINT "pk_s_2_1_ta_r_int" PRIMARY KEY("a") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_s_2_1_ta_r_int" ON "s_2_1_ta_r_int"("b")', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_s_2_1_ta_r_int" ON "s_2_1_ta_r_int"("c")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES5= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "s_2_1_ta_r_int" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TABLES6= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r_3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TABLES6= + SELECT spider_direct_sql('CREATE TABLE "ta_r_3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\') + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TABLES6= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r_3" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_FT_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_FT_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ft_r" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_1_ft_r" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_FT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_FT_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_FT_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "ft_r2" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_1_ft_r2" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_FT_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_GM_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_GM_TABLES= + SELECT spider_direct_sql('CREATE TABLE "gm_r" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_1_gm_r" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_GM_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_GM_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_GM_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "gm_r2" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_1_gm_r2" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_GM_TABLES2= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r2" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_LOCK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_LOCK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t1_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_LOCK_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t2_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_LOCK_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "t2_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t2_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_INCREMENT_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_INCREMENT_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_1_t1_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_INCREMENT_TABLES1= + SELECT spider_direct_sql('SELECT "id" FROM "t1_1" ORDER BY "id"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TEXT_PK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TEXT_PK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1" ( + "a" VARCHAR(255), + CONSTRAINT "pk_s_2_1_t1" PRIMARY KEY ("a") + )', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TEXT_PK_TABLES1= + SELECT spider_direct_sql('SELECT "a" FROM "t1" ORDER BY "a"', '', 'srv "s_2_1"'); +let $CHILD2_1_DROP_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"'); +let $CHILD2_1_CREATE_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1" ( + "a" VARCHAR(255), + "b" VARCHAR(255), + "c" VARCHAR(255), + CONSTRAINT "pk_s_2_1_t1" PRIMARY KEY ("c") + )', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_t1" ON "t1"("a","b")', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_t1" ON "t1"("b")', '', 'srv "s_2_1"'); +let $CHILD2_1_SELECT_TEXT_KEY_TABLES1= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "t1" ORDER BY "c"', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_INCREMENT1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_INCREMENT2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_OFFSET1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"'); +let $CHILD2_1_AUTO_INCREMENT_OFFSET2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"'); diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child2_2.inc new file mode 100644 index 00000000000..117040dcca6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child2_2.inc @@ -0,0 +1,94 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_2"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_2"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r3" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_2_ta_r3" PRIMARY KEY("a") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_TABLES5= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "s_2_2_ta_r_int"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_TABLES5= + SELECT spider_direct_sql('CREATE TABLE "s_2_2_ta_r_int" ( + "a" INT DEFAULT 3, + "b" INT DEFAULT 10, + "c" INT DEFAULT 11, + CONSTRAINT "pk_s_2_2_ta_r_int" PRIMARY KEY("a") + )', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx1_s_2_2_ta_r_int" ON "s_2_2_ta_r_int"("b")', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE INDEX "idx2_s_2_2_ta_r_int" ON "s_2_2_ta_r_int"("c")', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_FT_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ft_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_FT_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ft_r3" ( + "a" INT DEFAULT 0, + "b" TEXT, + "c" TEXT, + "d" TEXT, + CONSTRAINT "pk_s_2_2_ft_r3" PRIMARY KEY("a"), + FULLTEXT INDEX "ft_idx1"("b"), + FULLTEXT INDEX "ft_idx2"("c") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_FT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c", "d" FROM "ft_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_GM_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "gm_r3"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_GM_TABLES= + SELECT spider_direct_sql('CREATE TABLE "gm_r3" ( + "a" INT DEFAULT 0, + "b" GEOMETRY NOT NULL, + "c" GEOMETRY NOT NULL, + CONSTRAINT "pk_s_2_2_gm_r3" PRIMARY KEY("a"), + SPATIAL INDEX "sp_idx1"("b"), + SPATIAL INDEX "sp_idx2"("c") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_GM_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", "c" FROM "gm_r3" ORDER BY "a"', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_LOCK_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_LOCK_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t1_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_LOCK_TABLES2= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t2_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_LOCK_TABLES2= + SELECT spider_direct_sql('CREATE TABLE "t2_1" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t2_1" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_DROP_INCREMENT_TABLES1= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"'); +let $CHILD2_2_CREATE_INCREMENT_TABLES1= + SELECT spider_direct_sql('CREATE TABLE "t1_2" ( + "id" INT NOT NULL, + CONSTRAINT "pk_s_2_2_t1_2" PRIMARY KEY ("id") + )', '', 'srv "s_2_2"'); +let $CHILD2_2_SELECT_INCREMENT_TABLES1= + SELECT spider_direct_sql('SELECT "id" FROM "t1_2" ORDER BY "id"', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_INCREMENT1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_INCREMENT2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_OFFSET1= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $CHILD2_2_AUTO_INCREMENT_OFFSET2= + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child2_3.inc new file mode 100644 index 00000000000..5c06a9f6a73 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child2_3.inc @@ -0,0 +1,15 @@ +--connection master_1 +SELECT spider_direct_sql('ALTER SESSION SET NLS_DATE_FORMAT=\'YYYY-MM-DD HH24:MI:SS\'', '', 'srv "s_2_3"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIME_FORMAT=\'HH24:MI:SSXFF\'', '', 'srv "s_2_3"'); +SELECT spider_direct_sql('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'YYYY-MM-DD HH24:MI:SSXFF\'', '', 'srv "s_2_3"'); +let $CHILD2_3_DROP_TABLES= + SELECT spider_direct_sql('begin execute immediate \'DROP TABLE "ta_r4"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_3"'); +let $CHILD2_3_CREATE_TABLES= + SELECT spider_direct_sql('CREATE TABLE "ta_r4" ( + "a" INT DEFAULT 10, + "b" CHAR(1) DEFAULT \'c\', + "c" DATE DEFAULT TO_DATE(\'1999-10-10 10:10:10\', \'YYYY-MM-DD HH24:MI:SS\'), + CONSTRAINT "pk_s_2_3_ta_r4" PRIMARY KEY("a") + )', '', 'srv "s_2_3"'); +let $CHILD2_3_SELECT_TABLES= + SELECT spider_direct_sql('SELECT "a", "b", TO_CHAR("c", \'YYYY-MM-DD HH24:MI:SS\') FROM "ta_r4" ORDER BY "a"', '', 'srv "s_2_3"'); diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child3_1.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child3_1.inc new file mode 100644 index 00000000000..f70afeb58de --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child3_1.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_1_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child3_2.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child3_2.inc new file mode 100644 index 00000000000..e84567f2243 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child3_2.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_2_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_child3_3.inc b/storage/spider/mysql-test/spider/oracle2/include/init_child3_3.inc new file mode 100644 index 00000000000..d3f31049ff6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_child3_3.inc @@ -0,0 +1,3 @@ +--let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE +--source ../../include/init_engine.inc +--let $INIT_CHILD3_3_ENGINE= $INIT_TEST_ENGINE diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_master_1.inc b/storage/spider/mysql-test/spider/oracle2/include/init_master_1.inc new file mode 100644 index 00000000000..00c6f544992 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_master_1.inc @@ -0,0 +1,150 @@ +--source ../include/init_spider.inc +SET spider_direct_order_limit= 10000; +SET spider_init_sql_alloc_size= 1; +SET spider_conn_recycle_mode= 2; +let $MASTER_1_COMMENT_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r", wrapper "oracle", + pk_name "pk_s_2_1_ta_r"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD"'; +let $MASTER_1_COMMENT2_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_no_idx", wrapper "oracle", + pk_name "pk_s_2_1_ta_r_no_idx"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", prt "2000000"'; +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY KEY(a) ( + PARTITION pt1 COMMENT='srv "s_2_1", table "ta_r2", + priority "1000", pk_name "pk_s_2_1_ta_r2"', + PARTITION pt2 COMMENT='srv "s_2_2", priority "1000001", + pk_name "pk_s_2_2_ta_r3"' + ); +let $MASTER_1_COMMENT2_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ta_r2", priority "1000", pk_name "pk_s_2_1_ta_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ta_r3"' + ); +let $MASTER_1_COMMENT3_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_auto_inc", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_auto_inc"'; +let $MASTER_1_COMMENT3_P_2_1= + COMMENT='table "s_2_1_ta_r_int"' + PARTITION BY LIST(MOD(a, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='srv "s_2_1", priority "1000", pk_name "pk_s_2_1_ta_r_int"', + PARTITION pt2 VALUES IN (1) + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ta_r_int", + table "s_2_2_ta_r_int"' + ); +let $MASTER_1_COMMENT4_2_1= + COMMENT='database "$ORACLE_DATABASE", table "s_2_1_ta_r_int", + wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_int"'; +let $MASTER_1_COMMENT5_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ta_r_3", wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ta_r_3"'; +let $MASTER_1_COMMENT_FT_2_1= + COMMENT='database "$ORACLE_DATABASE", table "ft_r", wrapper "oracle"' + CONNECTION='host "$ORACLE_HOST", port "$ORACLE_PORT", user "$ORACLE_USER", + password "$ORACLE_PASSWORD", pk_name "pk_s_2_1_ft_r"'; +let $MASTER_1_COMMENT2_FT_P_2_1= + COMMENT='table "ft_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "ft_r2", priority "1000", pk_name "pk_s_2_1_ft_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_ft_r3"' + ); +let $MASTER_1_COMMENT_GM_2_1= + COMMENT='srv "s_2_1", table "gm_r", pk_name "pk_s_2_1_gm_r"'; +let $MASTER_1_COMMENT2_GM_P_2_1= + COMMENT='table "gm_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (4) COMMENT='srv "s_2_1", + table "gm_r2", priority "1000", pk_name "pk_s_2_1_gm_r2"', + PARTITION pt2 VALUES LESS THAN MAXVALUE + COMMENT='srv "s_2_2", priority "1000001", pk_name "pk_s_2_2_gm_r3"' + ); +let $MASTER_1_COMMENT_LOCK1= + COMMENT 'tbl "t1_1 t1_2", srv "s_2_1 s_2_2", + pk_name "pk_s_2_1_t1_1 pk_s_2_2_t1_2"'; +let $MASTER_1_COMMENT_LOCK2= + COMMENT 'tbl "t2_1 t2_2", srv "s_2_2 s_2_1", + pk_name "pk_s_2_2_t2_1 pk_s_2_1_t2_2"'; +let $MASTER_1_COMMENT_INCREMENT1_1= + COMMENT 'aim "2", sqn "seq_t1_1", tbl "t1_1", srv "s_2_1", + pk_name "pk_s_2_1_t1_1"'; +let $MASTER_1_COMMENT_INCREMENT1_P_1= + COMMENT 'aim "2"' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='sqn "seq_t1_1", tbl "t1_1", srv "s_2_1", pk_name "pk_s_2_1_t1_1"', + PARTITION pt2 VALUES IN (1) + COMMENT='sqn "seq_t1_2", tbl "t1_2", srv "s_2_2", pk_name "pk_s_2_2_t1_2"' + ); +let $MASTER_1_COMMENT_READONLY1_1= + COMMENT 'read_only_mode "1", tbl "t1_1", srv "s_2_1", + pk_name "pk_s_2_1_t1_1"'; +let $MASTER_1_COMMENT_ERROR_MODE1_1= + COMMENT 'erm "1", ewm "1", tbl "ter1_1", srv "s_2_1", + pk_name "pk_s_2_1_ter1_1"'; +let $MASTER_1_COMMENT_TEXT_PK1_1= + COMMENT 'tbl "t1", srv "s_2_1", pk_name "pk_s_2_1_t1"'; +let $MASTER_1_COMMENT_TEXT_KEY1_1= + COMMENT 'tbl "t1", srv "s_2_1", pk_name "pk_s_2_1_t1"'; +let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +let $MASTER_1_CHECK_DIRECT_DELETE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +let $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +let $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS= + SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +let $MASTER_1_AUTO_INCREMENT_INCREMENT1= + SET SESSION AUTO_INCREMENT_INCREMENT = 1 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_INCREMENT2= + SET SESSION AUTO_INCREMENT_INCREMENT = 777 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET1= + SET SESSION AUTO_INCREMENT_OFFSET = 1 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 1 INCREMENT BY 1', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET2= + SET SESSION AUTO_INCREMENT_OFFSET = 777 $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') + $STR_SEMICOLON + SELECT spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'$STR_SEMICOLON exception when others then null$STR_SEMICOLON end$STR_SEMICOLON', '', 'srv "s_2_2"') + $STR_SEMICOLON + SELECT spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"'); +let $MASTER_1_AUTO_INCREMENT_OFFSET3= + SET SESSION AUTO_INCREMENT_OFFSET = 1; +let $MASTER_1_AUTO_INCREMENT_OFFSET4= + SET SESSION AUTO_INCREMENT_OFFSET = 777; diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_slave1_1.inc b/storage/spider/mysql-test/spider/oracle2/include/init_slave1_1.inc new file mode 100644 index 00000000000..87c05f1f690 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_slave1_1.inc @@ -0,0 +1,10 @@ +let $SLAVE1_1_COMMENT_INCREMENT1_1= + COMMENT ''; +let $SLAVE1_1_COMMENT_INCREMENT1_P_1= + COMMENT '' + PARTITION BY LIST(MOD(id, 2)) ( + PARTITION pt1 VALUES IN (0) + COMMENT='', + PARTITION pt2 VALUES IN (1) + COMMENT='' + ); diff --git a/storage/spider/mysql-test/spider/oracle2/include/init_spider.inc b/storage/spider/mysql-test/spider/oracle2/include/init_spider.inc new file mode 100644 index 00000000000..ff9ac9aee29 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/include/init_spider.inc @@ -0,0 +1,105 @@ +--source ../../include/init_spider.inc +let $VERSION_COMPILE_OS_WIN= + `SELECT IF(@@version_compile_os like 'Win%', 1, 0)`; +if ($VERSION_COMPILE_OS_WIN) +{ + eval DROP SERVER s_2_1; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_2; + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_3; + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_3_1; + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_1_MYPORT + ); + eval DROP SERVER s_3_2; + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD3_2_MYPORT + ); + eval DROP SERVER s_3_3; + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + PORT $CHILD2_3_MYPORT + ); +} +if (!$VERSION_COMPILE_OS_WIN) +{ + eval DROP SERVER s_2_1; + eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_2; + eval CREATE SERVER s_2_2 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_2_3; + eval CREATE SERVER s_2_3 FOREIGN DATA WRAPPER oracle OPTIONS ( + HOST '$ORACLE_HOST', + DATABASE '$ORACLE_DATABASE', + USER '$ORACLE_USER', + PASSWORD '$ORACLE_PASSWORD', + PORT $ORACLE_PORT + ); + eval DROP SERVER s_3_1; + eval CREATE SERVER s_3_1 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_1_MYSOCK' + ); + eval DROP SERVER s_3_2; + eval CREATE SERVER s_3_2 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_2_MYSOCK' + ); + eval DROP SERVER s_3_3; + eval CREATE SERVER s_3_3 FOREIGN DATA WRAPPER mysql OPTIONS ( + HOST 'localhost', + DATABASE 'auto_test_local', + USER 'root', + PASSWORD '', + SOCKET '$CHILD3_3_MYSOCK' + ); +} diff --git a/storage/spider/mysql-test/spider/oracle2/my.cnf b/storage/spider/mysql-test/spider/oracle2/my.cnf new file mode 100644 index 00000000000..e24985bb8d4 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/my.cnf @@ -0,0 +1,146 @@ +# Use default setting for mysqld processes +!include include/default_mysqld.cnf + +[mysqld.1.1] +log-bin= master-bin +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[mysqld.3.1] +loose_partition= 1 + +[mysqld.3.2] +loose_partition= 1 + +[mysqld.3.3] +loose_partition= 1 + +[mysqld.4.1] +loose_partition= 1 + + +[ENV] +USE_GEOMETRY_TEST= 0 +USE_FULLTEXT_TEST= 0 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 0 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +SLAVE1_1_MYPORT= @mysqld.4.1.port +SLAVE1_1_MYSOCK= @mysqld.4.1.socket +SLAVE1_1_ENGINE_TYPE= MyISAM +SLAVE1_1_ENGINE= ENGINE=MyISAM +SLAVE1_1_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.1.1.port +CHILD2_1_MYSOCK= @mysqld.1.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_2_MYPORT= @mysqld.1.1.port +CHILD2_2_MYSOCK= @mysqld.1.1.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_3_MYPORT= @mysqld.1.1.port +CHILD2_3_MYSOCK= @mysqld.1.1.socket +CHILD2_3_ENGINE_TYPE= InnoDB +CHILD2_3_ENGINE= ENGINE=InnoDB +CHILD2_3_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_FT_MYPORT= @mysqld.1.1.port +CHILD2_1_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.1.1.port +CHILD2_2_FT_MYSOCK= @mysqld.1.1.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.1.1.port +CHILD2_1_GM_MYSOCK= @mysqld.1.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.1.1.port +CHILD2_2_GM_MYSOCK= @mysqld.1.1.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 +USE_CHILD_GROUP3= 1 +OUTPUT_CHILD_GROUP3= 0 +CHILD3_1_MYPORT= @mysqld.3.1.port +CHILD3_1_MYSOCK= @mysqld.3.1.socket +CHILD3_1_ENGINE_TYPE= InnoDB +CHILD3_1_ENGINE= ENGINE=InnoDB +CHILD3_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_2_MYPORT= @mysqld.3.2.port +CHILD3_2_MYSOCK= @mysqld.3.2.socket +CHILD3_2_ENGINE_TYPE= InnoDB +CHILD3_2_ENGINE= ENGINE=InnoDB +CHILD3_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD3_3_MYPORT= @mysqld.3.3.port +CHILD3_3_MYSOCK= @mysqld.3.3.socket +CHILD3_3_ENGINE_TYPE= InnoDB +CHILD3_3_ENGINE= ENGINE=InnoDB +CHILD3_3_CHARSET= DEFAULT CHARSET=utf8 +ORACLE_HOST= xe +ORACLE_PORT= 1521 +ORACLE_USER= system +ORACLE_PASSWORD= oracle +ORACLE_DATABASE= SYSTEM + +STR_SEMICOLON= ; + +#The followings are setted in include/init_xxx.inc files +#MASTER_1_COMMENT_2_1 +#MASTER_1_COMMENT2_2_1 +#MASTER_1_COMMENT3_2_1 +#MASTER_1_COMMENT4_2_1 +#MASTER_1_COMMENT5_2_1 +#MASTER_1_COMMENT_P_2_1 +#CHILD2_1_DROP_TABLES +#CHILD2_1_CREATE_TABLES +#CHILD2_1_SELECT_TABLES +#CHILD2_1_DROP_TABLES2 +#CHILD2_1_CREATE_TABLES2 +#CHILD2_1_SELECT_TABLES2 +#CHILD2_1_DROP_TABLES3 +#CHILD2_1_CREATE_TABLES3 +#CHILD2_1_SELECT_TABLES3 +#CHILD2_1_DROP_TABLES4 +#CHILD2_1_CREATE_TABLES4 +#CHILD2_1_SELECT_TABLES4 +#CHILD2_1_DROP_TABLES5 +#CHILD2_1_CREATE_TABLES5 +#CHILD2_1_SELECT_TABLES5 +#CHILD2_1_DROP_TABLES6 +#CHILD2_1_CREATE_TABLES6 +#CHILD2_1_SELECT_TABLES6 +#CHILD2_2_DROP_TABLES +#CHILD2_2_CREATE_TABLES +#CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/oracle2/r/basic_sql.result b/storage/spider/mysql-test/spider/oracle2/r/basic_sql.result new file mode 100644 index 00000000000..e6202327ef6 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/basic_sql.result @@ -0,0 +1,701 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'f', '2008-07-01 10:21:39'), +(2, 'g', '2000-02-01 00:00:00'), +(3, 'j', '2007-05-04 20:03:11'), +(4, 'i', '2003-10-30 05:01:03'), +(5, 'h', '2001-10-31 23:59:59'); +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l +Warnings: +Warning 1062 Duplicate entry '1' for key 'PRIMARY' +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +Warning 1062 Duplicate entry '3' for key 'PRIMARY' +Warning 1062 Duplicate entry '4' for key 'PRIMARY' +Warning 1062 Duplicate entry '5' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create table with partition and select test +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create no index table +DROP TABLE IF EXISTS ta_l_no_idx; +CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table shared mode +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table for update +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table join +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table straight_join +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_small_result +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_big_result +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_buffer_result +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_cache +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_no_cache +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_calc_found_rows +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +SELECT found_rows(); +found_rows() +5 + +select high_priority +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select distinct +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select count +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select using index and pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using index pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +insert select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 + +insert low_priority +TRUNCATE TABLE ta_l; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert high_priority +TRUNCATE TABLE ta_l; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert ignore +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +Warnings: +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (insert) +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (update) +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2005-08-08 11:11:11 + +replace +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2008-02-02 02:02:02 + +replace select +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace select a +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace low_priority +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 g 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 h 2010-04-04 04:04:04 +2 g 2009-03-03 03:03:03 + +update join +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update partition pushdown +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 e 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update partition index pushdown +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete all +DELETE FROM ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE IGNORE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE QUICK FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete partition index pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +truncate +TRUNCATE TABLE ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/direct_aggregate.result b/storage/spider/mysql-test/spider/oracle2/r/direct_aggregate.result new file mode 100644 index 00000000000..26860959718 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/direct_aggregate.result @@ -0,0 +1,132 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_aggregating test +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW GLOBAL STATUS LIKE 'Spider_direct_aggregate%'; +Variable_name Value +Spider_direct_aggregate 3 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/direct_update.result b/storage/spider/mysql-test/spider/oracle2/r/direct_update.result new file mode 100644 index 00000000000..db6066a6e46 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/direct_update.result @@ -0,0 +1,226 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_updating test +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-03 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l2 SET c = ADDDATE(c, 1); +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l2 SET b = 'x' WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_update%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-03 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l2 WHERE b = 'c'; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l2 WHERE a = 3; +SHOW GLOBAL STATUS LIKE 'Spider_direct_delete%'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/function.result b/storage/spider/mysql-test/spider/oracle2/r/function.result new file mode 100644 index 00000000000..764c774514b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/function.result @@ -0,0 +1,149 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +in() +CREATE TABLE t1 ( +a VARCHAR(255), +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1 +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-08-01 10:21:39 +2 b 1999-01-01 00:00:00 +3 e 2006-06-04 20:03:11 +4 d 2002-11-30 05:01:03 +5 c 2000-12-31 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-11-01 10:21:39 +2 b 1999-04-01 00:00:00 +3 e 2006-09-04 20:03:11 +4 d 2003-02-28 05:01:03 +5 c 2001-03-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-01 10:21:39 +2 b 1999-03-01 00:00:00 +3 e 2006-08-04 20:03:11 +4 d 2003-01-28 05:01:03 +5 c 2001-02-28 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-08 10:21:39 +2 b 1999-03-08 00:00:00 +3 e 2006-08-11 20:03:11 +4 d 2003-02-04 05:01:03 +5 c 2001-03-07 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 10:21:39 +2 b 1999-03-07 00:00:00 +3 e 2006-08-10 20:03:11 +4 d 2003-02-03 05:01:03 +5 c 2001-03-06 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:21:39 +2 b 1999-03-07 01:00:00 +3 e 2006-08-10 21:03:11 +4 d 2003-02-03 06:01:03 +5 c 2001-03-07 00:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:39 +2 b 1999-03-07 00:59:00 +3 e 2006-08-10 21:02:11 +4 d 2003-02-03 06:00:03 +5 c 2001-03-07 00:58:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:40 +2 b 1999-03-07 00:59:01 +3 e 2006-08-10 21:02:12 +4 d 2003-02-03 06:00:04 +5 c 2001-03-07 00:59:00 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/ha.result b/storage/spider/mysql-test/spider/oracle2/r/ha.result new file mode 100644 index 00000000000..95b428eb1ff --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/ha.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +test select 1 +SELECT 1; +1 +1 + +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 0 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r3' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", + database "SYSTEM", lst "0 2"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 2 +SELECT spider_copy_tables('ta_l', '0', '1'); +spider_copy_tables('ta_l', '0', '1') +1 +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", + database "SYSTEM", lst "0 1"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r4' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 2 +SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +spider_copy_tables('ta_l2#P#pt2', '0', '1') +1 +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +active standby test +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 3 +auto_test_local ta_l 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "xe", user "system", + password "oracle", msi "2", mkd "2", alc "1", + database "SYSTEM", lst "1 0"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'SYSTEM.ta_r2' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 3 +auto_test_local ta_l2#P#pt2 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +auto_test_local ta_l2#P#pt2 0 +SHOW GLOBAL STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 3 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/spider3_fixes.result b/storage/spider/mysql-test/spider/oracle2/r/spider3_fixes.result new file mode 100644 index 00000000000..e7fbceb3933 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/spider3_fixes.result @@ -0,0 +1,375 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +3.1 +auto_increment +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t2; +MAX(id) +6 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT MAX(id) FROM t1; +MAX(id) +10 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +14 +SELECT MAX(id) FROM t2; +MAX(id) +14 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +34 +SELECT id FROM t2 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +34 +38 +42 +46 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +50 +SELECT id FROM t1 ORDER BY id; +id +50 +54 +58 +62 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +66 +SELECT id FROM t2 ORDER BY id; +id +50 +54 +58 +62 +66 +70 +74 +78 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +82 +SELECT MAX(id) FROM t1; +MAX(id) +82 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +86 +SELECT MAX(id) FROM t2; +MAX(id) +86 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +90 +SELECT MAX(id) FROM t1; +MAX(id) +90 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +94 +SELECT MAX(id) FROM t2; +MAX(id) +94 +auto_increment with partition +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SELECT MAX(id) FROM t2; +MAX(id) +3 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t1; +MAX(id) +6 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT MAX(id) FROM t2; +MAX(id) +10 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +7 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +18 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +15 +SELECT id FROM t2 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +18 +19 +22 +26 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +23 +SELECT id FROM t1 ORDER BY id; +id +23 +27 +30 +34 +INSERT INTO t2 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +31 +SELECT id FROM t2 ORDER BY id; +id +23 +27 +30 +31 +34 +35 +38 +42 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +46 +SELECT MAX(id) FROM t1; +MAX(id) +46 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +39 +SELECT MAX(id) FROM t2; +MAX(id) +46 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +50 +SELECT MAX(id) FROM t1; +MAX(id) +50 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +54 +SELECT MAX(id) FROM t2; +MAX(id) +54 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/spider_fixes.result b/storage/spider/mysql-test/spider/oracle2/r/spider_fixes.result new file mode 100644 index 00000000000..d23ba9aeec8 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/spider_fixes.result @@ -0,0 +1,678 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +2.13 +select table with "order by desc" and "<" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 +2 b 2000-01-01 00:00:00 + +select table with "order by desc" and "<=" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +5 c 2001-12-31 23:59:59 +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 + +2.14 +update table with range scan and split_read +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-02-02 00:00:00 +3 e 2000-02-02 00:00:00 +4 d 2000-02-02 00:00:00 +5 c 2000-02-02 00:00:00 + +2.15 +select table with range scan +TRUNCATE TABLE ta_l; +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a int(11) NOT NULL DEFAULT '0', +b char(1) DEFAULT NULL, +c datetime DEFAULT NULL, +PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +CREATE TABLE ta_l_auto_inc ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tc_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END;; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 s 2008-12-31 20:59:59 + +2.17 +engine-condition-pushdown with "or" and joining +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +partition with sort +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +2.23 +partition update with moving partition +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); +UPDATE ta_l2 SET a = 4 WHERE a = 3; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 B 2010-09-26 00:00:00 +index merge +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 +index merge with partition +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT NOT NULL, +b INT DEFAULT 10, +c INT DEFAULT 11, +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +UPDATE ta_l_int SET c = 4 WHERE b = 2; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +0 2 4 +1 2 4 +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 + +2.25 +direct order limit +SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +Variable_name Value +Spider_direct_order_limit 0 +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +a b c +2 3 4 +4 5 6 +6 7 8 +SHOW GLOBAL STATUS LIKE 'Spider_direct_order_limit%'; +Variable_name Value +Spider_direct_order_limit 0 + +2.26 +lock tables +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1 +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t1; +MAX(id) +6 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT MAX(id) FROM t1; +MAX(id) +10 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +14 +SELECT MAX(id) FROM t1; +MAX(id) +14 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +30 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +34 +SELECT MAX(id) FROM t1; +MAX(id) +34 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +38 +SELECT MAX(id) FROM t1; +MAX(id) +38 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +42 +SELECT MAX(id) FROM t1; +MAX(id) +42 + +auto_increment with partition +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_1"\'; exception when others then null; end;', '', 'srv "s_2_1"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_1" START WITH 2 INCREMENT BY 4', '', 'srv "s_2_1"') +1 +spider_direct_sql('begin execute immediate \'DROP SEQUENCE "seq_t1_2"\'; exception when others then null; end;', '', 'srv "s_2_2"') +1 +spider_direct_sql('CREATE SEQUENCE "seq_t1_2" START WITH 3 INCREMENT BY 4', '', 'srv "s_2_2"') +1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2 +SELECT MAX(id) FROM t1; +MAX(id) +2 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SELECT MAX(id) FROM t1; +MAX(id) +3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6 +SELECT MAX(id) FROM t1; +MAX(id) +6 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +7 +SELECT MAX(id) FROM t1; +MAX(id) +7 +INSERT INTO t1 () VALUES (),(),(),(); +Warnings: +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +10 +SELECT id FROM t1 ORDER BY id; +id +2 +3 +6 +7 +10 +11 +14 +15 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +18 +SELECT MAX(id) FROM t1; +MAX(id) +18 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +22 +SELECT MAX(id) FROM t1; +MAX(id) +22 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +26 +SELECT MAX(id) FROM t1; +MAX(id) +26 + +read only +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1 +SELECT id FROM t1 ORDER BY id; +id +2 +6 +10 +14 +18 +22 +26 +INSERT INTO t1 (id) VALUES (1); +ERROR HY000: Table 'auto_test_local.t1' is read only +UPDATE t1 SET id = 4 WHERE id = 2; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 2; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1; +ERROR HY000: Table 'auto_test_local.t1' is read only +TRUNCATE t1; +ERROR HY000: Table 'auto_test_local.t1' is read only + +2.27 +error mode +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1 +SELECT id FROM t1 ORDER BY id; +id +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +INSERT INTO t1 (id) VALUES (1); +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +DELETE FROM t1; +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error +TRUNCATE t1; +Warnings: +Error 12712 Error from Oracle -1 942 ORA-00942: ??????????????? + +Error 12712 Oracle error + +3.0 +is null +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a VARCHAR(255), +b VARCHAR(255), +c VARCHAR(255), +KEY idx1(a,b), +KEY idx2(b), +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1 +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +select a from t1 where a is null order by a limit 30; +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +select b from t1 where b is null order by b limit 30; +b +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +direct_order_limit +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +a b c +10 74 74 +10 42 42 +10 234 234 +10 202 202 +10 170 170 +select a, c from t1 where a = '10' order by b desc limit 5; +a c +10 74 +10 42 +10 234 +10 202 +10 170 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/r/vp_fixes.result b/storage/spider/mysql-test/spider/oracle2/r/vp_fixes.result new file mode 100644 index 00000000000..15dd29aa4d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/r/vp_fixes.result @@ -0,0 +1,80 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +0.9 +create different primary key table +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT AUTO_INCREMENT, +c INT DEFAULT 11, +PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT DEFAULT 12, +c INT DEFAULT 11, +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/basic_sql.test b/storage/spider/mysql-test/spider/oracle2/t/basic_sql.test new file mode 100644 index 00000000000..2264b0e4e37 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/basic_sql.test @@ -0,0 +1,3189 @@ +# This test tests by executing basic SQL +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'f', '2008-07-01 10:21:39'), + (2, 'g', '2000-02-01 00:00:00'), + (3, 'j', '2007-05-04 20:03:11'), + (4, 'i', '2003-10-30 05:01:03'), + (5, 'h', '2001-10-31 23:59:59'); +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT IGNORE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + REPLACE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%replace %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table with partition and select test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + } + --enable_query_log + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo create no index table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES3; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_no_idx; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_NEEDPK) +{ + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + } +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES3; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; + +--echo +--echo select table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table shared mode +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table for update +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table straight_join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_small_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_big_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_buffer_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_no_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_calc_found_rows +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT found_rows(); + +--echo +--echo select high_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select distinct +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select count +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT count(*) FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join not use index +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using index and pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select partition using pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo select partition using index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.a > 0 AND a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo insert +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select a +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert low_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert high_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (insert) +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (update) +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update index pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update partition pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo update partition index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete all +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE IGNORE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE QUICK FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete partition pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete partition index pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo truncate +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'truncate %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_1.inc new file mode 100644 index 00000000000..cd9b0c9ca9b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_1.inc @@ -0,0 +1 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_2.inc new file mode 100644 index 00000000000..e145f66b630 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_2.inc @@ -0,0 +1 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child2_3.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_3.inc new file mode 100644 index 00000000000..d356348d8ea --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child2_3.inc @@ -0,0 +1 @@ +--connect (child2_3, localhost, root, , , $CHILD2_3_MYPORT, $CHILD2_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child3_1.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_1.inc new file mode 100644 index 00000000000..03e5c188c89 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_1.inc @@ -0,0 +1 @@ +--connect (child3_1, localhost, root, , , $CHILD3_1_MYPORT, $CHILD3_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child3_2.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_2.inc new file mode 100644 index 00000000000..d62a7ada824 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_2.inc @@ -0,0 +1 @@ +--connect (child3_2, localhost, root, , , $CHILD3_2_MYPORT, $CHILD3_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_child3_3.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_3.inc new file mode 100644 index 00000000000..fb49f5bfdac --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_child3_3.inc @@ -0,0 +1 @@ +--connect (child3_3, localhost, root, , , $CHILD3_3_MYPORT, $CHILD3_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_master_1.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_master_1.inc new file mode 100644 index 00000000000..0c129ce5775 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_master_1.inc @@ -0,0 +1 @@ +--connect (master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/connect_slave1_1.inc b/storage/spider/mysql-test/spider/oracle2/t/connect_slave1_1.inc new file mode 100644 index 00000000000..45a822743e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/connect_slave1_1.inc @@ -0,0 +1 @@ +--connect (slave1_1, localhost, root, , , $SLAVE1_1_MYPORT, $SLAVE1_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/oracle2/t/direct_aggregate.test b/storage/spider/mysql-test/spider/oracle2/t/direct_aggregate.test new file mode 100644 index 00000000000..59c45f3f190 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/direct_aggregate.test @@ -0,0 +1,316 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_aggregating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT COUNT(*) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l WHERE a < 5; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/direct_update.test b/storage/spider/mysql-test/spider/oracle2/t/direct_update.test new file mode 100644 index 00000000000..1c3ce91ff3f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/direct_update.test @@ -0,0 +1,354 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_updating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key +DELETE FROM ta_l WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update all rows with function + UPDATE ta_l2 SET c = ADDDATE(c, 1); + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key + UPDATE ta_l2 SET b = 'x' WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by a column without index + UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key with order and limit + UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key with order and limit + DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by a column without index + DELETE FROM ta_l2 WHERE b = 'c'; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key + DELETE FROM ta_l2 WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/function.test b/storage/spider/mysql-test/spider/oracle2/t/function.test new file mode 100644 index 00000000000..2b1b53c8a4f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/function.test @@ -0,0 +1,276 @@ +# This test tests for using functions +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo in() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_PK_TABLES1; + echo CHILD2_1_CREATE_TEXT_PK_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_PK_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_PK_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET3 $MASTER_1_COMMENT_TEXT_PK1_1; +--enable_query_log +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a in ('15', '120'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo date_sub() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/ha.test b/storage/spider/mysql-test/spider/oracle2/t/ha.test new file mode 100644 index 00000000000..319b1793753 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/ha.test @@ -0,0 +1,1794 @@ +# This test tests for ha features +--let $SKIP_REASON= +if ($USE_HA_TEST) +{ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source ha_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + } + if ($USE_CHILD_GROUP3) + { + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + } + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + --connection child2_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + SELECT 1; + --connection child3_2 + SELECT 1; + --connection child3_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_2_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_CREATE_TABLES; + } + eval $CHILD2_2_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_RECOVERY_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_COPY_TABLES_2_1; +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_3_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_CREATE_TABLES; + } + eval $CHILD2_3_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_RECOVERY_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_COPY_TABLES_P_2_1; + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo active standby test +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_AS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES2; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES2; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES2; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_AS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; +} +--disable_query_log +--disable_result_log +--source ha_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +} +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/ha_test_deinit.inc b/storage/spider/mysql-test/spider/oracle2/t/ha_test_deinit.inc new file mode 100644 index 00000000000..53d0409d066 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/ha_test_deinit.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_deinit_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_deinit_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_deinit_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_deinit_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/ha_test_init.inc b/storage/spider/mysql-test/spider/oracle2/t/ha_test_init.inc new file mode 100644 index 00000000000..70576ab16dc --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/ha_test_init.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_init_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_init_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_init_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_init_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/have_engine.inc b/storage/spider/mysql-test/spider/oracle2/t/have_engine.inc new file mode 100644 index 00000000000..64bef7499cb --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/have_engine.inc @@ -0,0 +1,7 @@ +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + SELECT engine, support FROM information_schema.engines; + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/have_func.inc b/storage/spider/mysql-test/spider/oracle2/t/have_func.inc new file mode 100644 index 00000000000..e0823e73fc8 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/have_func.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM mysql.func WHERE name = '$TEST_FUNC_NAME'`) +{ + SELECT name FROM mysql.func; + --let $SKIP_REASON= "Need $TEST_FUNC_NAME function" +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/have_partition.inc b/storage/spider/mysql-test/spider/oracle2/t/have_partition.inc new file mode 100644 index 00000000000..573c76ab43b --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/have_partition.inc @@ -0,0 +1,7 @@ +let $HAVE_PARTITION= 0; +if (`SELECT count(*) FROM information_schema.plugins WHERE + plugin_status = 'ACTIVE' AND + plugin_name = 'partition'`) +{ + let $HAVE_PARTITION= 1; +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/have_trigger.inc b/storage/spider/mysql-test/spider/oracle2/t/have_trigger.inc new file mode 100644 index 00000000000..10c0871dd5f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/have_trigger.inc @@ -0,0 +1,2 @@ +let $HAVE_TRIGGER= `SELECT COUNT(*) FROM information_schema.tables + WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'TRIGGERS'`; diff --git a/storage/spider/mysql-test/spider/oracle2/t/hs_test_deinit.inc b/storage/spider/mysql-test/spider/oracle2/t/hs_test_deinit.inc new file mode 100644 index 00000000000..7ec2e981fd2 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/hs_test_deinit.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_deinit_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/hs_test_init.inc b/storage/spider/mysql-test/spider/oracle2/t/hs_test_init.inc new file mode 100644 index 00000000000..831bf479524 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/hs_test_init.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_init_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/slave_test_deinit.inc b/storage/spider/mysql-test/spider/oracle2/t/slave_test_deinit.inc new file mode 100644 index 00000000000..e9d99b7a960 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/slave_test_deinit.inc @@ -0,0 +1,6 @@ +# get connection and exist engine test +--echo for slave1_1 +--connection slave1_1 +STOP SLAVE; +--source ../include/deinit_slave1_1.inc +--disconnect slave1_1 diff --git a/storage/spider/mysql-test/spider/oracle2/t/slave_test_init.inc b/storage/spider/mysql-test/spider/oracle2/t/slave_test_init.inc new file mode 100644 index 00000000000..739d88970c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/slave_test_init.inc @@ -0,0 +1,44 @@ +# get connection and exist engine test +--echo for slave1_1 +--source connect_slave1_1.inc +--connection slave1_1 +SET SESSION sql_log_bin= 0; +--let $SLAVE1_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $SLAVE1_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_slave1_1.inc +--source have_engine.inc +--let $SLAVE1_1_SLAVE_STATUS=`SHOW SLAVE STATUS` +if (!$SLAVE1_1_SLAVE_STATUS) +{ + eval CHANGE MASTER TO + MASTER_HOST = '127.0.0.1', + MASTER_USER = 'root', + MASTER_PASSWORD = '', + MASTER_PORT = $MASTER_1_MYPORT + ; +} +START SLAVE; +--connection master_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--connection slave1_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/spider3_fixes.test b/storage/spider/mysql-test/spider/oracle2/t/spider3_fixes.test new file mode 100644 index 00000000000..4139f3af955 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/spider3_fixes.test @@ -0,0 +1,570 @@ +# This test tests for Spider 3.0's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo 3.1 +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +SET INSERT_ID=5000; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + TRUNCATE TABLE t1; + TRUNCATE TABLE t2; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + SET INSERT_ID=5000; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/spider_fixes.test b/storage/spider/mysql-test/spider/oracle2/t/spider_fixes.test new file mode 100644 index 00000000000..b9ff61abcb4 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/spider_fixes.test @@ -0,0 +1,1967 @@ +# This test tests for Spider's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 2.13 +--echo select table with "order by desc" and "<" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table with "order by desc" and "<=" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.14 +--echo update table with range scan and split_read +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo 2.15 +--echo select table with range scan +TRUNCATE TABLE ta_l; +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES6; + echo CHILD2_1_CREATE_TABLES6; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES6; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES6; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.16 +--echo auto_increment insert with trigger +if ($HAVE_TRIGGER) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_CREATE_TABLES4; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES4; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES4; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; + eval CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; + echo CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE2 MASTER_1_CHARSET2; + eval CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; + --enable_query_log + --eval CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + INSERT INTO ta_l_auto_inc (a, b, c) VALUES + (NULL, 's', '2008-12-31 20:59:59'); + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES4; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +} + +--echo +--echo 2.17 +--echo engine-condition-pushdown with "or" and joining +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo partition with sort +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 + ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.23 +--echo partition update with moving partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); + UPDATE ta_l2 SET a = 4 WHERE a = 3; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo index merge +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo index merge with partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l_int; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_2_DROP_TABLES5; + echo CHILD2_2_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES5; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES5; + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1; + eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_P_2_1; + --enable_query_log + INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); + INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) + WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.24 +--echo index scan update without PK +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +if (!$MASTER_1_NEEDPK) +{ + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +--enable_query_log +SELECT a, b, c FROM ta_l_int ORDER BY a; +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l_int SET c = 4 WHERE b = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; + + +--echo +--echo 2.25 +--echo direct order limit +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; + + +--echo +--echo 2.26 +--echo lock tables +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_LOCK_TABLES1; + echo CHILD2_1_DROP_LOCK_TABLES2; + echo CHILD2_1_CREATE_LOCK_TABLES1; + echo CHILD2_1_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_LOCK_TABLES1; + eval $CHILD2_1_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_LOCK_TABLES1; + eval $CHILD2_1_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_LOCK_TABLES1; + echo CHILD2_2_DROP_LOCK_TABLES2; + echo CHILD2_2_CREATE_LOCK_TABLES1; + echo CHILD2_2_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_LOCK_TABLES1; + eval $CHILD2_2_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_LOCK_TABLES1; + eval $CHILD2_2_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1; +eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2; +eval CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK2; +--enable_query_log +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + + +--echo +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + SET INSERT_ID=5000; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo read only +let $MASTER_1_ENGINE_IS_SPIDER= + `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'Spider' OR + '$MASTER_1_HIDDEN_ENGINE_TYPE' = 'Spider', 1, 0)`; +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_READONLY1_1; + --let $MIN_VAL= `SELECT MIN(id) FROM t1` + --enable_query_log + SELECT id FROM t1 ORDER BY id; + --error 12518 + INSERT INTO t1 (id) VALUES (1); + --error 12518 + eval UPDATE t1 SET id = 4 WHERE id = $MIN_VAL; + --error 12518 + eval DELETE FROM t1 WHERE id = $MIN_VAL; + --error 12518 + DELETE FROM t1; + --error 12518 + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 2.27 +--echo error mode +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_ERROR_MODE1_1; + --enable_query_log + SELECT id FROM t1 ORDER BY id; + INSERT INTO t1 (id) VALUES (1); + DELETE FROM t1; + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 3.0 +--echo is null +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_KEY_TABLES1; + echo CHILD2_1_CREATE_TEXT_KEY_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_KEY_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_KEY_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_TEXT_KEY1_1; +--enable_query_log +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a is null order by a limit 30; +select b from t1 where b is null order by b limit 30; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo direct_order_limit +--connection master_1 +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +select a, c from t1 where a = '10' order by b desc limit 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/oracle2/t/test_deinit.inc b/storage/spider/mysql-test/spider/oracle2/t/test_deinit.inc new file mode 100644 index 00000000000..989bde26d3c --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/test_deinit.inc @@ -0,0 +1,37 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/deinit_master_1.inc +--disconnect master_1 +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/deinit_child2_1.inc + --disconnect child2_1 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --echo child2_3 + --connection child2_3 + --source ../include/deinit_child2_3.inc + --disconnect child2_3 +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/deinit_child3_1.inc + --disconnect child3_1 + --echo child3_2 + --connection child3_2 + --source ../include/deinit_child3_2.inc + --disconnect child3_2 + --echo child3_3 + --connection child3_3 + --source ../include/deinit_child3_3.inc + --disconnect child3_3 +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/test_init.inc b/storage/spider/mysql-test/spider/oracle2/t/test_init.inc new file mode 100644 index 00000000000..f2cd6c0269f --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/test_init.inc @@ -0,0 +1,74 @@ +# get connection and exist engine test +--echo for master_1 +--source connect_master_1.inc +--connection master_1 +CALL mtr.add_suppression("unknown variable"); +SET SESSION sql_log_bin= 0; +--let $MASTER_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $MASTER_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_master_1.inc +--source have_engine.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --source connect_child2_1.inc + --connection child2_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE + --source ../include/init_child2_1.inc + --source have_engine.inc + --echo child2_2 + --source connect_child2_2.inc + --connection child2_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE + --source ../include/init_child2_2.inc + --source have_engine.inc + --echo child2_3 + --source connect_child2_3.inc + --connection child2_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE + --source ../include/init_child2_3.inc + --source have_engine.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --source connect_child3_1.inc + --connection child3_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE + --source ../include/init_child3_1.inc + --source have_engine.inc + --echo child3_2 + --source connect_child3_2.inc + --connection child3_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE + --source ../include/init_child3_2.inc + --source have_engine.inc + --echo child3_3 + --source connect_child3_3.inc + --connection child3_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE + --source ../include/init_child3_3.inc + --source have_engine.inc +} diff --git a/storage/spider/mysql-test/spider/oracle2/t/vp_fixes.test b/storage/spider/mysql-test/spider/oracle2/t/vp_fixes.test new file mode 100644 index 00000000000..46e7b0afc36 --- /dev/null +++ b/storage/spider/mysql-test/spider/oracle2/t/vp_fixes.test @@ -0,0 +1,358 @@ +# This test tests for VP's bug fixes +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 0.9 +--echo create different primary key table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--let $MASTER_1_IS_VP= `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'VP', 1, 0)` +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo create un-correspond primary key table +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/r/basic_sql.result b/storage/spider/mysql-test/spider/r/basic_sql.result new file mode 100644 index 00000000000..e6202327ef6 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/basic_sql.result @@ -0,0 +1,701 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'f', '2008-07-01 10:21:39'), +(2, 'g', '2000-02-01 00:00:00'), +(3, 'j', '2007-05-04 20:03:11'), +(4, 'i', '2003-10-30 05:01:03'), +(5, 'h', '2001-10-31 23:59:59'); +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l +Warnings: +Warning 1062 Duplicate entry '1' for key 'PRIMARY' +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +Warning 1062 Duplicate entry '3' for key 'PRIMARY' +Warning 1062 Duplicate entry '4' for key 'PRIMARY' +Warning 1062 Duplicate entry '5' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +create table ignore select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create table with partition and select test +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +create no index table +DROP TABLE IF EXISTS ta_l_no_idx; +CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table shared mode +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table for update +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table join +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select table straight_join +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +a b date_format(b.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_small_result +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_big_result +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_buffer_result +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_cache +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_no_cache +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select sql_calc_found_rows +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +SELECT found_rows(); +found_rows() +5 + +select high_priority +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select distinct +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select count +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +select using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select using index and pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +select partition using index pushdown +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +insert select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 + +insert low_priority +TRUNCATE TABLE ta_l; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert high_priority +TRUNCATE TABLE ta_l; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert ignore +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +Warnings: +Warning 1062 Duplicate entry '2' for key 'PRIMARY' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (insert) +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 + +insert update (update) +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2005-08-08 11:11:11 + +replace +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 f 2008-02-02 02:02:02 + +replace select +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace select a +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +replace low_priority +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 g 2000-02-01 00:00:00 +3 g 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 h 2010-04-04 04:04:04 +2 g 2009-03-03 03:03:03 + +update join +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update partition pushdown +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 e 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +update partition index pushdown +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 +3 j 2009-03-03 03:03:03 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete all +DELETE FROM ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE IGNORE FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE QUICK FROM ta_l WHERE a = 2; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 e 2008-01-01 23:59:59 +3 e 2008-01-01 23:59:59 +4 e 2008-01-01 23:59:59 +5 e 2008-01-01 23:59:59 +6 e 2008-01-01 23:59:59 +7 e 2008-01-01 23:59:59 +8 e 2008-01-01 23:59:59 +9 e 2008-01-01 23:59:59 +10 j 2008-01-01 23:59:59 + +delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +10 j 2008-01-01 23:59:59 + +delete partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +delete partition index pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 f 2008-07-01 10:21:39 +3 j 2007-05-04 20:03:11 +4 i 2003-10-30 05:01:03 +5 h 2001-10-31 23:59:59 + +truncate +TRUNCATE TABLE ta_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/direct_aggregate.result b/storage/spider/mysql-test/spider/r/direct_aggregate.result new file mode 100644 index 00000000000..7bf1cb4aea7 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_aggregate.result @@ -0,0 +1,132 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_aggregating test +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 3 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/direct_update.result b/storage/spider/mysql-test/spider/r/direct_update.result new file mode 100644 index 00000000000..135734641c1 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_update.result @@ -0,0 +1,226 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table select test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +direct_updating test +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +with partition test +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +update all rows with function +UPDATE ta_l2 SET c = ADDDATE(c, 1); +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 e 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key +UPDATE ta_l2 SET b = 'x' WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2007-06-05 20:03:11 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by a column without index +UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-17 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +update by primary key with order and limit +UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_update'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +2 b 2000-01-02 00:00:00 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by primary key with order and limit +DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +5 c 2002-01-01 23:59:59 +delete by a column without index +DELETE FROM ta_l2 WHERE b = 'c'; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +3 x 2011-10-18 00:00:00 +4 d 2003-12-01 05:01:03 +delete by primary key +DELETE FROM ta_l2 WHERE a = 3; +SHOW STATUS LIKE 'Spider_direct_delete'; +Variable_name Value +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-02 10:21:39 +4 d 2003-12-01 05:01:03 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/function.result b/storage/spider/mysql-test/spider/r/function.result new file mode 100644 index 00000000000..764c774514b --- /dev/null +++ b/storage/spider/mysql-test/spider/r/function.result @@ -0,0 +1,149 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +in() +CREATE TABLE t1 ( +a VARCHAR(255), +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1 +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-08-01 10:21:39 +2 b 1999-01-01 00:00:00 +3 e 2006-06-04 20:03:11 +4 d 2002-11-30 05:01:03 +5 c 2000-12-31 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-11-01 10:21:39 +2 b 1999-04-01 00:00:00 +3 e 2006-09-04 20:03:11 +4 d 2003-02-28 05:01:03 +5 c 2001-03-31 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-01 10:21:39 +2 b 1999-03-01 00:00:00 +3 e 2006-08-04 20:03:11 +4 d 2003-01-28 05:01:03 +5 c 2001-02-28 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-08 10:21:39 +2 b 1999-03-08 00:00:00 +3 e 2006-08-11 20:03:11 +4 d 2003-02-04 05:01:03 +5 c 2001-03-07 23:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 10:21:39 +2 b 1999-03-07 00:00:00 +3 e 2006-08-10 20:03:11 +4 d 2003-02-03 05:01:03 +5 c 2001-03-06 23:59:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:21:39 +2 b 1999-03-07 01:00:00 +3 e 2006-08-10 21:03:11 +4 d 2003-02-03 06:01:03 +5 c 2001-03-07 00:59:59 +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:39 +2 b 1999-03-07 00:59:00 +3 e 2006-08-10 21:02:11 +4 d 2003-02-03 06:00:03 +5 c 2001-03-07 00:58:59 +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2007-10-07 11:20:40 +2 b 1999-03-07 00:59:01 +3 e 2006-08-10 21:02:12 +4 d 2003-02-03 06:00:04 +5 c 2001-03-07 00:59:00 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/ha.result b/storage/spider/mysql-test/spider/r/ha.result new file mode 100644 index 00000000000..e05ecb32e1b --- /dev/null +++ b/storage/spider/mysql-test/spider/r/ha.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +test select 1 +SELECT 1; +1 +1 + +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 0 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote2.ta_r3' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 1 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 2 +SELECT spider_copy_tables('ta_l', '0', '1'); +spider_copy_tables('ta_l', '0', '1') +1 +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 1"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 1 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote3.ta_r4' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 3 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 2"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 2 +SELECT spider_copy_tables('ta_l2#P#pt2', '0', '1'); +spider_copy_tables('ta_l2#P#pt2', '0', '1') +1 +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "0 1"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +active standby test +create table test +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1 +INSERT INTO ta_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 3 +auto_test_local ta_l 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 2 +INSERT INTO ta_l (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", alc "1", + database "auto_test_remote auto_test_remote2", lst "1 0"'; +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l 0 1 +auto_test_local ta_l 1 1 +INSERT INTO ta_l (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +8 g 2011-05-05 21:33:30 +DROP TABLE ta_l; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +create table with partition test +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); + +select test +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +fail-over test +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 2 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +ERROR HY000: Table 'auto_test_remote.ta_r2' get a problem +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 3 +auto_test_local ta_l2#P#pt2 1 1 +SELECT db_name, table_name, link_id FROM mysql.spider_link_failed_log; +db_name table_name link_id +auto_test_local ta_l 1 +auto_test_local ta_l2#P#pt2 1 +auto_test_local ta_l 0 +auto_test_local ta_l2#P#pt2 0 +SHOW STATUS LIKE 'Spider_mon_table_cache_version%'; +Variable_name Value +Spider_mon_table_cache_version 3 +Spider_mon_table_cache_version_req 3 +INSERT INTO ta_l2 (a, b, c) VALUES +(6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +6 e 2011-05-05 20:04:05 + +recovery test +ALTER TABLE ta_l2 +PARTITION BY KEY(a) ( +PARTITION pt1 COMMENT='srv "s_2_1 s_2_2", tbl "ta_r ta_r3", + priority "1000"', +PARTITION pt2 COMMENT='srv "s_2_1 s_2_3", tbl "ta_r2 ta_r4", + priority "1000001", lst "1 0"' + ); +SELECT db_name, table_name, link_id, link_status FROM mysql.spider_tables +ORDER BY db_name, table_name, link_id; +db_name table_name link_id link_status +auto_test_local ta_l2#P#pt1 0 1 +auto_test_local ta_l2#P#pt1 1 1 +auto_test_local ta_l2#P#pt2 0 1 +auto_test_local ta_l2#P#pt2 1 1 +INSERT INTO ta_l2 (a, b, c) VALUES +(8, 'g', '2011-05-05 21:33:30'), +(9, 'h', '2011-05-05 22:32:10'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +3 e 2007-06-04 20:03:11 +5 c 2001-12-31 23:59:59 +8 g 2011-05-05 21:33:30 +9 h 2011-05-05 22:32:10 +DROP TABLE ta_l2; + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +DROP DATABASE IF EXISTS auto_test_remote3; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/spider3_fixes.result b/storage/spider/mysql-test/spider/r/spider3_fixes.result new file mode 100644 index 00000000000..34a8f3cf933 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider3_fixes.result @@ -0,0 +1,371 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +3.1 +auto_increment +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT MAX(id) FROM t1; +MAX(id) +1555 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2332 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +1555 +2331 +2332 +3109 +3886 +4663 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5439 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +1555 +2331 +2332 +3109 +3886 +4663 +5439 +6216 +6993 +7770 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +auto_increment with partition +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +CREATE TABLE t2 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t2; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +778 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t2; +MAX(id) +2331 +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1555 +SELECT id FROM t1 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3109 +3886 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT id FROM t2 ORDER BY id; +id +777 +778 +1554 +1555 +2331 +2332 +3108 +3109 +3885 +3886 +4662 +5439 +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t2 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +MASTER_1_AUTO_INCREMENT_OFFSET3 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +MASTER_1_AUTO_INCREMENT_OFFSET4 +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +6993 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +6993 +SELECT MAX(id) FROM t2; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/spider_fixes.result b/storage/spider/mysql-test/spider/r/spider_fixes.result new file mode 100644 index 00000000000..aedde01e178 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider_fixes.result @@ -0,0 +1,692 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +2.13 +select table with "order by desc" and "<" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 +2 b 2000-01-01 00:00:00 + +select table with "order by desc" and "<=" +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +5 c 2001-12-31 23:59:59 +4 d 2003-11-30 05:01:03 +3 e 2007-06-04 20:03:11 + +2.14 +update table with range scan and split_read +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-02-02 00:00:00 +3 e 2000-02-02 00:00:00 +4 d 2000-02-02 00:00:00 +5 c 2000-02-02 00:00:00 + +2.15 +select table with range scan +TRUNCATE TABLE ta_l; +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +a int(11) NOT NULL DEFAULT '0', +b char(1) DEFAULT NULL, +c datetime DEFAULT NULL, +PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +a b c +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +CREATE TABLE ta_l_auto_inc ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tc_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END;; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 s 2008-12-31 20:59:59 + +2.17 +engine-condition-pushdown with "or" and joining +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +partition with sort +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 +ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +2.23 +partition update with moving partition +DROP TABLE IF EXISTS ta_l2; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); +UPDATE ta_l2 SET a = 4 WHERE a = 3; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +4 B 2010-09-26 00:00:00 +index merge +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 +index merge with partition +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT AUTO_INCREMENT, +b INT DEFAULT 10, +c INT DEFAULT 11, +PRIMARY KEY(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT NOT NULL, +b INT DEFAULT 10, +c INT DEFAULT 11, +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +UPDATE ta_l_int SET c = 4 WHERE b = 2; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +1 2 4 +2 3 4 +4 5 6 +6 7 8 +8 9 10 +10 11 12 +12 13 14 +14 15 16 +16 17 18 +17 2 4 + +2.25 +direct order limit +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 0 +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +a b c +1 2 4 +2 3 4 +4 5 6 +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 0 + +2.26 +lock tables +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1 +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 + +auto_increment with partition +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1 +MASTER_1_AUTO_INCREMENT_INCREMENT2 +MASTER_1_AUTO_INCREMENT_OFFSET2 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_1"') +1 +spider_direct_sql('SET SESSION AUTO_INCREMENT_INCREMENT = 4', '', +'srv "s_2_2"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 2', '', +'srv "s_2_1"') +1 +spider_bg_direct_sql('SET SESSION AUTO_INCREMENT_OFFSET = 3', '', +'srv "s_2_2"') +1 +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +PRIMARY KEY (id) +) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +777 +SELECT MAX(id) FROM t1; +MAX(id) +777 +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1554 +SELECT MAX(id) FROM t1; +MAX(id) +1554 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +2331 +SELECT MAX(id) FROM t1; +MAX(id) +2331 +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3108 +SELECT MAX(id) FROM t1; +MAX(id) +3108 +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3885 +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +3885 +4662 +5439 +6216 +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +6216 +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +5000 +SELECT MAX(id) FROM t1; +MAX(id) +10000 +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 + +read only +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1 +SELECT id FROM t1 ORDER BY id; +id +1000 +1554 +3108 +4662 +5000 +6216 +10000 +INSERT INTO t1 (id) VALUES (1); +ERROR HY000: Table 'auto_test_local.t1' is read only +UPDATE t1 SET id = 4 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 1000; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1; +ERROR HY000: Table 'auto_test_local.t1' is read only +TRUNCATE t1; +ERROR HY000: Table 'auto_test_local.t1' is read only + +2.27 +error mode +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1 +SELECT id FROM t1 ORDER BY id; +id +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +INSERT INTO t1 (id) VALUES (1); +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +DELETE FROM t1; +Warnings: +Error 12702 Remote table 'auto_test_remote.ter1_1' is not found +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist +TRUNCATE t1; +Warnings: +Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist + +3.0 +is null +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a VARCHAR(255), +b VARCHAR(255), +c VARCHAR(255), +KEY idx1(a,b), +KEY idx2(b), +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1 +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +select a from t1 where a is null order by a limit 30; +a +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +select b from t1 where b is null order by b limit 30; +b +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL + +direct_order_limit +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +a b c +10 74 74 +10 42 42 +10 234 234 +10 202 202 +10 170 170 +select a, c from t1 where a = '10' order by b desc limit 5; +a c +10 74 +10 42 +10 234 +10 202 +10 170 + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/r/vp_fixes.result b/storage/spider/mysql-test/spider/r/vp_fixes.result new file mode 100644 index 00000000000..15dd29aa4d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/vp_fixes.result @@ -0,0 +1,80 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +test select 1 +SELECT 1; +1 +1 + +create table and insert +DROP TABLE IF EXISTS tb_l; +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tb_l (a, b, c) VALUES +(1, 'a', '2008-08-01 10:21:39'), +(2, 'b', '2000-01-01 00:00:00'), +(3, 'e', '2007-06-04 20:03:11'), +(4, 'd', '2003-11-30 05:01:03'), +(5, 'c', '2001-12-31 23:59:59'); +DROP TABLE IF EXISTS ta_l; +CREATE TABLE ta_l ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +0.9 +create different primary key table +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT AUTO_INCREMENT, +c INT DEFAULT 11, +PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +DROP TABLE IF EXISTS ta_l_int; +CREATE TABLE ta_l_int ( +a INT DEFAULT 10, +b INT DEFAULT 12, +c INT DEFAULT 11, +PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1 +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +DROP DATABASE IF EXISTS auto_test_local; +DROP DATABASE IF EXISTS auto_test_remote; +DROP DATABASE IF EXISTS auto_test_remote2; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +end of test diff --git a/storage/spider/mysql-test/spider/suite.opt b/storage/spider/mysql-test/spider/suite.opt new file mode 100644 index 00000000000..48457b17309 --- /dev/null +++ b/storage/spider/mysql-test/spider/suite.opt @@ -0,0 +1 @@ +--loose-innodb diff --git a/storage/spider/mysql-test/spider/suite.pm b/storage/spider/mysql-test/spider/suite.pm new file mode 100644 index 00000000000..5569c57bec9 --- /dev/null +++ b/storage/spider/mysql-test/spider/suite.pm @@ -0,0 +1,9 @@ +package My::Suite::Spider; + +@ISA = qw(My::Suite); + +return "No Spider engine" unless $ENV{HA_SPIDER_SO}; +return "Not run for embedded server" if $::opt_embedded_server; + +bless { }; + diff --git a/storage/spider/mysql-test/spider/t/basic_sql.test b/storage/spider/mysql-test/spider/t/basic_sql.test new file mode 100644 index 00000000000..2264b0e4e37 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/basic_sql.test @@ -0,0 +1,3189 @@ +# This test tests by executing basic SQL +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'f', '2008-07-01 10:21:39'), + (2, 'g', '2000-02-01 00:00:00'), + (3, 'j', '2007-05-04 20:03:11'), + (4, 'i', '2003-10-30 05:01:03'), + (5, 'h', '2001-10-31 23:59:59'); +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +IGNORE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + INSERT IGNORE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + IGNORE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table ignore select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +REPLACE SELECT a, b, c FROM tb_l; +if ($MASTER_1_MERGE) +{ + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + REPLACE INTO ta_l SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_MERGE) +{ + eval CREATE TABLE ta_l ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1 + REPLACE SELECT a, b, c FROM tb_l; +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%replace %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo create table with partition and select test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l2 ( + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1 + SELECT a, b, c FROM tb_l; + } + --enable_query_log + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo create no index table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES3; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_no_idx; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_no_idx +MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +SELECT a, b, c FROM tb_l; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; +} +if (!$MASTER_1_NEEDPK) +{ + if ($MASTER_1_MERGE) + { + --error ER_WRONG_OBJECT + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + eval CREATE TABLE ta_l_no_idx ( + a INT, + b CHAR(1), + c DATETIME + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; + INSERT INTO ta_l_no_idx SELECT a, b, c FROM tb_l; + } + if (!$MASTER_1_MERGE) + { + eval CREATE TABLE ta_l_no_idx + $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1 + SELECT a, b, c FROM tb_l; + } +} +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES3; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l_no_idx ORDER BY a; + +--echo +--echo select table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table shared mode +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +LOCK IN SHARE MODE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table for update +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a +FOR UPDATE; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a, tb_l b +WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table straight_join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s') +FROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_small_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_SMALL_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_big_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BIG_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_buffer_result +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_BUFFER_RESULT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_no_cache +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_NO_CACHE a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select sql_calc_found_rows +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT SQL_CALC_FOUND_ROWS a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a LIMIT 4; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT found_rows(); + +--echo +--echo select high_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT HIGH_PRIORITY a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select distinct +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT DISTINCT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select count +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT count(*) FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table join not use index +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM tb_l a WHERE +EXISTS (SELECT * FROM ta_l b WHERE b.b = a.b) ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select using index and pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l a WHERE +a.a > 0 AND a.b = 'g' ORDER BY a.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select partition using pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo select partition using index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a.a, a.b, date_format(a.c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 a WHERE + a.a > 0 AND a.b = 'g' ORDER BY a.a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo insert +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert select a +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert low_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert high_priority +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT IGNORE INTO ta_l (a, b, c) VALUES (2, 'd', '2009-02-02 01:01:01'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (insert) +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo insert update (update) +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59') ON DUPLICATE +KEY UPDATE b = 'f', c = '2005-08-08 11:11:11'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE INTO ta_l (a, b, c) VALUES ((SELECT a FROM tb_l ORDER BY a LIMIT 1), +'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo replace low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update select a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'h', c = '2010-04-04 04:04:04' WHERE a = (SELECT a FROM +tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update join a +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l a, tb_l b SET a.b = 'g', a.c = '2009-03-03 03:03:03' WHERE +a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update low_priority +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update ignore +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update index pushdown +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo update partition pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo update partition index pushdown +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'update %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete all +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete select a +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete join +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete low_priority +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete ignore +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE IGNORE FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete quick +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE QUICK FROM ta_l WHERE a = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete index pushdown +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (1, 'e', '2008-01-01 23:59:59'), +(2, 'e', '2008-01-01 23:59:59'), (3, 'e', '2008-01-01 23:59:59'), +(4, 'e', '2008-01-01 23:59:59'), (5, 'e', '2008-01-01 23:59:59'), +(6, 'e', '2008-01-01 23:59:59'), (7, 'e', '2008-01-01 23:59:59'), +(8, 'e', '2008-01-01 23:59:59'), (9, 'e', '2008-01-01 23:59:59'), +(10, 'j', '2008-01-01 23:59:59'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo delete partition pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo delete partition index pushdown +if ($HAVE_PARTITION) +{ + TRUNCATE TABLE ta_l2; + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE 'delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; +} + +--echo +--echo truncate +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +TRUNCATE TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE 'truncate %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/connect_child2_1.inc b/storage/spider/mysql-test/spider/t/connect_child2_1.inc new file mode 100644 index 00000000000..cd9b0c9ca9b --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child2_1.inc @@ -0,0 +1 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child2_2.inc b/storage/spider/mysql-test/spider/t/connect_child2_2.inc new file mode 100644 index 00000000000..e145f66b630 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child2_2.inc @@ -0,0 +1 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child2_3.inc b/storage/spider/mysql-test/spider/t/connect_child2_3.inc new file mode 100644 index 00000000000..d356348d8ea --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child2_3.inc @@ -0,0 +1 @@ +--connect (child2_3, localhost, root, , , $CHILD2_3_MYPORT, $CHILD2_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child3_1.inc b/storage/spider/mysql-test/spider/t/connect_child3_1.inc new file mode 100644 index 00000000000..03e5c188c89 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child3_1.inc @@ -0,0 +1 @@ +--connect (child3_1, localhost, root, , , $CHILD3_1_MYPORT, $CHILD3_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child3_2.inc b/storage/spider/mysql-test/spider/t/connect_child3_2.inc new file mode 100644 index 00000000000..d62a7ada824 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child3_2.inc @@ -0,0 +1 @@ +--connect (child3_2, localhost, root, , , $CHILD3_2_MYPORT, $CHILD3_2_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_child3_3.inc b/storage/spider/mysql-test/spider/t/connect_child3_3.inc new file mode 100644 index 00000000000..fb49f5bfdac --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child3_3.inc @@ -0,0 +1 @@ +--connect (child3_3, localhost, root, , , $CHILD3_3_MYPORT, $CHILD3_3_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_master_1.inc b/storage/spider/mysql-test/spider/t/connect_master_1.inc new file mode 100644 index 00000000000..0c129ce5775 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_master_1.inc @@ -0,0 +1 @@ +--connect (master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/connect_slave1_1.inc b/storage/spider/mysql-test/spider/t/connect_slave1_1.inc new file mode 100644 index 00000000000..45a822743e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_slave1_1.inc @@ -0,0 +1 @@ +--connect (slave1_1, localhost, root, , , $SLAVE1_1_MYPORT, $SLAVE1_1_MYSOCK) diff --git a/storage/spider/mysql-test/spider/t/direct_aggregate.test b/storage/spider/mysql-test/spider/t/direct_aggregate.test new file mode 100644 index 00000000000..59c45f3f190 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_aggregate.test @@ -0,0 +1,316 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_aggregating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT COUNT(*) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MAX(a) FROM ta_l WHERE a < 5; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_update.test b/storage/spider/mysql-test/spider/t/direct_update.test new file mode 100644 index 00000000000..1c3ce91ff3f --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_update.test @@ -0,0 +1,354 @@ +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo direct_updating test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update all rows with function +UPDATE ta_l SET c = ADDDATE(c, 1); +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key +UPDATE ta_l SET b = 'x' WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by a column without index +UPDATE ta_l SET c = '2011-10-17' WHERE b = 'x'; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo update by primary key with order and limit +UPDATE ta_l SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key with order and limit +DELETE FROM ta_l WHERE a < 4 ORDER BY c LIMIT 1; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by a column without index +DELETE FROM ta_l WHERE b = 'c'; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +--echo delete by primary key +DELETE FROM ta_l WHERE a = 3; +eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo with partition test +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + --enable_query_log + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update all rows with function + UPDATE ta_l2 SET c = ADDDATE(c, 1); + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key + UPDATE ta_l2 SET b = 'x' WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by a column without index + UPDATE ta_l2 SET c = '2011-10-17' WHERE b = 'x'; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo update by primary key with order and limit + UPDATE ta_l2 SET c = ADDDATE(c, 1) WHERE a < 4 ORDER BY b DESC LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_UPDATE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key with order and limit + DELETE FROM ta_l2 WHERE a < 4 ORDER BY c LIMIT 1; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by a column without index + DELETE FROM ta_l2 WHERE b = 'c'; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + --echo delete by primary key + DELETE FROM ta_l2 WHERE a = 3; + eval $MASTER_1_CHECK_DIRECT_DELETE_STATUS; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/function.test b/storage/spider/mysql-test/spider/t/function.test new file mode 100644 index 00000000000..2b1b53c8a4f --- /dev/null +++ b/storage/spider/mysql-test/spider/t/function.test @@ -0,0 +1,276 @@ +# This test tests for using functions +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo in() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_PK_TABLES1; + echo CHILD2_1_CREATE_TEXT_PK_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_PK_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_PK_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET3 MASTER_1_COMMENT_TEXT_PK1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET3 $MASTER_1_COMMENT_TEXT_PK1_1; +--enable_query_log +insert into t1 values ('1'); +insert into t1 select a + 1 from t1; +insert into t1 select a + 2 from t1; +insert into t1 select a + 4 from t1; +insert into t1 select a + 8 from t1; +insert into t1 select a + 16 from t1; +insert into t1 select a + 32 from t1; +insert into t1 select a + 64 from t1; +insert into t1 select a + 128 from t1; +insert into t1 select a + 256 from t1; +insert into t1 select a + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a in ('15', '120'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo date_sub() +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 YEAR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 QUARTER); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MONTH); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 WEEK); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 DAY); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 HOUR); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_SUB(c, INTERVAL 1 MINUTE); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +UPDATE ta_l SET c = DATE_ADD(c, INTERVAL 1 SECOND); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/ha.test b/storage/spider/mysql-test/spider/t/ha.test new file mode 100644 index 00000000000..319b1793753 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/ha.test @@ -0,0 +1,1794 @@ +# This test tests for ha features +--let $SKIP_REASON= +if ($USE_HA_TEST) +{ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source ha_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + } + if ($USE_CHILD_GROUP3) + { + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; + } + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + --connection child2_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + SELECT 1; + --connection child3_2 + SELECT 1; + --connection child3_3 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_2_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_HA_CREATE_TABLES; + } + eval $CHILD2_2_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_RECOVERY_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_COPY_TABLES_2_1; +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_3_HA_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_HA_CREATE_TABLES; + } + eval $CHILD2_3_HA_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_RECOVERY_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_RECOVERY_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_COPY_TABLES_P_2_1; + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo active standby test +--echo create table test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_2_1; +--enable_query_log +INSERT INTO ta_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + +--echo +--echo select test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo fail-over test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_CHECK_HA_STATUS; +--error 12511 +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +eval $MASTER_1_CHECK_LINK_STATUS; +eval $MASTER_1_CHECK_LINK_FAILED_LOG; +eval $MASTER_1_CHECK_HA_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo recovery test +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +eval $MASTER_1_SET_OK_STATUS_AS_2_1; +eval $MASTER_1_CHECK_LINK_STATUS; +INSERT INTO ta_l (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'); +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; +DROP TABLE ta_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_CHILD_GROUP3) +{ + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +eval $MASTER_1_CHANGE_HA_MON; + +if ($HAVE_PARTITION) +{ + --echo + --echo create table with partition test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_3_DROP_TABLES; + echo CHILD2_3_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_1_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_2_CREATE_TABLES_HA_AS_P_2_1; + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + eval $CHILD3_3_CREATE_TABLES_HA_AS_P_2_1; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_HA_AS_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_HA_AS_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); + + --echo + --echo select test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo fail-over test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_DROP_TABLES2; + } + --disable_warnings + eval $CHILD2_1_HA_AS_DROP_TABLES2; + --enable_warnings + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_CHECK_HA_STATUS; + --error 12511 + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + eval $MASTER_1_CHECK_LINK_STATUS; + eval $MASTER_1_CHECK_LINK_FAILED_LOG; + eval $MASTER_1_CHECK_HA_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (6, 'e', '2011-05-05 20:04:05'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_CHECK_LINK_STATUS; + eval $CHILD3_1_CHECK_LINK_FAILED_LOG; + --connection child3_2 + eval $CHILD3_2_CHECK_LINK_STATUS; + eval $CHILD3_2_CHECK_LINK_FAILED_LOG; + --connection child3_3 + eval $CHILD3_3_CHECK_LINK_STATUS; + eval $CHILD3_3_CHECK_LINK_FAILED_LOG; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + + --echo + --echo recovery test + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_HA_AS_CREATE_TABLES2; + } + eval $CHILD2_1_HA_AS_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_3 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + eval $CHILD3_1_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_1_CHECK_LINK_STATUS; + --connection child3_2 + eval $CHILD3_2_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_2_CHECK_LINK_STATUS; + --connection child3_3 + eval $CHILD3_3_SET_OK_STATUS_AS_P_2_1; + eval $CHILD3_3_CHECK_LINK_STATUS; + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + eval $MASTER_1_SET_OK_STATUS_AS_P_2_1; + eval $MASTER_1_CHECK_LINK_STATUS; + INSERT INTO ta_l2 (a, b, c) VALUES + (8, 'g', '2011-05-05 21:33:30'), + (9, 'h', '2011-05-05 22:32:10'); + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 ORDER BY a; + DROP TABLE ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + eval $CHILD2_1_SELECT_TABLES2; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + if ($USE_CHILD_GROUP3) + { + if (!$OUTPUT_CHILD_GROUP3) + { + --disable_query_log + --disable_result_log + } + --connection child3_1 + --disable_warnings + eval $CHILD3_1_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_2 + --disable_warnings + eval $CHILD3_2_DROP_TABLES_HA_P_2_1; + --enable_warnings + --connection child3_3 + --disable_warnings + eval $CHILD3_3_DROP_TABLES_HA_P_2_1; + --enable_warnings + if (!$OUTPUT_CHILD_GROUP3) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_2 + DROP DATABASE IF EXISTS auto_test_local; + --connection child3_3 + DROP DATABASE IF EXISTS auto_test_local; +} +--disable_query_log +--disable_result_log +--source ha_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +} +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/ha_test_deinit.inc b/storage/spider/mysql-test/spider/t/ha_test_deinit.inc new file mode 100644 index 00000000000..53d0409d066 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/ha_test_deinit.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_deinit_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_deinit_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_deinit_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_deinit_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/t/ha_test_init.inc b/storage/spider/mysql-test/spider/t/ha_test_init.inc new file mode 100644 index 00000000000..70576ab16dc --- /dev/null +++ b/storage/spider/mysql-test/spider/t/ha_test_init.inc @@ -0,0 +1,30 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/ha_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/ha_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/ha_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/ha_init_child2_3.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/ha_init_child3_1.inc + --echo child3_2 + --connection child3_2 + --source ../include/ha_init_child3_2.inc + --echo child3_3 + --connection child3_3 + --source ../include/ha_init_child3_3.inc +} diff --git a/storage/spider/mysql-test/spider/t/have_engine.inc b/storage/spider/mysql-test/spider/t/have_engine.inc new file mode 100644 index 00000000000..64bef7499cb --- /dev/null +++ b/storage/spider/mysql-test/spider/t/have_engine.inc @@ -0,0 +1,7 @@ +if (!`SELECT count(*) FROM information_schema.engines WHERE + (support = 'YES' OR support = 'DEFAULT') AND + engine = '$TEST_ENGINE_TYPE'`) +{ + SELECT engine, support FROM information_schema.engines; + --let $SKIP_REASON= "Need $TEST_ENGINE_TYPE engine" +} diff --git a/storage/spider/mysql-test/spider/t/have_func.inc b/storage/spider/mysql-test/spider/t/have_func.inc new file mode 100644 index 00000000000..e0823e73fc8 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/have_func.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM mysql.func WHERE name = '$TEST_FUNC_NAME'`) +{ + SELECT name FROM mysql.func; + --let $SKIP_REASON= "Need $TEST_FUNC_NAME function" +} diff --git a/storage/spider/mysql-test/spider/t/have_partition.inc b/storage/spider/mysql-test/spider/t/have_partition.inc new file mode 100644 index 00000000000..573c76ab43b --- /dev/null +++ b/storage/spider/mysql-test/spider/t/have_partition.inc @@ -0,0 +1,7 @@ +let $HAVE_PARTITION= 0; +if (`SELECT count(*) FROM information_schema.plugins WHERE + plugin_status = 'ACTIVE' AND + plugin_name = 'partition'`) +{ + let $HAVE_PARTITION= 1; +} diff --git a/storage/spider/mysql-test/spider/t/have_plugin.inc b/storage/spider/mysql-test/spider/t/have_plugin.inc new file mode 100644 index 00000000000..316ede9ec46 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/have_plugin.inc @@ -0,0 +1,5 @@ +if (!`SELECT count(*) FROM information_schema.plugins WHERE plugin_name = '$TEST_PLUGIN_NAME'`) +{ + SELECT plugin_name FROM information_schema.plugins; + --let $SKIP_REASON= "Need $TEST_PLUGIN_NAME plugin" +} diff --git a/storage/spider/mysql-test/spider/t/have_trigger.inc b/storage/spider/mysql-test/spider/t/have_trigger.inc new file mode 100644 index 00000000000..10c0871dd5f --- /dev/null +++ b/storage/spider/mysql-test/spider/t/have_trigger.inc @@ -0,0 +1,2 @@ +let $HAVE_TRIGGER= `SELECT COUNT(*) FROM information_schema.tables + WHERE TABLE_SCHEMA = 'information_schema' AND TABLE_NAME = 'TRIGGERS'`; diff --git a/storage/spider/mysql-test/spider/t/hs_test_deinit.inc b/storage/spider/mysql-test/spider/t/hs_test_deinit.inc new file mode 100644 index 00000000000..7ec2e981fd2 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/hs_test_deinit.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_deinit_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_deinit_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_deinit_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_deinit_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/t/hs_test_init.inc b/storage/spider/mysql-test/spider/t/hs_test_init.inc new file mode 100644 index 00000000000..831bf479524 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/hs_test_init.inc @@ -0,0 +1,17 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/hs_init_master_1.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/hs_init_child2_1.inc + --echo child2_2 + --connection child2_2 + --source ../include/hs_init_child2_2.inc + --echo child2_3 + --connection child2_3 + --source ../include/hs_init_child2_3.inc +} diff --git a/storage/spider/mysql-test/spider/t/slave_test_deinit.inc b/storage/spider/mysql-test/spider/t/slave_test_deinit.inc new file mode 100644 index 00000000000..e9d99b7a960 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/slave_test_deinit.inc @@ -0,0 +1,6 @@ +# get connection and exist engine test +--echo for slave1_1 +--connection slave1_1 +STOP SLAVE; +--source ../include/deinit_slave1_1.inc +--disconnect slave1_1 diff --git a/storage/spider/mysql-test/spider/t/slave_test_init.inc b/storage/spider/mysql-test/spider/t/slave_test_init.inc new file mode 100644 index 00000000000..739d88970c5 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/slave_test_init.inc @@ -0,0 +1,44 @@ +# get connection and exist engine test +--echo for slave1_1 +--source connect_slave1_1.inc +--connection slave1_1 +SET SESSION sql_log_bin= 0; +--let $SLAVE1_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $SLAVE1_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_slave1_1.inc +--source have_engine.inc +--let $SLAVE1_1_SLAVE_STATUS=`SHOW SLAVE STATUS` +if (!$SLAVE1_1_SLAVE_STATUS) +{ + eval CHANGE MASTER TO + MASTER_HOST = '127.0.0.1', + MASTER_USER = 'root', + MASTER_PASSWORD = '', + MASTER_PORT = $MASTER_1_MYPORT + ; +} +START SLAVE; +--connection master_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--connection slave1_1 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child2_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} +if ($USE_CHILD_GROUP3) +{ + --connection child3_1 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_2 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); + --connection child3_3 + call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +} diff --git a/storage/spider/mysql-test/spider/t/spider3_fixes.test b/storage/spider/mysql-test/spider/t/spider3_fixes.test new file mode 100644 index 00000000000..4139f3af955 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider3_fixes.test @@ -0,0 +1,570 @@ +# This test tests for Spider 3.0's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo 3.1 +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +INSERT INTO t2 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t2 ORDER BY id; +SET INSERT_ID=5000; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET3; +eval $MASTER_1_AUTO_INCREMENT_OFFSET3; +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT_OFFSET4; +eval $MASTER_1_AUTO_INCREMENT_OFFSET4; +--enable_query_log +INSERT INTO t2 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t2 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t2; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1, t2; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + echo CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + TRUNCATE TABLE t1; + TRUNCATE TABLE t2; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + INSERT INTO t2 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t2 ORDER BY id; + SET INSERT_ID=5000; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET3; + eval $MASTER_1_AUTO_INCREMENT_OFFSET3; + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + --disable_query_log + echo MASTER_1_AUTO_INCREMENT_OFFSET4; + eval $MASTER_1_AUTO_INCREMENT_OFFSET4; + --enable_query_log + INSERT INTO t2 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t2 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t2; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/spider_fixes.test b/storage/spider/mysql-test/spider/t/spider_fixes.test new file mode 100644 index 00000000000..b9ff61abcb4 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider_fixes.test @@ -0,0 +1,1967 @@ +# This test tests for Spider's bug fixes +--let $SKIP_REASON= +source include/have_log_bin.inc; +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--source slave_test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_REPLICATION) + { + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; + } + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 2.13 +--echo select table with "order by desc" and "<" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo select table with "order by desc" and "<=" +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.14 +--echo update table with range scan and split_read +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l ORDER BY a; + +--echo +--echo 2.15 +--echo select table with range scan +TRUNCATE TABLE ta_l; +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES6; + echo CHILD2_1_CREATE_TABLES6; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES6; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES6; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE ta_l ( + a int(11) NOT NULL DEFAULT '0', + b char(1) DEFAULT NULL, + c datetime DEFAULT NULL, + PRIMARY KEY (a, b, c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a >= 4 AND b = 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a > 4 AND b = 'c' +AND c = '2001-12-31 23:59:59'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b <= 'd' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b < 'e' +AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND b = 'b' +AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b >= 'b' +AND b <= 'd' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a = 4 AND b > 'b' +AND b < 'e' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a <= 4 AND a >= 1 +AND b >= 'b' AND c = '2003-11-30 05:01:03'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l FORCE INDEX(PRIMARY) WHERE a < 4 AND a > 1 +AND b >= 'b' AND c = '2000-01-01 00:00:00'; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.16 +--echo auto_increment insert with trigger +if ($HAVE_TRIGGER) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_CREATE_TABLES4; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES4; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES4; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; + eval CREATE TABLE ta_l_auto_inc ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; + echo CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE2 MASTER_1_CHARSET2; + eval CREATE TABLE tc_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; + --enable_query_log + --eval CREATE TRIGGER ins_ta_l_auto_inc AFTER INSERT ON ta_l_auto_inc FOR EACH ROW BEGIN INSERT INTO tc_l (a, b, c) VALUES (NEW.a, NEW.b, NEW.c); END; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + INSERT INTO ta_l_auto_inc (a, b, c) VALUES + (NULL, 's', '2008-12-31 20:59:59'); + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES4; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM tc_l ORDER BY a; +} + +--echo +--echo 2.17 +--echo engine-condition-pushdown with "or" and joining +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l WHERE a = 1 OR a IN (SELECT a FROM tb_l); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo partition with sort +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2 WHERE a > 1 + ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.23 +--echo partition update with moving partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_TABLES; + echo CHILD2_2_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES2; + echo CHILD2_1_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1; + eval CREATE TABLE ta_l2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT2_P_2_1; + --enable_query_log + INSERT INTO ta_l2 (a, b, c) VALUES (3, 'B', '2010-09-26 00:00:00'); + UPDATE ta_l2 SET a = 4 WHERE a = 3; + SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l2; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo index merge +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; +INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) +WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo index merge with partition +if ($HAVE_PARTITION) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS ta_l_int; + --enable_warnings + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_2_DROP_TABLES5; + echo CHILD2_2_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES5; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES5; + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } + } + --connection master_1 + --disable_query_log + echo CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_P_2_1; + eval CREATE TABLE ta_l_int ( + a INT AUTO_INCREMENT, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_P_2_1; + --enable_query_log + INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); + INSERT INTO ta_l_int (a, b, c) SELECT a + 1, b + 1, c + 1 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 2, b + 2, c + 2 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 4, b + 4, c + 4 FROM ta_l_int; + INSERT INTO ta_l_int (a, b, c) SELECT a + 8, b + 8, c + 8 FROM ta_l_int; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + SELECT a, b, c FROM ta_l_int force index(primary, idx1, idx2) + WHERE a = 5 OR b = 5 OR c = 5 ORDER BY a; + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--echo +--echo 2.24 +--echo index scan update without PK +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +if ($MASTER_1_NEEDPK) +{ + --error ER_REQUIRES_PRIMARY_KEY + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + PRIMARY KEY(a), + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +if (!$MASTER_1_NEEDPK) +{ + eval CREATE TABLE ta_l_int ( + a INT NOT NULL, + b INT DEFAULT 10, + c INT DEFAULT 11, + KEY idx1(b), + KEY idx2(c) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +} +--enable_query_log +SELECT a, b, c FROM ta_l_int ORDER BY a; +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (1, 2, 3); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +UPDATE ta_l_int SET c = 4 WHERE b = 2; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE argument LIKE '%update %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SELECT a, b, c FROM ta_l_int ORDER BY a; + + +--echo +--echo 2.25 +--echo direct order limit +--connection master_1 +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +eval $MASTER_1_CHECK_DIRECT_ORDER_LIMIT_STATUS; + + +--echo +--echo 2.26 +--echo lock tables +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_LOCK_TABLES1; + echo CHILD2_1_DROP_LOCK_TABLES2; + echo CHILD2_1_CREATE_LOCK_TABLES1; + echo CHILD2_1_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_1_DROP_LOCK_TABLES1; + eval $CHILD2_1_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_1_CREATE_LOCK_TABLES1; + eval $CHILD2_1_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_LOCK_TABLES1; + echo CHILD2_2_DROP_LOCK_TABLES2; + echo CHILD2_2_CREATE_LOCK_TABLES1; + echo CHILD2_2_CREATE_LOCK_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_LOCK_TABLES1; + eval $CHILD2_2_DROP_LOCK_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_LOCK_TABLES1; + eval $CHILD2_2_CREATE_LOCK_TABLES2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK1; +eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK1; +echo CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2; +eval CREATE TABLE t2 ( + id int(11) NOT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_LOCK2; +--enable_query_log +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + + +--echo +--echo auto_increment +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_1; +echo MASTER_1_AUTO_INCREMENT_INCREMENT2; +echo MASTER_1_AUTO_INCREMENT_OFFSET2; +eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_1; +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_1; + --connection master_1 +} +--enable_query_log +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (null); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 () VALUES (),(),(),(); +SELECT LAST_INSERT_ID(); +SELECT id FROM t1 ORDER BY id; +SET INSERT_ID=5000; +INSERT INTO t1 () VALUES (); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (10000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +INSERT INTO t1 (id) VALUES (1000); +SELECT LAST_INSERT_ID(); +SELECT MAX(id) FROM t1; +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo auto_increment with partition +if ($HAVE_PARTITION) +{ + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_INCREMENT_TABLES1; + echo CHILD2_1_CREATE_INCREMENT_TABLES1; + echo CHILD2_1_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_1_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_1_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_INCREMENT_TABLES1; + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + --connection child2_2 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_DROP_INCREMENT_TABLES1; + echo CHILD2_2_CREATE_INCREMENT_TABLES1; + echo CHILD2_2_AUTO_INCREMENT_INCREMENT2; + echo CHILD2_2_AUTO_INCREMENT_OFFSET2; + } + --disable_warnings + eval $CHILD2_2_DROP_INCREMENT_TABLES1; + --enable_warnings + eval $CHILD2_2_CREATE_INCREMENT_TABLES1; + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT2; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET2; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } + --connection master_1 + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_INCREMENT1_P_1; + echo MASTER_1_AUTO_INCREMENT_INCREMENT2; + echo MASTER_1_AUTO_INCREMENT_OFFSET2; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_INCREMENT1_P_1; + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + if ($USE_REPLICATION) + { + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + echo CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) SLAVE1_1_ENGINE SLAVE1_1_CHARSET SLAVE1_1_COMMENT_INCREMENT1_P_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (id) + ) $SLAVE1_1_ENGINE $SLAVE1_1_CHARSET $SLAVE1_1_COMMENT_INCREMENT1_P_1; + --connection master_1 + } + --enable_query_log + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (null); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 () VALUES (),(),(),(); + SELECT LAST_INSERT_ID(); + SELECT id FROM t1 ORDER BY id; + SET INSERT_ID=5000; + INSERT INTO t1 () VALUES (); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (10000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + INSERT INTO t1 (id) VALUES (1000); + SELECT LAST_INSERT_ID(); + SELECT MAX(id) FROM t1; + if ($USE_REPLICATION) + { + save_master_pos; + --connection slave1_1 + sync_with_master; + SELECT id FROM t1 ORDER BY id; + --connection master_1 + --disable_query_log + SET SESSION sql_log_bin= 0; + --enable_query_log + } + if ($USE_CHILD_GROUP2) + { + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_1_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_1_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_1_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_INCREMENT_TABLES1; + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_2_AUTO_INCREMENT_INCREMENT1; + echo CHILD2_2_AUTO_INCREMENT_OFFSET1; + } + eval $CHILD2_2_AUTO_INCREMENT_INCREMENT1; + eval $CHILD2_2_AUTO_INCREMENT_OFFSET1; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo read only +let $MASTER_1_ENGINE_IS_SPIDER= + `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'Spider' OR + '$MASTER_1_HIDDEN_ENGINE_TYPE' = 'Spider', 1, 0)`; +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_READONLY1_1; + --let $MIN_VAL= `SELECT MIN(id) FROM t1` + --enable_query_log + SELECT id FROM t1 ORDER BY id; + --error 12518 + INSERT INTO t1 (id) VALUES (1); + --error 12518 + eval UPDATE t1 SET id = 4 WHERE id = $MIN_VAL; + --error 12518 + eval DELETE FROM t1 WHERE id = $MIN_VAL; + --error 12518 + DELETE FROM t1; + --error 12518 + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 2.27 +--echo error mode +if ($MASTER_1_ENGINE_IS_SPIDER) +{ + --connection master_1 + --disable_warnings + DROP TABLE IF EXISTS t1; + --enable_warnings + --disable_query_log + echo CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_ERROR_MODE1_1; + eval CREATE TABLE t1 ( + id int(11) NOT NULL, + PRIMARY KEY (id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_ERROR_MODE1_1; + --enable_query_log + SELECT id FROM t1 ORDER BY id; + INSERT INTO t1 (id) VALUES (1); + DELETE FROM t1; + TRUNCATE t1; +} +if (!$MASTER_1_ENGINE_IS_SPIDER) +{ + --echo skipped +} + + +--echo +--echo 3.0 +--echo is null +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TEXT_KEY_TABLES1; + echo CHILD2_1_CREATE_TEXT_KEY_TABLES1; + } + --disable_warnings + eval $CHILD2_1_DROP_TEXT_KEY_TABLES1; + --enable_warnings + eval $CHILD2_1_CREATE_TEXT_KEY_TABLES1; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--disable_query_log +echo CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_TEXT_KEY1_1; +eval CREATE TABLE t1 ( + a VARCHAR(255), + b VARCHAR(255), + c VARCHAR(255), + KEY idx1(a,b), + KEY idx2(b), + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_TEXT_KEY1_1; +--enable_query_log +insert into t1 values (null, null, '2048'); +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a + 32, b + 32, c + 32 from t1; +insert into t1 select a + 64, b + 64, c + 64 from t1; +insert into t1 select a + 128, b + 128, c + 128 from t1; +insert into t1 select a + 256, b + 256, c + 256 from t1; +insert into t1 select a + 512, b + 512, c + 512 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a from t1 where a is null order by a limit 30; +select b from t1 where b is null order by b limit 30; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo direct_order_limit +--connection master_1 +TRUNCATE TABLE t1; +insert into t1 values ('1', '1', '1'); +insert into t1 select a + 1, b + 1, c + 1 from t1; +insert into t1 select a + 2, b + 2, c + 2 from t1; +insert into t1 select a + 4, b + 4, c + 4 from t1; +insert into t1 select a + 8, b + 8, c + 8 from t1; +insert into t1 select a + 16, b + 16, c + 16 from t1; +insert into t1 select a, b + 32, c + 32 from t1; +insert into t1 select a, b + 64, c + 64 from t1; +insert into t1 select a, b + 128, c + 128 from t1; +flush tables; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +select a, b, c from t1 where a = '10' and b <> '100' order by c desc limit 5; +select a, c from t1 where a = '10' order by b desc limit 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TEXT_PK_TABLES1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + DROP DATABASE IF EXISTS auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source slave_test_deinit.inc +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/test_deinit.inc b/storage/spider/mysql-test/spider/t/test_deinit.inc new file mode 100644 index 00000000000..989bde26d3c --- /dev/null +++ b/storage/spider/mysql-test/spider/t/test_deinit.inc @@ -0,0 +1,37 @@ +# get connection and exist engine test +--echo for master_1 +--connection master_1 +--source ../include/deinit_master_1.inc +--disconnect master_1 +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --connection child2_1 + --source ../include/deinit_child2_1.inc + --disconnect child2_1 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --echo child2_3 + --connection child2_3 + --source ../include/deinit_child2_3.inc + --disconnect child2_3 +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --connection child3_1 + --source ../include/deinit_child3_1.inc + --disconnect child3_1 + --echo child3_2 + --connection child3_2 + --source ../include/deinit_child3_2.inc + --disconnect child3_2 + --echo child3_3 + --connection child3_3 + --source ../include/deinit_child3_3.inc + --disconnect child3_3 +} diff --git a/storage/spider/mysql-test/spider/t/test_init.inc b/storage/spider/mysql-test/spider/t/test_init.inc new file mode 100644 index 00000000000..f2cd6c0269f --- /dev/null +++ b/storage/spider/mysql-test/spider/t/test_init.inc @@ -0,0 +1,74 @@ +# get connection and exist engine test +--echo for master_1 +--source connect_master_1.inc +--connection master_1 +CALL mtr.add_suppression("unknown variable"); +SET SESSION sql_log_bin= 0; +--let $MASTER_1_SERVER_ID=`SELECT @@global.server_id` +--let $TEST_ENGINE_TYPE= $MASTER_1_ENGINE_TYPE +--source have_partition.inc +--source have_trigger.inc +--source ../include/init_master_1.inc +--source have_engine.inc +--echo for child2 +if ($USE_CHILD_GROUP2) +{ + --echo child2_1 + --source connect_child2_1.inc + --connection child2_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_1_ENGINE_TYPE + --source ../include/init_child2_1.inc + --source have_engine.inc + --echo child2_2 + --source connect_child2_2.inc + --connection child2_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_2_ENGINE_TYPE + --source ../include/init_child2_2.inc + --source have_engine.inc + --echo child2_3 + --source connect_child2_3.inc + --connection child2_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD2_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD2_3_ENGINE_TYPE + --source ../include/init_child2_3.inc + --source have_engine.inc +} +--echo for child3 +if ($USE_CHILD_GROUP3) +{ + --echo child3_1 + --source connect_child3_1.inc + --connection child3_1 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_1_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_1_ENGINE_TYPE + --source ../include/init_child3_1.inc + --source have_engine.inc + --echo child3_2 + --source connect_child3_2.inc + --connection child3_2 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_2_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_2_ENGINE_TYPE + --source ../include/init_child3_2.inc + --source have_engine.inc + --echo child3_3 + --source connect_child3_3.inc + --connection child3_3 + CALL mtr.add_suppression("unknown variable *"); + SET SESSION sql_log_bin= 0; + --let $CHILD3_3_SERVER_ID=`SELECT @@global.server_id` + --let $TEST_ENGINE_TYPE= $CHILD3_3_ENGINE_TYPE + --source ../include/init_child3_3.inc + --source have_engine.inc +} diff --git a/storage/spider/mysql-test/spider/t/vp_fixes.test b/storage/spider/mysql-test/spider/t/vp_fixes.test new file mode 100644 index 00000000000..46e7b0afc36 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/vp_fixes.test @@ -0,0 +1,358 @@ +# This test tests for VP's bug fixes +--let $SKIP_REASON= +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo drop and create databases +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +if ($SKIP_REASON) +{ + --echo deinit + --disable_warnings + --connection master_1 + DROP DATABASE IF EXISTS auto_test_local; + if ($USE_CHILD_GROUP2) + { + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + } + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + --skip $SKIP_REASON +} + +--echo +--echo test select 1 +--connection master_1 +SELECT 1; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + SELECT 1; + --connection child2_2 + SELECT 1; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create table and insert +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + --disable_query_log + echo CHILD2_1_DROP_TABLES; + echo CHILD2_1_CREATE_TABLES; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + if ($OUTPUT_CHILD_GROUP2) + { + --enable_query_log + } + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tb_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2; +eval CREATE TABLE tb_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET2; +--enable_query_log +INSERT INTO tb_l (a, b, c) VALUES + (1, 'a', '2008-08-01 10:21:39'), + (2, 'b', '2000-01-01 00:00:00'), + (3, 'e', '2007-06-04 20:03:11'), + (4, 'd', '2003-11-30 05:01:03'), + (5, 'c', '2001-12-31 23:59:59'); +--disable_warnings +DROP TABLE IF EXISTS ta_l; +--enable_warnings +--disable_query_log +echo CREATE TABLE ta_l ( + PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE ta_l ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO ta_l SELECT a, b, c FROM tb_l; + +--echo +--echo 0.9 +--echo create different primary key table +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT AUTO_INCREMENT, + c INT DEFAULT 11, + PRIMARY KEY(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--let $MASTER_1_IS_VP= `SELECT IF('$MASTER_1_ENGINE_TYPE' = 'VP', 1, 0)` +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo create un-correspond primary key table +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS ta_l_int; +--enable_warnings +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_result_log + } + --disable_query_log + --connection child2_1 + if ($OUTPUT_CHILD_GROUP2) + { + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES5; + --enable_query_log + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_result_log + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT4_2_1; +eval CREATE TABLE ta_l_int ( + a INT DEFAULT 10, + b INT DEFAULT 12, + c INT DEFAULT 11, + PRIMARY KEY(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT4_2_1; +--enable_query_log +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +if ($MASTER_1_IS_VP) +{ + --error 14514 + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +} +if (!$MASTER_1_IS_VP) +{ + INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + --disable_query_log + --disable_result_log + TRUNCATE TABLE ta_l_int; + --enable_query_log + --enable_result_log +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE argument LIKE '%insert %'; + } + eval $CHILD2_1_SELECT_TABLES5; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS auto_test_remote; + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; +} +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings +--echo +--echo end of test diff --git a/storage/spider/plug.in b/storage/spider/plug.in new file mode 100644 index 00000000000..7bbfff37688 --- /dev/null +++ b/storage/spider/plug.in @@ -0,0 +1,6 @@ +MYSQL_STORAGE_ENGINE(spider,,[Spider Storage Engine], + [Access transactional/nontransactional objects on remote servers], + [max,max-no-ndb]) +MYSQL_PLUGIN_DIRECTORY(spider, [storage/spider]) +MYSQL_PLUGIN_STATIC(spider, [libspider.a]) +MYSQL_PLUGIN_DYNAMIC(spider, [ha_spider.la]) diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc new file mode 100644 index 00000000000..13003207f9b --- /dev/null +++ b/storage/spider/spd_conn.cc @@ -0,0 +1,3988 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "tztime.h" +#endif +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_table.h" +#include "spd_direct_sql.h" +#include "spd_ping_table.h" +#include "spd_malloc.h" + +extern ulong *spd_db_att_thread_id; + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +pthread_mutex_t spider_conn_id_mutex; +ulonglong spider_conn_id = 1; + +#ifndef WITHOUT_SPIDER_BG_SEARCH +extern pthread_attr_t spider_pt_attr; + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key spd_key_mutex_mta_conn; +#ifndef WITHOUT_SPIDER_BG_SEARCH +extern PSI_mutex_key spd_key_mutex_bg_conn_chain; +extern PSI_mutex_key spd_key_mutex_bg_conn_sync; +extern PSI_mutex_key spd_key_mutex_bg_conn; +extern PSI_mutex_key spd_key_mutex_bg_job_stack; +extern PSI_mutex_key spd_key_mutex_bg_mon; +extern PSI_cond_key spd_key_cond_bg_conn_sync; +extern PSI_cond_key spd_key_cond_bg_conn; +extern PSI_cond_key spd_key_cond_bg_sts; +extern PSI_cond_key spd_key_cond_bg_sts_sync; +extern PSI_cond_key spd_key_cond_bg_crd; +extern PSI_cond_key spd_key_cond_bg_crd_sync; +extern PSI_cond_key spd_key_cond_bg_mon; +extern PSI_thread_key spd_key_thd_bg; +extern PSI_thread_key spd_key_thd_bg_sts; +extern PSI_thread_key spd_key_thd_bg_crd; +extern PSI_thread_key spd_key_thd_bg_mon; +#endif +#endif + +extern pthread_mutex_t spider_global_trx_mutex; +extern SPIDER_TRX *spider_global_trx; +#endif + +HASH spider_open_connections; +uint spider_open_connections_id; +const char *spider_open_connections_func_name; +const char *spider_open_connections_file_name; +ulong spider_open_connections_line_no; +pthread_mutex_t spider_conn_mutex; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +HASH spider_hs_r_conn_hash; +uint spider_hs_r_conn_hash_id; +const char *spider_hs_r_conn_hash_func_name; +const char *spider_hs_r_conn_hash_file_name; +ulong spider_hs_r_conn_hash_line_no; +pthread_mutex_t spider_hs_r_conn_mutex; +HASH spider_hs_w_conn_hash; +uint spider_hs_w_conn_hash_id; +const char *spider_hs_w_conn_hash_func_name; +const char *spider_hs_w_conn_hash_file_name; +ulong spider_hs_w_conn_hash_line_no; +pthread_mutex_t spider_hs_w_conn_mutex; +#endif + +/* for spider_open_connections and trx_conn_hash */ +uchar *spider_conn_get_key( + SPIDER_CONN *conn, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_conn_get_key"); + *length = conn->conn_key_length; + DBUG_PRINT("info",("spider conn_kind=%u", conn->conn_kind)); +#ifndef DBUG_OFF + spider_print_keys(conn->conn_key, conn->conn_key_length); +#endif + DBUG_RETURN((uchar*) conn->conn_key); +} + +int spider_reset_conn_setted_parameter( + SPIDER_CONN *conn, + THD *thd +) { + DBUG_ENTER("spider_reset_conn_setted_parameter"); + conn->autocommit = spider_param_remote_autocommit(); + conn->sql_log_off = spider_param_remote_sql_log_off(); + if (thd && spider_param_remote_time_zone()) + { + int tz_length = strlen(spider_param_remote_time_zone()); + String tz_str(spider_param_remote_time_zone(), tz_length, + &my_charset_latin1); + conn->time_zone = my_tz_find(thd, &tz_str); + } else + conn->time_zone = NULL; + conn->trx_isolation = spider_param_remote_trx_isolation(); + DBUG_PRINT("info",("spider conn->trx_isolation=%d", conn->trx_isolation)); + if (spider_param_remote_access_charset()) + { + if (!(conn->access_charset = + get_charset_by_csname(spider_param_remote_access_charset(), + MY_CS_PRIMARY, MYF(MY_WME)))) + DBUG_RETURN(ER_UNKNOWN_CHARACTER_SET); + } else + conn->access_charset = NULL; + char *default_database = spider_param_remote_default_database(); + if (default_database) + { + uint default_database_length = strlen(default_database); + if (conn->default_database.reserve(default_database_length + 1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + conn->default_database.q_append(default_database, + default_database_length + 1); + conn->default_database.length(default_database_length); + } else + conn->default_database.length(0); + DBUG_RETURN(0); +} + +int spider_free_conn_alloc( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_free_conn_alloc"); + spider_db_disconnect(conn); +#ifndef WITHOUT_SPIDER_BG_SEARCH + spider_free_conn_thread(conn); +#endif + if (conn->db_conn) + { + delete conn->db_conn; + conn->db_conn = NULL; + } + DBUG_ASSERT(!conn->mta_conn_mutex_file_pos.file_name); + pthread_mutex_destroy(&conn->mta_conn_mutex); + conn->default_database.free(); + DBUG_RETURN(0); +} + +void spider_free_conn_from_trx( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + bool another, + bool trx_free, + int *roop_count +) { + ha_spider *spider; + DBUG_ENTER("spider_free_conn_from_trx"); + spider_conn_clear_queue(conn); + conn->use_for_active_standby = FALSE; + conn->error_mode = 1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if ( + trx_free || + ( + ( + conn->server_lost || + spider_param_conn_recycle_mode(trx->thd) != 2 + ) && + !conn->opened_handlers + ) + ) { + conn->thd = NULL; + if (another) + { + ha_spider *next_spider; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_another_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_another_conn_hash, (uchar*) conn); +#endif + spider = (ha_spider*) conn->another_ha_first; + while (spider) + { + next_spider = spider->next; + spider_free_tmp_dbton_handler(spider); + spider_free_tmp_dbton_share(spider->share); + spider_free_tmp_share_alloc(spider->share); + spider_free(spider_current_trx, spider->share, MYF(0)); + delete spider; + spider = next_spider; + } + conn->another_ha_first = NULL; + conn->another_ha_last = NULL; + } else { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_conn_hash, (uchar*) conn); +#endif + } + + if ( + !trx_free && + !conn->server_lost && + !conn->queued_connect && + spider_param_conn_recycle_mode(trx->thd) == 1 + ) { + /* conn_recycle_mode == 1 */ + *conn->conn_key = '0'; + if ( + conn->quick_target && + spider_db_free_result((ha_spider *) conn->quick_target, FALSE) + ) { + spider_free_conn(conn); + } else { + pthread_mutex_lock(&spider_conn_mutex); + uint old_elements = spider_open_connections.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_open_connections, + conn->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&spider_open_connections, (uchar*) conn)) +#endif + { + pthread_mutex_unlock(&spider_conn_mutex); + spider_free_conn(conn); + } else { + if (spider_open_connections.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_open_connections, + (spider_open_connections.array.max_element - old_elements) * + spider_open_connections.array.size_of_element); + } + pthread_mutex_unlock(&spider_conn_mutex); + } + } + } else { + /* conn_recycle_mode == 0 */ + spider_free_conn(conn); + } + } else if (roop_count) + (*roop_count)++; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn->conn_kind == SPIDER_CONN_KIND_HS_READ) + { + spider_db_hs_request_buf_reset(conn); + if ( + trx_free || + ( + ( + conn->server_lost || + spider_param_hs_r_conn_recycle_mode(trx->thd) != 2 + ) && + !conn->opened_handlers + ) + ) { + conn->thd = NULL; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_hs_r_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_hs_r_conn_hash, (uchar*) conn); +#endif + + DBUG_ASSERT(conn->opened_handlers == + conn->db_conn->get_opened_handler_count()); + if (conn->db_conn->get_opened_handler_count()) + { + conn->db_conn->reset_opened_handler(); + } + + if ( + !trx_free && + !conn->server_lost && + !conn->queued_connect && + spider_param_hs_r_conn_recycle_mode(trx->thd) == 1 + ) { + /* conn_recycle_mode == 1 */ + *conn->conn_key = '0'; + pthread_mutex_lock(&spider_hs_r_conn_mutex); + uint old_elements = spider_hs_r_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_hs_r_conn_hash, + conn->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&spider_hs_r_conn_hash, (uchar*) conn)) +#endif + { + pthread_mutex_unlock(&spider_hs_r_conn_mutex); + spider_free_conn(conn); + } else { + if (spider_hs_r_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_hs_r_conn_hash, + (spider_hs_r_conn_hash.array.max_element - old_elements) * + spider_hs_r_conn_hash.array.size_of_element); + } + pthread_mutex_unlock(&spider_hs_r_conn_mutex); + } + } else { + /* conn_recycle_mode == 0 */ + spider_free_conn(conn); + } + } else if (roop_count) + (*roop_count)++; + } else { + spider_db_hs_request_buf_reset(conn); + if ( + trx_free || + ( + ( + conn->server_lost || + spider_param_hs_w_conn_recycle_mode(trx->thd) != 2 + ) && + !conn->opened_handlers + ) + ) { + conn->thd = NULL; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_hs_w_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_hs_w_conn_hash, (uchar*) conn); +#endif + + DBUG_ASSERT(conn->opened_handlers == + conn->db_conn->get_opened_handler_count()); + if (conn->db_conn->get_opened_handler_count()) + { + conn->db_conn->reset_opened_handler(); + } + + if ( + !trx_free && + !conn->server_lost && + !conn->queued_connect && + spider_param_hs_w_conn_recycle_mode(trx->thd) == 1 + ) { + /* conn_recycle_mode == 1 */ + *conn->conn_key = '0'; + pthread_mutex_lock(&spider_hs_w_conn_mutex); + uint old_elements = spider_hs_w_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_hs_w_conn_hash, + conn->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&spider_hs_w_conn_hash, (uchar*) conn)) +#endif + { + pthread_mutex_unlock(&spider_hs_w_conn_mutex); + spider_free_conn(conn); + } else { + if (spider_hs_w_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_hs_w_conn_hash, + (spider_hs_w_conn_hash.array.max_element - old_elements) * + spider_hs_w_conn_hash.array.size_of_element); + } + pthread_mutex_unlock(&spider_hs_w_conn_mutex); + } + } else { + /* conn_recycle_mode == 0 */ + spider_free_conn(conn); + } + } else if (roop_count) + (*roop_count)++; + } +#endif + DBUG_VOID_RETURN; +} + +SPIDER_CONN *spider_create_conn( + SPIDER_SHARE *share, + ha_spider *spider, + int link_idx, + int base_link_idx, + uint conn_kind, + int *error_num +) { + int *need_mon; + SPIDER_CONN *conn; + char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket; + char *tmp_wrapper, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert; + char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group; + DBUG_ENTER("spider_create_conn"); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 18, MYF(MY_WME | MY_ZEROFILL), + &conn, sizeof(*conn), + &tmp_name, share->conn_keys_lengths[link_idx] + 1, + &tmp_host, share->tgt_hosts_lengths[link_idx] + 1, + &tmp_username, + share->tgt_usernames_lengths[link_idx] + 1, + &tmp_password, + share->tgt_passwords_lengths[link_idx] + 1, + &tmp_socket, share->tgt_sockets_lengths[link_idx] + 1, + &tmp_wrapper, + share->tgt_wrappers_lengths[link_idx] + 1, + &tmp_ssl_ca, share->tgt_ssl_cas_lengths[link_idx] + 1, + &tmp_ssl_capath, + share->tgt_ssl_capaths_lengths[link_idx] + 1, + &tmp_ssl_cert, + share->tgt_ssl_certs_lengths[link_idx] + 1, + &tmp_ssl_cipher, + share->tgt_ssl_ciphers_lengths[link_idx] + 1, + &tmp_ssl_key, + share->tgt_ssl_keys_lengths[link_idx] + 1, + &tmp_default_file, + share->tgt_default_files_lengths[link_idx] + 1, + &tmp_default_group, + share->tgt_default_groups_lengths[link_idx] + 1, + &need_mon, sizeof(int), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + + conn->default_database.init_calc_mem(75); + conn->conn_key_length = share->conn_keys_lengths[link_idx]; + conn->conn_key = tmp_name; + memcpy(conn->conn_key, share->conn_keys[link_idx], + share->conn_keys_lengths[link_idx]); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + conn->conn_key_hash_value = share->conn_keys_hash_value[link_idx]; +#endif + conn->tgt_host_length = share->tgt_hosts_lengths[link_idx]; + conn->tgt_host = tmp_host; + memcpy(conn->tgt_host, share->tgt_hosts[link_idx], + share->tgt_hosts_lengths[link_idx]); + conn->tgt_username_length = share->tgt_usernames_lengths[link_idx]; + conn->tgt_username = tmp_username; + memcpy(conn->tgt_username, share->tgt_usernames[link_idx], + share->tgt_usernames_lengths[link_idx]); + conn->tgt_password_length = share->tgt_passwords_lengths[link_idx]; + conn->tgt_password = tmp_password; + memcpy(conn->tgt_password, share->tgt_passwords[link_idx], + share->tgt_passwords_lengths[link_idx]); + conn->tgt_socket_length = share->tgt_sockets_lengths[link_idx]; + conn->tgt_socket = tmp_socket; + memcpy(conn->tgt_socket, share->tgt_sockets[link_idx], + share->tgt_sockets_lengths[link_idx]); + conn->tgt_wrapper_length = share->tgt_wrappers_lengths[link_idx]; + conn->tgt_wrapper = tmp_wrapper; + memcpy(conn->tgt_wrapper, share->tgt_wrappers[link_idx], + share->tgt_wrappers_lengths[link_idx]); + conn->tgt_ssl_ca_length = share->tgt_ssl_cas_lengths[link_idx]; + if (conn->tgt_ssl_ca_length) + { + conn->tgt_ssl_ca = tmp_ssl_ca; + memcpy(conn->tgt_ssl_ca, share->tgt_ssl_cas[link_idx], + share->tgt_ssl_cas_lengths[link_idx]); + } else + conn->tgt_ssl_ca = NULL; + conn->tgt_ssl_capath_length = share->tgt_ssl_capaths_lengths[link_idx]; + if (conn->tgt_ssl_capath_length) + { + conn->tgt_ssl_capath = tmp_ssl_capath; + memcpy(conn->tgt_ssl_capath, share->tgt_ssl_capaths[link_idx], + share->tgt_ssl_capaths_lengths[link_idx]); + } else + conn->tgt_ssl_capath = NULL; + conn->tgt_ssl_cert_length = share->tgt_ssl_certs_lengths[link_idx]; + if (conn->tgt_ssl_cert_length) + { + conn->tgt_ssl_cert = tmp_ssl_cert; + memcpy(conn->tgt_ssl_cert, share->tgt_ssl_certs[link_idx], + share->tgt_ssl_certs_lengths[link_idx]); + } else + conn->tgt_ssl_cert = NULL; + conn->tgt_ssl_cipher_length = share->tgt_ssl_ciphers_lengths[link_idx]; + if (conn->tgt_ssl_cipher_length) + { + conn->tgt_ssl_cipher = tmp_ssl_cipher; + memcpy(conn->tgt_ssl_cipher, share->tgt_ssl_ciphers[link_idx], + share->tgt_ssl_ciphers_lengths[link_idx]); + } else + conn->tgt_ssl_cipher = NULL; + conn->tgt_ssl_key_length = share->tgt_ssl_keys_lengths[link_idx]; + if (conn->tgt_ssl_key_length) + { + conn->tgt_ssl_key = tmp_ssl_key; + memcpy(conn->tgt_ssl_key, share->tgt_ssl_keys[link_idx], + share->tgt_ssl_keys_lengths[link_idx]); + } else + conn->tgt_ssl_key = NULL; + conn->tgt_default_file_length = share->tgt_default_files_lengths[link_idx]; + if (conn->tgt_default_file_length) + { + conn->tgt_default_file = tmp_default_file; + memcpy(conn->tgt_default_file, share->tgt_default_files[link_idx], + share->tgt_default_files_lengths[link_idx]); + } else + conn->tgt_default_file = NULL; + conn->tgt_default_group_length = + share->tgt_default_groups_lengths[link_idx]; + if (conn->tgt_default_group_length) + { + conn->tgt_default_group = tmp_default_group; + memcpy(conn->tgt_default_group, share->tgt_default_groups[link_idx], + share->tgt_default_groups_lengths[link_idx]); + } else + conn->tgt_default_group = NULL; + conn->tgt_port = share->tgt_ports[link_idx]; + conn->tgt_ssl_vsc = share->tgt_ssl_vscs[link_idx]; + conn->dbton_id = share->sql_dbton_ids[link_idx]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) { + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 19, MYF(MY_WME | MY_ZEROFILL), + &conn, sizeof(*conn), + &tmp_name, share->hs_read_conn_keys_lengths[link_idx] + 1, + &tmp_host, share->tgt_hosts_lengths[link_idx] + 1, + &tmp_socket, share->hs_read_socks_lengths[link_idx] + 1, + &tmp_wrapper, + share->tgt_wrappers_lengths[link_idx] + 1, + &need_mon, sizeof(int), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + + conn->default_database.init_calc_mem(76); + conn->conn_key_length = share->hs_read_conn_keys_lengths[link_idx]; + conn->conn_key = tmp_name; + memcpy(conn->conn_key, share->hs_read_conn_keys[link_idx], + share->hs_read_conn_keys_lengths[link_idx]); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + conn->conn_key_hash_value = share->hs_read_conn_keys_hash_value[link_idx]; +#endif + conn->tgt_host_length = share->tgt_hosts_lengths[link_idx]; + conn->tgt_host = tmp_host; + memcpy(conn->tgt_host, share->tgt_hosts[link_idx], + share->tgt_hosts_lengths[link_idx]); + conn->hs_sock_length = share->hs_read_socks_lengths[link_idx]; + if (conn->hs_sock_length) + { + conn->hs_sock = tmp_socket; + memcpy(conn->hs_sock, share->hs_read_socks[link_idx], + share->hs_read_socks_lengths[link_idx]); + } else + conn->hs_sock = NULL; + conn->tgt_wrapper_length = share->tgt_wrappers_lengths[link_idx]; + conn->tgt_wrapper = tmp_wrapper; + memcpy(conn->tgt_wrapper, share->tgt_wrappers[link_idx], + share->tgt_wrappers_lengths[link_idx]); + conn->hs_port = share->hs_read_ports[link_idx]; + conn->dbton_id = share->hs_dbton_ids[link_idx]; + } else { + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 20, MYF(MY_WME | MY_ZEROFILL), + &conn, sizeof(*conn), + &tmp_name, share->hs_write_conn_keys_lengths[link_idx] + 1, + &tmp_host, share->tgt_hosts_lengths[link_idx] + 1, + &tmp_socket, share->hs_write_socks_lengths[link_idx] + 1, + &tmp_wrapper, + share->tgt_wrappers_lengths[link_idx] + 1, + &need_mon, sizeof(int), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + + conn->default_database.init_calc_mem(77); + conn->conn_key_length = share->hs_write_conn_keys_lengths[link_idx]; + conn->conn_key = tmp_name; + memcpy(conn->conn_key, share->hs_write_conn_keys[link_idx], + share->hs_write_conn_keys_lengths[link_idx]); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + conn->conn_key_hash_value = share->hs_write_conn_keys_hash_value[link_idx]; +#endif + conn->tgt_host_length = share->tgt_hosts_lengths[link_idx]; + conn->tgt_host = tmp_host; + memcpy(conn->tgt_host, share->tgt_hosts[link_idx], + share->tgt_hosts_lengths[link_idx]); + conn->hs_sock_length = share->hs_write_socks_lengths[link_idx]; + if (conn->hs_sock_length) + { + conn->hs_sock = tmp_socket; + memcpy(conn->hs_sock, share->hs_write_socks[link_idx], + share->hs_write_socks_lengths[link_idx]); + } else + conn->hs_sock = NULL; + conn->tgt_wrapper_length = share->tgt_wrappers_lengths[link_idx]; + conn->tgt_wrapper = tmp_wrapper; + memcpy(conn->tgt_wrapper, share->tgt_wrappers[link_idx], + share->tgt_wrappers_lengths[link_idx]); + conn->hs_port = share->hs_write_ports[link_idx]; + conn->dbton_id = share->hs_dbton_ids[link_idx]; + } +#endif + if (!(conn->db_conn = spider_dbton[conn->dbton_id].create_db_conn(conn))) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_db_conn_create; + } + if ((*error_num = conn->db_conn->init())) + { + goto error_db_conn_init; + } + conn->join_trx = 0; + conn->thd = NULL; + conn->table_lock = 0; + conn->semi_trx_isolation = -2; + conn->semi_trx_isolation_chk = FALSE; + conn->semi_trx_chk = FALSE; + conn->link_idx = base_link_idx; + conn->conn_kind = conn_kind; + conn->conn_need_mon = need_mon; + if (spider) + conn->need_mon = &spider->need_mons[base_link_idx]; + else + conn->need_mon = need_mon; + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, + MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_mta_conn_mutex_init; + } + + spider_conn_queue_connect(share, conn, link_idx); + conn->ping_time = (time_t) time((time_t*) 0); + pthread_mutex_lock(&spider_conn_id_mutex); + conn->conn_id = spider_conn_id; + ++spider_conn_id; + pthread_mutex_unlock(&spider_conn_id_mutex); + + DBUG_RETURN(conn); + +/* +error_init_lock_table_hash: + DBUG_ASSERT(!conn->mta_conn_mutex_file_pos.file_name); + pthread_mutex_destroy(&conn->mta_conn_mutex); +*/ +error_mta_conn_mutex_init: +error_db_conn_init: + delete conn->db_conn; +error_db_conn_create: + spider_free(spider_current_trx, conn, MYF(0)); +error_alloc_conn: + DBUG_RETURN(NULL); +} + +SPIDER_CONN *spider_get_conn( + SPIDER_SHARE *share, + int link_idx, + char *conn_key, + SPIDER_TRX *trx, + ha_spider *spider, + bool another, + bool thd_chg, + uint conn_kind, + int *error_num +) { + SPIDER_CONN *conn = NULL; + int base_link_idx = link_idx; + DBUG_ENTER("spider_get_conn"); + DBUG_PRINT("info",("spider conn_kind=%u", conn_kind)); + + if (spider) + link_idx = spider->conn_link_idx[base_link_idx]; + DBUG_PRINT("info",("spider link_idx=%u", link_idx)); + DBUG_PRINT("info",("spider base_link_idx=%u", base_link_idx)); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif +#ifndef DBUG_OFF + spider_print_keys(conn_key, share->conn_keys_lengths[link_idx]); +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) + { + conn_key = share->hs_read_conn_keys[link_idx]; +#ifndef DBUG_OFF + spider_print_keys(conn_key, share->hs_read_conn_keys_lengths[link_idx]); +#endif + } else { + conn_key = share->hs_write_conn_keys[link_idx]; +#ifndef DBUG_OFF + spider_print_keys(conn_key, share->hs_write_conn_keys_lengths[link_idx]); +#endif + } +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (conn_kind == SPIDER_CONN_KIND_MYSQL && + ( +#endif + (another && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_another_conn_hash, + share->conn_keys_hash_value[link_idx], + (uchar*) conn_key, share->conn_keys_lengths[link_idx]))) || + (!another && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_conn_hash, + share->conn_keys_hash_value[link_idx], + (uchar*) conn_key, share->conn_keys_lengths[link_idx]))) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_READ && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_hs_r_conn_hash, + share->hs_read_conn_keys_hash_value[link_idx], + (uchar*) conn_key, share->hs_read_conn_keys_lengths[link_idx])) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_WRITE && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_hs_w_conn_hash, + share->hs_write_conn_keys_hash_value[link_idx], + (uchar*) conn_key, share->hs_write_conn_keys_lengths[link_idx])) + ) +#endif + ) +#else + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (conn_kind == SPIDER_CONN_KIND_MYSQL && + ( +#endif + (another && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_another_conn_hash, + (uchar*) conn_key, share->conn_keys_lengths[link_idx]))) || + (!another && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_conn_hash, + (uchar*) conn_key, share->conn_keys_lengths[link_idx]))) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_READ && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_hs_r_conn_hash, + (uchar*) conn_key, share->hs_read_conn_keys_lengths[link_idx])) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_WRITE && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_hs_w_conn_hash, + (uchar*) conn_key, share->hs_write_conn_keys_lengths[link_idx])) + ) +#endif + ) +#endif + { + if ( + !trx->thd || +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (conn_kind == SPIDER_CONN_KIND_MYSQL && +#endif + ( + (spider_param_conn_recycle_mode(trx->thd) & 1) || + spider_param_conn_recycle_strict(trx->thd) + ) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_READ && + ( + (spider_param_hs_r_conn_recycle_mode(trx->thd) & 1) || + spider_param_hs_r_conn_recycle_strict(trx->thd) + ) + ) || + (conn_kind == SPIDER_CONN_KIND_HS_WRITE && + ( + (spider_param_hs_w_conn_recycle_mode(trx->thd) & 1) || + spider_param_hs_w_conn_recycle_strict(trx->thd) + ) + ) +#endif + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + pthread_mutex_lock(&spider_conn_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &spider_open_connections, share->conn_keys_hash_value[link_idx], + (uchar*) share->conn_keys[link_idx], + share->conn_keys_lengths[link_idx]))) +#else + if (!(conn = (SPIDER_CONN*) my_hash_search(&spider_open_connections, + (uchar*) share->conn_keys[link_idx], + share->conn_keys_lengths[link_idx]))) +#endif + { + pthread_mutex_unlock(&spider_conn_mutex); + DBUG_PRINT("info",("spider create new conn")); + if (!(conn = spider_create_conn(share, spider, link_idx, + base_link_idx, conn_kind, error_num))) + goto error; + *conn->conn_key = *conn_key; + if (spider) + { + spider->conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } else { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_open_connections, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_open_connections, (uchar*) conn); +#endif + pthread_mutex_unlock(&spider_conn_mutex); + DBUG_PRINT("info",("spider get global conn")); + if (spider) + { + spider->conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) + { + pthread_mutex_lock(&spider_hs_r_conn_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &spider_hs_r_conn_hash, + share->hs_read_conn_keys_hash_value[link_idx], + (uchar*) share->hs_read_conn_keys[link_idx], + share->hs_read_conn_keys_lengths[link_idx]))) +#else + if (!(conn = (SPIDER_CONN*) my_hash_search(&spider_hs_r_conn_hash, + (uchar*) share->hs_read_conn_keys[link_idx], + share->hs_read_conn_keys_lengths[link_idx]))) +#endif + { + pthread_mutex_unlock(&spider_hs_r_conn_mutex); + DBUG_PRINT("info",("spider create new hs r conn")); + if (!(conn = spider_create_conn(share, spider, link_idx, + base_link_idx, conn_kind, error_num))) + goto error; + *conn->conn_key = *conn_key; + if (spider) + { + spider->hs_r_conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } else { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_hs_r_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_hs_r_conn_hash, (uchar*) conn); +#endif + pthread_mutex_unlock(&spider_hs_r_conn_mutex); + DBUG_PRINT("info",("spider get global hs r conn")); + if (spider) + { + spider->hs_r_conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } + } else { + pthread_mutex_lock(&spider_hs_w_conn_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &spider_hs_w_conn_hash, + share->hs_write_conn_keys_hash_value[link_idx], + (uchar*) share->hs_write_conn_keys[link_idx], + share->hs_write_conn_keys_lengths[link_idx]))) +#else + if (!(conn = (SPIDER_CONN*) my_hash_search(&spider_hs_w_conn_hash, + (uchar*) share->hs_write_conn_keys[link_idx], + share->hs_write_conn_keys_lengths[link_idx]))) +#endif + { + pthread_mutex_unlock(&spider_hs_w_conn_mutex); + DBUG_PRINT("info",("spider create new hs w conn")); + if (!(conn = spider_create_conn(share, spider, link_idx, + base_link_idx, conn_kind, error_num))) + goto error; + *conn->conn_key = *conn_key; + if (spider) + { + spider->hs_w_conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } else { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_hs_w_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_hs_w_conn_hash, (uchar*) conn); +#endif + pthread_mutex_unlock(&spider_hs_w_conn_mutex); + DBUG_PRINT("info",("spider get global hs w conn")); + if (spider) + { + spider->hs_w_conns[base_link_idx] = conn; + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } + } +#endif + } else { + DBUG_PRINT("info",("spider create new conn")); + /* conn_recycle_strict = 0 and conn_recycle_mode = 0 or 2 */ + if (!(conn = spider_create_conn(share, spider, link_idx, base_link_idx, + conn_kind, error_num))) + goto error; + *conn->conn_key = *conn_key; + if (spider) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + spider->conns[base_link_idx] = conn; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) + { + spider->hs_r_conns[base_link_idx] = conn; + } else { + spider->hs_w_conns[base_link_idx] = conn; + } +#endif + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + } + conn->thd = trx->thd; + conn->priority = share->priority; + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (another) + { + uint old_elements = trx->trx_another_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_another_conn_hash, + share->conn_keys_hash_value[link_idx], + (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_another_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_another_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_another_conn_hash, + (trx->trx_another_conn_hash.array.max_element - old_elements) * + trx->trx_another_conn_hash.array.size_of_element); + } + } else { + uint old_elements = trx->trx_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_conn_hash, + share->conn_keys_hash_value[link_idx], + (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_conn_hash, + (trx->trx_conn_hash.array.max_element - old_elements) * + trx->trx_conn_hash.array.size_of_element); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) + { + uint old_elements = trx->trx_hs_r_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_hs_r_conn_hash, + share->hs_read_conn_keys_hash_value[link_idx], + (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_hs_r_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_hs_r_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_hs_r_conn_hash, + (trx->trx_hs_r_conn_hash.array.max_element - old_elements) * + trx->trx_hs_r_conn_hash.array.size_of_element); + } + } else { + uint old_elements = trx->trx_hs_w_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_hs_w_conn_hash, + share->hs_write_conn_keys_hash_value[link_idx], + (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_hs_w_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_hs_w_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_hs_w_conn_hash, + (trx->trx_hs_w_conn_hash.array.max_element - old_elements) * + trx->trx_hs_w_conn_hash.array.size_of_element); + } + } +#endif + } else if (spider) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + spider->conns[base_link_idx] = conn; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn_kind == SPIDER_CONN_KIND_HS_READ) + { + spider->hs_r_conns[base_link_idx] = conn; + } else { + spider->hs_w_conns[base_link_idx] = conn; + } +#endif + if (spider_bit_is_set(spider->conn_can_fo, base_link_idx)) + conn->use_for_active_standby = TRUE; + } + conn->link_idx = base_link_idx; + + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_RETURN(conn); + +error: + DBUG_RETURN(NULL); +} + +int spider_free_conn( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_free_conn"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + spider_free_conn_alloc(conn); + spider_free(spider_current_trx, conn, MYF(0)); + DBUG_RETURN(0); +} + +void spider_conn_queue_connect( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_conn_queue_connect"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_connect = TRUE; + conn->queued_connect_share = share; + conn->queued_connect_link_idx = link_idx; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_connect_rewrite( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_conn_queue_connect_rewrite"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_connect_share = share; + conn->queued_connect_link_idx = link_idx; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_ping( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_conn_queue_ping"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_ping = TRUE; + conn->queued_ping_spider = spider; + conn->queued_ping_link_idx = link_idx; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation +) { + DBUG_ENTER("spider_conn_queue_trx_isolation"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_trx_isolation = TRUE; + conn->queued_trx_isolation_val = trx_isolation; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_semi_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation +) { + DBUG_ENTER("spider_conn_queue_semi_trx_isolation"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_semi_trx_isolation = TRUE; + conn->queued_semi_trx_isolation_val = trx_isolation; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_autocommit( + SPIDER_CONN *conn, + bool autocommit +) { + DBUG_ENTER("spider_conn_queue_autocommit"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_autocommit = TRUE; + conn->queued_autocommit_val = autocommit; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_sql_log_off( + SPIDER_CONN *conn, + bool sql_log_off +) { + DBUG_ENTER("spider_conn_queue_sql_log_off"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_sql_log_off = TRUE; + conn->queued_sql_log_off_val = sql_log_off; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_time_zone( + SPIDER_CONN *conn, + Time_zone *time_zone +) { + DBUG_ENTER("spider_conn_queue_time_zone"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_time_zone = TRUE; + conn->queued_time_zone_val = time_zone; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_start_transaction( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_conn_queue_start_transaction"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_trx_start = TRUE; + conn->trx_start = TRUE; + DBUG_VOID_RETURN; +} + +void spider_conn_queue_xa_start( + SPIDER_CONN *conn, + XID *xid +) { + DBUG_ENTER("spider_conn_queue_xa_start"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_xa_start = TRUE; + conn->queued_xa_start_xid = xid; + DBUG_VOID_RETURN; +} + +void spider_conn_clear_queue( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_conn_clear_queue"); + DBUG_PRINT("info", ("spider conn=%p", conn)); +/* + conn->queued_connect = FALSE; +*/ + conn->queued_ping = FALSE; + conn->queued_trx_isolation = FALSE; + conn->queued_semi_trx_isolation = FALSE; + conn->queued_autocommit = FALSE; + conn->queued_sql_log_off = FALSE; + conn->queued_time_zone = FALSE; + conn->queued_trx_start = FALSE; + conn->queued_xa_start = FALSE; + DBUG_VOID_RETURN; +} + +void spider_conn_clear_queue_at_commit( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_conn_clear_queue_at_commit"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + conn->queued_trx_start = FALSE; + conn->queued_xa_start = FALSE; + DBUG_VOID_RETURN; +} + +void spider_conn_set_timeout( + SPIDER_CONN *conn, + uint net_read_timeout, + uint net_write_timeout +) { + DBUG_ENTER("spider_conn_set_timeout"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + if (net_read_timeout != conn->net_read_timeout) + { + DBUG_PRINT("info",("spider net_read_timeout set from %u to %u", + conn->net_read_timeout, net_read_timeout)); + conn->queued_net_timeout = TRUE; + conn->net_read_timeout = net_read_timeout; + } + if (net_write_timeout != conn->net_write_timeout) + { + DBUG_PRINT("info",("spider net_write_timeout set from %u to %u", + conn->net_write_timeout, net_write_timeout)); + conn->queued_net_timeout = TRUE; + conn->net_write_timeout = net_write_timeout; + } + DBUG_VOID_RETURN; +} + +void spider_conn_set_timeout_from_share( + SPIDER_CONN *conn, + int link_idx, + THD *thd, + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_conn_set_timeout_from_share"); + spider_conn_set_timeout( + conn, + spider_param_net_read_timeout(thd, share->net_read_timeouts[link_idx]), + spider_param_net_write_timeout(thd, share->net_write_timeouts[link_idx]) + ); + DBUG_VOID_RETURN; +} + +void spider_conn_set_timeout_from_direct_sql( + SPIDER_CONN *conn, + THD *thd, + SPIDER_DIRECT_SQL *direct_sql +) { + DBUG_ENTER("spider_conn_set_timeout_from_direct_sql"); + spider_conn_set_timeout( + conn, + spider_param_net_read_timeout(thd, direct_sql->net_read_timeout), + spider_param_net_write_timeout(thd, direct_sql->net_write_timeout) + ); + DBUG_VOID_RETURN; +} + +void spider_tree_insert( + SPIDER_CONN *top, + SPIDER_CONN *conn +) { + SPIDER_CONN *current = top; + longlong priority = conn->priority; + DBUG_ENTER("spider_tree_insert"); + while (TRUE) + { + if (priority < current->priority) + { + if (current->c_small == NULL) + { + conn->p_small = NULL; + conn->p_big = current; + conn->c_small = NULL; + conn->c_big = NULL; + current->c_small = conn; + break; + } else + current = current->c_small; + } else { + if (current->c_big == NULL) + { + conn->p_small = current; + conn->p_big = NULL; + conn->c_small = NULL; + conn->c_big = NULL; + current->c_big = conn; + break; + } else + current = current->c_big; + } + } + DBUG_VOID_RETURN; +} + +SPIDER_CONN *spider_tree_first( + SPIDER_CONN *top +) { + SPIDER_CONN *current = top; + DBUG_ENTER("spider_tree_first"); + while (current) + { + if (current->c_small == NULL) + break; + else + current = current->c_small; + } + DBUG_RETURN(current); +} + +SPIDER_CONN *spider_tree_last( + SPIDER_CONN *top +) { + SPIDER_CONN *current = top; + DBUG_ENTER("spider_tree_last"); + while (TRUE) + { + if (current->c_big == NULL) + break; + else + current = current->c_big; + } + DBUG_RETURN(current); +} + +SPIDER_CONN *spider_tree_next( + SPIDER_CONN *current +) { + DBUG_ENTER("spider_tree_next"); + if (current->c_big) + DBUG_RETURN(spider_tree_first(current->c_big)); + while (TRUE) + { + if (current->p_big) + DBUG_RETURN(current->p_big); + if (!current->p_small) + DBUG_RETURN(NULL); + current = current->p_small; + } +} + +SPIDER_CONN *spider_tree_delete( + SPIDER_CONN *conn, + SPIDER_CONN *top +) { + DBUG_ENTER("spider_tree_delete"); + if (conn->p_small) + { + if (conn->c_small) + { + conn->c_small->p_big = NULL; + conn->c_small->p_small = conn->p_small; + conn->p_small->c_big = conn->c_small; + if (conn->c_big) + { + SPIDER_CONN *last = spider_tree_last(conn->c_small); + conn->c_big->p_small = last; + last->c_big = conn->c_big; + } + } else if (conn->c_big) + { + conn->c_big->p_small = conn->p_small; + conn->p_small->c_big = conn->c_big; + } else + conn->p_small->c_big = NULL; + } else if (conn->p_big) + { + if (conn->c_small) + { + conn->c_small->p_big = conn->p_big; + conn->p_big->c_small = conn->c_small; + if (conn->c_big) + { + SPIDER_CONN *last = spider_tree_last(conn->c_small); + conn->c_big->p_small = last; + last->c_big = conn->c_big; + } + } else if (conn->c_big) + { + conn->c_big->p_big = conn->p_big; + conn->c_big->p_small = NULL; + conn->p_big->c_small = conn->c_big; + } else + conn->p_big->c_small = NULL; + } else { + if (conn->c_small) + { + conn->c_small->p_big = NULL; + conn->c_small->p_small = NULL; + if (conn->c_big) + { + SPIDER_CONN *last = spider_tree_last(conn->c_small); + conn->c_big->p_small = last; + last->c_big = conn->c_big; + } + DBUG_RETURN(conn->c_small); + } else if (conn->c_big) + { + conn->c_big->p_small = NULL; + DBUG_RETURN(conn->c_big); + } + DBUG_RETURN(NULL); + } + DBUG_RETURN(top); +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_set_conn_bg_param( + ha_spider *spider +) { + int error_num, roop_count, bgs_mode; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + THD *thd = spider->trx->thd; + DBUG_ENTER("spider_set_conn_bg_param"); + bgs_mode = + spider_param_bgs_mode(thd, share->bgs_mode); + if (bgs_mode == 0) + result_list->bgs_phase = 0; + else if ( + bgs_mode <= 2 && + (result_list->lock_type == F_WRLCK || spider->lock_mode == 2) + ) + result_list->bgs_phase = 0; + else if (bgs_mode <= 1 && spider->lock_mode == 1) + result_list->bgs_phase = 0; + else { + result_list->bgs_phase = 1; + + result_list->bgs_first_read = + spider_param_bgs_first_read(thd, share->bgs_first_read); + result_list->bgs_second_read = + spider_param_bgs_second_read(thd, share->bgs_second_read); + result_list->bgs_split_read = spider_bg_split_read_param(spider); + + result_list->split_read = + result_list->bgs_first_read > 0 ? + result_list->bgs_first_read : + result_list->bgs_split_read; + } + + if (result_list->bgs_phase > 0) + { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + spider->lock_mode ? + SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + spider->lock_mode ? + SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK) + ) { + if ((error_num = spider_create_conn_thread(spider->conns[roop_count]))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = spider_create_conn_thread( + spider->hs_r_conns[roop_count]))) + DBUG_RETURN(error_num); + if ((error_num = spider_create_conn_thread( + spider->hs_w_conns[roop_count]))) + DBUG_RETURN(error_num); +#endif + } + } + DBUG_RETURN(0); +} + +int spider_create_conn_thread( + SPIDER_CONN *conn +) { + int error_num; + DBUG_ENTER("spider_create_conn_thread"); + if (conn && !conn->bg_init) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_bg_conn_chain, + &conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_chain_mutex_init; + } + conn->bg_conn_chain_mutex_ptr = NULL; +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_bg_conn_sync, + &conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->bg_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_bg_conn, &conn->bg_conn_mutex, + MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->bg_job_stack_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_bg_job_stack, &conn->bg_job_stack_mutex, + MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_job_stack_mutex_init; + } + if (SPD_INIT_DYNAMIC_ARRAY2(&conn->bg_job_stack, sizeof(void *), NULL, 16, + 16, MYF(MY_WME))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_job_stack_init; + } + spider_alloc_calc_mem_init(conn->bg_job_stack, 163); + spider_alloc_calc_mem(spider_current_trx, + conn->bg_job_stack, + conn->bg_job_stack.max_element * + conn->bg_job_stack.size_of_element); + conn->bg_job_stack_cur_pos = 0; +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&conn->bg_conn_sync_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_conn_sync, + &conn->bg_conn_sync_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&conn->bg_conn_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_conn, + &conn->bg_conn_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + pthread_mutex_lock(&conn->bg_conn_mutex); +#if MYSQL_VERSION_ID < 50500 + if (pthread_create(&conn->bg_thread, &spider_pt_attr, + spider_bg_conn_action, (void *) conn) + ) +#else + if (mysql_thread_create(spd_key_thd_bg, &conn->bg_thread, + &spider_pt_attr, spider_bg_conn_action, (void *) conn) + ) +#endif + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + if (!conn->bg_init) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + } + DBUG_RETURN(0); + +error_thread_create: + pthread_cond_destroy(&conn->bg_conn_cond); +error_cond_init: + pthread_cond_destroy(&conn->bg_conn_sync_cond); +error_sync_cond_init: + spider_free_mem_calc(spider_current_trx, + conn->bg_job_stack_id, + conn->bg_job_stack.max_element * + conn->bg_job_stack.size_of_element); + delete_dynamic(&conn->bg_job_stack); +error_job_stack_init: + pthread_mutex_destroy(&conn->bg_job_stack_mutex); +error_job_stack_mutex_init: + pthread_mutex_destroy(&conn->bg_conn_mutex); +error_mutex_init: + pthread_mutex_destroy(&conn->bg_conn_sync_mutex); +error_sync_mutex_init: + pthread_mutex_destroy(&conn->bg_conn_chain_mutex); +error_chain_mutex_init: + DBUG_RETURN(error_num); +} + +void spider_free_conn_thread( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_free_conn_thread"); + if (conn->bg_init) + { + spider_bg_conn_break(conn, NULL); + pthread_mutex_lock(&conn->bg_conn_mutex); + conn->bg_kill = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + pthread_join(conn->bg_thread, NULL); + pthread_cond_destroy(&conn->bg_conn_cond); + pthread_cond_destroy(&conn->bg_conn_sync_cond); + spider_free_mem_calc(spider_current_trx, + conn->bg_job_stack_id, + conn->bg_job_stack.max_element * + conn->bg_job_stack.size_of_element); + delete_dynamic(&conn->bg_job_stack); + pthread_mutex_destroy(&conn->bg_job_stack_mutex); + pthread_mutex_destroy(&conn->bg_conn_mutex); + pthread_mutex_destroy(&conn->bg_conn_sync_mutex); + pthread_mutex_destroy(&conn->bg_conn_chain_mutex); + conn->bg_kill = FALSE; + conn->bg_init = FALSE; + } + DBUG_VOID_RETURN; +} + +void spider_bg_conn_wait( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_bg_conn_wait"); + if (conn->bg_init) + { + pthread_mutex_lock(&conn->bg_conn_mutex); + pthread_mutex_unlock(&conn->bg_conn_mutex); + } + DBUG_VOID_RETURN; +} + +void spider_bg_all_conn_wait( + ha_spider *spider +) { + int roop_count; + SPIDER_CONN *conn; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_bg_all_conn_wait"); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (conn && result_list->bgs_working) + spider_bg_conn_wait(conn); +#endif + } + DBUG_VOID_RETURN; +} + +int spider_bg_all_conn_pre_next( + ha_spider *spider, + int link_idx +) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + int roop_start, roop_end, roop_count, lock_mode, link_ok, error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; +#endif + DBUG_ENTER("spider_bg_all_conn_pre_next"); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list->bgs_phase > 0) + { + lock_mode = spider_conn_lock_mode(spider); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = spider->share->link_count; + } else { + link_ok = link_idx; + roop_start = link_idx; + roop_end = link_idx + 1; + } + + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ((error_num = spider_bg_conn_search(spider, roop_count, roop_start, + TRUE, TRUE, (roop_count != link_ok)))) + DBUG_RETURN(error_num); + } + } +#endif + DBUG_RETURN(0); +} + +void spider_bg_conn_break( + SPIDER_CONN *conn, + ha_spider *spider +) { + DBUG_ENTER("spider_bg_conn_break"); + if ( + conn->bg_init && + conn->bg_thd != current_thd && + ( + !spider || + ( + spider->result_list.bgs_working && + conn->bg_target == spider + ) + ) + ) { + conn->bg_break = TRUE; + pthread_mutex_lock(&conn->bg_conn_mutex); + pthread_mutex_unlock(&conn->bg_conn_mutex); + conn->bg_break = FALSE; + } + DBUG_VOID_RETURN; +} + +void spider_bg_all_conn_break( + ha_spider *spider +) { + int roop_count; + SPIDER_CONN *conn; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_bg_all_conn_break"); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (conn && result_list->bgs_working) + spider_bg_conn_break(conn, spider); +#endif + if (spider->quick_targets[roop_count]) + { + DBUG_ASSERT(spider->quick_targets[roop_count] == conn->quick_target); + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn)); + conn->quick_target = NULL; + spider->quick_targets[roop_count] = NULL; + } + } + DBUG_VOID_RETURN; +} + +bool spider_bg_conn_get_job( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_bg_conn_get_job"); + pthread_mutex_lock(&conn->bg_job_stack_mutex); + if (conn->bg_job_stack_cur_pos >= conn->bg_job_stack.elements) + { + DBUG_PRINT("info",("spider bg all jobs are completed")); + conn->bg_get_job_stack_off = FALSE; + pthread_mutex_unlock(&conn->bg_job_stack_mutex); + DBUG_RETURN(FALSE); + } + DBUG_PRINT("info",("spider bg get job %u", + conn->bg_job_stack_cur_pos)); + conn->bg_target = ((void **) (conn->bg_job_stack.buffer + + conn->bg_job_stack.size_of_element * conn->bg_job_stack_cur_pos))[0]; + conn->bg_job_stack_cur_pos++; + if (conn->bg_job_stack_cur_pos == conn->bg_job_stack.elements) + { + DBUG_PRINT("info",("spider bg shift job stack")); + conn->bg_job_stack_cur_pos = 0; + conn->bg_job_stack.elements = 0; + } + pthread_mutex_unlock(&conn->bg_job_stack_mutex); + DBUG_RETURN(TRUE); +} + +int spider_bg_conn_search( + ha_spider *spider, + int link_idx, + int first_link_idx, + bool first, + bool pre_next, + bool discard_result +) { + int error_num; + SPIDER_CONN *conn, *first_conn = NULL; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + bool with_lock = FALSE; + DBUG_ENTER("spider_bg_conn_search"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = spider->conns[link_idx]; + with_lock = (spider_conn_lock_mode(spider) != SPIDER_LOCK_MODE_NO_LOCK); + first_conn = spider->conns[first_link_idx]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) + conn = spider->hs_r_conns[link_idx]; + else + conn = spider->hs_w_conns[link_idx]; +#endif + if (first) + { + if (spider->use_pre_call) + { + DBUG_PRINT("info",("spider skip bg first search")); + } else { + DBUG_PRINT("info",("spider bg first search")); + pthread_mutex_lock(&conn->bg_conn_mutex); + result_list->bgs_working = TRUE; + conn->bg_search = TRUE; + conn->bg_caller_wait = TRUE; + conn->bg_target = spider; + conn->link_idx = link_idx; + conn->bg_discard_result = discard_result; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_wait = FALSE; + if (result_list->bgs_error) + { + if (result_list->bgs_error_with_message) + my_message(result_list->bgs_error, + result_list->bgs_error_msg, MYF(0)); + DBUG_RETURN(result_list->bgs_error); + } + } + if (!result_list->finish_flg) + { + pthread_mutex_lock(&conn->bg_conn_mutex); + if (!result_list->finish_flg) + { + DBUG_PRINT("info",("spider bg second search")); + if (!spider->use_pre_call || pre_next) + { + if (result_list->bgs_error) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_PRINT("info",("spider bg error")); + if (result_list->bgs_error == HA_ERR_END_OF_FILE) + { + DBUG_PRINT("info",("spider bg current->finish_flg=%s", + result_list->current ? + (result_list->current->finish_flg ? "TRUE" : "FALSE") : "NULL")); + DBUG_RETURN(0); + } + if (result_list->bgs_error_with_message) + my_message(result_list->bgs_error, + result_list->bgs_error_msg, MYF(0)); + DBUG_RETURN(result_list->bgs_error); + } + if ( + result_list->quick_mode == 0 || + !result_list->bgs_current->result + ) { + result_list->split_read = + result_list->bgs_second_read > 0 ? + result_list->bgs_second_read : + result_list->bgs_split_read; + result_list->limit_num = + result_list->internal_limit - result_list->record_num >= + result_list->split_read ? + result_list->split_read : + result_list->internal_limit - result_list->record_num; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->reappend_limit_sql_part( + result_list->internal_offset + result_list->record_num, + result_list->limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + if ( + !result_list->use_union && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + spider_db_append_handler_next(spider); + if ((error_num = spider->reappend_limit_sql_part( + 0, result_list->limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + } + result_list->bgs_phase = 2; + } + result_list->bgs_working = TRUE; + conn->bg_search = TRUE; + if (with_lock) + conn->bg_conn_chain_mutex_ptr = &first_conn->bg_conn_chain_mutex; + conn->bg_caller_sync_wait = TRUE; + conn->bg_target = spider; + conn->link_idx = link_idx; + conn->bg_discard_result = discard_result; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_sync_wait = FALSE; + } else { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_PRINT("info",("spider bg current->finish_flg=%s", + result_list->current ? + (result_list->current->finish_flg ? "TRUE" : "FALSE") : "NULL")); + } + } else { + DBUG_PRINT("info",("spider bg current->finish_flg=%s", + result_list->current ? + (result_list->current->finish_flg ? "TRUE" : "FALSE") : "NULL")); + } + } else { + DBUG_PRINT("info",("spider bg search")); + if (result_list->current->finish_flg) + { + DBUG_PRINT("info",("spider bg end of file")); + result_list->table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + if (result_list->bgs_working) + { + /* wait */ + DBUG_PRINT("info",("spider bg working wait")); + pthread_mutex_lock(&conn->bg_conn_mutex); + pthread_mutex_unlock(&conn->bg_conn_mutex); + } + if (result_list->bgs_error) + { + DBUG_PRINT("info",("spider bg error")); + if (result_list->bgs_error == HA_ERR_END_OF_FILE) + { + result_list->current = result_list->current->next; + result_list->current_row_num = 0; + result_list->table->status = STATUS_NOT_FOUND; + } + if (result_list->bgs_error_with_message) + my_message(result_list->bgs_error, + result_list->bgs_error_msg, MYF(0)); + DBUG_RETURN(result_list->bgs_error); + } + result_list->current = result_list->current->next; + result_list->current_row_num = 0; + if (result_list->current == result_list->bgs_current) + { + DBUG_PRINT("info",("spider bg next search")); + if (!result_list->current->finish_flg) + { + pthread_mutex_lock(&conn->bg_conn_mutex); + result_list->bgs_phase = 3; + if ( + result_list->quick_mode == 0 || + !result_list->bgs_current->result + ) { + result_list->split_read = result_list->bgs_split_read; + result_list->limit_num = + result_list->internal_limit - result_list->record_num >= + result_list->split_read ? + result_list->split_read : + result_list->internal_limit - result_list->record_num; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->reappend_limit_sql_part( + result_list->internal_offset + result_list->record_num, + result_list->limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + if ( + !result_list->use_union && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + spider_db_append_handler_next(spider); + if ((error_num = spider->reappend_limit_sql_part( + 0, result_list->limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + } + conn->bg_target = spider; + conn->link_idx = link_idx; + conn->bg_discard_result = discard_result; + result_list->bgs_working = TRUE; + conn->bg_search = TRUE; + if (with_lock) + conn->bg_conn_chain_mutex_ptr = &first_conn->bg_conn_chain_mutex; + conn->bg_caller_sync_wait = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_sync_wait = FALSE; + } + } + } + DBUG_RETURN(0); +} + +void spider_bg_conn_simple_action( + SPIDER_CONN *conn, + uint simple_action +) { + DBUG_ENTER("spider_bg_conn_simple_action"); + pthread_mutex_lock(&conn->bg_conn_mutex); + conn->bg_caller_wait = TRUE; + conn->bg_simple_action = simple_action; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_wait = FALSE; + DBUG_VOID_RETURN; +} + +void *spider_bg_conn_action( + void *arg +) { + int error_num; + SPIDER_CONN *conn = (SPIDER_CONN*) arg; + SPIDER_TRX *trx; + ha_spider *spider; + SPIDER_RESULT_LIST *result_list; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_conn_action"); + /* init start */ + if (!(thd = new THD())) + { + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + my_thread_end(); + DBUG_RETURN(NULL); + } + pthread_mutex_lock(&LOCK_thread_count); + thd->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd->thread_stack = (char*) &thd; + thd->store_globals(); + if (!(trx = spider_get_trx(thd, FALSE, &error_num))) + { + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + /* lex_start(thd); */ + conn->bg_thd = thd; + pthread_mutex_lock(&conn->bg_conn_mutex); + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + conn->bg_init = TRUE; + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + /* init end */ + + while (TRUE) + { + if (conn->bg_conn_chain_mutex_ptr) + { + pthread_mutex_unlock(conn->bg_conn_chain_mutex_ptr); + conn->bg_conn_chain_mutex_ptr = NULL; + } + thd->clear_error(); + pthread_cond_wait(&conn->bg_conn_cond, &conn->bg_conn_mutex); + DBUG_PRINT("info",("spider bg roop start")); + if (conn->bg_caller_sync_wait) + { + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + if (conn->bg_direct_sql) + conn->bg_get_job_stack_off = TRUE; + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + if (conn->bg_conn_chain_mutex_ptr) + { + pthread_mutex_lock(conn->bg_conn_chain_mutex_ptr); + if ((&conn->bg_conn_chain_mutex) != conn->bg_conn_chain_mutex_ptr) + { + pthread_mutex_unlock(conn->bg_conn_chain_mutex_ptr); + conn->bg_conn_chain_mutex_ptr = NULL; + } + } + } + if (conn->bg_kill) + { + DBUG_PRINT("info",("spider bg kill start")); + if (conn->bg_conn_chain_mutex_ptr) + { + pthread_mutex_unlock(conn->bg_conn_chain_mutex_ptr); + conn->bg_conn_chain_mutex_ptr = NULL; + } + spider_free_trx(trx, TRUE); + /* lex_end(thd->lex); */ + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + if (conn->bg_get_job_stack) + { + conn->bg_get_job_stack = FALSE; + if (!spider_bg_conn_get_job(conn)) + { + conn->bg_direct_sql = FALSE; + } + } + if (conn->bg_search) + { + SPIDER_SHARE *share; + spider_db_handler *dbton_handler; + DBUG_PRINT("info",("spider bg search start")); + spider = (ha_spider*) conn->bg_target; + share = spider->share; + dbton_handler = spider->dbton_handler[conn->dbton_id]; + result_list = &spider->result_list; + result_list->bgs_error = 0; + result_list->bgs_error_with_message = FALSE; + if ( + result_list->quick_mode == 0 || + result_list->bgs_phase == 1 || + !result_list->bgs_current->result + ) { + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (spider->sql_kind[conn->link_idx] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + sql_type = SPIDER_SQL_TYPE_SELECT_HS; + } +#endif + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + conn->link_idx))) + { + result_list->bgs_error = error_num; + if ((result_list->bgs_error_with_message = thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, thd->stmt_da->message()); +#endif + } + if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + sql_type &= ~SPIDER_SQL_TYPE_TMP_SQL; + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); +#ifdef HA_CAN_BULK_ACCESS + if (spider->is_bulk_access_clone) + { + spider->connection_ids[conn->link_idx] = conn->connection_id; + spider_trx_add_bulk_access_conn(spider->trx, conn); + } +#endif + if (!result_list->bgs_error) + { + conn->need_mon = &spider->need_mons[conn->link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; +#ifdef HA_CAN_BULK_ACCESS + if (!spider->is_bulk_access_clone) + { +#endif + if (!(result_list->bgs_error = + spider_db_set_names(spider, conn, conn->link_idx))) + { + if ( + result_list->tmp_table_join && + spider_bit_is_set(result_list->tmp_table_join_first, + conn->link_idx) + ) { + spider_clear_bit(result_list->tmp_table_join_first, + conn->link_idx); + spider_set_bit(result_list->tmp_table_created, + conn->link_idx); + result_list->tmp_tables_created = TRUE; + spider_conn_set_timeout_from_share(conn, conn->link_idx, + spider->trx->thd, share); + if (dbton_handler->execute_sql( + SPIDER_SQL_TYPE_TMP_SQL, + conn, + -1, + &spider->need_mons[conn->link_idx]) + ) { + result_list->bgs_error = spider_db_errorno(conn); + if ((result_list->bgs_error_with_message = thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, + thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, + thd->stmt_da->message()); +#endif + } else + spider_db_discard_multiple_result(spider, conn->link_idx, + conn); + } + if (!result_list->bgs_error) + { + spider_conn_set_timeout_from_share(conn, conn->link_idx, + spider->trx->thd, share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[conn->link_idx]) + ) { + result_list->bgs_error = spider_db_errorno(conn); + if ((result_list->bgs_error_with_message = thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, + thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, + thd->stmt_da->message()); +#endif + } else { + spider->connection_ids[conn->link_idx] = conn->connection_id; + if (!conn->bg_discard_result) + { + if (!(result_list->bgs_error = + spider_db_store_result(spider, conn->link_idx, + result_list->table))) + spider->result_link_idx = conn->link_idx; + else { + if ((result_list->bgs_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, + thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, + thd->stmt_da->message()); +#endif + } + } else { + result_list->bgs_error = 0; + spider_db_discard_result(spider, conn->link_idx, conn); + } + } + } + } else { + if ((result_list->bgs_error_with_message = thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, thd->stmt_da->message()); +#endif + } +#ifdef HA_CAN_BULK_ACCESS + } +#endif + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } else { + spider->connection_ids[conn->link_idx] = conn->connection_id; + conn->mta_conn_mutex_unlock_later = TRUE; + result_list->bgs_error = + spider_db_store_result(spider, conn->link_idx, result_list->table); + if ((result_list->bgs_error_with_message = thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(result_list->bgs_error_msg, thd->main_da.message()); +#else + strmov(result_list->bgs_error_msg, thd->stmt_da->message()); +#endif + conn->mta_conn_mutex_unlock_later = FALSE; + } + conn->bg_search = FALSE; + result_list->bgs_working = FALSE; + if (conn->bg_caller_wait) + { + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + } + continue; + } + if (conn->bg_direct_sql) + { + bool is_error = FALSE; + DBUG_PRINT("info",("spider bg direct sql start")); + do { + SPIDER_DIRECT_SQL *direct_sql = (SPIDER_DIRECT_SQL *) conn->bg_target; + if ( + (error_num = spider_db_udf_direct_sql(direct_sql)) + ) { + if (thd->is_error()) + { + SPIDER_BG_DIRECT_SQL *bg_direct_sql = + (SPIDER_BG_DIRECT_SQL *) direct_sql->parent; + pthread_mutex_lock(direct_sql->bg_mutex); +#if MYSQL_VERSION_ID < 50500 + bg_direct_sql->bg_error = thd->main_da.sql_errno(); + strmov((char *) bg_direct_sql->bg_error_msg, + thd->main_da.message()); +#else + bg_direct_sql->bg_error = thd->stmt_da->sql_errno(); + strmov((char *) bg_direct_sql->bg_error_msg, + thd->stmt_da->message()); +#endif + pthread_mutex_unlock(direct_sql->bg_mutex); + is_error = TRUE; + } + } + if (direct_sql->modified_non_trans_table) + { + SPIDER_BG_DIRECT_SQL *bg_direct_sql = + (SPIDER_BG_DIRECT_SQL *) direct_sql->parent; + pthread_mutex_lock(direct_sql->bg_mutex); + bg_direct_sql->modified_non_trans_table = TRUE; + pthread_mutex_unlock(direct_sql->bg_mutex); + } + spider_udf_free_direct_sql_alloc(direct_sql, TRUE); + } while (!is_error && spider_bg_conn_get_job(conn)); + if (is_error) + { + while (spider_bg_conn_get_job(conn)) + spider_udf_free_direct_sql_alloc( + (SPIDER_DIRECT_SQL *) conn->bg_target, TRUE); + } + conn->bg_direct_sql = FALSE; + continue; + } + if (conn->bg_exec_sql) + { + DBUG_PRINT("info",("spider bg exec sql start")); + spider = (ha_spider*) conn->bg_target; + *conn->bg_error_num = spider_db_query_with_set_names( + conn->bg_sql_type, + spider, + conn, + conn->link_idx + ); + conn->bg_exec_sql = FALSE; + continue; + } + if (conn->bg_simple_action) + { + switch (conn->bg_simple_action) + { + case SPIDER_BG_SIMPLE_CONNECT: + conn->db_conn->bg_connect(); + break; + case SPIDER_BG_SIMPLE_DISCONNECT: + conn->db_conn->bg_disconnect(); + break; + default: + break; + } + conn->bg_simple_action = SPIDER_BG_SIMPLE_NO_ACTION; + if (conn->bg_caller_wait) + { + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_sync_cond); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + } + continue; + } + if (conn->bg_break) + { + DBUG_PRINT("info",("spider bg break start")); + spider = (ha_spider*) conn->bg_target; + result_list = &spider->result_list; + result_list->bgs_working = FALSE; + continue; + } + } +} + +int spider_create_sts_thread( + SPIDER_SHARE *share +) { + int error_num; + DBUG_ENTER("spider_create_sts_thread"); + if (!share->bg_sts_init) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&share->bg_sts_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_sts, + &share->bg_sts_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&share->bg_sts_sync_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_sts_sync, + &share->bg_sts_sync_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_create(&share->bg_sts_thread, &spider_pt_attr, + spider_bg_sts_action, (void *) share) + ) +#else + if (mysql_thread_create(spd_key_thd_bg_sts, &share->bg_sts_thread, + &spider_pt_attr, spider_bg_sts_action, (void *) share) + ) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + share->bg_sts_init = TRUE; + } + DBUG_RETURN(0); + +error_thread_create: + pthread_cond_destroy(&share->bg_sts_sync_cond); +error_sync_cond_init: + pthread_cond_destroy(&share->bg_sts_cond); +error_cond_init: + DBUG_RETURN(error_num); +} + +void spider_free_sts_thread( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_free_sts_thread"); + if (share->bg_sts_init) + { + pthread_mutex_lock(&share->sts_mutex); + share->bg_sts_kill = TRUE; + pthread_cond_signal(&share->bg_sts_cond); + pthread_cond_wait(&share->bg_sts_sync_cond, &share->sts_mutex); + pthread_mutex_unlock(&share->sts_mutex); + pthread_join(share->bg_sts_thread, NULL); + pthread_cond_destroy(&share->bg_sts_sync_cond); + pthread_cond_destroy(&share->bg_sts_cond); + share->bg_sts_thd_wait = FALSE; + share->bg_sts_kill = FALSE; + share->bg_sts_init = FALSE; + } + DBUG_VOID_RETURN; +} + +void *spider_bg_sts_action( + void *arg +) { + SPIDER_SHARE *share = (SPIDER_SHARE*) arg; + SPIDER_TRX *trx; + int error_num = 0, roop_count; + ha_spider spider; +#ifdef _MSC_VER + int *need_mons; + SPIDER_CONN **conns; + uint *conn_link_idx; + uchar *conn_can_fo; + char **conn_keys; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char **hs_r_conn_keys; + char **hs_w_conn_keys; +#endif + spider_db_handler **dbton_hdl; +#else + int need_mons[share->link_count]; + SPIDER_CONN *conns[share->link_count]; + uint conn_link_idx[share->link_count]; + uchar conn_can_fo[share->link_bitmap_size]; + char *conn_keys[share->link_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char *hs_r_conn_keys[share->link_count]; + char *hs_w_conn_keys[share->link_count]; +#endif + spider_db_handler *dbton_hdl[SPIDER_DBTON_SIZE]; +#endif + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_sts_action"); + /* init start */ +#ifdef _MSC_VER +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!(need_mons = (int *) + spider_bulk_malloc(spider_current_trx, 21, MYF(MY_WME), + &need_mons, sizeof(int) * share->link_count, + &conns, sizeof(SPIDER_CONN *) * share->link_count, + &conn_link_idx, sizeof(uint) * share->link_count, + &conn_can_fo, sizeof(uchar) * share->link_bitmap_size, + &conn_keys, sizeof(char *) * share->link_count, + &hs_r_conn_keys, sizeof(char *) * share->link_count, + &hs_w_conn_keys, sizeof(char *) * share->link_count, + &dbton_hdl, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) +#else + if (!(need_mons = (int *) + spider_bulk_malloc(spider_current_trx, 21, MYF(MY_WME), + &need_mons, sizeof(int) * share->link_count, + &conns, sizeof(SPIDER_CONN *) * share->link_count, + &conn_link_idx, sizeof(uint) * share->link_count, + &conn_can_fo, sizeof(uchar) * share->link_bitmap_size, + &conn_keys, sizeof(char *) * share->link_count, + &dbton_hdl, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) +#endif + { + pthread_mutex_lock(&share->sts_mutex); + share->bg_sts_thd_wait = FALSE; + share->bg_sts_kill = FALSE; + share->bg_sts_init = FALSE; + pthread_mutex_unlock(&share->sts_mutex); + my_thread_end(); + DBUG_RETURN(NULL); + } +#endif + pthread_mutex_lock(&share->sts_mutex); + if (!(thd = new THD())) + { + share->bg_sts_thd_wait = FALSE; + share->bg_sts_kill = FALSE; + share->bg_sts_init = FALSE; + pthread_mutex_unlock(&share->sts_mutex); + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + pthread_mutex_lock(&LOCK_thread_count); + thd->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd->thread_stack = (char*) &thd; + thd->store_globals(); + if (!(trx = spider_get_trx(thd, FALSE, &error_num))) + { + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + share->bg_sts_thd_wait = FALSE; + share->bg_sts_kill = FALSE; + share->bg_sts_init = FALSE; + pthread_mutex_unlock(&share->sts_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + share->bg_sts_thd = thd; +/* + spider.trx = spider_global_trx; +*/ + spider.trx = trx; + spider.share = share; + spider.conns = conns; + spider.conn_link_idx = conn_link_idx; + spider.conn_can_fo = conn_can_fo; + spider.need_mons = need_mons; + spider.conn_keys_first_ptr = share->conn_keys[0]; + spider.conn_keys = conn_keys; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider.hs_r_conn_keys = hs_r_conn_keys; + spider.hs_w_conn_keys = hs_w_conn_keys; +#endif + spider.dbton_handler = dbton_hdl; + memset(conns, 0, sizeof(SPIDER_CONN *) * share->link_count); + memset(need_mons, 0, sizeof(int) * share->link_count); + memset(dbton_hdl, 0, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE); + spider_trx_set_link_idx_for_all(&spider); + spider.search_link_idx = spider_conn_first_link_idx(thd, + share->link_statuses, share->access_balances, spider.conn_link_idx, + share->link_count, SPIDER_LINK_STATUS_OK); + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + spider_dbton[roop_count].create_db_handler + ) { + if ((dbton_hdl[roop_count] = spider_dbton[roop_count].create_db_handler( + &spider, share->dbton_share[roop_count]))) + break; + if (dbton_hdl[roop_count]->init()) + break; + } + } + if (roop_count == SPIDER_DBTON_SIZE) + { + DBUG_PRINT("info",("spider handler init error")); + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + dbton_hdl[roop_count] + ) { + delete dbton_hdl[roop_count]; + dbton_hdl[roop_count] = NULL; + } + } + spider_free_trx(trx, TRUE); + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + share->bg_sts_thd_wait = FALSE; + share->bg_sts_kill = FALSE; + share->bg_sts_init = FALSE; + pthread_mutex_unlock(&share->sts_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + /* init end */ + + while (TRUE) + { + DBUG_PRINT("info",("spider bg sts roop start")); + if (share->bg_sts_kill) + { + DBUG_PRINT("info",("spider bg sts kill start")); + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + dbton_hdl[roop_count] + ) { + delete dbton_hdl[roop_count]; + dbton_hdl[roop_count] = NULL; + } + } + spider_free_trx(trx, TRUE); + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + pthread_cond_signal(&share->bg_sts_sync_cond); + pthread_mutex_unlock(&share->sts_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + if (spider.search_link_idx == -1) + { + spider_trx_set_link_idx_for_all(&spider); + spider.search_link_idx = spider_conn_next_link_idx( + thd, share->link_statuses, share->access_balances, + spider.conn_link_idx, spider.search_link_idx, share->link_count, + SPIDER_LINK_STATUS_OK); + } + if (spider.search_link_idx >= 0) + { + if (difftime(share->bg_sts_try_time, share->sts_get_time) >= + share->bg_sts_interval) + { + if (!conns[spider.search_link_idx]) + { + pthread_mutex_lock(&spider_global_trx_mutex); + spider_get_conn(share, spider.search_link_idx, + share->conn_keys[spider.search_link_idx], + spider_global_trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + conns[spider.search_link_idx]->error_mode = 0; + pthread_mutex_unlock(&spider_global_trx_mutex); + if ( + error_num && + share->monitoring_kind[spider.search_link_idx] && + need_mons[spider.search_link_idx] + ) { + lex_start(thd); + error_num = spider_ping_table_mon_from_table( + spider_global_trx, + thd, + share, + (uint32) share->monitoring_sid[spider.search_link_idx], + share->table_name, + share->table_name_length, + spider.conn_link_idx[spider.search_link_idx], + NULL, + 0, + share->monitoring_kind[spider.search_link_idx], + share->monitoring_limit[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } + } + if (conns[spider.search_link_idx]) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (spider_get_sts(share, spider.search_link_idx, + share->bg_sts_try_time, &spider, + share->bg_sts_interval, share->bg_sts_mode, + share->bg_sts_sync, + 2, HA_STATUS_CONST | HA_STATUS_VARIABLE)) +#else + if (spider_get_sts(share, spider.search_link_idx, + share->bg_sts_try_time, &spider, + share->bg_sts_interval, share->bg_sts_mode, + 2, HA_STATUS_CONST | HA_STATUS_VARIABLE)) +#endif + { + if ( + share->monitoring_kind[spider.search_link_idx] && + need_mons[spider.search_link_idx] + ) { + lex_start(thd); + error_num = spider_ping_table_mon_from_table( + spider_global_trx, + thd, + share, + (uint32) share->monitoring_sid[spider.search_link_idx], + share->table_name, + share->table_name_length, + spider.conn_link_idx[spider.search_link_idx], + NULL, + 0, + share->monitoring_kind[spider.search_link_idx], + share->monitoring_limit[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } + spider.search_link_idx = -1; + } + } + } + } + memset(need_mons, 0, sizeof(int) * share->link_count); + share->bg_sts_thd_wait = TRUE; + pthread_cond_wait(&share->bg_sts_cond, &share->sts_mutex); + } +} + +int spider_create_crd_thread( + SPIDER_SHARE *share +) { + int error_num; + DBUG_ENTER("spider_create_crd_thread"); + if (!share->bg_crd_init) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&share->bg_crd_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_crd, + &share->bg_crd_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&share->bg_crd_sync_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_crd_sync, + &share->bg_crd_sync_cond, NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_create(&share->bg_crd_thread, &spider_pt_attr, + spider_bg_crd_action, (void *) share) + ) +#else + if (mysql_thread_create(spd_key_thd_bg_crd, &share->bg_crd_thread, + &spider_pt_attr, spider_bg_crd_action, (void *) share) + ) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + share->bg_crd_init = TRUE; + } + DBUG_RETURN(0); + +error_thread_create: + pthread_cond_destroy(&share->bg_crd_sync_cond); +error_sync_cond_init: + pthread_cond_destroy(&share->bg_crd_cond); +error_cond_init: + DBUG_RETURN(error_num); +} + +void spider_free_crd_thread( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_free_crd_thread"); + if (share->bg_crd_init) + { + pthread_mutex_lock(&share->crd_mutex); + share->bg_crd_kill = TRUE; + pthread_cond_signal(&share->bg_crd_cond); + pthread_cond_wait(&share->bg_crd_sync_cond, &share->crd_mutex); + pthread_mutex_unlock(&share->crd_mutex); + pthread_join(share->bg_crd_thread, NULL); + pthread_cond_destroy(&share->bg_crd_sync_cond); + pthread_cond_destroy(&share->bg_crd_cond); + share->bg_crd_thd_wait = FALSE; + share->bg_crd_kill = FALSE; + share->bg_crd_init = FALSE; + } + DBUG_VOID_RETURN; +} + +void *spider_bg_crd_action( + void *arg +) { + SPIDER_SHARE *share = (SPIDER_SHARE*) arg; + SPIDER_TRX *trx; + int error_num = 0, roop_count; + ha_spider spider; + TABLE table; +#ifdef _MSC_VER + int *need_mons; + SPIDER_CONN **conns; + uint *conn_link_idx; + uchar *conn_can_fo; + char **conn_keys; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char **hs_r_conn_keys; + char **hs_w_conn_keys; +#endif + spider_db_handler **dbton_hdl; +#else + int need_mons[share->link_count]; + SPIDER_CONN *conns[share->link_count]; + uint conn_link_idx[share->link_count]; + uchar conn_can_fo[share->link_bitmap_size]; + char *conn_keys[share->link_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char *hs_r_conn_keys[share->link_count]; + char *hs_w_conn_keys[share->link_count]; +#endif + spider_db_handler *dbton_hdl[SPIDER_DBTON_SIZE]; +#endif + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_crd_action"); + /* init start */ +#ifdef _MSC_VER +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!(need_mons = (int *) + spider_bulk_malloc(spider_current_trx, 22, MYF(MY_WME), + &need_mons, sizeof(int) * share->link_count, + &conns, sizeof(SPIDER_CONN *) * share->link_count, + &conn_link_idx, sizeof(uint) * share->link_count, + &conn_can_fo, sizeof(uchar) * share->link_bitmap_size, + &conn_keys, sizeof(char *) * share->link_count, + &hs_r_conn_keys, sizeof(char *) * share->link_count, + &hs_w_conn_keys, sizeof(char *) * share->link_count, + &dbton_hdl, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) +#else + if (!(need_mons = (int *) + spider_bulk_malloc(spider_current_trx, 22, MYF(MY_WME), + &need_mons, sizeof(int) * share->link_count, + &conns, sizeof(SPIDER_CONN *) * share->link_count, + &conn_link_idx, sizeof(uint) * share->link_count, + &conn_can_fo, sizeof(uchar) * share->link_bitmap_size, + &conn_keys, sizeof(char *) * share->link_count, + &dbton_hdl, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) +#endif + { + pthread_mutex_lock(&share->crd_mutex); + share->bg_crd_thd_wait = FALSE; + share->bg_crd_kill = FALSE; + share->bg_crd_init = FALSE; + pthread_mutex_unlock(&share->crd_mutex); + my_thread_end(); + DBUG_RETURN(NULL); + } +#endif + pthread_mutex_lock(&share->crd_mutex); + if (!(thd = new THD())) + { + share->bg_crd_thd_wait = FALSE; + share->bg_crd_kill = FALSE; + share->bg_crd_init = FALSE; + pthread_mutex_unlock(&share->crd_mutex); + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + pthread_mutex_lock(&LOCK_thread_count); + thd->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd->thread_stack = (char*) &thd; + thd->store_globals(); + if (!(trx = spider_get_trx(thd, FALSE, &error_num))) + { + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + share->bg_crd_thd_wait = FALSE; + share->bg_crd_kill = FALSE; + share->bg_crd_init = FALSE; + pthread_mutex_unlock(&share->crd_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + share->bg_crd_thd = thd; + table.s = share->table_share; + table.field = share->table_share->field; + table.key_info = share->table_share->key_info; +/* + spider.trx = spider_global_trx; +*/ + spider.trx = trx; + spider.change_table_ptr(&table, share->table_share); + spider.share = share; + spider.conns = conns; + spider.conn_link_idx = conn_link_idx; + spider.conn_can_fo = conn_can_fo; + spider.need_mons = need_mons; + spider.conn_keys_first_ptr = share->conn_keys[0]; + spider.conn_keys = conn_keys; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider.hs_r_conn_keys = hs_r_conn_keys; + spider.hs_w_conn_keys = hs_w_conn_keys; +#endif + spider.dbton_handler = dbton_hdl; + memset(conns, 0, sizeof(SPIDER_CONN *) * share->link_count); + memset(need_mons, 0, sizeof(int) * share->link_count); + memset(dbton_hdl, 0, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE); + spider_trx_set_link_idx_for_all(&spider); + spider.search_link_idx = spider_conn_first_link_idx(thd, + share->link_statuses, share->access_balances, spider.conn_link_idx, + share->link_count, SPIDER_LINK_STATUS_OK); + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + spider_dbton[roop_count].create_db_handler + ) { + if ((dbton_hdl[roop_count] = spider_dbton[roop_count].create_db_handler( + &spider, share->dbton_share[roop_count]))) + break; + if (dbton_hdl[roop_count]->init()) + break; + } + } + if (roop_count == SPIDER_DBTON_SIZE) + { + DBUG_PRINT("info",("spider handler init error")); + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + dbton_hdl[roop_count] + ) { + delete dbton_hdl[roop_count]; + dbton_hdl[roop_count] = NULL; + } + } + spider_free_trx(trx, TRUE); + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + share->bg_crd_thd_wait = FALSE; + share->bg_crd_kill = FALSE; + share->bg_crd_init = FALSE; + pthread_mutex_unlock(&share->crd_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + /* init end */ + + while (TRUE) + { + DBUG_PRINT("info",("spider bg crd roop start")); + if (share->bg_crd_kill) + { + DBUG_PRINT("info",("spider bg crd kill start")); + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count) + { + if ( + spider_bit_is_set(share->dbton_bitmap, roop_count) && + dbton_hdl[roop_count] + ) { + delete dbton_hdl[roop_count]; + dbton_hdl[roop_count] = NULL; + } + } + spider_free_trx(trx, TRUE); + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + pthread_cond_signal(&share->bg_crd_sync_cond); + pthread_mutex_unlock(&share->crd_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); +#ifdef _MSC_VER + spider_free(NULL, need_mons, MYF(MY_WME)); +#endif + DBUG_RETURN(NULL); + } + if (spider.search_link_idx == -1) + { + spider_trx_set_link_idx_for_all(&spider); + spider.search_link_idx = spider_conn_next_link_idx( + thd, share->link_statuses, share->access_balances, + spider.conn_link_idx, spider.search_link_idx, share->link_count, + SPIDER_LINK_STATUS_OK); + } + if (spider.search_link_idx >= 0) + { + if (difftime(share->bg_crd_try_time, share->crd_get_time) >= + share->bg_crd_interval) + { + if (!conns[spider.search_link_idx]) + { + pthread_mutex_lock(&spider_global_trx_mutex); + spider_get_conn(share, spider.search_link_idx, + share->conn_keys[spider.search_link_idx], + spider_global_trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + conns[spider.search_link_idx]->error_mode = 0; + pthread_mutex_unlock(&spider_global_trx_mutex); + if ( + error_num && + share->monitoring_kind[spider.search_link_idx] && + need_mons[spider.search_link_idx] + ) { + lex_start(thd); + error_num = spider_ping_table_mon_from_table( + spider_global_trx, + thd, + share, + (uint32) share->monitoring_sid[spider.search_link_idx], + share->table_name, + share->table_name_length, + spider.conn_link_idx[spider.search_link_idx], + NULL, + 0, + share->monitoring_kind[spider.search_link_idx], + share->monitoring_limit[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } + } + if (conns[spider.search_link_idx]) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (spider_get_crd(share, spider.search_link_idx, + share->bg_crd_try_time, &spider, &table, + share->bg_crd_interval, share->bg_crd_mode, + share->bg_crd_sync, + 2)) +#else + if (spider_get_crd(share, spider.search_link_idx, + share->bg_crd_try_time, &spider, &table, + share->bg_crd_interval, share->bg_crd_mode, + 2)) +#endif + { + if ( + share->monitoring_kind[spider.search_link_idx] && + need_mons[spider.search_link_idx] + ) { + lex_start(thd); + error_num = spider_ping_table_mon_from_table( + spider_global_trx, + thd, + share, + (uint32) share->monitoring_sid[spider.search_link_idx], + share->table_name, + share->table_name_length, + spider.conn_link_idx[spider.search_link_idx], + NULL, + 0, + share->monitoring_kind[spider.search_link_idx], + share->monitoring_limit[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } + spider.search_link_idx = -1; + } + } + } + } + memset(need_mons, 0, sizeof(int) * share->link_count); + share->bg_crd_thd_wait = TRUE; + pthread_cond_wait(&share->bg_crd_cond, &share->crd_mutex); + } +} + +int spider_create_mon_threads( + SPIDER_TRX *trx, + SPIDER_SHARE *share +) { + bool create_bg_mons = FALSE; + int error_num, roop_count, roop_count2; + SPIDER_LINK_PACK link_pack; + SPIDER_TABLE_MON_LIST *table_mon_list; + DBUG_ENTER("spider_create_mon_threads"); + if (!share->bg_mon_init) + { + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if (share->monitoring_bg_kind[roop_count]) + { + create_bg_mons = TRUE; + break; + } + } + if (create_bg_mons) + { + char link_idx_str[SPIDER_SQL_INT_LEN]; + int link_idx_str_length; +#ifdef _MSC_VER + spider_string conv_name_str(share->table_name_length + + SPIDER_SQL_INT_LEN + 1); + conv_name_str.set_charset(system_charset_info); +#else + char buf[share->table_name_length + SPIDER_SQL_INT_LEN + 1]; + spider_string conv_name_str(buf, share->table_name_length + + SPIDER_SQL_INT_LEN + 1, system_charset_info); +#endif + conv_name_str.init_calc_mem(105); + conv_name_str.length(0); + conv_name_str.q_append(share->table_name, share->table_name_length); + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if (share->monitoring_bg_kind[roop_count]) + { + conv_name_str.length(share->table_name_length); + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, + "%010d", roop_count)); + conv_name_str.q_append(link_idx_str, link_idx_str_length + 1); + conv_name_str.length(conv_name_str.length() - 1); + if (!(table_mon_list = spider_get_ping_table_mon_list(trx, trx->thd, + &conv_name_str, share->table_name_length, roop_count, + (uint32) share->monitoring_sid[roop_count], FALSE, &error_num))) + goto error_get_ping_table_mon_list; + spider_free_ping_table_mon_list(table_mon_list); + } + } + if (!(share->bg_mon_thds = (THD **) + spider_bulk_malloc(spider_current_trx, 23, MYF(MY_WME | MY_ZEROFILL), + &share->bg_mon_thds, sizeof(THD *) * share->all_link_count, + &share->bg_mon_threads, sizeof(pthread_t) * share->all_link_count, + &share->bg_mon_mutexes, sizeof(pthread_mutex_t) * + share->all_link_count, + &share->bg_mon_conds, sizeof(pthread_cond_t) * share->all_link_count, + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_base; + } + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if ( + share->monitoring_bg_kind[roop_count] && +#if MYSQL_VERSION_ID < 50500 + pthread_mutex_init(&share->bg_mon_mutexes[roop_count], + MY_MUTEX_INIT_FAST) +#else + mysql_mutex_init(spd_key_mutex_bg_mon, + &share->bg_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST) +#endif + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mutex_init; + } + } + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if ( + share->monitoring_bg_kind[roop_count] && +#if MYSQL_VERSION_ID < 50500 + pthread_cond_init(&share->bg_mon_conds[roop_count], NULL) +#else + mysql_cond_init(spd_key_cond_bg_mon, + &share->bg_mon_conds[roop_count], NULL) +#endif + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + } + link_pack.share = share; + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if (share->monitoring_bg_kind[roop_count]) + { + link_pack.link_idx = roop_count; + pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); +#if MYSQL_VERSION_ID < 50500 + if (pthread_create(&share->bg_mon_threads[roop_count], + &spider_pt_attr, spider_bg_mon_action, (void *) &link_pack) + ) +#else + if (mysql_thread_create(spd_key_thd_bg_mon, + &share->bg_mon_threads[roop_count], &spider_pt_attr, + spider_bg_mon_action, (void *) &link_pack) + ) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + pthread_cond_wait(&share->bg_mon_conds[roop_count], + &share->bg_mon_mutexes[roop_count]); + pthread_mutex_unlock(&share->bg_mon_mutexes[roop_count]); + } + } + share->bg_mon_init = TRUE; + } + } + DBUG_RETURN(0); + +error_thread_create: + roop_count2 = roop_count; + for (roop_count--; roop_count >= 0; roop_count--) + { + if (share->monitoring_bg_kind[roop_count]) + pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); + } + share->bg_mon_kill = TRUE; + for (roop_count = roop_count2 - 1; roop_count >= 0; roop_count--) + { + if (share->monitoring_bg_kind[roop_count]) + { + pthread_cond_wait(&share->bg_mon_conds[roop_count], + &share->bg_mon_mutexes[roop_count]); + pthread_mutex_unlock(&share->bg_mon_mutexes[roop_count]); + } + } + share->bg_mon_kill = FALSE; + roop_count = share->all_link_count; +error_cond_init: + for (roop_count--; roop_count >= 0; roop_count--) + { + if (share->monitoring_bg_kind[roop_count]) + pthread_cond_destroy(&share->bg_mon_conds[roop_count]); + } + roop_count = share->all_link_count; +error_mutex_init: + for (roop_count--; roop_count >= 0; roop_count--) + { + if (share->monitoring_bg_kind[roop_count]) + pthread_mutex_destroy(&share->bg_mon_mutexes[roop_count]); + } + spider_free(spider_current_trx, share->bg_mon_thds, MYF(0)); +error_alloc_base: +error_get_ping_table_mon_list: + DBUG_RETURN(error_num); +} + +void spider_free_mon_threads( + SPIDER_SHARE *share +) { + int roop_count; + DBUG_ENTER("spider_free_mon_threads"); + if (share->bg_mon_init) + { + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if (share->monitoring_bg_kind[roop_count]) + pthread_mutex_lock(&share->bg_mon_mutexes[roop_count]); + } + share->bg_mon_kill = TRUE; + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if (share->monitoring_bg_kind[roop_count]) + { + pthread_cond_wait(&share->bg_mon_conds[roop_count], + &share->bg_mon_mutexes[roop_count]); + pthread_mutex_unlock(&share->bg_mon_mutexes[roop_count]); + pthread_join(share->bg_mon_threads[roop_count], NULL); + pthread_cond_destroy(&share->bg_mon_conds[roop_count]); + pthread_mutex_destroy(&share->bg_mon_mutexes[roop_count]); + } + } + spider_free(spider_current_trx, share->bg_mon_thds, MYF(0)); + share->bg_mon_kill = FALSE; + share->bg_mon_init = FALSE; + } + DBUG_VOID_RETURN; +} + +void *spider_bg_mon_action( + void *arg +) { + SPIDER_LINK_PACK *link_pack = (SPIDER_LINK_PACK*) arg; + SPIDER_SHARE *share = link_pack->share; + SPIDER_TRX *trx; + int error_num, link_idx = link_pack->link_idx; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_mon_action"); + /* init start */ + pthread_mutex_lock(&share->bg_mon_mutexes[link_idx]); + if (!(thd = new THD())) + { + share->bg_mon_kill = FALSE; + share->bg_mon_init = FALSE; + pthread_cond_signal(&share->bg_mon_conds[link_idx]); + pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]); + my_thread_end(); + DBUG_RETURN(NULL); + } + pthread_mutex_lock(&LOCK_thread_count); + thd->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd->thread_stack = (char*) &thd; + thd->store_globals(); + if (!(trx = spider_get_trx(thd, FALSE, &error_num))) + { + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif + share->bg_mon_kill = FALSE; + share->bg_mon_init = FALSE; + pthread_cond_signal(&share->bg_mon_conds[link_idx]); + pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + share->bg_mon_thds[link_idx] = thd; + pthread_cond_signal(&share->bg_mon_conds[link_idx]); + pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]); + /* init end */ + + while (TRUE) + { + DBUG_PRINT("info",("spider bg mon sleep %lld", + share->monitoring_bg_interval[link_idx])); + if (!share->bg_mon_kill) + my_sleep((ulong) share->monitoring_bg_interval[link_idx]); + DBUG_PRINT("info",("spider bg mon roop start")); + if (share->bg_mon_kill) + { + DBUG_PRINT("info",("spider bg mon kill start")); + pthread_mutex_lock(&share->bg_mon_mutexes[link_idx]); + pthread_cond_signal(&share->bg_mon_conds[link_idx]); + pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]); + spider_free_trx(trx, TRUE); + delete thd; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + set_current_thd(NULL); +#endif +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + my_pthread_setspecific_ptr(THR_THD, NULL); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + if (share->monitoring_bg_kind[link_idx]) + { + lex_start(thd); + error_num = spider_ping_table_mon_from_table( + spider_global_trx, + thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + link_idx, + NULL, + 0, + share->monitoring_bg_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + lex_end(thd->lex); + } + } +} +#endif + +int spider_conn_first_link_idx( + THD *thd, + long *link_statuses, + long *access_balances, + uint *conn_link_idx, + int link_count, + int link_status +) { + int roop_count, active_links = 0; + longlong balance_total = 0, balance_val; + double rand_val; +#ifdef _MSC_VER + int *link_idxs, link_idx; + long *balances; +#else + int link_idxs[link_count]; + long balances[link_count]; +#endif + DBUG_ENTER("spider_conn_first_link_idx"); +#ifdef _MSC_VER + if (!(link_idxs = (int *) + spider_bulk_malloc(spider_current_trx, 24, MYF(MY_WME), + &link_idxs, sizeof(int) * link_count, + &balances, sizeof(long) * link_count, + NullS)) + ) { + DBUG_PRINT("info",("spider out of memory")); + DBUG_RETURN(-1); + } +#endif + for (roop_count = 0; roop_count < link_count; roop_count++) + { + DBUG_ASSERT((conn_link_idx[roop_count] - roop_count) % link_count == 0); + if (link_statuses[conn_link_idx[roop_count]] <= link_status) + { + link_idxs[active_links] = roop_count; + balances[active_links] = access_balances[roop_count]; + balance_total += access_balances[roop_count]; + active_links++; + } + } + + if (active_links == 0) + { + DBUG_PRINT("info",("spider all links are failed")); +#ifdef _MSC_VER + spider_free(spider_current_trx, link_idxs, MYF(MY_WME)); +#endif + DBUG_RETURN(-1); + } +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + DBUG_PRINT("info",("spider server_id=%lu", thd->variables.server_id)); +#else + DBUG_PRINT("info",("spider server_id=%u", thd->server_id)); +#endif + DBUG_PRINT("info",("spider thread_id=%lu", thd_get_thread_id(thd))); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); +#else + rand_val = spider_rand(thd->server_id + thd_get_thread_id(thd)); +#endif + DBUG_PRINT("info",("spider rand_val=%f", rand_val)); + balance_val = (longlong) (rand_val * balance_total); + DBUG_PRINT("info",("spider balance_val=%lld", balance_val)); + for (roop_count = 0; roop_count < active_links - 1; roop_count++) + { + DBUG_PRINT("info",("spider balances[%d]=%ld", + roop_count, balances[roop_count])); + if (balance_val < balances[roop_count]) + break; + balance_val -= balances[roop_count]; + } + + DBUG_PRINT("info",("spider first link_idx=%d", link_idxs[roop_count])); +#ifdef _MSC_VER + link_idx = link_idxs[roop_count]; + spider_free(spider_current_trx, link_idxs, MYF(MY_WME)); + DBUG_RETURN(link_idx); +#else + DBUG_RETURN(link_idxs[roop_count]); +#endif +} + +int spider_conn_next_link_idx( + THD *thd, + long *link_statuses, + long *access_balances, + uint *conn_link_idx, + int link_idx, + int link_count, + int link_status +) { + int tmp_link_idx; + DBUG_ENTER("spider_conn_next_link_idx"); + DBUG_ASSERT((conn_link_idx[link_idx] - link_idx) % link_count == 0); + tmp_link_idx = spider_conn_first_link_idx(thd, link_statuses, + access_balances, conn_link_idx, link_count, link_status); + if ( + tmp_link_idx >= 0 && + tmp_link_idx == link_idx + ) { + do { + tmp_link_idx++; + if (tmp_link_idx >= link_count) + tmp_link_idx = 0; + if (tmp_link_idx == link_idx) + break; + } while (link_statuses[conn_link_idx[tmp_link_idx]] > link_status); + DBUG_PRINT("info",("spider next link_idx=%d", tmp_link_idx)); + DBUG_RETURN(tmp_link_idx); + } + DBUG_PRINT("info",("spider next link_idx=%d", tmp_link_idx)); + DBUG_RETURN(tmp_link_idx); +} + +int spider_conn_link_idx_next( + long *link_statuses, + uint *conn_link_idx, + int link_idx, + int link_count, + int link_status +) { + DBUG_ENTER("spider_conn_link_idx_next"); + do { + link_idx++; + if (link_idx >= link_count) + break; + DBUG_ASSERT((conn_link_idx[link_idx] - link_idx) % link_count == 0); + } while (link_statuses[conn_link_idx[link_idx]] > link_status); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + DBUG_RETURN(link_idx); +} + +int spider_conn_lock_mode( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_conn_lock_mode"); + if (result_list->lock_type == F_WRLCK || spider->lock_mode == 2) + DBUG_RETURN(SPIDER_LOCK_MODE_EXCLUSIVE); + else if (spider->lock_mode == 1) + DBUG_RETURN(SPIDER_LOCK_MODE_SHARED); + DBUG_RETURN(SPIDER_LOCK_MODE_NO_LOCK); +} + +bool spider_conn_check_recovery_link( + SPIDER_SHARE *share +) { + int roop_count; + DBUG_ENTER("spider_check_recovery_link"); + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if (share->link_statuses[roop_count] == SPIDER_LINK_STATUS_RECOVERY) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +bool spider_conn_use_handler( + ha_spider *spider, + int lock_mode, + int link_idx +) { + THD *thd = spider->trx->thd; + int use_handler = spider_param_use_handler(thd, + spider->share->use_handlers[link_idx]); + DBUG_ENTER("spider_conn_use_handler"); + DBUG_PRINT("info",("spider use_handler=%d", use_handler)); + DBUG_PRINT("info",("spider spider->conn_kind[link_idx]=%u", + spider->conn_kind[link_idx])); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[link_idx] != SPIDER_CONN_KIND_MYSQL) + { + DBUG_PRINT("info",("spider TRUE by HS")); + spider->sql_kinds |= SPIDER_SQL_KIND_HS; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_HS; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->do_direct_update && + spider_bit_is_set(spider->do_hs_direct_update, link_idx) + ) { + DBUG_PRINT("info",("spider using HS direct_update")); + spider->direct_update_kinds |= SPIDER_SQL_KIND_HS; + } +#endif + DBUG_RETURN(TRUE); + } +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (spider->do_direct_update) + { + spider->sql_kinds |= SPIDER_SQL_KIND_SQL; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_SQL; + if (spider_bit_is_set(spider->do_hs_direct_update, link_idx)) + { + spider->direct_update_kinds |= SPIDER_SQL_KIND_HS; + DBUG_PRINT("info",("spider TRUE by using HS direct_update")); + DBUG_RETURN(TRUE); + } else + spider->direct_update_kinds |= SPIDER_SQL_KIND_SQL; + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) + { + DBUG_PRINT("info",("spider FALSE by using direct_update")); + DBUG_RETURN(FALSE); + } else { + DBUG_PRINT("info",("spider TRUE by using BOTH")); + DBUG_RETURN(TRUE); + } + } +#endif +#endif + if (spider->use_spatial_index) + { + DBUG_PRINT("info",("spider FALSE by use_spatial_index")); + spider->sql_kinds |= SPIDER_SQL_KIND_SQL; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_SQL; + DBUG_RETURN(FALSE); + } + uint dbton_id; + spider_db_handler *dbton_hdl; + dbton_id = spider->share->sql_dbton_ids[spider->conn_link_idx[link_idx]]; + dbton_hdl = spider->dbton_handler[dbton_id]; + if (!dbton_hdl->support_use_handler(use_handler)) + { + DBUG_PRINT("info",("spider FALSE by dbton")); + spider->sql_kinds |= SPIDER_SQL_KIND_SQL; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_SQL; + DBUG_RETURN(FALSE); + } + if ( + spider->sql_command == SQLCOM_HA_READ && + ( + !(use_handler & 2) || + ( + spider_param_sync_trx_isolation(thd) && + thd_tx_isolation(thd) == ISO_SERIALIZABLE + ) + ) + ) { + DBUG_PRINT("info",("spider TRUE by HA")); + spider->sql_kinds |= SPIDER_SQL_KIND_HANDLER; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_HANDLER; + DBUG_RETURN(TRUE); + } + if ( + spider->sql_command != SQLCOM_HA_READ && + lock_mode == SPIDER_LOCK_MODE_NO_LOCK && + spider_param_sync_trx_isolation(thd) && + thd_tx_isolation(thd) != ISO_SERIALIZABLE && + (use_handler & 1) + ) { + DBUG_PRINT("info",("spider TRUE by PARAM")); + spider->sql_kinds |= SPIDER_SQL_KIND_HANDLER; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_HANDLER; + DBUG_RETURN(TRUE); + } + spider->sql_kinds |= SPIDER_SQL_KIND_SQL; + spider->sql_kind[link_idx] = SPIDER_SQL_KIND_SQL; + DBUG_RETURN(FALSE); +} + +bool spider_conn_need_open_handler( + ha_spider *spider, + uint idx, + int link_idx +) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_CONN *conn; +#endif + DBUG_ENTER("spider_conn_need_open_handler"); + DBUG_PRINT("info",("spider spider=%p", spider)); + if (spider->handler_opened(link_idx, spider->conn_kind[link_idx])) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->do_direct_update && + spider_bit_is_set(spider->do_hs_direct_update, link_idx) + ) { + conn = spider->hs_w_conns[link_idx]; + if ( + !conn->server_lost && + conn->hs_pre_age == spider->hs_w_conn_ages[link_idx] + ) { + DBUG_PRINT("info",("spider hs_write is already opened")); + DBUG_RETURN(FALSE); + } + } else +#endif + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + DBUG_PRINT("info",("spider HA already opened")); + DBUG_RETURN(FALSE); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) + { + DBUG_PRINT("info",("spider r_handler_index[%d]=%d", + link_idx, spider->r_handler_index[link_idx])); + DBUG_PRINT("info",("spider idx=%d", idx)); + DBUG_PRINT("info",("spider hs_pushed_ret_fields_num=%zu", + spider->hs_pushed_ret_fields_num)); + DBUG_PRINT("info",("spider hs_r_ret_fields_num[%d]=%lu", + link_idx, spider->hs_r_ret_fields_num[link_idx])); + DBUG_PRINT("info",("spider hs_r_ret_fields[%d]=%p", + link_idx, spider->hs_r_ret_fields[link_idx])); +#ifndef DBUG_OFF + if ( + spider->hs_pushed_ret_fields_num < MAX_FIELDS && + spider->hs_r_ret_fields[link_idx] && + spider->hs_pushed_ret_fields_num == + spider->hs_r_ret_fields_num[link_idx] + ) { + int roop_count; + for (roop_count = 0; roop_count < (int) spider->hs_pushed_ret_fields_num; + ++roop_count) + { + DBUG_PRINT("info",("spider hs_pushed_ret_fields[%d]=%u", + roop_count, spider->hs_pushed_ret_fields[roop_count])); + DBUG_PRINT("info",("spider hs_r_ret_fields[%d][%d]=%u", + link_idx, roop_count, + spider->hs_r_ret_fields[link_idx][roop_count])); + } + } +#endif + if ( + spider->r_handler_index[link_idx] == idx +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + && ( + ( + spider->hs_pushed_ret_fields_num == MAX_FIELDS && + spider->hs_r_ret_fields_num[link_idx] == MAX_FIELDS + ) || + ( + spider->hs_pushed_ret_fields_num < MAX_FIELDS && + spider->hs_r_ret_fields[link_idx] && + spider->hs_pushed_ret_fields_num == + spider->hs_r_ret_fields_num[link_idx] && + !memcmp(spider->hs_pushed_ret_fields, + spider->hs_r_ret_fields[link_idx], + sizeof(uint32) * spider->hs_pushed_ret_fields_num) + ) + ) +#endif + ) { + SPIDER_CONN *conn = spider->hs_r_conns[link_idx]; + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->conn_id=%llu", conn->conn_id)); + DBUG_PRINT("info",("spider conn->connection_id=%llu", + conn->connection_id)); + DBUG_PRINT("info",("spider conn->server_lost=%s", + conn->server_lost ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider conn->hs_pre_age=%llu", conn->hs_pre_age)); + DBUG_PRINT("info",("spider hs_w_conn_ages[%d]=%llu", + link_idx, spider->hs_w_conn_ages[link_idx])); + if ( + !conn->server_lost && + conn->hs_pre_age == spider->hs_r_conn_ages[link_idx] + ) { + DBUG_PRINT("info",("spider hs_r same idx")); + DBUG_RETURN(FALSE); + } + } + } else if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_WRITE) + { + DBUG_PRINT("info",("spider w_handler_index[%d]=%d", + link_idx, spider->w_handler_index[link_idx])); + DBUG_PRINT("info",("spider idx=%d", idx)); + DBUG_PRINT("info",("spider hs_pushed_ret_fields_num=%zu", + spider->hs_pushed_ret_fields_num)); + DBUG_PRINT("info",("spider hs_w_ret_fields_num[%d]=%lu", + link_idx, spider->hs_w_ret_fields_num[link_idx])); + DBUG_PRINT("info",("spider hs_w_ret_fields[%d]=%p", + link_idx, spider->hs_w_ret_fields[link_idx])); +#ifndef DBUG_OFF + if ( + spider->hs_pushed_ret_fields_num < MAX_FIELDS && + spider->hs_w_ret_fields[link_idx] && + spider->hs_pushed_ret_fields_num == + spider->hs_w_ret_fields_num[link_idx] + ) { + int roop_count; + for (roop_count = 0; roop_count < (int) spider->hs_pushed_ret_fields_num; + ++roop_count) + { + DBUG_PRINT("info",("spider hs_pushed_ret_fields[%d]=%u", + roop_count, spider->hs_pushed_ret_fields[roop_count])); + DBUG_PRINT("info",("spider hs_w_ret_fields[%d][%d]=%u", + link_idx, roop_count, + spider->hs_w_ret_fields[link_idx][roop_count])); + } + } +#endif + if ( + spider->w_handler_index[link_idx] == idx +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + && ( + ( + spider->hs_pushed_ret_fields_num == MAX_FIELDS && + spider->hs_w_ret_fields_num[link_idx] == MAX_FIELDS + ) || + ( + spider->hs_pushed_ret_fields_num < MAX_FIELDS && + spider->hs_w_ret_fields[link_idx] && + spider->hs_pushed_ret_fields_num == + spider->hs_w_ret_fields_num[link_idx] && + !memcmp(spider->hs_pushed_ret_fields, + spider->hs_w_ret_fields[link_idx], + sizeof(uint32) * spider->hs_pushed_ret_fields_num) + ) + ) +#endif + ) { + SPIDER_CONN *conn = spider->hs_w_conns[link_idx]; + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->conn_id=%llu", conn->conn_id)); + DBUG_PRINT("info",("spider conn->connection_id=%llu", + conn->connection_id)); + DBUG_PRINT("info",("spider conn->server_lost=%s", + conn->server_lost ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider conn->hs_pre_age=%llu", conn->hs_pre_age)); + DBUG_PRINT("info",("spider hs_w_conn_ages[%d]=%llu", + link_idx, spider->hs_w_conn_ages[link_idx])); + if ( + !conn->server_lost && + conn->hs_pre_age == spider->hs_w_conn_ages[link_idx] + ) { + DBUG_PRINT("info",("spider hs_w same idx")); + DBUG_RETURN(FALSE); + } + } + } +#endif + } + DBUG_RETURN(TRUE); +} diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h new file mode 100644 index 00000000000..9dc8f3495fd --- /dev/null +++ b/storage/spider/spd_conn.h @@ -0,0 +1,313 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define SPIDER_LOCK_MODE_NO_LOCK 0 +#define SPIDER_LOCK_MODE_SHARED 1 +#define SPIDER_LOCK_MODE_EXCLUSIVE 2 + +#define SPIDER_BG_SIMPLE_NO_ACTION 0 +#define SPIDER_BG_SIMPLE_CONNECT 1 +#define SPIDER_BG_SIMPLE_DISCONNECT 2 + +uchar *spider_conn_get_key( + SPIDER_CONN *conn, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +int spider_reset_conn_setted_parameter( + SPIDER_CONN *conn, + THD *thd +); + +int spider_free_conn_alloc( + SPIDER_CONN *conn +); + +void spider_free_conn_from_trx( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + bool another, + bool trx_free, + int *roop_count +); + +SPIDER_CONN *spider_create_conn( + SPIDER_SHARE *share, + ha_spider *spider, + int link_id, + int base_link_id, + uint conn_kind, + int *error_num +); + +SPIDER_CONN *spider_get_conn( + SPIDER_SHARE *share, + int link_idx, + char *conn_key, + SPIDER_TRX *trx, + ha_spider *spider, + bool another, + bool thd_chg, + uint conn_kind, + int *error_num +); + +int spider_free_conn( + SPIDER_CONN *conn +); + +void spider_conn_queue_connect( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +); + +void spider_conn_queue_connect_rewrite( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +); + +void spider_conn_queue_ping( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +void spider_conn_queue_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation +); + +void spider_conn_queue_semi_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation +); + +void spider_conn_queue_autocommit( + SPIDER_CONN *conn, + bool autocommit +); + +void spider_conn_queue_sql_log_off( + SPIDER_CONN *conn, + bool sql_log_off +); + +void spider_conn_queue_time_zone( + SPIDER_CONN *conn, + Time_zone *time_zone +); + +void spider_conn_queue_start_transaction( + SPIDER_CONN *conn +); + +void spider_conn_queue_xa_start( + SPIDER_CONN *conn, + XID *xid +); + +void spider_conn_clear_queue( + SPIDER_CONN *conn +); + +void spider_conn_clear_queue_at_commit( + SPIDER_CONN *conn +); + +void spider_conn_set_timeout( + SPIDER_CONN *conn, + uint net_read_timeout, + uint net_write_timeout +); + +void spider_conn_set_timeout_from_share( + SPIDER_CONN *conn, + int link_idx, + THD *thd, + SPIDER_SHARE *share +); + +void spider_conn_set_timeout_from_direct_sql( + SPIDER_CONN *conn, + THD *thd, + SPIDER_DIRECT_SQL *direct_sql +); + +void spider_tree_insert( + SPIDER_CONN *top, + SPIDER_CONN *conn +); + +SPIDER_CONN *spider_tree_first( + SPIDER_CONN *top +); + +SPIDER_CONN *spider_tree_last( + SPIDER_CONN *top +); + +SPIDER_CONN *spider_tree_next( + SPIDER_CONN *current +); + +SPIDER_CONN *spider_tree_delete( + SPIDER_CONN *conn, + SPIDER_CONN *top +); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_set_conn_bg_param( + ha_spider *spider +); + +int spider_create_conn_thread( + SPIDER_CONN *conn +); + +void spider_free_conn_thread( + SPIDER_CONN *conn +); + +void spider_bg_conn_wait( + SPIDER_CONN *conn +); + +void spider_bg_all_conn_wait( + ha_spider *spider +); + +int spider_bg_all_conn_pre_next( + ha_spider *spider, + int link_idx +); + +void spider_bg_conn_break( + SPIDER_CONN *conn, + ha_spider *spider +); + +void spider_bg_all_conn_break( + ha_spider *spider +); + +bool spider_bg_conn_get_job( + SPIDER_CONN *conn +); + +int spider_bg_conn_search( + ha_spider *spider, + int link_idx, + int first_link_idx, + bool first, + bool pre_next, + bool discard_result +); + +void spider_bg_conn_simple_action( + SPIDER_CONN *conn, + uint simple_action +); + +void *spider_bg_conn_action( + void *arg +); + +int spider_create_sts_thread( + SPIDER_SHARE *share +); + +void spider_free_sts_thread( + SPIDER_SHARE *share +); + +void *spider_bg_sts_action( + void *arg +); + +int spider_create_crd_thread( + SPIDER_SHARE *share +); + +void spider_free_crd_thread( + SPIDER_SHARE *share +); + +void *spider_bg_crd_action( + void *arg +); + +int spider_create_mon_threads( + SPIDER_TRX *trx, + SPIDER_SHARE *share +); + +void spider_free_mon_threads( + SPIDER_SHARE *share +); + +void *spider_bg_mon_action( + void *arg +); +#endif + +int spider_conn_first_link_idx( + THD *thd, + long *link_statuses, + long *access_balances, + uint *conn_link_idx, + int link_count, + int link_status +); + +int spider_conn_next_link_idx( + THD *thd, + long *link_statuses, + long *access_balances, + uint *conn_link_idx, + int link_idx, + int link_count, + int link_status +); + +int spider_conn_link_idx_next( + long *link_statuses, + uint *conn_link_idx, + int link_idx, + int link_count, + int link_status +); + +int spider_conn_lock_mode( + ha_spider *spider +); + +bool spider_conn_check_recovery_link( + SPIDER_SHARE *share +); + +bool spider_conn_use_handler( + ha_spider *spider, + int lock_mode, + int link_idx +); + +bool spider_conn_need_open_handler( + ha_spider *spider, + uint idx, + int link_idx +); diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc new file mode 100644 index 00000000000..7c7d3836a00 --- /dev/null +++ b/storage/spider/spd_copy_tables.cc @@ -0,0 +1,1343 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_base.h" +#include "sql_partition.h" +#include "transaction.h" +#endif +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_sys_table.h" +#include "spd_table.h" +#include "spd_copy_tables.h" +#include "spd_udf.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +int spider_udf_set_copy_tables_param_default( + SPIDER_COPY_TABLES *copy_tables +) { + DBUG_ENTER("spider_udf_set_copy_tables_param_default"); + + if (!copy_tables->database) + { + DBUG_PRINT("info",("spider create default database")); + copy_tables->database_length = copy_tables->trx->thd->db_length; + if ( + !(copy_tables->database = spider_create_string( + copy_tables->trx->thd->db, + copy_tables->database_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (copy_tables->bulk_insert_interval == -1) + copy_tables->bulk_insert_interval = 10; + if (copy_tables->bulk_insert_rows == -1) + copy_tables->bulk_insert_rows = 100; + if (copy_tables->use_table_charset == -1) + copy_tables->use_table_charset = 1; + if (copy_tables->use_transaction == -1) + copy_tables->use_transaction = 1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (copy_tables->bg_mode == -1) + copy_tables->bg_mode = 0; +#endif + DBUG_RETURN(0); +} + +#define SPIDER_PARAM_STR_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!copy_tables->param_name) \ + { \ + if ((copy_tables->param_name = spider_get_string_between_quote( \ + start_ptr, TRUE))) \ + copy_tables->SPIDER_PARAM_STR_LEN(param_name) = \ + strlen(copy_tables->param_name); \ + else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%s", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_HINT_WITH_MAX(title_name, param_name, check_length, max_size, min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(tmp_ptr + check_length) - 1; \ + DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \ + DBUG_PRINT("info",("spider copy_tables->param_name=%x", \ + copy_tables->param_name)); \ + if (copy_tables->param_name) \ + { \ + if (hint_num < 0 || hint_num >= max_size) \ + { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } else if (copy_tables->param_name[hint_num] != -1) \ + break; \ + char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \ + if (hint_str) \ + { \ + copy_tables->param_name[hint_num] = atoi(hint_str); \ + if (copy_tables->param_name[hint_num] < min_val) \ + copy_tables->param_name[hint_num] = min_val; \ + else if (copy_tables->param_name[hint_num] > max_val) \ + copy_tables->param_name[hint_num] = max_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"[%d]=%d", hint_num, \ + copy_tables->param_name[hint_num])); \ + } else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (copy_tables->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + copy_tables->param_name = atoi(tmp_ptr2); \ + if (copy_tables->param_name < min_val) \ + copy_tables->param_name = min_val; \ + else if (copy_tables->param_name > max_val) \ + copy_tables->param_name = max_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (copy_tables->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + copy_tables->param_name = atoi(tmp_ptr2); \ + if (copy_tables->param_name < min_val) \ + copy_tables->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (copy_tables->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + copy_tables->param_name = \ + my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \ + if (copy_tables->param_name < min_val) \ + copy_tables->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%lld", \ + copy_tables->param_name)); \ + } \ + break; \ + } + +int spider_udf_parse_copy_tables_param( + SPIDER_COPY_TABLES *copy_tables, + char *param, + int param_length +) { + int error_num = 0; + char *param_string = NULL; + char *sprit_ptr[2]; + char *tmp_ptr, *tmp_ptr2, *start_ptr; + int title_length; + DBUG_ENTER("spider_udf_parse_copy_tables_param"); + copy_tables->bulk_insert_interval = -1; + copy_tables->bulk_insert_rows = -1; + copy_tables->use_table_charset = -1; + copy_tables->use_transaction = -1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + copy_tables->bg_mode = -1; +#endif + + if (param_length == 0) + goto set_default; + DBUG_PRINT("info",("spider create param_string string")); + if ( + !(param_string = spider_create_string( + param, + param_length)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_alloc_param_string; + } + DBUG_PRINT("info",("spider param_string=%s", param_string)); + + sprit_ptr[0] = param_string; + while (sprit_ptr[0]) + { + if ((sprit_ptr[1] = strchr(sprit_ptr[0], ','))) + { + *sprit_ptr[1] = '\0'; + sprit_ptr[1]++; + } + tmp_ptr = sprit_ptr[0]; + sprit_ptr[0] = sprit_ptr[1]; + while (*tmp_ptr == ' ' || *tmp_ptr == '\r' || + *tmp_ptr == '\n' || *tmp_ptr == '\t') + tmp_ptr++; + + if (*tmp_ptr == '\0') + continue; + + title_length = 0; + start_ptr = tmp_ptr; + while (*start_ptr != ' ' && *start_ptr != '\'' && + *start_ptr != '"' && *start_ptr != '\0' && + *start_ptr != '\r' && *start_ptr != '\n' && + *start_ptr != '\t') + { + title_length++; + start_ptr++; + } + + switch (title_length) + { + case 0: + continue; + case 3: +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_INT_WITH_MAX("bgm", bg_mode, 0, 1); +#endif + SPIDER_PARAM_INT("bii", bulk_insert_interval, 0); + SPIDER_PARAM_LONGLONG("bir", bulk_insert_rows, 1); + SPIDER_PARAM_STR("dtb", database); + SPIDER_PARAM_INT_WITH_MAX("utc", use_table_charset, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("utr", use_transaction, 0, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; +#ifndef WITHOUT_SPIDER_BG_SEARCH + case 7: + SPIDER_PARAM_INT_WITH_MAX("bg_mode", bg_mode, 0, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; +#endif + case 8: + SPIDER_PARAM_STR("database", database); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 15: + SPIDER_PARAM_INT_WITH_MAX("use_transaction", use_transaction, 0, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 16: + SPIDER_PARAM_LONGLONG("bulk_insert_rows", bulk_insert_rows, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 17: + SPIDER_PARAM_INT_WITH_MAX( + "use_table_charset", use_table_charset, 0, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 20: + SPIDER_PARAM_INT("bulk_insert_interval", bulk_insert_interval, 0); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + default: + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + } + } + +set_default: + if ((error_num = spider_udf_set_copy_tables_param_default( + copy_tables + ))) + goto error; + + if (param_string) + spider_free(spider_current_trx, param_string, MYF(0)); + DBUG_RETURN(0); + +error: + if (param_string) + spider_free(spider_current_trx, param_string, MYF(0)); +error_alloc_param_string: + DBUG_RETURN(error_num); +} + +int spider_udf_get_copy_tgt_tables( + THD *thd, + SPIDER_COPY_TABLES *copy_tables, + MEM_ROOT *mem_root, + bool need_lock +) { + int error_num, roop_count; + TABLE *table_tables = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + char table_key[MAX_KEY_LENGTH]; + SPIDER_COPY_TABLE_CONN *table_conn = NULL, *src_table_conn_prev = NULL, + *dst_table_conn_prev = NULL; + SPIDER_SHARE *tmp_share; + char **tmp_connect_info; + uint *tmp_connect_info_length; + long *tmp_long; + longlong *tmp_longlong; + DBUG_ENTER("spider_udf_get_copy_tgt_tables"); + + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, + need_lock, &error_num)) + ) { + my_error(error_num, MYF(0)); + goto error; + } + spider_store_db_and_table_name(table_tables, + copy_tables->spider_db_name, copy_tables->spider_db_name_length, + copy_tables->spider_table_name, copy_tables->spider_table_name_length + ); + if ((error_num = spider_get_sys_table_by_idx(table_tables, table_key, + table_tables->s->primary_key, 2))) + { + table_tables->file->print_error(error_num, MYF(0)); + goto error; + } + do { + if (!(table_conn = (SPIDER_COPY_TABLE_CONN *) + spider_bulk_malloc(spider_current_trx, 25, MYF(MY_WME | MY_ZEROFILL), + &table_conn, sizeof(SPIDER_COPY_TABLE_CONN), + &tmp_share, sizeof(SPIDER_SHARE), + &tmp_connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT, + &tmp_connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT, + &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT, + &tmp_longlong, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT, + NullS)) + ) { + spider_sys_index_end(table_tables); + error_num = HA_ERR_OUT_OF_MEM; + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + spider_set_tmp_share_pointer(tmp_share, tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + tmp_share->link_statuses[0] = -1; + table_conn->share = tmp_share; + + if ( + (error_num = spider_get_sys_tables_connect_info( + table_tables, tmp_share, 0, mem_root)) || + (error_num = spider_get_sys_tables_link_status( + table_tables, tmp_share, 0, mem_root)) || + (error_num = spider_get_sys_tables_link_idx( + table_tables, &table_conn->link_idx, mem_root)) + ) { + table_tables->file->print_error(error_num, MYF(0)); + spider_sys_index_end(table_tables); + goto error; + } + if ( + (error_num = spider_set_connect_info_default( + tmp_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + NULL, + NULL, +#endif + NULL + )) || + (error_num = spider_set_connect_info_default_db_table( + tmp_share, + copy_tables->spider_db_name, copy_tables->spider_db_name_length, + copy_tables->spider_table_name, copy_tables->spider_table_name_length + )) || + (error_num = spider_create_conn_keys(tmp_share)) || + (error_num = spider_create_tmp_dbton_share(tmp_share)) + ) { + spider_sys_index_end(table_tables); + goto error; + } + +/* + if (spider_db_create_table_names_str(tmp_share)) + { + spider_sys_index_end(table_tables); + error_num = HA_ERR_OUT_OF_MEM; + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } +*/ + + for (roop_count = 0; roop_count < (int) tmp_share->use_dbton_count; + roop_count++) + { + uint dbton_id = tmp_share->use_dbton_ids[roop_count]; + + if (!spider_dbton[dbton_id].create_db_copy_table) + continue; + + if (!(table_conn->copy_table = + spider_dbton[dbton_id].create_db_copy_table( + tmp_share->dbton_share[dbton_id]))) + { + spider_sys_index_end(table_tables); + error_num = HA_ERR_OUT_OF_MEM; + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + if ((error_num = table_conn->copy_table->init())) + goto error; + break; + } + + if ( + !copy_tables->use_auto_mode[0] + ) { + for (roop_count = 0; roop_count < copy_tables->link_idx_count[0]; + roop_count++) + { + if (table_conn->link_idx == copy_tables->link_idxs[0][roop_count]) + { + if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) + { + spider_sys_index_end(table_tables); + error_num = ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_NUM; + my_printf_error(ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_NUM, + ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_STR, MYF(0)); + goto error; + } + if (src_table_conn_prev) + src_table_conn_prev->next = table_conn; + else + copy_tables->table_conn[0] = table_conn; + src_table_conn_prev = table_conn; + table_conn = NULL; + break; + } + } + } + if (table_conn && !copy_tables->use_auto_mode[1]) + { + for (roop_count = 0; roop_count < copy_tables->link_idx_count[1]; + roop_count++) + { + if (table_conn->link_idx == copy_tables->link_idxs[1][roop_count]) + { + if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) + { + spider_sys_index_end(table_tables); + error_num = ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_NUM; + my_printf_error(ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_NUM, + ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_STR, MYF(0)); + goto error; + } + if (dst_table_conn_prev) + dst_table_conn_prev->next = table_conn; + else + copy_tables->table_conn[1] = table_conn; + dst_table_conn_prev = table_conn; + table_conn = NULL; + break; + } + } + } + if (table_conn && copy_tables->use_auto_mode[0] && + tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_OK) + { + if (src_table_conn_prev) + src_table_conn_prev->next = table_conn; + else + copy_tables->table_conn[0] = table_conn; + src_table_conn_prev = table_conn; + copy_tables->link_idx_count[0]++; + table_conn = NULL; + } + if (table_conn && copy_tables->use_auto_mode[1] && + tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_RECOVERY) + { + if (dst_table_conn_prev) + dst_table_conn_prev->next = table_conn; + else + copy_tables->table_conn[1] = table_conn; + dst_table_conn_prev = table_conn; + copy_tables->link_idx_count[1]++; + table_conn = NULL; + } + if (table_conn) + { + spider_free_tmp_dbton_share(tmp_share); + spider_free_tmp_share_alloc(tmp_share); + if (table_conn->copy_table) + delete table_conn->copy_table; + spider_free(spider_current_trx, table_conn, MYF(0)); + table_conn = NULL; + } + + error_num = spider_sys_index_next_same(table_tables, table_key); + } while (error_num == 0); + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + + if (!copy_tables->table_conn[0]) + { + error_num = ER_SPIDER_UDF_COPY_TABLE_SRC_NOT_FOUND_NUM; + my_printf_error(ER_SPIDER_UDF_COPY_TABLE_SRC_NOT_FOUND_NUM, + ER_SPIDER_UDF_COPY_TABLE_SRC_NOT_FOUND_STR, MYF(0)); + goto error; + } + if (!copy_tables->table_conn[1]) + { + error_num = ER_SPIDER_UDF_COPY_TABLE_DST_NOT_FOUND_NUM; + my_printf_error(ER_SPIDER_UDF_COPY_TABLE_DST_NOT_FOUND_NUM, + ER_SPIDER_UDF_COPY_TABLE_DST_NOT_FOUND_STR, MYF(0)); + goto error; + } + + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + if (table_conn) + { + spider_free_tmp_dbton_share(tmp_share); + spider_free_tmp_share_alloc(tmp_share); + if (table_conn->copy_table) + delete table_conn->copy_table; + spider_free(spider_current_trx, table_conn, MYF(0)); + } + DBUG_RETURN(error_num); +} + +int spider_udf_get_copy_tgt_conns( + SPIDER_COPY_TABLES *copy_tables +) { + int error_num, roop_count; + SPIDER_TRX *trx = copy_tables->trx; + SPIDER_SHARE *share; + SPIDER_COPY_TABLE_CONN *table_conn; + DBUG_ENTER("spider_udf_get_copy_tgt_conns"); + for (roop_count = 0; roop_count < 2; roop_count++) + { + table_conn = copy_tables->table_conn[roop_count]; + while (table_conn) + { + share = table_conn->share; + if ( + !(table_conn->conn = spider_get_conn( + share, 0, share->conn_keys[0], trx, NULL, FALSE, FALSE, + SPIDER_CONN_KIND_MYSQL, &error_num)) + ) { + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), share->server_names[0]); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + table_conn->conn->error_mode = 0; + table_conn = table_conn->next; + } + } + DBUG_RETURN(0); +} + +void spider_udf_free_copy_tables_alloc( + SPIDER_COPY_TABLES *copy_tables +) { + int roop_count; + SPIDER_COPY_TABLE_CONN *table_conn, *table_conn_next; + DBUG_ENTER("spider_udf_free_copy_tables_alloc"); + for (roop_count = 0; roop_count < 2; roop_count++) + { + table_conn = copy_tables->table_conn[roop_count]; + while (table_conn) + { + table_conn_next = table_conn->next; + spider_free_tmp_dbton_share(table_conn->share); + spider_free_tmp_share_alloc(table_conn->share); + if (table_conn->copy_table) + delete table_conn->copy_table; + spider_free(spider_current_trx, table_conn, MYF(0)); + table_conn = table_conn_next; + } + } + if (copy_tables->link_idxs[0]) + spider_free(spider_current_trx, copy_tables->link_idxs[0], MYF(0)); + if (copy_tables->database) + spider_free(spider_current_trx, copy_tables->database, MYF(0)); + spider_free(spider_current_trx, copy_tables, MYF(0)); + DBUG_VOID_RETURN; +} + +int spider_udf_copy_tables_create_table_list( + SPIDER_COPY_TABLES *copy_tables, + char *spider_table_name, + uint spider_table_name_length, + char *src_link_idx_list, + uint src_link_idx_list_length, + char *dst_link_idx_list, + uint dst_link_idx_list_length +) { + int roop_count, roop_count2, length; + char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *tmp_name_ptr; + DBUG_ENTER("spider_udf_copy_tables_create_table_list"); + + if (!spider_table_name_length) + { + my_printf_error(ER_SPIDER_BLANK_UDF_ARGUMENT_NUM, + ER_SPIDER_BLANK_UDF_ARGUMENT_STR, MYF(0), 1); + DBUG_RETURN(ER_SPIDER_BLANK_UDF_ARGUMENT_NUM); + } + + for (roop_count2 = 0; roop_count2 < 2; roop_count2++) + { + if (roop_count2 == 0) + tmp_ptr = src_link_idx_list; + else + tmp_ptr = dst_link_idx_list; + + while (*tmp_ptr == ' ') + tmp_ptr++; + if (*tmp_ptr) + copy_tables->link_idx_count[roop_count2] = 1; + else { + /* use auto detect */ + copy_tables->use_auto_mode[roop_count2] = TRUE; + copy_tables->link_idx_count[roop_count2] = 0; + continue; + } + + while (TRUE) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + { + copy_tables->link_idx_count[roop_count2]++; + tmp_ptr = tmp_ptr2 + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + } else + break; + } + } + + if (!(copy_tables->link_idxs[0] = (int *) + spider_bulk_malloc(spider_current_trx, 26, MYF(MY_WME | MY_ZEROFILL), + ©_tables->link_idxs[0], + sizeof(int) * copy_tables->link_idx_count[0], + ©_tables->link_idxs[1], + sizeof(int) * copy_tables->link_idx_count[1], + &tmp_name_ptr, sizeof(char) * ( + spider_table_name_length * 2 + copy_tables->database_length + 2 + ), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + copy_tables->spider_db_name = tmp_name_ptr; + if ((tmp_ptr3 = strchr(spider_table_name, '.'))) + { + /* exist database name */ + *tmp_ptr3 = '\0'; + length = strlen(spider_table_name); + memcpy(tmp_name_ptr, spider_table_name, length + 1); + copy_tables->spider_db_name_length = length; + tmp_name_ptr += length + 1; + tmp_ptr3++; + } else { + memcpy(tmp_name_ptr, copy_tables->database, + copy_tables->database_length + 1); + copy_tables->spider_db_name_length = copy_tables->database_length; + tmp_name_ptr += copy_tables->database_length + 1; + tmp_ptr3 = spider_table_name; + length = -1; + } + copy_tables->spider_table_name = tmp_name_ptr; + length = spider_table_name_length - length - 1; + memcpy(tmp_name_ptr, tmp_ptr3, length + 1); + copy_tables->spider_table_name_length = length; + tmp_name_ptr += length + 1; + memcpy(tmp_name_ptr, tmp_ptr3, length + 1); + copy_tables->spider_real_table_name = tmp_name_ptr; + if ((tmp_ptr2 = strstr(tmp_name_ptr, "#P#"))) + { + *tmp_ptr2 = '\0'; + copy_tables->spider_real_table_name_length = strlen(tmp_name_ptr); + } else + copy_tables->spider_real_table_name_length = length; + + DBUG_PRINT("info",("spider spider_db=%s", copy_tables->spider_db_name)); + DBUG_PRINT("info",("spider spider_table_name=%s", + copy_tables->spider_table_name)); + DBUG_PRINT("info",("spider spider_real_table_name=%s", + copy_tables->spider_real_table_name)); + + for (roop_count2 = 0; roop_count2 < 2; roop_count2++) + { + if (roop_count2 == 0) + tmp_ptr = src_link_idx_list; + else + tmp_ptr = dst_link_idx_list; + + while (*tmp_ptr == ' ') + tmp_ptr++; + roop_count = 0; + while (*tmp_ptr) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + *tmp_ptr2 = '\0'; + + copy_tables->link_idxs[roop_count2][roop_count] = atoi(tmp_ptr); + + DBUG_PRINT("info",("spider link_idx[%d][%d]=%d", + roop_count2, roop_count, + copy_tables->link_idxs[roop_count2][roop_count])); + if (!tmp_ptr2) + break; + + tmp_ptr = tmp_ptr2 + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + roop_count++; + } + } + DBUG_RETURN(0); +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_udf_bg_copy_exec_sql( + SPIDER_COPY_TABLE_CONN *table_conn +) { + int error_num; + SPIDER_CONN *conn = table_conn->conn; + ha_spider *spider = table_conn->spider; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_udf_bg_copy_exec_sql"); + if ((error_num = spider_create_conn_thread(conn))) + DBUG_RETURN(error_num); + if ((error_num = dbton_hdl->set_sql_for_exec(table_conn->copy_table, + SPIDER_SQL_TYPE_INSERT_SQL))) + DBUG_RETURN(error_num); + pthread_mutex_lock(&conn->bg_conn_mutex); + conn->bg_target = spider; + conn->bg_error_num = &table_conn->bg_error_num; + conn->bg_sql_type = SPIDER_SQL_TYPE_INSERT_SQL; + conn->link_idx = 0; + conn->bg_exec_sql = TRUE; + conn->bg_caller_sync_wait = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_sync_wait = FALSE; + DBUG_RETURN(0); +} +#endif + +long long spider_copy_tables_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + int error_num, roop_count, all_link_cnt = 0, use_table_charset; + SPIDER_COPY_TABLES *copy_tables = NULL; + THD *thd = current_thd; + TABLE_LIST *table_list = NULL; + TABLE *table; + TABLE_SHARE *table_share; + KEY *key_info; + ha_spider *spider = NULL, *tmp_spider; + spider_string *tmp_sql = NULL; + SPIDER_COPY_TABLE_CONN *table_conn, *src_tbl_conn, *dst_tbl_conn; + SPIDER_CONN *tmp_conn; + spider_db_copy_table *select_ct, *insert_ct; + MEM_ROOT mem_root; + longlong bulk_insert_rows; + Reprepare_observer *reprepare_observer_backup; + DBUG_ENTER("spider_copy_tables_body"); + if ( + thd->open_tables != 0 || + thd->handler_tables_hash.records != 0 || + thd->derived_tables != 0 || + thd->lock != 0 || +#if MYSQL_VERSION_ID < 50500 + thd->locked_tables != 0 || + thd->prelocked_mode != NON_PRELOCKED +#else + thd->locked_tables_list.locked_tables() || + thd->locked_tables_mode != LTM_NONE +#endif + ) { + if (thd->open_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->open_tables", thd->open_tables); + } else if (thd->handler_tables_hash.records != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->handler_tables_hash.records", + (longlong) thd->handler_tables_hash.records); + } else if (thd->derived_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->derived_tables", thd->derived_tables); + } else if (thd->lock != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->lock", thd->lock); +#if MYSQL_VERSION_ID < 50500 + } else if (thd->locked_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->locked_tables", thd->locked_tables); + } else if (thd->prelocked_mode != NON_PRELOCKED) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->prelocked_mode", (longlong) thd->prelocked_mode); +#else + } else if (thd->locked_tables_list.locked_tables()) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->locked_tables_list.locked_tables()", + thd->locked_tables_list.locked_tables()); + } else if (thd->locked_tables_mode != LTM_NONE) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); +#endif + } + goto error; + } + + if (!(copy_tables = (SPIDER_COPY_TABLES *) + spider_bulk_malloc(spider_current_trx, 27, MYF(MY_WME | MY_ZEROFILL), + ©_tables, sizeof(SPIDER_COPY_TABLES), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + if (!(copy_tables->trx = spider_get_trx(thd, TRUE, &error_num))) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + if (args->arg_count == 4) + { + if (spider_udf_parse_copy_tables_param( + copy_tables, + args->args[3] ? args->args[3] : (char *) "", + args->args[3] ? args->lengths[3] : 0 + )) + goto error; + } else { + if (spider_udf_parse_copy_tables_param( + copy_tables, + (char *) "", + 0 + )) + goto error; + } + if ( + spider_udf_copy_tables_create_table_list( + copy_tables, + args->args[0], + args->lengths[0], + args->args[1] ? args->args[1] : (char *) "", + args->args[1] ? args->lengths[1] : 0, + args->args[2] ? args->args[2] : (char *) "", + args->args[2] ? args->lengths[2] : 0 + ) + ) + goto error; + + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ( + spider_udf_get_copy_tgt_tables( + thd, + copy_tables, + &mem_root, + TRUE + ) + ) { + free_root(&mem_root, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + + if ( + spider_udf_get_copy_tgt_conns(copy_tables) + ) + goto error; + + table_list = ©_tables->spider_table_list; + table_list->db = copy_tables->spider_db_name; + table_list->db_length = copy_tables->spider_db_name_length; + table_list->alias = table_list->table_name = + copy_tables->spider_real_table_name; + table_list->table_name_length = copy_tables->spider_real_table_name_length; + table_list->lock_type = TL_READ; + + DBUG_PRINT("info",("spider db=%s", table_list->db)); + DBUG_PRINT("info",("spider db_length=%zd", table_list->db_length)); + DBUG_PRINT("info",("spider table_name=%s", table_list->table_name)); + DBUG_PRINT("info",("spider table_name_length=%zd", + table_list->table_name_length)); + reprepare_observer_backup = thd->m_reprepare_observer; + thd->m_reprepare_observer = NULL; +#if MYSQL_VERSION_ID < 50500 + if (open_and_lock_tables(thd, table_list)) +#else + table_list->mdl_request.init( + MDL_key::TABLE, + table_list->db, + table_list->table_name, + MDL_SHARED_READ, + MDL_TRANSACTION + ); + if (open_and_lock_tables(thd, table_list, FALSE, 0)) +#endif + { + thd->m_reprepare_observer = reprepare_observer_backup; + my_printf_error(ER_SPIDER_UDF_CANT_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_OPEN_TABLE_STR, MYF(0), table_list->db, + table_list->table_name); + goto error; + } + thd->m_reprepare_observer = reprepare_observer_backup; + + table = table_list->table; + table_share = table->s; + if (table_share->primary_key == MAX_KEY) + { + my_printf_error(ER_SPIDER_UDF_COPY_TABLE_NEED_PK_NUM, + ER_SPIDER_UDF_COPY_TABLE_NEED_PK_STR, MYF(0), + table_list->db, table_list->table_name); + goto error; + } + key_info = &table->key_info[table_share->primary_key]; + + use_table_charset = spider_param_use_table_charset( + copy_tables->use_table_charset); + if (use_table_charset) + copy_tables->access_charset = table_share->table_charset; + else + copy_tables->access_charset = system_charset_info; + + src_tbl_conn = copy_tables->table_conn[0]; + select_ct = src_tbl_conn->copy_table; + src_tbl_conn->share->access_charset = copy_tables->access_charset; + select_ct->set_sql_charset(copy_tables->access_charset); + if ( + select_ct->append_select_str() || + select_ct->append_table_columns(table_share) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + if ( + select_ct->append_from_str() || + select_ct->append_table_name(0) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + select_ct->set_sql_pos(); + + bulk_insert_rows = spider_param_udf_ct_bulk_insert_rows( + copy_tables->bulk_insert_rows); + if ( + select_ct->append_key_order_str(key_info, 0, FALSE) || + select_ct->append_limit(0, bulk_insert_rows) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + insert_ct = dst_tbl_conn->copy_table; + dst_tbl_conn->share->access_charset = copy_tables->access_charset; + insert_ct->set_sql_charset(copy_tables->access_charset); + if ( + insert_ct->append_insert_str(SPIDER_DB_INSERT_IGNORE) || + insert_ct->append_into_str() || + insert_ct->append_table_name(0) || + insert_ct->append_open_paren_str() || + insert_ct->append_table_columns(table_share) || + insert_ct->append_values_str() + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + insert_ct->set_sql_pos(); + } + + all_link_cnt = + copy_tables->link_idx_count[0] + copy_tables->link_idx_count[1]; + if ( + !(tmp_sql = new spider_string[all_link_cnt]) || + !(spider = new ha_spider[all_link_cnt]) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + spider[roop_count].conns = NULL; + } + for (roop_count = 0, table_conn = copy_tables->table_conn[0]; + table_conn; roop_count++, table_conn = table_conn->next) + { + tmp_spider = &spider[roop_count]; + if (!(tmp_spider->dbton_handler = (spider_db_handler **) + spider_bulk_alloc_mem(spider_current_trx, 205, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &tmp_spider->dbton_handler, + sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + tmp_spider->share = table_conn->share; + tmp_spider->trx = copy_tables->trx; +/* + if (spider_db_append_set_names(table_conn->share)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_append_set_names; + } +*/ + tmp_spider->conns = &table_conn->conn; + tmp_sql[roop_count].init_calc_mem(122); + tmp_sql[roop_count].set_charset(copy_tables->access_charset); + tmp_spider->result_list.sqls = &tmp_sql[roop_count]; + tmp_spider->need_mons = &table_conn->need_mon; + tmp_spider->lock_type = TL_READ; + uint dbton_id = tmp_spider->share->use_dbton_ids[0]; + if (!(tmp_spider->dbton_handler[dbton_id] = + spider_dbton[dbton_id].create_db_handler(tmp_spider, + tmp_spider->share->dbton_share[dbton_id]))) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_create_dbton_handler; + } + if ((error_num = tmp_spider->dbton_handler[dbton_id]->init())) + { + goto error_init_dbton_handler; + } + table_conn->spider = tmp_spider; + } + for (table_conn = copy_tables->table_conn[1]; + table_conn; roop_count++, table_conn = table_conn->next) + { + tmp_spider = &spider[roop_count]; + if (!(tmp_spider->dbton_handler = (spider_db_handler **) + spider_bulk_alloc_mem(spider_current_trx, 206, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &tmp_spider->dbton_handler, + sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + tmp_spider->share = table_conn->share; + tmp_spider->trx = copy_tables->trx; +/* + if (spider_db_append_set_names(table_conn->share)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_append_set_names; + } +*/ + tmp_spider->conns = &table_conn->conn; + tmp_sql[roop_count].init_calc_mem(201); + tmp_sql[roop_count].set_charset(copy_tables->access_charset); + tmp_spider->result_list.sqls = &tmp_sql[roop_count]; + tmp_spider->need_mons = &table_conn->need_mon; + tmp_spider->lock_type = TL_WRITE; + uint dbton_id = tmp_spider->share->use_dbton_ids[0]; + if (!(tmp_spider->dbton_handler[dbton_id] = + spider_dbton[dbton_id].create_db_handler(tmp_spider, + tmp_spider->share->dbton_share[dbton_id]))) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_create_dbton_handler; + } + if ((error_num = tmp_spider->dbton_handler[dbton_id]->init())) + { + goto error_init_dbton_handler; + } + table_conn->spider = tmp_spider; + } + + if ( + copy_tables->use_transaction && + select_ct->append_select_lock_str(SPIDER_LOCK_MODE_SHARED) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + + if ((error_num = spider_db_udf_copy_tables(copy_tables, spider, table, + bulk_insert_rows))) + goto error_db_udf_copy_tables; + +/* + for (table_conn = copy_tables->table_conn[0]; + table_conn; table_conn = table_conn->next) + spider_db_free_set_names(table_conn->share); + for (table_conn = copy_tables->table_conn[1]; + table_conn; table_conn = table_conn->next) + spider_db_free_set_names(table_conn->share); +*/ + if (table_list->table) + { +#if MYSQL_VERSION_ID < 50500 + ha_autocommit_or_rollback(thd, 0); +#else + (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); +#endif + close_thread_tables(thd); + } + if (spider) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + if (spider[roop_count].share && spider[roop_count].dbton_handler) + { + uint dbton_id = spider[roop_count].share->use_dbton_ids[0]; + if (spider[roop_count].dbton_handler[dbton_id]) + delete spider[roop_count].dbton_handler[dbton_id]; + spider_free(spider_current_trx, spider[roop_count].dbton_handler, + MYF(0)); + } + } + delete [] spider; + } + if (tmp_sql) + delete [] tmp_sql; + spider_udf_free_copy_tables_alloc(copy_tables); + + DBUG_RETURN(1); + +error_db_udf_copy_tables: +error_create_dbton_handler: +error_init_dbton_handler: +/* +error_append_set_names: +*/ +/* + for (table_conn = copy_tables->table_conn[0]; + table_conn; table_conn = table_conn->next) + spider_db_free_set_names(table_conn->share); + for (table_conn = copy_tables->table_conn[1]; + table_conn; table_conn = table_conn->next) + spider_db_free_set_names(table_conn->share); +*/ +error: + if (spider) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + if (tmp_spider->conns) + { + tmp_conn = tmp_spider->conns[0]; + if (tmp_conn && tmp_conn->db_conn && + tmp_conn->db_conn->get_lock_table_hash_count() + ) { + tmp_conn->db_conn->reset_lock_table_hash(); + tmp_conn->table_lock = 0; + } + } + } + } + if (table_list && table_list->table) + { +#if MYSQL_VERSION_ID < 50500 + ha_autocommit_or_rollback(thd, 0); +#else + (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); +#endif + close_thread_tables(thd); + } + if (spider) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + if (tmp_spider->share && spider[roop_count].dbton_handler) + { + uint dbton_id = tmp_spider->share->use_dbton_ids[0]; + if (tmp_spider->dbton_handler[dbton_id]) + delete tmp_spider->dbton_handler[dbton_id]; + spider_free(spider_current_trx, spider[roop_count].dbton_handler, + MYF(0)); + } + } + delete [] spider; + } + if (tmp_sql) + { + delete [] tmp_sql; + } + if (copy_tables) + spider_udf_free_copy_tables_alloc(copy_tables); + *error = 1; + DBUG_RETURN(0); +} + +my_bool spider_copy_tables_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + DBUG_ENTER("spider_copy_tables_init_body"); + if (args->arg_count != 3 && args->arg_count != 4) + { + strcpy(message, "spider_copy_tables() requires 3 or 4 arguments"); + goto error; + } + if ( + args->arg_type[0] != STRING_RESULT || + args->arg_type[1] != STRING_RESULT || + args->arg_type[2] != STRING_RESULT || + ( + args->arg_count == 4 && + args->arg_type[3] != STRING_RESULT + ) + ) { + strcpy(message, "spider_copy_tables() requires string arguments"); + goto error; + } + DBUG_RETURN(FALSE); + +error: + DBUG_RETURN(TRUE); +} + +void spider_copy_tables_deinit_body( + UDF_INIT *initid +) { + int error_num; + THD *thd = current_thd; + SPIDER_TRX *trx; + DBUG_ENTER("spider_copy_tables_deinit_body"); + if ( + !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) && + (trx = spider_get_trx(thd, TRUE, &error_num)) + ) + spider_free_trx_conn(trx, FALSE); + DBUG_VOID_RETURN; +} diff --git a/storage/spider/spd_copy_tables.h b/storage/spider/spd_copy_tables.h new file mode 100644 index 00000000000..88612d1dd12 --- /dev/null +++ b/storage/spider/spd_copy_tables.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2010-2013 Kentoku Shiba + + 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 */ + +int spider_udf_set_copy_tables_param_default( + SPIDER_COPY_TABLES *copy_tables +); + +int spider_udf_parse_copy_tables_param( + SPIDER_COPY_TABLES *copy_tables, + char *param, + int param_length +); + +int spider_udf_get_copy_tgt_tables( + THD *thd, + SPIDER_COPY_TABLES *copy_tables, + MEM_ROOT *mem_root, + bool need_lock +); + +int spider_udf_get_copy_tgt_conns( + SPIDER_COPY_TABLES *copy_tables +); + +void spider_udf_free_copy_tables_alloc( + SPIDER_COPY_TABLES *copy_tables +); + +int spider_udf_copy_tables_create_table_list( + SPIDER_COPY_TABLES *copy_tables, + char *spider_table_name, + uint spider_table_name_length, + char *src_link_idx_list, + uint src_link_idx_list_length, + char *dst_link_idx_list, + uint dst_link_idx_list_length +); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_udf_bg_copy_exec_sql( + SPIDER_COPY_TABLE_CONN *table_conn +); +#endif diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc new file mode 100644 index 00000000000..adf40c3ff94 --- /dev/null +++ b/storage/spider/spd_db_conn.cc @@ -0,0 +1,9729 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_analyse.h" +#include "sql_base.h" +#include "tztime.h" +#endif +#include "sql_common.h" +#include +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_sys_table.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_table.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_direct_sql.h" +#include "spd_ping_table.h" +#include "spd_copy_tables.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +#define SPIDER_SQL_COALESCE_STR "coalesce(" +#define SPIDER_SQL_COALESCE_LEN (sizeof(SPIDER_SQL_COALESCE_STR) - 1) +#define SPIDER_SQL_HEX_STR "0x" +#define SPIDER_SQL_HEX_LEN (sizeof(SPIDER_SQL_HEX_STR) - 1) +#define SPIDER_SQL_SQL_FORCE_IDX_STR " force index(" +#define SPIDER_SQL_SQL_FORCE_IDX_LEN (sizeof(SPIDER_SQL_SQL_FORCE_IDX_STR) - 1) +#define SPIDER_SQL_SQL_USE_IDX_STR " use index(" +#define SPIDER_SQL_SQL_USE_IDX_LEN (sizeof(SPIDER_SQL_SQL_USE_IDX_STR) - 1) +#define SPIDER_SQL_SQL_IGNORE_IDX_STR " ignore index(" +#define SPIDER_SQL_SQL_IGNORE_IDX_LEN (sizeof(SPIDER_SQL_SQL_IGNORE_IDX_STR) - 1) + +#define SPIDER_SQL_SET_NAMES_STR "set names " +#define SPIDER_SQL_SET_NAMES_LEN sizeof(SPIDER_SQL_SET_NAMES_STR) - 1 + +#define SPIDER_SQL_PING_TABLE_STR "spider_ping_table(" +#define SPIDER_SQL_PING_TABLE_LEN (sizeof(SPIDER_SQL_PING_TABLE_STR) - 1) + +#ifdef SPIDER_HAS_HASH_VALUE_TYPE +extern HASH spider_open_connections; +#endif +pthread_mutex_t spider_open_conn_mutex; +const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +int spider_db_connect( + const SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +) { + int error_num, connect_retry_count; + THD* thd = current_thd; + longlong connect_retry_interval; + DBUG_ENTER("spider_db_connect"); + DBUG_ASSERT(conn->conn_kind != SPIDER_CONN_KIND_MYSQL || conn->need_mon); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + + if (thd) + { + conn->connect_timeout = spider_param_connect_timeout(thd, + share->connect_timeouts[link_idx]); + conn->net_read_timeout = spider_param_net_read_timeout(thd, + share->net_read_timeouts[link_idx]); + conn->net_write_timeout = spider_param_net_write_timeout(thd, + share->net_write_timeouts[link_idx]); + connect_retry_interval = spider_param_connect_retry_interval(thd); + connect_retry_count = spider_param_connect_retry_count(thd); + } else { + conn->connect_timeout = spider_param_connect_timeout(NULL, + share->connect_timeouts[link_idx]); + conn->net_read_timeout = spider_param_net_read_timeout(NULL, + share->net_read_timeouts[link_idx]); + conn->net_write_timeout = spider_param_net_write_timeout(NULL, + share->net_write_timeouts[link_idx]); + connect_retry_interval = spider_param_connect_retry_interval(NULL); + connect_retry_count = spider_param_connect_retry_count(NULL); + } + DBUG_PRINT("info",("spider connect_timeout=%u", conn->connect_timeout)); + DBUG_PRINT("info",("spider net_read_timeout=%u", conn->net_read_timeout)); + DBUG_PRINT("info",("spider net_write_timeout=%u", conn->net_write_timeout)); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if ((error_num = spider_reset_conn_setted_parameter(conn, thd))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + + if (conn->dbton_id == SPIDER_DBTON_SIZE) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + my_printf_error( + ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR, + MYF(0), conn->tgt_wrapper); + DBUG_RETURN(ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + my_printf_error( + ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_STR, + MYF(0), conn->tgt_wrapper); + DBUG_RETURN(ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM); + } +#endif + } + + if ((error_num = conn->db_conn->connect( + share->tgt_hosts[link_idx], + share->tgt_usernames[link_idx], + share->tgt_passwords[link_idx], + share->tgt_ports[link_idx], + share->tgt_sockets[link_idx], + share->server_names[link_idx], + connect_retry_count, connect_retry_interval))) + { + DBUG_RETURN(error_num); + } + conn->opened_handlers = 0; + conn->db_conn->reset_opened_handler(); + ++conn->connection_id; + DBUG_RETURN(0); +} + +int spider_db_ping( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_db_ping"); +#ifndef DBUG_OFF + if (spider->trx->thd) + DBUG_PRINT("info", ("spider thd->query_id is %lld", + spider->trx->thd->query_id)); +#endif + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if (conn->server_lost || conn->queued_connect) + { + if ((error_num = spider_db_connect(spider->share, conn, + spider->conn_link_idx[link_idx]))) + { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + conn->server_lost = FALSE; + conn->queued_connect = FALSE; + } + if ((error_num = conn->db_conn->ping())) + { + spider_db_disconnect(conn); + if ((error_num = spider_db_connect(spider->share, conn, + spider->conn_link_idx[link_idx]))) + { + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + if((error_num = conn->db_conn->ping())) + { + spider_db_disconnect(conn); + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + } + conn->ping_time = (time_t) time((time_t*) 0); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); +} + +void spider_db_disconnect( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_db_disconnect"); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->conn_kind=%u", conn->conn_kind)); + if (conn->db_conn->is_connected()) + { + conn->db_conn->disconnect(); + } + DBUG_VOID_RETURN; +} + +int spider_db_conn_queue_action( + SPIDER_CONN *conn +) { + int error_num; + char sql_buf[MAX_FIELD_WIDTH * 2]; + spider_string sql_str(sql_buf, sizeof(sql_buf), system_charset_info); + DBUG_ENTER("spider_db_conn_queue_action"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + sql_str.init_calc_mem(106); + sql_str.length(0); + if (conn->queued_connect) + { + if ((error_num = spider_db_connect(conn->queued_connect_share, conn, + conn->queued_connect_link_idx))) + { + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + DBUG_RETURN(error_num); + } + conn->server_lost = FALSE; + conn->queued_connect = FALSE; + } + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (conn->queued_ping) + { + if ((error_num = spider_db_ping(conn->queued_ping_spider, conn, + conn->queued_ping_link_idx))) + DBUG_RETURN(error_num); + conn->queued_ping = FALSE; + } + + if (conn->server_lost) + { + DBUG_PRINT("info", ("spider no reconnect queue")); + DBUG_RETURN(CR_SERVER_GONE_ERROR); + } + + if (conn->queued_net_timeout) + { + conn->db_conn->set_net_timeout(); + conn->queued_net_timeout = FALSE; + } + if ( + ( + conn->queued_trx_isolation && + !conn->queued_semi_trx_isolation && + conn->queued_trx_isolation_val != conn->trx_isolation && + conn->db_conn->set_trx_isolation_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_trx_isolation(&sql_str, conn->queued_trx_isolation_val)) + ) || + ( + conn->queued_semi_trx_isolation && + conn->queued_semi_trx_isolation_val != conn->trx_isolation && + conn->db_conn->set_trx_isolation_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_trx_isolation(&sql_str, conn->queued_semi_trx_isolation_val)) + ) || + ( + conn->queued_autocommit && + ( + (conn->queued_autocommit_val && conn->autocommit != 1) || + (!conn->queued_autocommit_val && conn->autocommit != 0) + ) && + conn->db_conn->set_autocommit_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_autocommit(&sql_str, conn->queued_autocommit_val)) + ) || + ( + conn->queued_sql_log_off && + ( + (conn->queued_sql_log_off_val && conn->sql_log_off != 1) || + (!conn->queued_sql_log_off_val && conn->sql_log_off != 0) + ) && + conn->db_conn->set_sql_log_off_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_sql_log_off(&sql_str, conn->queued_sql_log_off_val)) + ) || + ( + conn->queued_time_zone && + conn->queued_time_zone_val != conn->time_zone && + conn->db_conn->set_time_zone_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_time_zone(&sql_str, conn->queued_time_zone_val)) + ) || + ( + conn->queued_trx_start && + conn->db_conn->trx_start_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_start_transaction(&sql_str)) + ) || + ( + conn->queued_xa_start && + conn->db_conn->xa_start_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_xa_start(&sql_str, conn->queued_xa_start_xid)) + ) + ) + DBUG_RETURN(error_num); + if (sql_str.length()) + { + if ((error_num = conn->db_conn->exec_query(sql_str.ptr(), + sql_str.length(), -1))) + DBUG_RETURN(error_num); + spider_db_result *result; + do { + st_spider_db_request_key request_key; + request_key.spider_thread_id = 1; + request_key.query_id = 1; + request_key.handler = NULL; + request_key.request_id = 1; + request_key.next = NULL; + if ((result = conn->db_conn->store_result(NULL, &request_key, + &error_num))) + { + result->free_result(); + delete result; + } else if ((error_num = conn->db_conn->get_errno())) + { + break; + } + } while (!(error_num = conn->db_conn->next_result())); + if (error_num > 0) + DBUG_RETURN(error_num); + } + + if ( + conn->queued_autocommit && + ( + (conn->queued_autocommit_val && conn->autocommit != 1) || + (!conn->queued_autocommit_val && conn->autocommit != 0) + ) && + !conn->db_conn->set_autocommit_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_autocommit(&sql_str, conn->queued_autocommit_val)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_sql_log_off && + ( + (conn->queued_sql_log_off_val && conn->sql_log_off != 1) || + (!conn->queued_sql_log_off_val && conn->sql_log_off != 0) + ) && + !conn->db_conn->set_sql_log_off_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_sql_log_off(&sql_str, conn->queued_sql_log_off_val)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_time_zone && + conn->queued_time_zone_val != conn->time_zone && + !conn->db_conn->set_time_zone_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_time_zone(&sql_str, conn->queued_time_zone_val)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_trx_isolation && + !conn->queued_semi_trx_isolation && + conn->queued_trx_isolation_val != conn->trx_isolation && + !conn->db_conn->set_trx_isolation_in_bulk_sql() && + (error_num = conn->db_conn->set_trx_isolation( + conn->queued_trx_isolation_val, (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_semi_trx_isolation && + conn->queued_semi_trx_isolation_val != conn->trx_isolation && + !conn->db_conn->set_trx_isolation_in_bulk_sql() && + (error_num = conn->db_conn->set_trx_isolation( + conn->queued_semi_trx_isolation_val, (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_trx_start && + !conn->db_conn->trx_start_in_bulk_sql() && + (error_num = conn->db_conn-> + start_transaction((int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_xa_start && + !conn->db_conn->xa_start_in_bulk_sql() && + (error_num = conn->db_conn-> + xa_start(conn->queued_xa_start_xid, (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + + if ( + conn->queued_trx_isolation && + !conn->queued_semi_trx_isolation && + conn->queued_trx_isolation_val != conn->trx_isolation + ) { + conn->trx_isolation = conn->queued_trx_isolation_val; + DBUG_PRINT("info", ("spider conn->trx_isolation=%d", + conn->trx_isolation)); + } + + if ( + conn->queued_semi_trx_isolation && + conn->queued_semi_trx_isolation_val != conn->trx_isolation + ) { + conn->semi_trx_isolation = conn->queued_semi_trx_isolation_val; + DBUG_PRINT("info", ("spider conn->semi_trx_isolation=%d", + conn->semi_trx_isolation)); + conn->trx_isolation = thd_tx_isolation(conn->thd); + DBUG_PRINT("info", ("spider conn->trx_isolation=%d", + conn->trx_isolation)); + } + + if (conn->queued_autocommit) + { + if (conn->queued_autocommit_val && conn->autocommit != 1) + { + conn->autocommit = 1; + } else if (!conn->queued_autocommit_val && conn->autocommit != 0) + { + conn->autocommit = 0; + } + DBUG_PRINT("info", ("spider conn->autocommit=%d", + conn->autocommit)); + } + + if (conn->queued_sql_log_off) + { + if (conn->queued_sql_log_off_val && conn->sql_log_off != 1) + { + conn->sql_log_off = 1; + } else if (!conn->queued_sql_log_off_val && conn->sql_log_off != 0) + { + conn->sql_log_off = 0; + } + DBUG_PRINT("info", ("spider conn->sql_log_off=%d", + conn->sql_log_off)); + } + + if ( + conn->queued_time_zone && + conn->queued_time_zone_val != conn->time_zone + ) { + conn->time_zone = conn->queued_time_zone_val; + DBUG_PRINT("info", ("spider conn->time_zone=%p", + conn->time_zone)); + } + spider_conn_clear_queue(conn); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (conn->server_lost) + { + DBUG_PRINT("info", ("spider no connect queue")); + DBUG_RETURN(CR_SERVER_GONE_ERROR); + } +#endif + DBUG_RETURN(0); +} + +int spider_db_before_query( + SPIDER_CONN *conn, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_db_before_query"); + DBUG_ASSERT(need_mon); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (conn->bg_search) + spider_bg_conn_break(conn, NULL); +#endif + conn->in_before_query = TRUE; + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ((error_num = spider_db_conn_queue_action(conn))) + { + conn->in_before_query = FALSE; + DBUG_RETURN(error_num); + } + if (conn->server_lost) + { + conn->in_before_query = FALSE; + DBUG_RETURN(CR_SERVER_GONE_ERROR); + } + DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", + conn, conn->quick_target)); + if (conn->quick_target) + { + bool tmp_mta_conn_mutex_unlock_later; + ha_spider *spider = (ha_spider*) conn->quick_target; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_PRINT("info", ("spider result_list->quick_mode=%d", + result_list->quick_mode)); + if (result_list->quick_mode == 2) + { + result_list->quick_phase = 1; + spider->connection_ids[conn->link_idx] = conn->connection_id; + tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = TRUE; + while (conn->quick_target) + { + if ( + (error_num = spider_db_store_result(spider, conn->link_idx, + result_list->table)) && + error_num != HA_ERR_END_OF_FILE + ) { + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + conn->in_before_query = FALSE; + DBUG_RETURN(error_num); + } + } + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + result_list->quick_phase = 2; + } else { + result_list->bgs_current->result->free_result(); + delete result_list->bgs_current->result; + result_list->bgs_current->result = NULL; + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn)); + conn->quick_target = NULL; + spider->quick_targets[conn->link_idx] = NULL; + } + } + conn->in_before_query = FALSE; + DBUG_RETURN(0); +} + +int spider_db_query( + SPIDER_CONN *conn, + const char *query, + uint length, + int quick_mode, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_db_query"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + DBUG_PRINT("info", ("spider conn->db_conn %p", conn->db_conn)); + if ( + !conn->in_before_query && + (error_num = spider_db_before_query(conn, need_mon)) + ) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + spider_string tmp_query_str(sizeof(char) * (length + 1)); + tmp_query_str.init_calc_mem(107); + char *tmp_query = (char *) tmp_query_str.c_ptr_safe(); + memcpy(tmp_query, query, length); + tmp_query[length] = '\0'; + query = (const char *) tmp_query; + DBUG_PRINT("info", ("spider query=%s", query)); + DBUG_PRINT("info", ("spider length=%u", length)); +#endif + if ((error_num = conn->db_conn->exec_query(query, length, quick_mode))) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn->queued_net_timeout) + { + if (conn->db_conn->set_net_timeout()) + DBUG_RETURN(ER_SPIDER_HS_NUM); + conn->queued_net_timeout = FALSE; + } + DBUG_RETURN(conn->db_conn->exec_query(NULL, 0, quick_mode)); + } +#endif +} + +int spider_db_errorno( + SPIDER_CONN *conn +) { + int error_num; + DBUG_ENTER("spider_db_errorno"); + DBUG_ASSERT(conn->need_mon); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (conn->server_lost) + { + *conn->need_mon = ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM; + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + if ((error_num = conn->db_conn->get_errno())) + { + DBUG_PRINT("info",("spider error_num = %d", error_num)); + if (conn->db_conn->is_server_gone_error(error_num)) + { + spider_db_disconnect(conn); + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + if (conn->disable_reconnect) + { + *conn->need_mon = ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM; + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + } + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } else if ( + conn->ignore_dup_key && + conn->db_conn->is_dup_entry_error(error_num) + ) { + conn->error_str = (char*) conn->db_conn->get_error(); + conn->error_length = strlen(conn->error_str); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); + } else if ( + conn->db_conn->is_xa_nota_error(error_num) && + current_thd && + spider_param_force_commit(current_thd) == 1 + ) { + push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + error_num, conn->db_conn->get_error()); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + *conn->need_mon = error_num; + my_message(error_num, conn->db_conn->get_error(), MYF(0)); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (conn->db_conn->is_server_gone_error(0)) + { + my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), + conn->db_conn->get_errno(), conn->db_conn->get_error()); + *conn->need_mon = ER_SPIDER_HS_NUM; + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_HS_NUM); + } else if (conn->db_conn->is_dup_entry_error(0)) + { + *conn->need_mon = 0; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); + } + my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), + conn->db_conn->get_errno(), conn->db_conn->get_error()); + *conn->need_mon = ER_SPIDER_HS_NUM; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_HS_NUM); + } +#endif + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); +} + +int spider_db_set_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation, + int *need_mon +) { + DBUG_ENTER("spider_db_set_trx_isolation"); + DBUG_RETURN(conn->db_conn->set_trx_isolation(trx_isolation, need_mon)); +} + +int spider_db_set_names_internal( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int all_link_idx, + int *need_mon +) { + bool tmp_mta_conn_mutex_lock_already; + DBUG_ENTER("spider_db_set_names_internal"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ( + !conn->access_charset || + share->access_charset->cset != conn->access_charset->cset + ) { + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + if ( + spider_db_before_query(conn, need_mon) || + conn->db_conn->set_character_set(share->access_charset->csname) + ) { + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + DBUG_RETURN(spider_db_errorno(conn)); + } + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->access_charset = share->access_charset; + } + if ( + spider_param_use_default_database(trx->thd) && + ( + !conn->default_database.length() || + conn->default_database.length() != + share->tgt_dbs_lengths[all_link_idx] || + memcmp(share->tgt_dbs[all_link_idx], conn->default_database.ptr(), + share->tgt_dbs_lengths[all_link_idx]) + ) + ) { + DBUG_PRINT("info",("spider all_link_idx=%d db=%s", all_link_idx, + share->tgt_dbs[all_link_idx])); + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + if ( + spider_db_before_query(conn, need_mon) || + conn->db_conn->select_db(share->tgt_dbs[all_link_idx]) + ) { + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + DBUG_RETURN(spider_db_errorno(conn)); + } + conn->default_database.length(0); + if (conn->default_database.reserve( + share->tgt_dbs_lengths[all_link_idx] + 1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + conn->default_database.q_append(share->tgt_dbs[all_link_idx], + share->tgt_dbs_lengths[all_link_idx] + 1); + conn->default_database.length(share->tgt_dbs_lengths[all_link_idx]); + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + } + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + DBUG_RETURN(0); +} + +int spider_db_set_names( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_db_set_names"); + DBUG_RETURN(spider_db_set_names_internal(spider->trx, spider->share, conn, + spider->conn_link_idx[link_idx], &spider->need_mons[link_idx])); +} + +int spider_db_query_with_set_names( + ulong sql_type, + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_db_query_with_set_names"); + +/* + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); +*/ + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_query_for_bulk_update( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + uint *dup_key_found +) { + int error_num; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_db_query_for_bulk_update"); + +/* + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); +*/ + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + error_num != ER_DUP_ENTRY && + error_num != ER_DUP_KEY && + error_num != HA_ERR_FOUND_DUPP_KEY && + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + if ( + error_num == ER_DUP_ENTRY || + error_num == ER_DUP_KEY || + error_num == HA_ERR_FOUND_DUPP_KEY + ) { + ++(*dup_key_found); + DBUG_RETURN(0); + } + DBUG_RETURN(error_num); + } + while (!(error_num = conn->db_conn->next_result())) + { + ; + } + if (error_num > 0 && !conn->db_conn->is_dup_entry_error(error_num)) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[link_idx], + NULL, + 0, + share->monitoring_kind[link_idx], + share->monitoring_limit[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +size_t spider_db_real_escape_string( + SPIDER_CONN *conn, + char *to, + const char *from, + size_t from_length +) { + DBUG_ENTER("spider_db_real_escape_string"); + DBUG_RETURN(conn->db_conn->escape_string(to, from, from_length)); +} + +int spider_db_consistent_snapshot( + SPIDER_CONN *conn, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_db_consistent_snapshot"); + if ((error_num = conn->db_conn->consistent_snapshot(need_mon))) + { + DBUG_RETURN(error_num); + } + conn->trx_start = TRUE; + DBUG_RETURN(0); +} + +int spider_db_start_transaction( + SPIDER_CONN *conn, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_db_start_transaction"); + if ((error_num = conn->db_conn->start_transaction(need_mon))) + { + DBUG_RETURN(error_num); + } + conn->trx_start = TRUE; + DBUG_RETURN(0); +} + +int spider_db_commit( + SPIDER_CONN *conn +) { + int need_mon = 0, error_num; + DBUG_ENTER("spider_db_commit"); + if (!conn->queued_connect && !conn->queued_trx_start) + { + if (conn->use_for_active_standby && conn->server_lost) + { + my_message(ER_SPIDER_LINK_IS_FAILOVER_NUM, + ER_SPIDER_LINK_IS_FAILOVER_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LINK_IS_FAILOVER_NUM); + } + if ((error_num = conn->db_conn->commit(&need_mon))) + { + DBUG_RETURN(error_num); + } + conn->trx_start = FALSE; + } else + conn->trx_start = FALSE; + DBUG_RETURN(0); +} + +int spider_db_rollback( + SPIDER_CONN *conn +) { + int error_num, need_mon = 0; + DBUG_ENTER("spider_db_rollback"); + if (!conn->queued_connect && !conn->queued_trx_start) + { + if ((error_num = conn->db_conn->rollback(&need_mon))) + { + DBUG_RETURN(error_num); + } + conn->trx_start = FALSE; + } else + conn->trx_start = FALSE; + DBUG_RETURN(0); +} + +int spider_db_append_hex_string( + spider_string *str, + uchar *hex_ptr, + int hex_ptr_length +) { + uchar *end_ptr; + char *str_ptr; + DBUG_ENTER("spider_db_append_hex_string"); + if (hex_ptr_length) + { + if (str->reserve(SPIDER_SQL_HEX_LEN + hex_ptr_length * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); + str_ptr = (char *) str->ptr() + str->length(); + for (end_ptr = hex_ptr + hex_ptr_length; hex_ptr < end_ptr; hex_ptr++) + { + *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; + *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; + } + str->length(str->length() + hex_ptr_length * 2); + } else { + if (str->reserve((SPIDER_SQL_VALUE_QUOTE_LEN) * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + DBUG_RETURN(0); +} + +void spider_db_append_xid_str( + spider_string *tmp_str, + XID *xid +) { + char format_id[sizeof(long) + 3]; + uint format_id_length; + DBUG_ENTER("spider_db_append_xid_str"); + + format_id_length = + my_sprintf(format_id, (format_id, "0x%lx", xid->formatID)); + spider_db_append_hex_string(tmp_str, (uchar *) xid->data, xid->gtrid_length); +/* + tmp_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + tmp_str->q_append(xid->data, xid->gtrid_length); + tmp_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); +*/ + tmp_str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + spider_db_append_hex_string(tmp_str, + (uchar *) xid->data + xid->gtrid_length, xid->bqual_length); +/* + tmp_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + tmp_str->q_append(xid->data + xid->gtrid_length, xid->bqual_length); + tmp_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); +*/ + tmp_str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + tmp_str->q_append(format_id, format_id_length); +#ifndef DBUG_OFF + ((char *) tmp_str->ptr())[tmp_str->length()] = '\0'; +#endif + + DBUG_VOID_RETURN; +} + +int spider_db_xa_end( + SPIDER_CONN *conn, + XID *xid +) { + int need_mon = 0; + DBUG_ENTER("spider_db_xa_end"); + if (!conn->queued_connect && !conn->queued_xa_start) + { + DBUG_RETURN(conn->db_conn->xa_end(xid, &need_mon)); + } + DBUG_RETURN(0); +} + +int spider_db_xa_prepare( + SPIDER_CONN *conn, + XID *xid +) { + int need_mon = 0; + DBUG_ENTER("spider_db_xa_prepare"); + if (!conn->queued_connect && !conn->queued_xa_start) + { + if (conn->use_for_active_standby && conn->server_lost) + { + my_message(ER_SPIDER_LINK_IS_FAILOVER_NUM, + ER_SPIDER_LINK_IS_FAILOVER_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LINK_IS_FAILOVER_NUM); + } + DBUG_RETURN(conn->db_conn->xa_prepare(xid, &need_mon)); + } + DBUG_RETURN(0); +} + +int spider_db_xa_commit( + SPIDER_CONN *conn, + XID *xid +) { + int need_mon = 0; + DBUG_ENTER("spider_db_xa_commit"); + if (!conn->queued_connect && !conn->queued_xa_start) + { + DBUG_RETURN(conn->db_conn->xa_commit(xid, &need_mon)); + } + DBUG_RETURN(0); +} + +int spider_db_xa_rollback( + SPIDER_CONN *conn, + XID *xid +) { + int need_mon = 0; + DBUG_ENTER("spider_db_xa_rollback"); + if (!conn->queued_connect && !conn->queued_xa_start) + { + DBUG_RETURN(conn->db_conn->xa_rollback(xid, &need_mon)); + } + DBUG_RETURN(0); +} + +int spider_db_lock_tables( + ha_spider *spider, + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_db_lock_tables"); + error_num = spider->dbton_handler[conn->dbton_id]->lock_tables(link_idx); + DBUG_RETURN(error_num); +} + +int spider_db_unlock_tables( + ha_spider *spider, + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_db_unlock_tables"); + error_num = spider->dbton_handler[conn->dbton_id]->unlock_tables(link_idx); + DBUG_RETURN(error_num); +} + +int spider_db_append_name_with_quote_str( + spider_string *str, + char *name, + uint dbton_id +) { + int error_num, length = strlen(name); + char *name_end, head_code; + DBUG_ENTER("spider_db_append_name_with_quote_str"); + for (name_end = name + length; name < name_end; name += length) + { + head_code = *name; + if (!(length = my_mbcharlen(system_charset_info, (uchar) head_code))) + { + my_message(ER_SPIDER_WRONG_CHARACTER_IN_NAME_NUM, + ER_SPIDER_WRONG_CHARACTER_IN_NAME_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_WRONG_CHARACTER_IN_NAME_NUM); + } + if ( + length == 1 && + spider_dbton[dbton_id].db_util->is_name_quote(head_code) + ) { + if ((error_num = spider_dbton[dbton_id].db_util-> + append_escaped_name_quote(str))) + { + DBUG_RETURN(error_num); + } + } else { + if (str->append(name, length, system_charset_info)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + DBUG_RETURN(0); +} + +int spider_db_append_select( + ha_spider *spider +) { + int error_num; + DBUG_ENTER("spider_db_append_select"); + + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->append_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = spider->append_select_sql_part( + SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_append_select_columns( + ha_spider *spider +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_append_select_columns"); + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->append_match_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, NULL, 0))) + DBUG_RETURN(error_num); + if (!spider->select_column_mode) + { + if (result_list->keyread) + { + if ((error_num = spider->append_key_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, spider->active_index))) + DBUG_RETURN(error_num); + } else { + if ((error_num = spider->append_table_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + } else { + if ((error_num = spider->append_minimum_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = spider->append_from_sql_part(SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_append_null_value( + spider_string *str, + KEY_PART_INFO *key_part, + const uchar **ptr +) { + DBUG_ENTER("spider_db_append_null_value"); + if (key_part->null_bit) + { + if (*(*ptr)++) + { + if (str->reserve(SPIDER_SQL_NULL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + DBUG_RETURN(-1); + } + } + DBUG_RETURN(0); +} + +int spider_db_append_key_columns( + const key_range *start_key, + ha_spider *spider, + spider_string *str +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + KEY *key_info = result_list->key_info; + uint key_name_length, key_count; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + char tmp_buf[MAX_FIELD_WIDTH]; + DBUG_ENTER("spider_db_append_key_columns"); + + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + for ( + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_count++ + ) { + key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(key_name_length + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(tmp_buf, key_name_length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + + DBUG_RETURN(0); +} + +int spider_db_append_key_hint( + spider_string *str, + char *hint_str +) { + int hint_str_len = strlen(hint_str); + DBUG_ENTER("spider_db_append_key_hint"); + if (hint_str_len >= 2 && + (hint_str[0] == 'f' || hint_str[0] == 'F') && hint_str[1] == ' ' + ) { + if (str->reserve(hint_str_len - 2 + + SPIDER_SQL_SQL_FORCE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + hint_str += 2; + str->q_append(SPIDER_SQL_SQL_FORCE_IDX_STR, SPIDER_SQL_SQL_FORCE_IDX_LEN); + str->q_append(hint_str, hint_str_len - 2); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (hint_str_len >= 2 && + (hint_str[0] == 'u' || hint_str[0] == 'U') && hint_str[1] == ' ' + ) { + if (str->reserve(hint_str_len - 2 + + SPIDER_SQL_SQL_USE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + hint_str += 2; + str->q_append(SPIDER_SQL_SQL_USE_IDX_STR, SPIDER_SQL_SQL_USE_IDX_LEN); + str->q_append(hint_str, hint_str_len - 2); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (hint_str_len >= 3 && + (hint_str[0] == 'i' || hint_str[0] == 'I') && + (hint_str[1] == 'g' || hint_str[1] == 'G') && hint_str[2] == ' ' + ) { + if (str->reserve(hint_str_len - 3 + + SPIDER_SQL_SQL_IGNORE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + hint_str += 3; + str->q_append( + SPIDER_SQL_SQL_IGNORE_IDX_STR, SPIDER_SQL_SQL_IGNORE_IDX_LEN); + str->q_append(hint_str, hint_str_len - 3); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (str->reserve(hint_str_len + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else + { + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(hint_str, hint_str_len); + } + DBUG_RETURN(0); +} + +int spider_db_append_hint_after_table( + ha_spider *spider, + spider_string *str, + spider_string *hint +) { + DBUG_ENTER("spider_db_append_hint_after_table"); + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if (str->append(*hint)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_RETURN(0); +} + +int spider_db_append_key_where_internal( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ha_spider *spider, + bool set_order, + ulong sql_type, + uint dbton_id +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; +#ifndef DBUG_OFF + TABLE *table = spider->get_table(); +#endif + KEY *key_info = result_list->key_info; + int error_num; + uint key_name_length; + key_part_map full_key_part_map; + key_part_map start_key_part_map; + key_part_map end_key_part_map; + key_part_map tgt_key_part_map; + int key_count; + uint length; + uint store_length; + const uchar *ptr, *another_ptr; + const key_range *use_key, *another_key; + KEY_PART_INFO *key_part; + Field *field; + bool use_both = TRUE, key_eq; + uint sql_kind; + spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id]; + spider_db_share *dbton_share = share->dbton_share[dbton_id]; + DBUG_ENTER("spider_db_append_key_where_internal"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + sql_kind = SPIDER_SQL_KIND_HANDLER; + break; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + case SPIDER_SQL_TYPE_SELECT_HS: + case SPIDER_SQL_TYPE_INSERT_HS: + case SPIDER_SQL_TYPE_UPDATE_HS: + case SPIDER_SQL_TYPE_DELETE_HS: + sql_kind = SPIDER_SQL_KIND_HS; + break; +#endif + default: + sql_kind = SPIDER_SQL_KIND_SQL; + break; + } + + if (key_info) + full_key_part_map = make_prev_keypart_map(key_info->key_parts); + else + full_key_part_map = 0; + + if (start_key) + start_key_part_map = start_key->keypart_map & full_key_part_map; + else { + start_key_part_map = 0; + use_both = FALSE; + } + if (end_key) + end_key_part_map = end_key->keypart_map & full_key_part_map; + else { + end_key_part_map = 0; + use_both = FALSE; + } + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info ? + key_info->key_parts : 0)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + DBUG_PRINT("info", ("spider end_key_part_map=%lu", end_key_part_map)); + +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, table->read_set); +#endif + + if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + char *key_name = key_info->name; + key_name_length = strlen(key_name); + if (str->reserve(SPIDER_SQL_READ_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + key_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_READ_STR, SPIDER_SQL_READ_LEN); + if ((error_num = spider_dbton[dbton_id].db_util-> + append_name(str, key_name, key_name_length))) + { + DBUG_RETURN(error_num); + } + dbton_hdl->set_order_pos(SPIDER_SQL_TYPE_HANDLER); + if (start_key_part_map || end_key_part_map) + { + if (str_part->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + result_list->ha_read_kind = 0; + } else if (!result_list->desc_flg) + { + if (str->reserve(SPIDER_SQL_FIRST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); + result_list->ha_read_kind = 1; + } else { + if (str->reserve(SPIDER_SQL_LAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LAST_STR, SPIDER_SQL_LAST_LEN); + result_list->ha_read_kind = 2; + } + } + if (!start_key_part_map && !end_key_part_map) + goto end; + else if (start_key_part_map >= end_key_part_map) + { + use_key = start_key; + another_key = end_key; + tgt_key_part_map = start_key_part_map; + } else { + use_key = end_key; + another_key = start_key; + tgt_key_part_map = end_key_part_map; + } + DBUG_PRINT("info", ("spider tgt_key_part_map=%lu", tgt_key_part_map)); + + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part2->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + } + + for ( + key_part = key_info->key_part, + length = 0, + key_count = 0; + tgt_key_part_map; + length += store_length, + tgt_key_part_map >>= 1, + start_key_part_map >>= 1, + end_key_part_map >>= 1, + key_part++, + key_count++ + ) { + store_length = key_part->store_length; + field = key_part->field; + key_name_length = dbton_share->get_column_name_length(field->field_index); + ptr = use_key->key + length; + if (use_both) + { + another_ptr = another_key->key + length; + if ( + start_key_part_map && + end_key_part_map && + !memcmp(ptr, another_ptr, store_length) + ) + key_eq = TRUE; + else { + key_eq = FALSE; +#ifndef DBUG_OFF + if ( + start_key_part_map && + end_key_part_map + ) + DBUG_PRINT("info", ("spider memcmp=%d", + memcmp(ptr, another_ptr, store_length))); +#endif + } + } else { + if (tgt_key_part_map > 1) + key_eq = TRUE; + else + key_eq = FALSE; + } + if ( + (key_eq && use_key == start_key) || + (!key_eq && start_key_part_map) + ) { + ptr = start_key->key + length; + if ( + (error_num = dbton_hdl->append_is_null_part(sql_type, key_part, + start_key, &ptr, key_eq)) + ) { + if (error_num > 0) + DBUG_RETURN(error_num); + if ( + !set_order && + start_key->flag != HA_READ_KEY_EXACT && + sql_kind == SPIDER_SQL_KIND_SQL + ) { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (key_eq) + { + DBUG_PRINT("info", ("spider key_eq")); + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#endif + } else { + DBUG_PRINT("info", ("spider start_key->flag=%d", start_key->flag)); + switch (start_key->flag) + { +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + case HA_READ_PREFIX_LAST: + result_list->desc_flg = TRUE; + /* fall through */ +#endif + case HA_READ_KEY_EXACT: + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_HS_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_EQUAL_STR, SPIDER_SQL_HS_EQUAL_LEN); + } +#endif + break; + case HA_READ_AFTER_KEY: + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_GT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (use_both) + start_key_part_map = 0; + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_GT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_GT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_HS_GT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_GT_STR, SPIDER_SQL_HS_GT_LEN); + } +#endif + break; + case HA_READ_BEFORE_KEY: + result_list->desc_flg = TRUE; + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (use_both) + start_key_part_map = 0; + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_HS_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_LT_STR, SPIDER_SQL_HS_LT_LEN); + } +#endif + break; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#else + case HA_READ_PREFIX_LAST: + result_list->limit_num = 1; + /* fall through */ +#endif + case HA_READ_KEY_OR_PREV: + case HA_READ_PREFIX_LAST_OR_PREV: + result_list->desc_flg = TRUE; + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_LTEQUAL_STR, SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_LTEQUAL_STR, + SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LTEQUAL_STR, SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_HS_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_LTEQUAL_STR, + SPIDER_SQL_HS_LTEQUAL_LEN); + } +#endif + break; + case HA_READ_MBR_CONTAIN: + if (str->reserve(SPIDER_SQL_MBR_CONTAIN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_CONTAIN_STR, + SPIDER_SQL_MBR_CONTAIN_LEN); + if ( + spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_CLOSE_PAREN_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case HA_READ_MBR_INTERSECT: + if (str->reserve(SPIDER_SQL_MBR_INTERSECT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_INTERSECT_STR, + SPIDER_SQL_MBR_INTERSECT_LEN); + if ( + spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_CLOSE_PAREN_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case HA_READ_MBR_WITHIN: + if (str->reserve(SPIDER_SQL_MBR_WITHIN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_WITHIN_STR, + SPIDER_SQL_MBR_WITHIN_LEN); + if ( + spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_CLOSE_PAREN_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case HA_READ_MBR_DISJOINT: + if (str->reserve(SPIDER_SQL_MBR_DISJOINT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_DISJOINT_STR, + SPIDER_SQL_MBR_DISJOINT_LEN); + if ( + spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_CLOSE_PAREN_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case HA_READ_MBR_EQUAL: + if (str->reserve(SPIDER_SQL_MBR_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_EQUAL_STR, SPIDER_SQL_MBR_EQUAL_LEN); + if ( + spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_CLOSE_PAREN_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + break; + default: + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_GTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_GTEQUAL_STR, SPIDER_SQL_GTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_GTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_GTEQUAL_STR, + SPIDER_SQL_GTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_GTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_GTEQUAL_STR, SPIDER_SQL_GTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else { + if (spider_dbton[share->use_hs_dbton_ids[0]].db_util-> + append_column_value(spider, NULL, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_HS_GTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_GTEQUAL_STR, + SPIDER_SQL_HS_GTEQUAL_LEN); + } +#endif + break; + } + } + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, + SPIDER_SQL_AND_LEN); + } else if (sql_kind == SPIDER_SQL_KIND_HANDLER) + { + if (str_part2->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part2->q_append(SPIDER_SQL_AND_STR, + SPIDER_SQL_AND_LEN); + + if (str_part->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (sql_kind != SPIDER_SQL_KIND_HS) + { +#endif + if ( + (key_eq && use_key == end_key) || + (!key_eq && end_key_part_map) + ) { + ptr = end_key->key + length; + if ((error_num = dbton_hdl->append_is_null_part(sql_type, key_part, + end_key, &ptr, key_eq))) + { + if (error_num > 0) + DBUG_RETURN(error_num); + if ( + !set_order && + end_key->flag != HA_READ_KEY_EXACT && + sql_kind == SPIDER_SQL_KIND_SQL + ) { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (key_eq) + { + DBUG_PRINT("info", ("spider key_eq")); + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + DBUG_PRINT("info", ("spider end_key->flag=%d", end_key->flag)); + switch (end_key->flag) + { + case HA_READ_BEFORE_KEY: + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (use_both) + end_key_part_map = 0; + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_LT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + break; + default: + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_LTEQUAL_STR, SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else { + if (str_part2->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str_part2, field->field_index); + str_part2->q_append(SPIDER_SQL_LTEQUAL_STR, + SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part2, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve(SPIDER_SQL_LTEQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LTEQUAL_STR, SPIDER_SQL_LTEQUAL_LEN); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str_part, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + break; + } + } + if (sql_kind == SPIDER_SQL_KIND_SQL) + { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, + SPIDER_SQL_AND_LEN); + } else { + if (str_part2->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part2->q_append(SPIDER_SQL_AND_STR, + SPIDER_SQL_AND_LEN); + + if (str_part->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str_part->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if (use_both && (!start_key_part_map || !end_key_part_map)) + break; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + } + if ((error_num = dbton_hdl->append_where_terminator_part(sql_type, + set_order, key_count))) + DBUG_RETURN(error_num); + +end: + /* use condition */ + if (dbton_hdl->append_condition_part(NULL, 0, sql_type, FALSE)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (sql_kind == SPIDER_SQL_KIND_SQL) + dbton_hdl->set_order_pos(sql_type); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + DBUG_RETURN(0); +} + +int spider_db_append_key_where( + const key_range *start_key, + const key_range *end_key, + ha_spider *spider +) { + int error_num; + DBUG_ENTER("spider_db_append_key_where"); + if ((spider->sql_kinds & SPIDER_SQL_KIND_SQL)) + { + DBUG_PRINT("info",("spider call internal by SPIDER_SQL_KIND_SQL")); + if ((error_num = spider->append_key_where_sql_part(start_key, end_key, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + DBUG_PRINT("info",("spider call internal by SPIDER_SQL_KIND_HANDLER")); + if ((error_num = spider->append_key_where_sql_part(start_key, end_key, + SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((spider->sql_kinds & SPIDER_SQL_KIND_HS)) + { + DBUG_PRINT("info",("spider call internal by SPIDER_SQL_KIND_HS")); + if ((error_num = spider->append_key_where_hs_part(start_key, end_key, + SPIDER_SQL_TYPE_SELECT_HS))) + DBUG_RETURN(error_num); + } +#endif + DBUG_RETURN(0); +} + +int spider_db_append_match_fetch( + ha_spider *spider, + st_spider_ft_info *ft_first, + st_spider_ft_info *ft_current, + SPIDER_DB_ROW *row +) { + DBUG_ENTER("spider_db_append_match_fetch"); + if (ft_current) + { + st_spider_ft_info *ft_info = ft_first; + while (TRUE) + { + DBUG_PRINT("info",("spider ft_info=%p", ft_info)); + if (!row->is_null()) + ft_info->score = (float) row->val_real(); + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + if (ft_info == ft_current) + break; + ft_info = ft_info->next; + } + } + DBUG_RETURN(0); +} + +int spider_db_append_match_where( + ha_spider *spider +) { + int error_num; + DBUG_ENTER("spider_db_append_match_where"); + if ((error_num = spider->append_match_where_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + + /* use condition */ + if ((error_num = spider->append_condition_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL, FALSE))) + DBUG_RETURN(error_num); + + spider->set_order_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + DBUG_RETURN(0); +} + +void spider_db_append_handler_next( + ha_spider *spider +) { + const char *alias; + uint alias_length; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_append_handler_next"); + if (result_list->sorted && result_list->desc_flg) + { + alias = SPIDER_SQL_PREV_STR; + alias_length = SPIDER_SQL_PREV_LEN; + } else { + alias = SPIDER_SQL_NEXT_STR; + alias_length = SPIDER_SQL_NEXT_LEN; + } + spider->set_order_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); + spider->append_key_order_with_alias_sql_part(alias, alias_length, + SPIDER_SQL_TYPE_HANDLER); + DBUG_VOID_RETURN; +} + +void spider_db_get_row_from_tmp_tbl_rec( + SPIDER_RESULT *current, + SPIDER_DB_ROW **row +) { + DBUG_ENTER("spider_db_get_row_from_tmp_tbl_rec"); + *row = current->result->fetch_row_from_tmp_table(current->result_tmp_tbl); + DBUG_VOID_RETURN; +} + +int spider_db_get_row_from_tmp_tbl( + SPIDER_RESULT *current, + SPIDER_DB_ROW **row +) { + int error_num; + DBUG_ENTER("spider_db_get_row_from_tmp_tbl"); + if (current->result_tmp_tbl_inited == 2) + { + current->result_tmp_tbl->file->ha_rnd_end(); + current->result_tmp_tbl_inited = 0; + } + if (current->result_tmp_tbl_inited == 0) + { + current->result_tmp_tbl->file->extra(HA_EXTRA_CACHE); + if ((error_num = current->result_tmp_tbl->file->ha_rnd_init(TRUE))) + DBUG_RETURN(error_num); + current->result_tmp_tbl_inited = 1; + } + if ( +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + (error_num = current->result_tmp_tbl->file->ha_rnd_next( + current->result_tmp_tbl->record[0])) +#else + (error_num = current->result_tmp_tbl->file->rnd_next( + current->result_tmp_tbl->record[0])) +#endif + ) { + DBUG_RETURN(error_num); + } + spider_db_get_row_from_tmp_tbl_rec(current, row); + DBUG_RETURN(0); +} + +int spider_db_get_row_from_tmp_tbl_pos( + SPIDER_POSITION *pos, + SPIDER_DB_ROW **row +) { + int error_num; + SPIDER_RESULT *result = pos->result; + TABLE *tmp_tbl = result->result_tmp_tbl; + DBUG_ENTER("spider_db_get_row_from_tmp_tbl_pos"); + if (result->result_tmp_tbl_inited == 1) + { + tmp_tbl->file->ha_rnd_end(); + result->result_tmp_tbl_inited = 0; + } + if (result->result_tmp_tbl_inited == 0) + { + if ((error_num = tmp_tbl->file->ha_rnd_init(FALSE))) + DBUG_RETURN(error_num); + result->result_tmp_tbl_inited = 2; + } + if ( +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + (error_num = tmp_tbl->file->ha_rnd_pos(tmp_tbl->record[0], + (uchar *) &pos->tmp_tbl_pos)) +#else + (error_num = tmp_tbl->file->rnd_pos(tmp_tbl->record[0], + (uchar *) &pos->tmp_tbl_pos)) +#endif + ) { + DBUG_RETURN(error_num); + } + spider_db_get_row_from_tmp_tbl_rec(result, row); + DBUG_RETURN(0); +} + +int spider_db_fetch_row( + SPIDER_SHARE *share, + Field *field, + SPIDER_DB_ROW *row, + my_ptrdiff_t ptr_diff +) { + int error_num; + DBUG_ENTER("spider_db_fetch_row"); + DBUG_PRINT("info", ("spider field_name %s", field->field_name)); + DBUG_PRINT("info", ("spider fieldcharset %s", field->charset()->csname)); + field->move_field_offset(ptr_diff); + error_num = row->store_to_field(field, share->access_charset); + field->move_field_offset(-ptr_diff); + DBUG_RETURN(error_num); +} + +int spider_db_fetch_table( + ha_spider *spider, + uchar *buf, + TABLE *table, + SPIDER_RESULT_LIST *result_list +) { + int error_num; + SPIDER_SHARE *share = spider->share; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + SPIDER_RESULT *current = (SPIDER_RESULT*) result_list->current; + SPIDER_DB_ROW *row; + Field **field; + DBUG_ENTER("spider_db_fetch_table"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[spider->result_link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (result_list->quick_mode == 0) + { + SPIDER_DB_RESULT *result = current->result; + if (!(row = result->fetch_row())) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } else { + if (result_list->current_row_num < result_list->quick_page_size) + { + row = current->first_position[result_list->current_row_num].row; + } else { + if ((error_num = spider_db_get_row_from_tmp_tbl( + current, &row))) + { + if (error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + } + } + + /* for mrr */ + if (spider->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + if (spider->sql_kind[spider->result_link_idx] == SPIDER_SQL_KIND_SQL) + { + if (!row->is_null()) + spider->multi_range_hit_point = row->val_int(); + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } else + spider->multi_range_hit_point = 0; + } + + if ((error_num = spider_db_append_match_fetch(spider, + spider->ft_first, spider->ft_current, row))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (!(row = result_list->hs_result->fetch_row_from_result_buffer( + result_list->hs_result_buf))) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } +#endif + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[spider->result_link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + for ( + field = table->field; + *field; + field++ + ) { + if (( + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + )) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", (*field)->field_name)); + if ((error_num = + spider_db_fetch_row(share, *field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + row->next(); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (spider->hs_pushed_ret_fields_num == MAX_FIELDS) + { +#endif + for ( + field = table->field; + *field; + field++ + ) { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + if ((error_num = spider_db_fetch_row(share, *field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + row->next(); + } + } +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + } else { + uint32 *field_idxs = spider->hs_pushed_ret_fields; + size_t field_idxs_num = spider->hs_pushed_ret_fields_num; + Field *tf; + int roop_count; + if (spider->hs_pushed_lcl_fields_num != + result_list->hs_result->num_fields()) + { + DBUG_PRINT("info", ("spider different field_num %zu %u", + spider->hs_pushed_lcl_fields_num, + result_list->hs_result->num_fields())); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + for (roop_count = 0; roop_count < (int) field_idxs_num; + roop_count++) + { + tf = spider->get_top_table_field(field_idxs[roop_count]); + if ((tf = spider->field_exchange(tf))) + { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + if ((error_num = spider_db_fetch_row(share, tf, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + row->next(); + } + } + } +#endif + } +#endif + table->status = 0; + DBUG_RETURN(0); +} + +int spider_db_fetch_key( + ha_spider *spider, + uchar *buf, + TABLE *table, + const KEY *key_info, + SPIDER_RESULT_LIST *result_list +) { + int error_num; + SPIDER_SHARE *share = spider->share; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + SPIDER_RESULT *current = (SPIDER_RESULT*) result_list->current; + KEY_PART_INFO *key_part; + uint part_num; + SPIDER_DB_ROW *row; + Field *field; + DBUG_ENTER("spider_db_fetch_key"); + if (result_list->quick_mode == 0) + { + SPIDER_DB_RESULT *result = current->result; + if (!(row = result->fetch_row())) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } else { + if (result_list->current_row_num < result_list->quick_page_size) + { + row = current->first_position[result_list->current_row_num].row; + } else { + if ((error_num = spider_db_get_row_from_tmp_tbl( + current, &row))) + { + if (error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + } + } + + /* for mrr */ + if (spider->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + if (!row->is_null()) + spider->multi_range_hit_point = row->val_int(); + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + if ((error_num = spider_db_append_match_fetch(spider, + spider->ft_first, spider->ft_current, row))) + DBUG_RETURN(error_num); + + for ( + key_part = key_info->key_part, + part_num = 0; + part_num < key_info->key_parts; + key_part++, + part_num++ + ) { + field = key_part->field; + if (( + bitmap_is_set(table->read_set, field->field_index) | + bitmap_is_set(table->write_set, field->field_index) + )) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", field->field_name)); + if ((error_num = + spider_db_fetch_row(share, field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + row->next(); + } + table->status = 0; + DBUG_RETURN(0); +} + +int spider_db_fetch_minimum_columns( + ha_spider *spider, + uchar *buf, + TABLE *table, + SPIDER_RESULT_LIST *result_list +) { + int error_num; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT *current = (SPIDER_RESULT*) result_list->current; + SPIDER_DB_ROW *row; + Field **field; + DBUG_ENTER("spider_db_fetch_minimum_columns"); + if (result_list->quick_mode == 0) + { + SPIDER_DB_RESULT *result = current->result; + if (!(row = result->fetch_row())) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } else { + if (result_list->current_row_num < result_list->quick_page_size) + { + row = current->first_position[result_list->current_row_num].row; + } else { + if ((error_num = spider_db_get_row_from_tmp_tbl( + current, &row))) + { + if (error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(error_num); + } + } + } + + /* for mrr */ + if (spider->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + if (!row->is_null()) + spider->multi_range_hit_point = row->val_int(); + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + if ((error_num = spider_db_append_match_fetch(spider, + spider->ft_first, spider->ft_current, row))) + DBUG_RETURN(error_num); + + for ( + field = table->field; + *field; + field++ + ) { + DBUG_PRINT("info", ("spider field_index %u", (*field)->field_index)); + DBUG_PRINT("info", ("spider searched_bitmap %u", + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index))); + DBUG_PRINT("info", ("spider read_set %u", + bitmap_is_set(table->read_set, (*field)->field_index))); + DBUG_PRINT("info", ("spider write_set %u", + bitmap_is_set(table->write_set, (*field)->field_index))); + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + if (( + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + )) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", (*field)->field_name)); + if ((error_num = spider_db_fetch_row(share, *field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + row->next(); + } + } + table->status = 0; + DBUG_RETURN(0); +} + +void spider_db_free_one_result_for_start_next( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_RESULT *result = (SPIDER_RESULT *) result_list->current; + DBUG_ENTER("spider_db_free_one_result_for_start_next"); + spider_bg_all_conn_break(spider); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[spider->result_link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (result_list->low_mem_read) + { + if (result) + { + do { + spider_db_free_one_result(result_list, result); + DBUG_PRINT("info",("spider result=%p", result)); + DBUG_PRINT("info",("spider result->finish_flg = FALSE")); + result->finish_flg = FALSE; + result = (SPIDER_RESULT *) result->next; + } while (result && (result->result || result->first_position)); + result = (SPIDER_RESULT *) result_list->current; + if ( + !result->result && + !result->first_position + ) + result_list->current = result->prev; + } + } else { + while ( + result && result->next && + (result->next->result || result->next->first_position) + ) { + result_list->current = result->next; + result = (SPIDER_RESULT *) result->next; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (result_list->hs_has_result) + { + if (result_list->hs_result) + { + result_list->hs_result->free_result(); + delete result_list->hs_result; + result_list->hs_result = NULL; + } + if (result_list->hs_result_buf) + { + result_list->hs_result_buf->clear(); + } + result_list->hs_has_result = FALSE; + } + } +#endif + DBUG_VOID_RETURN; +} + +void spider_db_free_one_result( + SPIDER_RESULT_LIST *result_list, + SPIDER_RESULT *result +) { + DBUG_ENTER("spider_db_free_one_result"); + if (result_list->quick_mode == 0) + { + if ( + !result->use_position && + result->result + ) { + result->result->free_result(); + delete result->result; + result->result = NULL; + } + } else { + int roop_count; + SPIDER_POSITION *position = result->first_position; + if (position) + { + for (roop_count = 0; roop_count < result->pos_page_size; roop_count++) + { + if ( + position[roop_count].row && + !position[roop_count].use_position + ) { + delete position[roop_count].row; + position[roop_count].row = NULL; + } + } + } + } + DBUG_VOID_RETURN; +} + +int spider_db_free_result( + ha_spider *spider, + bool final +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_RESULT *result; + SPIDER_RESULT *prev; + SPIDER_SHARE *share = spider->share; + SPIDER_TRX *trx = spider->trx; + SPIDER_POSITION *position; + int roop_count, error_num; + DBUG_ENTER("spider_db_free_result"); + spider_bg_all_conn_break(spider); + result = (SPIDER_RESULT*) result_list->first; + + while (result_list->tmp_pos_row_first) + { + SPIDER_DB_ROW *tmp_pos_row = result_list->tmp_pos_row_first; + result_list->tmp_pos_row_first = tmp_pos_row->next_pos; + delete tmp_pos_row; + } + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (result_list->hs_has_result) + { + if (result_list->hs_result) + { + result_list->hs_result->free_result(); + delete result_list->hs_result; + result_list->hs_result = NULL; + } + if (result_list->hs_result_buf) + { + if (result_list->hs_result_buf->check_size( + spider_param_hs_result_free_size(trx->thd, share->hs_result_free_size)) + ) { + trx->hs_result_free_count++; + } + result_list->hs_result_buf->clear(); + } + result_list->hs_has_result = FALSE; + } +#endif + + if ( + final || + spider_param_reset_sql_alloc(trx->thd, share->reset_sql_alloc) == 1 + ) { + int alloc_size = final ? 0 : + (spider_param_init_sql_alloc_size(trx->thd, share->init_sql_alloc_size)); + while (result) + { + position = result->first_position; + if (position) + { + for (roop_count = 0; roop_count < result->pos_page_size; roop_count++) + { + if (position[roop_count].row) + { + delete position[roop_count].row; + } + } + spider_free(spider_current_trx, position, MYF(0)); + } + if (result->result) + { + result->result->free_result(); + delete result->result; + result->result = NULL; + } + if (result->result_tmp_tbl) + { + if (result->result_tmp_tbl_inited) + { + result->result_tmp_tbl->file->ha_rnd_end(); + result->result_tmp_tbl_inited = 0; + } + spider_rm_sys_tmp_table_for_result(result->result_tmp_tbl_thd, + result->result_tmp_tbl, &result->result_tmp_tbl_prm); + result->result_tmp_tbl = NULL; + result->result_tmp_tbl_thd = NULL; + } + prev = result; + result = (SPIDER_RESULT*) result->next; + spider_free(spider_current_trx, prev, MYF(0)); + } + result_list->first = NULL; + result_list->last = NULL; + if (!final) + { + ulong realloced = 0; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(trx->thd, share->init_sql_alloc_size); + for (roop_count = 0; roop_count < (int) share->use_dbton_count; + roop_count++) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if ((error_num = spider->dbton_handler[dbton_id]-> + realloc_sql(&realloced))) + { + DBUG_RETURN(error_num); + } + } + if (realloced & (SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + if ((int) result_list->sqls[roop_count].alloced_length() > + alloc_size * 2) + { + result_list->sqls[roop_count].free(); + if (result_list->sqls[roop_count].real_alloc( + init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + if (realloced & SPIDER_SQL_TYPE_INSERT_SQL) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + if ((int) result_list->insert_sqls[roop_count].alloced_length() > + alloc_size * 2) + { + result_list->insert_sqls[roop_count].free(); + if (result_list->insert_sqls[roop_count].real_alloc( + init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + if (realloced & SPIDER_SQL_TYPE_UPDATE_SQL) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + if ((int) result_list->update_sqls[roop_count].alloced_length() > + alloc_size * 2) + { + result_list->update_sqls[roop_count].free(); + if (result_list->update_sqls[roop_count].real_alloc( + init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL))) + DBUG_RETURN(error_num); + + if (realloced & SPIDER_SQL_TYPE_TMP_SQL) + { + for (roop_count = 0; roop_count < (int) share->link_count; + roop_count++) + { + if ((int) result_list->tmp_sqls[roop_count].alloced_length() > + alloc_size * 2) + { + result_list->tmp_sqls[roop_count].free(); + if (result_list->tmp_sqls[roop_count].real_alloc( + init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + } + } else { + while (result) + { + position = result->first_position; + if (position) + { + for (roop_count = 0; roop_count < result->pos_page_size; roop_count++) + { + if (position[roop_count].row) + { + delete position[roop_count].row; + } + } + spider_free(spider_current_trx, position, MYF(0)); + } + result->first_position = NULL; + if (result->result) + { + result->result->free_result(); + delete result->result; + result->result = NULL; + } + if (result->result_tmp_tbl) + { + if (result->result_tmp_tbl_inited) + { + result->result_tmp_tbl->file->ha_rnd_end(); + result->result_tmp_tbl_inited = 0; + } + spider_rm_sys_tmp_table_for_result(result->result_tmp_tbl_thd, + result->result_tmp_tbl, &result->result_tmp_tbl_prm); + result->result_tmp_tbl = NULL; + result->result_tmp_tbl_thd = NULL; + } + result->record_num = 0; + DBUG_PRINT("info",("spider result->finish_flg = FALSE")); + result->finish_flg = FALSE; + result->use_position = FALSE; + result = (SPIDER_RESULT*) result->next; + } + } + result_list->current = NULL; + result_list->record_num = 0; + DBUG_PRINT("info",("spider result_list->finish_flg = FALSE")); + result_list->finish_flg = FALSE; + result_list->quick_phase = 0; +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list->bgs_phase = 0; +#endif + DBUG_RETURN(0); +} + +int spider_db_store_result( + ha_spider *spider, + int link_idx, + TABLE *table +) { + int error_num; + SPIDER_CONN *conn; + SPIDER_DB_CONN *db_conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_RESULT *current; + DBUG_ENTER("spider_db_store_result"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = spider->conns[link_idx]; + DBUG_PRINT("info",("spider conn->connection_id=%llu", + conn->connection_id)); + DBUG_PRINT("info",("spider spider->connection_ids[%d]=%llu", + link_idx, spider->connection_ids[link_idx])); + if (conn->connection_id != spider->connection_ids[link_idx]) + { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + db_conn = conn->db_conn; + if (!result_list->current) + { + if (!result_list->first) + { + if (!(result_list->first = (SPIDER_RESULT *) + spider_malloc(spider_current_trx, 4, sizeof(*result_list->first), + MYF(MY_WME | MY_ZEROFILL))) + ) { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) + &result_list->first->result_tmp_tbl_prm; + tmp_tbl_prm->init(); + tmp_tbl_prm->field_count = 3; + result_list->last = result_list->first; + result_list->current = result_list->first; + } else { + result_list->current = result_list->first; + } + result_list->bgs_current = result_list->current; + current = (SPIDER_RESULT*) result_list->current; + } else { + if ( +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list->bgs_phase > 0 || +#endif + result_list->quick_phase > 0 + ) { + if (result_list->bgs_current == result_list->last) + { + if (!(result_list->last = (SPIDER_RESULT *) + spider_malloc(spider_current_trx, 5, sizeof(*result_list->last), + MYF(MY_WME | MY_ZEROFILL))) + ) { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) + &result_list->last->result_tmp_tbl_prm; + tmp_tbl_prm->init(); + tmp_tbl_prm->field_count = 3; + result_list->bgs_current->next = result_list->last; + result_list->last->prev = result_list->bgs_current; + result_list->bgs_current = result_list->last; + } else { + result_list->bgs_current = result_list->bgs_current->next; + } + if ( +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list->bgs_phase == 1 || +#endif + result_list->quick_phase == 2 + ) { + if (result_list->low_mem_read) + { + do { + spider_db_free_one_result(result_list, + (SPIDER_RESULT*) result_list->current); + result_list->current = result_list->current->next; + } while (result_list->current != result_list->bgs_current); + } else { + result_list->current = result_list->bgs_current; + } + result_list->quick_phase = 0; + } + current = (SPIDER_RESULT*) result_list->bgs_current; + } else { + if (result_list->current == result_list->last) + { + if (!(result_list->last = (SPIDER_RESULT *) + spider_malloc(spider_current_trx, 6, sizeof(*result_list->last), + MYF(MY_WME | MY_ZEROFILL))) + ) { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *) + &result_list->last->result_tmp_tbl_prm; + tmp_tbl_prm->init(); + tmp_tbl_prm->field_count = 3; + result_list->current->next = result_list->last; + result_list->last->prev = result_list->current; + result_list->current = result_list->last; + } else { + result_list->current = result_list->current->next; + } + result_list->bgs_current = result_list->current; + current = (SPIDER_RESULT*) result_list->current; + } + } + + if (result_list->quick_mode == 0) + { + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if (!(current->result = db_conn->store_result(NULL, &request_key, + &error_num))) + { + if (error_num && error_num != HA_ERR_END_OF_FILE) + { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + if ( + error_num != HA_ERR_END_OF_FILE && + (error_num = spider_db_errorno(conn)) + ) + DBUG_RETURN(error_num); + else { + DBUG_PRINT("info",("spider set finish_flg point 1")); + DBUG_PRINT("info",("spider current->finish_flg = TRUE")); + DBUG_PRINT("info",("spider result_list->finish_flg = TRUE")); + current->finish_flg = TRUE; + result_list->finish_flg = TRUE; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list->bgs_phase <= 1) + { +#endif + result_list->current_row_num = 0; + table->status = STATUS_NOT_FOUND; +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } else { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + current->record_num = current->result->num_rows(); + result_list->record_num += current->record_num; + DBUG_PRINT("info",("spider current->record_num=%lld", + current->record_num)); + DBUG_PRINT("info",("spider result_list->record_num=%lld", + result_list->record_num)); + if ( + result_list->internal_limit <= result_list->record_num || + result_list->split_read > current->record_num + ) { + DBUG_PRINT("info",("spider result_list->internal_limit=%lld", + result_list->internal_limit)); + DBUG_PRINT("info",("spider result_list->split_read=%lld", + result_list->split_read)); + DBUG_PRINT("info",("spider set finish_flg point 2")); + DBUG_PRINT("info",("spider current->finish_flg = TRUE")); + DBUG_PRINT("info",("spider result_list->finish_flg = TRUE")); + current->finish_flg = TRUE; + result_list->finish_flg = TRUE; + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list->bgs_phase <= 1) + { +#endif + result_list->current_row_num = 0; +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + } + } else { + /* has_result() for case of result with result_tmp_tbl */ + if (current->prev && current->prev->result && + current->prev->result->has_result()) + { + current->result = current->prev->result; + current->prev->result = NULL; + result_list->limit_num -= current->prev->record_num; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } else { + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if (!(current->result = conn->db_conn->use_result(&request_key, + &error_num))) + { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } else { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + DBUG_RETURN(error_num); + } + DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", conn, spider)); + conn->quick_target = spider; + spider->quick_targets[link_idx] = spider; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + SPIDER_DB_ROW *row; + if (!(row = current->result->fetch_row())) + { + DBUG_PRINT("info",("spider set finish_flg point 3")); + DBUG_PRINT("info",("spider current->finish_flg = TRUE")); + DBUG_PRINT("info",("spider result_list->finish_flg = TRUE")); + current->finish_flg = TRUE; + result_list->finish_flg = TRUE; + current->result->free_result(); + delete current->result; + current->result = NULL; + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn)); + conn->quick_target = NULL; + spider->quick_targets[link_idx] = NULL; + if ( +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list->bgs_phase <= 1 && +#endif + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + table->status = STATUS_NOT_FOUND; + } else if (result_list->quick_phase > 0) + DBUG_RETURN(0); + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + SPIDER_DB_ROW *tmp_row; + uint field_count = current->result->num_fields(); + SPIDER_POSITION *position; + longlong page_size = + !result_list->quick_page_size || + result_list->limit_num < result_list->quick_page_size ? + result_list->limit_num : result_list->quick_page_size; + int roop_count = 0; + current->field_count = field_count; + if (!(position = (SPIDER_POSITION *) + spider_bulk_malloc(spider_current_trx, 7, MYF(MY_WME | MY_ZEROFILL), + &position, sizeof(SPIDER_POSITION) * page_size, + &tmp_row, sizeof(char*) * field_count, + NullS)) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current->pos_page_size = (int) page_size; + current->first_position = position; + current->tmp_tbl_row = tmp_row; + do { + if (!(position->row = row->clone())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + position++; + roop_count++; + } while ( + page_size > roop_count && + (row = current->result->fetch_row()) + ); + if ( + result_list->quick_mode == 3 && + page_size == roop_count && + result_list->limit_num > roop_count && + (row = current->result->fetch_row()) + ) { + THD *thd = current_thd; + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.init_calc_mem(120); + + DBUG_PRINT("info",("spider store result to temporary table")); + DBUG_ASSERT(!current->result_tmp_tbl); + if (!(current->result_tmp_tbl = spider_mk_sys_tmp_table_for_result( + thd, table, ¤t->result_tmp_tbl_prm, "a", "b", "c", + &my_charset_bin))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + current->result_tmp_tbl_thd = thd; + TABLE *tmp_tbl = current->result_tmp_tbl; + tmp_tbl->file->extra(HA_EXTRA_WRITE_CACHE); + tmp_tbl->file->ha_start_bulk_insert((ha_rows) 0); + do { + if ((error_num = row->store_to_tmp_table(tmp_tbl, &tmp_str))) + { + tmp_tbl->file->ha_end_bulk_insert(); + DBUG_RETURN(error_num); + } + roop_count++; + } while ( + result_list->limit_num > roop_count && + (row = current->result->fetch_row()) + ); + tmp_tbl->file->ha_end_bulk_insert(); + page_size = result_list->limit_num; + } + current->record_num = roop_count; + result_list->record_num += roop_count; + if ( + result_list->internal_limit <= result_list->record_num || + page_size > roop_count + ) { + DBUG_PRINT("info",("spider set finish_flg point 4")); + DBUG_PRINT("info",("spider current->finish_flg = TRUE")); + DBUG_PRINT("info",("spider result_list->finish_flg = TRUE")); + current->finish_flg = TRUE; + result_list->finish_flg = TRUE; + current->result->free_result(); + if (!current->result_tmp_tbl) + { + delete current->result; + current->result = NULL; + } + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn)); + conn->quick_target = NULL; + spider->quick_targets[link_idx] = NULL; + } else if (result_list->limit_num == roop_count) + { + current->result->free_result(); + if (!current->result_tmp_tbl) + { + delete current->result; + current->result = NULL; + } + DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn)); + conn->quick_target = NULL; + spider->quick_targets[link_idx] = NULL; + } + if ( +#ifndef WITHOUT_SPIDER_BG_SEARCH + result_list->bgs_phase <= 1 && +#endif + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) + conn = spider->hs_r_conns[link_idx]; + else + conn = spider->hs_w_conns[link_idx]; + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->connection_id=%llu", + conn->connection_id)); + DBUG_PRINT("info",("spider spider->connection_ids[%d]=%llu", + link_idx, spider->connection_ids[link_idx])); + if (conn->connection_id != spider->connection_ids[link_idx]) + { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if (!(result_list->hs_result = conn->db_conn->store_result( + &result_list->hs_result_buf, &request_key, &error_num))) + { + if (!error_num) + { + spider_db_errorno(conn); + DBUG_RETURN(ER_SPIDER_HS_NUM); + } else { + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + DBUG_RETURN(error_num); + } + result_list->hs_conn = conn->db_conn; + result_list->hs_has_result = TRUE; + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } +#endif + DBUG_RETURN(0); +} + +void spider_db_discard_result( + ha_spider *spider, + int link_idx, + SPIDER_CONN *conn +) { + int error_num; + SPIDER_DB_RESULT *result; + DBUG_ENTER("spider_db_discard_result"); + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + result->free_result(); + delete result; + } + DBUG_VOID_RETURN; +} + +void spider_db_discard_multiple_result( + ha_spider *spider, + int link_idx, + SPIDER_CONN *conn +) { + int error_num; + SPIDER_DB_RESULT *result; + st_spider_db_request_key request_key; + DBUG_ENTER("spider_db_discard_multiple_result"); + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + do + { + if (!conn->db_conn->cmp_request_key_to_snd(&request_key)) + break; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + result->free_result(); + delete result; + } while (!conn->db_conn->next_result()); + DBUG_VOID_RETURN; +} + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_store_result( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + bool discard_result +) { + int error_num, tmp_error_num; + DBUG_ENTER("spider_db_bulk_store_result"); + DBUG_PRINT("info",("spider spider=%p", spider)); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { + /* already stored */ + DBUG_RETURN(0); + } + error_num = spider_db_bulk_open_handler(spider, conn, link_idx); + if (!discard_result) + { + bool tmp_mta_conn_mutex_unlock_later; + tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((tmp_error_num = spider_db_store_result(spider, link_idx, + spider->get_table()))) + { + error_num = tmp_error_num; + } + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + } else { + if (spider->connection_ids[link_idx] == conn->connection_id) + spider_db_discard_result(spider, link_idx, conn); + } + DBUG_RETURN(error_num); +} +#endif + +int spider_db_fetch( + uchar *buf, + ha_spider *spider, + TABLE *table +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_fetch"); + if (spider->sql_kind[spider->result_link_idx] == SPIDER_SQL_KIND_SQL) + { + if (!spider->select_column_mode) { + if (result_list->keyread) + error_num = spider_db_fetch_key(spider, buf, table, + result_list->key_info, result_list); + else + error_num = spider_db_fetch_table(spider, buf, table, + result_list); + } else + error_num = spider_db_fetch_minimum_columns(spider, buf, table, + result_list); + } else { + error_num = spider_db_fetch_table(spider, buf, table, + result_list); + } + result_list->current_row_num++; + DBUG_PRINT("info",("spider error_num=%d", error_num)); + spider->pushed_pos = NULL; + DBUG_RETURN(error_num); +} + +int spider_db_seek_prev( + uchar *buf, + ha_spider *spider, + TABLE *table +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_seek_prev"); + if (result_list->current_row_num <= 1) + { + if (result_list->current == result_list->first) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + if (result_list->low_mem_read == 1) + { + my_message(ER_SPIDER_LOW_MEM_READ_PREV_NUM, + ER_SPIDER_LOW_MEM_READ_PREV_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LOW_MEM_READ_PREV_NUM); + } + result_list->current = result_list->current->prev; + result_list->current_row_num = result_list->current->record_num - 1; + } else { + result_list->current_row_num -= 2; + } + if (result_list->quick_mode == 0) + result_list->current->result->move_to_pos(result_list->current_row_num); + DBUG_RETURN(spider_db_fetch(buf, spider, table)); +} + +int spider_db_seek_next( + uchar *buf, + ha_spider *spider, + int link_idx, + TABLE *table +) { + int error_num; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_seek_next"); + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->conn_kind[spider->result_link_idx] == SPIDER_CONN_KIND_MYSQL && +#endif + result_list->current_row_num >= result_list->current->record_num + ) { + DBUG_PRINT("info",("spider result_list->current_row_num=%lld", + result_list->current_row_num)); + DBUG_PRINT("info",("spider result_list->current->record_num=%lld", + result_list->current->record_num)); + if (result_list->low_mem_read) + spider_db_free_one_result(result_list, + (SPIDER_RESULT*) result_list->current); + + int roop_start, roop_end, roop_count, lock_mode, link_ok; + lock_mode = spider_conn_lock_mode(spider); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = spider->share->link_count; + } else { + link_ok = link_idx; + roop_start = link_idx; + roop_end = link_idx + 1; + } + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (result_list->bgs_phase > 0) + { + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ((error_num = spider_bg_conn_search(spider, roop_count, roop_start, + FALSE, FALSE, (roop_count != link_ok)))) + { + DBUG_PRINT("info",("spider error_num 1=%d", error_num)); + DBUG_RETURN(error_num); + } + } + } else { +#endif + if (result_list->current == result_list->bgs_current) + { + if (result_list->finish_flg) + { + table->status = STATUS_NOT_FOUND; + DBUG_PRINT("info",("spider error_num 2=%d", HA_ERR_END_OF_FILE)); + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + spider_next_split_read_param(spider); + if ( + result_list->quick_mode == 0 || + !result_list->current->result + ) { + result_list->limit_num = + result_list->internal_limit - result_list->record_num >= + result_list->split_read ? + result_list->split_read : + result_list->internal_limit - result_list->record_num; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->reappend_limit_sql_part( + result_list->record_num, result_list->limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_PRINT("info",("spider error_num 3=%d", error_num)); + DBUG_RETURN(error_num); + } + if ( + !result_list->use_union && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) { + DBUG_PRINT("info",("spider error_num 4=%d", error_num)); + DBUG_RETURN(error_num); + } + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + spider_db_append_handler_next(spider); + if ((error_num = spider->reappend_limit_sql_part( + 0, result_list->limit_num, + SPIDER_SQL_TYPE_HANDLER))) + { + DBUG_PRINT("info",("spider error_num 5=%d", error_num)); + DBUG_RETURN(error_num); + } + } + + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; + conn = spider->conns[roop_count]; + if (spider->sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } + spider_db_handler *dbton_handler = + spider->dbton_handler[conn->dbton_id]; + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + roop_count))) + { + DBUG_PRINT("info",("spider error_num 6=%d", error_num)); + DBUG_RETURN(error_num); + } + if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider error_num 7=%d", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->trx->thd, share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider error_num 8=%d", error_num)); + DBUG_RETURN(error_num); + } + spider->connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(spider, roop_count, + table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider error_num 9=%d", error_num)); + DBUG_RETURN(error_num); + } + spider->result_link_idx = link_ok; + } else { + spider_db_discard_result(spider, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + } else { + spider->connection_ids[link_idx] = conn->connection_id; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_store_result(spider, link_idx, table))) + { + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_PRINT("info",("spider error_num 10=%d", error_num)); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_unlock_later = FALSE; + } + } else { + result_list->current = result_list->current->next; + result_list->current_row_num = 0; + if ( + result_list->current == result_list->bgs_current && + result_list->finish_flg + ) { + table->status = STATUS_NOT_FOUND; + DBUG_PRINT("info",("spider error_num 11=%d", HA_ERR_END_OF_FILE)); + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + DBUG_RETURN(spider_db_fetch(buf, spider, table)); + } else + DBUG_RETURN(spider_db_fetch(buf, spider, table)); +} + +int spider_db_seek_last( + uchar *buf, + ha_spider *spider, + int link_idx, + TABLE *table +) { + int error_num; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_seek_last"); + if (result_list->finish_flg) + { + if (result_list->low_mem_read == 1) + { + my_message(ER_SPIDER_LOW_MEM_READ_PREV_NUM, + ER_SPIDER_LOW_MEM_READ_PREV_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LOW_MEM_READ_PREV_NUM); + } + result_list->current = result_list->last; + result_list->current_row_num = result_list->current->record_num - 1; + if (result_list->quick_mode == 0) + result_list->current->result->move_to_pos(result_list->current_row_num); + DBUG_RETURN(spider_db_fetch(buf, spider, table)); + } else if (!result_list->sorted || + result_list->internal_limit <= result_list->record_num * 2) + { + if (result_list->low_mem_read == 1) + { + my_message(ER_SPIDER_LOW_MEM_READ_PREV_NUM, + ER_SPIDER_LOW_MEM_READ_PREV_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LOW_MEM_READ_PREV_NUM); + } + spider_next_split_read_param(spider); + result_list->limit_num = + result_list->internal_limit - result_list->record_num; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->reappend_limit_sql_part( + result_list->internal_offset + result_list->record_num, + result_list->limit_num, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + if ( + !result_list->use_union && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + spider_db_append_handler_next(spider); + if ((error_num = spider->reappend_limit_sql_part( + result_list->internal_offset + result_list->record_num, + result_list->limit_num, + SPIDER_SQL_TYPE_HANDLER))) + DBUG_RETURN(error_num); + if ( + !result_list->use_union && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_HANDLER)) + ) + DBUG_RETURN(error_num); + } + + int roop_start, roop_end, roop_count, lock_mode, link_ok; + lock_mode = spider_conn_lock_mode(spider); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = spider->share->link_count; + } else { + link_ok = link_idx; + roop_start = link_idx; + roop_end = link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; + if (spider->sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } + conn = spider->conns[roop_count]; + spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(spider, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->result_link_idx = link_ok; + } else { + spider_db_discard_result(spider, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + result_list->current_row_num = result_list->current->record_num - 1; + if (result_list->quick_mode == 0) + result_list->current->result->move_to_pos(result_list->current_row_num); + DBUG_RETURN(spider_db_fetch(buf, spider, table)); + } + if ((error_num = spider_db_free_result(spider, FALSE))) + DBUG_RETURN(error_num); + spider_first_split_read_param(spider); + result_list->desc_flg = !(result_list->desc_flg); + result_list->limit_num = + result_list->internal_limit >= result_list->split_read ? + result_list->split_read : result_list->internal_limit; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + spider->set_order_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + if ( + (error_num = spider->append_key_order_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)) || + (error_num = spider->append_limit_sql_part( + result_list->internal_offset, + result_list->limit_num, SPIDER_SQL_TYPE_SELECT_SQL)) || + ( + !result_list->use_union && + (spider->sql_kinds & SPIDER_SQL_KIND_SQL) && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + ) + DBUG_RETURN(error_num); + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + const char *alias; + uint alias_length; + if (result_list->sorted && result_list->desc_flg) + { + alias = SPIDER_SQL_LAST_STR; + alias_length = SPIDER_SQL_LAST_LEN; + } else { + alias = SPIDER_SQL_FIRST_STR; + alias_length = SPIDER_SQL_FIRST_LEN; + } + spider->set_order_to_pos_sql(SPIDER_SQL_TYPE_HANDLER); + if ( + (error_num = spider->append_key_order_with_alias_sql_part( + alias, alias_length, SPIDER_SQL_TYPE_HANDLER)) || + (error_num = spider->reappend_limit_sql_part( + result_list->internal_offset, + result_list->limit_num, SPIDER_SQL_TYPE_HANDLER)) + ) + DBUG_RETURN(error_num); + } + + int roop_start, roop_end, roop_count, lock_mode, link_ok; + lock_mode = spider_conn_lock_mode(spider); + if (lock_mode) + { + /* "for update" or "lock in share mode" */ + link_ok = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_OK); + roop_start = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_end = spider->share->link_count; + } else { + link_ok = link_idx; + roop_start = link_idx; + roop_end = link_idx + 1; + } + for (roop_count = roop_start; roop_count < roop_end; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; + if (spider->sql_kind[roop_count] == SPIDER_SQL_KIND_SQL) + { + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + } else { + sql_type = SPIDER_SQL_TYPE_HANDLER; + } + conn = spider->conns[roop_count]; + spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->connection_ids[roop_count] = conn->connection_id; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result(spider, roop_count, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->result_link_idx = link_ok; + } else { + spider_db_discard_result(spider, roop_count, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + DBUG_RETURN(spider_db_fetch(buf, spider, table)); +} + +int spider_db_seek_first( + uchar *buf, + ha_spider *spider, + TABLE *table +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_seek_first"); + if ( + result_list->current != result_list->first && + result_list->low_mem_read == 1 + ) { + my_message(ER_SPIDER_LOW_MEM_READ_PREV_NUM, ER_SPIDER_LOW_MEM_READ_PREV_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LOW_MEM_READ_PREV_NUM); + } + result_list->current = result_list->first; + spider_db_set_pos_to_first_row(result_list); + DBUG_RETURN(spider_db_fetch(buf, spider, table)); +} + +void spider_db_set_pos_to_first_row( + SPIDER_RESULT_LIST *result_list +) { + DBUG_ENTER("spider_db_set_pos_to_first_row"); + result_list->current_row_num = 0; + if (result_list->quick_mode == 0) + result_list->current->result->move_to_pos(0); + DBUG_VOID_RETURN; +} + +void spider_db_create_position( + ha_spider *spider, + SPIDER_POSITION *pos +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_RESULT *current = (SPIDER_RESULT*) result_list->current; + DBUG_ENTER("spider_db_create_position"); + if (result_list->quick_mode == 0) + { + SPIDER_DB_RESULT *result = current->result; + pos->row = result->current_row(); + pos->pos_mode = 2; + pos->row->next_pos = result_list->tmp_pos_row_first; + result_list->tmp_pos_row_first = pos->row; + } else { + if (result_list->current_row_num <= result_list->quick_page_size) + { + SPIDER_POSITION *tmp_pos = + ¤t->first_position[result_list->current_row_num - 1]; + memcpy(pos, tmp_pos, sizeof(SPIDER_POSITION)); + tmp_pos->use_position = TRUE; + tmp_pos->pos_mode = 0; + pos->pos_mode = 0; + } else { + TABLE *tmp_tbl = current->result_tmp_tbl; + pos->row = NULL; + pos->pos_mode = 1; + DBUG_PRINT("info",("spider tmp_tbl=%p", tmp_tbl)); + DBUG_PRINT("info",("spider tmp_tbl->file=%p", tmp_tbl->file)); + DBUG_PRINT("info",("spider tmp_tbl->file->ref=%p", tmp_tbl->file->ref)); + tmp_tbl->file->ref = (uchar *) &pos->tmp_tbl_pos; + tmp_tbl->file->position(tmp_tbl->record[0]); + } + } + current->use_position = TRUE; + pos->use_position = TRUE; + pos->mrr_with_cnt = spider->mrr_with_cnt; + pos->sql_kind = spider->sql_kind[spider->result_link_idx]; + pos->position_bitmap = spider->position_bitmap; + pos->ft_first = spider->ft_first; + pos->ft_current = spider->ft_current; + pos->result = current; + DBUG_VOID_RETURN; +} + +int spider_db_seek_tmp( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_seek_tmp"); + if (pos->pos_mode != 1) + { + if (!pos->row) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + pos->row->first(); + } + if (spider->sql_kind[spider->result_link_idx] == SPIDER_SQL_KIND_SQL) + { + if (!spider->select_column_mode) + { + if (result_list->keyread) + error_num = spider_db_seek_tmp_key(buf, pos, spider, table, + result_list->key_info); + else + error_num = spider_db_seek_tmp_table(buf, pos, spider, table); + } else + error_num = spider_db_seek_tmp_minimum_columns(buf, pos, spider, table); + } else + error_num = spider_db_seek_tmp_table(buf, pos, spider, table); + + DBUG_PRINT("info",("spider error_num=%d", error_num)); + DBUG_RETURN(error_num); +} + +int spider_db_seek_tmp_table( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +) { + int error_num; + Field **field; + SPIDER_DB_ROW *row = pos->row; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + DBUG_ENTER("spider_db_seek_tmp_table"); + if (pos->pos_mode == 1) + { + if ((error_num = spider_db_get_row_from_tmp_tbl_pos(pos, &row))) + DBUG_RETURN(error_num); + } else if (pos->pos_mode == 2) + { +/* + SPIDER_DB_RESULT *result = pos->result->result; + result->current_row = row; +*/ + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + if (pos->sql_kind == SPIDER_SQL_KIND_SQL) + { + row->next(); + } + } + if ((error_num = spider_db_append_match_fetch(spider, + pos->ft_first, pos->ft_current, row))) + DBUG_RETURN(error_num); + + for ( + field = table->field; + *field; + field++ + ) { + if (( + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + )) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", (*field)->field_name)); + if ((error_num = + spider_db_fetch_row(spider->share, *field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + row->next(); + } + DBUG_RETURN(0); +} + +int spider_db_seek_tmp_key( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table, + const KEY *key_info +) { + int error_num; + KEY_PART_INFO *key_part; + uint part_num; + SPIDER_DB_ROW *row = pos->row; + Field *field; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + DBUG_ENTER("spider_db_seek_tmp_key"); + if (pos->pos_mode == 1) + { + if ((error_num = spider_db_get_row_from_tmp_tbl_pos(pos, &row))) + DBUG_RETURN(error_num); + } else if (pos->pos_mode == 2) + { +/* + SPIDER_DB_RESULT *result = pos->result->result; + result->current_row = row; +*/ + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + row->next(); + } + if ((error_num = spider_db_append_match_fetch(spider, + pos->ft_first, pos->ft_current, row))) + DBUG_RETURN(error_num); + + for ( + key_part = key_info->key_part, + part_num = 0; + part_num < key_info->key_parts; + key_part++, + part_num++ + ) { + field = key_part->field; + if (( + bitmap_is_set(table->read_set, field->field_index) | + bitmap_is_set(table->write_set, field->field_index) + )) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", field->field_name)); + if ((error_num = + spider_db_fetch_row(spider->share, field, row, ptr_diff))) + DBUG_RETURN(error_num); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + row->next(); + } + DBUG_RETURN(0); +} + +int spider_db_seek_tmp_minimum_columns( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +) { + int error_num; + Field **field; + SPIDER_DB_ROW *row = pos->row; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + DBUG_ENTER("spider_db_seek_tmp_minimum_columns"); + if (pos->pos_mode == 1) + { + if ((error_num = spider_db_get_row_from_tmp_tbl_pos(pos, &row))) + DBUG_RETURN(error_num); + } else if (pos->pos_mode == 2) + { +/* + SPIDER_DB_RESULT *result = pos->result->result; + result->current_row = row; +*/ + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + row->next(); + } + if ((error_num = spider_db_append_match_fetch(spider, + pos->ft_first, pos->ft_current, row))) + DBUG_RETURN(error_num); + + for ( + field = table->field; + *field; + field++ + ) { + DBUG_PRINT("info", ("spider field_index %u", (*field)->field_index)); + if (spider_bit_is_set(pos->position_bitmap, (*field)->field_index)) + { +/* + if (( + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + )) { + DBUG_PRINT("info", ("spider read_set %u", + bitmap_is_set(table->read_set, (*field)->field_index))); + DBUG_PRINT("info", ("spider write_set %u", + bitmap_is_set(table->write_set, (*field)->field_index))); +*/ +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", (*field)->field_name)); + if ((error_num = + spider_db_fetch_row(spider->share, *field, row, ptr_diff))) + DBUG_RETURN(error_num); + row->next(); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + } + else if (bitmap_is_set(table->read_set, (*field)->field_index)) + { + DBUG_PRINT("info", ("spider bitmap is cleared %s", + (*field)->field_name)); + bitmap_clear_bit(table->read_set, (*field)->field_index); + } + } + DBUG_RETURN(0); +} + +int spider_db_show_table_status( + ha_spider *spider, + int link_idx, + int sts_mode, + uint flag +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_db_show_table_status"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + sts_mode = dbton_hdl->sts_mode_exchange(sts_mode); + error_num = dbton_hdl->show_table_status( + link_idx, + sts_mode, + flag + ); + DBUG_RETURN(error_num); +} + +int spider_db_show_records( + ha_spider *spider, + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_db_show_records"); + error_num = spider->dbton_handler[conn->dbton_id]->show_records( + link_idx + ); + DBUG_RETURN(error_num); +} + +void spider_db_set_cardinarity( + ha_spider *spider, + TABLE *table +) { + int roop_count, roop_count2; + SPIDER_SHARE *share = spider->share; + KEY *key_info; + KEY_PART_INFO *key_part; + Field *field; + ha_rows rec_per_key; + DBUG_ENTER("spider_db_set_cardinarity"); + for (roop_count = 0; roop_count < (int) table->s->keys; roop_count++) + { + key_info = &table->key_info[roop_count]; + for (roop_count2 = 0; roop_count2 < (int) key_info->key_parts; + roop_count2++) + { + key_part = &key_info->key_part[roop_count2]; + field = key_part->field; + rec_per_key = (ha_rows) share->records / + share->cardinality[field->field_index]; + if (rec_per_key > ~(ulong) 0) + key_info->rec_per_key[roop_count2] = ~(ulong) 0; + else if (rec_per_key == 0) + key_info->rec_per_key[roop_count2] = 1; + else + key_info->rec_per_key[roop_count2] = (ulong) rec_per_key; + DBUG_PRINT("info", + ("spider column id=%d", field->field_index)); + DBUG_PRINT("info", + ("spider cardinality=%lld", + share->cardinality[field->field_index])); + DBUG_PRINT("info", + ("spider rec_per_key=%lu", + key_info->rec_per_key[roop_count2])); + } + } + DBUG_VOID_RETURN; +} + +int spider_db_show_index( + ha_spider *spider, + int link_idx, + TABLE *table, + int crd_mode +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_db_show_index"); + crd_mode = dbton_hdl->crd_mode_exchange(crd_mode); + error_num = spider->dbton_handler[conn->dbton_id]->show_index( + link_idx, + crd_mode + ); + DBUG_RETURN(error_num); +} + +ha_rows spider_db_explain_select( + key_range *start_key, + key_range *end_key, + ha_spider *spider, + int link_idx +) { + SPIDER_CONN *conn = spider->conns[link_idx]; + ha_rows rows; + DBUG_ENTER("spider_db_explain_select"); + rows = spider->dbton_handler[conn->dbton_id]->explain_select( + start_key, + end_key, + link_idx + ); + DBUG_RETURN(rows); +} + +int spider_db_bulk_insert_init( + ha_spider *spider, + const TABLE *table +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_db_bulk_insert_init"); + spider->sql_kinds = 0; + spider->reset_sql_sql(SPIDER_SQL_TYPE_INSERT_SQL); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->reset_hs_sql(SPIDER_SQL_TYPE_OTHER_HS); +#endif + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if (spider->conns[roop_count]) + spider->conns[roop_count]->ignore_dup_key = spider->ignore_dup_key; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + spider_conn_use_handler(spider, spider->lock_mode, roop_count) && + ( + !spider->handler_opened(roop_count, SPIDER_CONN_KIND_HS_WRITE) || +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + spider->hs_w_ret_fields_num[roop_count] < MAX_FIELDS || +#endif + spider->hs_w_conns[roop_count]->server_lost + ) + ) { + if ((error_num = spider_db_open_handler(spider, + spider->hs_w_conns[roop_count], roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->set_handler_opened(roop_count); + } +#else + spider_conn_use_handler(spider, spider->lock_mode, roop_count); +#endif + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { +#endif + if ( + (error_num = spider->append_insert_sql_part()) || + (error_num = spider->append_into_sql_part( + SPIDER_SQL_TYPE_INSERT_SQL)) + ) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HS) + { + spider->result_list.hs_upd_rows = 0; + } +#endif + DBUG_RETURN(0); +} + +int spider_db_bulk_insert( + ha_spider *spider, + TABLE *table, + bool bulk_end +) { + int error_num, first_insert_link_idx = -1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_RESULT_LIST *result_list = &spider->result_list; +#endif + SPIDER_SHARE *share = spider->share; + THD *thd = spider->trx->thd; + bool mta_conn_mutex_lock_already_backup; + bool mta_conn_mutex_unlock_later_backup; + DBUG_ENTER("spider_db_bulk_insert"); + + if (!bulk_end) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { +#endif + if ((error_num = spider->append_insert_values_sql_part( + SPIDER_SQL_TYPE_INSERT_SQL))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HS) + { + if ((error_num = spider->append_insert_values_hs_part( + SPIDER_SQL_TYPE_INSERT_HS))) + DBUG_RETURN(error_num); + result_list->hs_upd_rows++; + } +#endif + } + + if (spider->is_bulk_insert_exec_period(bulk_end)) + { + int roop_count2; + SPIDER_CONN *conn, *first_insert_conn = NULL; + if ((error_num = spider->append_insert_terminator_sql_part( + SPIDER_SQL_TYPE_INSERT_SQL))) + { + DBUG_RETURN(error_num); + } +#ifdef HA_CAN_BULK_ACCESS + if (!spider->is_bulk_access_clone) + { +#endif + for ( + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count2 < (int) share->link_count; + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count2, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; + spider_db_handler *dbton_handler; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[roop_count2] == SPIDER_CONN_KIND_MYSQL) + { +#endif + sql_type = SPIDER_SQL_TYPE_INSERT_SQL; + conn = spider->conns[roop_count2]; + dbton_handler = spider->dbton_handler[conn->dbton_id]; + mta_conn_mutex_lock_already_backup = + conn->mta_conn_mutex_lock_already; + mta_conn_mutex_unlock_later_backup = + conn->mta_conn_mutex_unlock_later; + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + if (!mta_conn_mutex_lock_already_backup) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + } + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + roop_count2))) + { + DBUG_RETURN(error_num); + } + if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + if (!mta_conn_mutex_lock_already_backup) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + sql_type = SPIDER_SQL_TYPE_INSERT_HS; + conn = spider->hs_w_conns[roop_count2]; + dbton_handler = spider->dbton_handler[conn->dbton_id]; + mta_conn_mutex_lock_already_backup = + conn->mta_conn_mutex_lock_already; + mta_conn_mutex_unlock_later_backup = + conn->mta_conn_mutex_unlock_later; + if (!mta_conn_mutex_lock_already_backup) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + } +#endif + conn->need_mon = &spider->need_mons[roop_count2]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count2))) + { + conn->mta_conn_mutex_lock_already = + mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = + mta_conn_mutex_unlock_later_backup; + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if ( + share->monitoring_kind[roop_count2] && + spider->need_mons[roop_count2] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count2], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count2], + NULL, + 0, + share->monitoring_kind[roop_count2], + share->monitoring_limit[roop_count2], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count2, spider->trx->thd, + share); + if (dbton_handler->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[roop_count2]) + ) { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + error_num = spider_db_errorno(conn); + if (error_num == HA_ERR_FOUND_DUPP_KEY) + { + conn->db_conn->set_dup_key_idx(spider, roop_count2); + } + conn->mta_conn_mutex_lock_already = + mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = + mta_conn_mutex_unlock_later_backup; + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if ( + error_num != ER_DUP_ENTRY && + error_num != ER_DUP_KEY && + error_num != HA_ERR_FOUND_DUPP_KEY && + share->monitoring_kind[roop_count2] && + spider->need_mons[roop_count2] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count2], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count2], + NULL, + 0, + share->monitoring_kind[roop_count2], + share->monitoring_limit[roop_count2], + TRUE + ); + } + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind != SPIDER_CONN_KIND_MYSQL) + { + uint roop_count; + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider result_list->hs_upd_rows=%llu", + result_list->hs_upd_rows)); + for (roop_count = 0; roop_count < result_list->hs_upd_rows; + roop_count++) + { + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, roop_count2)) + { + spider_clear_bit(spider->db_request_phase, roop_count2); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[roop_count2]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + DBUG_RETURN(error_num); + } + } + } +#endif + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if (first_insert_link_idx == -1) + { + first_insert_link_idx = roop_count2; + first_insert_conn = conn; + } + } + + conn = first_insert_conn; + mta_conn_mutex_lock_already_backup = conn->mta_conn_mutex_lock_already; + mta_conn_mutex_unlock_later_backup = conn->mta_conn_mutex_unlock_later; + if (!mta_conn_mutex_lock_already_backup) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &spider->need_mons[first_insert_link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + if (table->next_number_field && + ( + !table->auto_increment_field_not_null || + ( + !table->next_number_field->val_int() && + !(thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + ) + ) + ) { + ulonglong last_insert_id; + spider_db_handler *dbton_handler = + spider->dbton_handler[conn->dbton_id]; + if (spider->store_last_insert_id) + last_insert_id = spider->store_last_insert_id; + else if ((error_num = dbton_handler-> + show_last_insert_id(first_insert_link_idx, last_insert_id))) + { + conn->mta_conn_mutex_lock_already = + mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = + mta_conn_mutex_unlock_later_backup; + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + table->next_number_field->set_notnull(); + if ( + (error_num = spider_db_update_auto_increment(spider, + first_insert_link_idx)) || + (error_num = table->next_number_field->store( + last_insert_id, TRUE)) + ) { + conn->mta_conn_mutex_lock_already = + mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = + mta_conn_mutex_unlock_later_backup; + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + } + conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; + conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; + if (!mta_conn_mutex_unlock_later_backup) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + spider->store_last_insert_id = 0; +#ifdef HA_CAN_BULK_ACCESS + } +#endif + } + if ( + (bulk_end || !spider->bulk_insert) && + (error_num = spider_trx_check_link_idx_failed(spider)) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_bulk_insert( + ha_spider *spider +) { + int error_num = 0, first_insert_link_idx = -1, tmp_error_num; + int roop_count2; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn, *first_insert_conn = NULL; + TABLE *table = spider->get_table(); + THD *thd = spider->trx->thd; + DBUG_ENTER("spider_db_bulk_bulk_insert"); + for ( + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count2 < (int) share->link_count; + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count2, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[roop_count2] == SPIDER_CONN_KIND_MYSQL) + { +#endif + conn = spider->conns[roop_count2]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + conn = spider->hs_w_conns[roop_count2]; + } +#endif + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, + roop_count2))) + { + error_num = tmp_error_num; + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind != SPIDER_CONN_KIND_MYSQL) + { + uint roop_count; + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider result_list->hs_upd_rows=%llu", + result_list->hs_upd_rows)); + for (roop_count = 0; roop_count < result_list->hs_upd_rows; + roop_count++) + { + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, roop_count2)) + { + spider_clear_bit(spider->db_request_phase, roop_count2); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[roop_count2]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + DBUG_RETURN(error_num); + } + } + } +#endif + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (first_insert_link_idx == -1) + { + first_insert_link_idx = roop_count2; + first_insert_conn = conn; + } + } + + conn = first_insert_conn; + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[first_insert_link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (table->next_number_field && + ( + !table->auto_increment_field_not_null || + ( + !table->next_number_field->val_int() && + !(thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + ) + ) + ) { + ulonglong last_insert_id; + if (spider->store_last_insert_id) + last_insert_id = spider->store_last_insert_id; + else + last_insert_id = conn->db_conn->last_insert_id(); + table->next_number_field->set_notnull(); + if ( + (tmp_error_num = spider_db_update_auto_increment(spider, + first_insert_link_idx)) || + (tmp_error_num = table->next_number_field->store( + last_insert_id, TRUE)) + ) { + error_num = tmp_error_num; + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + spider->store_last_insert_id = 0; + DBUG_RETURN(error_num); +} +#endif + +int spider_db_update_auto_increment( + ha_spider *spider, + int link_idx +) { + int roop_count; + THD *thd = spider->trx->thd; + ulonglong last_insert_id, affected_rows; + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + int auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + DBUG_ENTER("spider_db_update_auto_increment"); + if ( + auto_increment_mode == 2 || + (auto_increment_mode == 3 && !table->auto_increment_field_not_null) + ) { + last_insert_id = spider->conns[link_idx]->db_conn->last_insert_id(); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL) + { +#endif + affected_rows = spider->conns[link_idx]->db_conn->affected_rows(); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + affected_rows = spider->result_list.hs_upd_rows; + } +#endif + DBUG_PRINT("info",("spider last_insert_id=%llu", last_insert_id)); + share->auto_increment_value = + last_insert_id + affected_rows; +/* + thd->record_first_successful_insert_id_in_cur_stmt(last_insert_id); +*/ + if ( + thd->first_successful_insert_id_in_cur_stmt == 0 || + thd->first_successful_insert_id_in_cur_stmt > last_insert_id + ) { + bool first_set = (thd->first_successful_insert_id_in_cur_stmt == 0); + thd->first_successful_insert_id_in_cur_stmt = last_insert_id; + if ( + table->s->next_number_keypart == 0 && + mysql_bin_log.is_open() && +#if MYSQL_VERSION_ID < 50500 + !thd->current_stmt_binlog_row_based +#else + !thd->is_current_stmt_binlog_format_row() +#endif + ) { + if ( + spider->check_partitioned() && + thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0 + ) { + DBUG_PRINT("info",("spider table partitioning")); + Discrete_interval *current = + thd->auto_inc_intervals_in_cur_stmt_for_binlog.get_current(); + current->replace(last_insert_id, affected_rows, 1); + } else { + DBUG_PRINT("info",("spider table")); + thd->auto_inc_intervals_in_cur_stmt_for_binlog.append( + last_insert_id, affected_rows, 1); + } + if (affected_rows > 1 || !first_set) + { + for (roop_count = first_set ? 1 : 0; + roop_count < (int) affected_rows; + roop_count++) + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_NUM, + ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_STR); + } + } + } else { + if ( + table->s->next_number_keypart == 0 && + mysql_bin_log.is_open() && +#if MYSQL_VERSION_ID < 50500 + !thd->current_stmt_binlog_row_based +#else + !thd->is_current_stmt_binlog_format_row() +#endif + ) { + for (roop_count = 0; roop_count < (int) affected_rows; roop_count++) + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_NUM, + ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_STR); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_bulk_update_size_limit( + ha_spider *spider, + TABLE *table +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_CONN *conn; + uint dup_key_found = 0; + DBUG_ENTER("spider_db_bulk_update_size_limit"); + + if (result_list->bulk_update_mode == 1) + { + /* execute bulk updating */ + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = spider_db_query_for_bulk_update( + spider, conn, roop_count, &dup_key_found))) + DBUG_RETURN(error_num); + } + spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); + } else { + /* store query to temporary tables */ + if ((error_num = spider->mk_bulk_tmp_table_and_bulk_start())) + { + goto error_mk_table; + } + if ((error_num = spider->bulk_tmp_table_insert())) + { + goto error_write_row; + } + spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); + } + DBUG_RETURN(0); + +error_write_row: + spider->bulk_tmp_table_end_bulk_insert(); + spider->rm_bulk_tmp_table(); + spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); +error_mk_table: + DBUG_RETURN(error_num); +} + +int spider_db_bulk_update_end( + ha_spider *spider, + uint *dup_key_found +) { + int error_num = 0, error_num2, roop_count; + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + bool is_error = thd->is_error(); + DBUG_ENTER("spider_db_bulk_update_end"); + + if (spider->bulk_tmp_table_created()) + { + if ((error_num2 = spider->bulk_tmp_table_end_bulk_insert())) + { + error_num = error_num2; + } + + if (!is_error) + { + if (error_num) + goto error_last_query; + + if ((error_num = spider->bulk_tmp_table_rnd_init())) + { + goto error_rnd_init; + } + + while (!(error_num = spider->bulk_tmp_table_rnd_next())) + { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) + { + if (error_num == ER_SPIDER_COND_SKIP_NUM) + { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + continue; + } + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = spider_db_query_for_bulk_update( + spider, conn, roop_count, dup_key_found))) + goto error_query; + } + } + if (error_num != HA_ERR_END_OF_FILE) + goto error_rnd_next; + + spider->bulk_tmp_table_rnd_end(); + } + } + + if (!is_error) + { + if (!spider->sql_is_empty(SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = spider_db_query_for_bulk_update( + spider, conn, roop_count, dup_key_found))) + goto error_last_query; + } + } + } + spider->rm_bulk_tmp_table(); + spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); + DBUG_RETURN(0); + +error_query: +error_rnd_next: + spider->bulk_tmp_table_rnd_end(); +error_rnd_init: +error_last_query: + spider->rm_bulk_tmp_table(); + spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); + DBUG_RETURN(error_num); +} + +int spider_db_bulk_update( + ha_spider *spider, + TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + DBUG_ENTER("spider_db_bulk_update"); + + if ((error_num = spider->append_update_sql(table, ptr_diff, TRUE))) + DBUG_RETURN(error_num); + + if ( + spider->sql_is_filled_up(SPIDER_SQL_TYPE_BULK_UPDATE_SQL) && + (error_num = spider_db_bulk_update_size_limit(spider, table)) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_db_update( + ha_spider *spider, + TABLE *table, + const uchar *old_data +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(old_data, table->record[0]); + DBUG_ENTER("spider_db_update"); + if (result_list->bulk_update_mode) + DBUG_RETURN(spider_db_bulk_update(spider, table, ptr_diff)); + + if ((error_num = spider->append_update_sql(table, ptr_diff, FALSE))) + DBUG_RETURN(error_num); + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + conn->ignore_dup_key = spider->ignore_dup_key; +#endif + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_UPDATE_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + error_num != ER_DUP_ENTRY && + error_num != ER_DUP_KEY && + error_num != HA_ERR_FOUND_DUPP_KEY && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + + if ( + !conn->db_conn->affected_rows() && + share->link_statuses[roop_count] == SPIDER_LINK_STATUS_RECOVERY && + spider->pk_update + ) { + /* insert */ + if ((error_num = dbton_hdl->append_insert_for_recovery( + SPIDER_SQL_TYPE_INSERT_SQL, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_INSERT_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + error_num != ER_DUP_ENTRY && + error_num != ER_DUP_KEY && + error_num != HA_ERR_FOUND_DUPP_KEY && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + result_list->update_sqls[roop_count].length(0); + } + spider->reset_sql_sql(SPIDER_SQL_TYPE_UPDATE_SQL); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_direct_update( + ha_spider *spider, + TABLE *table, + KEY_MULTI_RANGE *ranges, + uint range_count, + uint *update_rows +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + bool counted = FALSE; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + DBUG_ENTER("spider_db_direct_update"); + + spider_set_result_list_param(spider); + result_list->finish_flg = FALSE; + DBUG_PRINT("info", ("spider do_direct_update=%s", + spider->do_direct_update ? "TRUE" : "FALSE")); + DBUG_PRINT("info", ("spider direct_update_kinds=%u", + spider->direct_update_kinds)); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + ( + spider->do_direct_update && + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + ) || + ( + !spider->do_direct_update && +#endif + (spider->sql_kinds & SPIDER_SQL_KIND_SQL) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + ) +#endif + ) { +#endif + if ((error_num = spider->append_update_sql_part())) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + +/* + SQL access -> SQL remote access + !spider->do_direct_update && + (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + + SQL access -> SQL remote access with dirct_update + spider->do_direct_update && + spider->direct_update_kinds == SPIDER_SQL_KIND_SQL && + spider->direct_update_fields + + Handlersocket access -> SQL remote access with dirct_update + spider->do_direct_update && + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + + Handlersocket access -> Handlersocket access + spider->do_direct_update && + (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) +*/ + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider->hs_increment || spider->hs_decrement) + { + if ( + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) && + (error_num = spider->append_increment_update_set_sql_part()) + ) { + DBUG_RETURN(error_num); + } + } else { +#endif +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (!spider->do_direct_update) + { +#endif + if ( + (spider->sql_kinds & SPIDER_SQL_KIND_SQL) && + (error_num = spider->append_update_set_sql_part()) + ) { + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + } else { + if ( + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) && + (error_num = spider->append_direct_update_set_sql_part()) + ) { + DBUG_RETURN(error_num); + } + if ( + (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) && + (error_num = spider->append_direct_update_set_hs_part()) + ) { + DBUG_RETURN(error_num); + } + } +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + + result_list->desc_flg = FALSE; + result_list->sorted = TRUE; + if (spider->active_index == MAX_KEY) + result_list->key_info = NULL; + else + result_list->key_info = &table->key_info[spider->active_index]; + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + result_list->limit_num = + result_list->internal_limit >= select_limit ? + select_limit : result_list->internal_limit; + result_list->internal_offset += offset_limit; + if (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + { + if ( + (error_num = spider->append_key_where_sql_part( + (ranges && ranges->start_key.key) ? &ranges->start_key : NULL, + (ranges && ranges->end_key.key) ? &ranges->end_key : NULL, + SPIDER_SQL_TYPE_UPDATE_SQL)) || + (error_num = spider-> + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_UPDATE_SQL)) || + (error_num = spider->append_limit_sql_part( + result_list->internal_offset, result_list->limit_num, + SPIDER_SQL_TYPE_UPDATE_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) + { + if ( + (error_num = spider->append_key_where_hs_part( + (ranges && ranges->start_key.key) ? &ranges->start_key : NULL, + (ranges && ranges->end_key.key) ? &ranges->end_key : NULL, + SPIDER_SQL_TYPE_UPDATE_HS)) || + (error_num = spider->append_limit_hs_part( + result_list->internal_offset, result_list->limit_num, + SPIDER_SQL_TYPE_UPDATE_HS)) + ) { + DBUG_RETURN(error_num); + } + } + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { +#endif + DBUG_PRINT("info", ("spider exec sql")); + conn = spider->conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_UPDATE_SQL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + DBUG_PRINT("info", ("spider exec hs")); + conn = spider->hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_UPDATE_HS; + } +#endif + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } +#ifdef HA_CAN_BULK_ACCESS + if (spider->is_bulk_access_clone) + { + spider->connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(spider->trx, conn); + } else { +#endif + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if ( + (error_num = dbton_hdl->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[roop_count]) + ) && + (error_num != HA_ERR_FOUND_DUPP_KEY || !spider->ignore_dup_key) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + error_num != ER_DUP_ENTRY && + error_num != ER_DUP_KEY && + error_num != HA_ERR_FOUND_DUPP_KEY && + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { + if (!counted) + { +#endif + *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider update_rows = %u", *update_rows)); + counted = TRUE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, roop_count)) + { + spider_clear_bit(spider->db_request_phase, roop_count); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[roop_count]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + if (!counted) + { + *update_rows = conn->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider update_rows = %u", *update_rows)); + counted = TRUE; + } + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } +#endif +#ifdef HA_CAN_BULK_ACCESS + } +#endif + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + spider->reset_sql_sql(SPIDER_SQL_TYPE_UPDATE_SQL); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->reset_hs_sql(SPIDER_SQL_TYPE_UPDATE_HS); + spider->reset_hs_keys(SPIDER_SQL_TYPE_UPDATE_HS); + spider->reset_hs_upds(SPIDER_SQL_TYPE_UPDATE_HS); +#endif + DBUG_RETURN(0); +} +#endif + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_direct_update( + ha_spider *spider, + uint *update_rows +) { + int error_num = 0, roop_count, tmp_error_num; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + bool counted = FALSE; + DBUG_ENTER("spider_db_bulk_direct_update"); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { +#endif + DBUG_PRINT("info", ("spider exec sql")); + conn = spider->conns[roop_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + DBUG_PRINT("info", ("spider exec hs")); + conn = spider->hs_w_conns[roop_count]; + } +#endif + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, + roop_count))) + { + error_num = tmp_error_num; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { + if (!counted) + { +#endif + *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider update_rows = %u", *update_rows)); + counted = TRUE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, roop_count)) + { + spider_clear_bit(spider->db_request_phase, roop_count); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[roop_count]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + if (!counted) + { + *update_rows = conn->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider update_rows = %u", *update_rows)); + counted = TRUE; + } + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } +#endif + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); +} +#endif + +int spider_db_bulk_delete( + ha_spider *spider, + TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + DBUG_ENTER("spider_db_bulk_delete"); + + if ((error_num = spider->append_delete_sql(table, ptr_diff, TRUE))) + DBUG_RETURN(error_num); + + if ( + spider->sql_is_filled_up(SPIDER_SQL_TYPE_BULK_UPDATE_SQL) && + (error_num = spider_db_bulk_update_size_limit(spider, table)) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_db_delete( + ha_spider *spider, + TABLE *table, + const uchar *buf +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); + DBUG_ENTER("spider_db_delete"); + if (result_list->bulk_update_mode) + DBUG_RETURN(spider_db_bulk_delete(spider, table, ptr_diff)); + + if ((error_num = spider->append_delete_sql(table, ptr_diff, FALSE))) + DBUG_RETURN(error_num); + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = spider_db_query_with_set_names( + SPIDER_SQL_TYPE_DELETE_SQL, spider, conn, roop_count))) + DBUG_RETURN(error_num); + result_list->update_sqls[roop_count].length(0); + } + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_direct_delete( + ha_spider *spider, + TABLE *table, + KEY_MULTI_RANGE *ranges, + uint range_count, + uint *delete_rows +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + bool counted = FALSE; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + DBUG_ENTER("spider_db_direct_delete"); + + spider_set_result_list_param(spider); + result_list->finish_flg = FALSE; + result_list->desc_flg = FALSE; + result_list->sorted = TRUE; + if (spider->active_index == MAX_KEY) + result_list->key_info = NULL; + else + result_list->key_info = &table->key_info[spider->active_index]; + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + result_list->limit_num = + result_list->internal_limit >= select_limit ? + select_limit : result_list->internal_limit; + result_list->internal_offset += offset_limit; +/* + result_list->limit_num = + result_list->internal_limit >= result_list->split_read ? + result_list->split_read : result_list->internal_limit; +*/ + if (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + { + if ( + (error_num = spider->append_delete_sql_part()) || + (error_num = spider->append_from_sql_part(SPIDER_SQL_TYPE_DELETE_SQL)) + ) { + DBUG_RETURN(error_num); + } + spider->set_where_pos_sql(SPIDER_SQL_TYPE_DELETE_SQL); + if ( + (error_num = spider->append_key_where_sql_part( + (ranges && ranges->start_key.key) ? &ranges->start_key : NULL, + (ranges && ranges->end_key.key) ? &ranges->end_key : NULL, + SPIDER_SQL_TYPE_DELETE_SQL)) || + (error_num = spider-> + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_DELETE_SQL)) || + (error_num = spider->append_limit_sql_part( + result_list->internal_offset, result_list->limit_num, + SPIDER_SQL_TYPE_DELETE_SQL)) + ) { + DBUG_RETURN(error_num); + } + } + if (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) + { + if ( + (error_num = spider->append_key_where_hs_part( + (ranges && ranges->start_key.key) ? &ranges->start_key : NULL, + (ranges && ranges->end_key.key) ? &ranges->end_key : NULL, + SPIDER_SQL_TYPE_DELETE_HS)) || + (error_num = spider->append_limit_hs_part( + result_list->internal_offset, result_list->limit_num, + SPIDER_SQL_TYPE_DELETE_HS)) + ) { + DBUG_RETURN(error_num); + } + } + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + ulong sql_type; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { +#endif + DBUG_PRINT("info", ("spider exec sql")); + conn = spider->conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_DELETE_SQL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + DBUG_PRINT("info", ("spider exec hs")); + conn = spider->hs_w_conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_DELETE_HS; + } +#endif + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } +#ifdef HA_CAN_BULK_ACCESS + if (spider->is_bulk_access_clone) + { + spider->connection_ids[roop_count] = conn->connection_id; + spider_trx_add_bulk_access_conn(spider->trx, conn); + } else { +#endif + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider_bit_is_set(spider->do_hs_direct_update, roop_count)) + { +#endif + if (!counted) + { + *delete_rows = spider->conns[roop_count]->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider delete_rows = %u", *delete_rows)); + counted = TRUE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, roop_count)) + { + spider_clear_bit(spider->db_request_phase, roop_count); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[roop_count]; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + if (!counted) + { + *delete_rows = conn->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider delete_rows = %u", *delete_rows)); + counted = TRUE; + } + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + DBUG_RETURN(error_num); + } + } +#endif +#ifdef HA_CAN_BULK_ACCESS + } +#endif + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + int error_num2 = 0; + if (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) + error_num2 = error_num; + } + if (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) + { + if ((error_num = spider->reset_hs_sql(SPIDER_SQL_TYPE_DELETE_HS))) + error_num2 = error_num; + if ((error_num = spider->reset_hs_keys(SPIDER_SQL_TYPE_DELETE_HS))) + error_num2 = error_num; + } + DBUG_RETURN(error_num2); +} +#endif + +int spider_db_delete_all_rows( + ha_spider *spider +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + DBUG_ENTER("spider_db_delete_all_rows"); + if ((error_num = spider->append_delete_all_rows_sql_part( + SPIDER_SQL_TYPE_DELETE_SQL))) + DBUG_RETURN(error_num); + + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + uint dbton_id = share->use_sql_dbton_ids[roop_count]; + spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id]; + conn = spider->conns[roop_count]; + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + if (!dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + } + conn->need_mon = &spider->need_mons[roop_count]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, roop_count)) || + ( + dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_DELETE_SQL, + conn, + -1, + &spider->need_mons[roop_count]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_DELETE_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_db_disable_keys( + ha_spider *spider +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_disable_keys"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->disable_keys(conn, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_enable_keys( + ha_spider *spider +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_enable_keys"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->enable_keys(conn, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_check_table( + ha_spider *spider, + HA_CHECK_OPT* check_opt +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_check_table"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->check_table(conn, roop_count, check_opt))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_repair_table( + ha_spider *spider, + HA_CHECK_OPT* check_opt +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_repair_table"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->repair_table(conn, roop_count, check_opt))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_analyze_table( + ha_spider *spider +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_analyze_table"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->analyze_table(conn, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_optimize_table( + ha_spider *spider +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_optimize_table"); + if ( + spider_param_internal_optimize(spider->trx->thd, + share->internal_optimize) == 1 + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->optimize_table(conn, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_flush_tables( + ha_spider *spider, + bool lock +) { + int error_num, roop_count; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_flush_tables"); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->flush_tables(conn, roop_count, lock))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_db_flush_logs( + ha_spider *spider +) { + int roop_count, error_num; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_db_flush_logs"); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + conn = spider->conns[roop_count]; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + if ((error_num = dbton_hdl->flush_logs(conn, roop_count))) + { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_db_print_item_type( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + DBUG_ENTER("spider_db_print_item_type"); + DBUG_PRINT("info",("spider COND type=%d", item->type())); + switch (item->type()) + { + case Item::FUNC_ITEM: + DBUG_RETURN(spider_db_open_item_func((Item_func *) item, spider, str, + alias, alias_length, dbton_id)); + case Item::COND_ITEM: + DBUG_RETURN(spider_db_open_item_cond((Item_cond *) item, spider, str, + alias, alias_length, dbton_id)); + case Item::FIELD_ITEM: + DBUG_RETURN(spider_db_open_item_field((Item_field *) item, spider, str, + alias, alias_length, dbton_id)); + case Item::REF_ITEM: + DBUG_RETURN(spider_db_open_item_ref((Item_ref *) item, spider, str, + alias, alias_length, dbton_id)); + case Item::ROW_ITEM: + DBUG_RETURN(spider_db_open_item_row((Item_row *) item, spider, str, + alias, alias_length, dbton_id)); + case Item::STRING_ITEM: + DBUG_RETURN(spider_db_open_item_string(item, spider, str, + alias, alias_length, dbton_id)); + case Item::INT_ITEM: + case Item::REAL_ITEM: + case Item::DECIMAL_ITEM: + DBUG_RETURN(spider_db_open_item_int(item, spider, str, + alias, alias_length, dbton_id)); + case Item::CACHE_ITEM: + DBUG_RETURN(spider_db_open_item_cache((Item_cache *)item, spider, str, + alias, alias_length, dbton_id)); + case Item::SUBSELECT_ITEM: + case Item::TRIGGER_FIELD_ITEM: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + default: + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + if (spider_param_skip_default_condition(thd, + share->skip_default_condition)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + if (spider->share->access_charset->cset == system_charset_info->cset) + { +#if MYSQL_VERSION_ID < 50500 + item->print(str->get_str(), QT_IS); +#else + item->print(str->get_str(), QT_TO_SYSTEM_CHARSET); +#endif + } else { + item->print(str->get_str(), QT_ORDINARY); + } + str->mem_calc(); + } + break; + } + DBUG_RETURN(0); +} + +int spider_db_open_item_cond( + Item_cond *item_cond, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num = 0; + List_iterator_fast lif(*(item_cond->argument_list())); + Item *item; + char *func_name = NULL; + int func_name_length = 0, restart_pos = 0; + DBUG_ENTER("spider_db_open_item_cond"); + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + +restart_first: + if ((item = lif++)) + { + if (str) + restart_pos = str->length(); + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + { + if ( + str && + error_num == ER_SPIDER_COND_SKIP_NUM && + item_cond->functype() == Item_func::COND_AND_FUNC + ) { + DBUG_PRINT("info",("spider COND skip")); + str->length(restart_pos); + goto restart_first; + } + DBUG_RETURN(error_num); + } + } + if (error_num) + DBUG_RETURN(error_num); + while ((item = lif++)) + { + if (str) + { + restart_pos = str->length(); + if (!func_name) + { + func_name = (char*) item_cond->func_name(); + func_name_length = strlen(func_name); + } + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + { + if ( + str && + error_num == ER_SPIDER_COND_SKIP_NUM && + item_cond->functype() == Item_func::COND_AND_FUNC + ) { + DBUG_PRINT("info",("spider COND skip")); + str->length(restart_pos); + } else + DBUG_RETURN(error_num); + } + } + if (str) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + DBUG_ENTER("spider_db_open_item_func"); + DBUG_RETURN(spider_dbton[dbton_id].db_util->open_item_func( + item_func, spider, str, alias, alias_length)); +} + +int spider_db_open_item_ident( + Item_ident *item_ident, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num, field_name_length; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_db_open_item_ident"); + if ( + item_ident->cached_field_index != NO_CACHED_FIELD_INDEX && + item_ident->cached_table + ) { + Field *field = item_ident->cached_table->table->field[ + item_ident->cached_field_index]; + if (!(field = spider->field_exchange(field))) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + DBUG_PRINT("info",("spider use cached_field_index")); + if (str) + { + if ((error_num = share->dbton_share[dbton_id]-> + append_column_name_with_alias(str, field->field_index, + alias, alias_length))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); + } + if (str) + { + if (item_ident->field_name) + field_name_length = strlen(item_ident->field_name); + else + field_name_length = 0; + if (share->access_charset->cset == system_charset_info->cset) + { + if (str->reserve(alias_length + + field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(alias, alias_length); + if ((error_num = spider_dbton[dbton_id].db_util-> + append_name(str, item_ident->field_name, field_name_length))) + { + DBUG_RETURN(error_num); + } + } else { + if (str->reserve(alias_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + if ((error_num = spider_dbton[dbton_id].db_util-> + append_name_with_charset(str, item_ident->field_name, + field_name_length, system_charset_info))) + { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_open_item_field( + Item_field *item_field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num; + Field *field = item_field->field; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_db_open_item_field"); + if (field) + { + DBUG_PRINT("info",("spider field=%p", field)); + if (!(field = spider->field_exchange(field))) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (field->table->const_table) + { + if (str) + { + if ((error_num = share->dbton_share[dbton_id]-> + append_column_name_with_alias(str, field->field_index, + alias, alias_length))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); + } + } + DBUG_RETURN(spider_db_open_item_ident( + (Item_ident *) item_field, spider, str, alias, alias_length, dbton_id)); +} + +int spider_db_open_item_ref( + Item_ref *item_ref, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num; + DBUG_ENTER("spider_db_open_item_ref"); + if (item_ref->ref) + { + if ( + (*(item_ref->ref))->type() != Item::CACHE_ITEM && + item_ref->ref_type() != Item_ref::VIEW_REF && + !item_ref->table_name && + item_ref->name && + item_ref->alias_name_used + ) { + if (str) + { + uint length = strlen(item_ref->name); + if (str->reserve(length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if ((error_num = spider_dbton[dbton_id].db_util-> + append_name(str, item_ref->name, length))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); + } + DBUG_RETURN(spider_db_print_item_type(*(item_ref->ref), spider, str, + alias, alias_length, dbton_id)); + } + DBUG_RETURN(spider_db_open_item_ident((Item_ident *) item_ref, spider, str, + alias, alias_length, dbton_id)); +} + +int spider_db_open_item_row( + Item_row *item_row, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num; + uint roop_count, cols = item_row->cols() - 1; + Item *item; + DBUG_ENTER("spider_db_open_item_row"); + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + for (roop_count = 0; roop_count < cols; roop_count++) + { + item = item_row->element_index(roop_count); + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + item = item_row->element_index(roop_count); + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_open_item_string( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + DBUG_ENTER("spider_db_open_item_string"); + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + String *tmp_str2; + tmp_str.init_calc_mem(126); + if ( + !(tmp_str2 = item->val_str(tmp_str.get_str())) || + str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + tmp_str2->length() * 2) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_str.mem_calc(); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if ( + append_escaped(str->get_str(), tmp_str2) || + str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->mem_calc(); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_open_item_int( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + DBUG_ENTER("spider_db_open_item_int"); + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(127); + if (str->append(*item->val_str(tmp_str.get_str()))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_str.mem_calc(); + } + DBUG_RETURN(0); +} + +int spider_db_open_item_cache( + Item_cache *item_cache, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + DBUG_ENTER("spider_db_open_item_cache"); + if (!item_cache->const_item()) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + switch (item_cache->result_type()) + { + case STRING_RESULT: + DBUG_RETURN(spider_db_open_item_string(item_cache, spider, str, + alias, alias_length, dbton_id)); + case ROW_RESULT: + { + int error_num; + Item_cache_row *item_cache_row = (Item_cache_row *) item_cache; + uint item_count = item_cache_row->cols() - 1, roop_count; + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + for (roop_count = 0; roop_count < item_count; ++roop_count) + { + if ((error_num = spider_db_open_item_cache( + (Item_cache *) item_cache_row->element_index(roop_count), + spider, str, alias, alias_length, dbton_id + ))) { + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ((error_num = spider_db_open_item_cache( + (Item_cache *) item_cache_row->element_index(roop_count), + spider, str, alias, alias_length, dbton_id + ))) { + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + } + DBUG_RETURN(0); + case REAL_RESULT: + case INT_RESULT: + case DECIMAL_RESULT: + default: + break; + } + DBUG_RETURN(spider_db_open_item_int(item_cache, spider, str, + alias, alias_length, dbton_id)); +} + +int spider_db_append_condition( + ha_spider *spider, + const char *alias, + uint alias_length, + bool test_flg +) { + int error_num; + DBUG_ENTER("spider_db_append_condition"); + if (!test_flg) + { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + { + if ((error_num = spider->append_condition_sql_part( + alias, alias_length, SPIDER_SQL_TYPE_SELECT_SQL, FALSE))) + DBUG_RETURN(error_num); + } + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + if ((error_num = spider->append_condition_sql_part( + alias, alias_length, SPIDER_SQL_TYPE_HANDLER, FALSE))) + DBUG_RETURN(error_num); + } + } else { + if (spider->cond_check) + DBUG_RETURN(spider->cond_check_error); + spider->cond_check = TRUE; + if ((spider->cond_check_error = spider->append_condition_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL, TRUE))) + DBUG_RETURN(spider->cond_check_error); + } + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_append_update_columns( + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +) { + int error_num; + List_iterator_fast fi(*spider->direct_update_fields), + vi(*spider->direct_update_values); + Item *field, *value; + DBUG_ENTER("spider_db_append_update_columns"); + while ((field = fi++)) + { + value = vi++; + if ((error_num = spider_db_print_item_type( + (Item *) field, spider, str, alias, alias_length, dbton_id))) + { + if ( + error_num == ER_SPIDER_COND_SKIP_NUM && + field->type() == Item::FIELD_ITEM && + ((Item_field *) field)->field + ) + continue; + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + } + if ((error_num = spider_db_print_item_type( + (Item *) value, spider, str, alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if (str) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} +#endif + +uint spider_db_check_ft_idx( + Item_func *item_func, + ha_spider *spider +) { + uint roop_count, roop_count2, part_num; + uint item_count = item_func->argument_count(); + Item **item_list = item_func->arguments(); + Item_field *item_field; + Field *field; + TABLE *table = spider->get_table(); + TABLE_SHARE *table_share = table->s; + KEY *key_info; + KEY_PART_INFO *key_part; + bool match1, match2; + DBUG_ENTER("spider_db_check_ft_idx"); + + for (roop_count = 0; roop_count < table_share->keys; roop_count++) + { + key_info = &table->key_info[roop_count]; + if ( + key_info->algorithm == HA_KEY_ALG_FULLTEXT && + item_count - 1 == key_info->key_parts + ) { + match1 = TRUE; + for (roop_count2 = 1; roop_count2 < item_count; roop_count2++) + { + item_field = (Item_field *) item_list[roop_count2]; + field = item_field->field; + if (!(field = spider->field_exchange(field))) + DBUG_RETURN(MAX_KEY); + match2 = FALSE; + for (key_part = key_info->key_part, part_num = 0; + part_num < key_info->key_parts; key_part++, part_num++) + { + if (key_part->field == field) + { + match2 = TRUE; + break; + } + } + if (!match2) + { + match1 = FALSE; + break; + } + } + if (match1) + DBUG_RETURN(roop_count); + } + } + DBUG_RETURN(MAX_KEY); +} + +int spider_db_udf_fetch_row( + SPIDER_TRX *trx, + Field *field, + SPIDER_DB_ROW *row +) { + DBUG_ENTER("spider_db_udf_fetch_row"); + DBUG_RETURN(row->store_to_field(field, trx->udf_access_charset)); + DBUG_RETURN(0); +} + +int spider_db_udf_fetch_table( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + TABLE *table, + SPIDER_DB_RESULT *result, + uint set_on, + uint set_off +) { + int error_num; + SPIDER_DB_ROW *row = NULL; + Field **field; + uint roop_count; + DBUG_ENTER("spider_db_udf_fetch_table"); + if (!(row = result->fetch_row())) + DBUG_RETURN(HA_ERR_END_OF_FILE); + +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->write_set); +#endif + for ( + roop_count = 0, + field = table->field; + roop_count < set_on; + roop_count++, + field++ + ) { + if ((error_num = + spider_db_udf_fetch_row(trx, *field, row))) + { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + DBUG_RETURN(error_num); + } + row->next(); + } + + for (; roop_count < set_off; roop_count++, field++) + (*field)->set_default(); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->write_set, tmp_map); +#endif + table->status = 0; + DBUG_RETURN(0); +} + +int spider_db_udf_direct_sql_connect( + const SPIDER_DIRECT_SQL *direct_sql, + SPIDER_CONN *conn +) { + int error_num, connect_retry_count; + THD* thd = current_thd; + longlong connect_retry_interval; + DBUG_ENTER("spider_db_udf_direct_sql_connect"); + + if (thd) + { + conn->connect_timeout = spider_param_connect_timeout(thd, + direct_sql->connect_timeout); + conn->net_read_timeout = spider_param_net_read_timeout(thd, + direct_sql->net_read_timeout); + conn->net_write_timeout = spider_param_net_write_timeout(thd, + direct_sql->net_write_timeout); + connect_retry_interval = spider_param_connect_retry_interval(thd); + connect_retry_count = spider_param_connect_retry_count(thd); + } else { + conn->connect_timeout = spider_param_connect_timeout(NULL, + direct_sql->connect_timeout); + conn->net_read_timeout = spider_param_net_read_timeout(NULL, + direct_sql->net_read_timeout); + conn->net_write_timeout = spider_param_net_write_timeout(NULL, + direct_sql->net_write_timeout); + connect_retry_interval = spider_param_connect_retry_interval(NULL); + connect_retry_count = spider_param_connect_retry_count(NULL); + } + DBUG_PRINT("info",("spider connect_timeout=%u", conn->connect_timeout)); + DBUG_PRINT("info",("spider net_read_timeout=%u", conn->net_read_timeout)); + DBUG_PRINT("info",("spider net_write_timeout=%u", conn->net_write_timeout)); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if ((error_num = spider_reset_conn_setted_parameter(conn, thd))) + DBUG_RETURN(error_num); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + + if (conn->dbton_id == SPIDER_DBTON_SIZE) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + my_printf_error( + ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR, + MYF(0), conn->tgt_wrapper); + DBUG_RETURN(ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + my_printf_error( + ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_STR, + MYF(0), conn->tgt_wrapper); + DBUG_RETURN(ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM); + } +#endif + } + +/* + if (!(conn->db_conn = spider_dbton[conn->dbton_id].create_db_conn(conn))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +*/ + + if ((error_num = conn->db_conn->connect( + direct_sql->tgt_host, + direct_sql->tgt_username, + direct_sql->tgt_password, + direct_sql->tgt_port, + direct_sql->tgt_socket, + direct_sql->server_name, + connect_retry_count, connect_retry_interval))) + { + DBUG_RETURN(error_num); + } + ++conn->connection_id; + DBUG_RETURN(0); +} + +int spider_db_udf_direct_sql_ping( + SPIDER_DIRECT_SQL *direct_sql +) { + int error_num; + SPIDER_CONN *conn = direct_sql->conn; + DBUG_ENTER("spider_db_udf_direct_sql_ping"); + if (conn->server_lost) + { + if ((error_num = spider_db_udf_direct_sql_connect(direct_sql, conn))) + DBUG_RETURN(error_num); + conn->server_lost = FALSE; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if ((error_num = conn->db_conn->ping())) + { + spider_db_disconnect(conn); + if ((error_num = spider_db_udf_direct_sql_connect(direct_sql, conn))) + { + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + DBUG_RETURN(error_num); + } + if((error_num = conn->db_conn->ping())) + { + spider_db_disconnect(conn); + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + DBUG_RETURN(error_num); + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + conn->ping_time = (time_t) time((time_t*) 0); + DBUG_RETURN(0); +} + +int spider_db_udf_direct_sql( + SPIDER_DIRECT_SQL *direct_sql +) { + int error_num = 0, status = 0, roop_count = 0, need_mon = 0; + uint udf_table_mutex_index, field_num, set_on, set_off; + long long roop_count2; + bool end_of_file; + SPIDER_TRX *trx = direct_sql->trx; + THD *thd = trx->thd, *c_thd = current_thd; + SPIDER_CONN *conn = direct_sql->conn; + SPIDER_DB_RESULT *result = NULL; + TABLE *table; + int bulk_insert_rows = (int) spider_param_udf_ds_bulk_insert_rows(thd, + direct_sql->bulk_insert_rows); + int table_loop_mode = spider_param_udf_ds_table_loop_mode(thd, + direct_sql->table_loop_mode); + double ping_interval_at_trx_start = + spider_param_ping_interval_at_trx_start(thd); + time_t tmp_time = (time_t) time((time_t*) 0); + bool need_trx_end, need_all_commit, insert_start = FALSE; +#if MYSQL_VERSION_ID < 50500 +#else + enum_sql_command sql_command_backup; +#endif + DBUG_ENTER("spider_db_udf_direct_sql"); +#if MYSQL_VERSION_ID < 50500 +#else + if (direct_sql->real_table_used) + { + if (spider_sys_open_tables(c_thd, &direct_sql->table_list_first, + &direct_sql->open_tables_backup)) + { + direct_sql->real_table_used = FALSE; + DBUG_RETURN(my_errno); + } + for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) + { + if (!spider_bit_is_set(direct_sql->real_table_bitmap, roop_count)) + continue; + direct_sql->tables[roop_count] = + direct_sql->table_list[roop_count].table; + } + direct_sql->open_tables_thd = c_thd; + roop_count = 0; + } +#endif + + if (c_thd != thd) + { + need_all_commit = TRUE; + need_trx_end = TRUE; + } else { + need_all_commit = FALSE; +#if MYSQL_VERSION_ID < 50500 +#else + if (direct_sql->real_table_used) + { + need_trx_end = TRUE; + } else { +#endif + if (c_thd->transaction.stmt.ha_list) + need_trx_end = FALSE; + else + need_trx_end = TRUE; +#if MYSQL_VERSION_ID < 50500 +#else + } +#endif + } + + if (!conn->disable_reconnect) + { + if ( + ( + conn->server_lost || + difftime(tmp_time, conn->ping_time) >= ping_interval_at_trx_start + ) && + (error_num = spider_db_udf_direct_sql_ping(direct_sql)) + ) + DBUG_RETURN(error_num); + } else if (conn->server_lost) + { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + +#if MYSQL_VERSION_ID < 50500 +#else + sql_command_backup = c_thd->lex->sql_command; + c_thd->lex->sql_command = SQLCOM_INSERT; +#endif + + conn->need_mon = &need_mon; + if ( + !(error_num = spider_db_udf_direct_sql_set_names(direct_sql, trx, conn)) && + !(error_num = spider_db_udf_direct_sql_select_db(direct_sql, conn)) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode != 0) + { + st_spider_db_request_key request_key; + request_key.spider_thread_id = direct_sql->trx->spider_thread_id; + request_key.query_id = direct_sql->trx->thd->query_id; + request_key.handler = direct_sql; + request_key.request_id = 1; + request_key.next = NULL; + if ((error_num = conn->db_conn->append_sql( + direct_sql->sql, direct_sql->sql_length, &request_key))) + { +#if MYSQL_VERSION_ID < 50500 +#else + c_thd->lex->sql_command = sql_command_backup; +#endif + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + } +#endif + spider_conn_set_timeout_from_direct_sql(conn, thd, direct_sql); + if (spider_db_query( + conn, + direct_sql->sql, + direct_sql->sql_length, + -1, + &need_mon) + ) { + error_num = spider_db_errorno(conn); + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + } else { + DBUG_PRINT("info",("spider conn=%p", conn)); + if (!direct_sql->table_count) + roop_count = -1; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + do { + if (roop_count == direct_sql->table_count) + { + if (table_loop_mode == 1) + roop_count--; + else if (table_loop_mode == 2) + roop_count = 0; + else + roop_count = -1; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = direct_sql->trx->spider_thread_id; + request_key.query_id = direct_sql->trx->thd->query_id; + request_key.handler = direct_sql; + request_key.request_id = 1; + request_key.next = NULL; + if ((result = conn->db_conn->use_result(&request_key, &error_num))) + { + end_of_file = FALSE; + if (roop_count >= 0) + { + while (!error_num && !end_of_file) + { + udf_table_mutex_index = spider_udf_calc_hash( + direct_sql->db_names[roop_count], + spider_param_udf_table_lock_mutex_count()); + udf_table_mutex_index += spider_udf_calc_hash( + direct_sql->table_names[roop_count], + spider_param_udf_table_lock_mutex_count()); + udf_table_mutex_index %= + spider_param_udf_table_lock_mutex_count(); + pthread_mutex_lock( + &trx->udf_table_mutexes[udf_table_mutex_index]); + table = direct_sql->tables[roop_count]; + table->in_use = c_thd; + memset((uchar *) table->null_flags, ~(uchar) 0, + sizeof(uchar) * table->s->null_bytes); + insert_start = TRUE; + + field_num = result->num_fields(); + if (field_num > table->s->fields) + { + set_on = table->s->fields; + set_off = table->s->fields; + } else { + set_on = field_num; + set_off = table->s->fields; + } + for (roop_count2 = 0; roop_count2 < set_on; roop_count2++) + bitmap_set_bit(table->write_set, (uint) roop_count2); + for (; roop_count2 < set_off; roop_count2++) + bitmap_clear_bit(table->write_set, (uint) roop_count2); + +#if MYSQL_VERSION_ID < 50500 + if (table->file->has_transactions()) +#endif + { + THR_LOCK_DATA *to[2]; + table->file->store_lock(table->in_use, to, + TL_WRITE_CONCURRENT_INSERT); + if ((error_num = table->file->ha_external_lock(table->in_use, + F_WRLCK))) + { + table->file->print_error(error_num, MYF(0)); + break; + } +#if MYSQL_VERSION_ID < 50500 +#else + if (table->pos_in_table_list) + { + TABLE_LIST *next_tables = + table->pos_in_table_list->next_global; + while (next_tables && next_tables->parent_l) + { + DBUG_PRINT("info",("spider call child lock")); + TABLE *child_table = next_tables->table; + child_table->file->store_lock(child_table->in_use, to, + TL_WRITE_CONCURRENT_INSERT); + if ((error_num = child_table->file->ha_external_lock( + child_table->in_use, F_WRLCK))) + { + table->file->print_error(error_num, MYF(0)); + break; + } + next_tables = next_tables->next_global; + } + } +#endif + } + + if (direct_sql->iop) + { + if (direct_sql->iop[roop_count] == 1) + table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); + else if (direct_sql->iop[roop_count] == 2) + table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE); + } + table->file->ha_start_bulk_insert( + (ha_rows) bulk_insert_rows); + + for (roop_count2 = 0; + roop_count2 < bulk_insert_rows; + roop_count2++) + { + if ((error_num = spider_db_udf_fetch_table( + trx, conn, table, result, set_on, set_off))) + { + if (error_num == HA_ERR_END_OF_FILE) + { + end_of_file = TRUE; + error_num = 0; + } + break; + } + if (direct_sql->iop && direct_sql->iop[roop_count] == 2) + { + if ((error_num = spider_sys_replace(table, + &direct_sql->modified_non_trans_table))) + { + table->file->print_error(error_num, MYF(0)); + break; + } + } else if ((error_num = + table->file->ha_write_row(table->record[0]))) + { + /* insert */ + if ( + !direct_sql->iop || direct_sql->iop[roop_count] != 1 || + table->file->is_fatal_error(error_num, HA_CHECK_DUP) + ) { + DBUG_PRINT("info",("spider error_num=%d", error_num)); + table->file->print_error(error_num, MYF(0)); + break; + } else + error_num = 0; + } + } + + if (error_num) + table->file->ha_end_bulk_insert(); + else + error_num = table->file->ha_end_bulk_insert(); + if (direct_sql->iop) + { + if (direct_sql->iop[roop_count] == 1) + table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); + else if (direct_sql->iop[roop_count] == 2) + table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); + } +#if MYSQL_VERSION_ID < 50500 + if (table->file->has_transactions()) +#endif + { + table->file->ha_external_lock(table->in_use, F_UNLCK); +#if MYSQL_VERSION_ID < 50500 +#else + if (table->pos_in_table_list) + { + TABLE_LIST *next_tables = + table->pos_in_table_list->next_global; + while (next_tables && next_tables->parent_l) + { + DBUG_PRINT("info",("spider call child lock")); + TABLE *child_table = next_tables->table; + child_table->file->ha_external_lock(child_table->in_use, + F_UNLCK); + next_tables = next_tables->next_global; + } + } +#endif + } + table->file->ha_reset(); + table->in_use = thd; + pthread_mutex_unlock( + &trx->udf_table_mutexes[udf_table_mutex_index]); + } + if (error_num) + roop_count = -1; + } + result->free_result(); + delete result; + } else { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } + if (error_num) + { + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + else if (error_num == HA_ERR_FOUND_DUPP_KEY) + { + my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), + conn->db_conn->get_errno(), conn->db_conn->get_error()); + } + break; + } + } + if ((status = conn->db_conn->next_result()) > 0) + { + error_num = status; + break; + } + if (roop_count >= 0) + roop_count++; + } while (status == 0); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + if (need_trx_end && insert_start) + { + if (error_num) + { + (void) ha_rollback_trans(c_thd, FALSE); + if (need_all_commit) + (void) ha_rollback_trans(c_thd, TRUE); + } else { + if ((error_num = ha_commit_trans(c_thd, FALSE))) + my_error(error_num, MYF(0)); + if (need_all_commit) + { + if ((error_num = ha_commit_trans(c_thd, TRUE))) + my_error(error_num, MYF(0)); + } + } + } +#if MYSQL_VERSION_ID < 50500 +#else + c_thd->lex->sql_command = sql_command_backup; +#endif + DBUG_RETURN(error_num); +} + +int spider_db_udf_direct_sql_select_db( + SPIDER_DIRECT_SQL *direct_sql, + SPIDER_CONN *conn +) { + int error_num, need_mon = 0; + bool tmp_mta_conn_mutex_lock_already; + SPIDER_DB_CONN *db_conn = conn->db_conn; + DBUG_ENTER("spider_db_udf_direct_sql_select_db"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ( + !conn->default_database.length() || + conn->default_database.length() != + direct_sql->tgt_default_db_name_length || + memcmp(direct_sql->tgt_default_db_name, conn->default_database.ptr(), + direct_sql->tgt_default_db_name_length) + ) { + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + if ( + ( + spider_db_before_query(conn, &need_mon) || + db_conn->select_db(direct_sql->tgt_default_db_name) + ) && + (error_num = spider_db_errorno(conn)) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + DBUG_RETURN(error_num); + } + conn->default_database.length(0); + if (conn->default_database.reserve( + direct_sql->tgt_default_db_name_length + 1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + conn->default_database.q_append(direct_sql->tgt_default_db_name, + direct_sql->tgt_default_db_name_length + 1); + conn->default_database.length(direct_sql->tgt_default_db_name_length); + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + } + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + DBUG_RETURN(0); +} + +int spider_db_udf_direct_sql_set_names( + SPIDER_DIRECT_SQL *direct_sql, + SPIDER_TRX *trx, + SPIDER_CONN *conn +) { + int error_num, need_mon = 0; + bool tmp_mta_conn_mutex_lock_already; + DBUG_ENTER("spider_db_udf_direct_sql_set_names"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ( + !conn->access_charset || + trx->udf_access_charset->cset != conn->access_charset->cset + ) { + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + if ( + ( + spider_db_before_query(conn, &need_mon) || + conn->db_conn->set_character_set(trx->udf_access_charset->csname) + ) && + (error_num = spider_db_errorno(conn)) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + } + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->access_charset = trx->udf_access_charset; + } + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + DBUG_RETURN(0); +} + +int spider_db_udf_check_and_set_set_names( + SPIDER_TRX *trx +) { + int error_num; + DBUG_ENTER("spider_db_udf_check_and_set_set_names"); + if ( + !trx->udf_access_charset || + trx->udf_access_charset->cset != + trx->thd->variables.character_set_client->cset) + { + trx->udf_access_charset = trx->thd->variables.character_set_client; + if ((error_num = spider_db_udf_append_set_names(trx))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_udf_append_set_names( + SPIDER_TRX *trx +) { + DBUG_ENTER("spider_db_udf_append_set_names"); + DBUG_RETURN(0); +} + +void spider_db_udf_free_set_names( + SPIDER_TRX *trx +) { + DBUG_ENTER("spider_db_udf_free_set_names"); + DBUG_VOID_RETURN; +} + +int spider_db_udf_ping_table( + SPIDER_TABLE_MON_LIST *table_mon_list, + SPIDER_SHARE *share, + SPIDER_TRX *trx, + SPIDER_CONN *conn, + char *where_clause, + uint where_clause_length, + bool ping_only, + bool use_where, + longlong limit +) { + int error_num, need_mon = 0; + uint tmp_conn_link_idx = 0; + ha_spider spider; + DBUG_ENTER("spider_db_udf_ping_table"); + if (!pthread_mutex_trylock(&table_mon_list->monitor_mutex)) + { + spider.share = share; + spider.trx = trx; + spider.need_mons = &need_mon; + spider.conn_link_idx = &tmp_conn_link_idx; + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_ping(&spider, conn, 0))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + table_mon_list->last_mon_result = error_num; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + share->server_names[0]); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (!ping_only) + { + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(trx->thd, share->init_sql_alloc_size); +#ifdef _MSC_VER + spider_string sql_str(init_sql_alloc_size); + sql_str.set_charset(system_charset_info); + spider_string where_str(init_sql_alloc_size); + where_str.set_charset(system_charset_info); +#else + char sql_buf[init_sql_alloc_size], where_buf[init_sql_alloc_size]; + spider_string sql_str(sql_buf, sizeof(sql_buf), + system_charset_info); + spider_string where_str(where_buf, sizeof(where_buf), + system_charset_info); +#endif + sql_str.init_calc_mem(128); + where_str.init_calc_mem(129); + sql_str.length(0); + where_str.length(0); + if ( + use_where && + where_str.append(where_clause, where_clause_length, + trx->thd->variables.character_set_client) + ) { + table_mon_list->last_mon_result = HA_ERR_OUT_OF_MEM; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + share->access_charset = system_charset_info; + if ((error_num = spider_db_udf_ping_table_append_select(&sql_str, + share, trx, &where_str, use_where, limit, conn->dbton_id))) + { + table_mon_list->last_mon_result = error_num; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + my_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(&spider, conn, 0))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + table_mon_list->last_mon_result = error_num; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, 0, trx->thd, share); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + &need_mon) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + table_mon_list->last_mon_result = error_num; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + spider_db_discard_result(&spider, 0, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + table_mon_list->last_mon_result = 0; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + } else { + pthread_mutex_lock(&table_mon_list->monitor_mutex); + error_num = table_mon_list->last_mon_result; + pthread_mutex_unlock(&table_mon_list->monitor_mutex); + DBUG_RETURN(error_num); + } + + DBUG_RETURN(0); +} + +int spider_db_udf_ping_table_append_mon_next( + spider_string *str, + char *child_table_name, + uint child_table_name_length, + int link_id, + char *where_clause, + uint where_clause_length, + longlong first_sid, + int full_mon_count, + int current_mon_count, + int success_count, + int fault_count, + int flags, + longlong limit +) { + char limit_str[SPIDER_SQL_INT_LEN], sid_str[SPIDER_SQL_INT_LEN]; + int limit_str_length, sid_str_length; + spider_string child_table_name_str(child_table_name, + child_table_name_length + 1, str->charset()); + spider_string where_clause_str(where_clause ? where_clause : "", + where_clause_length + 1, str->charset()); + DBUG_ENTER("spider_db_udf_ping_table_append_mon_next"); + child_table_name_str.init_calc_mem(130); + where_clause_str.init_calc_mem(131); + child_table_name_str.length(child_table_name_length); + where_clause_str.length(where_clause_length); + limit_str_length = my_sprintf(limit_str, (limit_str, "%lld", limit)); + sid_str_length = my_sprintf(sid_str, (sid_str, "%lld", first_sid)); + if (str->reserve( + SPIDER_SQL_SELECT_LEN + + SPIDER_SQL_PING_TABLE_LEN + + (child_table_name_length * 2) + + (SPIDER_SQL_INT_LEN * 6) + + sid_str_length + + limit_str_length + + (where_clause_length * 2) + + (SPIDER_SQL_VALUE_QUOTE_LEN * 4) + + (SPIDER_SQL_COMMA_LEN * 9) + + SPIDER_SQL_CLOSE_PAREN_LEN + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + str->q_append(SPIDER_SQL_PING_TABLE_STR, SPIDER_SQL_PING_TABLE_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + append_escaped(str->get_str(), child_table_name_str.get_str()); + str->mem_calc(); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(link_id); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(flags); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(limit_str, limit_str_length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + append_escaped(str->get_str(), where_clause_str.get_str()); + str->mem_calc(); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(sid_str, sid_str_length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(full_mon_count); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(current_mon_count); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(success_count); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->qs_append(fault_count); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_db_udf_ping_table_append_select( + spider_string *str, + SPIDER_SHARE *share, + SPIDER_TRX *trx, + spider_string *where_str, + bool use_where, + longlong limit, + uint dbton_id +) { + int error_num; + char limit_str[SPIDER_SQL_INT_LEN]; + int limit_str_length; + DBUG_ENTER("spider_db_udf_ping_table_append_select"); + if (str->reserve(SPIDER_SQL_SELECT_LEN + SPIDER_SQL_ONE_LEN + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + if ((error_num = spider_db_append_name_with_quote_str(str, + share->tgt_dbs[0], dbton_id))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_DOT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + if ((error_num = spider_db_append_name_with_quote_str(str, + share->tgt_table_names[0], share->sql_dbton_ids[0]))) + DBUG_RETURN(error_num); + + limit_str_length = my_sprintf(limit_str, (limit_str, "%lld", limit)); + if (str->reserve( + (use_where ? (where_str->length() * 2) : 0) + + SPIDER_SQL_LIMIT_LEN + limit_str_length + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (use_where) + append_escaped(str->get_str(), where_str->get_str()); + str->mem_calc(); + str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN); + str->q_append(limit_str, limit_str_length); + DBUG_RETURN(0); +} + +int spider_db_udf_ping_table_mon_next( + THD *thd, + SPIDER_TABLE_MON *table_mon, + SPIDER_CONN *conn, + SPIDER_MON_TABLE_RESULT *mon_table_result, + char *child_table_name, + uint child_table_name_length, + int link_id, + char *where_clause, + uint where_clause_length, + longlong first_sid, + int full_mon_count, + int current_mon_count, + int success_count, + int fault_count, + int flags, + longlong limit +) { + int error_num, need_mon = 0; + uint tmp_conn_link_idx = 0; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = table_mon->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); +#ifdef _MSC_VER + spider_string sql_str(init_sql_alloc_size); + sql_str.set_charset(thd->variables.character_set_client); +#else + char sql_buf[init_sql_alloc_size]; + spider_string sql_str(sql_buf, sizeof(sql_buf), + thd->variables.character_set_client); +#endif + ha_spider spider; + SPIDER_TRX trx; + DBUG_ENTER("spider_db_udf_ping_table_mon_next"); + sql_str.init_calc_mem(132); + sql_str.length(0); + trx.thd = thd; + spider.share = share; + spider.trx = &trx; + spider.need_mons = &need_mon; + spider.conn_link_idx = &tmp_conn_link_idx; + + share->access_charset = thd->variables.character_set_client; + if ((error_num = spider_db_udf_ping_table_append_mon_next(&sql_str, + child_table_name, child_table_name_length, link_id, where_clause, + where_clause_length, first_sid, full_mon_count, current_mon_count, + success_count, fault_count, flags, limit))) + { + my_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_ping(&spider, conn, 0))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + share->server_names[0]); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + if ((error_num = spider_db_set_names(&spider, conn, 0))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, 0, thd, share); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + &need_mon) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = trx.spider_thread_id; + request_key.query_id = trx.thd->query_id; + request_key.handler = table_mon; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_mon_status(mon_table_result->result_status); + res->free_result(); + delete res; + DBUG_RETURN(error_num); +} + +int spider_db_udf_copy_key_row( + spider_string *str, + spider_string *source_str, + Field *field, + ulong *row_pos, + ulong *length, + const char *joint_str, + const int joint_length, + uint dbton_id +) { + int error_num; + DBUG_ENTER("spider_db_udf_copy_key_row"); + if ((error_num = spider_db_append_name_with_quote_str(str, + (char *) field->field_name, dbton_id))) + DBUG_RETURN(error_num); + if (str->reserve(joint_length + *length + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(joint_str, joint_length); + str->q_append(source_str->ptr() + *row_pos, *length); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + DBUG_RETURN(0); +} + +int spider_db_udf_copy_tables( + SPIDER_COPY_TABLES *copy_tables, + ha_spider *spider, + TABLE *table, + longlong bulk_insert_rows +) { + int error_num = 0, roop_count; + bool end_of_file = FALSE; + ulong *last_lengths, *last_row_pos = NULL; + ha_spider *tmp_spider; + SPIDER_CONN *tmp_conn; + int all_link_cnt = + copy_tables->link_idx_count[0] + copy_tables->link_idx_count[1]; + SPIDER_COPY_TABLE_CONN *src_tbl_conn = copy_tables->table_conn[0]; + SPIDER_COPY_TABLE_CONN *dst_tbl_conn; + spider_db_copy_table *select_ct = src_tbl_conn->copy_table; + spider_db_copy_table *insert_ct = NULL; + KEY *key_info = &table->key_info[table->s->primary_key]; + int bulk_insert_interval; + DBUG_ENTER("spider_db_udf_copy_tables"); + if (!(last_row_pos = (ulong *) + spider_bulk_malloc(spider_current_trx, 30, MYF(MY_WME), + &last_row_pos, sizeof(ulong) * table->s->fields, + &last_lengths, sizeof(ulong) * table->s->fields, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + while (!end_of_file) + { + if (copy_tables->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + error_num = ER_QUERY_INTERRUPTED; + goto error_killed; + } + if (copy_tables->use_transaction) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (!tmp_conn->trx_start) + { + if (spider_db_ping(tmp_spider, tmp_conn, 0)) + { + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + tmp_spider->share->server_names[0]); + error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; + goto error_db_ping; + } + if ( + (error_num = spider_db_set_names(tmp_spider, tmp_conn, 0)) || + (error_num = spider_db_start_transaction(tmp_conn, + tmp_spider->need_mons)) + ) + goto error_start_transaction; + } + } + } else { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + spider_db_handler *tmp_dbton_hdl = + tmp_spider->dbton_handler[tmp_conn->dbton_id]; + if ((error_num = tmp_dbton_hdl->insert_lock_tables_list(tmp_conn, 0))) + goto error_lock_table_hash; + tmp_conn->table_lock = 2; + } + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (spider_db_ping(tmp_spider, tmp_conn, 0)) + { + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + tmp_spider->share->server_names[0]); + error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; + goto error_db_ping; + } + if ( + tmp_conn->db_conn->have_lock_table_list() && + ( + (error_num = spider_db_set_names(tmp_spider, tmp_conn, 0)) || + (error_num = spider_db_lock_tables(tmp_spider, 0)) + ) + ) { + tmp_conn->table_lock = 0; + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_lock_tables; + } + tmp_conn->table_lock = 1; + } + } + + tmp_conn = src_tbl_conn->conn; + spider_conn_set_timeout_from_share(tmp_conn, 0, + copy_tables->trx->thd, src_tbl_conn->share); + if (select_ct->exec_query( + tmp_conn, + -1, + &src_tbl_conn->need_mon) + ) { + error_num = spider_db_errorno(tmp_conn); + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + goto error_db_query; + } else { + SPIDER_DB_RESULT *result; + st_spider_db_request_key request_key; + request_key.spider_thread_id = copy_tables->trx->spider_thread_id; + request_key.query_id = copy_tables->trx->thd->query_id; + request_key.handler = copy_tables; + request_key.request_id = 1; + request_key.next = NULL; + if ((result = tmp_conn->db_conn->use_result(&request_key, &error_num))) + { + SPIDER_DB_ROW *row; + roop_count = 0; + while ((row = result->fetch_row())) + { + dst_tbl_conn = copy_tables->table_conn[1]; + insert_ct = dst_tbl_conn->copy_table; + if ((error_num = insert_ct->copy_rows(table, row, + &last_row_pos, &last_lengths))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + goto error_db_query; + } + for (dst_tbl_conn = dst_tbl_conn->next; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + row->first(); + insert_ct = dst_tbl_conn->copy_table; + if ((error_num = insert_ct->copy_rows(table, row))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + goto error_db_query; + } + } + ++roop_count; + } + error_num = result->get_errno(); + if (error_num == HA_ERR_END_OF_FILE) + { + if (roop_count < copy_tables->bulk_insert_rows) + { + end_of_file = TRUE; + if (roop_count) + error_num = 0; + } else { + /* add next where clause */ + select_ct->set_sql_to_pos(); + error_num = select_ct->append_copy_where(insert_ct, key_info, + last_row_pos, last_lengths); + if (error_num) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + goto error_db_query; + } + bulk_insert_rows = spider_param_udf_ct_bulk_insert_rows( + copy_tables->bulk_insert_rows); + if ( + select_ct->append_key_order_str(key_info, 0, FALSE) || + select_ct->append_limit(0, bulk_insert_rows) || + ( + copy_tables->use_transaction && + select_ct->append_select_lock_str(SPIDER_LOCK_MODE_SHARED) + ) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + error_num = ER_OUT_OF_RESOURCES; + goto error_db_query; + } + error_num = 0; + } + } else { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + goto error_db_query; + } + result->free_result(); + delete result; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + insert_ct = dst_tbl_conn->copy_table; + if ((error_num = insert_ct->append_insert_terminator())) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_db_query; + } + } + } else { + if (!error_num) + { + error_num = spider_db_errorno(tmp_conn); + } + if (error_num) + { + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + goto error_db_query; + } + error_num = HA_ERR_END_OF_FILE; + end_of_file = TRUE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + } + } + + if (!error_num) + { +/* + dst_tbl_conn = copy_tables->table_conn[1]; + spider_db_copy_table *source_ct = dst_tbl_conn->copy_table; + for (dst_tbl_conn = dst_tbl_conn->next; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + insert_ct = dst_tbl_conn->copy_table; + if (insert_ct->copy_insert_values(source_ct)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + error_num = ER_OUT_OF_RESOURCES; + goto error_db_query; + } + } +*/ +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (copy_tables->bg_mode) + { + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + if (spider_udf_bg_copy_exec_sql(dst_tbl_conn)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + error_num = ER_OUT_OF_RESOURCES; + goto error_db_query; + } + } + } else { +#endif + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + tmp_conn = dst_tbl_conn->conn; + insert_ct = dst_tbl_conn->copy_table; + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &dst_tbl_conn->need_mon; + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(tmp_conn, 0, + copy_tables->trx->thd, dst_tbl_conn->share); + if (insert_ct->exec_query( + tmp_conn, + -1, + &dst_tbl_conn->need_mon) + ) { + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(tmp_conn); + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + goto error_db_query; + } else { + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); + } + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (copy_tables->bg_mode) + { + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + tmp_conn = dst_tbl_conn->conn; + if (tmp_conn->bg_exec_sql) + { + /* wait */ + pthread_mutex_lock(&tmp_conn->bg_conn_mutex); + pthread_mutex_unlock(&tmp_conn->bg_conn_mutex); + } + + if (dst_tbl_conn->bg_error_num) + { + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + goto error_db_query; + } + } + } +#endif + } + + if (copy_tables->use_transaction) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (tmp_conn->trx_start) + { + if ((error_num = spider_db_commit(tmp_conn))) + goto error_commit; + } + } + } else { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (tmp_conn->table_lock == 1) + { + tmp_conn->table_lock = 0; + if ((error_num = spider_db_unlock_tables(tmp_spider, 0))) + goto error_unlock_tables; + } + } + } + if (!end_of_file) + { + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + insert_ct = dst_tbl_conn->copy_table; + insert_ct->set_sql_to_pos(); + } + DBUG_PRINT("info",("spider sleep")); + bulk_insert_interval = spider_param_udf_ct_bulk_insert_interval( + copy_tables->bulk_insert_interval); + my_sleep(bulk_insert_interval); + } + } + spider_free(spider_current_trx, last_row_pos, MYF(0)); + DBUG_RETURN(0); + +error_db_query: +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (copy_tables->bg_mode) + { + for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; + dst_tbl_conn = dst_tbl_conn->next) + { + tmp_conn = dst_tbl_conn->conn; + if (tmp_conn->bg_exec_sql) + { + /* wait */ + pthread_mutex_lock(&tmp_conn->bg_conn_mutex); + pthread_mutex_unlock(&tmp_conn->bg_conn_mutex); + } + } + } +#endif +error_unlock_tables: +error_commit: +error_lock_tables: +error_lock_table_hash: +error_start_transaction: +error_db_ping: +error_killed: + if (copy_tables->use_transaction) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (tmp_conn->trx_start) + spider_db_rollback(tmp_conn); + } + } else { + if (copy_tables->trx->locked_connections) + { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + if (tmp_conn->table_lock == 1) + { + tmp_conn->table_lock = 0; + spider_db_unlock_tables(tmp_spider, 0); + } + } + } + } +error: + if (last_row_pos) + { + spider_free(spider_current_trx, last_row_pos, MYF(0)); + } + DBUG_RETURN(error_num); +} + +int spider_db_open_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + bool tmp_mta_conn_mutex_lock_already; + bool tmp_mta_conn_mutex_unlock_later; + SPIDER_SHARE *share = spider->share; + uint *handler_id_ptr = +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + conn->conn_kind == SPIDER_CONN_KIND_MYSQL ? +#endif + &spider->m_handler_id[link_idx] +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + : conn->conn_kind == SPIDER_CONN_KIND_HS_READ ? + &spider->r_handler_id[link_idx] : + &spider->w_handler_id[link_idx] +#endif + ; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_db_open_handler"); + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = TRUE; + if (!spider->handler_opened(link_idx, conn->conn_kind)) + *handler_id_ptr = conn->opened_handlers; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + if (!spider->handler_opened(link_idx, conn->conn_kind)) + my_sprintf(spider->m_handler_cid[link_idx], + (spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_FORMAT, + *handler_id_ptr)); + + if ((error_num = dbton_hdl->append_open_handler_part( + SPIDER_SQL_TYPE_HANDLER, *handler_id_ptr, conn, link_idx))) + { + goto error; + } + + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_HANDLER, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + goto error; + } + dbton_hdl->reset_sql(SPIDER_SQL_TYPE_HANDLER); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + uint reconnect = 0; + if (conn->hs_pre_age != conn->hs_age && conn->server_lost) + { + spider_conn_queue_connect(share, conn, link_idx); + reconnect |= 1; + } + if ((error_num = spider_db_conn_queue_action(conn))) + { + goto error; + } + if (conn->hs_pre_age != conn->hs_age) + { + if (conn->db_conn->ping()) + { + my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), + conn->db_conn->get_errno(), conn->db_conn->get_error()); + if (!conn->mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + spider->need_mons[link_idx] = ER_SPIDER_HS_NUM; + error_num = ER_SPIDER_HS_NUM; + goto error; + } + conn->opened_handlers = 0; + conn->db_conn->reset_opened_handler(); + conn->hs_age = conn->hs_pre_age; + reconnect |= 2; + } + if (conn->conn_kind == SPIDER_CONN_KIND_HS_READ) + { + if (spider->hs_r_conn_ages[link_idx] != conn->hs_age) + { + spider->clear_handler_opened(link_idx, SPIDER_CONN_KIND_HS_READ); + *handler_id_ptr = conn->opened_handlers; + } + } else { + if (spider->hs_w_conn_ages[link_idx] != conn->hs_age) + { + spider->clear_handler_opened(link_idx, SPIDER_CONN_KIND_HS_WRITE); + *handler_id_ptr = conn->opened_handlers; + } + } + +#ifdef HA_CAN_BULK_ACCESS + if (!spider->is_bulk_access_clone) + { +#endif + conn->db_conn->reset_request_queue(); +#ifdef HA_CAN_BULK_ACCESS + } else if (!spider->bulk_access_executing) + { + if (conn->conn_kind == SPIDER_CONN_KIND_HS_READ) + { + spider_set_bit(spider->result_list.hs_r_bulk_open_index, link_idx); + } else { + spider_set_bit(spider->result_list.hs_w_bulk_open_index, link_idx); + } + } +#endif + if ((error_num = dbton_hdl->append_open_handler_part( + SPIDER_SQL_TYPE_OTHER_HS, *handler_id_ptr, conn, link_idx))) + { + goto error; + } +#ifdef HA_CAN_BULK_ACCESS + if (spider->is_bulk_access_clone && !spider->bulk_access_executing) + { + spider->connection_ids[link_idx] = conn->connection_id; + spider_trx_add_bulk_access_conn(spider->trx, conn); + } else { +#endif + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_SELECT_HS, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + goto error; + } + + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if (!(result = conn->db_conn->use_result(&request_key, &error_num))) + { + if (!error_num) + { + spider_db_errorno(conn); + error_num = ER_SPIDER_HS_NUM; + } + goto error; + } else { + conn->ping_time = (time_t) time((time_t*) 0); + } + result->free_result(); + delete result; +#ifdef HA_CAN_BULK_ACCESS + } +#endif + if (conn->conn_kind == SPIDER_CONN_KIND_HS_READ) + { + spider->r_handler_index[link_idx] = spider->active_index; + spider->hs_r_conn_ages[link_idx] = conn->hs_age; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->sql_command != SQLCOM_HS_INSERT && + spider->hs_pushed_ret_fields_num < MAX_FIELDS + ) { + spider->hs_r_ret_fields_num[link_idx] = + spider->hs_pushed_ret_fields_num; + memcpy(spider->hs_r_ret_fields[link_idx], spider->hs_pushed_ret_fields, + sizeof(uint32) * spider->hs_pushed_ret_fields_num); + } else { + spider->hs_r_ret_fields_num[link_idx] = MAX_FIELDS; + } +#endif + } else { + spider->w_handler_index[link_idx] = spider->active_index; + spider->hs_w_conn_ages[link_idx] = conn->hs_age; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->sql_command != SQLCOM_HS_INSERT && + spider->hs_pushed_ret_fields_num < MAX_FIELDS + ) { + spider->hs_w_ret_fields_num[link_idx] = + spider->hs_pushed_ret_fields_num; + memcpy(spider->hs_w_ret_fields[link_idx], spider->hs_pushed_ret_fields, + sizeof(uint32) * spider->hs_pushed_ret_fields_num); + } else { + spider->hs_w_ret_fields_num[link_idx] = MAX_FIELDS; + } +#endif + } + } +#endif + if (!spider->handler_opened(link_idx, conn->conn_kind)) + { + if ((error_num = dbton_hdl->insert_opened_handler(conn, link_idx))) + goto error; + conn->opened_handlers++; + } + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + if (!tmp_mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); + +error: + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + if (!tmp_mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); +} + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_open_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num = 0; + bool opening_index = FALSE; + DBUG_ENTER("spider_db_bulk_open_handler"); + DBUG_PRINT("info",("spider spider=%p", spider)); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + DBUG_ASSERT(conn->conn_kind != SPIDER_CONN_KIND_MYSQL); + if (conn->conn_kind == SPIDER_CONN_KIND_HS_READ) + { + if (spider_bit_is_set(spider->result_list.hs_r_bulk_open_index, link_idx)) + { + DBUG_PRINT("info",("spider SPIDER_CONN_KIND_HS_READ")); + spider_clear_bit(spider->result_list.hs_r_bulk_open_index, link_idx); + opening_index = TRUE; + } + } else { + if (spider_bit_is_set(spider->result_list.hs_w_bulk_open_index, link_idx)) + { + DBUG_PRINT("info",("spider SPIDER_CONN_KIND_HS_WRITE")); + spider_clear_bit(spider->result_list.hs_w_bulk_open_index, link_idx); + opening_index = TRUE; + } + } + if (opening_index) + { + DBUG_PRINT("info",("spider conn->connection_id=%llu", + conn->connection_id)); + DBUG_PRINT("info",("spider spider->connection_ids[%d]=%llu", + link_idx, spider->connection_ids[link_idx])); + if (conn->connection_id != spider->connection_ids[link_idx]) + { + my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, + ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + + bool tmp_mta_conn_mutex_unlock_later; + tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = TRUE; + SPIDER_DB_RESULT *result; + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + if (!(result = conn->db_conn->use_result(&request_key, &error_num))) + { + if (!error_num) + { + spider_db_errorno(conn); + error_num = ER_SPIDER_HS_NUM; + } + } else { + result->free_result(); + delete result; + } + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + } +#endif + DBUG_RETURN(error_num); +} +#endif + +int spider_db_close_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + uint tgt_conn_kind +) { + int error_num; + bool tmp_mta_conn_mutex_lock_already; + bool tmp_mta_conn_mutex_unlock_later; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_db_close_handler"); + DBUG_PRINT("info",("spider conn=%p", conn)); + if (spider->handler_opened(link_idx, tgt_conn_kind)) + { + if (!conn->mta_conn_mutex_lock_already) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + } + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + conn->mta_conn_mutex_lock_already = TRUE; + tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = TRUE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) + { +#endif + dbton_hdl->reset_sql(SPIDER_SQL_TYPE_HANDLER); + if ((error_num = dbton_hdl->append_close_handler_part( + SPIDER_SQL_TYPE_HANDLER, link_idx))) + DBUG_RETURN(error_num); + + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_HANDLER, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + goto error; + } + dbton_hdl->reset_sql(SPIDER_SQL_TYPE_HANDLER); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { +/* + conn->hs_conn->close(); + conn->server_lost = TRUE; +*/ + } +#endif + if ((error_num = dbton_hdl->delete_opened_handler(conn, link_idx))) + goto error; + conn->opened_handlers--; + DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + if (!tmp_mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + DBUG_RETURN(0); + +error: + conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + if (!tmp_mta_conn_mutex_unlock_later) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +void spider_db_hs_request_buf_reset( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_db_hs_request_buf_reset"); + if (conn->bulk_access_requests) + { + if (conn->db_conn->is_connected()) + { + conn->db_conn->reset_request_queue(); + } + conn->bulk_access_requests = 0; + } + DBUG_VOID_RETURN; +} +#endif diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h new file mode 100644 index 00000000000..d819255394d --- /dev/null +++ b/storage/spider/spd_db_conn.h @@ -0,0 +1,1022 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define SPIDER_DB_WRAPPER_STR "mysql" +#define SPIDER_DB_WRAPPER_LEN (sizeof(SPIDER_DB_WRAPPER_STR) - 1) +#define SPIDER_DB_PK_NAME_STR "PRIMARY" +#define SPIDER_DB_PK_NAME_LEN (sizeof(SPIDER_DB_PK_NAME_STR) - 1) +#define SPIDER_DB_UNIQUE_NAME_STR "UNIQUE" +#define SPIDER_DB_UNIQUE_NAME_LEN (sizeof(SPIDER_DB_UNIQUE_NAME_STR) - 1) +#define SPIDER_DB_KEY_NAME_STR "KEY" +#define SPIDER_DB_KEY_NAME_LEN (sizeof(SPIDER_DB_KEY_NAME_STR) - 1) +#define SPIDER_DB_SEQUENCE_NAME_STR "" +#define SPIDER_DB_SEQUENCE_NAME_LEN (sizeof(SPIDER_DB_SEQUENCE_NAME_STR) - 1) + +#define SPIDER_DB_TABLE_LOCK_READ_LOCAL 0 +#define SPIDER_DB_TABLE_LOCK_READ 1 +#define SPIDER_DB_TABLE_LOCK_LOW_PRIORITY_WRITE 2 +#define SPIDER_DB_TABLE_LOCK_WRITE 3 + +#define SPIDER_DB_INSERT_REPLACE (1 << 0) +#define SPIDER_DB_INSERT_IGNORE (1 << 1) +#define SPIDER_DB_INSERT_LOW_PRIORITY (1 << 2) +#define SPIDER_DB_INSERT_HIGH_PRIORITY (1 << 3) +#define SPIDER_DB_INSERT_DELAYED (1 << 4) + +#define SPIDER_SQL_OPEN_PAREN_STR "(" +#define SPIDER_SQL_OPEN_PAREN_LEN (sizeof(SPIDER_SQL_OPEN_PAREN_STR) - 1) +#define SPIDER_SQL_CLOSE_PAREN_STR ")" +#define SPIDER_SQL_CLOSE_PAREN_LEN (sizeof(SPIDER_SQL_CLOSE_PAREN_STR) - 1) +#define SPIDER_SQL_COMMA_STR "," +#define SPIDER_SQL_COMMA_LEN (sizeof(SPIDER_SQL_COMMA_STR) - 1) +#define SPIDER_SQL_UNION_ALL_STR ")union all(" +#define SPIDER_SQL_UNION_ALL_LEN (sizeof(SPIDER_SQL_UNION_ALL_STR) - 1) +#define SPIDER_SQL_NULL_STR "null" +#define SPIDER_SQL_NULL_LEN (sizeof(SPIDER_SQL_NULL_STR) - 1) +#define SPIDER_SQL_GT_STR " > " +#define SPIDER_SQL_GT_LEN (sizeof(SPIDER_SQL_GT_STR) - 1) +#define SPIDER_SQL_GTEQUAL_STR " >= " +#define SPIDER_SQL_GTEQUAL_LEN (sizeof(SPIDER_SQL_GTEQUAL_STR) - 1) +#define SPIDER_SQL_LT_STR " < " +#define SPIDER_SQL_LT_LEN (sizeof(SPIDER_SQL_LT_STR) - 1) +#define SPIDER_SQL_LTEQUAL_STR " <= " +#define SPIDER_SQL_LTEQUAL_LEN (sizeof(SPIDER_SQL_LTEQUAL_STR) - 1) + +#define SPIDER_SQL_ID_STR "id" +#define SPIDER_SQL_ID_LEN (sizeof(SPIDER_SQL_ID_STR) - 1) +#define SPIDER_SQL_TMP_BKA_ENGINE_STR "memory" +#define SPIDER_SQL_TMP_BKA_ENGINE_LEN (sizeof(SPIDER_SQL_TMP_BKA_ENGINE_STR) - 1) + +#define SPIDER_SQL_INSERT_STR "insert " +#define SPIDER_SQL_INSERT_LEN (sizeof(SPIDER_SQL_INSERT_STR) - 1) +#define SPIDER_SQL_REPLACE_STR "replace " +#define SPIDER_SQL_REPLACE_LEN (sizeof(SPIDER_SQL_REPLACE_STR) - 1) +#define SPIDER_SQL_SELECT_STR "select " +#define SPIDER_SQL_SELECT_LEN (sizeof(SPIDER_SQL_SELECT_STR) - 1) +#define SPIDER_SQL_UPDATE_STR "update " +#define SPIDER_SQL_UPDATE_LEN (sizeof(SPIDER_SQL_UPDATE_STR) - 1) +#define SPIDER_SQL_DELETE_STR "delete " +#define SPIDER_SQL_DELETE_LEN (sizeof(SPIDER_SQL_DELETE_STR) - 1) +#define SPIDER_SQL_HIGH_PRIORITY_STR "high_priority " +#define SPIDER_SQL_HIGH_PRIORITY_LEN (sizeof(SPIDER_SQL_HIGH_PRIORITY_STR) - 1) +#define SPIDER_SQL_LOW_PRIORITY_STR "low_priority " +#define SPIDER_SQL_LOW_PRIORITY_LEN (sizeof(SPIDER_SQL_LOW_PRIORITY_STR) - 1) +#define SPIDER_SQL_SQL_DELAYED_STR "delayed " +#define SPIDER_SQL_SQL_DELAYED_LEN (sizeof(SPIDER_SQL_SQL_DELAYED_STR) - 1) +#define SPIDER_SQL_SQL_IGNORE_STR "ignore " +#define SPIDER_SQL_SQL_IGNORE_LEN (sizeof(SPIDER_SQL_SQL_IGNORE_STR) - 1) +#define SPIDER_SQL_FROM_STR " from " +#define SPIDER_SQL_FROM_LEN (sizeof(SPIDER_SQL_FROM_STR) - 1) +#define SPIDER_SQL_WHERE_STR " where " +#define SPIDER_SQL_WHERE_LEN (sizeof(SPIDER_SQL_WHERE_STR) - 1) +#define SPIDER_SQL_OR_STR " or " +#define SPIDER_SQL_OR_LEN (sizeof(SPIDER_SQL_OR_STR) - 1) +#define SPIDER_SQL_ORDER_STR " order by " +#define SPIDER_SQL_ORDER_LEN (sizeof(SPIDER_SQL_ORDER_STR) - 1) +#define SPIDER_SQL_DESC_STR " desc" +#define SPIDER_SQL_DESC_LEN (sizeof(SPIDER_SQL_DESC_STR) - 1) +#define SPIDER_SQL_LIMIT_STR " limit " +#define SPIDER_SQL_LIMIT_LEN (sizeof(SPIDER_SQL_LIMIT_STR) - 1) +#define SPIDER_SQL_INTO_STR "into " +#define SPIDER_SQL_INTO_LEN (sizeof(SPIDER_SQL_INTO_STR) - 1) +#define SPIDER_SQL_VALUES_STR ")values" +#define SPIDER_SQL_VALUES_LEN (sizeof(SPIDER_SQL_VALUES_STR) - 1) +#define SPIDER_SQL_SHARED_LOCK_STR " lock in share mode" +#define SPIDER_SQL_SHARED_LOCK_LEN (sizeof(SPIDER_SQL_SHARED_LOCK_STR) - 1) +#define SPIDER_SQL_FOR_UPDATE_STR " for update" +#define SPIDER_SQL_FOR_UPDATE_LEN (sizeof(SPIDER_SQL_FOR_UPDATE_STR) - 1) + +#define SPIDER_SQL_SQL_ALTER_TABLE_STR "alter table " +#define SPIDER_SQL_SQL_ALTER_TABLE_LEN (sizeof(SPIDER_SQL_SQL_ALTER_TABLE_STR) - 1) +#define SPIDER_SQL_SQL_DISABLE_KEYS_STR " disable keys" +#define SPIDER_SQL_SQL_DISABLE_KEYS_LEN (sizeof(SPIDER_SQL_SQL_DISABLE_KEYS_STR) - 1) +#define SPIDER_SQL_SQL_ENABLE_KEYS_STR " enable keys" +#define SPIDER_SQL_SQL_ENABLE_KEYS_LEN (sizeof(SPIDER_SQL_SQL_ENABLE_KEYS_STR) - 1) +#define SPIDER_SQL_SQL_CHECK_TABLE_STR "check table " +#define SPIDER_SQL_SQL_CHECK_TABLE_LEN (sizeof(SPIDER_SQL_SQL_CHECK_TABLE_STR) - 1) +#define SPIDER_SQL_SQL_ANALYZE_STR "analyze " +#define SPIDER_SQL_SQL_ANALYZE_LEN (sizeof(SPIDER_SQL_SQL_ANALYZE_STR) - 1) +#define SPIDER_SQL_SQL_OPTIMIZE_STR "optimize " +#define SPIDER_SQL_SQL_OPTIMIZE_LEN (sizeof(SPIDER_SQL_SQL_OPTIMIZE_STR) - 1) +#define SPIDER_SQL_SQL_REPAIR_STR "repair " +#define SPIDER_SQL_SQL_REPAIR_LEN (sizeof(SPIDER_SQL_SQL_REPAIR_STR) - 1) +#define SPIDER_SQL_SQL_TABLE_STR "table " +#define SPIDER_SQL_SQL_TABLE_LEN (sizeof(SPIDER_SQL_SQL_TABLE_STR) - 1) +#define SPIDER_SQL_SQL_QUICK_STR " quick" +#define SPIDER_SQL_SQL_QUICK_LEN (sizeof(SPIDER_SQL_SQL_QUICK_STR) - 1) +#define SPIDER_SQL_SQL_FAST_STR " fast" +#define SPIDER_SQL_SQL_FAST_LEN (sizeof(SPIDER_SQL_SQL_FAST_STR) - 1) +#define SPIDER_SQL_SQL_MEDIUM_STR " medium" +#define SPIDER_SQL_SQL_MEDIUM_LEN (sizeof(SPIDER_SQL_SQL_MEDIUM_STR) - 1) +#define SPIDER_SQL_SQL_EXTENDED_STR " extended" +#define SPIDER_SQL_SQL_EXTENDED_LEN (sizeof(SPIDER_SQL_SQL_EXTENDED_STR) - 1) +#define SPIDER_SQL_SQL_LOCAL_STR "local " +#define SPIDER_SQL_SQL_LOCAL_LEN (sizeof(SPIDER_SQL_SQL_LOCAL_STR) - 1) +#define SPIDER_SQL_SQL_USE_FRM_STR " use_frm" +#define SPIDER_SQL_SQL_USE_FRM_LEN (sizeof(SPIDER_SQL_SQL_USE_FRM_STR) - 1) +#define SPIDER_SQL_TRUNCATE_TABLE_STR "truncate table " +#define SPIDER_SQL_TRUNCATE_TABLE_LEN (sizeof(SPIDER_SQL_TRUNCATE_TABLE_STR) - 1) +#define SPIDER_SQL_EXPLAIN_SELECT_STR "explain select 1 " +#define SPIDER_SQL_EXPLAIN_SELECT_LEN sizeof(SPIDER_SQL_EXPLAIN_SELECT_STR) - 1 +#define SPIDER_SQL_FLUSH_LOGS_STR "flush logs" +#define SPIDER_SQL_FLUSH_LOGS_LEN sizeof(SPIDER_SQL_FLUSH_LOGS_STR) - 1 +#define SPIDER_SQL_FLUSH_TABLES_STR "flush tables" +#define SPIDER_SQL_FLUSH_TABLES_LEN sizeof(SPIDER_SQL_FLUSH_TABLES_STR) - 1 +#define SPIDER_SQL_WITH_READ_LOCK_STR " with read lock" +#define SPIDER_SQL_WITH_READ_LOCK_LEN sizeof(SPIDER_SQL_WITH_READ_LOCK_STR) - 1 +#define SPIDER_SQL_DUPLICATE_KEY_UPDATE_STR " on duplicate key update " +#define SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN (sizeof(SPIDER_SQL_DUPLICATE_KEY_UPDATE_STR) - 1) +#define SPIDER_SQL_HANDLER_STR "handler " +#define SPIDER_SQL_HANDLER_LEN (sizeof(SPIDER_SQL_HANDLER_STR) - 1) +#define SPIDER_SQL_OPEN_STR " open " +#define SPIDER_SQL_OPEN_LEN (sizeof(SPIDER_SQL_OPEN_STR) - 1) +#define SPIDER_SQL_CLOSE_STR " close " +#define SPIDER_SQL_CLOSE_LEN (sizeof(SPIDER_SQL_CLOSE_STR) - 1) +#define SPIDER_SQL_READ_STR " read " +#define SPIDER_SQL_READ_LEN (sizeof(SPIDER_SQL_READ_STR) - 1) +#define SPIDER_SQL_FIRST_STR " first " +#define SPIDER_SQL_FIRST_LEN (sizeof(SPIDER_SQL_FIRST_STR) - 1) +#define SPIDER_SQL_NEXT_STR " next " +#define SPIDER_SQL_NEXT_LEN (sizeof(SPIDER_SQL_NEXT_STR) - 1) +#define SPIDER_SQL_PREV_STR " prev " +#define SPIDER_SQL_PREV_LEN (sizeof(SPIDER_SQL_PREV_STR) - 1) +#define SPIDER_SQL_LAST_STR " last " +#define SPIDER_SQL_LAST_LEN (sizeof(SPIDER_SQL_LAST_STR) - 1) +#define SPIDER_SQL_AS_STR "as " +#define SPIDER_SQL_AS_LEN (sizeof(SPIDER_SQL_AS_STR) - 1) +#define SPIDER_SQL_WITH_QUERY_EXPANSION_STR " with query expansion" +#define SPIDER_SQL_WITH_QUERY_EXPANSION_LEN (sizeof(SPIDER_SQL_WITH_QUERY_EXPANSION_STR) - 1) +#define SPIDER_SQL_IN_BOOLEAN_MODE_STR " in boolean mode" +#define SPIDER_SQL_IN_BOOLEAN_MODE_LEN (sizeof(SPIDER_SQL_IN_BOOLEAN_MODE_STR) - 1) +#define SPIDER_SQL_MATCH_STR "match(" +#define SPIDER_SQL_MATCH_LEN (sizeof(SPIDER_SQL_MATCH_STR) - 1) +#define SPIDER_SQL_AGAINST_STR ")against(" +#define SPIDER_SQL_AGAINST_LEN (sizeof(SPIDER_SQL_AGAINST_STR) - 1) +#define SPIDER_SQL_IS_NULL_STR " is null" +#define SPIDER_SQL_IS_NULL_LEN (sizeof(SPIDER_SQL_IS_NULL_STR) - 1) +#define SPIDER_SQL_IS_NOT_NULL_STR " is not null" +#define SPIDER_SQL_IS_NOT_NULL_LEN (sizeof(SPIDER_SQL_IS_NOT_NULL_STR) - 1) +#define SPIDER_SQL_NOT_NULL_STR " not null" +#define SPIDER_SQL_NOT_NULL_LEN (sizeof(SPIDER_SQL_NOT_NULL_STR) - 1) +#define SPIDER_SQL_DEFAULT_STR " default " +#define SPIDER_SQL_DEFAULT_LEN (sizeof(SPIDER_SQL_DEFAULT_STR) - 1) +#define SPIDER_SQL_SPACE_STR " " +#define SPIDER_SQL_SPACE_LEN (sizeof(SPIDER_SQL_SPACE_STR) - 1) +#define SPIDER_SQL_ONE_STR "1" +#define SPIDER_SQL_ONE_LEN sizeof(SPIDER_SQL_ONE_STR) - 1 +#define SPIDER_SQL_SQL_CACHE_STR "sql_cache " +#define SPIDER_SQL_SQL_CACHE_LEN (sizeof(SPIDER_SQL_SQL_CACHE_STR) - 1) +#define SPIDER_SQL_SQL_NO_CACHE_STR "sql_no_cache " +#define SPIDER_SQL_SQL_NO_CACHE_LEN (sizeof(SPIDER_SQL_SQL_NO_CACHE_STR) - 1) +#define SPIDER_SQL_SQL_QUICK_MODE_STR "quick " +#define SPIDER_SQL_SQL_QUICK_MODE_LEN (sizeof(SPIDER_SQL_SQL_QUICK_MODE_STR) - 1) +#define SPIDER_SQL_SET_STR " set " +#define SPIDER_SQL_SET_LEN (sizeof(SPIDER_SQL_SET_STR) - 1) +#define SPIDER_SQL_UNDERSCORE_STR "_" +#define SPIDER_SQL_UNDERSCORE_LEN sizeof(SPIDER_SQL_UNDERSCORE_STR) - 1 +#define SPIDER_SQL_PF_EQUAL_STR " <=> " +#define SPIDER_SQL_PF_EQUAL_LEN (sizeof(SPIDER_SQL_PF_EQUAL_STR) - 1) +#define SPIDER_SQL_GROUP_STR " group by " +#define SPIDER_SQL_GROUP_LEN (sizeof(SPIDER_SQL_GROUP_STR) - 1) +#define SPIDER_SQL_PLUS_STR " + " +#define SPIDER_SQL_PLUS_LEN (sizeof(SPIDER_SQL_PLUS_STR) - 1) +#define SPIDER_SQL_MINUS_STR " - " +#define SPIDER_SQL_MINUS_LEN (sizeof(SPIDER_SQL_MINUS_STR) - 1) + +#define SPIDER_SQL_SHOW_RECORDS_STR "select count(*) from " +#define SPIDER_SQL_SHOW_RECORDS_LEN sizeof(SPIDER_SQL_SHOW_RECORDS_STR) - 1 +#define SPIDER_SQL_SHOW_INDEX_STR "show index from " +#define SPIDER_SQL_SHOW_INDEX_LEN sizeof(SPIDER_SQL_SHOW_INDEX_STR) - 1 +#define SPIDER_SQL_SELECT_STATISTICS_STR "select `column_name`,`cardinality` from `information_schema`.`statistics` where `table_schema` = " +#define SPIDER_SQL_SELECT_STATISTICS_LEN sizeof(SPIDER_SQL_SELECT_STATISTICS_STR) - 1 +#define SPIDER_SQL_MAX_STR "max" +#define SPIDER_SQL_MAX_LEN sizeof(SPIDER_SQL_MAX_STR) - 1 + +#define SPIDER_SQL_DROP_TMP_STR "drop temporary table if exists " +#define SPIDER_SQL_DROP_TMP_LEN (sizeof(SPIDER_SQL_DROP_TMP_STR) - 1) +#define SPIDER_SQL_CREATE_TMP_STR "create temporary table " +#define SPIDER_SQL_CREATE_TMP_LEN (sizeof(SPIDER_SQL_CREATE_TMP_STR) - 1) +#define SPIDER_SQL_TMP_BKA_STR "tmp_spider_bka_" +#define SPIDER_SQL_TMP_BKA_LEN (sizeof(SPIDER_SQL_TMP_BKA_STR) - 1) +#define SPIDER_SQL_ENGINE_STR ")engine=" +#define SPIDER_SQL_ENGINE_LEN (sizeof(SPIDER_SQL_ENGINE_STR) - 1) +#define SPIDER_SQL_DEF_CHARSET_STR " default charset=" +#define SPIDER_SQL_DEF_CHARSET_LEN (sizeof(SPIDER_SQL_DEF_CHARSET_STR) - 1) +#define SPIDER_SQL_ID_TYPE_STR " bigint" +#define SPIDER_SQL_ID_TYPE_LEN (sizeof(SPIDER_SQL_ID_TYPE_STR) - 1) + +#define SPIDER_SQL_COLUMN_NAME_STR "`column_name`" +#define SPIDER_SQL_COLUMN_NAME_LEN sizeof(SPIDER_SQL_COLUMN_NAME_STR) - 1 + +#define SPIDER_SQL_A_DOT_STR "a." +#define SPIDER_SQL_A_DOT_LEN (sizeof(SPIDER_SQL_A_DOT_STR) - 1) +#define SPIDER_SQL_B_DOT_STR "b." +#define SPIDER_SQL_B_DOT_LEN (sizeof(SPIDER_SQL_B_DOT_STR) - 1) +#define SPIDER_SQL_A_STR "a" +#define SPIDER_SQL_A_LEN (sizeof(SPIDER_SQL_A_STR) - 1) +#define SPIDER_SQL_B_STR "b" +#define SPIDER_SQL_B_LEN (sizeof(SPIDER_SQL_B_STR) - 1) + +#define SPIDER_SQL_INT_LEN 20 +#define SPIDER_SQL_HANDLER_CID_LEN 6 +#define SPIDER_SQL_HANDLER_CID_FORMAT "t%05u" +#define SPIDER_UDF_PING_TABLE_PING_ONLY (1 << 0) +#define SPIDER_UDF_PING_TABLE_USE_WHERE (1 << 1) + +int spider_db_connect( + const SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +); + +int spider_db_ping( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +void spider_db_disconnect( + SPIDER_CONN *conn +); + +int spider_db_conn_queue_action( + SPIDER_CONN *conn +); + +int spider_db_before_query( + SPIDER_CONN *conn, + int *need_mon +); + +int spider_db_query( + SPIDER_CONN *conn, + const char *query, + uint length, + int quick_mode, + int *need_mon +); + +int spider_db_errorno( + SPIDER_CONN *conn +); + +int spider_db_set_trx_isolation( + SPIDER_CONN *conn, + int trx_isolation, + int *need_mon +); + +int spider_db_set_names_internal( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int all_link_idx, + int *need_mon +); + +int spider_db_set_names( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +int spider_db_query_with_set_names( + ulong sql_type, + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +int spider_db_query_for_bulk_update( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + uint *dup_key_found +); + +size_t spider_db_real_escape_string( + SPIDER_CONN *conn, + char *to, + const char *from, + size_t from_length +); + +int spider_db_consistent_snapshot( + SPIDER_CONN *conn, + int *need_mon +); + +int spider_db_start_transaction( + SPIDER_CONN *conn, + int *need_mon +); + +int spider_db_commit( + SPIDER_CONN *conn +); + +int spider_db_rollback( + SPIDER_CONN *conn +); + +int spider_db_append_hex_string( + spider_string *str, + uchar *hex_ptr, + int hex_ptr_length +); + +void spider_db_append_xid_str( + spider_string *tmp_str, + XID *xid +); + +int spider_db_xa_end( + SPIDER_CONN *conn, + XID *xid +); + +int spider_db_xa_prepare( + SPIDER_CONN *conn, + XID *xid +); + +int spider_db_xa_commit( + SPIDER_CONN *conn, + XID *xid +); + +int spider_db_xa_rollback( + SPIDER_CONN *conn, + XID *xid +); + +int spider_db_lock_tables( + ha_spider *spider, + int link_idx +); + +int spider_db_unlock_tables( + ha_spider *spider, + int link_idx +); + +int spider_db_append_name_with_quote_str( + spider_string *str, + char *name, + uint dbton_id +); + +int spider_db_append_select( + ha_spider *spider +); + +int spider_db_append_select_columns( + ha_spider *spider +); + +int spider_db_append_null_value( + spider_string *str, + KEY_PART_INFO *key_part, + const uchar **ptr +); + +int spider_db_append_key_columns( + const key_range *start_key, + ha_spider *spider, + spider_string *str +); + +int spider_db_append_key_hint( + spider_string *str, + char *hint_str +); + +int spider_db_append_key_where_internal( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ha_spider *spider, + bool set_order, + ulong sql_type, + uint dbton_id +); + +int spider_db_append_key_where( + const key_range *start_key, + const key_range *end_key, + ha_spider *spider +); + +int spider_db_append_match_fetch( + ha_spider *spider, + st_spider_ft_info *ft_first, + st_spider_ft_info *ft_current, + SPIDER_DB_ROW *row +); + +int spider_db_append_match_where( + ha_spider *spider +); + +int spider_db_append_hint_after_table( + ha_spider *spider, + spider_string *str, + spider_string *hint +); + +int spider_db_append_show_records( + SPIDER_SHARE *share +); + +void spider_db_free_show_records( + SPIDER_SHARE *share +); + +int spider_db_append_show_index( + SPIDER_SHARE *share +); + +void spider_db_free_show_index( + SPIDER_SHARE *share +); + +void spider_db_append_handler_next( + ha_spider *spider +); + +void spider_db_get_row_from_tmp_tbl_rec( + SPIDER_RESULT *current, + SPIDER_DB_ROW **row +); + +int spider_db_get_row_from_tmp_tbl( + SPIDER_RESULT *current, + SPIDER_DB_ROW **row +); + +int spider_db_get_row_from_tmp_tbl_pos( + SPIDER_POSITION *pos, + SPIDER_DB_ROW **row +); + +int spider_db_fetch_row( + SPIDER_SHARE *share, + Field *field, + SPIDER_DB_ROW *row, + my_ptrdiff_t ptr_diff +); + +int spider_db_fetch_table( + ha_spider *spider, + uchar *buf, + TABLE *table, + SPIDER_RESULT_LIST *result_list +); + +int spider_db_fetch_key( + ha_spider *spider, + uchar *buf, + TABLE *table, + const KEY *key_info, + SPIDER_RESULT_LIST *result_list +); + +int spider_db_fetch_minimum_columns( + ha_spider *spider, + uchar *buf, + TABLE *table, + SPIDER_RESULT_LIST *result_list +); + +void spider_db_free_one_result_for_start_next( + ha_spider *spider +); + +void spider_db_free_one_result( + SPIDER_RESULT_LIST *result_list, + SPIDER_RESULT *result +); + +int spider_db_free_result( + ha_spider *spider, + bool final +); + +int spider_db_store_result( + ha_spider *spider, + int link_idx, + TABLE *table +); + +void spider_db_discard_result( + ha_spider *spider, + int link_idx, + SPIDER_CONN *conn +); + +void spider_db_discard_multiple_result( + ha_spider *spider, + int link_idx, + SPIDER_CONN *conn +); + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_store_result( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + bool discard_result +); +#endif + +int spider_db_fetch( + uchar *buf, + ha_spider *spider, + TABLE *table +); + +int spider_db_seek_prev( + uchar *buf, + ha_spider *spider, + TABLE *table +); + +int spider_db_seek_next( + uchar *buf, + ha_spider *spider, + int link_idx, + TABLE *table +); + +int spider_db_seek_last( + uchar *buf, + ha_spider *spider, + int link_idx, + TABLE *table +); + +int spider_db_seek_first( + uchar *buf, + ha_spider *spider, + TABLE *table +); + +void spider_db_set_pos_to_first_row( + SPIDER_RESULT_LIST *result_list +); + +void spider_db_create_position( + ha_spider *spider, + SPIDER_POSITION *pos +); + +int spider_db_seek_tmp( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +); + +int spider_db_seek_tmp_table( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +); + +int spider_db_seek_tmp_key( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table, + const KEY *key_info +); + +int spider_db_seek_tmp_minimum_columns( + uchar *buf, + SPIDER_POSITION *pos, + ha_spider *spider, + TABLE *table +); + +int spider_db_show_table_status( + ha_spider *spider, + int link_idx, + int sts_mode, + uint flag +); + +int spider_db_show_records( + ha_spider *spider, + int link_idx +); + +void spider_db_set_cardinarity( + ha_spider *spider, + TABLE *table +); + +int spider_db_show_index( + ha_spider *spider, + int link_idx, + TABLE *table, + int crd_mode +); + +ha_rows spider_db_explain_select( + key_range *start_key, + key_range *end_key, + ha_spider *spider, + int link_idx +); + +int spider_db_bulk_insert_init( + ha_spider *spider, + const TABLE *table +); + +int spider_db_bulk_insert( + ha_spider *spider, + TABLE *table, + bool bulk_end +); + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_bulk_insert( + ha_spider *spider +); +#endif + +int spider_db_update_auto_increment( + ha_spider *spider, + int link_idx +); + +int spider_db_bulk_update_size_limit( + ha_spider *spider, + TABLE *table +); + +int spider_db_bulk_update_end( + ha_spider *spider, + uint *dup_key_found +); + +int spider_db_bulk_update( + ha_spider *spider, + TABLE *table, + my_ptrdiff_t ptr_diff +); + +int spider_db_update( + ha_spider *spider, + TABLE *table, + const uchar *old_data +); + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_direct_update( + ha_spider *spider, + TABLE *table, + KEY_MULTI_RANGE *ranges, + uint range_count, + uint *update_rows +); +#endif + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_direct_update( + ha_spider *spider, + uint *update_rows +); +#endif + +int spider_db_bulk_delete( + ha_spider *spider, + TABLE *table, + my_ptrdiff_t ptr_diff +); + +int spider_db_delete( + ha_spider *spider, + TABLE *table, + const uchar *buf +); + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_direct_delete( + ha_spider *spider, + TABLE *table, + KEY_MULTI_RANGE *ranges, + uint range_count, + uint *delete_rows +); +#endif + +int spider_db_delete_all_rows( + ha_spider *spider +); + +int spider_db_disable_keys( + ha_spider *spider +); + +int spider_db_enable_keys( + ha_spider *spider +); + +int spider_db_check_table( + ha_spider *spider, + HA_CHECK_OPT* check_opt +); + +int spider_db_repair_table( + ha_spider *spider, + HA_CHECK_OPT* check_opt +); + +int spider_db_analyze_table( + ha_spider *spider +); + +int spider_db_optimize_table( + ha_spider *spider +); + +int spider_db_flush_tables( + ha_spider *spider, + bool lock +); + +int spider_db_flush_logs( + ha_spider *spider +); + +int spider_db_print_item_type( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_cond( + Item_cond *item_cond, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_ident( + Item_ident *item_ident, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_field( + Item_field *item_field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_ref( + Item_ref *item_ref, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_row( + Item_row *item_row, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_string( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_int( + Item *item, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_open_item_cache( + Item_cache *item_cache, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); + +int spider_db_append_condition( + ha_spider *spider, + const char *alias, + uint alias_length, + bool test_flg +); + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_db_append_update_columns( + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id +); +#endif + +uint spider_db_check_ft_idx( + Item_func *item_func, + ha_spider *spider +); + +int spider_db_udf_fetch_row( + SPIDER_TRX *trx, + Field *field, + SPIDER_DB_ROW *row, + ulong *length +); + +int spider_db_udf_fetch_table( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + TABLE *table, + SPIDER_DB_RESULT *result, + uint set_on, + uint set_off +); + +int spider_db_udf_direct_sql_connect( + const SPIDER_DIRECT_SQL *direct_sql, + SPIDER_CONN *conn +); + +int spider_db_udf_direct_sql_ping( + SPIDER_DIRECT_SQL *direct_sql +); + +int spider_db_udf_direct_sql( + SPIDER_DIRECT_SQL *direct_sql +); + +int spider_db_udf_direct_sql_select_db( + SPIDER_DIRECT_SQL *direct_sql, + SPIDER_CONN *conn +); + +int spider_db_udf_direct_sql_set_names( + SPIDER_DIRECT_SQL *direct_sql, + SPIDER_TRX *trx, + SPIDER_CONN *conn +); + +int spider_db_udf_check_and_set_set_names( + SPIDER_TRX *trx +); + +int spider_db_udf_append_set_names( + SPIDER_TRX *trx +); + +void spider_db_udf_free_set_names( + SPIDER_TRX *trx +); + +int spider_db_udf_ping_table( + SPIDER_TABLE_MON_LIST *table_mon_list, + SPIDER_SHARE *share, + SPIDER_TRX *trx, + SPIDER_CONN *conn, + char *where_clause, + uint where_clause_length, + bool ping_only, + bool use_where, + longlong limit +); + +int spider_db_udf_ping_table_append_mon_next( + spider_string *str, + char *child_table_name, + uint child_table_name_length, + int link_id, + char *where_clause, + uint where_clause_length, + longlong first_sid, + int full_mon_count, + int current_mon_count, + int success_count, + int fault_count, + int flags, + longlong limit +); + +int spider_db_udf_ping_table_append_select( + spider_string *str, + SPIDER_SHARE *share, + SPIDER_TRX *trx, + spider_string *where_str, + bool use_where, + longlong limit, + uint dbton_id +); + +int spider_db_udf_ping_table_mon_next( + THD *thd, + SPIDER_TABLE_MON *table_mon, + SPIDER_CONN *conn, + SPIDER_MON_TABLE_RESULT *mon_table_result, + char *child_table_name, + uint child_table_name_length, + int link_id, + char *where_clause, + uint where_clause_length, + longlong first_sid, + int full_mon_count, + int current_mon_count, + int success_count, + int fault_count, + int flags, + longlong limit +); + +int spider_db_udf_copy_tables( + SPIDER_COPY_TABLES *copy_tables, + ha_spider *spider, + TABLE *table, + longlong bulk_insert_rows +); + +int spider_db_open_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +#ifdef HA_CAN_BULK_ACCESS +int spider_db_bulk_open_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); +#endif + +int spider_db_close_handler( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + uint tgt_conn_kind +); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +void spider_db_hs_request_buf_reset( + SPIDER_CONN *conn +); +#endif diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc new file mode 100644 index 00000000000..0c1dce876dc --- /dev/null +++ b/storage/spider/spd_db_handlersocket.cc @@ -0,0 +1,5308 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_analyse.h" +#endif + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_db_handlersocket.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; +extern HASH spider_open_connections; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern const char spider_dig_upper[]; + +#define SPIDER_SQL_INTERVAL_STR " + interval " +#define SPIDER_SQL_INTERVAL_LEN (sizeof(SPIDER_SQL_INTERVAL_STR) - 1) +#define SPIDER_SQL_NEGINTERVAL_STR " - interval " +#define SPIDER_SQL_NEGINTERVAL_LEN (sizeof(SPIDER_SQL_NEGINTERVAL_STR) - 1) + +#define SPIDER_SQL_NAME_QUOTE_STR "" +#define SPIDER_SQL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_NAME_QUOTE_STR) - 1) +static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; + +#define SPIDER_SQL_TYPE_FULL_HS (SPIDER_SQL_TYPE_SELECT_HS | \ + SPIDER_SQL_TYPE_INSERT_HS | SPIDER_SQL_TYPE_UPDATE_HS | \ + SPIDER_SQL_TYPE_DELETE_HS | SPIDER_SQL_TYPE_OTHER_HS) + +static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = + {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; +#define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) + +static const char *spider_db_timefunc_interval_str[] = +{ + " year", " quarter", " month", " week", " day", + " hour", " minute", " second", " microsecond", + " year_month", " day_hour", " day_minute", + " day_second", " hour_minute", " hour_second", + " minute_second", " day_microsecond", " hour_microsecond", + " minute_microsecond", " second_microsecond" +}; + +static SPIDER_HS_STRING_REF spider_null_string_ref = SPIDER_HS_STRING_REF(); + +int spider_handlersocket_init() +{ + DBUG_ENTER("spider_handlersocket_init"); + DBUG_RETURN(0); +} + +int spider_handlersocket_deinit() +{ + DBUG_ENTER("spider_handlersocket_deinit"); + DBUG_RETURN(0); +} + +spider_db_share *spider_handlersocket_create_share( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_handlersocket_create_share"); + DBUG_RETURN(new spider_handlersocket_share(share)); +} + +spider_db_handler *spider_handlersocket_create_handler( + ha_spider *spider, + spider_db_share *db_share +) { + DBUG_ENTER("spider_handlersocket_create_handler"); + DBUG_RETURN(new spider_handlersocket_handler(spider, + (spider_handlersocket_share *) db_share)); +} + +SPIDER_DB_CONN *spider_handlersocket_create_conn( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_handlersocket_create_conn"); + DBUG_RETURN(new spider_db_handlersocket(conn)); +} + +spider_db_handlersocket_util spider_db_handlersocket_utility; + +SPIDER_DBTON spider_dbton_handlersocket = { + 0, + SPIDER_DB_WRAPPER_MYSQL, + SPIDER_DB_ACCESS_TYPE_NOSQL, + spider_handlersocket_init, + spider_handlersocket_deinit, + spider_handlersocket_create_share, + spider_handlersocket_create_handler, + NULL, + spider_handlersocket_create_conn, + &spider_db_handlersocket_utility +}; + +#ifndef HANDLERSOCKET_MYSQL_UTIL +spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_hs_string_ref_buffer::init() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +void spider_db_hs_string_ref_buffer::clear() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::clear"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_conds.clear(); + DBUG_VOID_RETURN; +} + +int spider_db_hs_string_ref_buffer::push_back( + SPIDER_HS_STRING_REF &cond +) { + DBUG_ENTER("spider_db_hs_string_ref_buffer::push_back"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_conds.push_back(cond); + DBUG_RETURN(0); +} + +SPIDER_HS_STRING_REF *spider_db_hs_string_ref_buffer::ptr() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(&hs_conds[0]); +} + +uint spider_db_hs_string_ref_buffer::size() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::size"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((uint) hs_conds.size()); +} +#else +spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer() : hs_da_init(FALSE) +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::spider_db_hs_string_ref_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::~spider_db_hs_string_ref_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + if (hs_da_init) + { + spider_free_mem_calc(spider_current_trx, + hs_conds_id, hs_conds.max_element * hs_conds.size_of_element); + delete_dynamic(&hs_conds); + } + DBUG_VOID_RETURN; +} + +int spider_db_hs_string_ref_buffer::init() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!hs_da_init) + { + SPD_INIT_DYNAMIC_ARRAY2(&hs_conds, sizeof(SPIDER_HS_STRING_REF), + NULL, 16, 16, MYF(MY_WME)); + spider_alloc_calc_mem_init(hs_conds, 159); + spider_alloc_calc_mem(spider_current_trx, + hs_conds, hs_conds.max_element * hs_conds.size_of_element); + hs_da_init = TRUE; + } + DBUG_RETURN(0); +} + +void spider_db_hs_string_ref_buffer::clear() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::clear"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_conds.elements = 0; + DBUG_VOID_RETURN; +} + +int spider_db_hs_string_ref_buffer::push_back( + SPIDER_HS_STRING_REF &cond +) { + uint old_elements = hs_conds.max_element; + DBUG_ENTER("spider_db_hs_string_ref_buffer::push_back"); + DBUG_PRINT("info",("spider this=%p", this)); + if (insert_dynamic(&hs_conds, (uchar *) &cond)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (hs_conds.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + hs_conds, + (hs_conds.max_element - old_elements) * hs_conds.size_of_element); + } + DBUG_RETURN(0); +} + +SPIDER_HS_STRING_REF *spider_db_hs_string_ref_buffer::ptr() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_HS_STRING_REF *) hs_conds.buffer); +} + +uint spider_db_hs_string_ref_buffer::size() +{ + DBUG_ENTER("spider_db_hs_string_ref_buffer::size"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(hs_conds.elements); +} +#endif + +spider_db_hs_str_buffer::spider_db_hs_str_buffer() : hs_da_init(FALSE) +{ + DBUG_ENTER("spider_db_hs_str_buffer::spider_db_hs_str_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_hs_str_buffer::~spider_db_hs_str_buffer() +{ + DBUG_ENTER("spider_db_hs_str_buffer::~spider_db_hs_str_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + if (hs_da_init) + { + spider_free_mem_calc(spider_current_trx, + hs_conds_id, hs_conds.max_element * hs_conds.size_of_element); + delete_dynamic(&hs_conds); + } + DBUG_VOID_RETURN; +} + +int spider_db_hs_str_buffer::init() +{ + DBUG_ENTER("spider_db_hs_str_buffer::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!hs_da_init) + { + SPD_INIT_DYNAMIC_ARRAY2(&hs_conds, sizeof(spider_string *), + NULL, 16, 16, MYF(MY_WME)); + spider_alloc_calc_mem_init(hs_conds, 160); + spider_alloc_calc_mem(spider_current_trx, + hs_conds, hs_conds.max_element * hs_conds.size_of_element); + hs_da_init = TRUE; + } + DBUG_RETURN(0); +} + +void spider_db_hs_str_buffer::clear() +{ + uint i; + spider_string *element; + DBUG_ENTER("spider_db_hs_str_buffer::clear"); + DBUG_PRINT("info",("spider this=%p", this)); + for (i = 0; i < hs_conds.elements; i++) + { + get_dynamic(&hs_conds, (uchar *) &element, i); + element->free(); + spider_free(spider_current_trx, element, MYF(0)); + } + hs_conds.elements = 0; + DBUG_VOID_RETURN; +} + +spider_string *spider_db_hs_str_buffer::add( + uint *strs_pos, + const char *str, + uint str_len +) { + spider_string *element; + DBUG_ENTER("spider_db_hs_str_buffer::add"); + DBUG_PRINT("info",("spider this=%p", this)); + if (hs_conds.elements <= *strs_pos + 1) + { + if (!(element = (spider_string *) spider_malloc(spider_current_trx, 8, + sizeof(spider_string), MYF(MY_WME | MY_ZEROFILL)))) + DBUG_RETURN(NULL); + element->init_calc_mem(98); + element->set_charset(&my_charset_bin); + if ((element->reserve(str_len + 1))) + { + spider_free(spider_current_trx, element, MYF(0)); + DBUG_RETURN(NULL); + } + element->q_append(str, str_len); + uint old_elements = hs_conds.max_element; + if (insert_dynamic(&hs_conds, (uchar *) &element)) + { + element->free(); + spider_free(spider_current_trx, element, MYF(0)); + DBUG_RETURN(NULL); + } + if (hs_conds.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + hs_conds, + (hs_conds.max_element - old_elements) * + hs_conds.size_of_element); + } + } else { + element = ((spider_string **) hs_conds.buffer)[*strs_pos]; + element->length(0); + if ((element->reserve(str_len + 1))) + DBUG_RETURN(NULL); + element->q_append(str, str_len); + } + (*strs_pos)++; + DBUG_RETURN(element); +} + +spider_db_handlersocket_row::spider_db_handlersocket_row() : spider_db_row(), + hs_row(NULL), field_count(0), cloned(FALSE) +{ + DBUG_ENTER("spider_db_handlersocket_row::spider_db_handlersocket_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_handlersocket_row::~spider_db_handlersocket_row() +{ + DBUG_ENTER("spider_db_handlersocket_row::~spider_db_handlersocket_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (cloned) + { + spider_free(spider_current_trx, hs_row_first, MYF(0)); + } + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket_row::store_to_field( + Field *field, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_handlersocket_row::store_to_field"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!hs_row->begin()) + { + DBUG_PRINT("info", ("spider field is null")); + field->set_null(); + field->reset(); + } else { +#ifndef DBUG_OFF + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, field->charset()); + tmp_str.init_calc_mem(119); + tmp_str.length(0); + tmp_str.append(hs_row->begin(), hs_row->size(), &my_charset_bin); + DBUG_PRINT("info", ("spider val=%s", tmp_str.c_ptr_safe())); +#endif + field->set_notnull(); + if (field->flags & BLOB_FLAG) + { + DBUG_PRINT("info", ("spider blob field")); + ((Field_blob *)field)->set_ptr( + hs_row->size(), (uchar *) hs_row->begin()); + } else + field->store(hs_row->begin(), hs_row->size(), &my_charset_bin); + } + DBUG_RETURN(0); +} + +int spider_db_handlersocket_row::append_to_str( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_row::append_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(hs_row->size())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(hs_row->begin(), hs_row->size()); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_row::append_escaped_to_str( + spider_string *str, + uint dbton_id +) { + DBUG_ENTER("spider_db_handlersocket_row::append_escaped_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_string tmp_str(hs_row->begin(), hs_row->size() + 1, &my_charset_bin); + tmp_str.init_calc_mem(172); + tmp_str.length(hs_row->size()); + if (str->reserve(hs_row->size() * 2 + 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + spider_dbton[dbton_id].db_util->append_escaped_util(str, tmp_str.get_str()); + str->mem_calc(); + DBUG_RETURN(0); +} + +void spider_db_handlersocket_row::first() +{ + DBUG_ENTER("spider_db_handlersocket_row::first"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_row = hs_row_first; + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket_row::next() +{ + DBUG_ENTER("spider_db_handlersocket_row::next"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_row++; + DBUG_VOID_RETURN; +} + +bool spider_db_handlersocket_row::is_null() +{ + DBUG_ENTER("spider_db_handlersocket_row::is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(!hs_row->begin()); +} + +int spider_db_handlersocket_row::val_int() +{ + DBUG_ENTER("spider_db_handlersocket_row::val_int"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(atoi(hs_row->begin())); +} + +double spider_db_handlersocket_row::val_real() +{ + DBUG_ENTER("spider_db_handlersocket_row::val_real"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(hs_row->begin() ? my_atof(hs_row->begin()) : 0.0); +} + +SPIDER_DB_ROW *spider_db_handlersocket_row::clone() +{ + spider_db_handlersocket_row *clone_row; + char *tmp_char; + uint row_size, i; + DBUG_ENTER("spider_db_handlersocket_row::clone"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(clone_row = new spider_db_handlersocket_row())) + { + DBUG_RETURN(NULL); + } + row_size = 0; + for (i = 0; i < field_count; i++) + { + row_size += hs_row_first[i].size(); + } + if (!spider_bulk_malloc(spider_current_trx, 169, MYF(MY_WME), + &clone_row->hs_row, sizeof(SPIDER_HS_STRING_REF) * field_count, + &tmp_char, row_size, + NullS) + ) { + delete clone_row; + DBUG_RETURN(NULL); + } + for (i = 0; i < field_count; i++) + { + memcpy(tmp_char, hs_row_first[i].begin(), hs_row_first[i].size()); + clone_row->hs_row[i].set(tmp_char, hs_row_first[i].size()); + tmp_char += hs_row_first[i].size(); + } + clone_row->hs_row_first = clone_row->hs_row; + clone_row->cloned = TRUE;; + DBUG_RETURN(NULL); +} + +int spider_db_handlersocket_row::store_to_tmp_table( + TABLE *tmp_table, + spider_string *str +) { + uint i; + SPIDER_HS_STRING_REF *tmp_hs_row = hs_row; + DBUG_ENTER("spider_db_handlersocket_row::store_to_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + for (i = 0; i < field_count; i++) + { + if (tmp_hs_row->begin()) + { + if (str->reserve(tmp_hs_row->size())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(tmp_hs_row->begin(), tmp_hs_row->size()); + } + tmp_hs_row++; + } + tmp_table->field[0]->set_notnull(); + tmp_table->field[0]->store( + (const char *) hs_row, + sizeof(SPIDER_HS_STRING_REF) * field_count, &my_charset_bin); + tmp_table->field[1]->set_notnull(); + tmp_table->field[1]->store( + str->ptr(), str->length(), &my_charset_bin); + tmp_table->field[2]->set_null(); + DBUG_RETURN(tmp_table->file->ha_write_row(tmp_table->record[0])); +} + + +spider_db_handlersocket_result_buffer::spider_db_handlersocket_result_buffer( +) : spider_db_result_buffer() +{ + DBUG_ENTER("spider_db_handlersocket_result_buffer::spider_db_handlersocket_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_handlersocket_result_buffer::~spider_db_handlersocket_result_buffer() +{ + DBUG_ENTER( + "spider_db_handlersocket_result_buffer::~spider_db_handlersocket_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket_result_buffer::clear() +{ + DBUG_ENTER("spider_db_handlersocket_result_buffer::clear"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_result.readbuf.clear(); + DBUG_VOID_RETURN; +} + +bool spider_db_handlersocket_result_buffer::check_size( + longlong size +) { + DBUG_ENTER("spider_db_handlersocket_result_buffer::check_size"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((uint) hs_result.readbuf.real_size() > size) + { + hs_result.readbuf.real_free(); + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +spider_db_handlersocket_result::spider_db_handlersocket_result( +) : spider_db_result() +{ + DBUG_ENTER("spider_db_handlersocket_result::spider_db_handlersocket_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_handlersocket_result::~spider_db_handlersocket_result() +{ + DBUG_ENTER( + "spider_db_handlersocket_result::~spider_db_handlersocket_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +bool spider_db_handlersocket_result::has_result() +{ + DBUG_ENTER("spider_db_handlersocket_result::has_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(((*hs_conn_p)->get_response_end_offset() > 0)); +} + +void spider_db_handlersocket_result::free_result() +{ + DBUG_ENTER("spider_db_handlersocket_result::free_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ((*hs_conn_p)->get_response_end_offset() > 0) + { + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + } + DBUG_VOID_RETURN; +} + +SPIDER_DB_ROW *spider_db_handlersocket_result::current_row() +{ + DBUG_ENTER("spider_db_handlersocket_result::current_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); +} + +SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row() +{ + DBUG_ENTER("spider_db_handlersocket_result::fetch_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(row.hs_row = (SPIDER_HS_STRING_REF *) + (*hs_conn_p)->get_next_row())) + { + store_error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + row.field_count = field_count; + row.hs_row_first = row.hs_row; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf +) { + spider_db_handlersocket_result_buffer *hs_res_buf; + DBUG_ENTER("spider_db_handlersocket_result::fetch_row_from_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_res_buf = (spider_db_handlersocket_result_buffer *) spider_res_buf; + if (!(row.hs_row = (SPIDER_HS_STRING_REF *) + (*hs_conn_p)->get_next_row_from_result(hs_res_buf->hs_result))) + { + store_error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + row.field_count = field_count; + row.hs_row_first = row.hs_row; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_handlersocket_result::fetch_row_from_tmp_table( + TABLE *tmp_table +) { + uint i; + spider_string tmp_str1, tmp_str2; + const char *row_ptr; + SPIDER_HS_STRING_REF *tmp_hs_row; + uint field_count; + DBUG_ENTER("spider_db_handlersocket_result::fetch_row_from_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_str1.init_calc_mem(171); + tmp_str2.init_calc_mem(173); + tmp_table->field[0]->val_str(tmp_str1.get_str()); + tmp_table->field[1]->val_str(tmp_str2.get_str()); + tmp_str1.mem_calc(); + tmp_str2.mem_calc(); + row_ptr = tmp_str2.ptr(); + tmp_hs_row = (SPIDER_HS_STRING_REF *) tmp_str1.ptr(); + field_count = tmp_str1.length() / sizeof(SPIDER_HS_STRING_REF); + row.hs_row = tmp_hs_row; + row.field_count = field_count; + row.hs_row_first = row.hs_row; + for (i = 0; i < field_count; i++) + { + if (tmp_hs_row->begin()) + { + uint length = tmp_hs_row->size(); + tmp_hs_row->set(row_ptr, length); + row_ptr += length; + } + tmp_hs_row++; + } + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +int spider_db_handlersocket_result::fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_table_status"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_result::fetch_table_records( + int mode, + ha_rows &records +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_table_records"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_result::fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_table_cardinality"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_result::fetch_table_mon_status( + int &status +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_table_mon_status"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +longlong spider_db_handlersocket_result::num_rows() +{ + DBUG_ENTER("spider_db_handlersocket_result::num_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((longlong) 0); +} + +uint spider_db_handlersocket_result::num_fields() +{ + DBUG_ENTER("spider_db_handlersocket_result::num_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(field_count); +} + +void spider_db_handlersocket_result::move_to_pos( + longlong pos +) { + DBUG_ENTER("spider_db_handlersocket_result::move_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket_result::get_errno() +{ + DBUG_ENTER("spider_db_handlersocket_result::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider store_error_num=%d", store_error_num)); + DBUG_RETURN(store_error_num); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_db_handlersocket_result::fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_columns_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int spider_db_handlersocket_result::fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_handlersocket_result::fetch_index_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} +#endif + +spider_db_handlersocket::spider_db_handlersocket( + SPIDER_CONN *conn +) : spider_db_conn(conn), + handler_open_array_inited(FALSE), + request_key_req_first(NULL), + request_key_req_last(NULL), + request_key_snd_first(NULL), + request_key_snd_last(NULL), + request_key_reuse_first(NULL), + request_key_reuse_last(NULL) +{ + DBUG_ENTER("spider_db_handlersocket::spider_db_handlersocket"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifndef HANDLERSOCKET_MYSQL_UTIL +#else + hs_conn = NULL; +#endif + DBUG_VOID_RETURN; +} + +spider_db_handlersocket::~spider_db_handlersocket() +{ + st_spider_db_request_key *tmp_request_key; + DBUG_ENTER("spider_db_handlersocket::~spider_db_handlersocket"); + DBUG_PRINT("info",("spider this=%p", this)); + if (handler_open_array_inited) + { + reset_opened_handler(); + spider_free_mem_calc(spider_current_trx, + handler_open_array_id, + handler_open_array.max_element * + handler_open_array.size_of_element); + delete_dynamic(&handler_open_array); + } + while (request_key_req_first) + { + tmp_request_key = request_key_req_first->next; + spider_free(spider_current_trx, request_key_req_first, MYF(0)); + request_key_req_first = tmp_request_key; + } + while (request_key_snd_first) + { + tmp_request_key = request_key_snd_first->next; + spider_free(spider_current_trx, request_key_snd_first, MYF(0)); + request_key_snd_first = tmp_request_key; + } + while (request_key_reuse_first) + { + tmp_request_key = request_key_reuse_first->next; + spider_free(spider_current_trx, request_key_reuse_first, MYF(0)); + request_key_reuse_first = tmp_request_key; + } + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket::init() +{ + DBUG_ENTER("spider_db_handlersocket::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + SPD_INIT_DYNAMIC_ARRAY2(&handler_open_array, + sizeof(SPIDER_LINK_FOR_HASH *), NULL, 16, 16, MYF(MY_WME)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_alloc_calc_mem_init(handler_open_array, 79); + spider_alloc_calc_mem(spider_current_trx, + handler_open_array, + handler_open_array.max_element * + handler_open_array.size_of_element); + handler_open_array_inited = TRUE; + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::is_connected() +{ + DBUG_ENTER("spider_db_handlersocket::is_connected"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifndef HANDLERSOCKET_MYSQL_UTIL + DBUG_RETURN(hs_conn.operator->()); +#else + DBUG_RETURN(hs_conn); +#endif +} + +void spider_db_handlersocket::bg_connect() +{ + DBUG_ENTER("spider_db_handlersocket::bg_connect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket::connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval +) { + DBUG_ENTER("spider_db_handlersocket::connect"); + DBUG_PRINT("info",("spider this=%p", this)); + SPIDER_HS_SOCKARGS sockargs; + sockargs.timeout = conn->connect_timeout; + sockargs.recv_timeout = conn->net_read_timeout; + sockargs.send_timeout = conn->net_write_timeout; + if (conn->hs_sock) + { + sockargs.family = AF_UNIX; + sockargs.set_unix_domain(conn->hs_sock); + } else { + char port_str[6]; + my_sprintf(port_str, (port_str, "%05ld", conn->hs_port)); + if (sockargs.resolve(conn->tgt_host, port_str) != 0) + { + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + conn->tgt_host); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + } +#ifndef HANDLERSOCKET_MYSQL_UTIL + if (!(hs_conn.operator->())) +#else + if (!(hs_conn)) +#endif + { + hs_conn = SPIDER_HS_CONN_CREATE(sockargs); + } else { + hs_conn->reconnect(); + spider_db_hs_request_buf_reset(conn); + } +#ifndef HANDLERSOCKET_MYSQL_UTIL + if (!(hs_conn.operator->())) +#else + if (!(hs_conn)) +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + while (hs_conn->get_error_code()) + { + if (!connect_retry_count) + { + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + conn->tgt_host); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + connect_retry_count--; + my_sleep((ulong) connect_retry_interval); + hs_conn->reconnect(); + } + reset_request_key_req(); + reset_request_key_snd(); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::ping() +{ + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::ping"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ((*hs_conn_p)->reconnect()) + { + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(ER_SPIDER_HS_NUM); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + + reset_request_key_req(); + reset_request_key_snd(); + conn->opened_handlers = 0; + conn->db_conn->reset_opened_handler(); + ++conn->connection_id; + DBUG_RETURN(0); +} + +void spider_db_handlersocket::bg_disconnect() +{ + DBUG_ENTER("spider_db_handlersocket::bg_disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket::disconnect() +{ + DBUG_ENTER("spider_db_handlersocket::disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifndef HANDLERSOCKET_MYSQL_UTIL + if (hs_conn.operator->()) +#else + DBUG_PRINT("info",("spider hs_conn=%p", hs_conn)); + if (hs_conn) +#endif + { + hs_conn->close(); +#ifndef HANDLERSOCKET_MYSQL_UTIL + SPIDER_HS_CONN tmp_hs_conn; + tmp_hs_conn = hs_conn; +#else + delete hs_conn; + hs_conn = NULL; +#endif + } + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket::set_net_timeout() +{ + DBUG_ENTER("spider_db_handlersocket::set_net_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(hs_conn->set_timeout( + conn->net_write_timeout, + conn->net_read_timeout + )); +} + +int spider_db_handlersocket::exec_query( + const char *query, + uint length, + int quick_mode +) { + DBUG_ENTER("spider_db_handlersocket::query"); + DBUG_PRINT("info",("spider this=%p", this)); + SPIDER_HS_CONN *hs_conn_p = &hs_conn; +#ifndef HANDLERSOCKET_MYSQL_UTIL + DBUG_PRINT("info", ("spider hs_conn %p", hs_conn.operator->())); +#else + DBUG_PRINT("info", ("spider hs_conn %p", hs_conn)); +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ((*hs_conn_p)->request_send() < 0) + { + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(ER_SPIDER_HS_NUM); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + move_request_key_to_snd(); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::get_errno() +{ + DBUG_ENTER("spider_db_handlersocket::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + stored_error = hs_conn->get_error_code(); + DBUG_PRINT("info",("spider stored_error=%d", stored_error)); + DBUG_RETURN(stored_error); +} + +const char *spider_db_handlersocket::get_error() +{ + const char *error_ptr; + DBUG_ENTER("spider_db_handlersocket::get_error"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifndef HANDLERSOCKET_MYSQL_UTIL + error_ptr = hs_conn->get_error().c_str(); +#else + error_ptr = hs_conn->get_error().c_ptr(); +#endif + DBUG_PRINT("info",("spider error=%s", error_ptr)); + DBUG_RETURN(error_ptr); +} + +bool spider_db_handlersocket::is_server_gone_error( + int error_num +) { + bool server_gone; + DBUG_ENTER("spider_db_handlersocket::is_server_gone_error"); + DBUG_PRINT("info",("spider this=%p", this)); + server_gone = (hs_conn->get_error_code() < 0); + DBUG_PRINT("info",("spider server_gone=%s", server_gone ? "TRUE" : "FALSE")); + DBUG_RETURN(server_gone); +} + +bool spider_db_handlersocket::is_dup_entry_error( + int error_num +) { + bool dup_entry; + DBUG_ENTER("spider_db_handlersocket::is_dup_entry_error"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifndef HANDLERSOCKET_MYSQL_UTIL + const char *c_str = hs_conn->get_error().c_str(); +#else + const char *c_str = hs_conn->get_error().c_ptr_safe(); +#endif + dup_entry = + ( + c_str[0] == '1' && + c_str[1] == '2' && + c_str[2] == '1' && + c_str[3] == '\0' + ); + DBUG_PRINT("info",("spider dup_entry=%s", dup_entry ? "TRUE" : "FALSE")); + DBUG_RETURN(dup_entry); +} + +bool spider_db_handlersocket::is_xa_nota_error( + int error_num +) { + bool xa_nota; + DBUG_ENTER("spider_db_handlersocket::is_xa_nota_error"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + xa_nota = (stored_error == ER_XAER_NOTA); + DBUG_PRINT("info",("spider xa_nota=%s", xa_nota ? "TRUE" : "FALSE")); + DBUG_RETURN(xa_nota); +} + +spider_db_result *spider_db_handlersocket::store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num +) { + int internal_error; + spider_db_handlersocket_result *result; + spider_db_handlersocket_result_buffer *hs_res_buf; + DBUG_ENTER("spider_db_handlersocket::store_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (*spider_res_buf) + { + hs_res_buf = (spider_db_handlersocket_result_buffer *) *spider_res_buf; + } else { + if (!(hs_res_buf = new spider_db_handlersocket_result_buffer())) + { + *error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + *spider_res_buf = (spider_db_result_buffer *) hs_res_buf; + } + hs_res_buf->clear(); + if (!(result = new spider_db_handlersocket_result())) + { + *error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + *error_num = 0; + result->hs_conn_p = &hs_conn; + size_t num_fields; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + if (request_key) + { + int tmp_res, tmp_err = (*hs_conn_p)->get_error_code(); + while ((tmp_res = check_request_key(request_key)) == 1) + { + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ((internal_error = (*hs_conn_p)->response_recv(num_fields))) + { + if (!tmp_err && internal_error > 0) + { + (*hs_conn_p)->clear_error(); + } else { + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf01 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if (internal_error > 0) + { + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->clear_error(); + } + delete result; + DBUG_RETURN(NULL); + } + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->response_buf_remove(); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + } + if (tmp_res == -1) + { + DBUG_PRINT("info",("spider ER_SPIDER_REQUEST_KEY_NUM")); + *error_num = ER_SPIDER_REQUEST_KEY_NUM; + DBUG_RETURN(NULL); + } + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ( + (internal_error = (*hs_conn_p)->response_recv(num_fields)) || + (*error_num = (*hs_conn_p)->get_result(hs_res_buf->hs_result)) + ) { + if (*error_num) + { + *error_num = HA_ERR_OUT_OF_MEM; + } + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf01 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if (internal_error > 0) + { + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + } + delete result; + DBUG_RETURN(NULL); + } +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf02 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + field_count = (uint) num_fields; + result->field_count = field_count; + DBUG_RETURN(result); +} + +spider_db_result *spider_db_handlersocket::use_result( + st_spider_db_request_key *request_key, + int *error_num +) { + int internal_error; + spider_db_handlersocket_result *result; + DBUG_ENTER("spider_db_handlersocket::use_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(result = new spider_db_handlersocket_result())) + { + *error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + *error_num = 0; + result->hs_conn_p = &hs_conn; + size_t num_fields; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + if (request_key) + { + int tmp_res, tmp_err = (*hs_conn_p)->get_error_code(); + while ((tmp_res = check_request_key(request_key)) == 1) + { + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ((internal_error = (*hs_conn_p)->response_recv(num_fields))) + { + if (!tmp_err && internal_error > 0) + { + (*hs_conn_p)->clear_error(); + } else { + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf01 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if (internal_error > 0) + { + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->clear_error(); + } + delete result; + DBUG_RETURN(NULL); + } + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->response_buf_remove(); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + } + if (tmp_res == -1) + { + DBUG_PRINT("info",("spider ER_SPIDER_REQUEST_KEY_NUM")); + *error_num = ER_SPIDER_REQUEST_KEY_NUM; + DBUG_RETURN(NULL); + } + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if ( + (internal_error = (*hs_conn_p)->response_recv(num_fields)) + ) { + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf01 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if (internal_error > 0) + { + (*hs_conn_p)->response_buf_remove(); + if ((*hs_conn_p)->get_error_code()) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + } + delete result; + DBUG_RETURN(NULL); + } +#ifndef DBUG_OFF + if ((*hs_conn_p)->get_response_end_offset() > 0 && + (*hs_conn_p)->get_readbuf_begin()) + { + char tmp_buf[MAX_FIELD_WIDTH]; + String tmp_str(tmp_buf, MAX_FIELD_WIDTH, &my_charset_bin); + tmp_str.length(0); + tmp_str.append((*hs_conn_p)->get_readbuf_begin(), + (*hs_conn_p)->get_response_end_offset(), &my_charset_bin); + DBUG_PRINT("info",("spider hs readbuf02 size=%zu str=%s", + (*hs_conn_p)->get_response_end_offset(), tmp_str.c_ptr_safe())); + } +#endif + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + field_count = (uint) num_fields; + result->field_count = field_count; + DBUG_RETURN(result); +} + +int spider_db_handlersocket::next_result() +{ + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::next_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + if ((*hs_conn_p)->stable_point()) + DBUG_RETURN(-1); + DBUG_RETURN(0); +} + +uint spider_db_handlersocket::affected_rows() +{ + int error_num; + const SPIDER_HS_STRING_REF *hs_row; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::affected_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + if ( + field_count != 1 || + !(hs_row = (*hs_conn_p)->get_next_row()) || + !hs_row->begin() + ) { + DBUG_RETURN(0); + } + DBUG_RETURN((uint) my_strtoll10(hs_row->begin(), (char**) NULL, &error_num)); +} + +ulonglong spider_db_handlersocket::last_insert_id() +{ + DBUG_ENTER("spider_db_handlersocket::last_insert_id"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::set_character_set( + const char *csname +) { + DBUG_ENTER("spider_db_handlersocket::set_character_set"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::select_db( + const char *dbname +) { + DBUG_ENTER("spider_db_handlersocket::select_db"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::consistent_snapshot( + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::consistent_snapshot"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::trx_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::trx_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::start_transaction( + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::commit( + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::commit"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::rollback( + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::xa_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::xa_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::xa_start( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::xa_end( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::xa_end"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::xa_prepare( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::xa_prepare"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::xa_commit( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::xa_commit"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::xa_rollback( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::xa_rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::set_trx_isolation_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::set_trx_isolation_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::set_trx_isolation( + int trx_isolation, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::set_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::set_autocommit_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::set_autocommit_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::set_autocommit( + bool autocommit, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::set_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::set_sql_log_off_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::set_sql_log_off_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::set_sql_log_off( + bool sql_log_off, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::set_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::set_time_zone_in_bulk_sql() +{ + DBUG_ENTER("spider_db_handlersocket::set_time_zone_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::set_time_zone( + Time_zone *time_zone, + int *need_mon +) { + DBUG_ENTER("spider_db_handlersocket::set_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key +) { + int error_num; + size_t req_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + if (!(req_num = (*hs_conn_p)->request_buf_append(sql, sql + sql_length))) + { + DBUG_PRINT("info",("spider hs %d %s", + (*hs_conn_p)->get_error_code(), + (*hs_conn_p)->get_error().ptr())); + (*hs_conn_p)->write_error_to_log(__func__, __FILE__, __LINE__); + DBUG_RETURN((*hs_conn_p)->get_error_code()); + } + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + while (req_num > 1) + { + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + --req_num; + } + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key +) { + int error_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_open_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_buf_open_index( + handler_id, + db_name, + table_name, + index_name, + sql + ); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + int error_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_select"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_buf_exec_generic( + handler_id, + SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), + keys->ptr(), (size_t) keys->size(), + limit, skip, + SPIDER_HS_STRING_REF(), + NULL, 0); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key +) { + int error_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_buf_exec_generic( + handler_id, + SPIDER_HS_STRING_REF(SPIDER_SQL_HS_INSERT_STR, SPIDER_SQL_HS_INSERT_LEN), + upds->ptr(), (size_t) upds->size(), + 0, 0, + SPIDER_HS_STRING_REF(), NULL, 0); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key +) { + int error_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_buf_exec_generic( + handler_id, + SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), + keys->ptr(), (size_t) keys->size(), + limit, skip, + increment ? + SPIDER_HS_STRING_REF(SPIDER_SQL_HS_INCREMENT_STR, + SPIDER_SQL_HS_INCREMENT_LEN) : + decrement ? + SPIDER_HS_STRING_REF(SPIDER_SQL_HS_DECREMENT_STR, + SPIDER_SQL_HS_DECREMENT_LEN) : + SPIDER_HS_STRING_REF(SPIDER_SQL_HS_UPDATE_STR, + SPIDER_SQL_HS_UPDATE_LEN), + upds->ptr(), (size_t) upds->size() + ); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + int error_num; + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = append_request_key(request_key))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_buf_exec_generic( + handler_id, + SPIDER_HS_STRING_REF(sql->ptr(), sql->length()), + keys->ptr(), (size_t) keys->size(), + limit, skip, + SPIDER_HS_STRING_REF(SPIDER_SQL_HS_DELETE_STR, SPIDER_SQL_HS_DELETE_LEN), + NULL, 0); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + DBUG_RETURN(0); +} + +void spider_db_handlersocket::reset_request_queue() +{ + SPIDER_HS_CONN *hs_conn_p = &hs_conn; + DBUG_ENTER("spider_db_handlersocket::reset_request_queue"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider hs hs_conn=%p", hs_conn_p)); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + (*hs_conn_p)->request_reset(); + DBUG_PRINT("info",("spider hs num_req_bufd=%zu", + (*hs_conn_p)->get_num_req_bufd())); + DBUG_PRINT("info",("spider hs num_req_sent=%zu", + (*hs_conn_p)->get_num_req_sent())); + DBUG_PRINT("info",("spider hs num_req_rcvd=%zu", + (*hs_conn_p)->get_num_req_rcvd())); + DBUG_PRINT("info",("spider hs response_end_offset=%zu", + (*hs_conn_p)->get_response_end_offset())); + reset_request_key_req(); + DBUG_VOID_RETURN; +} + +size_t spider_db_handlersocket::escape_string( + char *to, + const char *from, + size_t from_length +) { + DBUG_ENTER("spider_db_handlersocket::escape_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + memcpy(to, from, from_length); + DBUG_RETURN(from_length); +} + +bool spider_db_handlersocket::have_lock_table_list() +{ + DBUG_ENTER("spider_db_handlersocket::have_lock_table_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handlersocket::append_lock_tables( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket::lock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_db_handlersocket::append_unlock_tables( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket::append_unlock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +uint spider_db_handlersocket::get_lock_table_hash_count() +{ + DBUG_ENTER("spider_db_handlersocket::get_lock_table_hash_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_db_handlersocket::reset_lock_table_hash() +{ + DBUG_ENTER("spider_db_handlersocket::reset_lock_table_hash"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +uint spider_db_handlersocket::get_opened_handler_count() +{ + DBUG_ENTER("spider_db_handlersocket::get_opened_handler_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(handler_open_array.elements); +} + +void spider_db_handlersocket::reset_opened_handler() +{ + ha_spider *tmp_spider; + int tmp_link_idx; + SPIDER_LINK_FOR_HASH **tmp_link_for_hash; + DBUG_ENTER("spider_db_handlersocket::reset_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + while ((tmp_link_for_hash = + (SPIDER_LINK_FOR_HASH **) pop_dynamic(&handler_open_array))) + { + tmp_spider = (*tmp_link_for_hash)->spider; + tmp_link_idx = (*tmp_link_for_hash)->link_idx; + tmp_spider->clear_handler_opened(tmp_link_idx, conn->conn_kind); + } + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket::set_dup_key_idx( + ha_spider *spider, + int link_idx +) { + DBUG_ENTER("spider_db_handlersocket::set_dup_key_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket::append_request_key( + st_spider_db_request_key *request_key +) { + st_spider_db_request_key *tmp_request_key; + DBUG_ENTER("spider_db_handlersocket::append_request_key"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider request_key=%p", request_key)); + if (request_key) + { + DBUG_PRINT("info",("spider request_key->spider_thread_id=%llu", + request_key->spider_thread_id)); + DBUG_PRINT("info",("spider request_key->query_id=%llu", + request_key->query_id)); + DBUG_PRINT("info",("spider request_key->handler=%p", + request_key->handler)); + DBUG_PRINT("info",("spider request_key->request_id=%llu", + request_key->request_id)); + if (request_key_reuse_first) + { + tmp_request_key = request_key_reuse_first; + request_key_reuse_first = request_key_reuse_first->next; + if (!request_key_reuse_first) + request_key_reuse_last = NULL; + } else { + if (!(tmp_request_key = (st_spider_db_request_key *) + spider_malloc(spider_current_trx, 1, sizeof(st_spider_db_request_key), + MYF(MY_WME))) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + *tmp_request_key = *request_key; + tmp_request_key->next = NULL; + if (request_key_req_last) + request_key_req_last->next = tmp_request_key; + else + request_key_req_first = tmp_request_key; + request_key_req_last = tmp_request_key; + } + DBUG_RETURN(0); +} + +void spider_db_handlersocket::reset_request_key_req() +{ + DBUG_ENTER("spider_db_handlersocket::reset_request_key_req"); + DBUG_PRINT("info",("spider this=%p", this)); + if (request_key_req_first) + { + if (request_key_reuse_last) + request_key_reuse_last->next = request_key_req_first; + else + request_key_reuse_first = request_key_req_first; + request_key_reuse_last = request_key_req_last; + request_key_req_first = NULL; + request_key_req_last = NULL; + } + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket::reset_request_key_snd() +{ + DBUG_ENTER("spider_db_handlersocket::reset_request_key_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + if (request_key_snd_first) + { + if (request_key_reuse_last) + request_key_reuse_last->next = request_key_snd_first; + else + request_key_reuse_first = request_key_snd_first; + request_key_reuse_last = request_key_snd_last; + request_key_snd_first = NULL; + request_key_snd_last = NULL; + } + DBUG_VOID_RETURN; +} + +void spider_db_handlersocket::move_request_key_to_snd() +{ + DBUG_ENTER("spider_db_handlersocket::move_request_key_to_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + if (request_key_req_first) + { + if (request_key_snd_last) + request_key_snd_last->next = request_key_req_first; + else + request_key_snd_first = request_key_req_first; + request_key_snd_last = request_key_req_last; + request_key_req_first = NULL; + request_key_req_last = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket::check_request_key( + st_spider_db_request_key *request_key +) { + st_spider_db_request_key *tmp_request_key; + DBUG_ENTER("spider_db_handlersocket::check_request_key"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider request_key=%p", request_key)); + DBUG_PRINT("info",("spider request_key_snd_first=%p", + request_key_snd_first)); + if (!request_key_snd_first) + { + DBUG_PRINT("info",("spider -1")); + DBUG_RETURN(-1); + } + tmp_request_key = request_key_snd_first; + request_key_snd_first = request_key_snd_first->next; + if (!request_key_snd_first) + request_key_snd_last = NULL; + tmp_request_key->next = NULL; + if (request_key_reuse_last) + request_key_reuse_last->next = tmp_request_key; + else + request_key_reuse_first = tmp_request_key; + request_key_reuse_last = tmp_request_key; + + DBUG_PRINT("info",("spider tmp_request_key->spider_thread_id=%llu", + tmp_request_key->spider_thread_id)); + DBUG_PRINT("info",("spider request_key->spider_thread_id=%llu", + request_key->spider_thread_id)); + DBUG_PRINT("info",("spider tmp_request_key->query_id=%llu", + tmp_request_key->query_id)); + DBUG_PRINT("info",("spider request_key->query_id=%llu", + request_key->query_id)); + DBUG_PRINT("info",("spider tmp_request_key->handler=%p", + tmp_request_key->handler)); + DBUG_PRINT("info",("spider request_key->handler=%p", + request_key->handler)); + DBUG_PRINT("info",("spider tmp_request_key->request_id=%llu", + tmp_request_key->request_id)); + DBUG_PRINT("info",("spider request_key->request_id=%llu", + request_key->request_id)); + if ( + tmp_request_key->spider_thread_id != request_key->spider_thread_id || + tmp_request_key->query_id != request_key->query_id || + tmp_request_key->handler != request_key->handler || + tmp_request_key->request_id != request_key->request_id + ) { + DBUG_PRINT("info",("spider 1")); + DBUG_RETURN(1); + } + DBUG_PRINT("info",("spider 0")); + DBUG_RETURN(0); +} + +bool spider_db_handlersocket::cmp_request_key_to_snd( + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_handlersocket::cmp_request_key_to_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider request_key=%p", request_key)); + if ( + !request_key + ) { + DBUG_PRINT("info",("spider TRUE")); + DBUG_RETURN(TRUE); + } + DBUG_PRINT("info",("spider request_key_snd_first=%p", + request_key_snd_first)); + if ( + !request_key_snd_first + ) { + DBUG_PRINT("info",("spider FALSE")); + DBUG_RETURN(FALSE); + } + DBUG_PRINT("info",("spider request_key_snd_first->spider_thread_id=%llu", + request_key_snd_first->spider_thread_id)); + DBUG_PRINT("info",("spider request_key->spider_thread_id=%llu", + request_key->spider_thread_id)); + DBUG_PRINT("info",("spider request_key_snd_first->query_id=%llu", + request_key_snd_first->query_id)); + DBUG_PRINT("info",("spider request_key->query_id=%llu", + request_key->query_id)); + DBUG_PRINT("info",("spider request_key_snd_first->handler=%p", + request_key_snd_first->handler)); + DBUG_PRINT("info",("spider request_key->handler=%p", + request_key->handler)); + DBUG_PRINT("info",("spider request_key_snd_first->request_id=%llu", + request_key_snd_first->request_id)); + DBUG_PRINT("info",("spider request_key->request_id=%llu", + request_key->request_id)); + if ( + request_key_snd_first->spider_thread_id != request_key->spider_thread_id || + request_key_snd_first->query_id != request_key->query_id || + request_key_snd_first->handler != request_key->handler || + request_key_snd_first->request_id != request_key->request_id + ) { + DBUG_PRINT("info",("spider FALSE")); + DBUG_RETURN(FALSE); + } + DBUG_PRINT("info",("spider TRUE")); + DBUG_RETURN(TRUE); +} + +spider_db_handlersocket_util::spider_db_handlersocket_util() : spider_db_util() +{ + DBUG_ENTER("spider_db_handlersocket_util::spider_db_handlersocket_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_handlersocket_util::~spider_db_handlersocket_util() +{ + DBUG_ENTER("spider_db_handlersocket_util::~spider_db_handlersocket_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_handlersocket_util::append_name( + spider_string *str, + const char *name, + uint name_length +) { + DBUG_ENTER("spider_db_handlersocket_util::append_name"); + str->q_append(name, name_length); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset +) { + DBUG_ENTER("spider_db_handlersocket_util::append_name_with_charset"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2 + name_length * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->append(name, name_length, name_charset); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +bool spider_db_handlersocket_util::is_name_quote( + const char head_code +) { + DBUG_ENTER("spider_db_handlersocket_util::is_name_quote"); + DBUG_RETURN(head_code == *name_quote_str); +} + +int spider_db_handlersocket_util::append_escaped_name_quote( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_util::append_escaped_name_quote"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset +) { + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); + String *ptr; + uint length; + DBUG_ENTER("spider_db_handlersocket_util::append_column_value"); + tmp_str.init_calc_mem(180); + + if (new_ptr) + { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR + ) { + length = uint2korr(new_ptr); + tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, + &my_charset_bin); + ptr = tmp_str.get_str(); + } else if (field->type() == MYSQL_TYPE_GEOMETRY) + { +/* + uint mlength = SIZEOF_STORED_DOUBLE, lcnt; + uchar *dest = (uchar *) buf; + const uchar *source; + for (lcnt = 0; lcnt < 4; lcnt++) + { + mlength = SIZEOF_STORED_DOUBLE; + source = new_ptr + mlength + SIZEOF_STORED_DOUBLE * lcnt; + while (mlength--) + *dest++ = *--source; + } + tmp_str.length(SIZEOF_STORED_DOUBLE * lcnt); +*/ + double xmin, xmax, ymin, ymax; +/* + float8store(buf,xmin); + float8store(buf+8,xmax); + float8store(buf+16,ymin); + float8store(buf+24,ymax); + memcpy(&xmin,new_ptr,sizeof(xmin)); + memcpy(&xmax,new_ptr + 8,sizeof(xmax)); + memcpy(&ymin,new_ptr + 16,sizeof(ymin)); + memcpy(&ymax,new_ptr + 24,sizeof(ymax)); + float8get(xmin, buf); + float8get(xmax, buf + 8); + float8get(ymin, buf + 16); + float8get(ymax, buf + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + DBUG_PRINT("info", ("spider geo is %.14g %.14g %.14g %.14g", + xmin, xmax, ymin, ymax)); +*/ + float8get(xmin, new_ptr); + float8get(xmax, new_ptr + 8); + float8get(ymin, new_ptr + 16); + float8get(ymax, new_ptr + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +/* + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 4); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 5); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 6); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 7); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 8); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 9); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 10); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 11); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 12); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 13); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 14); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 15); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +*/ +/* + tmp_str.set_quick((char *) new_ptr, SIZEOF_STORED_DOUBLE * 4, + &my_charset_bin); +*/ + tmp_str.length(0); + tmp_str.q_append((char *) SPIDER_SQL_LINESTRING_HEAD_STR, + SPIDER_SQL_LINESTRING_HEAD_LEN); + tmp_str.q_append((char *) new_ptr, SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 2, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 3, + SIZEOF_STORED_DOUBLE); + ptr = tmp_str.get_str(); + } else { + ptr = field->val_str(tmp_str.get_str(), new_ptr); + tmp_str.mem_calc(); + } + } else { + ptr = field->val_str(tmp_str.get_str()); + tmp_str.mem_calc(); + } + DBUG_PRINT("info", ("spider field->type() is %d", field->type())); + DBUG_PRINT("info", ("spider ptr->length() is %d", ptr->length())); +/* + if ( + field->type() == MYSQL_TYPE_BIT || + (field->type() >= MYSQL_TYPE_TINY_BLOB && + field->type() <= MYSQL_TYPE_BLOB) + ) { + uchar *hex_ptr = (uchar *) ptr->ptr(), *end_ptr; + char *str_ptr; + DBUG_PRINT("info", ("spider HEX")); + if (str->reserve(SPIDER_SQL_HEX_LEN + ptr->length() * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); + str_ptr = (char *) str->ptr() + str->length(); + for (end_ptr = hex_ptr + ptr->length(); hex_ptr < end_ptr; hex_ptr++) + { + *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; + *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; + } + str->length(str->length() + ptr->length() * 2); + } else +*/ + spider_handlersocket_handler *hs_handler = (spider_handlersocket_handler *) + spider->dbton_handler[spider_dbton_handlersocket.dbton_id]; + spider_string *hs_str; + if (!(hs_str = hs_handler->hs_strs.add( + &hs_handler->hs_strs_pos, ptr->ptr(), ptr->length()))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + SPIDER_HS_STRING_REF ref = + SPIDER_HS_STRING_REF(hs_str->ptr(), hs_str->length()); + if (hs_handler->hs_adding_keys) + { + DBUG_PRINT("info", ("spider add to key:%s", hs_str->c_ptr_safe())); + hs_handler->hs_keys.push_back(ref); + } else { + DBUG_PRINT("info", ("spider add to upd:%s", hs_str->c_ptr_safe())); + hs_handler->hs_upds.push_back(ref); + } + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_trx_isolation( + spider_string *str, + int trx_isolation +) { + DBUG_ENTER("spider_db_handlersocket_util::append_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_autocommit( + spider_string *str, + bool autocommit +) { + DBUG_ENTER("spider_db_handlersocket_util::append_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_sql_log_off( + spider_string *str, + bool sql_log_off +) { + DBUG_ENTER("spider_db_handlersocket_util::append_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_time_zone( + spider_string *str, + Time_zone *time_zone +) { + DBUG_ENTER("spider_db_handlersocket_util::append_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_start_transaction( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_util::append_start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_xa_start( + spider_string *str, + XID *xid +) { + DBUG_ENTER("spider_db_handlersocket_util::append_xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_lock_table_head( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_head"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type +) { + DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_body"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_lock_table_tail( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_util::append_lock_table_tail"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_unlock_table( + spider_string *str +) { + DBUG_ENTER("spider_db_handlersocket_util::append_unlock_table"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length +) { + uint dbton_id = spider_dbton_handlersocket.dbton_id; + int error_num; + Item *item, **item_list = item_func->arguments(); + uint roop_count, item_count = item_func->argument_count(), start_item = 0; + const char *func_name = SPIDER_SQL_NULL_CHAR_STR, + *separete_str = SPIDER_SQL_NULL_CHAR_STR, + *last_str = SPIDER_SQL_NULL_CHAR_STR; + int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, + separete_str_length = SPIDER_SQL_NULL_CHAR_LEN, + last_str_length = SPIDER_SQL_NULL_CHAR_LEN; + int use_pushdown_udf; + DBUG_ENTER("spider_db_handlersocket_util::open_item_func"); + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + DBUG_PRINT("info",("spider functype = %d", item_func->functype())); + switch (item_func->functype()) + { + case Item_func::ISNULL_FUNC: + last_str = SPIDER_SQL_IS_NULL_STR; + last_str_length = SPIDER_SQL_IS_NULL_LEN; + break; + case Item_func::ISNOTNULL_FUNC: + last_str = SPIDER_SQL_IS_NOT_NULL_STR; + last_str_length = SPIDER_SQL_IS_NOT_NULL_LEN; + break; + case Item_func::UNKNOWN_FUNC: + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (func_name_length == 1 && + ( + !strncasecmp("+", func_name, func_name_length) || + !strncasecmp("-", func_name, func_name_length) || + !strncasecmp("*", func_name, func_name_length) || + !strncasecmp("/", func_name, func_name_length) || + !strncasecmp("%", func_name, func_name_length) || + !strncasecmp("&", func_name, func_name_length) || + !strncasecmp("|", func_name, func_name_length) || + !strncasecmp("^", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 2 && + ( + !strncasecmp("<<", func_name, func_name_length) || + !strncasecmp(">>", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 3 && + !strncasecmp("div", func_name, func_name_length) + ) { + /* no action */ + break; + } else if (func_name_length == 4) + { + if ( + !strncasecmp("rand", func_name, func_name_length) && + !item_func->arg_count + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("case", func_name, func_name_length) + ) { +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC + Item_func_case *item_func_case = (Item_func_case *) item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (item_func_case->first_expr_num != -1) + { + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->first_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + for (roop_count = 0; roop_count < item_func_case->ncases; + roop_count += 2) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count + 1], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func_case->else_expr_num != -1) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->else_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +#else + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif + } + } else if (func_name_length == 6 && + !strncasecmp("istrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_TRUE_STR; + last_str_length = SPIDER_SQL_IS_TRUE_LEN; + break; + } else if (func_name_length == 7) + { + if (!strncasecmp("isfalse", func_name, func_name_length)) + { + last_str = SPIDER_SQL_IS_FALSE_STR; + last_str_length = SPIDER_SQL_IS_FALSE_LEN; + break; + } else if ( + !strncasecmp("sysdate", func_name, func_name_length) || + !strncasecmp("curdate", func_name, func_name_length) || + !strncasecmp("curtime", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + if (str->reserve(func_name_length * 2 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } + } else if (func_name_length == 8 && + ( + !strncasecmp("utc_date", func_name, func_name_length) || + !strncasecmp("utc_time", func_name, func_name_length) + ) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 9 && + !strncasecmp("isnottrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_TRUE_STR; + last_str_length = SPIDER_SQL_IS_NOT_TRUE_LEN; + break; + } else if (func_name_length == 10 && + !strncasecmp("isnotfalse", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_FALSE_STR; + last_str_length = SPIDER_SQL_IS_NOT_FALSE_LEN; + break; + } else if (func_name_length == 12) + { + if (!strncasecmp("cast_as_date", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATE_STR; + last_str_length = SPIDER_SQL_AS_DATE_LEN; + break; + } else if (!strncasecmp("cast_as_time", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_TIME_STR; + last_str_length = SPIDER_SQL_AS_TIME_LEN; + break; + } + } else if (func_name_length == 13 && + !strncasecmp("utc_timestamp", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 14) + { + if (!strncasecmp("cast_as_binary", func_name, func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(123); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_BINARY_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_signed", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_SIGNED_STR; + last_str_length = SPIDER_SQL_AS_SIGNED_LEN; + break; + } + } else if (func_name_length == 16) + { + if (!strncasecmp("cast_as_unsigned", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_UNSIGNED_STR; + last_str_length = SPIDER_SQL_AS_UNSIGNED_LEN; + break; + } else if (!strncasecmp("decimal_typecast", func_name, + func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(124); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_DECIMAL_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_datetime", func_name, + func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATETIME_STR; + last_str_length = SPIDER_SQL_AS_DATETIME_LEN; + break; + } + } else if (func_name_length == 17) + { + if (!strncasecmp("date_add_interval", func_name, func_name_length)) + { + Item_date_add_interval *item_date_add_interval = + (Item_date_add_interval *) item_func; + func_name = spider_db_timefunc_interval_str[ + item_date_add_interval->int_type]; + func_name_length = strlen(func_name); + if ((error_num = spider_db_print_item_type(item_list[0], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->date_sub_interval) + { + if (str->reserve(SPIDER_SQL_NEGINTERVAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NEGINTERVAL_STR, + SPIDER_SQL_NEGINTERVAL_LEN); + } else { + if (str->reserve(SPIDER_SQL_INTERVAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INTERVAL_STR, SPIDER_SQL_INTERVAL_LEN); + } + } + if ((error_num = spider_db_print_item_type(item_list[1], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); + } + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::NOW_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::CHAR_TYPECAST_FUNC: + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(125); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_CHAR_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + } + break; + case Item_func::NOT_FUNC: + case Item_func::NEG_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + break; + case Item_func::IN_FUNC: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_IN_STR; + func_name_length = SPIDER_SQL_NOT_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } else { + func_name = SPIDER_SQL_IN_STR; + func_name_length = SPIDER_SQL_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + case Item_func::BETWEEN: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_BETWEEN_STR; + func_name_length = SPIDER_SQL_NOT_BETWEEN_LEN; + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } else { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } + break; + case Item_func::UDF_FUNC: + use_pushdown_udf = spider_param_use_pushdown_udf(spider->trx->thd, + spider->share->use_pushdown_udf); + if (!use_pushdown_udf) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; +#ifdef MARIADB_BASE_VERSION + case Item_func::XOR_FUNC: +#else + case Item_func::COND_XOR_FUNC: +#endif + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN( + spider_db_open_item_cond((Item_cond *) item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::TRIG_COND_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::GUSERVAR_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (item_func->result_type() == STRING_RESULT) + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + else + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::FT_FUNC: + if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + start_item = 1; + if (str) + { + if (str->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + } + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_EQUALS_FUNC: + if (str) + { + func_name = SPIDER_SQL_MBR_EQUAL_STR; + func_name_length = SPIDER_SQL_MBR_EQUAL_LEN; + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_DISJOINT_FUNC: + case Item_func::SP_INTERSECTS_FUNC: + case Item_func::SP_TOUCHES_FUNC: + case Item_func::SP_CROSSES_FUNC: + case Item_func::SP_WITHIN_FUNC: + case Item_func::SP_CONTAINS_FUNC: + case Item_func::SP_OVERLAPS_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(SPIDER_SQL_MBR_LEN + func_name_length + + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_STR, SPIDER_SQL_MBR_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::EQ_FUNC: + case Item_func::EQUAL_FUNC: + case Item_func::NE_FUNC: + case Item_func::LT_FUNC: + case Item_func::LE_FUNC: + case Item_func::GE_FUNC: + case Item_func::GT_FUNC: + case Item_func::LIKE_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + default: + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + if (spider_param_skip_default_condition(thd, + share->skip_default_condition)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + } + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + DBUG_PRINT("info",("spider separete_str = %s", separete_str)); + DBUG_PRINT("info",("spider separete_str_length = %d", separete_str_length)); + DBUG_PRINT("info",("spider last_str = %s", last_str)); + DBUG_PRINT("info",("spider last_str_length = %d", last_str_length)); + if (item_count) + { + item_count--; + for (roop_count = start_item; roop_count < item_count; roop_count++) + { + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (roop_count == 1) + { + func_name = separete_str; + func_name_length = separete_str_length; + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + } + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func->functype() == Item_func::FT_FUNC) + { + Item_func_match *item_func_match = (Item_func_match *)item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_AGAINST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); + } + item = item_list[0]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve( + ((item_func_match->flags & FT_BOOL) ? + SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((item_func_match->flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (item_func_match->flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (item_func_match->flags & FT_EXPAND) + str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); + } + } else if (item_func->functype() == Item_func::UNKNOWN_FUNC) + { + if ( + func_name_length == 7 && + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + Item_func_conv_charset *item_func_conv_charset = + (Item_func_conv_charset *)item_func; + CHARSET_INFO *conv_charset = item_func_conv_charset->conv_charset; + uint cset_length = strlen(conv_charset->csname); + if (str->reserve(SPIDER_SQL_USING_LEN + cset_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); + str->q_append(conv_charset->csname, cset_length); + } + } + } + if (str) + { + if (str->reserve(last_str_length + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(last_str, last_str_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_handlersocket_util::append_escaped_util( + spider_string *to, + String *from +) { + DBUG_ENTER("spider_db_handlersocket_util::append_escaped_util"); + DBUG_PRINT("info",("spider this=%p", this)); + append_escaped(to->get_str(), from); + to->mem_calc(); + DBUG_RETURN(0); +} + +spider_handlersocket_share::spider_handlersocket_share( + st_spider_share *share +) : spider_db_share( + share +), + table_names_str(NULL), + db_names_str(NULL), + db_table_str(NULL), +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value(NULL), +#endif + table_nm_max_length(0), + db_nm_max_length(0), + column_name_str(NULL), + same_db_table_name(TRUE), + first_all_link_idx(-1) +{ + DBUG_ENTER("spider_handlersocket_share::spider_handlersocket_share"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 186); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_handlersocket_share::~spider_handlersocket_share() +{ + DBUG_ENTER("spider_handlersocket_share::~spider_handlersocket_share"); + DBUG_PRINT("info",("spider this=%p", this)); + free_column_name_str(); + free_table_names_str(); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (db_table_str_hash_value) + { + spider_free(spider_current_trx, db_table_str_hash_value, MYF(0)); + } +#endif + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_share::init() +{ + int error_num; + DBUG_ENTER("spider_handlersocket_share::init"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(db_table_str_hash_value = (my_hash_value_type *) + spider_bulk_alloc_mem(spider_current_trx, 203, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &db_table_str_hash_value, + sizeof(my_hash_value_type) * spider_share->all_link_count, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#endif + + if ( + (error_num = create_table_names_str()) || + (error_num = create_column_name_str()) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_share::append_table_name( + spider_string *str, + int all_link_idx +) { + const char *db_nm = db_names_str[all_link_idx].ptr(); + uint db_nm_len = db_names_str[all_link_idx].length(); + const char *table_nm = table_names_str[all_link_idx].ptr(); + uint table_nm_len = table_names_str[all_link_idx].length(); + DBUG_ENTER("spider_handlersocket_share::append_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(db_nm_len + SPIDER_SQL_DOT_LEN + table_nm_len + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_db_handlersocket_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_handlersocket_utility.append_name(str, table_nm, table_nm_len); + DBUG_RETURN(0); +} + +int spider_handlersocket_share::create_table_names_str() +{ + int error_num, roop_count; + uint table_nm_len, db_nm_len; + spider_string *str, *first_tbl_nm_str, *first_db_nm_str, *first_db_tbl_str; + char *first_tbl_nm, *first_db_nm; + uint dbton_id = spider_dbton_handlersocket.dbton_id; + DBUG_ENTER("spider_handlersocket_share::create_table_names_str"); + table_names_str = NULL; + db_names_str = NULL; + db_table_str = NULL; + if ( + !(table_names_str = new spider_string[spider_share->all_link_count]) || + !(db_names_str = new spider_string[spider_share->all_link_count]) || + !(db_table_str = new spider_string[spider_share->all_link_count]) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + + same_db_table_name = TRUE; + first_tbl_nm = spider_share->tgt_table_names[0]; + first_db_nm = spider_share->tgt_dbs[0]; + table_nm_len = spider_share->tgt_table_names_lengths[0]; + db_nm_len = spider_share->tgt_dbs_lengths[0]; + first_tbl_nm_str = &table_names_str[0]; + first_db_nm_str = &db_names_str[0]; + first_db_tbl_str = &db_table_str[0]; + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + table_names_str[roop_count].init_calc_mem(86); + db_names_str[roop_count].init_calc_mem(87); + db_table_str[roop_count].init_calc_mem(88); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + if (first_all_link_idx == -1) + first_all_link_idx = roop_count; + + str = &table_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_table_names_lengths[roop_count] == table_nm_len && + !memcmp(first_tbl_nm, spider_share->tgt_table_names[roop_count], + table_nm_len) + ) { + if (str->copy(*first_tbl_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_table_names[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different table name %s", + spider_share->tgt_table_names[roop_count])); + if (str->length() > table_nm_max_length) + table_nm_max_length = str->length(); + } else + table_nm_max_length = str->length(); + } + + str = &db_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_dbs_lengths[roop_count] == db_nm_len && + !memcmp(first_db_nm, spider_share->tgt_dbs[roop_count], + db_nm_len) + ) { + if (str->copy(*first_db_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_dbs[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different db name %s", + spider_share->tgt_dbs[roop_count])); + if (str->length() > db_nm_max_length) + db_nm_max_length = str->length(); + } else + db_nm_max_length = str->length(); + } + + str = &db_table_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name + ) { + if (str->copy(*first_db_tbl_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = append_table_name(str, roop_count))) + goto error; + } +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) str->ptr(), str->length()); +#endif + } + DBUG_RETURN(0); + +error: + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_handlersocket_share::free_table_names_str() +{ + DBUG_ENTER("spider_handlersocket_share::free_table_names_str"); + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_handlersocket_share::create_column_name_str() +{ + spider_string *str; + int error_num; + Field **field; + TABLE_SHARE *table_share = spider_share->table_share; + uint dbton_id = spider_dbton_handlersocket.dbton_id; + DBUG_ENTER("spider_handlersocket_share::create_column_name_str"); + if ( + table_share->fields && + !(column_name_str = new spider_string[table_share->fields]) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + for (field = table_share->field, str = column_name_str; + *field; field++, str++) + { + str->init_calc_mem(202); + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + (char *) (*field)->field_name, dbton_id))) + goto error; + } + DBUG_RETURN(0); + +error: + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_handlersocket_share::free_column_name_str() +{ + DBUG_ENTER("spider_handlersocket_share::free_column_name_str"); + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_VOID_RETURN; +} + +uint spider_handlersocket_share::get_column_name_length( + uint field_index +) { + DBUG_ENTER("spider_handlersocket_share::get_column_name_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(column_name_str[field_index].length()); +} + +int spider_handlersocket_share::append_column_name( + spider_string *str, + uint field_index +) { + int error_num; + DBUG_ENTER("spider_handlersocket_share::append_column_name"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_handlersocket_utility.append_name(str, + column_name_str[field_index].ptr(), column_name_str[field_index].length()); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_share::append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_handlersocket_share::append_column_name_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve( + alias_length + + column_name_str[field_index].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + append_column_name(str, field_index); + DBUG_RETURN(0); +} + +bool spider_handlersocket_share::need_change_db_table_name() +{ + DBUG_ENTER("spider_handlersocket_share::need_change_db_table_name"); + DBUG_RETURN(!same_db_table_name); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_handlersocket_share::discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +) { + DBUG_ENTER("spider_handlersocket_share::discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} +#endif + +spider_handlersocket_handler::spider_handlersocket_handler( + ha_spider *spider, + spider_handlersocket_share *db_share +) : spider_db_handler( + spider, + db_share +), + handlersocket_share(db_share), + link_for_hash(NULL) +{ + DBUG_ENTER("spider_handlersocket_handler::spider_handlersocket_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 187); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_handlersocket_handler::~spider_handlersocket_handler() +{ + DBUG_ENTER("spider_handlersocket_handler::~spider_handlersocket_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (link_for_hash) + { + spider_free(spider_current_trx, link_for_hash, MYF(0)); + } + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_handler::init() +{ + st_spider_share *share = spider->share; + DBUG_ENTER("spider_handlersocket_handler::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *) + spider_bulk_alloc_mem(spider_current_trx, 204, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &link_for_hash, + sizeof(SPIDER_LINK_FOR_HASH) * share->link_count, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + uint roop_count; + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + link_for_hash[roop_count].spider = spider; + link_for_hash[roop_count].link_idx = roop_count; + link_for_hash[roop_count].db_table_str = + &handlersocket_share->db_table_str[roop_count]; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + link_for_hash[roop_count].db_table_str_hash_value = + handlersocket_share->db_table_str_hash_value[roop_count]; +#endif + } + hs_sql.init_calc_mem(63); + hs_sql.set_charset(share->access_charset); + hs_keys.init(); + hs_upds.init(); + hs_strs.init(); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_tmp_table_and_sql_for_bka( + const key_range *start_key +) { + DBUG_ENTER("spider_handlersocket_handler::append_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reuse_tmp_table_and_sql_for_bka() +{ + DBUG_ENTER("spider_handlersocket_handler::reuse_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_insert_for_recovery( + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_insert_for_recovery"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + DBUG_ENTER("spider_handlersocket_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + DBUG_ENTER("spider_handlersocket_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_insert_part() +{ + DBUG_ENTER("spider_handlersocket_handler::append_insert_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_update_part() +{ + DBUG_ENTER("spider_handlersocket_handler::append_update_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_delete_part() +{ + DBUG_ENTER("spider_handlersocket_handler::append_delete_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_handlersocket_handler::append_increment_update_set_part() +{ + DBUG_ENTER("spider_handlersocket_handler::append_increment_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} +#endif + +int spider_handlersocket_handler::append_update_set_part() +{ + DBUG_ENTER("spider_handlersocket_handler::append_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_handlersocket_handler::append_direct_update_set_part() +{ + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_handlersocket_handler::append_direct_update_set_part"); + if ( + spider->do_direct_update && + (spider->direct_update_kinds & SPIDER_SQL_KIND_HS) + ) { + DBUG_PRINT("info",("spider add set for DU SPIDER_SQL_KIND_HS")); + size_t roop_count; + Field *field; + hs_adding_keys = FALSE; + for (roop_count = 0; roop_count < spider->hs_pushed_ret_fields_num; + roop_count++) + { + Field *top_table_field = + spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); + if (!(field = spider->field_exchange(top_table_field))) + continue; + if (top_table_field->is_null()) + { + hs_upds.push_back(spider_null_string_ref); + } else { + if (spider_db_handlersocket_utility. + append_column_value(spider, NULL, top_table_field, NULL, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + DBUG_RETURN(0); +} +#endif + +int spider_handlersocket_handler::append_minimum_select_without_quote( + spider_string *str +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_without_quote"); + for (field = table->field; *field; field++) + { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + field_length = + handlersocket_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(field_length + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append( + handlersocket_share->column_name_str[(*field)->field_index].ptr(), + handlersocket_share->column_name_str[(*field)->field_index].length()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_handlersocket_handler::append_minimum_select_by_field_idx_list( + spider_string *str, + uint32 *field_idxs, + size_t field_idxs_num +) { + Field *field; + int roop_count, field_length; + bool appended = FALSE; + DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_by_field_idx_list"); + for (roop_count = 0; roop_count < (int) field_idxs_num; roop_count++) + { + field = spider->get_top_table_field(field_idxs[roop_count]); + if ((field = spider->field_exchange(field))) + { + field_length = + handlersocket_share->column_name_str[field->field_index].length(); + if (str->reserve(field_length + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append( + handlersocket_share->column_name_str[field->field_index].ptr(), + handlersocket_share->column_name_str[field->field_index].length()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_dup_update_pushdown_part( + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_handlersocket_handler::append_dup_update_pushdown_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_update_columns_part( + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_handlersocket_handler::append_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::check_update_columns_part() +{ + DBUG_ENTER("spider_handlersocket_handler::check_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} +#endif + +int spider_handlersocket_handler::append_select_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_table_select_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_table_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_key_select_part( + ulong sql_type, + uint idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_key_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_minimum_select_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_minimum_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_hint_after_table_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_hint_after_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_handlersocket_handler::set_where_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_where_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +void spider_handlersocket_handler::set_where_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_where_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_handler::check_item_type( + Item *item +) { + DBUG_ENTER("spider_handlersocket_handler::check_item_type"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_values_connector_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_values_connector_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_values_terminator_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_values_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_key_column_values_part( + const key_range *start_key, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_key_column_values_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type +) { + int error_num; + spider_string *str; + bool set_order; + DBUG_ENTER("spider_handlersocket_handler::append_key_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_HS: + case SPIDER_SQL_TYPE_INSERT_HS: + case SPIDER_SQL_TYPE_UPDATE_HS: + case SPIDER_SQL_TYPE_DELETE_HS: + str = &hs_sql; + str->length(0); + hs_adding_keys = TRUE; + set_order = FALSE; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_where(str, NULL, NULL, start_key, end_key, + sql_type, set_order); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order +) { + int error_num; + DBUG_ENTER("spider_handlersocket_handler::append_key_where"); + error_num = spider_db_append_key_where_internal(str, str_part, str_part2, + start_key, end_key, spider, set_order, sql_type, + spider_dbton_handlersocket.dbton_id); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_handlersocket_handler::append_is_null_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_HS: + case SPIDER_SQL_TYPE_INSERT_HS: + case SPIDER_SQL_TYPE_UPDATE_HS: + case SPIDER_SQL_TYPE_DELETE_HS: + str = &hs_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_is_null(sql_type, str, NULL, NULL, key_part, key, ptr, + key_eq); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + DBUG_ENTER("spider_handlersocket_handler::append_is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + if (key_part->null_bit) + { + if (*(*ptr)++) + { + hs_keys.push_back(spider_null_string_ref); + DBUG_RETURN(-1); + } + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count +) { + DBUG_ENTER("spider_handlersocket_handler::append_where_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_match_where_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_match_where_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg +) { + DBUG_ENTER("spider_handlersocket_handler::append_condition_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_handlersocket_handler::append_match_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_handlersocket_handler::set_order_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_order_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +void spider_handlersocket_handler::set_order_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_order_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_handler::append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_key_order_for_merge_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_key_order_for_direct_order_limit_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_key_order_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info", ("spider offset=%lld", offset)); + DBUG_PRINT("info", ("spider limit=%lld", limit)); + hs_skip = (int) offset; + hs_limit = (int) limit; + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reappend_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_select_lock_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_select_lock_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_union_all_start_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_union_all_start_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_union_all_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_union_all_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_union_all_end_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_union_all_end_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma +) { + DBUG_ENTER("spider_handlersocket_handler::append_multi_range_cnt_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_handlersocket_handler::append_open_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_HS: + str = &hs_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_open_handler(str, handler_id, conn, link_idx); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_handlersocket_handler::append_open_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + str->length() == 0 && +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + ( + ( + ( + spider->sql_command == SQLCOM_HS_INSERT || + spider->hs_pushed_ret_fields_num == MAX_FIELDS + ) && +#endif + (error_num = append_minimum_select_without_quote(str)) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + ) || + ( + ( + spider->sql_command != SQLCOM_HS_INSERT && + spider->hs_pushed_ret_fields_num < MAX_FIELDS + ) && + (error_num = append_minimum_select_by_field_idx_list(str, + spider->hs_pushed_ret_fields, spider->hs_pushed_ret_fields_num)) + ) + ) +#endif + ) { + DBUG_RETURN(error_num); + } + + TABLE *table = spider->get_table(); + SPIDER_SHARE *share = spider->share; + DBUG_PRINT("info",("spider field list=%s", str->c_ptr_safe())); + if (!spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_set_bit(spider->db_request_phase, link_idx); + ++spider->db_request_id[link_idx]; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + conn->db_conn->append_open_handler( + handler_id, + share->tgt_dbs[spider->conn_link_idx[link_idx]], + share->tgt_table_names[spider->conn_link_idx[link_idx]], + spider->active_index < MAX_KEY ? + table->s->key_info[spider->active_index].name : + "0", + str->c_ptr_safe(), + &request_key + ); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_close_handler_part( + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_close_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_insert_terminator_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_insert_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_insert_values_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_insert_values_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_HS: + str = &hs_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_insert_values(str); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::append_insert_values( + spider_string *str +) { + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + Field **field; + DBUG_ENTER("spider_mysql_handler::append_insert_values"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_adding_keys = FALSE; + for (field = table->field; *field; field++) + { + DBUG_PRINT("info",("spider field_index=%u", (*field)->field_index)); + if ( + bitmap_is_set(table->write_set, (*field)->field_index) || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->read_set); +#endif + DBUG_PRINT("info",("spider is_null()=%s", + (*field)->is_null() ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider table->next_number_field=%p", + table->next_number_field)); + DBUG_PRINT("info",("spider *field=%p", *field)); + DBUG_PRINT("info",("spider force_auto_increment=%s", + (table->next_number_field && spider->force_auto_increment) ? + "TRUE" : "FALSE")); + if ( + (*field)->is_null() || + ( + table->next_number_field == *field && + !table->auto_increment_field_not_null && + !spider->force_auto_increment + ) + ) { + hs_upds.push_back(spider_null_string_ref); + } else { + spider_db_handlersocket_utility. + append_column_value(spider, NULL, *field, NULL, + share->access_charset); + } +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + } + int error_num; + int roop_count2; + for ( + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count2 < (int) share->link_count; + roop_count2 = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count2, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if (spider->sql_kind[roop_count2] == SPIDER_SQL_KIND_HS) + { + SPIDER_CONN *conn = spider->hs_w_conns[roop_count2]; + if (conn->dbton_id == spider_dbton_handlersocket.dbton_id) + { + if ((error_num = request_buf_insert(roop_count2))) + DBUG_RETURN(error_num); +#ifdef HA_CAN_BULK_ACCESS + if (spider->is_bulk_access_clone) + { + spider->connection_ids[roop_count2] = conn->connection_id; + spider_trx_add_bulk_access_conn(spider->trx, conn); + } +#endif + } + } + } + hs_upds.clear(); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_into_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_into_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_handlersocket_handler::set_insert_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_insert_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_handler::append_from_part( + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_from_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_delete_all_rows_part( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_delete_all_rows_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::append_explain_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +bool spider_handlersocket_handler::is_bulk_insert_exec_period( + bool bulk_end +) { + DBUG_ENTER("spider_handlersocket_handler::is_bulk_insert_exec_period"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!spider->bulk_insert || bulk_end) + DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); +} + +bool spider_handlersocket_handler::sql_is_filled_up( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::sql_is_filled_up"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); +} + +bool spider_handlersocket_handler::sql_is_empty( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::sql_is_empty"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); +} + +bool spider_handlersocket_handler::support_multi_split_read() +{ + DBUG_ENTER("spider_handlersocket_handler::support_multi_split_read"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); +} + +bool spider_handlersocket_handler::support_bulk_update() +{ + DBUG_ENTER("spider_handlersocket_handler::support_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); +} + +int spider_handlersocket_handler::bulk_tmp_table_insert() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::bulk_tmp_table_insert( + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::bulk_tmp_table_end_bulk_insert() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_end_bulk_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::bulk_tmp_table_rnd_init() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::bulk_tmp_table_rnd_next() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::bulk_tmp_table_rnd_end() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_rnd_end"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +bool spider_handlersocket_handler::need_copy_for_update( + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::need_copy_for_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(TRUE); +} + +bool spider_handlersocket_handler::bulk_tmp_table_created() +{ + DBUG_ENTER("spider_handlersocket_handler::bulk_tmp_table_created"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); +} + +int spider_handlersocket_handler::mk_bulk_tmp_table_and_bulk_start() +{ + DBUG_ENTER("spider_handlersocket_handler::mk_bulk_tmp_table_and_bulk_start"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_handlersocket_handler::rm_bulk_tmp_table() +{ + DBUG_ENTER("spider_handlersocket_handler::rm_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} + +int spider_handlersocket_handler::insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::insert_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended +) { + DBUG_ENTER("spider_handlersocket_handler::append_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::realloc_sql( + ulong *realloced +) { + THD *thd = spider->trx->thd; + st_spider_share *share = spider->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + DBUG_ENTER("spider_handlersocket_handler::realloc_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((int) hs_sql.alloced_length() > init_sql_alloc_size * 2) + { + hs_sql.free(); + if (hs_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_FULL_HS; + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reset_sql( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reset_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_FULL_HS) + { + hs_sql.length(0); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reset_keys( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reset_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_FULL_HS) + { + hs_keys.clear(); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reset_upds( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reset_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_FULL_HS) + { + hs_upds.clear(); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reset_strs( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reset_strs"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_FULL_HS) + { + hs_strs.clear(); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::reset_strs_pos( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::reset_strs_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_FULL_HS) + { + hs_strs_pos = 0; + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::push_back_upds( + SPIDER_HS_STRING_REF &info +) { + int error_num; + DBUG_ENTER("spider_handlersocket_handler::push_back_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = hs_upds.push_back(info); + DBUG_RETURN(error_num); +} + +int spider_handlersocket_handler::request_buf_find( + int link_idx +) { + int error_num; + spider_string *hs_str; + SPIDER_CONN *conn; + uint handler_id; + DBUG_ENTER("spider_handlersocket_handler::request_buf_find"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (spider->conn_kind[link_idx] == SPIDER_CONN_KIND_HS_READ) + { + conn = spider->hs_r_conns[link_idx]; + handler_id = spider->r_handler_id[link_idx]; + } else { + conn = spider->hs_w_conns[link_idx]; + handler_id = spider->w_handler_id[link_idx]; + } + if ((error_num = spider_db_conn_queue_action(conn))) + DBUG_RETURN(error_num); + if (!spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_set_bit(spider->db_request_phase, link_idx); + ++spider->db_request_id[link_idx]; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + conn->db_conn->append_select( + handler_id, hs_str, &hs_keys, + hs_limit, hs_skip, &request_key); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::request_buf_insert( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_handlersocket_handler::request_buf_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) + DBUG_RETURN(error_num); + if (!spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_set_bit(spider->db_request_phase, link_idx); + ++spider->db_request_id[link_idx]; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + spider->hs_w_conns[link_idx]->db_conn->append_insert( + spider->w_handler_id[link_idx], &hs_upds, &request_key); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::request_buf_update( + int link_idx +) { + int error_num; + spider_string *hs_str; + DBUG_ENTER("spider_handlersocket_handler::request_buf_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) + DBUG_RETURN(error_num); + if (!spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_set_bit(spider->db_request_phase, link_idx); + ++spider->db_request_id[link_idx]; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + spider->hs_w_conns[link_idx]->db_conn->append_update( + spider->w_handler_id[link_idx], hs_str, &hs_keys, &hs_upds, + hs_limit, hs_skip, + spider->hs_increment, spider->hs_decrement, &request_key + ); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::request_buf_delete( + int link_idx +) { + int error_num; + spider_string *hs_str; + DBUG_ENTER("spider_handlersocket_handler::request_buf_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(hs_str = hs_strs.add(&hs_strs_pos, hs_sql.ptr(), hs_sql.length()))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if ((error_num = spider_db_conn_queue_action(spider->hs_w_conns[link_idx]))) + DBUG_RETURN(error_num); + if (!spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_set_bit(spider->db_request_phase, link_idx); + ++spider->db_request_id[link_idx]; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = spider->db_request_id[link_idx]; + request_key.next = NULL; + spider->hs_w_conns[link_idx]->db_conn->append_delete( + spider->w_handler_id[link_idx], hs_str, &hs_keys, + hs_limit, hs_skip, &request_key); + DBUG_RETURN(0); +} + +bool spider_handlersocket_handler::need_lock_before_set_sql_for_exec( + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::need_lock_before_set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_handlersocket_handler::set_sql_for_exec( + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_SELECT_HS) + { + DBUG_RETURN(request_buf_find(link_idx)); + } + if (sql_type & SPIDER_SQL_TYPE_INSERT_HS) + { + DBUG_RETURN(request_buf_insert(link_idx)); + } + if (sql_type & SPIDER_SQL_TYPE_UPDATE_HS) + { + DBUG_RETURN(request_buf_update(link_idx)); + } + if (sql_type & SPIDER_SQL_TYPE_DELETE_HS) + { + DBUG_RETURN(request_buf_delete(link_idx)); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + DBUG_ENTER("spider_handlersocket_handler::execute_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(sql_type & SPIDER_SQL_TYPE_FULL_HS)) + { + /* nothing to do */ + DBUG_RETURN(0); + } + DBUG_RETURN(spider_db_query( + conn, + NULL, + 0, + quick_mode, + need_mon + )); +} + +int spider_handlersocket_handler::reset() +{ + DBUG_ENTER("spider_handlersocket_handler::reset"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::sts_mode_exchange( + int sts_mode +) { + DBUG_ENTER("spider_handlersocket_handler::sts_mode_exchange"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + DBUG_RETURN(sts_mode); +} + +int spider_handlersocket_handler::show_table_status( + int link_idx, + int sts_mode, + uint flag +) { + spider_db_handlersocket_result res; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_handlersocket_show_table_status"); + res.fetch_table_status( + sts_mode, + share->records, + share->mean_rec_length, + share->data_file_length, + share->max_data_file_length, + share->index_file_length, + share->auto_increment_value, + share->create_time, + share->update_time, + share->check_time + ); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::crd_mode_exchange( + int crd_mode +) { + DBUG_ENTER("spider_handlersocket_handler::crd_mode_exchange"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + DBUG_RETURN(crd_mode); +} + +int spider_handlersocket_handler::show_index( + int link_idx, + int crd_mode +) { + DBUG_ENTER("spider_handlersocket_handler::show_index"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::show_records( + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::show_records"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::show_last_insert_id( + int link_idx, + ulonglong &last_insert_id +) { + DBUG_ENTER("spider_handlersocket_handler::show_last_insert_id"); + last_insert_id = 0; + DBUG_RETURN(0); +} + +ha_rows spider_handlersocket_handler::explain_select( + key_range *start_key, + key_range *end_key, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::explain_select"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::lock_tables( + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::lock_tables"); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::unlock_tables( + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::unlock_tables"); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::disable_keys( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::disable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::enable_keys( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::enable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + DBUG_ENTER("spider_handlersocket_handler::check_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + DBUG_ENTER("spider_handlersocket_handler::repair_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::analyze_table( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::analyze_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::optimize_table( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::optimize_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock +) { + DBUG_ENTER("spider_handlersocket_handler::flush_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::flush_logs( + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_handlersocket_handler::flush_logs"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::insert_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_handlersocket *db_conn = (spider_db_handlersocket *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash = &link_for_hash[link_idx]; + DBUG_ASSERT(tmp_link_for_hash->spider == spider); + DBUG_ASSERT(tmp_link_for_hash->link_idx == link_idx); + uint old_elements = db_conn->handler_open_array.max_element; + DBUG_ENTER("spider_handlersocket_handler::insert_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (insert_dynamic(&db_conn->handler_open_array, + (uchar*) &tmp_link_for_hash)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->handler_open_array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->handler_open_array, + (db_conn->handler_open_array.max_element - old_elements) * + db_conn->handler_open_array.size_of_element); + } + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::delete_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_handlersocket *db_conn = (spider_db_handlersocket *) conn->db_conn; + uint roop_count, elements = db_conn->handler_open_array.elements; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash; + DBUG_ENTER("spider_handlersocket_handler::delete_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + for (roop_count = 0; roop_count < elements; roop_count++) + { + get_dynamic(&db_conn->handler_open_array, (uchar *) &tmp_link_for_hash, + roop_count); + if (tmp_link_for_hash == &link_for_hash[link_idx]) + { + delete_dynamic_element(&db_conn->handler_open_array, roop_count); + break; + } + } + DBUG_ASSERT(roop_count < elements); + DBUG_RETURN(0); +} + +int spider_handlersocket_handler::sync_from_clone_source( + spider_db_handler *dbton_hdl +) { + spider_handlersocket_handler *hs_hdl = + (spider_handlersocket_handler *) dbton_hdl; + DBUG_ENTER("spider_handlersocket_handler::sync_from_clone_source"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_strs_pos = hs_hdl->hs_strs_pos; + DBUG_RETURN(0); +} + +bool spider_handlersocket_handler::support_use_handler( + int use_handler +) { + DBUG_ENTER("spider_handlersocket_handler::support_use_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} +#endif diff --git a/storage/spider/spd_db_handlersocket.h b/storage/spider/spd_db_handlersocket.h new file mode 100644 index 00000000000..f516e1ef101 --- /dev/null +++ b/storage/spider/spd_db_handlersocket.h @@ -0,0 +1,893 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define SPIDER_HS_CONN dena::hstcpcli_ptr +#define SPIDER_HS_CONN_CREATE dena::hstcpcli_i::create +#define SPIDER_HS_RESULT dena::hstresult +#define SPIDER_HS_SOCKARGS dena::socket_args + +class spider_db_handlersocket_util: public spider_db_util +{ +public: + spider_db_handlersocket_util(); + ~spider_db_handlersocket_util(); + int append_name( + spider_string *str, + const char *name, + uint name_length + ); + int append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ); + bool is_name_quote( + const char head_code + ); + int append_escaped_name_quote( + spider_string *str + ); + int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset + ); + int append_trx_isolation( + spider_string *str, + int trx_isolation + ); + int append_autocommit( + spider_string *str, + bool autocommit + ); + int append_sql_log_off( + spider_string *str, + bool sql_log_off + ); + int append_time_zone( + spider_string *str, + Time_zone *time_zone + ); + int append_start_transaction( + spider_string *str + ); + int append_xa_start( + spider_string *str, + XID *xid + ); + int append_lock_table_head( + spider_string *str + ); + int append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type + ); + int append_lock_table_tail( + spider_string *str + ); + int append_unlock_table( + spider_string *str + ); + int open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length + ); + int append_escaped_util( + spider_string *to, + String *from + ); +}; + +class spider_db_handlersocket_row: public spider_db_row +{ +public: + SPIDER_HS_STRING_REF *hs_row; + SPIDER_HS_STRING_REF *hs_row_first; + uint field_count; + bool cloned; + spider_db_handlersocket_row(); + ~spider_db_handlersocket_row(); + int store_to_field( + Field *field, + CHARSET_INFO *access_charset + ); + int append_to_str( + spider_string *str + ); + int append_escaped_to_str( + spider_string *str, + uint dbton_id + ); + void first(); + void next(); + bool is_null(); + int val_int(); + double val_real(); + SPIDER_DB_ROW *clone(); + int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ); +}; + +class spider_db_handlersocket_result_buffer: public spider_db_result_buffer +{ +public: + SPIDER_HS_RESULT hs_result; + spider_db_handlersocket_result_buffer(); + ~spider_db_handlersocket_result_buffer(); + void clear(); + bool check_size( + longlong size + ); +}; + +class spider_db_handlersocket_result: public spider_db_result +{ +public: + SPIDER_HS_CONN *hs_conn_p; + spider_db_handlersocket_row row; + SPIDER_HS_STRING_REF hs_row; + uint field_count; + int store_error_num; + spider_db_handlersocket_result(); + ~spider_db_handlersocket_result(); + bool has_result(); + void free_result(); + SPIDER_DB_ROW *current_row(); + SPIDER_DB_ROW *fetch_row(); + SPIDER_DB_ROW *fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf + ); + SPIDER_DB_ROW *fetch_row_from_tmp_table( + TABLE *tmp_table + ); + int fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time + ); + int fetch_table_records( + int mode, + ha_rows &records + ); + int fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size + ); + int fetch_table_mon_status( + int &status + ); + longlong num_rows(); + uint num_fields(); + void move_to_pos( + longlong pos + ); + int get_errno(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); + int fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); +#endif +}; + +class spider_db_handlersocket: public spider_db_conn +{ + SPIDER_HS_CONN hs_conn; + int stored_error; + uint field_count; +public: + DYNAMIC_ARRAY handler_open_array; + bool handler_open_array_inited; + uint handler_open_array_id; + const char *handler_open_array_func_name; + const char *handler_open_array_file_name; + ulong handler_open_array_line_no; + st_spider_db_request_key *request_key_req_first; + st_spider_db_request_key *request_key_req_last; + st_spider_db_request_key *request_key_snd_first; + st_spider_db_request_key *request_key_snd_last; + st_spider_db_request_key *request_key_reuse_first; + st_spider_db_request_key *request_key_reuse_last; + spider_db_handlersocket( + SPIDER_CONN *conn + ); + ~spider_db_handlersocket(); + int init(); + bool is_connected(); + void bg_connect(); + int connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval + ); + int ping(); + void bg_disconnect(); + void disconnect(); + int set_net_timeout(); + int exec_query( + const char *query, + uint length, + int quick_mode + ); + int get_errno(); + const char *get_error(); + bool is_server_gone_error( + int error_num + ); + bool is_dup_entry_error( + int error_num + ); + bool is_xa_nota_error( + int error_num + ); + spider_db_result *store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num + ); + spider_db_result *use_result( + st_spider_db_request_key *request_key, + int *error_num + ); + int next_result(); + uint affected_rows(); + ulonglong last_insert_id(); + int set_character_set( + const char *csname + ); + int select_db( + const char *dbname + ); + int consistent_snapshot( + int *need_mon + ); + bool trx_start_in_bulk_sql(); + int start_transaction( + int *need_mon + ); + int commit( + int *need_mon + ); + int rollback( + int *need_mon + ); + bool xa_start_in_bulk_sql(); + int xa_start( + XID *xid, + int *need_mon + ); + int xa_end( + XID *xid, + int *need_mon + ); + int xa_prepare( + XID *xid, + int *need_mon + ); + int xa_commit( + XID *xid, + int *need_mon + ); + int xa_rollback( + XID *xid, + int *need_mon + ); + bool set_trx_isolation_in_bulk_sql(); + int set_trx_isolation( + int trx_isolation, + int *need_mon + ); + bool set_autocommit_in_bulk_sql(); + int set_autocommit( + bool autocommit, + int *need_mon + ); + bool set_sql_log_off_in_bulk_sql(); + int set_sql_log_off( + bool sql_log_off, + int *need_mon + ); + bool set_time_zone_in_bulk_sql(); + int set_time_zone( + Time_zone *time_zone, + int *need_mon + ); + int append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key + ); + int append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key + ); + int append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + int append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key + ); + int append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key + ); + int append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + void reset_request_queue(); + size_t escape_string( + char *to, + const char *from, + size_t from_length + ); + bool have_lock_table_list(); + int append_lock_tables( + spider_string *str + ); + int append_unlock_tables( + spider_string *str + ); + uint get_lock_table_hash_count(); + void reset_lock_table_hash(); + uint get_opened_handler_count(); + void reset_opened_handler(); + void set_dup_key_idx( + ha_spider *spider, + int link_idx + ); + int append_request_key( + st_spider_db_request_key *request_key + ); + void reset_request_key_req(); + void reset_request_key_snd(); + void move_request_key_to_snd(); + int check_request_key( + st_spider_db_request_key *request_key + ); + bool cmp_request_key_to_snd( + st_spider_db_request_key *request_key + ); +}; + +class spider_handlersocket_share: public spider_db_share +{ +public: + spider_string *table_names_str; + spider_string *db_names_str; + spider_string *db_table_str; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type *db_table_str_hash_value; +#endif + uint table_nm_max_length; + uint db_nm_max_length; + spider_string *column_name_str; + bool same_db_table_name; + int first_all_link_idx; + spider_handlersocket_share( + st_spider_share *share + ); + ~spider_handlersocket_share(); + int init(); + int append_table_name( + spider_string *str, + int all_link_idx + ); + int create_table_names_str(); + void free_table_names_str(); + int create_column_name_str(); + void free_column_name_str(); + uint get_column_name_length( + uint field_index + ); + int append_column_name( + spider_string *str, + uint field_index + ); + int append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length + ); + bool need_change_db_table_name(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ); +#endif +}; + +class spider_handlersocket_handler: public spider_db_handler +{ + spider_string hs_sql; +public: + bool hs_adding_keys; + SPIDER_DB_HS_STRING_REF_BUFFER hs_keys; + SPIDER_DB_HS_STRING_REF_BUFFER hs_upds; + SPIDER_DB_HS_STR_BUFFER hs_strs; + uint hs_strs_pos; + int hs_limit; + int hs_skip; + spider_handlersocket_share *handlersocket_share; + SPIDER_LINK_FOR_HASH *link_for_hash; + spider_handlersocket_handler( + ha_spider *spider, + spider_handlersocket_share *db_share + ); + ~spider_handlersocket_handler(); + int init(); + int append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type + ); + int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_tmp_table_and_sql_for_bka(); + int append_insert_for_recovery( + ulong sql_type, + int link_idx + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_insert_part(); + int append_update_part(); + int append_delete_part(); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_increment_update_set_part(); +#endif + int append_update_set_part(); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_direct_update_set_part(); +#endif + int append_minimum_select_without_quote( + spider_string *str + ); +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_minimum_select_by_field_idx_list( + spider_string *str, + uint32 *field_idxs, + size_t field_idxs_num + ); + int append_dup_update_pushdown_part( + const char *alias, + uint alias_length + ); + int append_update_columns_part( + const char *alias, + uint alias_length + ); + int check_update_columns_part(); + int append_select_part( + ulong sql_type + ); +#endif + int append_table_select_part( + ulong sql_type + ); + int append_key_select_part( + ulong sql_type, + uint idx + ); + int append_minimum_select_part( + ulong sql_type + ); + int append_hint_after_table_part( + ulong sql_type + ); + void set_where_pos( + ulong sql_type + ); + void set_where_to_pos( + ulong sql_type + ); + int check_item_type( + Item *item + ); + int append_values_connector_part( + ulong sql_type + ); + int append_values_terminator_part( + ulong sql_type + ); + int append_key_column_values_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ); + int append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order + ); + int append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count + ); + int append_match_where_part( + ulong sql_type + ); + int append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg + ); + int append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + void set_order_pos( + ulong sql_type + ); + void set_order_to_pos( + ulong sql_type + ); + int append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int append_select_lock_part( + ulong sql_type + ); + int append_union_all_start_part( + ulong sql_type + ); + int append_union_all_part( + ulong sql_type + ); + int append_union_all_end_part( + ulong sql_type + ); + int append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma + ); + int append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_close_handler_part( + ulong sql_type, + int link_idx + ); + int append_insert_terminator_part( + ulong sql_type + ); + int append_insert_values_part( + ulong sql_type + ); + int append_insert_values( + spider_string *str + ); + int append_into_part( + ulong sql_type + ); + void set_insert_to_pos( + ulong sql_type + ); + int append_from_part( + ulong sql_type, + int link_idx + ); + int append_delete_all_rows_part( + ulong sql_type + ); + int append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ); + bool is_bulk_insert_exec_period( + bool bulk_end + ); + bool sql_is_filled_up( + ulong sql_type + ); + bool sql_is_empty( + ulong sql_type + ); + bool support_multi_split_read(); + bool support_bulk_update(); + int bulk_tmp_table_insert(); + int bulk_tmp_table_insert( + int link_idx + ); + int bulk_tmp_table_end_bulk_insert(); + int bulk_tmp_table_rnd_init(); + int bulk_tmp_table_rnd_next(); + int bulk_tmp_table_rnd_end(); + bool need_copy_for_update( + int link_idx + ); + bool bulk_tmp_table_created(); + int mk_bulk_tmp_table_and_bulk_start(); + void rm_bulk_tmp_table(); + int insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx + ); + int append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended + ); + int realloc_sql( + ulong *realloced + ); + int reset_sql( + ulong sql_type + ); + int reset_keys( + ulong sql_type + ); + int reset_upds( + ulong sql_type + ); + int reset_strs( + ulong sql_type + ); + int reset_strs_pos( + ulong sql_type + ); + int push_back_upds( + SPIDER_HS_STRING_REF &info + ); + int request_buf_find( + int link_idx + ); + int request_buf_insert( + int link_idx + ); + int request_buf_update( + int link_idx + ); + int request_buf_delete( + int link_idx + ); + bool need_lock_before_set_sql_for_exec( + ulong sql_type + ); + int set_sql_for_exec( + ulong sql_type, + int link_idx + ); + int set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type + ); + int execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ); + int reset(); + int sts_mode_exchange( + int sts_mode + ); + int show_table_status( + int link_idx, + int sts_mode, + uint flag + ); + int crd_mode_exchange( + int crd_mode + ); + int show_index( + int link_idx, + int crd_mode + ); + int show_records( + int link_idx + ); + int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ); + ha_rows explain_select( + key_range *start_key, + key_range *end_key, + int link_idx + ); + int lock_tables( + int link_idx + ); + int unlock_tables( + int link_idx + ); + int disable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int enable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int analyze_table( + SPIDER_CONN *conn, + int link_idx + ); + int optimize_table( + SPIDER_CONN *conn, + int link_idx + ); + int flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock + ); + int flush_logs( + SPIDER_CONN *conn, + int link_idx + ); + int insert_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int delete_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int sync_from_clone_source( + spider_db_handler *dbton_hdl + ); + bool support_use_handler( + int use_handler + ); +}; diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h new file mode 100644 index 00000000000..e2b3a2c95fe --- /dev/null +++ b/storage/spider/spd_db_include.h @@ -0,0 +1,1579 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 "hs_compat.h" +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#include "hstcpcli.hpp" +#endif + +#define SPIDER_DB_WRAPPER_MYSQL "mysql" + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 +#define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +#define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE +#define SPIDER_HAS_SHOW_SIMPLE_FUNC +#endif +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100003 +#define SPIDER_GENERATE_PARTITION_SYNTAX_HAS_CURRENT_COMMENT_START +#endif + +class spider_db_conn; +typedef spider_db_conn SPIDER_DB_CONN; +class spider_db_result; +typedef spider_db_result SPIDER_DB_RESULT; +class spider_db_row; +typedef spider_db_row SPIDER_DB_ROW; +class spider_db_result_buffer; +typedef spider_db_result_buffer SPIDER_DB_RESULT_BUFFER; +struct st_spider_conn; +typedef st_spider_conn SPIDER_CONN; +struct st_spider_result; +typedef st_spider_result SPIDER_RESULT; + +#define SPIDER_SQL_SEMICOLON_STR ";" +#define SPIDER_SQL_SEMICOLON_LEN sizeof(SPIDER_SQL_SEMICOLON_STR) - 1 +#define SPIDER_SQL_VALUE_QUOTE_STR "'" +#define SPIDER_SQL_VALUE_QUOTE_LEN (sizeof(SPIDER_SQL_VALUE_QUOTE_STR) - 1) + +#define SPIDER_SQL_DOT_STR "." +#define SPIDER_SQL_DOT_LEN (sizeof(SPIDER_SQL_DOT_STR) - 1) + +#define SPIDER_SQL_EQUAL_STR " = " +#define SPIDER_SQL_EQUAL_LEN (sizeof(SPIDER_SQL_EQUAL_STR) - 1) +#define SPIDER_SQL_AND_STR " and " +#define SPIDER_SQL_AND_LEN (sizeof(SPIDER_SQL_AND_STR) - 1) +#define SPIDER_SQL_BETWEEN_STR " between " +#define SPIDER_SQL_BETWEEN_LEN (sizeof(SPIDER_SQL_BETWEEN_STR) - 1) + +#define SPIDER_SQL_TABLE_NAME_STR "`table_name`" +#define SPIDER_SQL_TABLE_NAME_LEN sizeof(SPIDER_SQL_TABLE_NAME_STR) - 1 + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#define SPIDER_SQL_HS_EQUAL_STR "=" +#define SPIDER_SQL_HS_EQUAL_LEN (sizeof(SPIDER_SQL_HS_EQUAL_STR) - 1) +#define SPIDER_SQL_HS_GT_STR ">" +#define SPIDER_SQL_HS_GT_LEN (sizeof(SPIDER_SQL_HS_GT_STR) - 1) +#define SPIDER_SQL_HS_GTEQUAL_STR ">=" +#define SPIDER_SQL_HS_GTEQUAL_LEN (sizeof(SPIDER_SQL_HS_GTEQUAL_STR) - 1) +#define SPIDER_SQL_HS_LT_STR "<" +#define SPIDER_SQL_HS_LT_LEN (sizeof(SPIDER_SQL_HS_LT_STR) - 1) +#define SPIDER_SQL_HS_INSERT_STR "+" +#define SPIDER_SQL_HS_INSERT_LEN (sizeof(SPIDER_SQL_HS_INSERT_STR) - 1) +#define SPIDER_SQL_HS_UPDATE_STR "U" +#define SPIDER_SQL_HS_UPDATE_LEN (sizeof(SPIDER_SQL_HS_UPDATE_STR) - 1) +#define SPIDER_SQL_HS_DELETE_STR "D" +#define SPIDER_SQL_HS_DELETE_LEN (sizeof(SPIDER_SQL_HS_DELETE_STR) - 1) +#define SPIDER_SQL_HS_INCREMENT_STR "+" +#define SPIDER_SQL_HS_INCREMENT_LEN (sizeof(SPIDER_SQL_HS_INCREMENT_STR) - 1) +#define SPIDER_SQL_HS_DECREMENT_STR "-" +#define SPIDER_SQL_HS_DECREMENT_LEN (sizeof(SPIDER_SQL_HS_DECREMENT_STR) - 1) +#endif +#define SPIDER_SQL_HS_LTEQUAL_STR "<=" +#define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1) + +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC +#define SPIDER_SQL_CASE_STR "case " +#define SPIDER_SQL_CASE_LEN (sizeof(SPIDER_SQL_CASE_STR) - 1) +#define SPIDER_SQL_WHEN_STR " when " +#define SPIDER_SQL_WHEN_LEN (sizeof(SPIDER_SQL_WHEN_STR) - 1) +#define SPIDER_SQL_THEN_STR " then " +#define SPIDER_SQL_THEN_LEN (sizeof(SPIDER_SQL_THEN_STR) - 1) +#define SPIDER_SQL_ELSE_STR " else " +#define SPIDER_SQL_ELSE_LEN (sizeof(SPIDER_SQL_ELSE_STR) - 1) +#define SPIDER_SQL_END_STR " end" +#define SPIDER_SQL_END_LEN (sizeof(SPIDER_SQL_END_STR) - 1) +#endif + +#define SPIDER_SQL_USING_STR " using " +#define SPIDER_SQL_USING_LEN (sizeof(SPIDER_SQL_USING_STR) - 1) +#define SPIDER_SQL_MBR_STR "mbr" +#define SPIDER_SQL_MBR_LEN (sizeof(SPIDER_SQL_MBR_STR) - 1) +#define SPIDER_SQL_MBR_EQUAL_STR "mbrequal(" +#define SPIDER_SQL_MBR_EQUAL_LEN (sizeof(SPIDER_SQL_MBR_EQUAL_STR) - 1) +#define SPIDER_SQL_MBR_CONTAIN_STR "mbrcontains(" +#define SPIDER_SQL_MBR_CONTAIN_LEN (sizeof(SPIDER_SQL_MBR_CONTAIN_STR) - 1) +#define SPIDER_SQL_MBR_INTERSECT_STR "mbrintersects(" +#define SPIDER_SQL_MBR_INTERSECT_LEN (sizeof(SPIDER_SQL_MBR_INTERSECT_STR) - 1) +#define SPIDER_SQL_MBR_WITHIN_STR "mbrwithin(" +#define SPIDER_SQL_MBR_WITHIN_LEN (sizeof(SPIDER_SQL_MBR_WITHIN_STR) - 1) +#define SPIDER_SQL_MBR_DISJOINT_STR "mbrdisjoint(" +#define SPIDER_SQL_MBR_DISJOINT_LEN (sizeof(SPIDER_SQL_MBR_DISJOINT_STR) - 1) +#define SPIDER_SQL_NOT_BETWEEN_STR "not between" +#define SPIDER_SQL_NOT_BETWEEN_LEN (sizeof(SPIDER_SQL_NOT_BETWEEN_STR) - 1) +#define SPIDER_SQL_IN_STR "in(" +#define SPIDER_SQL_IN_LEN (sizeof(SPIDER_SQL_IN_STR) - 1) +#define SPIDER_SQL_NOT_IN_STR "not in(" +#define SPIDER_SQL_NOT_IN_LEN (sizeof(SPIDER_SQL_NOT_IN_STR) - 1) +#define SPIDER_SQL_AS_CHAR_STR " as char" +#define SPIDER_SQL_AS_CHAR_LEN (sizeof(SPIDER_SQL_AS_CHAR_STR) - 1) +#define SPIDER_SQL_CAST_STR "cast(" +#define SPIDER_SQL_CAST_LEN (sizeof(SPIDER_SQL_CAST_STR) - 1) +#define SPIDER_SQL_AS_DATETIME_STR " as datetime" +#define SPIDER_SQL_AS_DATETIME_LEN (sizeof(SPIDER_SQL_AS_DATETIME_STR) - 1) +#define SPIDER_SQL_AS_DECIMAL_STR " as decimal" +#define SPIDER_SQL_AS_DECIMAL_LEN (sizeof(SPIDER_SQL_AS_DECIMAL_STR) - 1) +#define SPIDER_SQL_AS_SIGNED_STR " as signed" +#define SPIDER_SQL_AS_SIGNED_LEN (sizeof(SPIDER_SQL_AS_SIGNED_STR) - 1) +#define SPIDER_SQL_AS_UNSIGNED_STR " as unsigned" +#define SPIDER_SQL_AS_UNSIGNED_LEN (sizeof(SPIDER_SQL_AS_UNSIGNED_STR) - 1) +#define SPIDER_SQL_AS_DATE_STR " as date" +#define SPIDER_SQL_AS_DATE_LEN (sizeof(SPIDER_SQL_AS_DATE_STR) - 1) +#define SPIDER_SQL_AS_TIME_STR " as time" +#define SPIDER_SQL_AS_TIME_LEN (sizeof(SPIDER_SQL_AS_TIME_STR) - 1) +#define SPIDER_SQL_AS_BINARY_STR " as binary" +#define SPIDER_SQL_AS_BINARY_LEN (sizeof(SPIDER_SQL_AS_BINARY_STR) - 1) +#define SPIDER_SQL_IS_TRUE_STR " is true" +#define SPIDER_SQL_IS_TRUE_LEN (sizeof(SPIDER_SQL_IS_TRUE_STR) - 1) +#define SPIDER_SQL_IS_NOT_TRUE_STR " is not true" +#define SPIDER_SQL_IS_NOT_TRUE_LEN (sizeof(SPIDER_SQL_IS_NOT_TRUE_STR) - 1) +#define SPIDER_SQL_IS_FALSE_STR " is false" +#define SPIDER_SQL_IS_FALSE_LEN (sizeof(SPIDER_SQL_IS_FALSE_STR) - 1) +#define SPIDER_SQL_IS_NOT_FALSE_STR " is not false" +#define SPIDER_SQL_IS_NOT_FALSE_LEN (sizeof(SPIDER_SQL_IS_NOT_FALSE_STR) - 1) +#define SPIDER_SQL_NULL_CHAR_STR "" +#define SPIDER_SQL_NULL_CHAR_LEN (sizeof(SPIDER_SQL_NULL_CHAR_STR) - 1) +#define SPIDER_SQL_CREATE_TABLE_STR "create table " +#define SPIDER_SQL_CREATE_TABLE_LEN (sizeof(SPIDER_SQL_CREATE_TABLE_STR) - 1) +#define SPIDER_SQL_DEFAULT_CHARSET_STR " default charset " +#define SPIDER_SQL_DEFAULT_CHARSET_LEN (sizeof(SPIDER_SQL_DEFAULT_CHARSET_STR) - 1) +#define SPIDER_SQL_COLLATE_STR " collate " +#define SPIDER_SQL_COLLATE_LEN (sizeof(SPIDER_SQL_COLLATE_STR) - 1) +#define SPIDER_SQL_COMMENT_STR " comment " +#define SPIDER_SQL_COMMENT_LEN (sizeof(SPIDER_SQL_COMMENT_STR) - 1) +#define SPIDER_SQL_CONNECTION_STR " connection " +#define SPIDER_SQL_CONNECTION_LEN (sizeof(SPIDER_SQL_CONNECTION_STR) - 1) +#define SPIDER_SQL_LCL_NAME_QUOTE_STR "`" +#define SPIDER_SQL_LCL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_LCL_NAME_QUOTE_STR) - 1) + +#define SPIDER_CONN_KIND_MYSQL (1 << 0) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#define SPIDER_CONN_KIND_HS_READ (1 << 2) +#define SPIDER_CONN_KIND_HS_WRITE (1 << 3) +#endif + +#define SPIDER_SQL_KIND_SQL (1 << 0) +#define SPIDER_SQL_KIND_HANDLER (1 << 1) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#define SPIDER_SQL_KIND_HS (1 << 2) +#endif + +#define SPIDER_SQL_TYPE_SELECT_SQL (1 << 0) +#define SPIDER_SQL_TYPE_INSERT_SQL (1 << 1) +#define SPIDER_SQL_TYPE_UPDATE_SQL (1 << 2) +#define SPIDER_SQL_TYPE_DELETE_SQL (1 << 3) +#define SPIDER_SQL_TYPE_BULK_UPDATE_SQL (1 << 4) +#define SPIDER_SQL_TYPE_TMP_SQL (1 << 5) +#define SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL (1 << 6) +#define SPIDER_SQL_TYPE_OTHER_SQL (1 << 7) +#define SPIDER_SQL_TYPE_HANDLER (1 << 8) +#define SPIDER_SQL_TYPE_SELECT_HS (1 << 9) +#define SPIDER_SQL_TYPE_INSERT_HS (1 << 10) +#define SPIDER_SQL_TYPE_UPDATE_HS (1 << 11) +#define SPIDER_SQL_TYPE_DELETE_HS (1 << 12) +#define SPIDER_SQL_TYPE_OTHER_HS (1 << 13) + +enum spider_bulk_upd_start { + SPD_BU_NOT_START, + SPD_BU_START_BY_INDEX_OR_RND_INIT, + SPD_BU_START_BY_BULK_INIT +}; + +struct st_spider_ft_info; +struct st_spider_result; +typedef struct st_spider_transaction SPIDER_TRX; +typedef struct st_spider_share SPIDER_SHARE; +class ha_spider; +class spider_db_copy_table; + +class spider_string +{ +public: + bool mem_calc_inited; + String str; + uint id; + const char *func_name; + const char *file_name; + ulong line_no; + uint32 current_alloc_mem; + spider_string *next; + + spider_string(); + spider_string( + uint32 length_arg + ); + spider_string( + const char *str, + CHARSET_INFO *cs + ); + spider_string( + const char *str, + uint32 len, + CHARSET_INFO *cs + ); + spider_string( + char *str, + uint32 len, + CHARSET_INFO *cs + ); + spider_string( + const String &str + ); + ~spider_string(); + void init_mem_calc( + uint id, + const char *func_name, + const char *file_name, + ulong line_no + ); + void mem_calc(); + String *get_str(); + void set_charset( + CHARSET_INFO *charset_arg + ); + CHARSET_INFO *charset() const; + uint32 length() const; + uint32 alloced_length() const; + char &operator [] ( + uint32 i + ) const; + void length( + uint32 len + ); + bool is_empty() const; + const char *ptr() const; + char *c_ptr(); + char *c_ptr_quick(); + char *c_ptr_safe(); + LEX_STRING lex_string() const; + void set( + String &str, + uint32 offset, + uint32 arg_length + ); + void set( + char *str, + uint32 arg_length, + CHARSET_INFO *cs + ); + void set( + const char *str, + uint32 arg_length, + CHARSET_INFO *cs + ); + bool set_ascii( + const char *str, + uint32 arg_length + ); + void set_quick( + char *str, + uint32 arg_length, + CHARSET_INFO *cs + ); + bool set_int( + longlong num, + bool unsigned_flag, + CHARSET_INFO *cs + ); + bool set( + longlong num, + CHARSET_INFO *cs + ); + bool set( + ulonglong num, + CHARSET_INFO *cs + ); + bool set_real( + double num, + uint decimals, + CHARSET_INFO *cs + ); + void chop(); + void free(); + bool alloc( + uint32 arg_length + ); + bool real_alloc( + uint32 arg_length + ); + bool realloc( + uint32 arg_length + ); + void shrink( + uint32 arg_length + ); + bool is_alloced(); + spider_string& operator = ( + const String &s + ); + bool copy(); + bool copy( + const spider_string &s + ); + bool copy( + const String &s + ); + bool copy( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs + ); + bool needs_conversion( + uint32 arg_length, + CHARSET_INFO *cs_from, + CHARSET_INFO *cs_to, + uint32 *offset + ); + bool copy_aligned( + const char *s, + uint32 arg_length, + uint32 offset, + CHARSET_INFO *cs + ); + bool set_or_copy_aligned( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs + ); + bool copy( + const char *s, + uint32 arg_length, + CHARSET_INFO *csfrom, + CHARSET_INFO *csto, + uint *errors + ); + bool append( + const spider_string &s + ); + bool append( + const String &s + ); + bool append( + const char *s + ); + bool append( + LEX_STRING *ls + ); + bool append( + const char *s, + uint32 arg_length + ); + bool append( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs + ); + bool append_ulonglong( + ulonglong val + ); + bool append( + IO_CACHE *file, + uint32 arg_length + ); + bool append_with_prefill( + const char *s, + uint32 arg_length, + uint32 full_length, + char fill_char + ); + int strstr( + const String &search, + uint32 offset = 0 + ); + int strrstr( + const String &search, + uint32 offset = 0 + ); + bool replace( + uint32 offset, + uint32 arg_length, + const char *to, + uint32 length + ); + bool replace( + uint32 offset, + uint32 arg_length, + const String &to + ); + inline bool append( + char chr + ); + bool fill( + uint32 max_length, + char fill + ); + void strip_sp(); + uint32 numchars(); + int charpos( + int i, + uint32 offset=0 + ); + int reserve( + uint32 space_needed + ); + int reserve( + uint32 space_needed, + uint32 grow_by + ); + void q_append( + const char c + ); + void q_append( + const uint32 n + ); + void q_append( + double d + ); + void q_append( + double *d + ); + void q_append( + const char *data, + uint32 data_len + ); + void write_at_position( + int position, + uint32 value + ); + void qs_append( + const char *str, + uint32 len + ); + void qs_append( + double d + ); + void qs_append( + double *d + ); + void qs_append( + const char c + ); + void qs_append( + int i + ); + void qs_append( + uint i + ); + char *prep_append( + uint32 arg_length, + uint32 step_alloc + ); + bool append( + const char *s, + uint32 arg_length, + uint32 step_alloc + ); +#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE + bool append_for_single_quote( + const char *st, + uint len + ); +#endif + void print( + String *print + ); + void swap( + spider_string &s + ); + bool uses_buffer_owned_by( + const String *s + ) const; + bool is_ascii() const; +}; + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#define SPIDER_HS_UINT32_INFO dena::uint32_info +#define SPIDER_HS_STRING_REF dena::string_ref +#ifndef HANDLERSOCKET_MYSQL_UTIL +#define SPIDER_HS_VECTOR std::vector +class spider_db_hs_string_ref_buffer +{ + SPIDER_HS_VECTOR hs_conds; +public: + spider_db_hs_string_ref_buffer(); + ~spider_db_hs_string_ref_buffer(); + int init(); + void clear(); + int push_back( + SPIDER_HS_STRING_REF &cond + ); + SPIDER_HS_STRING_REF *ptr(); + uint size(); +}; +#else +class spider_db_hs_string_ref_buffer +{ + bool hs_da_init; + DYNAMIC_ARRAY hs_conds; + uint hs_conds_id; + const char *hs_conds_func_name; + const char *hs_conds_file_name; + ulong hs_conds_line_no; +public: + spider_db_hs_string_ref_buffer(); + ~spider_db_hs_string_ref_buffer(); + int init(); + void clear(); + int push_back( + SPIDER_HS_STRING_REF &cond + ); + SPIDER_HS_STRING_REF *ptr(); + uint size(); +}; +#endif + +class spider_db_hs_str_buffer +{ + bool hs_da_init; + DYNAMIC_ARRAY hs_conds; + uint hs_conds_id; + const char *hs_conds_func_name; + const char *hs_conds_file_name; + ulong hs_conds_line_no; +public: + spider_db_hs_str_buffer(); + ~spider_db_hs_str_buffer(); + int init(); + void clear(); + spider_string *add( + uint *strs_pos, + const char *str, + uint str_len + ); +}; + +#define SPIDER_DB_HS_STRING_REF_BUFFER spider_db_hs_string_ref_buffer +#define SPIDER_DB_HS_STR_BUFFER spider_db_hs_str_buffer +#endif + +struct st_spider_db_request_key +{ + ulonglong spider_thread_id; + query_id_t query_id; + void *handler; + ulonglong request_id; + st_spider_db_request_key *next; +}; + +class spider_db_util +{ +public: + spider_db_util() {} + virtual ~spider_db_util() {} + virtual int append_name( + spider_string *str, + const char *name, + uint name_length + ) = 0; + virtual int append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ) = 0; + virtual bool is_name_quote( + const char head_code + ) = 0; + virtual int append_escaped_name_quote( + spider_string *str + ) = 0; + virtual int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset + ) = 0; + virtual int append_trx_isolation( + spider_string *str, + int trx_isolation + ) = 0; + virtual int append_autocommit( + spider_string *str, + bool autocommit + ) = 0; + virtual int append_sql_log_off( + spider_string *str, + bool sql_log_off + ) = 0; + virtual int append_time_zone( + spider_string *str, + Time_zone *time_zone + ) = 0; + virtual int append_start_transaction( + spider_string *str + ) = 0; + virtual int append_xa_start( + spider_string *str, + XID *xid + ) = 0; + virtual int append_lock_table_head( + spider_string *str + ) = 0; + virtual int append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type + ) = 0; + virtual int append_lock_table_tail( + spider_string *str + ) = 0; + virtual int append_unlock_table( + spider_string *str + ) = 0; + virtual int open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length + ) = 0; + virtual int append_escaped_util( + spider_string *to, + String *from + ) = 0; +}; + +class spider_db_row +{ +public: + SPIDER_DB_ROW *next_pos; + spider_db_row() : next_pos(NULL) {} + virtual ~spider_db_row() {} + virtual int store_to_field( + Field *field, + CHARSET_INFO *access_charset + ) = 0; + virtual int append_to_str( + spider_string *str + ) = 0; + virtual int append_escaped_to_str( + spider_string *str, + uint dbton_id + ) = 0; + virtual void first() = 0; + virtual void next() = 0; + virtual bool is_null() = 0; + virtual int val_int() = 0; + virtual double val_real() = 0; + virtual SPIDER_DB_ROW *clone() = 0; + virtual int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ) = 0; +}; + +class spider_db_result_buffer +{ +public: + spider_db_result_buffer() {} + virtual ~spider_db_result_buffer() {} + virtual void clear() = 0; + virtual bool check_size( + longlong size + ) = 0; +}; + +class spider_db_result +{ +public: + spider_db_result() {} + virtual ~spider_db_result() {} + virtual bool has_result() = 0; + virtual void free_result() = 0; + virtual SPIDER_DB_ROW *current_row() = 0; + virtual SPIDER_DB_ROW *fetch_row() = 0; + virtual SPIDER_DB_ROW *fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf + ) = 0; + virtual SPIDER_DB_ROW *fetch_row_from_tmp_table( + TABLE *tmp_table + ) = 0; + virtual int fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time + ) = 0; + virtual int fetch_table_records( + int mode, + ha_rows &records + ) = 0; + virtual int fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size + ) = 0; + virtual int fetch_table_mon_status( + int &status + ) = 0; + virtual longlong num_rows() = 0; + virtual uint num_fields() = 0; + virtual void move_to_pos( + longlong pos + ) = 0; + virtual int get_errno() = 0; +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + virtual int fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ) = 0; + virtual int fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ) = 0; +#endif +}; + +class spider_db_conn +{ +protected: + SPIDER_CONN *conn; +public: + spider_db_conn( + SPIDER_CONN *conn + ) : conn(conn) {} + virtual ~spider_db_conn() {} + virtual int init() = 0; + virtual bool is_connected() = 0; + virtual void bg_connect() = 0; + virtual int connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval + ) = 0; + virtual int ping() = 0; + virtual void bg_disconnect() = 0; + virtual void disconnect() = 0; + virtual int set_net_timeout() = 0; + virtual int exec_query( + const char *query, + uint length, + int quick_mode + ) = 0; + virtual int get_errno() = 0; + virtual const char *get_error() = 0; + virtual bool is_server_gone_error( + int error_num + ) = 0; + virtual bool is_dup_entry_error( + int error_num + ) = 0; + virtual bool is_xa_nota_error( + int error_num + ) = 0; + virtual spider_db_result *store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num + ) = 0; + virtual spider_db_result *use_result( + st_spider_db_request_key *request_key, + int *error_num + ) = 0; + virtual int next_result() = 0; + virtual uint affected_rows() = 0; + virtual ulonglong last_insert_id() = 0; + virtual int set_character_set( + const char *csname + ) = 0; + virtual int select_db( + const char *dbname + ) = 0; + virtual int consistent_snapshot( + int *need_mon + ) = 0; + virtual bool trx_start_in_bulk_sql() = 0; + virtual int start_transaction( + int *need_mon + ) = 0; + virtual int commit( + int *need_mon + ) = 0; + virtual int rollback( + int *need_mon + ) = 0; + virtual bool xa_start_in_bulk_sql() = 0; + virtual int xa_start( + XID *xid, + int *need_mon + ) = 0; + virtual int xa_end( + XID *xid, + int *need_mon + ) = 0; + virtual int xa_prepare( + XID *xid, + int *need_mon + ) = 0; + virtual int xa_commit( + XID *xid, + int *need_mon + ) = 0; + virtual int xa_rollback( + XID *xid, + int *need_mon + ) = 0; + virtual bool set_trx_isolation_in_bulk_sql() = 0; + virtual int set_trx_isolation( + int trx_isolation, + int *need_mon + ) = 0; + virtual bool set_autocommit_in_bulk_sql() = 0; + virtual int set_autocommit( + bool autocommit, + int *need_mon + ) = 0; + virtual bool set_sql_log_off_in_bulk_sql() = 0; + virtual int set_sql_log_off( + bool sql_log_off, + int *need_mon + ) = 0; + virtual bool set_time_zone_in_bulk_sql() = 0; + virtual int set_time_zone( + Time_zone *time_zone, + int *need_mon + ) = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + virtual int append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key + ) = 0; + virtual int append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key + ) = 0; + virtual int append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ) = 0; + virtual int append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key + ) = 0; + virtual int append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key + ) = 0; + virtual int append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ) = 0; + virtual void reset_request_queue() = 0; +#endif + virtual size_t escape_string( + char *to, + const char *from, + size_t from_length + ) = 0; + virtual bool have_lock_table_list() = 0; + virtual int append_lock_tables( + spider_string *str + ) = 0; + virtual int append_unlock_tables( + spider_string *str + ) = 0; + virtual uint get_lock_table_hash_count() = 0; + virtual void reset_lock_table_hash() = 0; + virtual uint get_opened_handler_count() = 0; + virtual void reset_opened_handler() = 0; + virtual void set_dup_key_idx( + ha_spider *spider, + int link_idx + ) = 0; + virtual bool cmp_request_key_to_snd( + st_spider_db_request_key *request_key + ) = 0; +}; + +class spider_db_share +{ +protected: + uint mem_calc_id; + const char *mem_calc_func_name; + const char *mem_calc_file_name; + ulong mem_calc_line_no; +public: + st_spider_share *spider_share; + spider_db_share(st_spider_share *share) : spider_share(share) {} + virtual ~spider_db_share() {} + virtual int init() = 0; + virtual uint get_column_name_length( + uint field_index + ) = 0; + virtual int append_column_name( + spider_string *str, + uint field_index + ) = 0; + virtual int append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length + ) = 0; + virtual bool need_change_db_table_name() = 0; +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + virtual int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ) = 0; +#endif +}; + +class spider_db_handler +{ +protected: + uint mem_calc_id; + const char *mem_calc_func_name; + const char *mem_calc_file_name; + ulong mem_calc_line_no; +public: + ha_spider *spider; + spider_db_share *db_share; + int first_link_idx; + spider_db_handler(ha_spider *spider, spider_db_share *db_share) : + spider(spider), db_share(db_share), first_link_idx(-1) {} + virtual ~spider_db_handler() {} + virtual int init() = 0; + virtual int append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type + ) = 0; + virtual int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ) = 0; + virtual int reuse_tmp_table_and_sql_for_bka() = 0; + virtual int append_insert_for_recovery( + ulong sql_type, + int link_idx + ) = 0; + virtual int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff + ) = 0; + virtual int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ) = 0; + virtual int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff + ) = 0; + virtual int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ) = 0; + virtual int append_insert_part() = 0; + virtual int append_update_part() = 0; + virtual int append_delete_part() = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + virtual int append_increment_update_set_part() = 0; +#endif +#endif + virtual int append_update_set_part() = 0; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + virtual int append_direct_update_set_part() = 0; + virtual int append_dup_update_pushdown_part( + const char *alias, + uint alias_length + ) = 0; + virtual int append_update_columns_part( + const char *alias, + uint alias_length + ) = 0; + virtual int check_update_columns_part() = 0; +#endif + virtual int append_select_part( + ulong sql_type + ) = 0; + virtual int append_table_select_part( + ulong sql_type + ) = 0; + virtual int append_key_select_part( + ulong sql_type, + uint idx + ) = 0; + virtual int append_minimum_select_part( + ulong sql_type + ) = 0; + virtual int append_hint_after_table_part( + ulong sql_type + ) = 0; + virtual void set_where_pos( + ulong sql_type + ) = 0; + virtual void set_where_to_pos( + ulong sql_type + ) = 0; + virtual int check_item_type( + Item *item + ) = 0; + virtual int append_values_connector_part( + ulong sql_type + ) = 0; + virtual int append_values_terminator_part( + ulong sql_type + ) = 0; + virtual int append_key_column_values_part( + const key_range *start_key, + ulong sql_type + ) = 0; + virtual int append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ) = 0; + virtual int append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ) = 0; + virtual int append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count + ) = 0; + virtual int append_match_where_part( + ulong sql_type + ) = 0; + virtual int append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg + ) = 0; + virtual int append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length + ) = 0; + virtual void set_order_pos( + ulong sql_type + ) = 0; + virtual void set_order_to_pos( + ulong sql_type + ) = 0; + virtual int append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ) = 0; + virtual int append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ) = 0; + virtual int append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ) = 0; + virtual int append_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ) = 0; + virtual int reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ) = 0; + virtual int append_select_lock_part( + ulong sql_type + ) = 0; + virtual int append_union_all_start_part( + ulong sql_type + ) = 0; + virtual int append_union_all_part( + ulong sql_type + ) = 0; + virtual int append_union_all_end_part( + ulong sql_type + ) = 0; + virtual int append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma + ) = 0; + virtual int append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int append_close_handler_part( + ulong sql_type, + int link_idx + ) = 0; + virtual int append_insert_terminator_part( + ulong sql_type + ) = 0; + virtual int append_insert_values_part( + ulong sql_type + ) = 0; + virtual int append_into_part( + ulong sql_type + ) = 0; + virtual void set_insert_to_pos( + ulong sql_type + ) = 0; + virtual int append_from_part( + ulong sql_type, + int link_idx + ) = 0; + virtual int append_delete_all_rows_part( + ulong sql_type + ) = 0; + virtual int append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ) = 0; + virtual bool is_bulk_insert_exec_period( + bool bulk_end + ) = 0; + virtual bool sql_is_filled_up( + ulong sql_type + ) = 0; + virtual bool sql_is_empty( + ulong sql_type + ) = 0; + virtual bool support_multi_split_read() = 0; + virtual bool support_bulk_update() = 0; + virtual int bulk_tmp_table_insert() = 0; + virtual int bulk_tmp_table_insert( + int link_idx + ) = 0; + virtual int bulk_tmp_table_end_bulk_insert() = 0; + virtual int bulk_tmp_table_rnd_init() = 0; + virtual int bulk_tmp_table_rnd_next() = 0; + virtual int bulk_tmp_table_rnd_end() = 0; + virtual bool need_copy_for_update( + int link_idx + ) = 0; + virtual bool bulk_tmp_table_created() = 0; + virtual int mk_bulk_tmp_table_and_bulk_start() = 0; + virtual void rm_bulk_tmp_table() = 0; + virtual int insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended + ) = 0; + virtual int realloc_sql( + ulong *realloced + ) = 0; + virtual int reset_sql( + ulong sql_type + ) = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + virtual int reset_keys( + ulong sql_type + ) = 0; + virtual int reset_upds( + ulong sql_type + ) = 0; + virtual int reset_strs( + ulong sql_type + ) = 0; + virtual int reset_strs_pos( + ulong sql_type + ) = 0; + virtual int push_back_upds( + SPIDER_HS_STRING_REF &info + ) = 0; +#endif + virtual bool need_lock_before_set_sql_for_exec( + ulong sql_type + ) = 0; + virtual int set_sql_for_exec( + ulong sql_type, + int link_idx + ) = 0; + virtual int set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type + ) = 0; + virtual int execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ) = 0; + virtual int reset() = 0; + virtual int sts_mode_exchange( + int sts_mode + ) = 0; + virtual int show_table_status( + int link_idx, + int sts_mode, + uint flag + ) = 0; + virtual int crd_mode_exchange( + int crd_mode + ) = 0; + virtual int show_index( + int link_idx, + int crd_mode + ) = 0; + virtual int show_records( + int link_idx + ) = 0; + virtual int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ) = 0; + virtual ha_rows explain_select( + key_range *start_key, + key_range *end_key, + int link_idx + ) = 0; + virtual int lock_tables( + int link_idx + ) = 0; + virtual int unlock_tables( + int link_idx + ) = 0; + virtual int disable_keys( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int enable_keys( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ) = 0; + virtual int repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ) = 0; + virtual int analyze_table( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int optimize_table( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock + ) = 0; + virtual int flush_logs( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int insert_opened_handler( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int delete_opened_handler( + SPIDER_CONN *conn, + int link_idx + ) = 0; + virtual int sync_from_clone_source( + spider_db_handler *dbton_hdl + ) = 0; + virtual bool support_use_handler( + int use_handler + ) = 0; +}; + +class spider_db_copy_table +{ +public: + spider_db_share *db_share; + spider_db_copy_table(spider_db_share *db_share) : + db_share(db_share) {} + virtual ~spider_db_copy_table() {} + virtual int init() = 0; + virtual void set_sql_charset( + CHARSET_INFO *cs + ) = 0; + virtual int append_select_str() = 0; + virtual int append_insert_str( + int insert_flg + ) = 0; + virtual int append_table_columns( + TABLE_SHARE *table_share + ) = 0; + virtual int append_from_str() = 0; + virtual int append_table_name( + int link_idx + ) = 0; + virtual void set_sql_pos() = 0; + virtual void set_sql_to_pos() = 0; + virtual int append_copy_where( + spider_db_copy_table *source_ct, + KEY *key_info, + ulong *last_row_pos, + ulong *last_lengths + ) = 0; + virtual int append_key_order_str( + KEY *key_info, + int start_pos, + bool desc_flg + ) = 0; + virtual int append_limit( + longlong offset, + longlong limit + ) = 0; + virtual int append_into_str() = 0; + virtual int append_open_paren_str() = 0; + virtual int append_values_str() = 0; + virtual int append_select_lock_str( + int lock_mode + ) = 0; + virtual int exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ) = 0; + virtual int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row, + ulong **last_row_pos, + ulong **last_lengths + ) = 0; + virtual int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row + ) = 0; + virtual int append_insert_terminator() = 0; + virtual int copy_insert_values( + spider_db_copy_table *source_ct + ) = 0; +}; + +enum spider_db_access_type +{ + SPIDER_DB_ACCESS_TYPE_SQL, + SPIDER_DB_ACCESS_TYPE_NOSQL +}; + +typedef struct st_spider_dbton +{ + uint dbton_id; + const char *wrapper; + enum spider_db_access_type db_access_type; + int (*init)(); + int (*deinit)(); + spider_db_share *(*create_db_share)(st_spider_share *share); + spider_db_handler *(*create_db_handler)(ha_spider *spider, + spider_db_share *db_share); + spider_db_copy_table *(*create_db_copy_table)( + spider_db_share *db_share); + SPIDER_DB_CONN *(*create_db_conn)(SPIDER_CONN *conn); + spider_db_util *db_util; +} SPIDER_DBTON; +#define SPIDER_DBTON_SIZE 15 + +typedef struct st_spider_position +{ + SPIDER_DB_ROW *row; + uint pos_mode; + bool use_position; + bool mrr_with_cnt; + uint sql_kind; + uchar *position_bitmap; + st_spider_ft_info *ft_first; + st_spider_ft_info *ft_current; + my_off_t tmp_tbl_pos; + SPIDER_RESULT *result; +} SPIDER_POSITION; + +typedef struct st_spider_condition +{ + COND *cond; + st_spider_condition *next; +} SPIDER_CONDITION; + +typedef struct st_spider_result +{ + SPIDER_DB_RESULT *result; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + st_spider_result *prev; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + st_spider_result *next; + SPIDER_POSITION *first_position; /* for quick mode */ + int pos_page_size; /* for quick mode */ + longlong record_num; + bool finish_flg; + bool use_position; + uint field_count; /* for quick mode */ + TABLE *result_tmp_tbl; + TMP_TABLE_PARAM result_tmp_tbl_prm; + THD *result_tmp_tbl_thd; + uint result_tmp_tbl_inited; + SPIDER_DB_ROW *tmp_tbl_row; +} SPIDER_RESULT; + +typedef struct st_spider_result_list +{ +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + SPIDER_RESULT *first; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + SPIDER_RESULT *last; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + SPIDER_RESULT *current; + KEY *key_info; + int key_order; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ulonglong hs_upd_rows; + SPIDER_DB_RESULT *hs_result; + SPIDER_DB_RESULT_BUFFER *hs_result_buf; + bool hs_has_result; + SPIDER_DB_CONN *hs_conn; +#endif +#ifdef HA_CAN_BULK_ACCESS +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uchar *hs_r_bulk_open_index; + uchar *hs_w_bulk_open_index; +#endif +#endif + spider_string *sqls; + int ha_read_kind; + bool have_sql_kind_backup; + uint *sql_kind_backup; + uint sql_kinds_backup; + bool use_union; + spider_string *insert_sqls; + spider_string *update_sqls; + TABLE **upd_tmp_tbls; + TMP_TABLE_PARAM *upd_tmp_tbl_prms; + bool tmp_table_join; + uchar *tmp_table_join_first; + bool tmp_tables_created; + uchar *tmp_table_created; + bool tmp_table_join_break_after_get_next; + key_part_map tmp_table_join_key_part_map; + spider_string *tmp_sqls; + bool tmp_reuse_sql; + bool sorted; + bool desc_flg; + longlong current_row_num; + longlong record_num; + bool finish_flg; + longlong limit_num; + longlong internal_offset; + longlong internal_limit; + longlong split_read; + int multi_split_read; + int max_order; + int quick_mode; + longlong quick_page_size; + int low_mem_read; + int bulk_update_mode; + int bulk_update_size; + spider_bulk_upd_start bulk_update_start; + bool check_direct_order_limit; + bool direct_order_limit; + bool set_split_read; + bool insert_dup_update_pushdown; + longlong split_read_base; + double semi_split_read; + longlong semi_split_read_limit; + longlong semi_split_read_base; + longlong first_read; + longlong second_read; + int set_split_read_count; +#ifndef WITHOUT_SPIDER_BG_SEARCH + /* 0:nomal 1:store 2:store end */ + volatile +#endif + int quick_phase; + bool keyread; + int lock_type; + TABLE *table; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile int bgs_error; + bool bgs_error_with_message; + char bgs_error_msg[MYSQL_ERRMSG_SIZE]; + volatile bool bgs_working; + /* 0:not use bg 1:first read 2:second read 3:after second read */ + volatile int bgs_phase; + volatile longlong bgs_first_read; + volatile longlong bgs_second_read; + volatile longlong bgs_split_read; + volatile +#endif + SPIDER_RESULT *bgs_current; + SPIDER_DB_ROW *tmp_pos_row_first; +} SPIDER_RESULT_LIST; diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc new file mode 100644 index 00000000000..48d127dac2f --- /dev/null +++ b/storage/spider/spd_db_mysql.cc @@ -0,0 +1,10845 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_analyse.h" +#include "sql_base.h" +#include "tztime.h" +#endif +#include "sql_common.h" +#include +#include +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_db_mysql.h" +#include "ha_spider.h" +#include "spd_conn.h" +#include "spd_db_conn.h" +#include "spd_malloc.h" +#include "spd_sys_table.h" +#include "spd_table.h" + +extern struct charset_info_st *spd_charset_utf8_bin; + +extern handlerton *spider_hton_ptr; +extern pthread_mutex_t spider_open_conn_mutex; +extern HASH spider_open_connections; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern const char spider_dig_upper[]; + +#define SPIDER_SQL_NAME_QUOTE_STR "`" +#define SPIDER_SQL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_NAME_QUOTE_STR) - 1) +static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; + +#define SPIDER_SQL_ISO_READ_UNCOMMITTED_STR "set session transaction isolation level read uncommitted" +#define SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN sizeof(SPIDER_SQL_ISO_READ_UNCOMMITTED_STR) - 1 +#define SPIDER_SQL_ISO_READ_COMMITTED_STR "set session transaction isolation level read committed" +#define SPIDER_SQL_ISO_READ_COMMITTED_LEN sizeof(SPIDER_SQL_ISO_READ_COMMITTED_STR) - 1 +#define SPIDER_SQL_ISO_REPEATABLE_READ_STR "set session transaction isolation level repeatable read" +#define SPIDER_SQL_ISO_REPEATABLE_READ_LEN sizeof(SPIDER_SQL_ISO_REPEATABLE_READ_STR) - 1 +#define SPIDER_SQL_ISO_SERIALIZABLE_STR "set session transaction isolation level serializable" +#define SPIDER_SQL_ISO_SERIALIZABLE_LEN sizeof(SPIDER_SQL_ISO_SERIALIZABLE_STR) - 1 + +#define SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR "start transaction with consistent snapshot" +#define SPIDER_SQL_START_CONSISTENT_SNAPSHOT_LEN sizeof(SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR) - 1 +#define SPIDER_SQL_START_TRANSACTION_STR "start transaction" +#define SPIDER_SQL_START_TRANSACTION_LEN sizeof(SPIDER_SQL_START_TRANSACTION_STR) - 1 + +#define SPIDER_SQL_AUTOCOMMIT_OFF_STR "set session autocommit = 0" +#define SPIDER_SQL_AUTOCOMMIT_OFF_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_OFF_STR) - 1 +#define SPIDER_SQL_AUTOCOMMIT_ON_STR "set session autocommit = 1" +#define SPIDER_SQL_AUTOCOMMIT_ON_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_ON_STR) - 1 + +#define SPIDER_SQL_SQL_LOG_OFF_STR "set session sql_log_off = 0" +#define SPIDER_SQL_SQL_LOG_OFF_LEN sizeof(SPIDER_SQL_SQL_LOG_OFF_STR) - 1 +#define SPIDER_SQL_SQL_LOG_ON_STR "set session sql_log_off = 1" +#define SPIDER_SQL_SQL_LOG_ON_LEN sizeof(SPIDER_SQL_SQL_LOG_ON_STR) - 1 + +#define SPIDER_SQL_TIME_ZONE_STR "set session time_zone = '" +#define SPIDER_SQL_TIME_ZONE_LEN sizeof(SPIDER_SQL_TIME_ZONE_STR) - 1 + +#define SPIDER_SQL_COMMIT_STR "commit" +#define SPIDER_SQL_COMMIT_LEN sizeof(SPIDER_SQL_COMMIT_STR) - 1 +#define SPIDER_SQL_ROLLBACK_STR "rollback" +#define SPIDER_SQL_ROLLBACK_LEN sizeof(SPIDER_SQL_ROLLBACK_STR) - 1 + +#define SPIDER_SQL_XA_START_STR "xa start " +#define SPIDER_SQL_XA_START_LEN sizeof(SPIDER_SQL_XA_START_STR) - 1 +#define SPIDER_SQL_XA_END_STR "xa end " +#define SPIDER_SQL_XA_END_LEN sizeof(SPIDER_SQL_XA_END_STR) - 1 +#define SPIDER_SQL_XA_PREPARE_STR "xa prepare " +#define SPIDER_SQL_XA_PREPARE_LEN sizeof(SPIDER_SQL_XA_PREPARE_STR) - 1 +#define SPIDER_SQL_XA_COMMIT_STR "xa commit " +#define SPIDER_SQL_XA_COMMIT_LEN sizeof(SPIDER_SQL_XA_COMMIT_STR) - 1 +#define SPIDER_SQL_XA_ROLLBACK_STR "xa rollback " +#define SPIDER_SQL_XA_ROLLBACK_LEN sizeof(SPIDER_SQL_XA_ROLLBACK_STR) - 1 + +#define SPIDER_SQL_LOCK_TABLE_STR "lock tables " +#define SPIDER_SQL_LOCK_TABLE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_STR) - 1) +#define SPIDER_SQL_UNLOCK_TABLE_STR "unlock tables" +#define SPIDER_SQL_UNLOCK_TABLE_LEN (sizeof(SPIDER_SQL_UNLOCK_TABLE_STR) - 1) + +#define SPIDER_SQL_SHOW_TABLE_STATUS_STR "show table status from " +#define SPIDER_SQL_SHOW_TABLE_STATUS_LEN sizeof(SPIDER_SQL_SHOW_TABLE_STATUS_STR) - 1 +#define SPIDER_SQL_SELECT_TABLES_STATUS_STR "select `table_rows`,`avg_row_length`,`data_length`,`max_data_length`,`index_length`,`auto_increment`,`create_time`,`update_time`,`check_time` from `information_schema`.`tables` where `table_schema` = " +#define SPIDER_SQL_SELECT_TABLES_STATUS_LEN sizeof(SPIDER_SQL_SELECT_TABLES_STATUS_STR) - 1 + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +#define SPIDER_SQL_SHOW_COLUMNS_STR "show columns from " +#define SPIDER_SQL_SHOW_COLUMNS_LEN sizeof(SPIDER_SQL_SHOW_COLUMNS_STR) - 1 +#endif + +#define SPIDER_SQL_LIKE_STR " like " +#define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1) +#define SPIDER_SQL_LIMIT1_STR " limit 1" +#define SPIDER_SQL_LIMIT1_LEN (sizeof(SPIDER_SQL_LIMIT1_STR) - 1) +#define SPIDER_SQL_COLLATE_STR " collate " +#define SPIDER_SQL_COLLATE_LEN (sizeof(SPIDER_SQL_COLLATE_STR) - 1) + +#define SPIDER_SQL_INTERVAL_STR " + interval " +#define SPIDER_SQL_INTERVAL_LEN (sizeof(SPIDER_SQL_INTERVAL_STR) - 1) +#define SPIDER_SQL_NEGINTERVAL_STR " - interval " +#define SPIDER_SQL_NEGINTERVAL_LEN (sizeof(SPIDER_SQL_NEGINTERVAL_STR) - 1) + +static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = + {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; +#define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) + +static const char *spider_db_table_lock_str[] = +{ + " read local,", + " read,", + " low_priority write,", + " write," +}; +static const int spider_db_table_lock_len[] = +{ + sizeof(" read local,") - 1, + sizeof(" read,") - 1, + sizeof(" low_priority write,") - 1, + sizeof(" write,") - 1 +}; +static const char *spider_db_timefunc_interval_str[] = +{ + " year", " quarter", " month", " week", " day", + " hour", " minute", " second", " microsecond", + " year_month", " day_hour", " day_minute", + " day_second", " hour_minute", " hour_second", + " minute_second", " day_microsecond", " hour_microsecond", + " minute_microsecond", " second_microsecond" +}; + +int spider_mysql_init() +{ + DBUG_ENTER("spider_mysql_init"); + DBUG_RETURN(0); +} + +int spider_mysql_deinit() +{ + DBUG_ENTER("spider_mysql_deinit"); + DBUG_RETURN(0); +} + +spider_db_share *spider_mysql_create_share( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_mysql_create_share"); + DBUG_RETURN(new spider_mysql_share(share)); +} + +spider_db_handler *spider_mysql_create_handler( + ha_spider *spider, + spider_db_share *db_share +) { + DBUG_ENTER("spider_mysql_create_handler"); + DBUG_RETURN(new spider_mysql_handler(spider, + (spider_mysql_share *) db_share)); +} + +spider_db_copy_table *spider_mysql_create_copy_table( + spider_db_share *db_share +) { + DBUG_ENTER("spider_mysql_create_copy_table"); + DBUG_RETURN(new spider_mysql_copy_table( + (spider_mysql_share *) db_share)); +} + +SPIDER_DB_CONN *spider_mysql_create_conn( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_mysql_create_conn"); + DBUG_RETURN(new spider_db_mysql(conn)); +} + +spider_db_mysql_util spider_db_mysql_utility; + +SPIDER_DBTON spider_dbton_mysql = { + 0, + SPIDER_DB_WRAPPER_MYSQL, + SPIDER_DB_ACCESS_TYPE_SQL, + spider_mysql_init, + spider_mysql_deinit, + spider_mysql_create_share, + spider_mysql_create_handler, + spider_mysql_create_copy_table, + spider_mysql_create_conn, + &spider_db_mysql_utility +}; + +spider_db_mysql_row::spider_db_mysql_row() : spider_db_row(), + row(NULL), lengths(NULL), cloned(FALSE) +{ + DBUG_ENTER("spider_db_mysql_row::spider_db_mysql_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_row::~spider_db_mysql_row() +{ + DBUG_ENTER("spider_db_mysql_row::~spider_db_mysql_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (cloned) + { + spider_free(spider_current_trx, row_first, MYF(0)); + } + DBUG_VOID_RETURN; +} + +int spider_db_mysql_row::store_to_field( + Field *field, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_mysql_row::store_to_field"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!*row) + { + DBUG_PRINT("info", ("spider field is null")); + field->set_null(); + field->reset(); + } else { + field->set_notnull(); + if (field->flags & BLOB_FLAG) + { + DBUG_PRINT("info", ("spider blob field")); + if ( + field->charset() == &my_charset_bin || + field->charset()->cset == access_charset->cset + ) + ((Field_blob *)field)->set_ptr(*lengths, (uchar *) *row); + else { + DBUG_PRINT("info", ("spider blob convert")); + if (field->table->file->ht == spider_hton_ptr) + { + ha_spider *spider = (ha_spider *) field->table->file; + spider_string *str = &spider->blob_buff[field->field_index]; + str->length(0); + if (str->append(*row, *lengths, access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + ((Field_blob *)field)->set_ptr(str->length(), (uchar *) str->ptr()); + } else { + field->store(*row, *lengths, access_charset); + } + } + } else + field->store(*row, *lengths, access_charset); + } + DBUG_RETURN(0); +} + +int spider_db_mysql_row::append_to_str( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_row::append_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(*lengths)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(*row, *lengths); + DBUG_RETURN(0); +} + +int spider_db_mysql_row::append_escaped_to_str( + spider_string *str, + uint dbton_id +) { + DBUG_ENTER("spider_db_mysql_row::append_escaped_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_string tmp_str(*row, *lengths + 1, str->charset()); + tmp_str.init_calc_mem(133); + tmp_str.length(*lengths); + if (str->reserve(*lengths * 2 + 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + spider_dbton[dbton_id].db_util->append_escaped_util(str, tmp_str.get_str()); + DBUG_RETURN(0); +} + +void spider_db_mysql_row::first() +{ + DBUG_ENTER("spider_db_mysql_row::first"); + DBUG_PRINT("info",("spider this=%p", this)); + row = row_first; + lengths = lengths_first; + DBUG_VOID_RETURN; +} + +void spider_db_mysql_row::next() +{ + DBUG_ENTER("spider_db_mysql_row::next"); + DBUG_PRINT("info",("spider this=%p", this)); + row++; + lengths++; + DBUG_VOID_RETURN; +} + +bool spider_db_mysql_row::is_null() +{ + DBUG_ENTER("spider_db_mysql_row::is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(!(*row)); +} + +int spider_db_mysql_row::val_int() +{ + DBUG_ENTER("spider_db_mysql_row::val_int"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(*row ? atoi(*row) : 0); +} + +double spider_db_mysql_row::val_real() +{ + DBUG_ENTER("spider_db_mysql_row::val_real"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(*row ? my_atof(*row) : 0.0); +} + +SPIDER_DB_ROW *spider_db_mysql_row::clone() +{ + spider_db_mysql_row *clone_row; + char *tmp_char; + MYSQL_ROW tmp_row = row_first, ctmp_row; + ulong *tmp_lengths = lengths_first; + uint row_size, i; + DBUG_ENTER("spider_db_mysql_row::clone"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(clone_row = new spider_db_mysql_row())) + { + DBUG_RETURN(NULL); + } + row_size = field_count; + for (i = 0; i < field_count; i++) + { + row_size += *tmp_lengths; + tmp_lengths++; + } + if (!spider_bulk_malloc(spider_current_trx, 29, MYF(MY_WME), + &clone_row->row, sizeof(char*) * field_count, + &tmp_char, row_size, + &clone_row->lengths, sizeof(ulong) * field_count, + NullS) + ) { + delete clone_row; + DBUG_RETURN(NULL); + } + memcpy(clone_row->lengths, lengths_first, sizeof(ulong) * field_count); + tmp_lengths = lengths_first; + ctmp_row = clone_row->row; + for (i = 0; i < field_count; i++) + { + DBUG_PRINT("info",("spider *lengths=%lu", *tmp_lengths)); + if (*tmp_row == NULL) + { + *ctmp_row = NULL; + *tmp_char = 0; + tmp_char++; + } else { + *ctmp_row = tmp_char; + memcpy(tmp_char, *tmp_row, *tmp_lengths + 1); + tmp_char += *tmp_lengths + 1; + } + ctmp_row++; + tmp_lengths++; + tmp_row++; + } + clone_row->field_count = field_count; + clone_row->row_first = clone_row->row; + clone_row->lengths_first = clone_row->lengths; + clone_row->cloned = TRUE; + DBUG_RETURN((SPIDER_DB_ROW *) clone_row); +} + +int spider_db_mysql_row::store_to_tmp_table( + TABLE *tmp_table, + spider_string *str +) { + uint i; + MYSQL_ROW tmp_row = row; + ulong *tmp_lengths = lengths; + DBUG_ENTER("spider_db_mysql_row::store_to_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + for (i = 0; i < field_count; i++) + { + if (*tmp_row) + { + if (str->reserve(*tmp_lengths + 1)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(*tmp_row, *tmp_lengths + 1); + } + tmp_lengths++; + tmp_row++; + } + tmp_table->field[0]->set_notnull(); + tmp_table->field[0]->store( + (const char *) lengths, + sizeof(ulong) * field_count, &my_charset_bin); + tmp_table->field[1]->set_notnull(); + tmp_table->field[1]->store( + str->ptr(), str->length(), &my_charset_bin); + tmp_table->field[2]->set_notnull(); + tmp_table->field[2]->store( + (char *) row, (uint) (sizeof(char *) * field_count), &my_charset_bin); + DBUG_RETURN(tmp_table->file->ha_write_row(tmp_table->record[0])); +} + +spider_db_mysql_result::spider_db_mysql_result() : spider_db_result(), + db_result(NULL) +{ + DBUG_ENTER("spider_db_mysql_result::spider_db_mysql_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_result::~spider_db_mysql_result() +{ + DBUG_ENTER("spider_db_mysql_result::~spider_db_mysql_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (db_result) + { + free_result(); + } + DBUG_VOID_RETURN; +} + +bool spider_db_mysql_result::has_result() +{ + DBUG_ENTER("spider_db_mysql_result::has_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(db_result); +} + +void spider_db_mysql_result::free_result() +{ + DBUG_ENTER("spider_db_mysql_result::free_result"); + DBUG_PRINT("info",("spider this=%p", this)); + /* need 2 times execution design */ + if (db_result) + { + mysql_free_result(db_result); + db_result = NULL; + } + DBUG_VOID_RETURN; +} + +SPIDER_DB_ROW *spider_db_mysql_result::current_row() +{ + DBUG_ENTER("spider_db_mysql_result::current_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); +} + +SPIDER_DB_ROW *spider_db_mysql_result::fetch_row() +{ + DBUG_ENTER("spider_db_mysql_result::fetch_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(row.row = mysql_fetch_row(db_result))) + { + store_error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + row.lengths = mysql_fetch_lengths(db_result); + row.field_count = mysql_num_fields(db_result); + row.row_first = row.row; + row.lengths_first = row.lengths; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_mysql_result::fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf +) { + DBUG_ENTER("spider_db_mysql_result::fetch_row_from_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(row.row = mysql_fetch_row(db_result))) + { + store_error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + row.lengths = mysql_fetch_lengths(db_result); + row.field_count = mysql_num_fields(db_result); + row.row_first = row.row; + row.lengths_first = row.lengths; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_mysql_result::fetch_row_from_tmp_table( + TABLE *tmp_table +) { + uint i; + spider_string tmp_str1, tmp_str2, tmp_str3; + const char *row_ptr; + MYSQL_ROW tmp_row; + ulong *tmp_lengths; + uint field_count; + DBUG_ENTER("spider_db_mysql_result::fetch_row_from_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_str1.init_calc_mem(117); + tmp_str2.init_calc_mem(118); + tmp_str3.init_calc_mem(170); + tmp_table->field[0]->val_str(tmp_str1.get_str()); + tmp_table->field[1]->val_str(tmp_str2.get_str()); + tmp_table->field[2]->val_str(tmp_str3.get_str()); + tmp_str1.mem_calc(); + tmp_str2.mem_calc(); + tmp_str3.mem_calc(); + row_ptr = tmp_str2.ptr(); + tmp_lengths = (ulong *) tmp_str1.ptr(); + tmp_row = (MYSQL_ROW) tmp_str3.ptr(); + field_count = tmp_str1.length() / sizeof(ulong); + row.row = tmp_row; + row.lengths = tmp_lengths; + row.field_count = field_count; + row.row_first = row.row; + row.lengths_first = row.lengths; + for (i = 0; i < field_count; i++) + { + if (*tmp_row) + { + *tmp_row = (char *) row_ptr; + row_ptr += *tmp_lengths + 1; + } + tmp_row++; + tmp_lengths++; + } + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +int spider_db_mysql_result::fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time +) { + int error_num; + MYSQL_ROW mysql_row; + MYSQL_TIME mysql_time; +#ifdef MARIADB_BASE_VERSION + uint not_used_uint; +#else + my_bool not_used_my_bool; +#endif + MYSQL_TIME_STATUS time_status; + long not_used_long; + DBUG_ENTER("spider_db_mysql_result::fetch_table_status"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); + } + if (mode == 1) + { + if (num_fields() != 18) + { + DBUG_PRINT("info",("spider field_count != 18")); + DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); + } + + if (mysql_row[4]) + records = + (ha_rows) my_strtoll10(mysql_row[4], (char**) NULL, &error_num); + else + records = (ha_rows) 0; + DBUG_PRINT("info", + ("spider records=%lld", records)); + if (mysql_row[5]) + mean_rec_length = + (ulong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num); + else + mean_rec_length = 0; + DBUG_PRINT("info", + ("spider mean_rec_length=%lu", mean_rec_length)); + if (mysql_row[6]) + data_file_length = + (ulonglong) my_strtoll10(mysql_row[6], (char**) NULL, &error_num); + else + data_file_length = 0; + DBUG_PRINT("info", + ("spider data_file_length=%lld", data_file_length)); + if (mysql_row[7]) + max_data_file_length = + (ulonglong) my_strtoll10(mysql_row[7], (char**) NULL, &error_num); + else + max_data_file_length = 0; + DBUG_PRINT("info", + ("spider max_data_file_length=%lld", max_data_file_length)); + if (mysql_row[8]) + index_file_length = + (ulonglong) my_strtoll10(mysql_row[8], (char**) NULL, &error_num); + else + index_file_length = 0; + DBUG_PRINT("info", + ("spider index_file_length=%lld", index_file_length)); + if (mysql_row[10]) + auto_increment_value = + (ulonglong) my_strtoll10(mysql_row[10], (char**) NULL, &error_num); + else + auto_increment_value = 1; + DBUG_PRINT("info", + ("spider auto_increment_value=%lld", auto_increment_value)); + if (mysql_row[11]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[11], strlen(mysql_row[11]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + create_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&create_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider create_time=%s", buf)); + } +#endif + if (mysql_row[12]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[12], strlen(mysql_row[12]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + update_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&update_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider update_time=%s", buf)); + } +#endif + if (mysql_row[13]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[13], strlen(mysql_row[13]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + check_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&check_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider check_time=%s", buf)); + } +#endif + } else { + if (mysql_row[0]) + records = + (ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num); + else + records = (ha_rows) 0; + DBUG_PRINT("info", + ("spider records=%lld", records)); + if (mysql_row[1]) + mean_rec_length = + (ulong) my_strtoll10(mysql_row[1], (char**) NULL, &error_num); + else + mean_rec_length = 0; + DBUG_PRINT("info", + ("spider mean_rec_length=%lu", mean_rec_length)); + if (mysql_row[2]) + data_file_length = + (ulonglong) my_strtoll10(mysql_row[2], (char**) NULL, &error_num); + else + data_file_length = 0; + DBUG_PRINT("info", + ("spider data_file_length=%lld", data_file_length)); + if (mysql_row[3]) + max_data_file_length = + (ulonglong) my_strtoll10(mysql_row[3], (char**) NULL, &error_num); + else + max_data_file_length = 0; + DBUG_PRINT("info", + ("spider max_data_file_length=%lld", max_data_file_length)); + if (mysql_row[4]) + index_file_length = + (ulonglong) my_strtoll10(mysql_row[4], (char**) NULL, &error_num); + else + index_file_length = 0; + DBUG_PRINT("info", + ("spider index_file_length=%lld", index_file_length)); + if (mysql_row[5]) + auto_increment_value = + (ulonglong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num); + else + auto_increment_value = 1; + DBUG_PRINT("info", + ("spider auto_increment_value=%lld", auto_increment_value)); + if (mysql_row[6]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[6], strlen(mysql_row[6]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + create_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&create_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider create_time=%s", buf)); + } +#endif + if (mysql_row[7]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[7], strlen(mysql_row[7]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + update_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&update_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider update_time=%s", buf)); + } +#endif + if (mysql_row[8]) + { + my_time_status_init(&time_status); + str_to_datetime(mysql_row[8], strlen(mysql_row[8]), &mysql_time, 0, + &time_status); +#ifdef MARIADB_BASE_VERSION + check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); +#else + check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_my_bool); +#endif + } else + check_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&check_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider check_time=%s", buf)); + } +#endif + } + DBUG_RETURN(0); +} + +int spider_db_mysql_result::fetch_table_records( + int mode, + ha_rows &records +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mysql_result::fetch_table_records"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + if (mode == 1) + { + if (mysql_row[0]) + { + records = + (ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num); + } else + records = (ha_rows) 0; + DBUG_PRINT("info", + ("spider records=%lld", records)); + } else { + if (num_fields() != 10) + { + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + + if (mysql_row[8]) + { + records = + (ha_rows) my_strtoll10(mysql_row[8], (char**) NULL, &error_num); + } else + records = 0; + } + DBUG_RETURN(0); +} + +int spider_db_mysql_result::fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size +) { + int error_num; + MYSQL_ROW mysql_row; + Field *field; + DBUG_ENTER("spider_db_mysql_result::fetch_table_cardinality"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + /* no index */ + DBUG_RETURN(0); + } + memset((uchar *) cardinality_upd, 0, sizeof(uchar) * bitmap_size); + if (mode == 1) + { + uint num_fields = this->num_fields(); + if (num_fields < 12 || num_fields > 13) + { + DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 13")); + DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); + } + + while (mysql_row) + { + if ( + mysql_row[4] && + mysql_row[6] && + (field = find_field_in_table_sef(table, mysql_row[4])) + ) { + if ((cardinality[field->field_index] = + (longlong) my_strtoll10(mysql_row[6], (char**) NULL, &error_num)) + <= 0) + cardinality[field->field_index] = 1; + spider_set_bit(cardinality_upd, field->field_index); + DBUG_PRINT("info", + ("spider col_name=%s", mysql_row[4])); + DBUG_PRINT("info", + ("spider cardinality=%lld", + cardinality[field->field_index])); + } else if (mysql_row[4]) + { + DBUG_PRINT("info", + ("spider skip col_name=%s", mysql_row[4])); + } else { + DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); + } + mysql_row = mysql_fetch_row(db_result); + } + } else { + while (mysql_row) + { + if ( + mysql_row[0] && + mysql_row[1] && + (field = find_field_in_table_sef(table, mysql_row[0])) + ) { + if ((cardinality[field->field_index] = + (longlong) my_strtoll10(mysql_row[1], (char**) NULL, &error_num)) + <= 0) + cardinality[field->field_index] = 1; + spider_set_bit(cardinality_upd, field->field_index); + DBUG_PRINT("info", + ("spider col_name=%s", mysql_row[0])); + DBUG_PRINT("info", + ("spider cardinality=%lld", + cardinality[field->field_index])); + } else if (mysql_row[0]) + { + DBUG_PRINT("info", + ("spider skip col_name=%s", mysql_row[0])); + } else { + DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); + } + mysql_row = mysql_fetch_row(db_result); + } + } + DBUG_RETURN(0); +} + +int spider_db_mysql_result::fetch_table_mon_status( + int &status +) { + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mysql_result::fetch_table_mon_status"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (num_fields() != 1) + { + DBUG_PRINT("info",("spider num_fields != 1")); + my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + if (mysql_row[0]) + status = atoi(mysql_row[0]); + else + status = SPIDER_LINK_MON_OK; + DBUG_PRINT("info", ("spider status=%d", status)); + DBUG_RETURN(0); +} + +longlong spider_db_mysql_result::num_rows() +{ + DBUG_ENTER("spider_db_mysql_result::num_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((longlong) mysql_num_rows(db_result)); +} + +uint spider_db_mysql_result::num_fields() +{ + DBUG_ENTER("spider_db_mysql_result::num_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(mysql_num_fields(db_result)); +} + +void spider_db_mysql_result::move_to_pos( + longlong pos +) { + DBUG_ENTER("spider_db_mysql_result::move_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider pos=%lld", pos)); +/* + DBUG_ASSERT(first_row); +*/ + db_result->data_cursor = first_row + pos; + DBUG_VOID_RETURN; +} + +int spider_db_mysql_result::get_errno() +{ + DBUG_ENTER("spider_db_mysql_result::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider store_error_num=%d", store_error_num)); + DBUG_RETURN(store_error_num); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_db_mysql_result::fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mysql_result::fetch_columns_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (num_fields() != 6) + { + DBUG_PRINT("info",("spider num_fields != 6")); + my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + do { + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (str->append(mysql_row[0], strlen(mysql_row[0]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + if (str->append(mysql_row[1], strlen(mysql_row[1]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (!strcmp(mysql_row[2], "NO")) + { + if (str->reserve(SPIDER_SQL_NOT_NULL_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NOT_NULL_STR, SPIDER_SQL_NOT_NULL_LEN); + if (mysql_row[4]) + { + if (str->reserve(SPIDER_SQL_DEFAULT_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_DEFAULT_STR, SPIDER_SQL_DEFAULT_LEN); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + } else { + if (str->reserve(SPIDER_SQL_DEFAULT_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_DEFAULT_STR, SPIDER_SQL_DEFAULT_LEN); + if (mysql_row[4]) + { + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else { + if (str->reserve(SPIDER_SQL_NULL_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } + } + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } while ((mysql_row = mysql_fetch_row(db_result))); + DBUG_RETURN(0); +} + +int spider_db_mysql_result::fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mysql_result::fetch_index_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (num_fields() != 13) + { + DBUG_PRINT("info",("spider num_fields != 13")); + my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + bool first = TRUE; + do { + if (!strcmp(mysql_row[3], "1")) + { + if (first) + { + first = FALSE; + } else { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + /* new index */ + if (!strcmp(mysql_row[2], SPIDER_DB_PK_NAME_STR)) + { + /* primary key */ + if (str->reserve(SPIDER_DB_PK_NAME_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_DB_PK_NAME_STR, SPIDER_DB_PK_NAME_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } else if (!strcmp(mysql_row[1], "0")) + { + /* unique key */ + if (str->reserve(SPIDER_DB_UNIQUE_NAME_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_DB_UNIQUE_NAME_STR, SPIDER_DB_UNIQUE_NAME_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + if (str->reserve(SPIDER_DB_KEY_NAME_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_DB_KEY_NAME_STR, SPIDER_DB_KEY_NAME_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + if (strcmp(mysql_row[2], SPIDER_DB_PK_NAME_STR)) + { + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (str->append(mysql_row[2], strlen(mysql_row[2]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + } + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (mysql_row[7]) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + if (str->append(mysql_row[7], strlen(mysql_row[7]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + } else { + if (str->reserve(SPIDER_SQL_COMMA_LEN + SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if (mysql_row[7]) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + if (str->append(mysql_row[7], strlen(mysql_row[7]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + } + } while ((mysql_row = mysql_fetch_row(db_result))); + if (!first) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} +#endif + +spider_db_mysql::spider_db_mysql( + SPIDER_CONN *conn +) : spider_db_conn(conn), lock_table_hash_inited(FALSE), + handler_open_array_inited(FALSE) +{ + DBUG_ENTER("spider_db_mysql::spider_db_mysql"); + DBUG_PRINT("info",("spider this=%p", this)); + db_conn = NULL; + DBUG_VOID_RETURN; +} + +spider_db_mysql::~spider_db_mysql() +{ + DBUG_ENTER("spider_db_mysql::~spider_db_mysql"); + DBUG_PRINT("info",("spider this=%p", this)); + if (handler_open_array_inited) + { + reset_opened_handler(); + spider_free_mem_calc(spider_current_trx, + handler_open_array_id, + handler_open_array.max_element * + handler_open_array.size_of_element); + delete_dynamic(&handler_open_array); + } + if (lock_table_hash_inited) + { + spider_free_mem_calc(spider_current_trx, + lock_table_hash_id, + lock_table_hash.array.max_element * + lock_table_hash.array.size_of_element); + my_hash_free(&lock_table_hash); + } + DBUG_VOID_RETURN; +} + +int spider_db_mysql::init() +{ + DBUG_ENTER("spider_db_mysql::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + my_hash_init(&lock_table_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_link_get_key, 0, 0) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_alloc_calc_mem_init(lock_table_hash, 140); + spider_alloc_calc_mem(spider_current_trx, + lock_table_hash, + lock_table_hash.array.max_element * + lock_table_hash.array.size_of_element); + lock_table_hash_inited = TRUE; + + if ( + SPD_INIT_DYNAMIC_ARRAY2(&handler_open_array, + sizeof(SPIDER_LINK_FOR_HASH *), NULL, 16, 16, MYF(MY_WME)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_alloc_calc_mem_init(handler_open_array, 162); + spider_alloc_calc_mem(spider_current_trx, + handler_open_array, + handler_open_array.max_element * + handler_open_array.size_of_element); + handler_open_array_inited = TRUE; + DBUG_RETURN(0); +} + +bool spider_db_mysql::is_connected() +{ + DBUG_ENTER("spider_db_mysql::is_connected"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(db_conn); +} + +void spider_db_mysql::bg_connect() +{ + DBUG_ENTER("spider_db_mysql::bg_connect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mysql::connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval +) { + int error_num; + my_bool connect_mutex = spider_param_connect_mutex(); + DBUG_ENTER("spider_db_mysql::connect"); + DBUG_PRINT("info",("spider this=%p", this)); + while (TRUE) + { + if (!db_conn) + { + if (!(db_conn = mysql_init(NULL))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + mysql_options(db_conn, MYSQL_OPT_READ_TIMEOUT, + &conn->net_read_timeout); + mysql_options(db_conn, MYSQL_OPT_WRITE_TIMEOUT, + &conn->net_write_timeout); + mysql_options(db_conn, MYSQL_OPT_CONNECT_TIMEOUT, + &conn->connect_timeout); + mysql_options(db_conn, MYSQL_OPT_USE_REMOTE_CONNECTION, + NULL); + + if ( + conn->tgt_ssl_ca_length | + conn->tgt_ssl_capath_length | + conn->tgt_ssl_cert_length | + conn->tgt_ssl_key_length + ) { + mysql_ssl_set(db_conn, conn->tgt_ssl_key, conn->tgt_ssl_cert, + conn->tgt_ssl_ca, conn->tgt_ssl_capath, conn->tgt_ssl_cipher); + if (conn->tgt_ssl_vsc) + { + my_bool verify_flg = TRUE; + mysql_options(db_conn, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + &verify_flg); + } + } + + if (conn->tgt_default_file) + { + DBUG_PRINT("info",("spider tgt_default_file=%s", + conn->tgt_default_file)); + mysql_options(db_conn, MYSQL_READ_DEFAULT_FILE, + conn->tgt_default_file); + } + if (conn->tgt_default_group) + { + DBUG_PRINT("info",("spider tgt_default_group=%s", + conn->tgt_default_group)); + mysql_options(db_conn, MYSQL_READ_DEFAULT_GROUP, + conn->tgt_default_group); + } + + if (connect_mutex) + pthread_mutex_lock(&spider_open_conn_mutex); + /* tgt_db not use */ + if (!mysql_real_connect( + db_conn, + tgt_host, + tgt_username, + tgt_password, + NULL, + tgt_port, + tgt_socket, + CLIENT_MULTI_STATEMENTS + )) { + if (connect_mutex) + pthread_mutex_unlock(&spider_open_conn_mutex); + error_num = mysql_errno(db_conn); + disconnect(); + if ( + ( + error_num != CR_CONN_HOST_ERROR && + error_num != CR_CONNECTION_ERROR + ) || + !connect_retry_count + ) { + *conn->need_mon = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + server_name ? server_name : tgt_host); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + connect_retry_count--; + my_sleep((ulong) connect_retry_interval); + } else { + if (connect_mutex) + pthread_mutex_unlock(&spider_open_conn_mutex); + break; + } + } + DBUG_RETURN(0); +} + +int spider_db_mysql::ping( +) { + DBUG_ENTER("spider_db_mysql::ping"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(simple_command(db_conn, COM_PING, 0, 0, 0)); +} + +void spider_db_mysql::bg_disconnect() +{ + DBUG_ENTER("spider_db_mysql::bg_disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +void spider_db_mysql::disconnect() +{ + DBUG_ENTER("spider_db_mysql::disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider db_conn=%p", db_conn)); + if (db_conn) + { + mysql_close(db_conn); + db_conn = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_db_mysql::set_net_timeout() +{ + DBUG_ENTER("spider_db_mysql::set_net_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider conn=%p", conn)); + my_net_set_read_timeout(&db_conn->net, conn->net_read_timeout); + my_net_set_write_timeout(&db_conn->net, conn->net_write_timeout); + DBUG_RETURN(0); +} + +int spider_db_mysql::exec_query( + const char *query, + uint length, + int quick_mode +) { + DBUG_ENTER("spider_db_mysql::exec_query"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(mysql_real_query(db_conn, query, length)); +} + +int spider_db_mysql::get_errno() +{ + DBUG_ENTER("spider_db_mysql::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + stored_error = mysql_errno(db_conn); + DBUG_PRINT("info",("spider stored_error=%d", stored_error)); + DBUG_RETURN(stored_error); +} + +const char *spider_db_mysql::get_error() +{ + const char *error_ptr; + DBUG_ENTER("spider_db_mysql::get_error"); + DBUG_PRINT("info",("spider this=%p", this)); + error_ptr = mysql_error(db_conn); + DBUG_PRINT("info",("spider error=%s", error_ptr)); + DBUG_RETURN(error_ptr); +} + +bool spider_db_mysql::is_server_gone_error( + int error_num +) { + bool server_gone; + DBUG_ENTER("spider_db_mysql::is_server_gone_error"); + DBUG_PRINT("info",("spider this=%p", this)); + server_gone = + (error_num == CR_SERVER_GONE_ERROR || error_num == CR_SERVER_LOST); + DBUG_PRINT("info",("spider server_gone=%s", server_gone ? "TRUE" : "FALSE")); + DBUG_RETURN(server_gone); +} + +bool spider_db_mysql::is_dup_entry_error( + int error_num +) { + bool dup_entry; + DBUG_ENTER("spider_db_mysql::is_dup_entry_error"); + DBUG_PRINT("info",("spider this=%p", this)); + dup_entry = + ( + error_num == ER_DUP_ENTRY || + error_num == ER_DUP_KEY || + error_num == HA_ERR_FOUND_DUPP_KEY + ); + DBUG_PRINT("info",("spider dup_entry=%s", dup_entry ? "TRUE" : "FALSE")); + DBUG_RETURN(dup_entry); +} + +bool spider_db_mysql::is_xa_nota_error( + int error_num +) { + bool xa_nota; + DBUG_ENTER("spider_db_mysql::is_xa_nota_error"); + DBUG_PRINT("info",("spider this=%p", this)); + xa_nota = + ( + error_num == ER_XAER_NOTA || + error_num == ER_XA_RBTIMEOUT || + error_num == ER_XA_RBDEADLOCK + ); + DBUG_PRINT("info",("spider xa_nota=%s", xa_nota ? "TRUE" : "FALSE")); + DBUG_RETURN(xa_nota); +} + +spider_db_result *spider_db_mysql::store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_mysql_result *result; + DBUG_ENTER("spider_db_mysql::store_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(!spider_res_buf); + if ((result = new spider_db_mysql_result())) + { + *error_num = 0; + if (!(result->db_result = mysql_store_result(db_conn))) + { + delete result; + result = NULL; + } else { + result->first_row = result->db_result->data_cursor; + DBUG_PRINT("info",("spider result->first_row=%p", result->first_row)); + } + } else { + *error_num = HA_ERR_OUT_OF_MEM; + } + DBUG_RETURN(result); +} + +spider_db_result *spider_db_mysql::use_result( + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_mysql_result *result; + DBUG_ENTER("spider_db_mysql::use_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((result = new spider_db_mysql_result())) + { + *error_num = 0; + if (!(result->db_result = db_conn->methods->use_result(db_conn))) + { + delete result; + result = NULL; + } else { + result->first_row = NULL; + } + } else { + *error_num = HA_ERR_OUT_OF_MEM; + } + DBUG_RETURN(result); +} + +int spider_db_mysql::next_result() +{ + int status; + DBUG_ENTER("spider_db_mysql::next_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (db_conn->status != MYSQL_STATUS_READY) + { + my_message(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + + db_conn->net.last_errno = 0; + db_conn->net.last_error[0] = '\0'; + strmov(db_conn->net.sqlstate, "00000"); + db_conn->affected_rows = ~(my_ulonglong) 0; + +#if MYSQL_VERSION_ID < 50500 + if (db_conn->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) +#else + if (db_conn->server_status & SERVER_MORE_RESULTS_EXISTS) +#endif + { + if ((status = db_conn->methods->read_query_result(db_conn)) > 0) + DBUG_RETURN(spider_db_errorno(conn)); + DBUG_RETURN(status); + } + DBUG_RETURN(-1); +} + +uint spider_db_mysql::affected_rows() +{ + MYSQL *last_used_con; + DBUG_ENTER("spider_db_mysql::affected_rows"); + DBUG_PRINT("info",("spider this=%p", this)); +#if MYSQL_VERSION_ID < 50500 + last_used_con = db_conn->last_used_con; +#else + last_used_con = db_conn; +#endif + DBUG_RETURN((uint) last_used_con->affected_rows); +} + +ulonglong spider_db_mysql::last_insert_id() +{ + MYSQL *last_used_con; + DBUG_ENTER("spider_db_mysql::last_insert_id"); + DBUG_PRINT("info",("spider this=%p", this)); +#if MYSQL_VERSION_ID < 50500 + last_used_con = db_conn->last_used_con; +#else + last_used_con = db_conn; +#endif + DBUG_RETURN((uint) last_used_con->insert_id); +} + +int spider_db_mysql::set_character_set( + const char *csname +) { + DBUG_ENTER("spider_db_mysql::set_character_set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(mysql_set_character_set(db_conn, csname)); +} + +int spider_db_mysql::select_db( + const char *dbname +) { + DBUG_ENTER("spider_db_mysql::select_db"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(mysql_select_db(db_conn, dbname)); +} + +int spider_db_mysql::consistent_snapshot( + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::consistent_snapshot"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_db_query( + conn, + SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR, + SPIDER_SQL_START_CONSISTENT_SNAPSHOT_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +bool spider_db_mysql::trx_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::trx_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::start_transaction( + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_db_query( + conn, + SPIDER_SQL_START_TRANSACTION_STR, + SPIDER_SQL_START_TRANSACTION_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::commit( + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::commit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_db_query( + conn, + SPIDER_SQL_COMMIT_STR, + SPIDER_SQL_COMMIT_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::rollback( + int *need_mon +) { + bool is_error; + int error_num; + DBUG_ENTER("spider_db_mysql::rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_db_query( + conn, + SPIDER_SQL_ROLLBACK_STR, + SPIDER_SQL_ROLLBACK_LEN, + -1, + need_mon) + ) { + is_error = conn->thd->is_error(); + conn->mta_conn_mutex_unlock_later = TRUE; + error_num = spider_db_errorno(conn); + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !is_error + ) + conn->thd->clear_error(); + else { + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::xa_start( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +bool spider_db_mysql::xa_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::xa_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::xa_end( + XID *xid, + int *need_mon +) { + char sql_buf[SPIDER_SQL_XA_END_LEN + XIDDATASIZE + sizeof(long) + 9]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mysql::xa_end"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(108); + + sql_str.length(0); + sql_str.q_append(SPIDER_SQL_XA_END_STR, SPIDER_SQL_XA_END_LEN); + spider_db_append_xid_str(&sql_str, xid); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::xa_prepare( + XID *xid, + int *need_mon +) { + char sql_buf[SPIDER_SQL_XA_PREPARE_LEN + XIDDATASIZE + sizeof(long) + 9]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mysql::xa_prepare"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(109); + + sql_str.length(0); + sql_str.q_append(SPIDER_SQL_XA_PREPARE_STR, SPIDER_SQL_XA_PREPARE_LEN); + spider_db_append_xid_str(&sql_str, xid); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::xa_commit( + XID *xid, + int *need_mon +) { + char sql_buf[SPIDER_SQL_XA_COMMIT_LEN + XIDDATASIZE + sizeof(long) + 9]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mysql::xa_commit"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(110); + + sql_str.length(0); + sql_str.q_append(SPIDER_SQL_XA_COMMIT_STR, SPIDER_SQL_XA_COMMIT_LEN); + spider_db_append_xid_str(&sql_str, xid); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_mysql::xa_rollback( + XID *xid, + int *need_mon +) { + char sql_buf[SPIDER_SQL_XA_ROLLBACK_LEN + XIDDATASIZE + sizeof(long) + 9]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mysql::xa_rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(111); + + sql_str.length(0); + sql_str.q_append(SPIDER_SQL_XA_ROLLBACK_STR, SPIDER_SQL_XA_ROLLBACK_LEN); + spider_db_append_xid_str(&sql_str, xid); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +bool spider_db_mysql::set_trx_isolation_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::set_trx_isolation_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::set_trx_isolation( + int trx_isolation, + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::set_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (trx_isolation) + { + case ISO_READ_UNCOMMITTED: + if (spider_db_query( + conn, + SPIDER_SQL_ISO_READ_UNCOMMITTED_STR, + SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_READ_COMMITTED: + if (spider_db_query( + conn, + SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_REPEATABLE_READ: + if (spider_db_query( + conn, + SPIDER_SQL_ISO_REPEATABLE_READ_STR, + SPIDER_SQL_ISO_REPEATABLE_READ_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_SERIALIZABLE: + if (spider_db_query( + conn, + SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + default: + DBUG_RETURN(HA_ERR_UNSUPPORTED); + } + DBUG_RETURN(0); +} + +bool spider_db_mysql::set_autocommit_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::set_autocommit_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::set_autocommit( + bool autocommit, + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::set_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (autocommit) + { + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); +} + +bool spider_db_mysql::set_sql_log_off_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::set_sql_log_off_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::set_sql_log_off( + bool sql_log_off, + int *need_mon +) { + DBUG_ENTER("spider_db_mysql::set_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_log_off) + { + if (spider_db_query( + conn, + SPIDER_SQL_SQL_LOG_ON_STR, + SPIDER_SQL_SQL_LOG_ON_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { + if (spider_db_query( + conn, + SPIDER_SQL_SQL_LOG_OFF_STR, + SPIDER_SQL_SQL_LOG_OFF_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); +} + +bool spider_db_mysql::set_time_zone_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mysql::set_time_zone_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mysql::set_time_zone( + Time_zone *time_zone, + int *need_mon +) { + const String *tz_str = time_zone->get_name(); + char sql_buf[MAX_FIELD_WIDTH]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mysql::set_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(214); + sql_str.length(0); + if (sql_str.reserve(SPIDER_SQL_TIME_ZONE_LEN + + tz_str->length() + SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_str.q_append(SPIDER_SQL_TIME_ZONE_STR, SPIDER_SQL_TIME_ZONE_LEN); + sql_str.q_append(tz_str->ptr(), tz_str->length()); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int spider_db_mysql::append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_mysql::append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_open_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_mysql::append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_select"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_mysql::append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_mysql::append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_mysql::append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_db_mysql::reset_request_queue() +{ + DBUG_ENTER("spider_db_mysql::reset_request_queue"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} +#endif + +size_t spider_db_mysql::escape_string( + char *to, + const char *from, + size_t from_length +) { + DBUG_ENTER("spider_db_mysql::escape_string"); + DBUG_PRINT("info",("spider this=%p", this)); + if (db_conn->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) + DBUG_RETURN(escape_quotes_for_mysql(db_conn->charset, to, 0, + from, from_length)); + DBUG_RETURN(escape_string_for_mysql(db_conn->charset, to, 0, + from, from_length)); +} + +bool spider_db_mysql::have_lock_table_list() +{ + DBUG_ENTER("spider_db_mysql::have_lock_table_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +int spider_db_mysql::append_lock_tables( + spider_string *str +) { + int error_num; + ha_spider *tmp_spider; + int lock_type; + uint conn_link_idx; + int tmp_link_idx; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash; + const char *db_name; + uint db_name_length; + CHARSET_INFO *db_name_charset; + const char *table_name; + uint table_name_length; + CHARSET_INFO *table_name_charset; + DBUG_ENTER("spider_db_mysql::lock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_mysql_utility.append_lock_table_head(str))) + { + DBUG_RETURN(error_num); + } + while ((tmp_link_for_hash = + (SPIDER_LINK_FOR_HASH *) my_hash_element(&lock_table_hash, 0))) + { + tmp_spider = tmp_link_for_hash->spider; + tmp_link_idx = tmp_link_for_hash->link_idx; + switch (tmp_spider->lock_type) + { + case TL_READ: + lock_type = SPIDER_DB_TABLE_LOCK_READ_LOCAL; + break; + case TL_READ_NO_INSERT: + lock_type = SPIDER_DB_TABLE_LOCK_READ; + break; + case TL_WRITE_LOW_PRIORITY: + lock_type = SPIDER_DB_TABLE_LOCK_LOW_PRIORITY_WRITE; + break; + case TL_WRITE: + lock_type = SPIDER_DB_TABLE_LOCK_WRITE; + break; + default: + // no lock + DBUG_PRINT("info",("spider lock_type=%d", tmp_spider->lock_type)); + DBUG_RETURN(0); + } + conn_link_idx = tmp_spider->conn_link_idx[tmp_link_idx]; + spider_mysql_share *db_share = (spider_mysql_share *) + tmp_spider->share->dbton_share[conn->dbton_id]; + if (&db_share->db_names_str[conn_link_idx]) + { + db_name = db_share->db_names_str[conn_link_idx].ptr(); + db_name_length = db_share->db_names_str[conn_link_idx].length(); + db_name_charset = tmp_spider->share->access_charset; + } else { + db_name = tmp_spider->share->tgt_dbs[conn_link_idx]; + db_name_length = tmp_spider->share->tgt_dbs_lengths[conn_link_idx]; + db_name_charset = system_charset_info; + } + if (&db_share->table_names_str[conn_link_idx]) + { + table_name = db_share->table_names_str[conn_link_idx].ptr(); + table_name_length = db_share->table_names_str[conn_link_idx].length(); + table_name_charset = tmp_spider->share->access_charset; + } else { + table_name = tmp_spider->share->tgt_table_names[conn_link_idx]; + table_name_length = + tmp_spider->share->tgt_table_names_lengths[conn_link_idx]; + table_name_charset = system_charset_info; + } + if ((error_num = spider_db_mysql_utility. + append_lock_table_body( + str, + db_name, + db_name_length, + db_name_charset, + table_name, + table_name_length, + table_name_charset, + lock_type + ) + )) { + my_hash_reset(&lock_table_hash); + DBUG_RETURN(error_num); + } +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&lock_table_hash, + tmp_link_for_hash->db_table_str_hash_value, (uchar*) tmp_link_for_hash); +#else + my_hash_delete(&lock_table_hash, (uchar*) tmp_link_for_hash); +#endif + } + if ((error_num = spider_db_mysql_utility.append_lock_table_tail(str))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_mysql::append_unlock_tables( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_db_mysql::append_unlock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_mysql_utility.append_unlock_table(str))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +uint spider_db_mysql::get_lock_table_hash_count() +{ + DBUG_ENTER("spider_db_mysql::get_lock_table_hash_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +void spider_db_mysql::reset_lock_table_hash() +{ + DBUG_ENTER("spider_db_mysql::reset_lock_table_hash"); + DBUG_PRINT("info",("spider this=%p", this)); + my_hash_reset(&lock_table_hash); + DBUG_VOID_RETURN; +} + +uint spider_db_mysql::get_opened_handler_count() +{ + DBUG_ENTER("spider_db_mysql::get_opened_handler_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(handler_open_array.elements); +} + +void spider_db_mysql::reset_opened_handler() +{ + ha_spider *tmp_spider; + int tmp_link_idx; + SPIDER_LINK_FOR_HASH **tmp_link_for_hash; + DBUG_ENTER("spider_db_mysql::reset_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + while ((tmp_link_for_hash = + (SPIDER_LINK_FOR_HASH **) pop_dynamic(&handler_open_array))) + { + tmp_spider = (*tmp_link_for_hash)->spider; + tmp_link_idx = (*tmp_link_for_hash)->link_idx; + tmp_spider->clear_handler_opened(tmp_link_idx, conn->conn_kind); + } + DBUG_VOID_RETURN; +} + +void spider_db_mysql::set_dup_key_idx( + ha_spider *spider, + int link_idx +) { + TABLE *table = spider->get_table(); + uint roop_count, pk_idx = table->s->primary_key; + int key_name_length; + int max_length = 0; + char *key_name; + DBUG_ENTER("spider_db_mysql::set_dup_key_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider error_str=%s", conn->error_str)); + for (roop_count = 0; roop_count < table->s->keys; roop_count++) + { + if (roop_count == pk_idx) + { + DBUG_PRINT("info",("spider pk_idx=%u", roop_count)); + int all_link_idx = spider->conn_link_idx[link_idx]; + key_name = spider->share->tgt_pk_names[all_link_idx]; + key_name_length = spider->share->tgt_pk_names_lengths[all_link_idx]; + } else { + key_name = table->s->key_info[roop_count].name; + key_name_length = strlen(key_name); + } + DBUG_PRINT("info",("spider key_name=%s", key_name)); + if ( + max_length < key_name_length && + conn->error_length - 1 >= key_name_length && + *(conn->error_str + conn->error_length - 2 - + key_name_length) == '\'' && + !strncasecmp(conn->error_str + + conn->error_length - 1 - key_name_length, + key_name, key_name_length) + ) { + max_length = key_name_length; + spider->dup_key_idx = roop_count; + } + } + if (max_length == 0) + spider->dup_key_idx = (uint) -1; + DBUG_PRINT("info",("spider dup_key_idx=%d", spider->dup_key_idx)); + DBUG_VOID_RETURN; +} + +bool spider_db_mysql::cmp_request_key_to_snd( + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mysql::cmp_request_key_to_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +spider_db_mysql_util::spider_db_mysql_util() : spider_db_util() +{ + DBUG_ENTER("spider_db_mysql_util::spider_db_mysql_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_util::~spider_db_mysql_util() +{ + DBUG_ENTER("spider_db_mysql_util::~spider_db_mysql_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mysql_util::append_name( + spider_string *str, + const char *name, + uint name_length +) { + DBUG_ENTER("spider_db_mysql_util::append_name"); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(name, name_length); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset +) { + DBUG_ENTER("spider_db_mysql_util::append_name_with_charset"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2 + name_length * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->append(name, name_length, name_charset); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +bool spider_db_mysql_util::is_name_quote( + const char head_code +) { + DBUG_ENTER("spider_db_mysql_util::is_name_quote"); + DBUG_RETURN(head_code == *name_quote_str); +} + +int spider_db_mysql_util::append_escaped_name_quote( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_util::append_escaped_name_quote"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset +) { + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); + String *ptr; + uint length; + DBUG_ENTER("spider_db_mysql_util::append_column_value"); + tmp_str.init_calc_mem(113); + + if (new_ptr) + { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR + ) { + length = uint2korr(new_ptr); + tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, + &my_charset_bin); + ptr = tmp_str.get_str(); + } else if (field->type() == MYSQL_TYPE_GEOMETRY) + { +/* + uint mlength = SIZEOF_STORED_DOUBLE, lcnt; + uchar *dest = (uchar *) buf; + const uchar *source; + for (lcnt = 0; lcnt < 4; lcnt++) + { + mlength = SIZEOF_STORED_DOUBLE; + source = new_ptr + mlength + SIZEOF_STORED_DOUBLE * lcnt; + while (mlength--) + *dest++ = *--source; + } + tmp_str.length(SIZEOF_STORED_DOUBLE * lcnt); +*/ +#ifndef DBUG_OFF + double xmin, xmax, ymin, ymax; +/* + float8store(buf,xmin); + float8store(buf+8,xmax); + float8store(buf+16,ymin); + float8store(buf+24,ymax); + memcpy(&xmin,new_ptr,sizeof(xmin)); + memcpy(&xmax,new_ptr + 8,sizeof(xmax)); + memcpy(&ymin,new_ptr + 16,sizeof(ymin)); + memcpy(&ymax,new_ptr + 24,sizeof(ymax)); + float8get(xmin, buf); + float8get(xmax, buf + 8); + float8get(ymin, buf + 16); + float8get(ymax, buf + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + DBUG_PRINT("info", ("spider geo is %.14g %.14g %.14g %.14g", + xmin, xmax, ymin, ymax)); +*/ + float8get(xmin, new_ptr); + float8get(xmax, new_ptr + 8); + float8get(ymin, new_ptr + 16); + float8get(ymax, new_ptr + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +/* + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 4); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 5); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 6); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 7); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 8); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 9); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 10); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 11); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 12); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 13); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 14); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 15); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +*/ +#endif +/* + tmp_str.set_quick((char *) new_ptr, SIZEOF_STORED_DOUBLE * 4, + &my_charset_bin); +*/ + tmp_str.length(0); + tmp_str.q_append((char *) SPIDER_SQL_LINESTRING_HEAD_STR, + SPIDER_SQL_LINESTRING_HEAD_LEN); + tmp_str.q_append((char *) new_ptr, SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 2, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 3, + SIZEOF_STORED_DOUBLE); + ptr = tmp_str.get_str(); + } else { + ptr = field->val_str(tmp_str.get_str(), new_ptr); + tmp_str.mem_calc(); + } + } else { + ptr = field->val_str(tmp_str.get_str()); + tmp_str.mem_calc(); + } + DBUG_PRINT("info", ("spider field->type() is %d", field->type())); + DBUG_PRINT("info", ("spider ptr->length() is %d", ptr->length())); +/* + if ( + field->type() == MYSQL_TYPE_BIT || + (field->type() >= MYSQL_TYPE_TINY_BLOB && + field->type() <= MYSQL_TYPE_BLOB) + ) { + uchar *hex_ptr = (uchar *) ptr->ptr(), *end_ptr; + char *str_ptr; + DBUG_PRINT("info", ("spider HEX")); + if (str->reserve(SPIDER_SQL_HEX_LEN + ptr->length() * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); + str_ptr = (char *) str->ptr() + str->length(); + for (end_ptr = hex_ptr + ptr->length(); hex_ptr < end_ptr; hex_ptr++) + { + *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; + *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; + } + str->length(str->length() + ptr->length() * 2); + } else +*/ + if (field->result_type() == STRING_RESULT) + { + DBUG_PRINT("info", ("spider STRING_RESULT")); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if ( + field->type() == MYSQL_TYPE_VARCHAR || + (field->type() >= MYSQL_TYPE_ENUM && + field->type() <= MYSQL_TYPE_GEOMETRY) + ) { + DBUG_PRINT("info", ("spider append_escaped")); + char buf2[MAX_FIELD_WIDTH]; + spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, access_charset); + tmp_str2.init_calc_mem(114); + tmp_str2.length(0); + if ( + tmp_str2.append(ptr->ptr(), ptr->length(), field->charset()) || + str->reserve(tmp_str2.length() * 2) || + append_escaped_util(str, tmp_str2.get_str()) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else if (str->append(*ptr)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else if (field->str_needs_quotes()) + { + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + ptr->length() * 2 + 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + append_escaped_util(str, ptr); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else if (str->append(*ptr)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_from_with_alias( + spider_string *str, + const char **table_names, + uint *table_name_lengths, + const char **table_aliases, + uint *table_alias_lengths, + uint table_count, + int *table_name_pos, + bool over_write +) { + uint roop_count, length = 0; + DBUG_ENTER("spider_db_mysql_util::append_from_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!over_write) + { + for (roop_count = 0; roop_count < table_count; roop_count++) + length += table_name_lengths[roop_count] + SPIDER_SQL_SPACE_LEN + + table_alias_lengths[roop_count] + SPIDER_SQL_COMMA_LEN; + if (str->reserve(SPIDER_SQL_FROM_LEN + length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + *table_name_pos = str->length(); + } + for (roop_count = 0; roop_count < table_count; roop_count++) + { + str->q_append(table_names[roop_count], table_name_lengths[roop_count]); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(table_aliases[roop_count], table_alias_lengths[roop_count]); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_trx_isolation( + spider_string *str, + int trx_isolation +) { + DBUG_ENTER("spider_db_mysql_util::append_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + switch (trx_isolation) + { + case ISO_READ_UNCOMMITTED: + str->q_append(SPIDER_SQL_ISO_READ_UNCOMMITTED_STR, + SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN); + break; + case ISO_READ_COMMITTED: + str->q_append(SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN); + break; + case ISO_REPEATABLE_READ: + str->q_append(SPIDER_SQL_ISO_REPEATABLE_READ_STR, + SPIDER_SQL_ISO_REPEATABLE_READ_LEN); + break; + case ISO_SERIALIZABLE: + str->q_append(SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN); + break; + default: + DBUG_RETURN(HA_ERR_UNSUPPORTED); + } + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_autocommit( + spider_string *str, + bool autocommit +) { + DBUG_ENTER("spider_db_mysql_util::append_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_AUTOCOMMIT_OFF_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + if (autocommit) + { + str->q_append(SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN); + } else { + str->q_append(SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_sql_log_off( + spider_string *str, + bool sql_log_off +) { + DBUG_ENTER("spider_db_mysql_util::append_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_SQL_LOG_OFF_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + if (sql_log_off) + { + str->q_append(SPIDER_SQL_SQL_LOG_ON_STR, SPIDER_SQL_SQL_LOG_ON_LEN); + } else { + str->q_append(SPIDER_SQL_SQL_LOG_OFF_STR, SPIDER_SQL_SQL_LOG_OFF_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_time_zone( + spider_string *str, + Time_zone *time_zone +) { + const String *tz_str = time_zone->get_name(); + DBUG_ENTER("spider_db_mysql_util::append_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_TIME_ZONE_LEN + + tz_str->length() + SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + str->q_append(SPIDER_SQL_TIME_ZONE_STR, SPIDER_SQL_TIME_ZONE_LEN); + str->q_append(tz_str->ptr(), tz_str->length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_start_transaction( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_util::append_start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_START_TRANSACTION_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + str->q_append(SPIDER_SQL_START_TRANSACTION_STR, + SPIDER_SQL_START_TRANSACTION_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_xa_start( + spider_string *str, + XID *xid +) { + DBUG_ENTER("spider_db_mysql_util::append_xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_XA_START_LEN + XIDDATASIZE + sizeof(long) + 9)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + str->q_append(SPIDER_SQL_XA_START_STR, SPIDER_SQL_XA_START_LEN); + spider_db_append_xid_str(str, xid); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_lock_table_head( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_util::append_lock_table_head"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_LOCK_TABLE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type +) { + DBUG_ENTER("spider_db_mysql_util::append_lock_table_body"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ( + str->append(db_name, db_name_length, db_name_charset) || + str->reserve((SPIDER_SQL_NAME_QUOTE_LEN) * 2 + SPIDER_SQL_DOT_LEN) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ( + str->append(table_name, table_name_length, table_name_charset) || + str->reserve(SPIDER_SQL_NAME_QUOTE_LEN + + spider_db_table_lock_len[lock_type]) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(spider_db_table_lock_str[lock_type], + spider_db_table_lock_len[lock_type]); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_lock_table_tail( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_util::append_lock_table_tail"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_unlock_table( + spider_string *str +) { + DBUG_ENTER("spider_db_mysql_util::append_unlock_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_UNLOCK_TABLE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_UNLOCK_TABLE_STR, SPIDER_SQL_UNLOCK_TABLE_LEN); + DBUG_RETURN(0); +} + +int spider_db_mysql_util::open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length +) { + uint dbton_id = spider_dbton_mysql.dbton_id; + int error_num; + Item *item, **item_list = item_func->arguments(); + uint roop_count, item_count = item_func->argument_count(), start_item = 0; + const char *func_name = SPIDER_SQL_NULL_CHAR_STR, + *separete_str = SPIDER_SQL_NULL_CHAR_STR, + *last_str = SPIDER_SQL_NULL_CHAR_STR; + int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, + separete_str_length = SPIDER_SQL_NULL_CHAR_LEN, + last_str_length = SPIDER_SQL_NULL_CHAR_LEN; + int use_pushdown_udf; + DBUG_ENTER("spider_db_mysql_util::open_item_func"); + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + DBUG_PRINT("info",("spider functype = %d", item_func->functype())); + switch (item_func->functype()) + { + case Item_func::ISNULL_FUNC: + last_str = SPIDER_SQL_IS_NULL_STR; + last_str_length = SPIDER_SQL_IS_NULL_LEN; + break; + case Item_func::ISNOTNULL_FUNC: + last_str = SPIDER_SQL_IS_NOT_NULL_STR; + last_str_length = SPIDER_SQL_IS_NOT_NULL_LEN; + break; + case Item_func::UNKNOWN_FUNC: + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (func_name_length == 1 && + ( + !strncasecmp("+", func_name, func_name_length) || + !strncasecmp("-", func_name, func_name_length) || + !strncasecmp("*", func_name, func_name_length) || + !strncasecmp("/", func_name, func_name_length) || + !strncasecmp("%", func_name, func_name_length) || + !strncasecmp("&", func_name, func_name_length) || + !strncasecmp("|", func_name, func_name_length) || + !strncasecmp("^", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 2 && + ( + !strncasecmp("<<", func_name, func_name_length) || + !strncasecmp(">>", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 3 && + !strncasecmp("div", func_name, func_name_length) + ) { + /* no action */ + break; + } else if (func_name_length == 4) + { + if ( + !strncasecmp("rand", func_name, func_name_length) && + !item_func->arg_count + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("case", func_name, func_name_length) + ) { +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC + Item_func_case *item_func_case = (Item_func_case *) item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (item_func_case->first_expr_num != -1) + { + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->first_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + for (roop_count = 0; roop_count < item_func_case->ncases; + roop_count += 2) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count + 1], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func_case->else_expr_num != -1) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->else_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +#else + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif + } + } else if (func_name_length == 6 && + !strncasecmp("istrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_TRUE_STR; + last_str_length = SPIDER_SQL_IS_TRUE_LEN; + break; + } else if (func_name_length == 7) + { + if (!strncasecmp("isfalse", func_name, func_name_length)) + { + last_str = SPIDER_SQL_IS_FALSE_STR; + last_str_length = SPIDER_SQL_IS_FALSE_LEN; + break; + } else if ( + !strncasecmp("sysdate", func_name, func_name_length) || + !strncasecmp("curdate", func_name, func_name_length) || + !strncasecmp("curtime", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + if (str->reserve(func_name_length * 2 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } + } else if (func_name_length == 8 && + ( + !strncasecmp("utc_date", func_name, func_name_length) || + !strncasecmp("utc_time", func_name, func_name_length) + ) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 9 && + !strncasecmp("isnottrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_TRUE_STR; + last_str_length = SPIDER_SQL_IS_NOT_TRUE_LEN; + break; + } else if (func_name_length == 10 && + !strncasecmp("isnotfalse", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_FALSE_STR; + last_str_length = SPIDER_SQL_IS_NOT_FALSE_LEN; + break; + } else if (func_name_length == 12) + { + if (!strncasecmp("cast_as_date", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATE_STR; + last_str_length = SPIDER_SQL_AS_DATE_LEN; + break; + } else if (!strncasecmp("cast_as_time", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_TIME_STR; + last_str_length = SPIDER_SQL_AS_TIME_LEN; + break; + } + } else if (func_name_length == 13 && + !strncasecmp("utc_timestamp", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 14) + { + if (!strncasecmp("cast_as_binary", func_name, func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(123); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_BINARY_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_signed", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_SIGNED_STR; + last_str_length = SPIDER_SQL_AS_SIGNED_LEN; + break; + } + } else if (func_name_length == 16) + { + if (!strncasecmp("cast_as_unsigned", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_UNSIGNED_STR; + last_str_length = SPIDER_SQL_AS_UNSIGNED_LEN; + break; + } else if (!strncasecmp("decimal_typecast", func_name, + func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(124); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_DECIMAL_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_datetime", func_name, + func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATETIME_STR; + last_str_length = SPIDER_SQL_AS_DATETIME_LEN; + break; + } + } else if (func_name_length == 17) + { + if (!strncasecmp("date_add_interval", func_name, func_name_length)) + { + Item_date_add_interval *item_date_add_interval = + (Item_date_add_interval *) item_func; + func_name = spider_db_timefunc_interval_str[ + item_date_add_interval->int_type]; + func_name_length = strlen(func_name); + if ((error_num = spider_db_print_item_type(item_list[0], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->date_sub_interval) + { + if (str->reserve(SPIDER_SQL_NEGINTERVAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NEGINTERVAL_STR, + SPIDER_SQL_NEGINTERVAL_LEN); + } else { + if (str->reserve(SPIDER_SQL_INTERVAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INTERVAL_STR, SPIDER_SQL_INTERVAL_LEN); + } + } + if ((error_num = spider_db_print_item_type(item_list[1], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); + } + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::NOW_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::CHAR_TYPECAST_FUNC: + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(125); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_CHAR_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + } + break; + case Item_func::NOT_FUNC: + case Item_func::NEG_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + break; + case Item_func::IN_FUNC: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_IN_STR; + func_name_length = SPIDER_SQL_NOT_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } else { + func_name = SPIDER_SQL_IN_STR; + func_name_length = SPIDER_SQL_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + case Item_func::BETWEEN: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_BETWEEN_STR; + func_name_length = SPIDER_SQL_NOT_BETWEEN_LEN; + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } else { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } + break; + case Item_func::UDF_FUNC: + use_pushdown_udf = spider_param_use_pushdown_udf(spider->trx->thd, + spider->share->use_pushdown_udf); + if (!use_pushdown_udf) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; +#ifdef MARIADB_BASE_VERSION + case Item_func::XOR_FUNC: +#else + case Item_func::COND_XOR_FUNC: +#endif + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN( + spider_db_open_item_cond((Item_cond *) item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::TRIG_COND_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::GUSERVAR_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (item_func->result_type() == STRING_RESULT) + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + else + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::FT_FUNC: + if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + start_item = 1; + if (str) + { + if (str->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + } + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_EQUALS_FUNC: + if (str) + { + func_name = SPIDER_SQL_MBR_EQUAL_STR; + func_name_length = SPIDER_SQL_MBR_EQUAL_LEN; + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_DISJOINT_FUNC: + case Item_func::SP_INTERSECTS_FUNC: + case Item_func::SP_TOUCHES_FUNC: + case Item_func::SP_CROSSES_FUNC: + case Item_func::SP_WITHIN_FUNC: + case Item_func::SP_CONTAINS_FUNC: + case Item_func::SP_OVERLAPS_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(SPIDER_SQL_MBR_LEN + func_name_length + + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_STR, SPIDER_SQL_MBR_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::EQ_FUNC: + case Item_func::EQUAL_FUNC: + case Item_func::NE_FUNC: + case Item_func::LT_FUNC: + case Item_func::LE_FUNC: + case Item_func::GE_FUNC: + case Item_func::GT_FUNC: + case Item_func::LIKE_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + default: + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + if (spider_param_skip_default_condition(thd, + share->skip_default_condition)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + } + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + DBUG_PRINT("info",("spider separete_str = %s", separete_str)); + DBUG_PRINT("info",("spider separete_str_length = %d", separete_str_length)); + DBUG_PRINT("info",("spider last_str = %s", last_str)); + DBUG_PRINT("info",("spider last_str_length = %d", last_str_length)); + if (item_count) + { + item_count--; + for (roop_count = start_item; roop_count < item_count; roop_count++) + { + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (roop_count == 1) + { + func_name = separete_str; + func_name_length = separete_str_length; + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + } + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func->functype() == Item_func::FT_FUNC) + { + Item_func_match *item_func_match = (Item_func_match *)item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_AGAINST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); + } + item = item_list[0]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve( + ((item_func_match->flags & FT_BOOL) ? + SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((item_func_match->flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (item_func_match->flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (item_func_match->flags & FT_EXPAND) + str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); + } + } else if (item_func->functype() == Item_func::UNKNOWN_FUNC) + { + if ( + func_name_length == 7 && + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + Item_func_conv_charset *item_func_conv_charset = + (Item_func_conv_charset *)item_func; + CHARSET_INFO *conv_charset = item_func_conv_charset->conv_charset; + uint cset_length = strlen(conv_charset->csname); + if (str->reserve(SPIDER_SQL_USING_LEN + cset_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); + str->q_append(conv_charset->csname, cset_length); + } + } + } + if (str) + { + if (str->reserve(last_str_length + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(last_str, last_str_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_escaped_util( + spider_string *to, + String *from +) { + DBUG_ENTER("spider_db_mysql_util::append_escaped_util"); + DBUG_PRINT("info",("spider this=%p", this)); + append_escaped(to->get_str(), from); + to->mem_calc(); + DBUG_RETURN(0); +} + +spider_mysql_share::spider_mysql_share( + st_spider_share *share +) : spider_db_share( + share +), + table_select(NULL), + table_select_pos(0), + key_select(NULL), + key_select_pos(NULL), + key_hint(NULL), + show_table_status(NULL), + show_records(NULL), + show_index(NULL), + table_names_str(NULL), + db_names_str(NULL), + db_table_str(NULL), +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value(NULL), +#endif + table_nm_max_length(0), + db_nm_max_length(0), + column_name_str(NULL), + same_db_table_name(TRUE), + first_all_link_idx(-1) +{ + DBUG_ENTER("spider_mysql_share::spider_mysql_share"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 71); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_mysql_share::~spider_mysql_share() +{ + DBUG_ENTER("spider_mysql_share::~spider_mysql_share"); + DBUG_PRINT("info",("spider this=%p", this)); + if (table_select) + delete [] table_select; + if (key_select) + delete [] key_select; + if (key_hint) + delete [] key_hint; + free_show_table_status(); + free_show_records(); + free_show_index(); + free_column_name_str(); + free_table_names_str(); + if (key_select_pos) + { + spider_free(spider_current_trx, key_select_pos, MYF(0)); + } + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_mysql_share::init() +{ + int error_num; + uint roop_count; + TABLE_SHARE *table_share = spider_share->table_share; + uint keys = table_share ? table_share->keys : 0; + DBUG_ENTER("spider_mysql_share::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(key_select_pos = (int *) + spider_bulk_alloc_mem(spider_current_trx, 112, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &key_select_pos, + sizeof(int) * keys, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + &db_table_str_hash_value, + sizeof(my_hash_value_type) * spider_share->all_link_count, +#endif + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if (keys > 0 && + !(key_hint = new spider_string[keys]) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + for (roop_count = 0; roop_count < keys; roop_count++) + { + key_hint[roop_count].init_calc_mem(189); + key_hint[roop_count].set_charset(spider_share->access_charset); + } + DBUG_PRINT("info",("spider key_hint=%p", key_hint)); + + if ( + !(table_select = new spider_string[1]) || + (keys > 0 && + !(key_select = new spider_string[keys]) + ) || + (error_num = create_table_names_str()) || + (table_share && + ( + (error_num = create_column_name_str()) || + (error_num = convert_key_hint_str()) || + (error_num = append_show_table_status()) || + (error_num = append_show_records()) || + (error_num = append_show_index()) + ) + ) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + table_select->init_calc_mem(96); + if (table_share && (error_num = append_table_select())) + DBUG_RETURN(error_num); + + for (roop_count = 0; roop_count < keys; roop_count++) + { + key_select[roop_count].init_calc_mem(97); + if ((error_num = append_key_select(roop_count))) + DBUG_RETURN(error_num); + } + + DBUG_RETURN(error_num); +} + +uint spider_mysql_share::get_column_name_length( + uint field_index +) { + DBUG_ENTER("spider_mysql_share::get_column_name_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(column_name_str[field_index].length()); +} + +int spider_mysql_share::append_column_name( + spider_string *str, + uint field_index +) { + int error_num; + DBUG_ENTER("spider_mysql_share::append_column_name"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_mysql_utility.append_name(str, + column_name_str[field_index].ptr(), column_name_str[field_index].length()); + DBUG_RETURN(error_num); +} + +int spider_mysql_share::append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_mysql_share::append_column_name_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve( + alias_length + + column_name_str[field_index].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + append_column_name(str, field_index); + DBUG_RETURN(0); +} + +int spider_mysql_share::append_table_name( + spider_string *str, + int all_link_idx +) { + const char *db_nm = db_names_str[all_link_idx].ptr(); + uint db_nm_len = db_names_str[all_link_idx].length(); + const char *table_nm = table_names_str[all_link_idx].ptr(); + uint table_nm_len = table_names_str[all_link_idx].length(); + DBUG_ENTER("spider_mysql_share::append_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(db_nm_len + SPIDER_SQL_DOT_LEN + table_nm_len + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_db_mysql_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mysql_utility.append_name(str, table_nm, table_nm_len); + DBUG_RETURN(0); +} + +int spider_mysql_share::append_table_name_with_adjusting( + spider_string *str, + int all_link_idx +) { + const char *db_nm = db_names_str[all_link_idx].ptr(); + uint db_nm_len = db_names_str[all_link_idx].length(); + uint db_nm_max_len = db_nm_max_length; + const char *table_nm = table_names_str[all_link_idx].ptr(); + uint table_nm_len = table_names_str[all_link_idx].length(); + uint table_nm_max_len = table_nm_max_length; + DBUG_ENTER("spider_mysql_share::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_db_mysql_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mysql_utility.append_name(str, table_nm, table_nm_len); + uint length = + db_nm_max_len - db_nm_len + + table_nm_max_len - table_nm_len; + memset((char *) str->ptr() + str->length(), ' ', length); + str->length(str->length() + length); + DBUG_RETURN(0); +} + +int spider_mysql_share::append_from_with_adjusted_table_name( + spider_string *str, + int *table_name_pos +) { + const char *db_nm = db_names_str[0].ptr(); + uint db_nm_len = db_names_str[0].length(); + uint db_nm_max_len = db_nm_max_length; + const char *table_nm = table_names_str[0].ptr(); + uint table_nm_len = table_names_str[0].length(); + uint table_nm_max_len = table_nm_max_length; + DBUG_ENTER("spider_mysql_share::append_from_with_adjusted_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_FROM_LEN + db_nm_max_length + + SPIDER_SQL_DOT_LEN + table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + *table_name_pos = str->length(); + spider_db_mysql_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mysql_utility.append_name(str, table_nm, table_nm_len); + uint length = + db_nm_max_len - db_nm_len + + table_nm_max_len - table_nm_len; + memset((char *) str->ptr() + str->length(), ' ', length); + str->length(str->length() + length); + DBUG_RETURN(0); +} + +int spider_mysql_share::create_table_names_str() +{ + int error_num, roop_count; + uint table_nm_len, db_nm_len; + spider_string *str, *first_tbl_nm_str, *first_db_nm_str, *first_db_tbl_str; + char *first_tbl_nm, *first_db_nm; + uint dbton_id = spider_dbton_mysql.dbton_id; + DBUG_ENTER("spider_mysql_share::create_table_names_str"); + table_names_str = NULL; + db_names_str = NULL; + db_table_str = NULL; + if ( + !(table_names_str = new spider_string[spider_share->all_link_count]) || + !(db_names_str = new spider_string[spider_share->all_link_count]) || + !(db_table_str = new spider_string[spider_share->all_link_count]) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + + same_db_table_name = TRUE; + first_tbl_nm = spider_share->tgt_table_names[0]; + first_db_nm = spider_share->tgt_dbs[0]; + table_nm_len = spider_share->tgt_table_names_lengths[0]; + db_nm_len = spider_share->tgt_dbs_lengths[0]; + first_tbl_nm_str = &table_names_str[0]; + first_db_nm_str = &db_names_str[0]; + first_db_tbl_str = &db_table_str[0]; + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + table_names_str[roop_count].init_calc_mem(86); + db_names_str[roop_count].init_calc_mem(87); + db_table_str[roop_count].init_calc_mem(88); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + if (first_all_link_idx == -1) + first_all_link_idx = roop_count; + + str = &table_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_table_names_lengths[roop_count] == table_nm_len && + !memcmp(first_tbl_nm, spider_share->tgt_table_names[roop_count], + table_nm_len) + ) { + if (str->copy(*first_tbl_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_table_names[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different table name %s", + spider_share->tgt_table_names[roop_count])); + if (str->length() > table_nm_max_length) + table_nm_max_length = str->length(); + } else + table_nm_max_length = str->length(); + } + + str = &db_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_dbs_lengths[roop_count] == db_nm_len && + !memcmp(first_db_nm, spider_share->tgt_dbs[roop_count], + db_nm_len) + ) { + if (str->copy(*first_db_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_dbs[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different db name %s", + spider_share->tgt_dbs[roop_count])); + if (str->length() > db_nm_max_length) + db_nm_max_length = str->length(); + } else + db_nm_max_length = str->length(); + } + + str = &db_table_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name + ) { + if (str->copy(*first_db_tbl_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = append_table_name(str, roop_count))) + goto error; + } +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) str->ptr(), str->length()); +#endif + } + DBUG_RETURN(0); + +error: + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_mysql_share::free_table_names_str() +{ + DBUG_ENTER("spider_mysql_share::free_table_names_str"); + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_share::create_column_name_str() +{ + spider_string *str; + int error_num; + Field **field; + TABLE_SHARE *table_share = spider_share->table_share; + uint dbton_id = spider_dbton_mysql.dbton_id; + DBUG_ENTER("spider_mysql_share::create_column_name_str"); + if ( + table_share->fields && + !(column_name_str = new spider_string[table_share->fields]) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + for (field = table_share->field, str = column_name_str; + *field; field++, str++) + { + str->init_calc_mem(89); + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + (char *) (*field)->field_name, dbton_id))) + goto error; + } + DBUG_RETURN(0); + +error: + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_mysql_share::free_column_name_str() +{ + DBUG_ENTER("spider_mysql_share::free_column_name_str"); + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_share::convert_key_hint_str() +{ + spider_string *tmp_key_hint; + int roop_count; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_mysql_share::convert_key_hint_str"); + if (spider_share->access_charset->cset != system_charset_info->cset) + { + /* need convertion */ + for (roop_count = 0, tmp_key_hint = key_hint; + roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) + { + tmp_key_hint->length(0); + if (tmp_key_hint->append(spider_share->key_hint->ptr(), + spider_share->key_hint->length(), system_charset_info)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + for (roop_count = 0, tmp_key_hint = key_hint; + roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) + { + if (tmp_key_hint->copy(spider_share->key_hint[roop_count])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_share::append_show_table_status() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_mysql.dbton_id; + DBUG_ENTER("spider_mysql_append_show_table_status"); + if (!(show_table_status = + new spider_string[2 * spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_table_status[0 + (2 * roop_count)].init_calc_mem(90); + show_table_status[1 + (2 * roop_count)].init_calc_mem(91); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_table_status[0 + (2 * roop_count)].reserve( + SPIDER_SQL_SHOW_TABLE_STATUS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_LIKE_LEN + table_names_str[roop_count].length() + + ((SPIDER_SQL_NAME_QUOTE_LEN) * 2) + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 2)) || + show_table_status[1 + (2 * roop_count)].reserve( + SPIDER_SQL_SELECT_TABLES_STATUS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + + table_names_str[roop_count].length() + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4)) + ) + goto error; + str = &show_table_status[0 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SHOW_TABLE_STATUS_STR, SPIDER_SQL_SHOW_TABLE_STATUS_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str = &show_table_status[1 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SELECT_TABLES_STATUS_STR, + SPIDER_SQL_SELECT_TABLES_STATUS_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + DBUG_RETURN(0); + +error: + if (show_table_status) + { + delete [] show_table_status; + show_table_status = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_mysql_share::free_show_table_status() +{ + DBUG_ENTER("spider_mysql_free_show_table_status"); + if (show_table_status) + { + delete [] show_table_status; + show_table_status = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_share::append_show_records() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_mysql.dbton_id; + DBUG_ENTER("spider_mysql_share::append_show_records"); + if (!(show_records = new spider_string[spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_records[roop_count].init_calc_mem(92); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_records[roop_count].reserve( + SPIDER_SQL_SHOW_RECORDS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) + ) + goto error; + str = &show_records[roop_count]; + str->q_append(SPIDER_SQL_SHOW_RECORDS_STR, SPIDER_SQL_SHOW_RECORDS_LEN); + append_table_name(str, roop_count); + } + DBUG_RETURN(0); + +error: + if (show_records) + { + delete [] show_records; + show_records = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_mysql_share::free_show_records() +{ + DBUG_ENTER("spider_mysql_share::free_show_records"); + if (show_records) + { + delete [] show_records; + show_records = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_share::append_show_index() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_mysql.dbton_id; + DBUG_ENTER("spider_mysql_share::append_show_index"); + if (!(show_index = new spider_string[2 * spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_index[0 + (2 * roop_count)].init_calc_mem(93); + show_index[1 + (2 * roop_count)].init_calc_mem(94); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_index[0 + (2 * roop_count)].reserve( + SPIDER_SQL_SHOW_INDEX_LEN + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) || + show_index[1 + (2 * roop_count)].reserve( + SPIDER_SQL_SELECT_STATISTICS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + + table_names_str[roop_count].length() + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4) + + SPIDER_SQL_GROUP_LEN + SPIDER_SQL_COLUMN_NAME_LEN) + ) + goto error; + str = &show_index[0 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SHOW_INDEX_STR, SPIDER_SQL_SHOW_INDEX_LEN); + append_table_name(str, roop_count); + str = &show_index[1 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SELECT_STATISTICS_STR, SPIDER_SQL_SELECT_STATISTICS_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); + str->q_append(SPIDER_SQL_COLUMN_NAME_STR, SPIDER_SQL_COLUMN_NAME_LEN); + } + DBUG_RETURN(0); + +error: + if (show_index) + { + delete [] show_index; + show_index = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_mysql_share::free_show_index() +{ + DBUG_ENTER("spider_mysql_share::free_show_index"); + if (show_index) + { + delete [] show_index; + show_index = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_share::append_table_select() +{ + Field **field; + uint field_length; + spider_string *str = table_select; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_mysql_share::append_table_select"); + for (field = table_share->field; *field; field++) + { + field_length = column_name_str[(*field)->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(append_from_with_adjusted_table_name(str, &table_select_pos)); +} + +int spider_mysql_share::append_key_select( + uint idx +) { + KEY_PART_INFO *key_part; + Field *field; + uint part_num; + uint field_length; + spider_string *str = &key_select[idx]; + TABLE_SHARE *table_share = spider_share->table_share; + const KEY *key_info = &table_share->key_info[idx]; + DBUG_ENTER("spider_mysql_share::append_key_select"); + for (key_part = key_info->key_part, part_num = 0; + part_num < key_info->key_parts; key_part++, part_num++) + { + field = key_part->field; + field_length = column_name_str[field->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(append_from_with_adjusted_table_name(str, &key_select_pos[idx])); +} + +bool spider_mysql_share::need_change_db_table_name() +{ + DBUG_ENTER("spider_mysql_share::need_change_db_table_name"); + DBUG_RETURN(!same_db_table_name); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_mysql_share::discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +) { + int roop_count, error_num = HA_ERR_WRONG_COMMAND; + char sql_buf[MAX_FIELD_WIDTH]; + spider_string sql_str(sql_buf, sizeof(sql_buf), system_charset_info); + uint dbton_id = spider_dbton_mysql.dbton_id; + uint strlen = str->length(); + DBUG_ENTER("spider_mysql_share::discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(228); + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + { + DBUG_PRINT("info",("spider spider_share->sql_dbton_ids[%d]=%u", + roop_count, spider_share->sql_dbton_ids[roop_count])); + DBUG_PRINT("info",("spider dbton_id=%u", dbton_id)); + continue; + } + + str->length(strlen); + sql_str.length(0); + if (sql_str.reserve( + SPIDER_SQL_SHOW_COLUMNS_LEN + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + + SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_SHOW_INDEX_LEN + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + )) { + DBUG_PRINT("info",("spider alloc sql_str error")); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql_str.q_append(SPIDER_SQL_SHOW_COLUMNS_STR, SPIDER_SQL_SHOW_COLUMNS_LEN); + append_table_name(&sql_str, roop_count); + sql_str.q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + sql_str.q_append(SPIDER_SQL_SHOW_INDEX_STR, SPIDER_SQL_SHOW_INDEX_LEN); + append_table_name(&sql_str, roop_count); + + SPIDER_CONN *conn; + int need_mon; + if (!(conn = spider_get_conn( + spider_share, 0, spider_share->conn_keys[roop_count], trx, NULL, FALSE, + FALSE, SPIDER_CONN_KIND_MYSQL, &error_num)) + ) { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(spider_share, conn, roop_count); + spider_conn_set_timeout_from_share(conn, roop_count, trx->thd, + spider_share); + if ( + (error_num = spider_db_set_names_internal(trx, spider_share, conn, + roop_count, &need_mon)) || + ( + spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + &need_mon) && + (error_num = spider_db_errorno(conn)) + ) + ) { + DBUG_PRINT("info",("spider spider_get_trx error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = trx->spider_thread_id; + request_key.query_id = trx->thd->query_id; + request_key.handler = NULL; + request_key.request_id = 1; + request_key.next = NULL; + spider_db_result *res; + /* get column list */ + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info",("spider column store error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + /* no record */ + DBUG_PRINT("info",("spider column no record error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + if ((error_num = res->fetch_columns_for_discover_table_structure(str, + spider_share->access_charset))) + { + DBUG_PRINT("info",("spider column fetch error")); + res->free_result(); + delete res; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + res->free_result(); + delete res; + if (conn->db_conn->next_result()) + { + DBUG_PRINT("info",("spider single result error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + /* get index list */ + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info",("spider index store error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + /* no record */ + DBUG_PRINT("info",("spider index no record error")); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + if ((error_num = res->fetch_index_for_discover_table_structure(str, + spider_share->access_charset))) + { + DBUG_PRINT("info",("spider index fetch error")); + res->free_result(); + delete res; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + continue; + } + res->free_result(); + delete res; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (!error_num) + break; + } + DBUG_RETURN(error_num); +} +#endif + +spider_mysql_handler::spider_mysql_handler( + ha_spider *spider, + spider_mysql_share *db_share +) : spider_db_handler( + spider, + db_share +), + where_pos(0), + order_pos(0), + limit_pos(0), + table_name_pos(0), + ha_read_pos(0), + ha_next_pos(0), + ha_where_pos(0), + ha_limit_pos(0), + ha_table_name_pos(0), + insert_pos(0), + insert_table_name_pos(0), + upd_tmp_tbl(NULL), + tmp_sql_pos1(0), + tmp_sql_pos2(0), + tmp_sql_pos3(0), + tmp_sql_pos4(0), + tmp_sql_pos5(0), + reading_from_bulk_tmp_table(FALSE), + mysql_share(db_share), + link_for_hash(NULL) +{ + DBUG_ENTER("spider_mysql_handler::spider_mysql_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 183); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_mysql_handler::~spider_mysql_handler() +{ + DBUG_ENTER("spider_mysql_handler::~spider_mysql_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (link_for_hash) + { + spider_free(spider_current_trx, link_for_hash, MYF(0)); + } + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::init() +{ + uint roop_count; + THD *thd = spider->trx->thd; + st_spider_share *share = spider->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + DBUG_ENTER("spider_mysql_handler::init"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.init_calc_mem(59); + sql_part.init_calc_mem(60); + sql_part2.init_calc_mem(61); + ha_sql.init_calc_mem(62); + insert_sql.init_calc_mem(64); + update_sql.init_calc_mem(65); + tmp_sql.init_calc_mem(66); + dup_update_sql.init_calc_mem(166); + if ( + (sql.real_alloc(init_sql_alloc_size)) || + (insert_sql.real_alloc(init_sql_alloc_size)) || + (update_sql.real_alloc(init_sql_alloc_size)) || + (tmp_sql.real_alloc(init_sql_alloc_size)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.set_charset(share->access_charset); + sql_part.set_charset(share->access_charset); + ha_sql.set_charset(share->access_charset); + insert_sql.set_charset(share->access_charset); + update_sql.set_charset(share->access_charset); + tmp_sql.set_charset(share->access_charset); + upd_tmp_tbl_prm.init(); + upd_tmp_tbl_prm.field_count = 1; + if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *) + spider_bulk_alloc_mem(spider_current_trx, 141, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &link_for_hash, + sizeof(SPIDER_LINK_FOR_HASH) * share->link_count, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + link_for_hash[roop_count].spider = spider; + link_for_hash[roop_count].link_idx = roop_count; + link_for_hash[roop_count].db_table_str = + &mysql_share->db_table_str[roop_count]; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + link_for_hash[roop_count].db_table_str_hash_value = + mysql_share->db_table_str_hash_value[roop_count]; +#endif + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + hs_upds.init(); +#endif + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type +) { + int error_num = 0; + DBUG_ENTER("spider_mysql_handler::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + } else { + error_num = mysql_share->append_table_name_with_adjusting(str, + spider->conn_link_idx[link_idx]); + } + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_column_types( + const key_range *start_key, + spider_string *str +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + KEY *key_info = result_list->key_info; + uint key_name_length, key_count; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + char tmp_buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(tmp_buf, sizeof(tmp_buf), system_charset_info); + DBUG_ENTER("spider_mysql_handler::append_key_column_types"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_str.init_calc_mem(115); + + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + for ( + key_part = key_info->key_part, + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(key_name_length + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(tmp_buf, key_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + + if (tmp_str.ptr() != tmp_buf) + tmp_str.set(tmp_buf, sizeof(tmp_buf), system_charset_info); + else + tmp_str.set_charset(system_charset_info); + field->sql_type(*tmp_str.get_str()); + tmp_str.mem_calc(); + str->append(tmp_str); + if (field->has_charset()) + { + CHARSET_INFO *cs = field->charset(); + uint coll_length = strlen(cs->name); + if (str->reserve(SPIDER_SQL_COLLATE_LEN + coll_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str->q_append(cs->name, coll_length); + } + + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_join_columns_for_bka( + const key_range *start_key, + spider_string *str, + const char **table_aliases, + uint *table_alias_lengths +) { + KEY *key_info = spider->result_list.key_info; + uint length, key_name_length, key_count; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + char tmp_buf[MAX_FIELD_WIDTH]; + bool start_where = ((int) str->length() == where_pos); + DBUG_ENTER("spider_mysql_handler::append_key_join_columns_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + if (start_where) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + } else { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + + for ( + key_part = key_info->key_part, + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(length + table_alias_lengths[0] + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + table_alias_lengths[1] + SPIDER_SQL_PF_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(table_aliases[0], table_alias_lengths[0]); + str->q_append(tmp_buf, length); + str->q_append(SPIDER_SQL_PF_EQUAL_STR, SPIDER_SQL_PF_EQUAL_LEN); + str->q_append(table_aliases[1], table_alias_lengths[1]); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + str->length(str->length() - SPIDER_SQL_AND_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_tmp_table_and_sql_for_bka( + const key_range *start_key +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + char tmp_table_name[MAX_FIELD_WIDTH * 2], + tgt_table_name[MAX_FIELD_WIDTH * 2]; + int tmp_table_name_length; + spider_string tgt_table_name_str(tgt_table_name, MAX_FIELD_WIDTH * 2, + mysql_share->db_names_str[0].charset()); + const char *table_names[2], *table_aliases[2], *table_dot_aliases[2]; + uint table_name_lengths[2], table_alias_lengths[2], + table_dot_alias_lengths[2]; + tgt_table_name_str.init_calc_mem(99); + tgt_table_name_str.length(0); + create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, + first_link_idx); + if ((error_num = append_table_name_with_adjusting(&tgt_table_name_str, + first_link_idx, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + table_names[0] = tmp_table_name; + table_names[1] = tgt_table_name_str.c_ptr_safe(); + table_name_lengths[0] = tmp_table_name_length; + table_name_lengths[1] = tgt_table_name_str.length(); + table_aliases[0] = SPIDER_SQL_A_STR; + table_aliases[1] = SPIDER_SQL_B_STR; + table_alias_lengths[0] = SPIDER_SQL_A_LEN; + table_alias_lengths[1] = SPIDER_SQL_B_LEN; + table_dot_aliases[0] = SPIDER_SQL_A_DOT_STR; + table_dot_aliases[1] = SPIDER_SQL_B_DOT_STR; + table_dot_alias_lengths[0] = SPIDER_SQL_A_DOT_LEN; + table_dot_alias_lengths[1] = SPIDER_SQL_B_DOT_LEN; + if ( + (error_num = append_drop_tmp_bka_table( + &tmp_sql, tmp_table_name, tmp_table_name_length, + &tmp_sql_pos1, &tmp_sql_pos5, TRUE)) || + (error_num = append_create_tmp_bka_table( + start_key, + &tmp_sql, tmp_table_name, + tmp_table_name_length, + &tmp_sql_pos2, spider->share->table_share->table_charset)) || + (error_num = append_insert_tmp_bka_table( + start_key, + &tmp_sql, tmp_table_name, + tmp_table_name_length, &tmp_sql_pos3)) + ) + DBUG_RETURN(error_num); + tmp_sql_pos4 = tmp_sql.length(); + if ((error_num = spider_db_append_select(spider))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_A_DOT_LEN + SPIDER_SQL_ID_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_A_DOT_STR, SPIDER_SQL_A_DOT_LEN); + sql.q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ( + (error_num = append_select_columns_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) || + (error_num = spider_db_mysql_utility.append_from_with_alias(&sql, + table_names, table_name_lengths, + table_aliases, table_alias_lengths, 2, + &table_name_pos, FALSE)) + ) + DBUG_RETURN(error_num); + if ( + mysql_share->key_hint && + (error_num = spider_db_append_hint_after_table(spider, + &sql, &mysql_share->key_hint[spider->active_index])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = sql.length(); + if ( + (error_num = append_key_join_columns_for_bka( + start_key, &sql, + table_dot_aliases, table_dot_alias_lengths)) || + (error_num = append_condition_part( + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, + SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) || + ( + spider->result_list.direct_order_limit && + (error_num = append_key_order_for_direct_order_limit_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) + ) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_mysql_handler::reuse_tmp_table_and_sql_for_bka() +{ + DBUG_ENTER("spider_mysql_handler::reuse_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_sql.length(tmp_sql_pos4); + sql.length(limit_pos); + ha_sql.length(ha_limit_pos); + DBUG_RETURN(0); +} + +void spider_mysql_handler::create_tmp_bka_table_name( + char *tmp_table_name, + int *tmp_table_name_length, + int link_idx +) { + uint adjust_length = + mysql_share->db_nm_max_length - + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].length() + + mysql_share->table_nm_max_length - + mysql_share->table_names_str[spider->conn_link_idx[link_idx]].length(), + length; + DBUG_ENTER("spider_mysql_handler::create_tmp_bka_table_name"); + *tmp_table_name_length = mysql_share->db_nm_max_length + + mysql_share->table_nm_max_length; + memset(tmp_table_name, ' ', adjust_length); + tmp_table_name += adjust_length; + memcpy(tmp_table_name, mysql_share->db_names_str[link_idx].c_ptr(), + mysql_share->db_names_str[link_idx].length()); + tmp_table_name += mysql_share->db_names_str[link_idx].length(); + length = my_sprintf(tmp_table_name, (tmp_table_name, + "%s%s%p%s", SPIDER_SQL_DOT_STR, SPIDER_SQL_TMP_BKA_STR, spider, + SPIDER_SQL_UNDERSCORE_STR)); + *tmp_table_name_length += length; + tmp_table_name += length; + memcpy(tmp_table_name, + mysql_share->table_names_str[spider->conn_link_idx[link_idx]].c_ptr(), + mysql_share->table_names_str[spider->conn_link_idx[link_idx]].length()); + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::append_create_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + CHARSET_INFO *table_charset +) { + int error_num; + SPIDER_SHARE *share = spider->share; + THD *thd = spider->trx->thd; + char *bka_engine = spider_param_bka_engine(thd, share->bka_engine); + uint bka_engine_length = strlen(bka_engine), + cset_length = strlen(table_charset->csname), + coll_length = strlen(table_charset->name); + DBUG_ENTER("spider_mysql_handler::append_create_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_CREATE_TMP_LEN + tmp_table_name_length + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + SPIDER_SQL_ID_TYPE_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CREATE_TMP_STR, SPIDER_SQL_CREATE_TMP_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + str->q_append(SPIDER_SQL_ID_TYPE_STR, SPIDER_SQL_ID_TYPE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ((error_num = append_key_column_types(start_key, str))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_ENGINE_LEN + bka_engine_length + + SPIDER_SQL_DEF_CHARSET_LEN + cset_length + SPIDER_SQL_COLLATE_LEN + + coll_length + SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ENGINE_STR, SPIDER_SQL_ENGINE_LEN); + str->q_append(bka_engine, bka_engine_length); + str->q_append(SPIDER_SQL_DEF_CHARSET_STR, SPIDER_SQL_DEF_CHARSET_LEN); + str->q_append(table_charset->csname, cset_length); + str->q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str->q_append(table_charset->name, coll_length); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_drop_tmp_bka_table( + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + int *drop_table_end_pos, + bool with_semicolon +) { + DBUG_ENTER("spider_mysql_handler::append_drop_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_DROP_TMP_LEN + tmp_table_name_length + + (with_semicolon ? SPIDER_SQL_SEMICOLON_LEN : 0))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DROP_TMP_STR, SPIDER_SQL_DROP_TMP_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + *drop_table_end_pos = str->length(); + if (with_semicolon) + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_insert_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_insert_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_INSERT_LEN + SPIDER_SQL_INTO_LEN + + tmp_table_name_length + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ((error_num = spider_db_append_key_columns(start_key, spider, str))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_insert_for_recovery( + ulong sql_type, + int link_idx +) { + const TABLE *table = spider->get_table(); + SPIDER_SHARE *share = spider->share; + Field **field; + uint field_name_length = 0; + bool add_value = FALSE; + spider_string *insert_sql; + DBUG_ENTER("spider_mysql_handler::append_insert_for_recovery"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) + { + insert_sql = &spider->result_list.insert_sqls[link_idx]; + insert_sql->length(0); + } else { + insert_sql = &spider->result_list.update_sqls[link_idx]; + } + if (insert_sql->reserve( + SPIDER_SQL_INSERT_LEN + SPIDER_SQL_SQL_IGNORE_LEN + + SPIDER_SQL_INTO_LEN + mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + insert_sql->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + insert_sql->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + mysql_share->append_table_name(insert_sql, spider->conn_link_idx[link_idx]); + insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + field_name_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (insert_sql->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(insert_sql, (*field)->field_index); + insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (field_name_length) + insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); + if (insert_sql->reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + add_value = TRUE; + if ((*field)->is_null()) + { + if (insert_sql->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if ( + spider_db_mysql_utility. + append_column_value(spider, insert_sql, *field, NULL, + share->access_charset) || + insert_sql->reserve(SPIDER_SQL_COMMA_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (add_value) + insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); + if (insert_sql->reserve(SPIDER_SQL_CLOSE_PAREN_LEN, SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) + { + exec_insert_sql = insert_sql; + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_mysql_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_update(str, 0)) || + (error_num = append_update_set(str)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.update_sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_update(str, link_idx)) || + (error_num = append_update_set(str)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + + if ( + spider->pk_update && + share->link_statuses[link_idx] == SPIDER_LINK_STATUS_RECOVERY + ) { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + if ((error_num = append_insert_for_recovery( + SPIDER_SQL_TYPE_UPDATE_SQL, link_idx))) + DBUG_RETURN(error_num); + } + + if (!filled_up) + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_mysql_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, + first_link_idx)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + int error_num; + spider_string *str = &spider->result_list.update_sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, link_idx)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + if (!filled_up) + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_insert_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_insert_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_insert(&insert_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_insert( + spider_string *str, + int link_idx +) { + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_mysql_handler::append_insert"); + if ( + ( + spider->write_can_replace || + /* for direct_dup_insert without patch for partition */ + spider->sql_command == SQLCOM_REPLACE || + spider->sql_command == SQLCOM_REPLACE_SELECT + ) && + spider->direct_dup_insert + ) { + if (str->reserve(SPIDER_SQL_REPLACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_REPLACE_STR, SPIDER_SQL_REPLACE_LEN); + } else { + if (str->reserve(SPIDER_SQL_INSERT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + } + if (spider->low_priority) + { + if (str->reserve(SPIDER_SQL_LOW_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOW_PRIORITY_STR, SPIDER_SQL_LOW_PRIORITY_LEN); + } + else if (spider->insert_delayed) + { + if (share->internal_delayed) + { + if (str->reserve(SPIDER_SQL_SQL_DELAYED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_DELAYED_STR, SPIDER_SQL_SQL_DELAYED_LEN); + } + } + else if ( + spider->lock_type >= TL_WRITE && + !spider->write_can_replace && + /* for direct_dup_insert without patch for partition */ + spider->sql_command != SQLCOM_REPLACE && + spider->sql_command != SQLCOM_REPLACE_SELECT + ) { + if (str->reserve(SPIDER_SQL_HIGH_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HIGH_PRIORITY_STR, SPIDER_SQL_HIGH_PRIORITY_LEN); + } + if ( + spider->ignore_dup_key && + spider->direct_dup_insert && + !spider->write_can_replace && + !spider->insert_with_update && + /* for direct_dup_insert without patch for partition */ + spider->sql_command != SQLCOM_REPLACE && + spider->sql_command != SQLCOM_REPLACE_SELECT + ) { + if (str->reserve(SPIDER_SQL_SQL_IGNORE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_update_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_update_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update(&update_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_update( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_mysql_handler::append_update"); + if (str->reserve(SPIDER_SQL_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_UPDATE_STR, SPIDER_SQL_UPDATE_LEN); + if (spider->low_priority) + { + if (str->reserve(SPIDER_SQL_LOW_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOW_PRIORITY_STR, SPIDER_SQL_LOW_PRIORITY_LEN); + } + if ( + spider->ignore_dup_key && + !spider->insert_with_update + ) { + if (str->reserve(SPIDER_SQL_SQL_IGNORE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + } + if (str->reserve(mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, SPIDER_SQL_TYPE_UPDATE_SQL); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_delete_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_delete_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_delete(&update_sql); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_delete( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_delete"); + if (str->reserve(SPIDER_SQL_DELETE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DELETE_STR, SPIDER_SQL_DELETE_LEN); + if (spider->low_priority) + { + if (str->reserve(SPIDER_SQL_LOW_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOW_PRIORITY_STR, SPIDER_SQL_LOW_PRIORITY_LEN); + } + if (spider->quick_mode) + { + if (str->reserve(SPIDER_SQL_SQL_QUICK_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_QUICK_MODE_STR, + SPIDER_SQL_SQL_QUICK_MODE_LEN); + } + if (spider->ignore_dup_key) + { + if (str->reserve(SPIDER_SQL_SQL_IGNORE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + } + str->length(str->length() - 1); + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_mysql_handler::append_increment_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_increment_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_increment_update_set(&update_sql); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_increment_update_set( + spider_string *str +) { + uint field_name_length; + uint roop_count; + Field *field; + DBUG_ENTER("spider_mysql_handler::append_increment_update_set"); + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + const SPIDER_HS_STRING_REF *value = hs_upds.ptr(); + for (roop_count = 0; roop_count < hs_upds.size(); + roop_count++) + { + if ( + value[roop_count].size() == 1 && + *(value[roop_count].begin()) == '0' + ) + continue; + + Field *top_table_field = + spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); + if (!(field = spider->field_exchange(top_table_field))) + continue; + field_name_length = + mysql_share->column_name_str[field->field_index].length(); + + if (str->reserve(field_name_length * 2 + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 4 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_HS_INCREMENT_LEN + + SPIDER_SQL_COMMA_LEN + value[roop_count].size())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + mysql_share->append_column_name(str, field->field_index); + if (spider->hs_increment) + str->q_append(SPIDER_SQL_HS_INCREMENT_STR, + SPIDER_SQL_HS_INCREMENT_LEN); + else + str->q_append(SPIDER_SQL_HS_DECREMENT_STR, + SPIDER_SQL_HS_DECREMENT_LEN); + str->q_append(value[roop_count].begin(), value[roop_count].size()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} +#endif +#endif + +int spider_mysql_handler::append_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update_set(&update_sql); + where_pos = update_sql.length(); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_update_set( + spider_string *str +) { + uint field_name_length; + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + Field **fields; + DBUG_ENTER("spider_mysql_handler::append_update_set"); + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + for (fields = table->field; *fields; fields++) + { + if (bitmap_is_set(table->write_set, (*fields)->field_index)) + { + field_name_length = + mysql_share->column_name_str[(*fields)->field_index].length(); + if ((*fields)->is_null()) + { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*fields)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*fields)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, + table->read_set); +#endif + if ( + spider_db_mysql_utility. + append_column_value(spider, str, *fields, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_mysql_handler::append_direct_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::append_direct_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_direct_update_set(&update_sql); + where_pos = update_sql.length(); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_direct_update_set( + spider_string *str +) { + uint field_name_length; + SPIDER_SHARE *share = spider->share; +#ifndef DBUG_OFF + TABLE *table = spider->get_table(); +#endif + DBUG_ENTER("spider_mysql_handler::append_direct_update_set"); + if ( + spider->direct_update_kinds == SPIDER_SQL_KIND_SQL && + spider->direct_update_fields + ) { + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + DBUG_RETURN(spider_db_append_update_columns(spider, str, NULL, 0, + spider_dbton_mysql.dbton_id)); + } + + if ( + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + ) { + size_t roop_count; + Field *field; + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + for (roop_count = 0; roop_count < spider->hs_pushed_ret_fields_num; + roop_count++) + { + Field *top_table_field = + spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); + if (!(field = spider->field_exchange(top_table_field))) + continue; + field_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (top_table_field->is_null()) + { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, + table->read_set); +#endif + if ( + spider_db_mysql_utility. + append_column_value(spider, str, top_table_field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_dup_update_pushdown_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_dup_update_pushdown_part"); + DBUG_PRINT("info",("spider this=%p", this)); + dup_update_sql.length(0); + error_num = append_update_columns(&dup_update_sql, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_update_columns_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update_columns(&update_sql, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::check_update_columns_part() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::check_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update_columns(NULL, NULL, 0); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_update_columns( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_update_columns"); + error_num = spider_db_append_update_columns(spider, str, + alias, alias_length, spider_dbton_mysql.dbton_id); + DBUG_RETURN(error_num); +} +#endif + +int spider_mysql_handler::append_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_select(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_select( + spider_string *str, + ulong sql_type +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_mysql_handler::append_select"); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + if (str->reserve(SPIDER_SQL_HANDLER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + } else { + if (str->reserve(SPIDER_SQL_SELECT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + if (result_list->lock_type != F_WRLCK && spider->lock_mode < 1) + { + /* no lock */ + if (spider->share->query_cache == 1) + { + if (str->reserve(SPIDER_SQL_SQL_CACHE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_CACHE_STR, SPIDER_SQL_SQL_CACHE_LEN); + } else if (spider->share->query_cache == 2) + { + if (str->reserve(SPIDER_SQL_SQL_NO_CACHE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_NO_CACHE_STR, + SPIDER_SQL_SQL_NO_CACHE_LEN); + } + } + if (spider->high_priority) + { + if (str->reserve(SPIDER_SQL_HIGH_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HIGH_PRIORITY_STR, + SPIDER_SQL_HIGH_PRIORITY_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_table_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_table_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_table_select(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_table_select( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_table_select"); + table_name_pos = str->length() + mysql_share->table_select_pos; + if (str->append(*(mysql_share->table_select))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_select_part( + ulong sql_type, + uint idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_key_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_select(str, idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_select( + spider_string *str, + uint idx +) { + DBUG_ENTER("spider_mysql_handler::append_key_select"); + table_name_pos = str->length() + mysql_share->key_select_pos[idx]; + if (str->append(mysql_share->key_select[idx])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_minimum_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_minimum_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_minimum_select(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_minimum_select( + spider_string *str, + ulong sql_type +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + DBUG_ENTER("spider_mysql_handler::append_minimum_select"); + for (field = table->field; *field; field++) + { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + else { + if (str->reserve(SPIDER_SQL_ONE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); + } + DBUG_RETURN(append_from(str, sql_type, first_link_idx)); +} + +int spider_mysql_handler::append_table_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + DBUG_ENTER("spider_mysql_handler::append_table_select_with_alias"); + for (field = table->field; *field; field++) + { + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_select_with_alias( + spider_string *str, + const KEY *key_info, + const char *alias, + uint alias_length +) { + KEY_PART_INFO *key_part; + Field *field; + uint part_num; + int field_length; + DBUG_ENTER("spider_mysql_handler::append_key_select_with_alias"); + for (key_part = key_info->key_part, part_num = 0; + part_num < key_info->key_parts; key_part++, part_num++) + { + field = key_part->field; + field_length = mysql_share->column_name_str[field->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_minimum_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + DBUG_ENTER("spider_mysql_handler::append_minimum_select_with_alias"); + for (field = table->field; *field; field++) + { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + else { + if (str->reserve(SPIDER_SQL_ONE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_select_columns_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_mysql_handler::append_select_columns_with_alias"); + if ((error_num = append_match_select(str, alias, alias_length))) + DBUG_RETURN(error_num); + if (!spider->select_column_mode) + { + if (result_list->keyread) + DBUG_RETURN(append_key_select_with_alias( + str, result_list->key_info, alias, alias_length)); + else + DBUG_RETURN(append_table_select_with_alias( + str, alias, alias_length)); + } + DBUG_RETURN(append_minimum_select_with_alias(str, alias, alias_length)); +} + +int spider_mysql_handler::append_hint_after_table_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_hint_after_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_hint_after_table(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_hint_after_table( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_hint_after_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + mysql_share->key_hint && + (error_num = spider_db_append_hint_after_table(spider, + str, &mysql_share->key_hint[spider->active_index])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +void spider_mysql_handler::set_where_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::set_where_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + where_pos = sql.length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + where_pos = update_sql.length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_read_pos = ha_sql.length(); + break; + default: + break; + } + DBUG_VOID_RETURN; +} + +void spider_mysql_handler::set_where_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::set_where_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + sql.length(where_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + update_sql.length(where_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_sql.length(ha_read_pos); + break; + default: + break; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::check_item_type( + Item *item +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::check_item_type"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_print_item_type(item, spider, NULL, NULL, 0, + spider_dbton_mysql.dbton_id); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_values_connector_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_values_connector_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_values_connector(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_values_connector( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_values_connector"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_COMMA_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_values_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_values_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_values_terminator(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_values_terminator( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_values_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - + SPIDER_SQL_COMMA_LEN - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_column_values_part( + const key_range *start_key, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_key_column_values_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_column_values(str, start_key); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_column_values( + spider_string *str, + const key_range *start_key +) { + int error_num; + const uchar *ptr; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; + KEY *key_info = result_list->key_info; + uint length; + uint store_length; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_mysql_handler::append_key_column_values"); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + for ( + key_part = key_info->key_part, + length = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + length += store_length + ) { + store_length = key_part->store_length; + ptr = start_key->key + length; + field = key_part->field; + if ((error_num = spider_db_append_null_value(str, key_part, &ptr))) + { + if (error_num > 0) + DBUG_RETURN(error_num); + } else { + if (spider_db_mysql_utility.append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + bool set_order; + DBUG_ENTER("spider_mysql_handler::append_key_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + set_order = FALSE; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + set_order = FALSE; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_read_pos = str->length(); + str_part = &sql_part; + str_part2 = &sql_part2; + str_part->length(0); + str_part2->length(0); + set_order = TRUE; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_where(str, str_part, str_part2, start_key, end_key, + sql_type, set_order); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_key_where"); + error_num = spider_db_append_key_where_internal(str, str_part, str_part2, + start_key, end_key, spider, set_order, sql_type, + spider_dbton_mysql.dbton_id); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + DBUG_ENTER("spider_mysql_handler::append_is_null_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str_part = &sql_part; + str_part2 = &sql_part2; + break; + default: + DBUG_RETURN(0); + } + error_num = append_is_null(sql_type, str, str_part, str_part2, + key_part, key, ptr, key_eq); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + DBUG_ENTER("spider_mysql_handler::append_is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + if (key_part->null_bit) + { + if (*(*ptr)++) + { + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + str = str_part; + if ( + key_eq || + key->flag == HA_READ_KEY_EXACT || + key->flag == HA_READ_KEY_OR_NEXT + ) { + if (str->reserve(SPIDER_SQL_IS_NULL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + ha_next_pos = str->length(); + if (str->reserve(SPIDER_SQL_FIRST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); + spider->result_list.ha_read_kind = 1; + } + str = str_part2; + } + if ( + key_eq || + key->flag == HA_READ_KEY_EXACT || + key->flag == HA_READ_KEY_OR_NEXT + ) { + if (str->reserve(SPIDER_SQL_IS_NULL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + mysql_share->column_name_str[key_part->field->field_index].length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, key_part->field->field_index); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + if (str->reserve(SPIDER_SQL_IS_NOT_NULL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + mysql_share->column_name_str[key_part->field->field_index].length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, key_part->field->field_index); + str->q_append(SPIDER_SQL_IS_NOT_NULL_STR, SPIDER_SQL_IS_NOT_NULL_LEN); + } + DBUG_RETURN(-1); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + DBUG_ENTER("spider_mysql_handler::append_where_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str_part = &sql_part; + str_part2 = &sql_part2; + break; + default: + DBUG_RETURN(0); + } + error_num = append_where_terminator(sql_type, str, str_part, str_part2, + set_order, key_count); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_where_terminator( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + bool set_order, + int key_count +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_mysql_handler::append_where_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type != SPIDER_SQL_TYPE_HANDLER) + { + str->length(str->length() - SPIDER_SQL_AND_LEN); + if (!set_order) + result_list->key_order = key_count; + } else { + str_part2->length(str_part2->length() - SPIDER_SQL_AND_LEN); + + str_part->length(str_part->length() - SPIDER_SQL_COMMA_LEN); + if (!result_list->ha_read_kind) + str_part->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + if (str->append(*str_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + uint clause_length = str->length() - ha_next_pos; + if (clause_length < SPIDER_SQL_NEXT_LEN) + { + int roop_count; + clause_length = SPIDER_SQL_NEXT_LEN - clause_length; + if (str->reserve(clause_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + for (roop_count = 0; roop_count < (int) clause_length; roop_count++) + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_match_where_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_match_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_ASSERT(0); + DBUG_RETURN(0); + } + error_num = append_match_where(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_match_where( + spider_string *str +) { + int error_num; + bool first = TRUE; + st_spider_ft_info *ft_info = spider->ft_first; + DBUG_ENTER("spider_mysql_handler::append_match_where"); + if (spider->ft_current) + { + while (TRUE) + { + if (ft_info->used_in_where) + { + if (first) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + first = FALSE; + } + if ((error_num = append_match_against(str, ft_info, NULL, 0))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + + if (ft_info == spider->ft_current) + break; + ft_info = ft_info->next; + } + if (!first) + str->length(str->length() - SPIDER_SQL_AND_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_update_where( + spider_string *str, + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + uint field_name_length; + Field **field; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_mysql_handler::append_update_where"); + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + for (field = table->field; *field; field++) + { + if ( + table->s->primary_key == MAX_KEY || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { + field_name_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if ((*field)->is_null(ptr_diff)) + { + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_IS_NULL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + (*field)->move_field_offset(ptr_diff); + if ( + spider_db_mysql_utility. + append_column_value(spider, str, *field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_AND_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + (*field)->move_field_offset(-ptr_diff); + } + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + } + str->length(str->length() - SPIDER_SQL_AND_LEN); + if (str->reserve(SPIDER_SQL_LIMIT1_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LIMIT1_STR, SPIDER_SQL_LIMIT1_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg +) { + int error_num; + spider_string *str; + bool start_where = FALSE; + DBUG_ENTER("spider_mysql_handler::append_condition_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + if (test_flg) + { + str = NULL; + } else { + str = &sql; + start_where = ((int) str->length() == where_pos); + } + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + if (test_flg) + { + str = NULL; + } else { + str = &update_sql; + start_where = ((int) str->length() == where_pos); + } + break; + case SPIDER_SQL_TYPE_HANDLER: + if (test_flg) + { + str = NULL; + } else { + str = &ha_sql; + start_where = TRUE; + if (spider->active_index == MAX_KEY) + { + set_where_pos(SPIDER_SQL_TYPE_HANDLER); + if (str->reserve(SPIDER_SQL_READ_LEN + SPIDER_SQL_FIRST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_READ_STR, SPIDER_SQL_READ_LEN); + ha_next_pos = str->length(); + str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); + sql_part2.length(0); + } + ha_where_pos = str->length(); + + if (sql_part2.length()) + { + str->append(sql_part2); + start_where = FALSE; + } + } + break; + default: + DBUG_RETURN(0); + } + error_num = append_condition(str, alias, alias_length, start_where, + sql_type); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_condition( + spider_string *str, + const char *alias, + uint alias_length, + bool start_where, + ulong sql_type +) { + int error_num, restart_pos = 0, start_where_pos; + SPIDER_CONDITION *tmp_cond = spider->condition; + DBUG_ENTER("spider_mysql_handler::append_condition"); + if (str && start_where) + { + start_where_pos = str->length(); + } else { + start_where_pos = 0; + } + + if (spider->is_clone && !tmp_cond) + { + tmp_cond = spider->pt_clone_source_handler->condition; + } + + while (tmp_cond) + { + if (str) + { + restart_pos = str->length(); + if (start_where) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + start_where = FALSE; + } else { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + } + if ((error_num = spider_db_print_item_type( + (Item *) tmp_cond->cond, spider, str, alias, alias_length, + spider_dbton_mysql.dbton_id))) + { + if (str && error_num == ER_SPIDER_COND_SKIP_NUM) + { + DBUG_PRINT("info",("spider COND skip")); + str->length(restart_pos); + start_where = (restart_pos == start_where_pos); + } else + DBUG_RETURN(error_num); + } + tmp_cond = tmp_cond->next; + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_match_against_part( + ulong sql_type, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_match_against_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_match_against(str, ft_info, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_match_against( + spider_string *str, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length +) { + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + String *ft_init_key; + KEY *key_info; + uint key_name_length; + int key_count; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_mysql_handler::append_match_against"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + + ft_init_key = ft_info->key; + key_info = &table->key_info[ft_info->inx]; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", + key_info->key_parts)); + + for ( + key_part = key_info->key_part, + key_count = 0; + key_count < (int) key_info->key_parts; + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (alias_length) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + } else { + if (str->reserve(key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_AGAINST_LEN + SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, share->access_charset); + tmp_str.init_calc_mem(116); + tmp_str.length(0); + if ( + tmp_str.append(ft_init_key->ptr(), ft_init_key->length(), + ft_init_key->charset()) || + str->reserve(tmp_str.length() * 2) || + spider_db_mysql_utility.append_escaped_util(str, tmp_str.get_str()) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->mem_calc(); + + if (str->reserve( + SPIDER_SQL_VALUE_QUOTE_LEN + SPIDER_SQL_CLOSE_PAREN_LEN + + ((ft_info->flags & FT_BOOL) ? SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((ft_info->flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (ft_info->flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (ft_info->flags & FT_EXPAND) + str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_match_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_match_select(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_match_select( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_match_select"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->ft_current) + { + st_spider_ft_info *ft_info = spider->ft_first; + while (TRUE) + { + if ((error_num = append_match_against(str, ft_info, + alias, alias_length))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if (ft_info == spider->ft_current) + break; + ft_info = ft_info->next; + } + } + DBUG_RETURN(0); +} + +void spider_mysql_handler::set_order_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::set_order_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + order_pos = sql.length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + order_pos = update_sql.length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_next_pos = ha_sql.length(); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +void spider_mysql_handler::set_order_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::set_order_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + sql.length(order_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + update_sql.length(order_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_sql.length(ha_next_pos); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_key_order_for_merge_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_limit_pos = ha_sql.length(); + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_for_merge_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_order_for_merge_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + /* sort for index merge */ + TABLE *table = spider->get_table(); + int length; + Field *field; + uint key_name_length; + DBUG_ENTER("spider_mysql_handler::append_key_order_for_merge_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (table->s->primary_key < MAX_KEY) + { + /* sort by primary key */ + KEY *key_info = &table->key_info[table->s->primary_key]; + KEY_PART_INFO *key_part; + for ( + key_part = key_info->key_part, + length = 1; + length <= (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (length > 1) + { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + } else { + /* sort by all columns */ + Field **fieldp; + for ( + fieldp = table->field, length = 1; + *fieldp; + fieldp++, length++ + ) { + key_name_length = + mysql_share->column_name_str[(*fieldp)->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, (*fieldp)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (length > 1) + { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_key_order_for_direct_order_limit_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_for_direct_order_limit_with_alias( + str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_order_for_direct_order_limit_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + ORDER *order; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + DBUG_ENTER("spider_mysql_handler::append_key_order_for_direct_order_limit_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_get_select_limit(spider, &select_lex, &select_limit, + &offset_limit); + if (select_lex->order_list.first) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if ((error_num = + spider_db_print_item_type((*order->item), spider, str, alias, + alias_length, spider_dbton_mysql.dbton_id))) + { + DBUG_PRINT("info",("spider error=%d", error_num)); + DBUG_RETURN(error_num); + } + if (order->asc) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_key_order_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + error_num = append_key_order_for_handler(str, alias, alias_length); + DBUG_RETURN(error_num); + default: + DBUG_RETURN(0); + } + error_num = append_key_order_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_key_order_for_handler( + spider_string *str, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_mysql_handler::append_key_order_for_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider ha_next_pos=%d", ha_next_pos)); + DBUG_PRINT("info",("spider ha_where_pos=%d", ha_where_pos)); + str->q_append(alias, alias_length); + memset((char *) str->ptr() + str->length(), ' ', + ha_where_pos - ha_next_pos - alias_length); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_key_order_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + KEY *key_info = result_list->key_info; + int length; + KEY_PART_INFO *key_part; + Field *field; + uint key_name_length; + DBUG_ENTER("spider_mysql_handler::append_key_order_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (result_list->sorted == TRUE) + { + if (result_list->desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order < (int) key_info->key_parts && + length < result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ( + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order < (int) key_info->key_parts && + length < result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ( + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order + ) { + field = key_part->field; + key_name_length = + mysql_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + } + } + } + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_limit_pos = str->length(); + break; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::reappend_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str->length(ha_limit_pos); + break; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_limit( + spider_string *str, + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_mysql_handler::append_limit"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info", ("spider offset=%lld", offset)); + DBUG_PRINT("info", ("spider limit=%lld", limit)); + if (offset || limit < 9223372036854775807LL) + { + if (str->reserve(SPIDER_SQL_LIMIT_LEN + SPIDER_SQL_COMMA_LEN + + ((SPIDER_LONGLONG_LEN) * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN); + if (offset) + { + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset); + str->q_append(buf, length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + str->q_append(buf, length); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_select_lock_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_select_lock_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_select_lock(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_select_lock( + spider_string *str +) { + int lock_mode = spider_conn_lock_mode(spider); + DBUG_ENTER("spider_mysql_handler::append_select_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (str->reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (str->reserve(SPIDER_SQL_SHARED_LOCK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SHARED_LOCK_STR, SPIDER_SQL_SHARED_LOCK_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_union_all_start_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_union_all_start_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all_start(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_union_all_start( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_union_all_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_union_all_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_union_all_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_union_all( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_union_all"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_UNION_ALL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_UNION_ALL_STR, SPIDER_SQL_UNION_ALL_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_union_all_end_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_union_all_end_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all_end(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_union_all_end( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_union_all_end"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - + SPIDER_SQL_UNION_ALL_LEN + SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_multi_range_cnt_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_multi_range_cnt(str, multi_range_cnt, with_comma); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_multi_range_cnt( + spider_string *str, + uint multi_range_cnt, + bool with_comma +) { + int range_cnt_length; + char range_cnt_str[SPIDER_SQL_INT_LEN]; + DBUG_ENTER("spider_mysql_handler::append_multi_range_cnt"); + DBUG_PRINT("info",("spider this=%p", this)); + range_cnt_length = my_sprintf(range_cnt_str, (range_cnt_str, "%u", + multi_range_cnt)); + if (with_comma) + { + if (str->reserve(range_cnt_length + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(range_cnt_str, range_cnt_length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(range_cnt_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(range_cnt_str, range_cnt_length); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_open_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_open_handler(str, handler_id, conn, link_idx); + exec_ha_sql = str; + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_open_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + DBUG_PRINT("info",("spider m_handler_cid=%s", + spider->m_handler_cid[link_idx])); + if (str->reserve(SPIDER_SQL_HANDLER_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + if ((error_num = mysql_share->append_table_name(str, + spider->conn_link_idx[link_idx]))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_OPEN_LEN + SPIDER_SQL_AS_LEN + + SPIDER_SQL_HANDLER_CID_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_STR, SPIDER_SQL_OPEN_LEN); + str->q_append(SPIDER_SQL_AS_STR, SPIDER_SQL_AS_LEN); + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_close_handler_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_close_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_close_handler(str, link_idx); + exec_ha_sql = str; + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_close_handler( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_mysql_handler::append_close_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_HANDLER_LEN + SPIDER_SQL_CLOSE_LEN + + SPIDER_SQL_HANDLER_CID_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + str->q_append(spider->m_handler_cid[link_idx], + SPIDER_SQL_HANDLER_CID_LEN); + str->q_append(SPIDER_SQL_CLOSE_STR, SPIDER_SQL_CLOSE_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_insert_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_insert_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_insert_terminator(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_insert_terminator( + spider_string *str +) { + DBUG_ENTER("spider_mysql_handler::append_insert_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->result_list.insert_dup_update_pushdown) + { + DBUG_PRINT("info",("spider add duplicate key update")); + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN + + dup_update_sql.length())) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_DUPLICATE_KEY_UPDATE_STR, + SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN); + if (str->append(dup_update_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_insert_values_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_insert_values_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_insert_values(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_insert_values( + spider_string *str +) { + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + Field **field; + bool add_value = FALSE; + DBUG_ENTER("spider_mysql_handler::append_insert_values"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + DBUG_PRINT("info",("spider field_index=%u", (*field)->field_index)); + if ( + bitmap_is_set(table->write_set, (*field)->field_index) || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->read_set); +#endif + add_value = TRUE; + DBUG_PRINT("info",("spider is_null()=%s", + (*field)->is_null() ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider table->next_number_field=%p", + table->next_number_field)); + DBUG_PRINT("info",("spider *field=%p", *field)); + DBUG_PRINT("info",("spider force_auto_increment=%s", + (table->next_number_field && spider->force_auto_increment) ? + "TRUE" : "FALSE")); + if ( + (*field)->is_null() || + ( + table->next_number_field == *field && + !table->auto_increment_field_not_null && + !spider->force_auto_increment + ) + ) { + if (str->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if ( + spider_db_mysql_utility. + append_column_value(spider, str, *field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + } + if (add_value) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_into_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_into_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_into(str); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_into( + spider_string *str +) { + const TABLE *table = spider->get_table(); + Field **field; + uint field_name_length = 0; + DBUG_ENTER("spider_mysql_handler::append_into"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_INTO_LEN + mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + insert_table_name_pos = str->length(); + append_table_name_with_adjusting(str, first_link_idx, + SPIDER_SQL_TYPE_INSERT_SQL); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + if ( + bitmap_is_set(table->write_set, (*field)->field_index) || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { + field_name_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if (field_name_length) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_VALUES_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + insert_pos = str->length(); + DBUG_RETURN(0); +} + +void spider_mysql_handler::set_insert_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::set_insert_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + insert_sql.length(insert_pos); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::append_from_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_from_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + default: + str = &sql; + break; + } + error_num = append_from(str, sql_type, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_from( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_mysql_handler::append_from"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + ha_table_name_pos = str->length(); + DBUG_PRINT("info",("spider ha_table_name_pos=%u", ha_table_name_pos)); + ha_sql_handler_id = spider->m_handler_id[link_idx]; + DBUG_PRINT("info",("spider ha_sql_handler_id=%u", ha_sql_handler_id)); + if (str->reserve(SPIDER_SQL_HANDLER_CID_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + DBUG_PRINT("info",("spider m_handler_cid=%s", + spider->m_handler_cid[link_idx])); + } else { + if (str->reserve(SPIDER_SQL_FROM_LEN + mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, sql_type); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_flush_tables_part( + ulong sql_type, + int link_idx, + bool lock +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_flush_tables_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_flush_tables(str, link_idx, lock); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_flush_tables( + spider_string *str, + int link_idx, + bool lock +) { + DBUG_ENTER("spider_mysql_handler::append_flush_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if (lock) + { + if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN + + SPIDER_SQL_WITH_READ_LOCK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); + str->q_append(SPIDER_SQL_WITH_READ_LOCK_STR, + SPIDER_SQL_WITH_READ_LOCK_LEN); + } else { + if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_optimize_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_optimize_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_optimize_table(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_optimize_table( + spider_string *str, + int link_idx +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mysql_handler::append_optimize_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_OPTIMIZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_OPTIMIZE_STR, SPIDER_SQL_SQL_OPTIMIZE_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_analyze_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_analyze_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_analyze_table(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_analyze_table( + spider_string *str, + int link_idx +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mysql_handler::append_analyze_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ANALYZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ANALYZE_STR, SPIDER_SQL_SQL_ANALYZE_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_repair_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_repair_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_repair_table(str, link_idx, check_opt); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_repair_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mysql_handler::append_repair_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_REPAIR_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_REPAIR_STR, SPIDER_SQL_SQL_REPAIR_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + if (check_opt->flags & T_QUICK) + { + if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (check_opt->flags & T_EXTEND) + { + if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); + } + if (check_opt->sql_flags & TT_USEFRM) + { + if (str->reserve(SPIDER_SQL_SQL_USE_FRM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_USE_FRM_STR, SPIDER_SQL_SQL_USE_FRM_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_check_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_check_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_check_table(str, link_idx, check_opt); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_check_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::append_check_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_CHECK_TABLE_LEN + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_CHECK_TABLE_STR, + SPIDER_SQL_SQL_CHECK_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + if (check_opt->flags & T_QUICK) + { + if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (check_opt->flags & T_FAST) + { + if (str->reserve(SPIDER_SQL_SQL_FAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_FAST_STR, SPIDER_SQL_SQL_FAST_LEN); + } + if (check_opt->flags & T_MEDIUM) + { + if (str->reserve(SPIDER_SQL_SQL_MEDIUM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_MEDIUM_STR, SPIDER_SQL_SQL_MEDIUM_LEN); + } + if (check_opt->flags & T_EXTEND) + { + if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_enable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_enable_keys_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_enable_keys(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_enable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::append_enable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_ENABLE_KEYS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, + SPIDER_SQL_SQL_ALTER_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + str->q_append(SPIDER_SQL_SQL_ENABLE_KEYS_STR, + SPIDER_SQL_SQL_ENABLE_KEYS_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_disable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_disable_keys_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_disable_keys(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_disable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::append_disable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + + mysql_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + mysql_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_DISABLE_KEYS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, + SPIDER_SQL_SQL_ALTER_TABLE_LEN); + mysql_share->append_table_name(str, conn_link_idx); + str->q_append(SPIDER_SQL_SQL_DISABLE_KEYS_STR, + SPIDER_SQL_SQL_DISABLE_KEYS_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_delete_all_rows_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_delete_all_rows_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_DELETE_SQL: + str = &update_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_delete_all_rows(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_delete_all_rows( + spider_string *str, + ulong sql_type +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_delete_all_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->sql_command == SQLCOM_TRUNCATE) + { + if ((error_num = append_truncate(str, sql_type, first_link_idx))) + DBUG_RETURN(error_num); + } else { + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, sql_type, first_link_idx)) + ) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_truncate( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_mysql_handler::append_truncate"); + if (str->reserve(SPIDER_SQL_TRUNCATE_TABLE_LEN + + mysql_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + mysql_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_TRUNCATE_TABLE_STR, SPIDER_SQL_TRUNCATE_TABLE_LEN); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, sql_type); + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_explain_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = + append_explain_select(str, start_key, end_key, sql_type, link_idx); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::append_explain_select( + spider_string *str, + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::append_explain_select"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_EXPLAIN_SELECT_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_EXPLAIN_SELECT_STR, SPIDER_SQL_EXPLAIN_SELECT_LEN); + if ( + (error_num = append_from(str, sql_type, link_idx)) || + (error_num = append_key_where(str, NULL, NULL, start_key, end_key, + sql_type, FALSE)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_RETURN(0); +} + +bool spider_mysql_handler::is_bulk_insert_exec_period( + bool bulk_end +) { + DBUG_ENTER("spider_mysql_handler::is_bulk_insert_exec_period"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider insert_sql.length=%u", insert_sql.length())); + DBUG_PRINT("info",("spider insert_pos=%d", insert_pos)); + DBUG_PRINT("info",("spider insert_sql=%s", insert_sql.c_ptr_safe())); + if ( + (bulk_end || (int) insert_sql.length() >= spider->bulk_size) && + (int) insert_sql.length() > insert_pos + ) { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +bool spider_mysql_handler::sql_is_filled_up( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::sql_is_filled_up"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(filled_up); +} + +bool spider_mysql_handler::sql_is_empty( + ulong sql_type +) { + bool is_empty; + DBUG_ENTER("spider_mysql_handler::sql_is_empty"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + is_empty = (sql.length() == 0); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + is_empty = (insert_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + is_empty = (update_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + is_empty = (tmp_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_HANDLER: + is_empty = (ha_sql.length() == 0); + break; + default: + is_empty = TRUE; + break; + } + DBUG_RETURN(is_empty); +} + +bool spider_mysql_handler::support_multi_split_read() +{ + DBUG_ENTER("spider_mysql_handler::support_multi_split_read"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_mysql_handler::support_bulk_update() +{ + DBUG_ENTER("spider_mysql_handler::support_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_mysql_handler::bulk_tmp_table_insert() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = store_sql_to_bulk_tmp_table(&update_sql, upd_tmp_tbl); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::bulk_tmp_table_insert( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = store_sql_to_bulk_tmp_table( + &spider->result_list.update_sqls[link_idx], + spider->result_list.upd_tmp_tbls[link_idx]); + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::bulk_tmp_table_end_bulk_insert() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_end_bulk_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = upd_tmp_tbl->file->ha_end_bulk_insert())) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::bulk_tmp_table_rnd_init() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_rnd_init"); + DBUG_PRINT("info",("spider this=%p", this)); + upd_tmp_tbl->file->extra(HA_EXTRA_CACHE); + if ((error_num = upd_tmp_tbl->file->ha_rnd_init(TRUE))) + { + DBUG_RETURN(error_num); + } + reading_from_bulk_tmp_table = TRUE; + DBUG_RETURN(0); +} + +int spider_mysql_handler::bulk_tmp_table_rnd_next() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); +#else + error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); +#endif + if (!error_num) + { + error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); + } + DBUG_RETURN(error_num); +} + +int spider_mysql_handler::bulk_tmp_table_rnd_end() +{ + int error_num; + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_rnd_end"); + DBUG_PRINT("info",("spider this=%p", this)); + reading_from_bulk_tmp_table = FALSE; + if ((error_num = upd_tmp_tbl->file->ha_rnd_end())) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +bool spider_mysql_handler::need_copy_for_update( + int link_idx +) { + int all_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::need_copy_for_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(!mysql_share->same_db_table_name || + spider->share->link_statuses[all_link_idx] == SPIDER_LINK_STATUS_RECOVERY); +} + +bool spider_mysql_handler::bulk_tmp_table_created() +{ + DBUG_ENTER("spider_mysql_handler::bulk_tmp_table_created"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(upd_tmp_tbl); +} + +int spider_mysql_handler::mk_bulk_tmp_table_and_bulk_start() +{ + THD *thd = spider->trx->thd; + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_mysql_handler::mk_bulk_tmp_table_and_bulk_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!upd_tmp_tbl) + { + if (!(upd_tmp_tbl = spider_mk_sys_tmp_table( + thd, table, &upd_tmp_tbl_prm, "a", update_sql.charset()))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + upd_tmp_tbl->file->extra(HA_EXTRA_WRITE_CACHE); + upd_tmp_tbl->file->ha_start_bulk_insert((ha_rows) 0); + } + DBUG_RETURN(0); +} + +void spider_mysql_handler::rm_bulk_tmp_table() +{ + DBUG_ENTER("spider_mysql_handler::rm_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (upd_tmp_tbl) + { + spider_rm_sys_tmp_table(spider->trx->thd, upd_tmp_tbl, &upd_tmp_tbl_prm); + upd_tmp_tbl = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mysql_handler::store_sql_to_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::store_sql_to_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_table->field[0]->set_notnull(); + tmp_table->field[0]->store(str->ptr(), str->length(), str->charset()); + if ((error_num = tmp_table->file->ha_write_row(tmp_table->record[0]))) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_mysql_handler::restore_sql_from_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + DBUG_ENTER("spider_mysql_handler::restore_sql_from_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_table->field[0]->val_str(str->get_str()); + str->mem_calc(); + DBUG_RETURN(0); +} + +int spider_mysql_handler::insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_mysql *db_conn = (spider_db_mysql *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash2 = &link_for_hash[link_idx]; + DBUG_ENTER("spider_mysql_handler::insert_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + uint old_elements = + db_conn->lock_table_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2)) +#else + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) +#endif + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->lock_table_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->lock_table_hash, + (db_conn->lock_table_hash.array.max_element - old_elements) * + db_conn->lock_table_hash.array.size_of_element); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended +) { + int error_num; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash, *tmp_link_for_hash2; + int conn_link_idx = spider->conn_link_idx[link_idx]; + spider_db_mysql *db_conn = (spider_db_mysql *) conn->db_conn; + DBUG_ENTER("spider_mysql_handler::append_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_link_for_hash2 = &link_for_hash[link_idx]; + tmp_link_for_hash2->db_table_str = + &mysql_share->db_table_str[conn_link_idx]; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + tmp_link_for_hash2->db_table_str_hash_value = + mysql_share->db_table_str_hash_value[conn_link_idx]; + if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) + my_hash_search_using_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2->db_table_str->ptr(), + tmp_link_for_hash2->db_table_str->length()))) +#else + if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) my_hash_search( + &db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2->db_table_str->ptr(), + tmp_link_for_hash2->db_table_str->length()))) +#endif + { + if ((error_num = insert_lock_tables_list(conn, link_idx))) + DBUG_RETURN(error_num); + *appended = 1; + } else { + if (tmp_link_for_hash->spider->lock_type < spider->lock_type) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash->db_table_str_hash_value, + (uchar*) tmp_link_for_hash); +#else + my_hash_delete(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash); +#endif + uint old_elements = + db_conn->lock_table_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2)) +#else + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) +#endif + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->lock_table_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->lock_table_hash, + (db_conn->lock_table_hash.array.max_element - old_elements) * + db_conn->lock_table_hash.array.size_of_element); + } + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::realloc_sql( + ulong *realloced +) { + THD *thd = spider->trx->thd; + st_spider_share *share = spider->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + DBUG_ENTER("spider_mysql_handler::realloc_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((int) sql.alloced_length() > init_sql_alloc_size * 2) + { + sql.free(); + if (sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; + } + if ((int) ha_sql.alloced_length() > init_sql_alloc_size * 2) + { + ha_sql.free(); + if (ha_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; + } + if ((int) dup_update_sql.alloced_length() > init_sql_alloc_size * 2) + { + dup_update_sql.free(); + if (dup_update_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if ((int) insert_sql.alloced_length() > init_sql_alloc_size * 2) + { + insert_sql.free(); + if (insert_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_INSERT_SQL; + } + if ((int) update_sql.alloced_length() > init_sql_alloc_size * 2) + { + update_sql.free(); + if (update_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL); + } + update_sql.length(0); + if ((int) tmp_sql.alloced_length() > init_sql_alloc_size * 2) + { + tmp_sql.free(); + if (tmp_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_TMP_SQL; + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::reset_sql( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::reset_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + { + sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) + { + insert_sql.length(0); + } + if (sql_type & (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL | + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + update_sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + { + tmp_sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_HANDLER) + { + ha_sql.length(0); + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int spider_mysql_handler::reset_keys( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::reset_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_mysql_handler::reset_upds( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::reset_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_upds.clear(); + DBUG_RETURN(0); +} + +int spider_mysql_handler::reset_strs( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::reset_strs"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_mysql_handler::reset_strs_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::reset_strs_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_mysql_handler::push_back_upds( + SPIDER_HS_STRING_REF &info +) { + int error_num; + DBUG_ENTER("spider_mysql_handler::push_back_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = hs_upds.push_back(info); + DBUG_RETURN(error_num); +} +#endif + +bool spider_mysql_handler::need_lock_before_set_sql_for_exec( + ulong sql_type +) { + DBUG_ENTER("spider_mysql_handler::need_lock_before_set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_mysql_handler::set_sql_for_exec( + ulong sql_type, + int link_idx +) { + int error_num; + uint tmp_pos; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + int all_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & (SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL)) + { + if (mysql_share->same_db_table_name || link_idx == first_link_idx) + { + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + exec_sql = &sql; + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + exec_tmp_sql = &tmp_sql; + } else { + char tmp_table_name[MAX_FIELD_WIDTH * 2], + tgt_table_name[MAX_FIELD_WIDTH * 2]; + int tmp_table_name_length; + spider_string tgt_table_name_str(tgt_table_name, + MAX_FIELD_WIDTH * 2, + mysql_share->db_names_str[link_idx].charset()); + const char *table_names[2], *table_aliases[2]; + uint table_name_lengths[2], table_alias_lengths[2]; + tgt_table_name_str.init_calc_mem(104); + tgt_table_name_str.length(0); + if (result_list->tmp_table_join) + { + create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, + link_idx); + append_table_name_with_adjusting(&tgt_table_name_str, link_idx, + SPIDER_SQL_TYPE_TMP_SQL); + table_names[0] = tmp_table_name; + table_names[1] = tgt_table_name_str.c_ptr(); + table_name_lengths[0] = tmp_table_name_length; + table_name_lengths[1] = tgt_table_name_str.length(); + table_aliases[0] = SPIDER_SQL_A_STR; + table_aliases[1] = SPIDER_SQL_B_STR; + table_alias_lengths[0] = SPIDER_SQL_A_LEN; + table_alias_lengths[1] = SPIDER_SQL_B_LEN; + } + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + { + exec_sql = &result_list->sqls[link_idx]; + if (exec_sql->copy(sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_sql->length(); + exec_sql->length(table_name_pos); + if (result_list->tmp_table_join) + { + if ((error_num = spider_db_mysql_utility.append_from_with_alias( + exec_sql, table_names, table_name_lengths, + table_aliases, table_alias_lengths, 2, + &table_name_pos, TRUE)) + ) + DBUG_RETURN(error_num); + } else { + append_table_name_with_adjusting(exec_sql, link_idx, + SPIDER_SQL_TYPE_SELECT_SQL); + } + exec_sql->length(tmp_pos); + } + } + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + { + exec_tmp_sql = &result_list->tmp_sqls[link_idx]; + if (result_list->tmp_table_join) + { + if (exec_tmp_sql->copy(tmp_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_tmp_sql->length(); + exec_tmp_sql->length(tmp_sql_pos1); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_sql_pos2); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_sql_pos3); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_pos); + } + } + } + } + } + if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) + { + if (mysql_share->same_db_table_name || link_idx == first_link_idx) + exec_insert_sql = &insert_sql; + else { + exec_insert_sql = &result_list->insert_sqls[link_idx]; + if (exec_insert_sql->copy(insert_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_PRINT("info",("spider exec_insert_sql=%s", + exec_insert_sql->c_ptr_safe())); + tmp_pos = exec_insert_sql->length(); + exec_insert_sql->length(insert_table_name_pos); + append_table_name_with_adjusting(exec_insert_sql, link_idx, + sql_type); + exec_insert_sql->length(tmp_pos); + DBUG_PRINT("info",("spider exec_insert_sql->length=%u", + exec_insert_sql->length())); + DBUG_PRINT("info",("spider exec_insert_sql=%s", + exec_insert_sql->c_ptr_safe())); + } + } + if (sql_type & SPIDER_SQL_TYPE_BULK_UPDATE_SQL) + { + if (reading_from_bulk_tmp_table) + { + if ( + mysql_share->same_db_table_name && + share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY + ) { + exec_update_sql = &insert_sql; + } else if (!spider->result_list.upd_tmp_tbls[link_idx]) + { + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } else { + exec_update_sql = &spider->result_list.insert_sqls[link_idx]; + if ((error_num = restore_sql_from_bulk_tmp_table(exec_update_sql, + spider->result_list.upd_tmp_tbls[link_idx]))) + { + DBUG_RETURN(error_num); + } + } + } else { + if ( + mysql_share->same_db_table_name && + share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY + ) { + exec_update_sql = &update_sql; + } else { + exec_update_sql = &spider->result_list.update_sqls[link_idx]; + } + } + } else if (sql_type & + (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL)) + { + if (mysql_share->same_db_table_name || link_idx == first_link_idx) + exec_update_sql = &update_sql; + else { + exec_update_sql = &spider->result_list.update_sqls[link_idx]; + if (exec_update_sql->copy(update_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_pos = exec_update_sql->length(); + exec_update_sql->length(table_name_pos); + append_table_name_with_adjusting(exec_update_sql, link_idx, + sql_type); + exec_update_sql->length(tmp_pos); + } + } + if (sql_type & SPIDER_SQL_TYPE_HANDLER) + { + if (spider->m_handler_id[link_idx] == ha_sql_handler_id) + exec_ha_sql = &ha_sql; + else { + exec_ha_sql = &result_list->sqls[link_idx]; + if (exec_ha_sql->copy(ha_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_ha_sql->length(); + exec_ha_sql->length(ha_table_name_pos); + append_table_name_with_adjusting(exec_ha_sql, link_idx, + SPIDER_SQL_TYPE_HANDLER); + exec_ha_sql->length(tmp_pos); + } + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type +) { + spider_mysql_copy_table *mysql_ct = (spider_mysql_copy_table *) tgt_ct; + DBUG_ENTER("spider_mysql_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + exec_insert_sql = &mysql_ct->sql; + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + spider_string *tgt_sql; + uint tgt_length; + DBUG_ENTER("spider_mysql_handler::execute_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_SELECT_SQL")); + tgt_sql = exec_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_SELECT_SQL")); + tgt_sql = exec_insert_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + DBUG_PRINT("info",("spider %s", + sql_type == SPIDER_SQL_TYPE_UPDATE_SQL ? "SPIDER_SQL_TYPE_UPDATE_SQL" : + sql_type == SPIDER_SQL_TYPE_DELETE_SQL ? "SPIDER_SQL_TYPE_DELETE_SQL" : + "SPIDER_SQL_TYPE_BULK_UPDATE_SQL" + )); + tgt_sql = exec_update_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_TMP_SQL")); + tgt_sql = exec_tmp_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL")); + tgt_sql = exec_tmp_sql; + tgt_length = tmp_sql_pos5; + break; + case SPIDER_SQL_TYPE_HANDLER: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_HANDLER")); + tgt_sql = exec_ha_sql; + tgt_length = tgt_sql->length(); + break; + default: + /* nothing to do */ + DBUG_PRINT("info",("spider default")); + DBUG_RETURN(0); + } + DBUG_RETURN(spider_db_query( + conn, + tgt_sql->ptr(), + tgt_length, + quick_mode, + need_mon + )); +} + +int spider_mysql_handler::reset() +{ + DBUG_ENTER("spider_mysql_handler::reset"); + DBUG_PRINT("info",("spider this=%p", this)); + update_sql.length(0); + DBUG_RETURN(0); +} + +int spider_mysql_handler::sts_mode_exchange( + int sts_mode +) { + DBUG_ENTER("spider_mysql_handler::sts_mode_exchange"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + DBUG_RETURN(sts_mode); +} + +int spider_mysql_handler::show_table_status( + int link_idx, + int sts_mode, + uint flag +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = spider->share; + uint pos = (2 * spider->conn_link_idx[link_idx]); + DBUG_ENTER("spider_mysql_handler::show_table_status"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + if (sts_mode == 1) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + mysql_share->show_table_status[0 + pos].ptr(), + mysql_share->show_table_status[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + mysql_share->show_table_status[0 + pos].ptr(), + mysql_share->show_table_status[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + else { + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_status( + sts_mode, + share->records, + share->mean_rec_length, + share->data_file_length, + share->max_data_file_length, + share->index_file_length, + share->auto_increment_value, + share->create_time, + share->update_time, + share->check_time + ); + res->free_result(); + delete res; + if (error_num) + { + switch (error_num) + { + case ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM: + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + case ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM: + my_printf_error(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM, + ER_SPIDER_INVALID_REMOTE_TABLE_INFO_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + default: + break; + } + DBUG_RETURN(error_num); + } + } else { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + mysql_share->show_table_status[1 + pos].ptr(), + mysql_share->show_table_status[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + mysql_share->show_table_status[1 + pos].ptr(), + mysql_share->show_table_status[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + else + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_status( + sts_mode, + share->records, + share->mean_rec_length, + share->data_file_length, + share->max_data_file_length, + share->index_file_length, + share->auto_increment_value, + share->create_time, + share->update_time, + share->check_time + ); + res->free_result(); + delete res; + if (error_num) + { + switch (error_num) + { + case ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM: + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + case ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM: + my_printf_error(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM, + ER_SPIDER_INVALID_REMOTE_TABLE_INFO_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + default: + break; + } + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::crd_mode_exchange( + int crd_mode +) { + DBUG_ENTER("spider_mysql_handler::crd_mode_exchange"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + DBUG_RETURN(crd_mode); +} + +int spider_mysql_handler::show_index( + int link_idx, + int crd_mode +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + SPIDER_DB_RESULT *res; + int roop_count; + longlong *tmp_cardinality; + uint pos = (2 * spider->conn_link_idx[link_idx]); + DBUG_ENTER("spider_mysql_handler::show_index"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + if (crd_mode == 1) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + mysql_share->show_index[0 + pos].ptr(), + mysql_share->show_index[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + mysql_share->show_index[0 + pos].ptr(), + mysql_share->show_index[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + /* no record is ok */ + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (res) + { + error_num = res->fetch_table_cardinality( + crd_mode, + table, + share->cardinality, + share->cardinality_upd, + share->bitmap_size + ); + } + for (roop_count = 0, tmp_cardinality = share->cardinality; + roop_count < (int) table->s->fields; + roop_count++, tmp_cardinality++) + { + if (!spider_bit_is_set(share->cardinality_upd, roop_count)) + { + DBUG_PRINT("info", + ("spider init column cardinality id=%d", roop_count)); + *tmp_cardinality = 1; + } + } + if (res) + { + res->free_result(); + delete res; + } + if (error_num) + { + switch (error_num) + { + case ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM: + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + case ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM: + my_printf_error(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM, + ER_SPIDER_INVALID_REMOTE_TABLE_INFO_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + default: + break; + } + DBUG_RETURN(error_num); + } + } else { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + mysql_share->show_index[1 + pos].ptr(), + mysql_share->show_index[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + mysql_share->show_index[1 + pos].ptr(), + mysql_share->show_index[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + /* no record is ok */ + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (res) + { + error_num = res->fetch_table_cardinality( + crd_mode, + table, + share->cardinality, + share->cardinality_upd, + share->bitmap_size + ); + } + for (roop_count = 0, tmp_cardinality = share->cardinality; + roop_count < (int) table->s->fields; + roop_count++, tmp_cardinality++) + { + if (!spider_bit_is_set(share->cardinality_upd, roop_count)) + { + DBUG_PRINT("info", + ("spider init column cardinality id=%d", roop_count)); + *tmp_cardinality = 1; + } + } + if (res) + { + res->free_result(); + delete res; + } + if (error_num) + { + switch (error_num) + { + case ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM: + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + case ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM: + my_printf_error(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM, + ER_SPIDER_INVALID_REMOTE_TABLE_INFO_STR, MYF(0), + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + mysql_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + break; + default: + break; + } + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::show_records( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = spider->share; + uint pos = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mysql_handler::show_records"); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + mysql_share->show_records[pos].ptr(), + mysql_share->show_records[pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 1", error_num)); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 2", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + mysql_share->show_records[pos].ptr(), + mysql_share->show_records[pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 4", error_num)); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 6", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_records( + 1, + share->records + ); + res->free_result(); + delete res; + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); + DBUG_RETURN(error_num); + } + spider->trx->direct_aggregate_count++; + DBUG_RETURN(0); +} + +int spider_mysql_handler::show_last_insert_id( + int link_idx, + ulonglong &last_insert_id +) { + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_mysql_handler::show_last_insert_id"); + last_insert_id = conn->db_conn->last_insert_id(); + DBUG_RETURN(0); +} + +ha_rows spider_mysql_handler::explain_select( + key_range *start_key, + key_range *end_key, + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + spider_string *str = &result_list->sqls[link_idx]; + SPIDER_DB_RESULT *res; + ha_rows rows; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_mysql_handler::explain_select"); + if ((error_num = dbton_hdl->append_explain_select_part( + start_key, end_key, SPIDER_SQL_TYPE_OTHER_SQL, link_idx))) + { + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(spider->share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } else { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } else { + my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_records( + 2, + rows + ); + res->free_result(); + delete res; + if (error_num) + { + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + DBUG_RETURN(rows); +} + +int spider_mysql_handler::lock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + spider_string *str = &sql; + DBUG_ENTER("spider_mysql_handler::lock_tables"); + str->length(0); + if ((error_num = conn->db_conn->append_lock_tables(str))) + { + DBUG_RETURN(error_num); + } + if (str->length()) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if (!conn->table_locked) + { + conn->table_locked = TRUE; + spider->trx->locked_connections++; + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::unlock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_mysql_handler::unlock_tables"); + if (conn->table_locked) + { + spider_string *str = &sql; + conn->table_locked = FALSE; + spider->trx->locked_connections--; + + str->length(0); + if ((error_num = conn->db_conn->append_unlock_tables(str))) + { + DBUG_RETURN(error_num); + } + if (str->length()) + { + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::disable_keys( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::disable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_disable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::enable_keys( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::enable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_enable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::check_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_check_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, check_opt))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::repair_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_repair_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, check_opt))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::analyze_table( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::analyze_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_analyze_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::optimize_table( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::optimize_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_optimize_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_mysql_handler::flush_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_flush_tables_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, lock))) + { + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::flush_logs( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_mysql_handler::flush_logs"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + SPIDER_SQL_FLUSH_LOGS_STR, + SPIDER_SQL_FLUSH_LOGS_LEN, + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_mysql_handler::insert_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_mysql *db_conn = (spider_db_mysql *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash = &link_for_hash[link_idx]; + DBUG_ASSERT(tmp_link_for_hash->spider == spider); + DBUG_ASSERT(tmp_link_for_hash->link_idx == link_idx); + uint old_elements = db_conn->handler_open_array.max_element; + DBUG_ENTER("spider_mysql_handler::insert_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (insert_dynamic(&db_conn->handler_open_array, + (uchar*) &tmp_link_for_hash)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->handler_open_array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->handler_open_array, + (db_conn->handler_open_array.max_element - old_elements) * + db_conn->handler_open_array.size_of_element); + } + DBUG_RETURN(0); +} + +int spider_mysql_handler::delete_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_mysql *db_conn = (spider_db_mysql *) conn->db_conn; + uint roop_count, elements = db_conn->handler_open_array.elements; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash; + DBUG_ENTER("spider_mysql_handler::delete_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + for (roop_count = 0; roop_count < elements; roop_count++) + { + get_dynamic(&db_conn->handler_open_array, (uchar *) &tmp_link_for_hash, + roop_count); + if (tmp_link_for_hash == &link_for_hash[link_idx]) + { + delete_dynamic_element(&db_conn->handler_open_array, roop_count); + break; + } + } + DBUG_ASSERT(roop_count < elements); + DBUG_RETURN(0); +} + +int spider_mysql_handler::sync_from_clone_source( + spider_db_handler *dbton_hdl +) { + DBUG_ENTER("spider_mysql_handler::sync_from_clone_source"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_mysql_handler::support_use_handler( + int use_handler +) { + DBUG_ENTER("spider_mysql_handler::support_use_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +spider_mysql_copy_table::spider_mysql_copy_table( + spider_mysql_share *db_share +) : spider_db_copy_table( + db_share +), + mysql_share(db_share) +{ + DBUG_ENTER("spider_mysql_copy_table::spider_mysql_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mysql_copy_table::~spider_mysql_copy_table() +{ + DBUG_ENTER("spider_mysql_copy_table::~spider_mysql_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_mysql_copy_table::init() +{ + DBUG_ENTER("spider_mysql_copy_table::init"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.init_calc_mem(78); + DBUG_RETURN(0); +} + +void spider_mysql_copy_table::set_sql_charset( + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_mysql_copy_table::set_sql_charset"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.set_charset(cs); + DBUG_VOID_RETURN; +} + +int spider_mysql_copy_table::append_select_str() +{ + DBUG_ENTER("spider_mysql_copy_table::append_select_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_SELECT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_insert_str( + int insert_flg +) { + DBUG_ENTER("spider_mysql_copy_table::append_insert_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (insert_flg & SPIDER_DB_INSERT_REPLACE) + { + if (sql.reserve(SPIDER_SQL_REPLACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_REPLACE_STR, SPIDER_SQL_REPLACE_LEN); + } else { + if (sql.reserve(SPIDER_SQL_INSERT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + } + if (insert_flg & SPIDER_DB_INSERT_LOW_PRIORITY) + { + if (sql.reserve(SPIDER_SQL_LOW_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_LOW_PRIORITY_STR, SPIDER_SQL_LOW_PRIORITY_LEN); + } + else if (insert_flg & SPIDER_DB_INSERT_DELAYED) + { + if (sql.reserve(SPIDER_SQL_SQL_DELAYED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SQL_DELAYED_STR, SPIDER_SQL_SQL_DELAYED_LEN); + } + else if (insert_flg & SPIDER_DB_INSERT_HIGH_PRIORITY) + { + if (sql.reserve(SPIDER_SQL_HIGH_PRIORITY_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_HIGH_PRIORITY_STR, SPIDER_SQL_HIGH_PRIORITY_LEN); + } + if (insert_flg & SPIDER_DB_INSERT_IGNORE) + { + if (sql.reserve(SPIDER_SQL_SQL_IGNORE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_table_columns( + TABLE_SHARE *table_share +) { + int error_num; + Field **field; + DBUG_ENTER("spider_mysql_copy_table::append_table_columns"); + DBUG_PRINT("info",("spider this=%p", this)); + for (field = table_share->field; *field; field++) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) (*field)->field_name, spider_dbton_mysql.dbton_id))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_from_str() +{ + DBUG_ENTER("spider_mysql_copy_table::append_from_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_table_name( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mysql_copy_table::append_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = mysql_share->append_table_name(&sql, link_idx); + DBUG_RETURN(error_num); +} + +void spider_mysql_copy_table::set_sql_pos() +{ + DBUG_ENTER("spider_mysql_copy_table::set_sql_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + pos = sql.length(); + DBUG_VOID_RETURN; +} + +void spider_mysql_copy_table::set_sql_to_pos() +{ + DBUG_ENTER("spider_mysql_copy_table::set_sql_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.length(pos); + DBUG_VOID_RETURN; +} + +int spider_mysql_copy_table::append_copy_where( + spider_db_copy_table *source_ct, + KEY *key_info, + ulong *last_row_pos, + ulong *last_lengths +) { + int error_num, roop_count, roop_count2; + DBUG_ENTER("spider_mysql_copy_table::append_copy_where"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_WHERE_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + Field *field; + KEY_PART_INFO *key_part = key_info->key_part; + for (roop_count = key_info->key_parts - 1; roop_count >= 0; roop_count--) + { + for (roop_count2 = 0; roop_count2 < roop_count; roop_count2++) + { + field = key_part[roop_count2].field; + if ((error_num = copy_key_row(source_ct, + field, &last_row_pos[field->field_index], + &last_lengths[field->field_index], + SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN))) + { + DBUG_RETURN(error_num); + } + } + field = key_part[roop_count2].field; + if ((error_num = copy_key_row(source_ct, + field, &last_row_pos[field->field_index], + &last_lengths[field->field_index], + SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN))) + { + DBUG_RETURN(error_num); + } + sql.length(sql.length() - SPIDER_SQL_AND_LEN); + if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_OR_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + sql.q_append(SPIDER_SQL_OR_STR, SPIDER_SQL_OR_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + sql.length(sql.length() - SPIDER_SQL_OR_LEN - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_key_order_str( + KEY *key_info, + int start_pos, + bool desc_flg +) { + int length, error_num; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_mysql_copy_table::append_key_order_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((int) key_info->key_parts > start_pos) + { + if (sql.reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + if (desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_mysql.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_mysql.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_limit( + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_mysql_copy_table::append_limit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (offset || limit < 9223372036854775807LL) + { + if (sql.reserve(SPIDER_SQL_LIMIT_LEN + SPIDER_SQL_COMMA_LEN + + ((SPIDER_LONGLONG_LEN) * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN); + if (offset) + { + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset); + sql.q_append(buf, length); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + sql.q_append(buf, length); + } + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_into_str() +{ + DBUG_ENTER("spider_mysql_copy_table::append_into_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_INTO_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_open_paren_str() +{ + DBUG_ENTER("spider_mysql_copy_table::append_open_paren_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_values_str() +{ + DBUG_ENTER("spider_mysql_copy_table::append_values_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_select_lock_str( + int lock_mode +) { + DBUG_ENTER("spider_mysql_copy_table::append_select_lock_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (sql.reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (sql.reserve(SPIDER_SQL_SHARED_LOCK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SHARED_LOCK_STR, SPIDER_SQL_SHARED_LOCK_LEN); + } + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_mysql_copy_table::exec_query"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_query(conn, sql.ptr(), sql.length(), quick_mode, + need_mon); + DBUG_RETURN(error_num); +} + +int spider_mysql_copy_table::copy_key_row( + spider_db_copy_table *source_ct, + Field *field, + ulong *row_pos, + ulong *length, + const char *joint_str, + const int joint_length +) { + int error_num; + spider_string *source_str = &((spider_mysql_copy_table *) source_ct)->sql; + DBUG_ENTER("spider_mysql_copy_table::copy_key_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_mysql.dbton_id))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + joint_length + *length + + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(joint_str, joint_length); + sql.q_append(source_str->ptr() + *row_pos, *length); + sql.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::copy_row( + Field *field, + SPIDER_DB_ROW *row +) { + int error_num; + DBUG_ENTER("spider_mysql_copy_table::copy_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (row->is_null()) + { + if (sql.reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else if (field->str_needs_quotes()) + { + if (sql.reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if ((error_num = row->append_escaped_to_str(&sql, + spider_dbton_mysql.dbton_id))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_VALUE_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else { + if ((error_num = row->append_to_str(&sql))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::copy_rows( + TABLE *table, + SPIDER_DB_ROW *row, + ulong **last_row_pos, + ulong **last_lengths +) { + int error_num; + Field **field; + ulong *lengths2, *row_pos2; + DBUG_ENTER("spider_mysql_copy_table::copy_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + row_pos2 = *last_row_pos; + lengths2 = *last_lengths; + + for ( + field = table->field; + *field; + field++, + lengths2++ + ) { + *row_pos2 = sql.length(); + if ((error_num = + copy_row(*field, row))) + DBUG_RETURN(error_num); + *lengths2 = sql.length() - *row_pos2 - SPIDER_SQL_COMMA_LEN; + row->next(); + row_pos2++; + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_COMMA_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::copy_rows( + TABLE *table, + SPIDER_DB_ROW *row +) { + int error_num; + Field **field; + DBUG_ENTER("spider_mysql_copy_table::copy_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + for ( + field = table->field; + *field; + field++ + ) { + if ((error_num = + copy_row(*field, row))) + DBUG_RETURN(error_num); + row->next(); + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_COMMA_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::append_insert_terminator() +{ + DBUG_ENTER("spider_mysql_copy_table::append_insert_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mysql_copy_table::copy_insert_values( + spider_db_copy_table *source_ct +) { + spider_mysql_copy_table *tmp_ct = (spider_mysql_copy_table *) source_ct; + spider_string *source_str = &tmp_ct->sql; + int values_length = source_str->length() - tmp_ct->pos; + const char *values_ptr = source_str->ptr() + tmp_ct->pos; + DBUG_ENTER("spider_mysql_copy_table::copy_insert_values"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(values_length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(values_ptr, values_length); + DBUG_RETURN(0); +} diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h new file mode 100644 index 00000000000..761537ba0a0 --- /dev/null +++ b/storage/spider/spd_db_mysql.h @@ -0,0 +1,1295 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +class spider_db_mysql_util: public spider_db_util +{ +public: + spider_db_mysql_util(); + ~spider_db_mysql_util(); + int append_name( + spider_string *str, + const char *name, + uint name_length + ); + int append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ); + bool is_name_quote( + const char head_code + ); + int append_escaped_name_quote( + spider_string *str + ); + int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset + ); + int append_from_with_alias( + spider_string *str, + const char **table_names, + uint *table_name_lengths, + const char **table_aliases, + uint *table_alias_lengths, + uint table_count, + int *table_name_pos, + bool over_write + ); + int append_trx_isolation( + spider_string *str, + int trx_isolation + ); + int append_autocommit( + spider_string *str, + bool autocommit + ); + int append_sql_log_off( + spider_string *str, + bool sql_log_off + ); + int append_time_zone( + spider_string *str, + Time_zone *time_zone + ); + int append_start_transaction( + spider_string *str + ); + int append_xa_start( + spider_string *str, + XID *xid + ); + int append_lock_table_head( + spider_string *str + ); + int append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type + ); + int append_lock_table_tail( + spider_string *str + ); + int append_unlock_table( + spider_string *str + ); + int open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length + ); + int append_escaped_util( + spider_string *to, + String *from + ); +}; + +class spider_db_mysql_row: public spider_db_row +{ +public: + MYSQL_ROW row; + MYSQL_ROW row_first; + ulong *lengths; + ulong *lengths_first; + uint field_count; + bool cloned; + spider_db_mysql_row(); + ~spider_db_mysql_row(); + int store_to_field( + Field *field, + CHARSET_INFO *access_charset + ); + int append_to_str( + spider_string *str + ); + int append_escaped_to_str( + spider_string *str, + uint dbton_id + ); + void first(); + void next(); + bool is_null(); + int val_int(); + double val_real(); + SPIDER_DB_ROW *clone(); + int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ); +}; + +class spider_db_mysql_result: public spider_db_result +{ +public: + MYSQL_RES *db_result; + spider_db_mysql_row row; + MYSQL_ROW_OFFSET first_row; + int store_error_num; + spider_db_mysql_result(); + ~spider_db_mysql_result(); + bool has_result(); + void free_result(); + SPIDER_DB_ROW *current_row(); + SPIDER_DB_ROW *fetch_row(); + SPIDER_DB_ROW *fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf + ); + SPIDER_DB_ROW *fetch_row_from_tmp_table( + TABLE *tmp_table + ); + int fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time + ); + int fetch_table_records( + int mode, + ha_rows &records + ); + int fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size + ); + int fetch_table_mon_status( + int &status + ); + longlong num_rows(); + uint num_fields(); + void move_to_pos( + longlong pos + ); + int get_errno(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); + int fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); +#endif +}; + +class spider_db_mysql: public spider_db_conn +{ + MYSQL *db_conn; + int stored_error; +public: + HASH lock_table_hash; + bool lock_table_hash_inited; + uint lock_table_hash_id; + const char *lock_table_hash_func_name; + const char *lock_table_hash_file_name; + ulong lock_table_hash_line_no; + DYNAMIC_ARRAY handler_open_array; + bool handler_open_array_inited; + uint handler_open_array_id; + const char *handler_open_array_func_name; + const char *handler_open_array_file_name; + ulong handler_open_array_line_no; + spider_db_mysql( + SPIDER_CONN *conn + ); + ~spider_db_mysql(); + int init(); + bool is_connected(); + void bg_connect(); + int connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval + ); + int ping(); + void bg_disconnect(); + void disconnect(); + int set_net_timeout(); + int exec_query( + const char *query, + uint length, + int quick_mode + ); + int get_errno(); + const char *get_error(); + bool is_server_gone_error( + int error_num + ); + bool is_dup_entry_error( + int error_num + ); + bool is_xa_nota_error( + int error_num + ); + spider_db_result *store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num + ); + spider_db_result *use_result( + st_spider_db_request_key *request_key, + int *error_num + ); + int next_result(); + uint affected_rows(); + ulonglong last_insert_id(); + int set_character_set( + const char *csname + ); + int select_db( + const char *dbname + ); + int consistent_snapshot( + int *need_mon + ); + bool trx_start_in_bulk_sql(); + int start_transaction( + int *need_mon + ); + int commit( + int *need_mon + ); + int rollback( + int *need_mon + ); + bool xa_start_in_bulk_sql(); + int xa_start( + XID *xid, + int *need_mon + ); + int xa_end( + XID *xid, + int *need_mon + ); + int xa_prepare( + XID *xid, + int *need_mon + ); + int xa_commit( + XID *xid, + int *need_mon + ); + int xa_rollback( + XID *xid, + int *need_mon + ); + bool set_trx_isolation_in_bulk_sql(); + int set_trx_isolation( + int trx_isolation, + int *need_mon + ); + bool set_autocommit_in_bulk_sql(); + int set_autocommit( + bool autocommit, + int *need_mon + ); + bool set_sql_log_off_in_bulk_sql(); + int set_sql_log_off( + bool sql_log_off, + int *need_mon + ); + bool set_time_zone_in_bulk_sql(); + int set_time_zone( + Time_zone *time_zone, + int *need_mon + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key + ); + int append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key + ); + int append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + int append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key + ); + int append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key + ); + int append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + void reset_request_queue(); +#endif + size_t escape_string( + char *to, + const char *from, + size_t from_length + ); + bool have_lock_table_list(); + int append_lock_tables( + spider_string *str + ); + int append_unlock_tables( + spider_string *str + ); + uint get_lock_table_hash_count(); + void reset_lock_table_hash(); + uint get_opened_handler_count(); + void reset_opened_handler(); + void set_dup_key_idx( + ha_spider *spider, + int link_idx + ); + bool cmp_request_key_to_snd( + st_spider_db_request_key *request_key + ); +}; + +class spider_mysql_share: public spider_db_share +{ +public: + spider_string *table_select; + int table_select_pos; + spider_string *key_select; + int *key_select_pos; + spider_string *key_hint; + spider_string *show_table_status; + spider_string *show_records; + spider_string *show_index; + spider_string *table_names_str; + spider_string *db_names_str; + spider_string *db_table_str; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type *db_table_str_hash_value; +#endif + uint table_nm_max_length; + uint db_nm_max_length; + spider_string *column_name_str; + bool same_db_table_name; + int first_all_link_idx; + + spider_mysql_share( + st_spider_share *share + ); + ~spider_mysql_share(); + int init(); + uint get_column_name_length( + uint field_index + ); + int append_column_name( + spider_string *str, + uint field_index + ); + int append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length + ); + int append_table_name( + spider_string *str, + int all_link_idx + ); + int append_table_name_with_adjusting( + spider_string *str, + int all_link_idx + ); + int append_from_with_adjusted_table_name( + spider_string *str, + int *table_name_pos + ); + bool need_change_db_table_name(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ); +#endif +private: + int create_table_names_str(); + void free_table_names_str(); + int create_column_name_str(); + void free_column_name_str(); + int convert_key_hint_str(); + int append_show_table_status(); + void free_show_table_status(); + int append_show_records(); + void free_show_records(); + int append_show_index(); + void free_show_index(); + int append_table_select(); + int append_key_select( + uint idx + ); +}; + +class spider_mysql_handler: public spider_db_handler +{ + spider_string sql; + spider_string sql_part; + spider_string sql_part2; + spider_string ha_sql; + int where_pos; + int order_pos; + int limit_pos; + int table_name_pos; + int ha_read_pos; + int ha_next_pos; + int ha_where_pos; + int ha_limit_pos; + int ha_table_name_pos; + uint ha_sql_handler_id; + spider_string insert_sql; + int insert_pos; + int insert_table_name_pos; + spider_string update_sql; + TABLE *upd_tmp_tbl; + TMP_TABLE_PARAM upd_tmp_tbl_prm; + spider_string tmp_sql; + int tmp_sql_pos1; /* drop db nm pos at tmp_table_join */ + int tmp_sql_pos2; /* create db nm pos at tmp_table_join */ + int tmp_sql_pos3; /* insert db nm pos at tmp_table_join */ + int tmp_sql_pos4; /* insert val pos at tmp_table_join */ + int tmp_sql_pos5; /* end of drop tbl at tmp_table_join */ + spider_string dup_update_sql; + spider_string *exec_sql; + spider_string *exec_insert_sql; + spider_string *exec_update_sql; + spider_string *exec_tmp_sql; + spider_string *exec_ha_sql; + bool reading_from_bulk_tmp_table; + bool filled_up; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_DB_HS_STRING_REF_BUFFER hs_upds; +#endif +public: + spider_mysql_share *mysql_share; + SPIDER_LINK_FOR_HASH *link_for_hash; + spider_mysql_handler( + ha_spider *spider, + spider_mysql_share *share + ); + ~spider_mysql_handler(); + int init(); + int append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type + ); + int append_key_column_types( + const key_range *start_key, + spider_string *str + ); + int append_key_join_columns_for_bka( + const key_range *start_key, + spider_string *str, + const char **table_aliases, + uint *table_alias_lengths + ); + int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_tmp_table_and_sql_for_bka(); + void create_tmp_bka_table_name( + char *tmp_table_name, + int *tmp_table_name_length, + int link_idx + ); + int append_create_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + CHARSET_INFO *table_charset + ); + int append_drop_tmp_bka_table( + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + int *drop_table_end_pos, + bool with_semicolon + ); + int append_insert_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos + ); + int append_insert_for_recovery( + ulong sql_type, + int link_idx + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_insert_part(); + int append_insert( + spider_string *str, + int link_idx + ); + int append_update_part(); + int append_update( + spider_string *str, + int link_idx + ); + int append_delete_part(); + int append_delete( + spider_string *str + ); + #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_increment_update_set_part(); + int append_increment_update_set( + spider_string *str + ); + #endif + #endif + int append_update_set_part(); + int append_update_set( + spider_string *str + ); + #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_direct_update_set_part(); + int append_direct_update_set( + spider_string *str + ); + int append_dup_update_pushdown_part( + const char *alias, + uint alias_length + ); + int append_update_columns_part( + const char *alias, + uint alias_length + ); + int check_update_columns_part(); + int append_update_columns( + spider_string *str, + const char *alias, + uint alias_length + ); + #endif + int append_select_part( + ulong sql_type + ); + int append_select( + spider_string *str, + ulong sql_type + ); + int append_table_select_part( + ulong sql_type + ); + int append_table_select( + spider_string *str + ); + int append_key_select_part( + ulong sql_type, + uint idx + ); + int append_key_select( + spider_string *str, + uint idx + ); + int append_minimum_select_part( + ulong sql_type + ); + int append_minimum_select( + spider_string *str, + ulong sql_type + ); + int append_table_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_select_with_alias( + spider_string *str, + const KEY *key_info, + const char *alias, + uint alias_length + ); + int append_minimum_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_select_columns_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_hint_after_table_part( + ulong sql_type + ); + int append_hint_after_table( + spider_string *str + ); + void set_where_pos( + ulong sql_type + ); + void set_where_to_pos( + ulong sql_type + ); + int check_item_type( + Item *item + ); + int append_values_connector_part( + ulong sql_type + ); + int append_values_connector( + spider_string *str + ); + int append_values_terminator_part( + ulong sql_type + ); + int append_values_terminator( + spider_string *str + ); + int append_key_column_values_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_column_values( + spider_string *str, + const key_range *start_key + ); + int append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ); + int append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order + ); + int append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count + ); + int append_where_terminator( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + bool set_order, + int key_count + ); + int append_match_where_part( + ulong sql_type + ); + int append_match_where( + spider_string *str + ); + int append_update_where( + spider_string *str, + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg + ); + int append_condition( + spider_string *str, + const char *alias, + uint alias_length, + bool start_where, + ulong sql_type + ); + int append_match_against_part( + ulong sql_type, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length + ); + int append_match_against( + spider_string *str, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length + ); + int append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + int append_match_select( + spider_string *str, + const char *alias, + uint alias_length + ); + void set_order_pos( + ulong sql_type + ); + void set_order_to_pos( + ulong sql_type + ); + int append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_merge_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_direct_order_limit_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_handler( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int append_limit( + spider_string *str, + longlong offset, + longlong limit + ); + int append_select_lock_part( + ulong sql_type + ); + int append_select_lock( + spider_string *str + ); + int append_union_all_start_part( + ulong sql_type + ); + int append_union_all_start( + spider_string *str + ); + int append_union_all_part( + ulong sql_type + ); + int append_union_all( + spider_string *str + ); + int append_union_all_end_part( + ulong sql_type + ); + int append_union_all_end( + spider_string *str + ); + int append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma + ); + int append_multi_range_cnt( + spider_string *str, + uint multi_range_cnt, + bool with_comma + ); + int append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_close_handler_part( + ulong sql_type, + int link_idx + ); + int append_close_handler( + spider_string *str, + int link_idx + ); + int append_insert_terminator_part( + ulong sql_type + ); + int append_insert_terminator( + spider_string *str + ); + int append_insert_values_part( + ulong sql_type + ); + int append_insert_values( + spider_string *str + ); + int append_into_part( + ulong sql_type + ); + int append_into( + spider_string *str + ); + void set_insert_to_pos( + ulong sql_type + ); + int append_from_part( + ulong sql_type, + int link_idx + ); + int append_from( + spider_string *str, + ulong sql_type, + int link_idx + ); + int append_flush_tables_part( + ulong sql_type, + int link_idx, + bool lock + ); + int append_flush_tables( + spider_string *str, + int link_idx, + bool lock + ); + int append_optimize_table_part( + ulong sql_type, + int link_idx + ); + int append_optimize_table( + spider_string *str, + int link_idx + ); + int append_analyze_table_part( + ulong sql_type, + int link_idx + ); + int append_analyze_table( + spider_string *str, + int link_idx + ); + int append_repair_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_repair_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_check_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_check_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_enable_keys_part( + ulong sql_type, + int link_idx + ); + int append_enable_keys( + spider_string *str, + int link_idx + ); + int append_disable_keys_part( + ulong sql_type, + int link_idx + ); + int append_disable_keys( + spider_string *str, + int link_idx + ); + int append_delete_all_rows_part( + ulong sql_type + ); + int append_delete_all_rows( + spider_string *str, + ulong sql_type + ); + int append_truncate( + spider_string *str, + ulong sql_type, + int link_idx + ); + int append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ); + int append_explain_select( + spider_string *str, + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ); + bool is_bulk_insert_exec_period( + bool bulk_end + ); + bool sql_is_filled_up( + ulong sql_type + ); + bool sql_is_empty( + ulong sql_type + ); + bool support_multi_split_read(); + bool support_bulk_update(); + int bulk_tmp_table_insert(); + int bulk_tmp_table_insert( + int link_idx + ); + int bulk_tmp_table_end_bulk_insert(); + int bulk_tmp_table_rnd_init(); + int bulk_tmp_table_rnd_next(); + int bulk_tmp_table_rnd_end(); + bool need_copy_for_update( + int link_idx + ); + bool bulk_tmp_table_created(); + int mk_bulk_tmp_table_and_bulk_start(); + void rm_bulk_tmp_table(); + int store_sql_to_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table + ); + int restore_sql_from_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table + ); + int insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx + ); + int append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended + ); + int realloc_sql( + ulong *realloced + ); + int reset_sql( + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int reset_keys( + ulong sql_type + ); + int reset_upds( + ulong sql_type + ); + int reset_strs( + ulong sql_type + ); + int reset_strs_pos( + ulong sql_type + ); + int push_back_upds( + SPIDER_HS_STRING_REF &info + ); +#endif + bool need_lock_before_set_sql_for_exec( + ulong sql_type + ); + int set_sql_for_exec( + ulong sql_type, + int link_idx + ); + int set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type + ); + int execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ); + int reset(); + int sts_mode_exchange( + int sts_mode + ); + int show_table_status( + int link_idx, + int sts_mode, + uint flag + ); + int crd_mode_exchange( + int crd_mode + ); + int show_index( + int link_idx, + int crd_mode + ); + int show_records( + int link_idx + ); + int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ); + ha_rows explain_select( + key_range *start_key, + key_range *end_key, + int link_idx + ); + int lock_tables( + int link_idx + ); + int unlock_tables( + int link_idx + ); + int disable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int enable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int analyze_table( + SPIDER_CONN *conn, + int link_idx + ); + int optimize_table( + SPIDER_CONN *conn, + int link_idx + ); + int flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock + ); + int flush_logs( + SPIDER_CONN *conn, + int link_idx + ); + int insert_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int delete_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int sync_from_clone_source( + spider_db_handler *dbton_hdl + ); + bool support_use_handler( + int use_handler + ); +}; + +class spider_mysql_copy_table: public spider_db_copy_table +{ +public: + spider_mysql_share *mysql_share; + spider_string sql; + uint pos; + spider_mysql_copy_table( + spider_mysql_share *db_share + ); + ~spider_mysql_copy_table(); + int init(); + void set_sql_charset( + CHARSET_INFO *cs + ); + int append_select_str(); + int append_insert_str( + int insert_flg + ); + int append_table_columns( + TABLE_SHARE *table_share + ); + int append_from_str(); + int append_table_name( + int link_idx + ); + void set_sql_pos(); + void set_sql_to_pos(); + int append_copy_where( + spider_db_copy_table *source_ct, + KEY *key_info, + ulong *last_row_pos, + ulong *last_lengths + ); + int append_key_order_str( + KEY *key_info, + int start_pos, + bool desc_flg + ); + int append_limit( + longlong offset, + longlong limit + ); + int append_into_str(); + int append_open_paren_str(); + int append_values_str(); + int append_select_lock_str( + int lock_mode + ); + int exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ); + int copy_key_row( + spider_db_copy_table *source_ct, + Field *field, + ulong *row_pos, + ulong *length, + const char *joint_str, + const int joint_length + ); + int copy_row( + Field *field, + SPIDER_DB_ROW *row + ); + int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row, + ulong **last_row_pos, + ulong **last_lengths + ); + int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row + ); + int append_insert_terminator(); + int copy_insert_values( + spider_db_copy_table *source_ct + ); +}; diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc new file mode 100644 index 00000000000..7c40b3a4477 --- /dev/null +++ b/storage/spider/spd_db_oracle.cc @@ -0,0 +1,11764 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_partition.h" +#include "sql_analyse.h" +#endif + +#ifdef HAVE_ORACLE_OCI +#include +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_db_oracle.h" +#include "ha_spider.h" +#include "spd_conn.h" +#include "spd_db_conn.h" +#include "spd_malloc.h" +#include "spd_sys_table.h" +#include "spd_table.h" + +extern struct charset_info_st *spd_charset_utf8_bin; + +extern handlerton *spider_hton_ptr; +extern pthread_mutex_t spider_open_conn_mutex; +extern HASH spider_open_connections; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern const char spider_dig_upper[]; + +#define SPIDER_DB_WRAPPER_ORACLE "oracle" + +#define SPIDER_SQL_NAME_QUOTE_STR "\"" +#define SPIDER_SQL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_NAME_QUOTE_STR) - 1) +static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR; + +#define SPIDER_SQL_ISO_READ_COMMITTED_STR "set transaction isolation level read committed" +#define SPIDER_SQL_ISO_READ_COMMITTED_LEN sizeof(SPIDER_SQL_ISO_READ_COMMITTED_STR) - 1 +#define SPIDER_SQL_ISO_SERIALIZABLE_STR "set transaction isolation level serializable" +#define SPIDER_SQL_ISO_SERIALIZABLE_LEN sizeof(SPIDER_SQL_ISO_SERIALIZABLE_STR) - 1 + +#define SPIDER_SQL_START_TRANSACTION_STR "set transaction read write" +#define SPIDER_SQL_START_TRANSACTION_LEN sizeof(SPIDER_SQL_START_TRANSACTION_STR) - 1 + +#define SPIDER_SQL_AUTOCOMMIT_OFF_STR "set autocommit off" +#define SPIDER_SQL_AUTOCOMMIT_OFF_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_OFF_STR) - 1 +#define SPIDER_SQL_AUTOCOMMIT_ON_STR "set autocommit on" +#define SPIDER_SQL_AUTOCOMMIT_ON_LEN sizeof(SPIDER_SQL_AUTOCOMMIT_ON_STR) - 1 + +#define SPIDER_SQL_LOCK_TABLE_STR "lock table " +#define SPIDER_SQL_LOCK_TABLE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_STR) - 1) +#define SPIDER_SQL_UNLOCK_TABLE_STR "unlock tables" +#define SPIDER_SQL_UNLOCK_TABLE_LEN (sizeof(SPIDER_SQL_UNLOCK_TABLE_STR) - 1) +#define SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR " in share mode" +#define SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR) - 1) +#define SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR " in exclusive mode" +#define SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN (sizeof(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR) - 1) + +#define SPIDER_SQL_COMMIT_STR "commit" +#define SPIDER_SQL_COMMIT_LEN sizeof(SPIDER_SQL_COMMIT_STR) - 1 + +#define SPIDER_SQL_SET_NLS_DATE_FORMAT_STR "alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS'" +#define SPIDER_SQL_SET_NLS_DATE_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_DATE_FORMAT_STR) - 1 +#define SPIDER_SQL_SET_NLS_TIME_FORMAT_STR "alter session set nls_time_format='HH24:MI:SSXFF'" +#define SPIDER_SQL_SET_NLS_TIME_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_TIME_FORMAT_STR) - 1 +#define SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR "alter session set nls_timestamp_format='YYYY-MM-DD HH24:MI:SSXFF'" +#define SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_LEN sizeof(SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR) - 1 + +#define SPIDER_SQL_SELECT_WRAPPER_HEAD_STR "select * from (" +#define SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN sizeof(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR) - 1 +#define SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR " where rowid in (select rowid from (select rowid, row_number() over (order by " +#define SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN sizeof(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR) - 1 +#define SPIDER_SQL_ROW_NUMBER_HEAD_STR ", row_number() over (order by " +#define SPIDER_SQL_ROW_NUMBER_HEAD_LEN sizeof(SPIDER_SQL_ROW_NUMBER_HEAD_STR) - 1 +#define SPIDER_SQL_ROW_NUMBER_TAIL_STR "rowid) row_num" +#define SPIDER_SQL_ROW_NUMBER_TAIL_LEN sizeof(SPIDER_SQL_ROW_NUMBER_TAIL_STR) - 1 +#define SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR "rowid desc) row_num" +#define SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN sizeof(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR) - 1 +#define SPIDER_SQL_SELECT_WRAPPER_TAIL_STR ") where row_num " +#define SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN sizeof(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR) - 1 +#define SPIDER_SQL_ROW_NUM_STR "row_num" +#define SPIDER_SQL_ROW_NUM_LEN sizeof(SPIDER_SQL_ROW_NUM_STR) - 1 +#define SPIDER_SQL_ROWNUM_STR "rownum" +#define SPIDER_SQL_ROWNUM_LEN sizeof(SPIDER_SQL_ROWNUM_STR) - 1 +#define SPIDER_SQL_NEXTVAL_STR ".nextval" +#define SPIDER_SQL_NEXTVAL_LEN sizeof(SPIDER_SQL_NEXTVAL_STR) - 1 +#define SPIDER_SQL_CURRVAL_STR ".currval" +#define SPIDER_SQL_CURRVAL_LEN sizeof(SPIDER_SQL_CURRVAL_STR) - 1 +#define SPIDER_SQL_FROM_DUAL_STR " from dual" +#define SPIDER_SQL_FROM_DUAL_LEN sizeof(SPIDER_SQL_FROM_DUAL_STR) - 1 + +#define SPIDER_SQL_SHOW_TABLE_STATUS_STR "show table status from " +#define SPIDER_SQL_SHOW_TABLE_STATUS_LEN sizeof(SPIDER_SQL_SHOW_TABLE_STATUS_STR) - 1 +#define SPIDER_SQL_SELECT_TABLES_STATUS_STR "select `table_rows`,`avg_row_length`,`data_length`,`max_data_length`,`index_length`,`auto_increment`,`create_time`,`update_time`,`check_time` from `information_schema`.`tables` where `table_schema` = " +#define SPIDER_SQL_SELECT_TABLES_STATUS_LEN sizeof(SPIDER_SQL_SELECT_TABLES_STATUS_STR) - 1 + +#define SPIDER_SQL_LIKE_STR " like " +#define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1) +#define SPIDER_SQL_LIMIT1_STR "rownum = 1" +#define SPIDER_SQL_LIMIT1_LEN (sizeof(SPIDER_SQL_LIMIT1_STR) - 1) + +#define SPIDER_SQL_ADD_MONTHS_STR "add_months" +#define SPIDER_SQL_ADD_MONTHS_LEN (sizeof(SPIDER_SQL_ADD_MONTHS_STR) - 1) + +#define SPIDER_ORACLE_ERR_BUF_LEN 512 + +static uchar SPIDER_SQL_LINESTRING_HEAD_STR[] = + {0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00}; +#define SPIDER_SQL_LINESTRING_HEAD_LEN sizeof(SPIDER_SQL_LINESTRING_HEAD_STR) + +static const char *spider_db_table_lock_str[] = +{ + " in share mode", + " in share mode", + " in exclusive mode", + " in exclusive mode" +}; +static const int spider_db_table_lock_len[] = +{ + sizeof(" in share mode") - 1, + sizeof(" in share mode") - 1, + sizeof(" in exclusive mode") - 1, + sizeof(" in exclusive mode") - 1 +}; + +int spider_db_oracle_get_error( + sword res, + dvoid *hndlp, + int error_num, + const char *error1, + const char *error2, + CHARSET_INFO *access_charset, + char *stored_error_msg +) { + sb4 error_code; + char buf[SPIDER_ORACLE_ERR_BUF_LEN]; + char buf2[SPIDER_ORACLE_ERR_BUF_LEN]; + spider_string tmp_str(buf2, SPIDER_ORACLE_ERR_BUF_LEN, system_charset_info); + DBUG_ENTER("spider_db_oracle_get_error"); + tmp_str.init_calc_mem(176); + tmp_str.length(0); + + switch (res) + { + case OCI_SUCCESS: + DBUG_PRINT("info",("spider res=OCI_SUCCESS")); + break; + case OCI_SUCCESS_WITH_INFO: + DBUG_PRINT("info",("spider res=OCI_SUCCESS_WITH_INFO")); + OCIErrorGet(hndlp, 1, NULL, &error_code, (OraText *) buf, sizeof(buf), + OCI_HTYPE_ERROR); + DBUG_PRINT("info",("spider error_code=%d error='%s'",error_code ,buf)); + if (access_charset && access_charset->cset != system_charset_info->cset) + { + tmp_str.append(buf, strlen(buf), access_charset); + } else { + tmp_str.set(buf, strlen(buf), system_charset_info); + } + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, res, error_code, + tmp_str.c_ptr_safe()); + break; + case OCI_NO_DATA: + DBUG_PRINT("info",("spider res=OCI_NO_DATA")); + DBUG_RETURN(HA_ERR_END_OF_FILE); + case OCI_ERROR: + DBUG_PRINT("info",("spider res=OCI_ERROR")); + OCIErrorGet(hndlp, 1, NULL, &error_code, (OraText *) buf, sizeof(buf), + OCI_HTYPE_ERROR); + DBUG_PRINT("info",("spider error_code=%d error='%s'",error_code ,buf)); + if (error_code == 1) + { + DBUG_PRINT("info",("spider found dupp key")); + if (stored_error_msg) + strmov(stored_error_msg, buf); + DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); + } + if (error_num) + { + if (error1) + { + if (error2) + { + my_printf_error(error_num, error1, MYF(0), error2); + } else { + my_printf_error(error_num, error1, MYF(0)); + } + } else if (error2) { + my_error(error_num, MYF(0), error2); + } else { + my_error(error_num, MYF(0)); + } + } + if (access_charset && access_charset->cset != system_charset_info->cset) + { + tmp_str.append(buf, strlen(buf), access_charset); + } else { + tmp_str.set(buf, strlen(buf), system_charset_info); + } + my_printf_error(ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, MYF(0), + res, error_code, tmp_str.c_ptr_safe()); + if (error_num) + { + DBUG_RETURN(error_num); + } else { + DBUG_RETURN(ER_SPIDER_ORACLE_NUM); + } + case OCI_INVALID_HANDLE: + case OCI_NEED_DATA: + if (res == OCI_INVALID_HANDLE) + DBUG_PRINT("info",("spider res=OCI_INVALID_HANDLE")); + else + DBUG_PRINT("info",("spider res=OCI_NEED_DATA")); + default: + DBUG_PRINT("info",("spider res=%d", res)); + if (error_num) + { + if (error1) + { + if (error2) + { + my_printf_error(error_num, error1, MYF(0), error2); + } else { + my_printf_error(error_num, error1, MYF(0)); + } + } else if (error2) { + my_error(error_num, MYF(0), error2); + } else { + my_error(error_num, MYF(0)); + } + } + my_printf_error(ER_SPIDER_ORACLE_NUM, ER_SPIDER_ORACLE_STR, MYF(0), + res, 0, ""); + if (error_num) + { + DBUG_RETURN(error_num); + } else { + DBUG_RETURN(ER_SPIDER_ORACLE_NUM); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_init() +{ + DBUG_ENTER("spider_oracle_init"); + DBUG_RETURN(0); +} + +int spider_oracle_deinit() +{ + DBUG_ENTER("spider_oracle_deinit"); + DBUG_RETURN(0); +} + +spider_db_share *spider_oracle_create_share( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_oracle_create_share"); + DBUG_RETURN(new spider_oracle_share(share)); +} + +spider_db_handler *spider_oracle_create_handler( + ha_spider *spider, + spider_db_share *db_share +) { + DBUG_ENTER("spider_oracle_create_handler"); + DBUG_RETURN(new spider_oracle_handler(spider, + (spider_oracle_share *) db_share)); +} + +spider_db_copy_table *spider_oracle_create_copy_table( + spider_db_share *db_share +) { + DBUG_ENTER("spider_oracle_create_copy_table"); + DBUG_RETURN(new spider_oracle_copy_table( + (spider_oracle_share *) db_share)); +} + +SPIDER_DB_CONN *spider_oracle_create_conn( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_oracle_create_conn"); + DBUG_RETURN(new spider_db_oracle(conn)); +} + +spider_db_oracle_util spider_db_oracle_utility; + +SPIDER_DBTON spider_dbton_oracle = { + 0, + SPIDER_DB_WRAPPER_ORACLE, + SPIDER_DB_ACCESS_TYPE_SQL, + spider_oracle_init, + spider_oracle_deinit, + spider_oracle_create_share, + spider_oracle_create_handler, + spider_oracle_create_copy_table, + spider_oracle_create_conn, + &spider_db_oracle_utility +}; + +spider_db_oracle_row::spider_db_oracle_row() : spider_db_row(), + db_conn(NULL), result(NULL), + ind(NULL), val(NULL), rlen(NULL), ind_first(NULL), val_first(NULL), + rlen_first(NULL), val_str(NULL), val_str_first(NULL), defnp(NULL), + lobhp(NULL), colhp(NULL), coltp(NULL), colsz(NULL), field_count(0), + row_size(NULL), row_size_first(NULL), access_charset(NULL), cloned(FALSE) +{ + DBUG_ENTER("spider_db_oracle_row::spider_db_oracle_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_oracle_row::~spider_db_oracle_row() +{ + DBUG_ENTER("spider_db_oracle_row::~spider_db_oracle_row"); + DBUG_PRINT("info",("spider this=%p", this)); + deinit(); + DBUG_VOID_RETURN; +} + +int spider_db_oracle_row::store_to_field( + Field *field, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_oracle_row::store_to_field"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider ind=%d", *ind)); + if (*ind == -1) + { + DBUG_PRINT("info", ("spider field is null")); + field->set_null(); + field->reset(); + } else { + DBUG_PRINT("info", ("spider field->type()=%u", field->type())); + field->set_notnull(); + if (field->type() == MYSQL_TYPE_YEAR) + { + field->store(val_str->ptr(), 4, + field->table->s->table_charset); + } else if (field->type() == MYSQL_TYPE_DATE) + { + field->store(val_str->ptr(), 10, + field->table->s->table_charset); + } else if (field->type() == MYSQL_TYPE_TIME) + { + field->store(val_str->ptr() + 11, 8, + field->table->s->table_charset); + } else { + DBUG_PRINT("info", ("spider val_str->length()=%u", val_str->length())); + if (field->flags & BLOB_FLAG) + { + DBUG_PRINT("info", ("spider blob field")); + ((Field_blob *)field)->set_ptr( + val_str->length(), (uchar *) val_str->ptr()); + } else { + field->store(val_str->ptr(), val_str->length(), + field->table->s->table_charset); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_oracle_row::append_to_str( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_row::append_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(val_str->length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(val_str->ptr(), val_str->length()); + DBUG_RETURN(0); +} + +int spider_db_oracle_row::append_escaped_to_str( + spider_string *str, + uint dbton_id +) { + DBUG_ENTER("spider_db_oracle_row::append_escaped_to_str"); + DBUG_PRINT("info",("spider this=%p", this)); +/* + spider_string tmp_str(*val, *rlen, str->charset()); + tmp_str.init_calc_mem(174); + tmp_str.length(*rlen); +#ifndef DBUG_OFF + tmp_str.c_ptr_safe(); +#endif + if (str->reserve(*rlen * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + util.append_escaped(str, tmp_str.get_str()); +*/ + if (str->reserve(val_str->length() * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + spider_dbton[dbton_id].db_util->append_escaped_util(str, val_str->get_str()); + DBUG_RETURN(0); +} + +void spider_db_oracle_row::first() +{ + DBUG_ENTER("spider_db_oracle_row::first"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider ind_first=%p", ind_first)); + ind = ind_first; + DBUG_PRINT("info",("spider val_first=%p", val_first)); + val = val_first; + DBUG_PRINT("info",("spider rlen_first=%p", rlen_first)); + rlen = rlen_first; + DBUG_PRINT("info",("spider row_size_first=%p", row_size_first)); + row_size = row_size_first; + DBUG_PRINT("info",("spider val_str_first=%p", val_str_first)); + val_str = val_str_first; + DBUG_VOID_RETURN; +} + +void spider_db_oracle_row::next() +{ + DBUG_ENTER("spider_db_oracle_row::next"); + DBUG_PRINT("info",("spider this=%p", this)); + ind++; + val++; + rlen++; + row_size++; + val_str++; + DBUG_VOID_RETURN; +} + +bool spider_db_oracle_row::is_null() +{ + DBUG_ENTER("spider_db_oracle_row::is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((*ind == -1)); +} + +int spider_db_oracle_row::val_int() +{ + DBUG_ENTER("spider_db_oracle_row::val_int"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((*ind != -1) ? atoi(*val) : 0); +} + +double spider_db_oracle_row::val_real() +{ + DBUG_ENTER("spider_db_oracle_row::val_real"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((*ind != -1) ? my_atof(*val) : 0.0); +} + +SPIDER_DB_ROW *spider_db_oracle_row::clone() +{ + uint i; + spider_db_oracle_row *clone_row; + DBUG_ENTER("spider_db_oracle_row::clone"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(clone_row = new spider_db_oracle_row())) + { + DBUG_RETURN(NULL); + } + clone_row->db_conn = db_conn; + clone_row->result = result; + clone_row->field_count = field_count; + clone_row->access_charset = access_charset; + clone_row->cloned = TRUE; + if (clone_row->init()) + { + delete clone_row; + DBUG_RETURN(NULL); + } + memcpy(clone_row->ind, ind_first, sizeof(ub2) * field_count * 4 + + sizeof(ulong) * field_count); + for (i = 0; i < field_count; i++) + { + if (clone_row->val_str[i].copy(val_str_first[i])) + { + delete clone_row; + DBUG_RETURN(NULL); + } + } + DBUG_RETURN((SPIDER_DB_ROW *) clone_row); +} + +int spider_db_oracle_row::store_to_tmp_table( + TABLE *tmp_table, + spider_string *str +) { + uint i; + DBUG_ENTER("spider_db_oracle_row::store_to_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + for (i = 0; i < field_count; i++) + { + if (row_size_first[i]) + { + if (str->reserve(val_str_first[i].length())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(val_str_first[i].ptr(), val_str_first[i].length()); + } + } + tmp_table->field[0]->set_notnull(); + tmp_table->field[0]->store( + (const char *) row_size_first, + sizeof(ulong) * field_count, &my_charset_bin); + tmp_table->field[1]->set_notnull(); + tmp_table->field[1]->store( + str->ptr(), str->length(), &my_charset_bin); + tmp_table->field[2]->set_notnull(); + tmp_table->field[2]->store( + (char *) ind_first, (uint) (sizeof(sb2) * field_count), &my_charset_bin); + DBUG_RETURN(tmp_table->file->ha_write_row(tmp_table->record[0])); +} + +int spider_db_oracle_row::init() +{ + char *tmp_val; + uint i; + DBUG_ENTER("spider_db_oracle_row::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + !(ind = (sb2 *) + spider_bulk_malloc(spider_current_trx, 161, MYF(MY_WME | MY_ZEROFILL), + &ind, sizeof(sb2) * field_count, + &rlen, sizeof(ub2) * field_count, + &coltp, sizeof(ub2) * field_count, + &colsz, sizeof(ub2) * field_count, + &row_size, sizeof(ulong) * field_count, + &val, sizeof(char *) * field_count, + &tmp_val, MAX_FIELD_WIDTH * field_count, + &defnp, sizeof(OCIDefine *) * field_count, + &lobhp, sizeof(OCILobLocator *) * field_count, + &colhp, sizeof(OCIParam *) * field_count, + NullS) + ) || + !(val_str = new spider_string[field_count]) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + ind_first = ind; + val_first = val; + rlen_first = rlen; + row_size_first = row_size; + val_str_first = val_str; + for (i = 0; i < field_count; i++) + { + val[i] = tmp_val; + val_str[i].init_calc_mem(177); + val_str[i].set(tmp_val, MAX_FIELD_WIDTH, access_charset); + tmp_val += MAX_FIELD_WIDTH; + } + DBUG_RETURN(0); +} + +void spider_db_oracle_row::deinit() +{ + uint i; + DBUG_ENTER("spider_db_oracle_row::deinit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!cloned) + { + for (i = 0; i < field_count; i++) + { + if (defnp && defnp[i]) + { + OCIHandleFree(defnp[i], OCI_HTYPE_DEFINE); + defnp[i] = NULL; + } + if (lobhp && lobhp[i]) + { + OCIDescriptorFree(lobhp[i], OCI_DTYPE_LOB); + lobhp[i] = NULL; + } + } + } + if (val_str_first) + { + delete [] val_str_first; + val_str_first = NULL; + } + if (ind_first) + { + spider_free(spider_current_trx, ind_first, MYF(0)); + ind_first = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_db_oracle_row::define() +{ + sword res; + uint i; + DBUG_ENTER("spider_db_oracle_row::define"); + DBUG_PRINT("info",("spider this=%p", this)); + for (i = 0; i < field_count; i++) + { + if (coltp[i] == SQLT_BLOB) + { + res = OCIDescriptorAlloc(db_conn->envhp, (dvoid **) &lobhp[i], + OCI_DTYPE_LOB, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_RETURN( + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL)); + } + res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, + &lobhp[i], 0, SQLT_BLOB, &ind[i], &rlen[i], NULL, + OCI_DEFAULT); + } else if (coltp[i] == SQLT_DAT) + { + res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, + (char *) val_str[i].ptr() + 20, sizeof(ub1) * 7, SQLT_DAT, &ind[i], + &rlen[i], NULL, OCI_DEFAULT); + } else { + if (val_str[i].alloc(colsz[i])) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + res = OCIDefineByPos(result->stmtp, &defnp[i], db_conn->errhp, i + 1, + (char *) val_str[i].ptr(), colsz[i], SQLT_CHR, &ind[i], &rlen[i], NULL, + OCI_DEFAULT); + } + if (res != OCI_SUCCESS) + { + DBUG_RETURN( + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL)); + } + } + DBUG_RETURN(0); +} + +int spider_db_oracle_row::fetch() +{ + sword res; + uint i; + DBUG_ENTER("spider_db_oracle_row::fetch"); + DBUG_PRINT("info",("spider this=%p", this)); + for (i = 0; i < field_count; i++) + { + if (ind[i] == -1) + { + DBUG_PRINT("info",("spider NULL")); + val_str[i].length(0); + } else { + if (coltp[i] == SQLT_BLOB) + { + DBUG_PRINT("info",("spider SQLT_BLOB")); + oraub8 len; + res = OCILobGetLength2(db_conn->svchp, db_conn->errhp, lobhp[i], &len); + if (res != OCI_SUCCESS) + { + DBUG_RETURN( + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL)); + } +#ifndef DBUG_OFF + { + ulonglong print_len = len; + DBUG_PRINT("info",("spider len=%llu", print_len)); + } +#endif + if (val_str[i].alloc(len)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + res = OCILobRead2(db_conn->svchp, db_conn->errhp, lobhp[i], &len, + NULL, 1, (char *) val_str[i].ptr(), len, OCI_ONE_PIECE, NULL, NULL, + 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_RETURN( + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL)); + } +#ifndef DBUG_OFF + { + ulonglong print_len = len; + DBUG_PRINT("info",("spider lenb=%llu", print_len)); + } +#endif + val_str[i].length(len); + } else if (coltp[i] == SQLT_DAT) + { + DBUG_PRINT("info",("spider SQLT_DAT")); + char *val = (char *) val_str[i].ptr(); + ub1 *src = (ub1 *) val + 20; + val_str[i].length(19); + if (src[0] < 100) + my_sprintf(val, (val, "0000-00-00 00:00:00")); + else + my_sprintf(val, (val, "%02u%02u-%02u-%02u %02u:%02u:%02u", + src[0] - 100, src[1] - 100, src[2], src[3], + src[4] - 1, src[5] - 1, src[6] - 1)); + } else { + val_str[i].length(rlen[i]); + } + } + row_size[i] = val_str[i].length(); + } + DBUG_RETURN(0); +} + +spider_db_oracle_result::spider_db_oracle_result() : spider_db_result(), + db_conn(NULL), stmtp(NULL), field_count(0), access_charset(NULL), + fetched(FALSE) +{ + DBUG_ENTER("spider_db_oracle_result::spider_db_oracle_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_oracle_result::~spider_db_oracle_result() +{ + DBUG_ENTER("spider_db_oracle_result::~spider_db_oracle_result"); + DBUG_PRINT("info",("spider this=%p", this)); + free_result(); + DBUG_VOID_RETURN; +} + +bool spider_db_oracle_result::has_result() +{ + DBUG_ENTER("spider_db_oracle_result::has_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(stmtp); +} + +void spider_db_oracle_result::free_result() +{ + DBUG_ENTER("spider_db_oracle_result::free_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (stmtp) + { + OCIHandleFree(stmtp, OCI_HTYPE_STMT); + stmtp = NULL; + } + DBUG_VOID_RETURN; +} + +SPIDER_DB_ROW *spider_db_oracle_result::current_row() +{ + DBUG_ENTER("spider_db_oracle_result::current_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); +} + +SPIDER_DB_ROW *spider_db_oracle_result::fetch_row() +{ + sword res; + DBUG_ENTER("spider_db_oracle_result::fetch_row"); + DBUG_PRINT("info",("spider this=%p", this)); + row.ind = row.ind_first; + row.val = row.val_first; + row.rlen = row.rlen_first; + row.row_size = row.row_size_first; + row.val_str = row.val_str_first; + if (fetched) + { + /* already fetched */ + fetched = FALSE; + } else { + res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_NEXT, 0, + OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + store_error_num = spider_db_oracle_get_error(res, db_conn->errhp, 0, + NULL, NULL, access_charset, NULL); + DBUG_RETURN(NULL); + } + } + if ((store_error_num = row.fetch())) + { + DBUG_RETURN(NULL); + } + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_oracle_result::fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf +) { + sword res; + DBUG_ENTER("spider_db_oracle_result::fetch_row_from_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + row.ind = row.ind_first; + row.val = row.val_first; + row.rlen = row.rlen_first; + row.row_size = row.row_size_first; + row.val_str = row.val_str_first; + if (fetched) + { + /* already fetched */ + fetched = FALSE; + } else { + res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_NEXT, 0, + OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + store_error_num = spider_db_oracle_get_error(res, db_conn->errhp, 0, + NULL, NULL, access_charset, NULL); + DBUG_RETURN(NULL); + } + } + if ((store_error_num = row.fetch())) + { + DBUG_RETURN(NULL); + } + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_oracle_result::fetch_row_from_tmp_table( + TABLE *tmp_table +) { + uint i; + const char *str; + spider_string tmp_str1, tmp_str2, tmp_str3; + DBUG_ENTER("spider_db_oracle_result::fetch_row_from_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_str1.init_calc_mem(175); + tmp_str2.init_calc_mem(178); + tmp_str3.init_calc_mem(179); + tmp_table->field[0]->val_str(tmp_str1.get_str()); + tmp_table->field[1]->val_str(tmp_str2.get_str()); + tmp_table->field[2]->val_str(tmp_str3.get_str()); + tmp_str1.mem_calc(); + tmp_str2.mem_calc(); + tmp_str3.mem_calc(); + row.ind = row.ind_first; + row.val = row.val_first; + row.rlen = row.rlen_first; + row.row_size = row.row_size_first; + row.val_str = row.val_str_first; + DBUG_PRINT("info",("spider tmp_str1.length()=%u", tmp_str1.length())); + DBUG_PRINT("info",("spider tmp_str2.length()=%u", tmp_str2.length())); + DBUG_PRINT("info",("spider tmp_str3.length()=%u", tmp_str3.length())); + memcpy(row.ind, tmp_str3.ptr(), tmp_str3.length()); + memcpy(row.row_size, tmp_str1.ptr(), tmp_str1.length()); + row.field_count = tmp_str1.length() / sizeof(ulong); + str = tmp_str2.ptr(); + for (i = 0; i < row.field_count; i++) + { + row.val_str[i].length(0); + if (row.row_size[i]) + { + if (row.val_str[i].reserve(row.row_size[i])) + { + store_error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + row.val_str[i].q_append(str, row.row_size[i]); + str += row.row_size[i]; + } + } + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +int spider_db_oracle_result::fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time +) { + DBUG_ENTER("spider_db_oracle_result::fetch_table_status"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + records = 2; + mean_rec_length = 65535; + data_file_length = 65535; + max_data_file_length = 65535; + index_file_length = 65535; +/* + auto_increment_value = 0; +*/ + create_time = (time_t) 0; + update_time = (time_t) 0; + check_time = (time_t) 0; + DBUG_RETURN(0); +} + +int spider_db_oracle_result::fetch_table_records( + int mode, + ha_rows &records +) { + DBUG_ENTER("spider_db_oracle_result::fetch_table_records"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!fetch_row()) + { + records = 0; + } else { + records = row.val_int(); + } + DBUG_RETURN(0); +} + +int spider_db_oracle_result::fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size +) { + DBUG_ENTER("spider_db_oracle_result::fetch_table_cardinality"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(0); +} + +int spider_db_oracle_result::fetch_table_mon_status( + int &status +) { + DBUG_ENTER("spider_db_oracle_result::fetch_table_mon_status"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + status = SPIDER_LINK_MON_OK; + DBUG_RETURN(0); +} + +longlong spider_db_oracle_result::num_rows() +{ + sword res; + ub4 rowcnt; + DBUG_ENTER("spider_db_oracle_result::num_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &rowcnt, 0, + OCI_ATTR_ROW_COUNT, db_conn->errhp); + if (res != OCI_SUCCESS) + { + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL); + DBUG_RETURN(0); + } + DBUG_PRINT("info",("spider rowcnt=%u", rowcnt)); + DBUG_RETURN((longlong) rowcnt); +} + +uint spider_db_oracle_result::num_fields() +{ + sword res; + ub4 parmcnt; + DBUG_ENTER("spider_db_oracle_result::num_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &parmcnt, 0, + OCI_ATTR_PARAM_COUNT, db_conn->errhp); + if (res != OCI_SUCCESS) + { + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL); + DBUG_RETURN(0); + } + DBUG_RETURN((uint) parmcnt); +} + +void spider_db_oracle_result::move_to_pos( + longlong pos +) { + sword res; + DBUG_ENTER("spider_db_oracle_result::move_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider pos=%lld", pos)); + res = OCIStmtFetch2(stmtp, db_conn->errhp, 1, OCI_FETCH_ABSOLUTE, pos, + OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, NULL, + access_charset, NULL); + } + DBUG_VOID_RETURN; +} + +int spider_db_oracle_result::set_column_info() +{ + sword res; + uint i; + DBUG_ENTER("spider_db_oracle_result::set_column_info"); + DBUG_PRINT("info",("spider this=%p", this)); + for (i = 0; i < field_count; i++) + { + res = OCIParamGet(stmtp, OCI_HTYPE_STMT, db_conn->errhp, + (dvoid **) &row.colhp[i], i + 1); + if (res != OCI_SUCCESS) + { + DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, + NULL, access_charset, NULL)); + } + res = OCIAttrGet(row.colhp[i], OCI_DTYPE_PARAM, &row.coltp[i], NULL, + OCI_ATTR_DATA_TYPE, db_conn->errhp); + if (res != OCI_SUCCESS) + { + DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, + NULL, access_charset, NULL)); + } + res = OCIAttrGet(row.colhp[i], OCI_DTYPE_PARAM, &row.colsz[i], NULL, + OCI_ATTR_DATA_SIZE, db_conn->errhp); + if (res != OCI_SUCCESS) + { + DBUG_RETURN(spider_db_oracle_get_error(res, db_conn->errhp, 0, NULL, + NULL, access_charset, NULL)); + } + } + DBUG_RETURN(0); +} + +int spider_db_oracle_result::get_errno() +{ + DBUG_ENTER("spider_db_oracle_result::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider store_error_num=%d", store_error_num)); + DBUG_RETURN(store_error_num); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_db_oracle_result::fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_oracle_result::fetch_columns_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + +int spider_db_oracle_result::fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_oracle_result::fetch_index_for_discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} +#endif + +spider_db_oracle::spider_db_oracle( + SPIDER_CONN *conn +) : spider_db_conn(conn), envhp(NULL), errhp(NULL), srvhp(NULL), svchp(NULL), + usrhp(NULL), stmtp(NULL), txnhp(NULL), result(NULL), table_lock_mode(0), + lock_table_hash_inited(FALSE), handler_open_array_inited(FALSE) +{ + DBUG_ENTER("spider_db_oracle::spider_db_oracle"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_oracle::~spider_db_oracle() +{ + DBUG_ENTER("spider_db_oracle::~spider_db_oracle"); + DBUG_PRINT("info",("spider this=%p", this)); + if (handler_open_array_inited) + { + reset_opened_handler(); + spider_free_mem_calc(spider_current_trx, + handler_open_array_id, + handler_open_array.max_element * + handler_open_array.size_of_element); + delete_dynamic(&handler_open_array); + } + if (lock_table_hash_inited) + { + spider_free_mem_calc(spider_current_trx, + lock_table_hash_id, + lock_table_hash.array.max_element * + lock_table_hash.array.size_of_element); + my_hash_free(&lock_table_hash); + } + disconnect(); + DBUG_VOID_RETURN; +} + +int spider_db_oracle::init() +{ + DBUG_ENTER("spider_db_oracle::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + my_hash_init(&lock_table_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_link_get_key, 0, 0) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_alloc_calc_mem_init(lock_table_hash, 199); + spider_alloc_calc_mem(spider_current_trx, + lock_table_hash, + lock_table_hash.array.max_element * + lock_table_hash.array.size_of_element); + lock_table_hash_inited = TRUE; + + if ( + SPD_INIT_DYNAMIC_ARRAY2(&handler_open_array, + sizeof(SPIDER_LINK_FOR_HASH *), NULL, 16, 16, MYF(MY_WME)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_alloc_calc_mem_init(handler_open_array, 164); + spider_alloc_calc_mem(spider_current_trx, + handler_open_array, + handler_open_array.max_element * + handler_open_array.size_of_element); + handler_open_array_inited = TRUE; + DBUG_RETURN(0); +} + +bool spider_db_oracle::is_connected() +{ + DBUG_ENTER("spider_db_oracle::is_connected"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(svchp); +} + +void spider_db_oracle::bg_connect() +{ + sword res; + DBUG_ENTER("spider_db_oracle::bg_connect"); + DBUG_PRINT("info",("spider this=%p", this)); + res = OCIEnvNlsCreate(&envhp, OCI_DEFAULT, 0, 0, 0, 0, 0, 0, 0, 0); +/* + res = OCIEnvCreate(&envhp, OCI_THREADED, 0, 0, 0, 0, 0, 0); +*/ + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create environment error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + goto error; + } + DBUG_PRINT("info",("spider OCI init envhp=%p", envhp)); + + res = OCIHandleAlloc(envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create error handler error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + DBUG_PRINT("info",("spider OCI init errhp=%p", errhp)); + + res = OCIHandleAlloc(envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create server handler error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + DBUG_PRINT("info",("spider OCI init srvhp=%p", srvhp)); + + res = OCIServerAttach(srvhp, errhp, (OraText *) tgt_host, strlen(tgt_host), + OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider attach server error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + + res = OCIHandleAlloc(envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create service context error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + DBUG_PRINT("info",("spider OCI init svchp=%p", svchp)); + + res = OCIAttrSet(svchp, OCI_HTYPE_SVCCTX, srvhp, 0, OCI_ATTR_SERVER, errhp); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider set server attr error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + + res = OCIHandleAlloc(envhp, (dvoid **) &usrhp, OCI_HTYPE_SESSION, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create session handler error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + DBUG_PRINT("info",("spider OCI init usrhp=%p", usrhp)); + + res = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, + tgt_username, strlen(tgt_username), OCI_ATTR_USERNAME, errhp); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider set username attr error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + + res = OCIAttrSet(usrhp, OCI_HTYPE_SESSION, + tgt_password, strlen(tgt_password), OCI_ATTR_PASSWORD, errhp); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider set password attr error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + + res = OCISessionBegin(svchp, errhp, usrhp, OCI_CRED_RDBMS, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider session begin error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + DBUG_PRINT("info",("spider OCISessionBegin")); + + // set the session in the context handle + res = OCIAttrSet(svchp, OCI_HTYPE_SVCCTX, usrhp, 0, OCI_ATTR_SESSION, errhp); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider set session attr error")); + stored_error_num = set_error(res, errhp, 0, NULL, NULL); + bg_disconnect(); + goto error; + } + + if ( + (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_DATE_FORMAT_STR, + SPIDER_SQL_SET_NLS_DATE_FORMAT_LEN, -1)) || + (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_TIME_FORMAT_STR, + SPIDER_SQL_SET_NLS_TIME_FORMAT_LEN, -1)) || + (stored_error_num = exec_query(SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_STR, + SPIDER_SQL_SET_NLS_TIMESTAMP_FORMAT_LEN, -1)) + ) { + DBUG_PRINT("info",("spider init connection error")); + bg_disconnect(); + goto error; + } + DBUG_VOID_RETURN; + +error: +#if MYSQL_VERSION_ID < 50500 + strmov(stored_error_msg, current_thd->main_da.message()); +#else + strmov(stored_error_msg, current_thd->stmt_da->message()); +#endif + current_thd->clear_error(); + DBUG_VOID_RETURN; +} + +int spider_db_oracle::connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval +) { + int error_num; + DBUG_ENTER("spider_db_oracle::connect"); + DBUG_PRINT("info",("spider this=%p", this)); + this->tgt_host = tgt_host; + this->tgt_username = tgt_username; + this->tgt_password = tgt_password; + this->tgt_port = tgt_port; + this->tgt_socket = tgt_socket; + this->server_name = server_name; + this->connect_retry_count = connect_retry_count; + this->connect_retry_interval = connect_retry_interval; + if ((error_num = spider_create_conn_thread(conn))) + DBUG_RETURN(error_num); + spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_CONNECT); + + if (stored_error_num) + { + my_message(stored_error_num, stored_error_msg, MYF(0)); + DBUG_RETURN(stored_error_num); + } + DBUG_RETURN(0); +} + +int spider_db_oracle::ping( +) { + sword res; + DBUG_ENTER("spider_db_oracle::ping"); + DBUG_PRINT("info",("spider this=%p", this)); + res = OCIPing(svchp, errhp, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider ping error %d", res)); + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + DBUG_RETURN(0); +} + +void spider_db_oracle::bg_disconnect() +{ + DBUG_ENTER("spider_db_oracle::bg_disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + if (result) + { + delete result; + result = NULL; + } + if (txnhp) + { + DBUG_PRINT("info",("spider OCI free txnhp=%p", txnhp)); + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + if (stmtp) + { + DBUG_PRINT("info",("spider OCI free stmtp=%p", stmtp)); + OCIHandleFree(stmtp, OCI_HTYPE_STMT); + stmtp = NULL; + } + if (svchp && errhp && usrhp) + { + DBUG_PRINT("info",("spider OCISessionEnd")); + OCISessionEnd(svchp, errhp, usrhp, OCI_DEFAULT); + } + if (usrhp) + { + DBUG_PRINT("info",("spider OCI free usrhp=%p", usrhp)); + OCIHandleFree(usrhp, OCI_HTYPE_SESSION); + usrhp = NULL; + } + if (svchp) + { + DBUG_PRINT("info",("spider OCI free svchp=%p", svchp)); + OCIHandleFree(svchp, OCI_HTYPE_SVCCTX); + svchp = NULL; + } + if (srvhp) + { + DBUG_PRINT("info",("spider OCI free srvhp=%p", srvhp)); + OCIServerDetach(srvhp, errhp, OCI_DEFAULT); + OCIHandleFree(srvhp, OCI_HTYPE_SERVER); + srvhp = NULL; + } + if (errhp) + { + DBUG_PRINT("info",("spider OCI free errhp=%p", errhp)); + OCIHandleFree(errhp, OCI_HTYPE_ERROR); + errhp = NULL; + } + if (envhp) + { + DBUG_PRINT("info",("spider OCI free envhp=%p", envhp)); + OCIHandleFree(envhp, OCI_HTYPE_ENV); + envhp = NULL; + } + DBUG_VOID_RETURN; +} + +void spider_db_oracle::disconnect() +{ + DBUG_ENTER("spider_db_oracle::disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!conn->bg_init) + DBUG_VOID_RETURN; + spider_bg_conn_simple_action(conn, SPIDER_BG_SIMPLE_DISCONNECT); + DBUG_VOID_RETURN; +} + +int spider_db_oracle::set_net_timeout() +{ + DBUG_ENTER("spider_db_oracle::set_net_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(0); +} + +int spider_db_oracle::exec_query( + const char *query, + uint length, + int quick_mode +) { + sword res; + int error_num; + DBUG_ENTER("spider_db_oracle::exec_query"); + DBUG_PRINT("info",("spider this=%p", this)); + stored_error_num = 0; + if (table_lock_mode && !conn->in_before_query) + { + DBUG_PRINT("info",("spider table_lock_mode=%d", table_lock_mode)); + table_lock_mode = 0; + if ((error_num = exec_query(exec_lock_sql->ptr(), exec_lock_sql->length(), + -1))) { + DBUG_RETURN(error_num); + } + } + + if (length) + { + if (result) + { + delete result; + result = NULL; + } + + if (!stmtp) + { + DBUG_PRINT("info",("spider create stmt")); + res = OCIHandleAlloc(envhp, (dvoid **) &stmtp, OCI_HTYPE_STMT, 0, 0); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider create stmt handler error")); + DBUG_RETURN(set_error(res, errhp, 0, NULL, NULL)); + } + } + + res = OCIStmtPrepare(stmtp, errhp, (OraText *) query, length, + OCI_NTV_SYNTAX, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider stmt prepare error")); + DBUG_RETURN(set_error(res, errhp, 0, NULL, NULL)); + } + +/* + if ((result = new spider_db_oracle_result())) + { + result->db_conn = this; + result->stmtp = stmtp; + stmtp = NULL; + result->field_count = result->num_fields(); + result->row.field_count = result->field_count; + result->row.db_conn = this; + result->row.result = result; + if ((error_num = result->row.init())) + { + delete result; + result = NULL; + DBUG_RETURN(error_num); + } + } else { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +*/ + + /* select statement check */ + ub4 iters; + if ( + !strncasecmp(query, "select ", sizeof("select ") - 1) || + !strncasecmp(query, "(select ", sizeof("(select ") - 1) + ) { + iters = 0; + } else { + iters = 1; + } + + if (quick_mode) + { + DBUG_PRINT("info",("spider use OCI_DEFAULT")); + res = OCIStmtExecute(svchp, stmtp, errhp, iters, 0, NULL, NULL, + OCI_DEFAULT); + } else { + DBUG_PRINT("info",("spider use OCI_STMT_SCROLLABLE_READONLY")); + res = OCIStmtExecute(svchp, stmtp, errhp, iters, 0, NULL, NULL, + OCI_STMT_SCROLLABLE_READONLY); +/* + if (res == OCI_SUCCESS) + { + DBUG_PRINT("info",("spider fetch last for row count")); + res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_LAST, 0, + OCI_DEFAULT); + } + if (res == OCI_SUCCESS) + { + DBUG_PRINT("info",("spider fetch first for row count")); + res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_FIRST, 0, + OCI_DEFAULT); + } +*/ + } + if (res == OCI_SUCCESS && iters) + { + DBUG_PRINT("info",("spider get row count")); + ub4 row_count; + res = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &row_count, 0, + OCI_ATTR_ROW_COUNT, errhp); + update_rows = (uint) row_count; + DBUG_PRINT("info",("spider row_count=%u", update_rows)); + } + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider stmt execute error")); + error_num = set_error(res, errhp, 0, NULL, NULL); + if (error_num == HA_ERR_END_OF_FILE) + DBUG_RETURN(0); + DBUG_RETURN(error_num); + } + + if ((result = new spider_db_oracle_result())) + { + result->db_conn = this; + result->stmtp = stmtp; + stmtp = NULL; + result->field_count = result->num_fields(); + result->row.field_count = result->field_count; + result->row.db_conn = this; + result->row.result = result; + result->row.access_charset = conn->access_charset; + result->access_charset = conn->access_charset; + if ( + (error_num = result->row.init()) || + (error_num = result->set_column_info()) + ) { + delete result; + result = NULL; + DBUG_RETURN(error_num); + } + result->row.define(); + } else { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if (!quick_mode && !iters) + { + if (res == OCI_SUCCESS) + { + DBUG_PRINT("info",("spider fetch last for row count")); + res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_LAST, 0, + OCI_DEFAULT); + } + if (res == OCI_SUCCESS) + { + DBUG_PRINT("info",("spider fetch first for row count")); + res = OCIStmtFetch2(result->stmtp, errhp, 1, OCI_FETCH_FIRST, 0, + OCI_DEFAULT); + } + if (res != OCI_SUCCESS) + { + DBUG_PRINT("info",("spider stmt execute error")); + error_num = set_error(res, errhp, 0, NULL, NULL); + if (error_num == HA_ERR_END_OF_FILE) + DBUG_RETURN(0); + DBUG_RETURN(error_num); + } + result->fetched = TRUE; + } + } + DBUG_RETURN(0); +} + +int spider_db_oracle::get_errno() +{ + DBUG_ENTER("spider_db_oracle::get_errno"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider stored_error=%d", stored_error_num)); + DBUG_RETURN(stored_error_num); +} + +const char *spider_db_oracle::get_error() +{ + DBUG_ENTER("spider_db_oracle::get_error"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider error=%s", stored_error)); + DBUG_RETURN(stored_error); +} + +bool spider_db_oracle::is_server_gone_error( + int error_num +) { + DBUG_ENTER("spider_db_oracle::is_server_gone_error"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(FALSE); +} + +bool spider_db_oracle::is_dup_entry_error( + int error_num +) { + DBUG_ENTER("spider_db_oracle::is_dup_entry_error"); + DBUG_PRINT("info",("spider this=%p", this)); + if (error_num == HA_ERR_FOUND_DUPP_KEY) + DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); +} + +bool spider_db_oracle::is_xa_nota_error( + int error_num +) { + DBUG_ENTER("spider_db_oracle::is_xa_nota_error"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(FALSE); +} + +spider_db_result *spider_db_oracle::store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_oracle_result *tmp_result = result; + DBUG_ENTER("spider_db_oracle::store_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(!spider_res_buf); + if (stored_error_num == HA_ERR_END_OF_FILE) + { + *error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + + *error_num = 0; + result = NULL; + DBUG_RETURN(tmp_result); +} + +spider_db_result *spider_db_oracle::use_result( + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_oracle_result *tmp_result = result; + DBUG_ENTER("spider_db_oracle::use_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (stored_error_num == HA_ERR_END_OF_FILE) + { + *error_num = HA_ERR_END_OF_FILE; + DBUG_RETURN(NULL); + } + + *error_num = 0; + result = NULL; + DBUG_RETURN(tmp_result); +} + +int spider_db_oracle::next_result() +{ + DBUG_ENTER("spider_db_oracle::next_result"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(-1); +} + +uint spider_db_oracle::affected_rows() +{ + DBUG_ENTER("spider_db_oracle::affected_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(update_rows); +} + +ulonglong spider_db_oracle::last_insert_id() +{ + DBUG_ENTER("spider_db_oracle::last_insert_id"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(stored_last_insert_id); +} + +int spider_db_oracle::set_character_set( + const char *csname +) { + DBUG_ENTER("spider_db_oracle::set_character_set"); + DBUG_PRINT("info",("spider this=%p", this)); + /* TODO: develop later */ + DBUG_RETURN(0); +} + +int spider_db_oracle::select_db( + const char *dbname +) { + DBUG_ENTER("spider_db_oracle::select_db"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do for oracle */ + DBUG_RETURN(0); +} + +int spider_db_oracle::consistent_snapshot( + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::consistent_snapshot"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do for oracle */ + DBUG_RETURN(0); +} + +bool spider_db_oracle::trx_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::trx_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::start_transaction( + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->in_before_query) + { + if (conn->queued_semi_trx_isolation) + { + if (conn->queued_semi_trx_isolation_val != conn->trx_isolation) + { + /* nothing to do */ + DBUG_RETURN(0); + } + } else if (conn->queued_trx_isolation) + { + if (conn->queued_trx_isolation_val != conn->trx_isolation) + { + /* nothing to do */ + DBUG_RETURN(0); + } + } + DBUG_RETURN(set_trx_isolation(conn->trx_isolation, need_mon)); + } + if (spider_db_query( + conn, + SPIDER_SQL_START_TRANSACTION_STR, + SPIDER_SQL_START_TRANSACTION_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_oracle::commit( + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::commit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->table_locked) + { + conn->table_locked = FALSE; + spider_current_trx->locked_connections--; + } + res = OCITransCommit(svchp, errhp, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + DBUG_RETURN(*need_mon); + } + DBUG_RETURN(0); +} + +int spider_db_oracle::rollback( + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->table_locked) + { + conn->table_locked = FALSE; + spider_current_trx->locked_connections--; + } + if (svchp && errhp) + { + res = OCITransRollback(svchp, errhp, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + DBUG_RETURN(*need_mon); + } + } + DBUG_RETURN(0); +} + +bool spider_db_oracle::xa_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::xa_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::xa_start( + XID *xid, + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (txnhp) + { + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + OCIHandleAlloc((dvoid *)envhp, (dvoid **)&txnhp, OCI_HTYPE_TRANS, 0, 0); + OCIAttrSet((dvoid *)svchp, OCI_HTYPE_SVCCTX, (dvoid *)txnhp, 0, + OCI_ATTR_TRANS, errhp); + OCIAttrSet((dvoid *)txnhp, OCI_HTYPE_TRANS, (dvoid *)xid, sizeof(XID), + OCI_ATTR_XID, errhp); + + res = OCITransStart(svchp, errhp, 31622400, OCI_TRANS_NEW); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + DBUG_RETURN(*need_mon); + } + DBUG_RETURN(0); +} + +int spider_db_oracle::xa_end( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::xa_end"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do for oracle */ + DBUG_RETURN(0); +} + +int spider_db_oracle::xa_prepare( + XID *xid, + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::xa_prepare"); + DBUG_PRINT("info",("spider this=%p", this)); + res = OCITransPrepare(svchp, errhp, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + DBUG_RETURN(*need_mon); + } + DBUG_RETURN(0); +} + +int spider_db_oracle::xa_commit( + XID *xid, + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::xa_commit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->table_locked) + { + conn->table_locked = FALSE; + spider_current_trx->locked_connections--; + } + res = OCITransCommit(svchp, errhp, OCI_TRANS_TWOPHASE); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + if (txnhp) + { + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + DBUG_RETURN(*need_mon); + } + if (txnhp) + { + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + DBUG_RETURN(0); +} + +int spider_db_oracle::xa_rollback( + XID *xid, + int *need_mon +) { + sword res; + DBUG_ENTER("spider_db_oracle::xa_rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + if (svchp && errhp) + { + res = OCITransRollback(svchp, errhp, OCI_DEFAULT); + if (res != OCI_SUCCESS) + { + *need_mon = set_error(res, errhp, 0, NULL, NULL); + if (txnhp) + { + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + DBUG_RETURN(*need_mon); + } + } + if (txnhp) + { + OCIHandleFree(txnhp, OCI_HTYPE_TRANS); + txnhp = NULL; + } + DBUG_RETURN(0); +} + +bool spider_db_oracle::set_trx_isolation_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::set_trx_isolation_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::set_trx_isolation( + int trx_isolation, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::set_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (trx_isolation) + { + case ISO_READ_UNCOMMITTED: + case ISO_READ_COMMITTED: + if (conn->in_before_query) + { + DBUG_RETURN(exec_query(SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1)); + } + if (spider_db_query( + conn, + SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_REPEATABLE_READ: + case ISO_SERIALIZABLE: + if (conn->in_before_query) + { + DBUG_RETURN(exec_query(SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1)); + } + if (spider_db_query( + conn, + SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + default: + DBUG_RETURN(HA_ERR_UNSUPPORTED); + } + DBUG_RETURN(0); +} + +bool spider_db_oracle::set_autocommit_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::set_autocommit_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::set_autocommit( + bool autocommit, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::set_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (autocommit) + { + if (conn->in_before_query) + { + DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1)); + } + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } else { + if (conn->in_before_query) + { + DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1)); + } + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN, + -1, + need_mon) + ) + DBUG_RETURN(spider_db_errorno(conn)); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(0); +} + +bool spider_db_oracle::set_sql_log_off_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::set_sql_log_off_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::set_sql_log_off( + bool sql_log_off, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::set_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_oracle::set_time_zone_in_bulk_sql() +{ + DBUG_ENTER("spider_db_oracle::set_time_zone_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_oracle::set_time_zone( + Time_zone *time_zone, + int *need_mon +) { + DBUG_ENTER("spider_db_oracle::set_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int spider_db_oracle::append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle::append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle::append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_select"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle::append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle::append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle::append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +void spider_db_oracle::reset_request_queue() +{ + DBUG_ENTER("spider_db_oracle::reset_request_queue"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_VOID_RETURN; +} +#endif + +size_t spider_db_oracle::escape_string( + char *to, + const char *from, + size_t from_length +) { + DBUG_ENTER("spider_db_oracle::escape_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(util.escape_string(to, from, from_length, conn->access_charset)); +} + +bool spider_db_oracle::have_lock_table_list() +{ + DBUG_ENTER("spider_db_oracle::have_lock_table_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +int spider_db_oracle::append_lock_tables( + spider_string *str +) { + int error_num; + ha_spider *tmp_spider; + int lock_type; + uint conn_link_idx; + int tmp_link_idx; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash; + const char *db_name; + uint db_name_length; + CHARSET_INFO *db_name_charset; + const char *table_name; + uint table_name_length; + CHARSET_INFO *table_name_charset; + DBUG_ENTER("spider_db_oracle::lock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((tmp_link_for_hash = + (SPIDER_LINK_FOR_HASH *) my_hash_element(&lock_table_hash, 0))) + { + if ((error_num = spider_db_oracle_utility.append_lock_table_head(str))) + { + DBUG_RETURN(error_num); + } + + tmp_spider = tmp_link_for_hash->spider; + tmp_link_idx = tmp_link_for_hash->link_idx; + switch (tmp_spider->lock_type) + { + case TL_READ: + lock_type = SPIDER_DB_TABLE_LOCK_READ_LOCAL; + break; + case TL_READ_NO_INSERT: + lock_type = SPIDER_DB_TABLE_LOCK_READ; + break; + case TL_WRITE_LOW_PRIORITY: + lock_type = SPIDER_DB_TABLE_LOCK_LOW_PRIORITY_WRITE; + break; + case TL_WRITE: + lock_type = SPIDER_DB_TABLE_LOCK_WRITE; + break; + default: + // no lock + DBUG_PRINT("info",("spider lock_type=%d", tmp_spider->lock_type)); + DBUG_RETURN(0); + } + conn_link_idx = tmp_spider->conn_link_idx[tmp_link_idx]; + spider_oracle_share *db_share = (spider_oracle_share *) + tmp_spider->share->dbton_share[conn->dbton_id]; + if (&db_share->db_names_str[conn_link_idx]) + { + db_name = db_share->db_names_str[conn_link_idx].ptr(); + db_name_length = db_share->db_names_str[conn_link_idx].length(); + db_name_charset = tmp_spider->share->access_charset; + } else { + db_name = tmp_spider->share->tgt_dbs[conn_link_idx]; + db_name_length = tmp_spider->share->tgt_dbs_lengths[conn_link_idx]; + db_name_charset = system_charset_info; + } + if (&db_share->table_names_str[conn_link_idx]) + { + table_name = db_share->table_names_str[conn_link_idx].ptr(); + table_name_length = db_share->table_names_str[conn_link_idx].length(); + table_name_charset = tmp_spider->share->access_charset; + } else { + table_name = tmp_spider->share->tgt_table_names[conn_link_idx]; + table_name_length = + tmp_spider->share->tgt_table_names_lengths[conn_link_idx]; + table_name_charset = system_charset_info; + } + if ((error_num = spider_db_oracle_utility. + append_lock_table_body( + str, + db_name, + db_name_length, + db_name_charset, + table_name, + table_name_length, + table_name_charset, + lock_type + ) + )) { + my_hash_reset(&lock_table_hash); + DBUG_RETURN(error_num); + } +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&lock_table_hash, + tmp_link_for_hash->db_table_str_hash_value, (uchar*) tmp_link_for_hash); +#else + my_hash_delete(&lock_table_hash, (uchar*) tmp_link_for_hash); +#endif + + if ((error_num = spider_db_oracle_utility.append_lock_table_tail(str))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_db_oracle::append_unlock_tables( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_db_oracle::append_unlock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_oracle_utility.append_unlock_table(str))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +uint spider_db_oracle::get_lock_table_hash_count() +{ + DBUG_ENTER("spider_db_oracle::get_lock_table_hash_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +void spider_db_oracle::reset_lock_table_hash() +{ + DBUG_ENTER("spider_db_oracle::reset_lock_table_hash"); + DBUG_PRINT("info",("spider this=%p", this)); + my_hash_reset(&lock_table_hash); + DBUG_VOID_RETURN; +} + +uint spider_db_oracle::get_opened_handler_count() +{ + DBUG_ENTER("spider_db_oracle::get_opened_handler_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(handler_open_array.elements); +} + +void spider_db_oracle::reset_opened_handler() +{ + ha_spider *tmp_spider; + int tmp_link_idx; + SPIDER_LINK_FOR_HASH **tmp_link_for_hash; + DBUG_ENTER("spider_db_oracle::reset_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + while ((tmp_link_for_hash = + (SPIDER_LINK_FOR_HASH **) pop_dynamic(&handler_open_array))) + { + tmp_spider = (*tmp_link_for_hash)->spider; + tmp_link_idx = (*tmp_link_for_hash)->link_idx; + tmp_spider->clear_handler_opened(tmp_link_idx, conn->conn_kind); + } + DBUG_VOID_RETURN; +} + +void spider_db_oracle::set_dup_key_idx( + ha_spider *spider, + int link_idx +) { + TABLE *table = spider->get_table(); + uint roop_count, pk_idx = table->s->primary_key; + int key_name_length; + int max_length = 0; + char *key_name, *tmp_pos; + char buf[SPIDER_ORACLE_ERR_BUF_LEN]; + DBUG_ENTER("spider_db_oracle::set_dup_key_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider error_str=%s", stored_error_msg)); + memcpy(buf, spider->share->tgt_dbs[link_idx], + spider->share->tgt_dbs_lengths[link_idx]); + tmp_pos = buf + spider->share->tgt_dbs_lengths[link_idx]; + *tmp_pos = '.'; + ++tmp_pos; + for (roop_count = 0; roop_count < table->s->keys; roop_count++) + { + if (roop_count == pk_idx) + { + DBUG_PRINT("info",("spider pk_idx=%u", roop_count)); + int all_link_idx = spider->conn_link_idx[link_idx]; + key_name = spider->share->tgt_pk_names[all_link_idx]; + key_name_length = spider->share->tgt_pk_names_lengths[all_link_idx]; + } else { + key_name = table->s->key_info[roop_count].name; + key_name_length = strlen(key_name); + } + memcpy(tmp_pos, key_name, key_name_length + 1); + DBUG_PRINT("info",("spider key_name=%s", key_name)); + DBUG_PRINT("info",("spider full key name=%s", buf)); + if ( + max_length < key_name_length && + strcasestr(stored_error_msg, buf) + ) { + max_length = key_name_length; + spider->dup_key_idx = roop_count; + } + } + if (max_length == 0) + spider->dup_key_idx = (uint) -1; + DBUG_PRINT("info",("spider dup_key_idx=%d", spider->dup_key_idx)); + DBUG_VOID_RETURN; +} + +bool spider_db_oracle::cmp_request_key_to_snd( + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_oracle::cmp_request_key_to_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_oracle::set_error( + sword res, + dvoid *hndlp, + int error_num, + const char *error1, + const char *error2 +) { + DBUG_ENTER("spider_db_oracle::set_error"); + DBUG_PRINT("info",("spider this=%p", this)); + stored_error_num = + spider_db_oracle_get_error(res, hndlp, error_num, error1, error2, + conn->access_charset, stored_error_msg); + if (stored_error_num) + stored_error = ER_SPIDER_ORACLE_ERR; + else + stored_error = ""; + DBUG_RETURN(stored_error_num); +} + +spider_db_oracle_util::spider_db_oracle_util() : spider_db_util() +{ + DBUG_ENTER("spider_db_oracle_util::spider_db_oracle_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_oracle_util::~spider_db_oracle_util() +{ + DBUG_ENTER("spider_db_oracle_util::~spider_db_oracle_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_oracle_util::append_name( + spider_string *str, + const char *name, + uint name_length +) { + DBUG_ENTER("spider_db_oracle_util::append_name"); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(name, name_length); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset +) { + DBUG_ENTER("spider_db_oracle_util::append_name_with_charset"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2 + name_length * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->append(name, name_length, name_charset); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +bool spider_db_oracle_util::is_name_quote( + const char head_code +) { + DBUG_ENTER("spider_db_oracle_util::is_name_quote"); + DBUG_RETURN(head_code == *name_quote_str); +} + +int spider_db_oracle_util::append_escaped_name_quote( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_util::append_escaped_name_quote"); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset +) { + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); + String *ptr; + uint length; + DBUG_ENTER("spider_db_oracle_util::append_column_value"); + tmp_str.init_calc_mem(181); + + if (new_ptr) + { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR + ) { + length = uint2korr(new_ptr); + tmp_str.set_quick((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, + &my_charset_bin); + ptr = tmp_str.get_str(); + } else if (field->type() == MYSQL_TYPE_GEOMETRY) + { +/* + uint mlength = SIZEOF_STORED_DOUBLE, lcnt; + uchar *dest = (uchar *) buf; + const uchar *source; + for (lcnt = 0; lcnt < 4; lcnt++) + { + mlength = SIZEOF_STORED_DOUBLE; + source = new_ptr + mlength + SIZEOF_STORED_DOUBLE * lcnt; + while (mlength--) + *dest++ = *--source; + } + tmp_str.length(SIZEOF_STORED_DOUBLE * lcnt); +*/ + double xmin, xmax, ymin, ymax; +/* + float8store(buf,xmin); + float8store(buf+8,xmax); + float8store(buf+16,ymin); + float8store(buf+24,ymax); + memcpy(&xmin,new_ptr,sizeof(xmin)); + memcpy(&xmax,new_ptr + 8,sizeof(xmax)); + memcpy(&ymin,new_ptr + 16,sizeof(ymin)); + memcpy(&ymax,new_ptr + 24,sizeof(ymax)); + float8get(xmin, buf); + float8get(xmax, buf + 8); + float8get(ymin, buf + 16); + float8get(ymax, buf + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + DBUG_PRINT("info", ("spider geo is %.14g %.14g %.14g %.14g", + xmin, xmax, ymin, ymax)); +*/ + float8get(xmin, new_ptr); + float8get(xmax, new_ptr + 8); + float8get(ymin, new_ptr + 16); + float8get(ymax, new_ptr + 24); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +/* + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 4); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 5); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 6); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 7); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 8); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 9); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 10); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 11); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); + float8get(xmin, new_ptr + SIZEOF_STORED_DOUBLE * 12); + float8get(xmax, new_ptr + SIZEOF_STORED_DOUBLE * 13); + float8get(ymin, new_ptr + SIZEOF_STORED_DOUBLE * 14); + float8get(ymax, new_ptr + SIZEOF_STORED_DOUBLE * 15); + DBUG_PRINT("info", ("spider geo is %f %f %f %f", + xmin, xmax, ymin, ymax)); +*/ +/* + tmp_str.set_quick((char *) new_ptr, SIZEOF_STORED_DOUBLE * 4, + &my_charset_bin); +*/ + tmp_str.length(0); + tmp_str.q_append((char *) SPIDER_SQL_LINESTRING_HEAD_STR, + SPIDER_SQL_LINESTRING_HEAD_LEN); + tmp_str.q_append((char *) new_ptr, SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 2, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE, + SIZEOF_STORED_DOUBLE); + tmp_str.q_append((char *) new_ptr + SIZEOF_STORED_DOUBLE * 3, + SIZEOF_STORED_DOUBLE); + ptr = tmp_str.get_str(); + } else { + ptr = field->val_str(tmp_str.get_str(), new_ptr); + tmp_str.mem_calc(); + } + } else { + ptr = field->val_str(tmp_str.get_str()); + tmp_str.mem_calc(); + } + DBUG_PRINT("info", ("spider field->type() is %d", field->type())); + DBUG_PRINT("info", ("spider ptr->length() is %d", ptr->length())); +/* + if ( + field->type() == MYSQL_TYPE_BIT || + (field->type() >= MYSQL_TYPE_TINY_BLOB && + field->type() <= MYSQL_TYPE_BLOB) + ) { + uchar *hex_ptr = (uchar *) ptr->ptr(), *end_ptr; + char *str_ptr; + DBUG_PRINT("info", ("spider HEX")); + if (str->reserve(SPIDER_SQL_HEX_LEN + ptr->length() * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HEX_STR, SPIDER_SQL_HEX_LEN); + str_ptr = (char *) str->ptr() + str->length(); + for (end_ptr = hex_ptr + ptr->length(); hex_ptr < end_ptr; hex_ptr++) + { + *str_ptr++ = spider_dig_upper[(*hex_ptr) >> 4]; + *str_ptr++ = spider_dig_upper[(*hex_ptr) & 0x0F]; + } + str->length(str->length() + ptr->length() * 2); + } else +*/ + if (field->result_type() == STRING_RESULT) + { + DBUG_PRINT("info", ("spider STRING_RESULT")); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if ( + field->type() == MYSQL_TYPE_VARCHAR || + (field->type() >= MYSQL_TYPE_ENUM && + field->type() <= MYSQL_TYPE_GEOMETRY) + ) { + DBUG_PRINT("info", ("spider append_escaped")); + char buf2[MAX_FIELD_WIDTH]; + spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, access_charset); + tmp_str2.init_calc_mem(182); + tmp_str2.length(0); + if ( + tmp_str2.append(ptr->ptr(), ptr->length(), field->charset()) || + str->reserve(tmp_str2.length() * 2) || + append_escaped_util(str, tmp_str2.get_str()) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else if (str->append(*ptr)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else if (field->str_needs_quotes()) + { + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + ptr->length() * 2 + 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + append_escaped_util(str, ptr); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else if (str->append(*ptr)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_from_with_alias( + spider_string *str, + const char **table_names, + uint *table_name_lengths, + const char **table_aliases, + uint *table_alias_lengths, + uint table_count, + int *table_name_pos, + bool over_write +) { + uint roop_count, length = 0; + DBUG_ENTER("spider_db_oracle_util::append_from_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!over_write) + { + for (roop_count = 0; roop_count < table_count; roop_count++) + length += table_name_lengths[roop_count] + SPIDER_SQL_SPACE_LEN + + table_alias_lengths[roop_count] + SPIDER_SQL_COMMA_LEN; + if (str->reserve(SPIDER_SQL_FROM_LEN + length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + *table_name_pos = str->length(); + } + for (roop_count = 0; roop_count < table_count; roop_count++) + { + str->q_append(table_names[roop_count], table_name_lengths[roop_count]); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(table_aliases[roop_count], table_alias_lengths[roop_count]); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_trx_isolation( + spider_string *str, + int trx_isolation +) { + DBUG_ENTER("spider_db_oracle_util::append_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_ISO_READ_COMMITTED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + switch (trx_isolation) + { + case ISO_READ_UNCOMMITTED: + case ISO_READ_COMMITTED: + str->q_append(SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN); + break; + case ISO_REPEATABLE_READ: + case ISO_SERIALIZABLE: + str->q_append(SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN); + break; + default: + DBUG_RETURN(HA_ERR_UNSUPPORTED); + } + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_autocommit( + spider_string *str, + bool autocommit +) { + DBUG_ENTER("spider_db_oracle_util::append_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_AUTOCOMMIT_OFF_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + if (autocommit) + { + str->q_append(SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN); + } else { + str->q_append(SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_sql_log_off( + spider_string *str, + bool sql_log_off +) { + DBUG_ENTER("spider_db_oracle_util::append_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_time_zone( + spider_string *str, + Time_zone *time_zone +) { + DBUG_ENTER("spider_db_oracle_util::append_time_zone"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_start_transaction( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_util::append_start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + + SPIDER_SQL_START_TRANSACTION_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + str->q_append(SPIDER_SQL_START_TRANSACTION_STR, + SPIDER_SQL_START_TRANSACTION_LEN); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_xa_start( + spider_string *str, + XID *xid +) { + DBUG_ENTER("spider_db_oracle_util::append_xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_lock_table_head( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_util::append_lock_table_head"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type +) { + DBUG_ENTER("spider_db_oracle_util::append_lock_table_body"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_LOCK_TABLE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->length()) + { + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); + if (str->reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ( + str->append(db_name, db_name_length, db_name_charset) || + str->reserve((SPIDER_SQL_NAME_QUOTE_LEN) * 2 + SPIDER_SQL_DOT_LEN) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ( + str->append(table_name, table_name_length, table_name_charset) || + str->reserve(SPIDER_SQL_NAME_QUOTE_LEN + + spider_db_table_lock_len[lock_type]) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(spider_db_table_lock_str[lock_type], + spider_db_table_lock_len[lock_type]); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_lock_table_tail( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_util::append_lock_table_tail"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::append_unlock_table( + spider_string *str +) { + DBUG_ENTER("spider_db_oracle_util::append_unlock_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_COMMIT_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_COMMIT_STR, SPIDER_SQL_COMMIT_LEN); + DBUG_RETURN(0); +} + +int spider_db_oracle_util::open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length +) { + uint dbton_id = spider_dbton_oracle.dbton_id; + int error_num; + Item *item, **item_list = item_func->arguments(); + uint roop_count, item_count = item_func->argument_count(), start_item = 0; + const char *func_name = SPIDER_SQL_NULL_CHAR_STR, + *separete_str = SPIDER_SQL_NULL_CHAR_STR, + *last_str = SPIDER_SQL_NULL_CHAR_STR; + int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, + separete_str_length = SPIDER_SQL_NULL_CHAR_LEN, + last_str_length = SPIDER_SQL_NULL_CHAR_LEN; + int use_pushdown_udf; + DBUG_ENTER("spider_db_oracle_util::open_item_func"); + if (str) + { + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + DBUG_PRINT("info",("spider functype = %d", item_func->functype())); + switch (item_func->functype()) + { + case Item_func::ISNULL_FUNC: + last_str = SPIDER_SQL_IS_NULL_STR; + last_str_length = SPIDER_SQL_IS_NULL_LEN; + break; + case Item_func::ISNOTNULL_FUNC: + last_str = SPIDER_SQL_IS_NOT_NULL_STR; + last_str_length = SPIDER_SQL_IS_NOT_NULL_LEN; + break; + case Item_func::UNKNOWN_FUNC: + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (func_name_length == 1 && + ( + !strncasecmp("+", func_name, func_name_length) || + !strncasecmp("-", func_name, func_name_length) || + !strncasecmp("*", func_name, func_name_length) || + !strncasecmp("/", func_name, func_name_length) || + !strncasecmp("%", func_name, func_name_length) || + !strncasecmp("&", func_name, func_name_length) || + !strncasecmp("|", func_name, func_name_length) || + !strncasecmp("^", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 2 && + ( + !strncasecmp("<<", func_name, func_name_length) || + !strncasecmp(">>", func_name, func_name_length) + ) + ) { + /* no action */ + break; + } else if (func_name_length == 3 && + !strncasecmp("div", func_name, func_name_length) + ) { + /* no action */ + break; + } else if (func_name_length == 4) + { + if ( + !strncasecmp("rand", func_name, func_name_length) && + !item_func->arg_count + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("case", func_name, func_name_length) + ) { +#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC + Item_func_case *item_func_case = (Item_func_case *) item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_CASE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN); + } + if (item_func_case->first_expr_num != -1) + { + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->first_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + for (roop_count = 0; roop_count < item_func_case->ncases; + roop_count += 2) + { + if (str) + { + if (str->reserve(SPIDER_SQL_WHEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_THEN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[roop_count + 1], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func_case->else_expr_num != -1) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ELSE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN); + } + if ((error_num = spider_db_print_item_type( + item_list[item_func_case->else_expr_num], spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +#else + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif + } + } else if (func_name_length == 6 && + !strncasecmp("istrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_TRUE_STR; + last_str_length = SPIDER_SQL_IS_TRUE_LEN; + break; + } else if (func_name_length == 7) + { + if (!strncasecmp("isfalse", func_name, func_name_length)) + { + last_str = SPIDER_SQL_IS_FALSE_STR; + last_str_length = SPIDER_SQL_IS_FALSE_LEN; + break; + } else if ( + !strncasecmp("sysdate", func_name, func_name_length) || + !strncasecmp("curdate", func_name, func_name_length) || + !strncasecmp("curtime", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if ( + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + if (str->reserve(func_name_length * 2 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } + } else if (func_name_length == 8 && + ( + !strncasecmp("utc_date", func_name, func_name_length) || + !strncasecmp("utc_time", func_name, func_name_length) + ) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 9 && + !strncasecmp("isnottrue", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_TRUE_STR; + last_str_length = SPIDER_SQL_IS_NOT_TRUE_LEN; + break; + } else if (func_name_length == 10 && + !strncasecmp("isnotfalse", func_name, func_name_length) + ) { + last_str = SPIDER_SQL_IS_NOT_FALSE_STR; + last_str_length = SPIDER_SQL_IS_NOT_FALSE_LEN; + break; + } else if (func_name_length == 12) + { + if (!strncasecmp("cast_as_date", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATE_STR; + last_str_length = SPIDER_SQL_AS_DATE_LEN; + break; + } else if (!strncasecmp("cast_as_time", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_TIME_STR; + last_str_length = SPIDER_SQL_AS_TIME_LEN; + break; + } + } else if (func_name_length == 13 && + !strncasecmp("utc_timestamp", func_name, func_name_length) + ) { + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + } else if (func_name_length == 14) + { + if (!strncasecmp("cast_as_binary", func_name, func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(123); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_BINARY_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_signed", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_SIGNED_STR; + last_str_length = SPIDER_SQL_AS_SIGNED_LEN; + break; + } + } else if (func_name_length == 16) + { + if (!strncasecmp("cast_as_unsigned", func_name, func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_UNSIGNED_STR; + last_str_length = SPIDER_SQL_AS_UNSIGNED_LEN; + break; + } else if (!strncasecmp("decimal_typecast", func_name, + func_name_length)) + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(124); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_DECIMAL_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + } else if (!strncasecmp("cast_as_datetime", func_name, + func_name_length)) + { + if (str) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + } + last_str = SPIDER_SQL_AS_DATETIME_STR; + last_str_length = SPIDER_SQL_AS_DATETIME_LEN; + break; + } + } else if (func_name_length == 17) + { + if (!strncasecmp("date_add_interval", func_name, func_name_length)) + { + Item_date_add_interval *item_date_add_interval = + (Item_date_add_interval *) item_func; + switch (item_date_add_interval->int_type) + { + case INTERVAL_YEAR: + case INTERVAL_QUARTER: + case INTERVAL_MONTH: + if (str) + { + if (str->reserve(SPIDER_SQL_ADD_MONTHS_LEN + + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ADD_MONTHS_STR, + SPIDER_SQL_ADD_MONTHS_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + } + if ((error_num = spider_db_print_item_type(item_list[0], spider, + str, alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->date_sub_interval) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN + + SPIDER_SQL_MINUS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(SPIDER_SQL_MINUS_STR, SPIDER_SQL_MINUS_LEN); + } else { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ((error_num = spider_db_print_item_type(item_list[1], spider, + str, alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->int_type == INTERVAL_YEAR) + { + func_name = " * 12"; + func_name_length = sizeof(" * 12") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (item_date_add_interval->int_type == + INTERVAL_QUARTER) + { + func_name = " * 3"; + func_name_length = sizeof(" * 3") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + } + break; + case INTERVAL_WEEK: + case INTERVAL_DAY: + case INTERVAL_HOUR: + case INTERVAL_MINUTE: + case INTERVAL_SECOND: + case INTERVAL_MICROSECOND: + if ((error_num = spider_db_print_item_type(item_list[0], spider, + str, alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->date_sub_interval) + { + if (str->reserve(SPIDER_SQL_MINUS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MINUS_STR, SPIDER_SQL_MINUS_LEN); + } else { + if (str->reserve(SPIDER_SQL_PLUS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_PLUS_STR, SPIDER_SQL_PLUS_LEN); + } + } + if ((error_num = spider_db_print_item_type(item_list[1], spider, + str, alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (item_date_add_interval->int_type == INTERVAL_WEEK) + { + func_name = " * 7"; + func_name_length = sizeof(" * 7") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (item_date_add_interval->int_type == INTERVAL_HOUR) + { + func_name = " / 24"; + func_name_length = sizeof(" / 24") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (item_date_add_interval->int_type == INTERVAL_MINUTE) + { + func_name = " / 1440"; + func_name_length = sizeof(" / 1440") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (item_date_add_interval->int_type == INTERVAL_SECOND) + { + func_name = " / 86400"; + func_name_length = sizeof(" / 86400") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (item_date_add_interval->int_type == + INTERVAL_MICROSECOND) + { + func_name = " / 86400000000"; + func_name_length = sizeof(" / 86400000000") - 1; + if (str->reserve(func_name_length + + (SPIDER_SQL_CLOSE_PAREN_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + } + } + break; + default: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + DBUG_RETURN(0); + break; + } + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::NOW_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::CHAR_TYPECAST_FUNC: + { + if (str) + { + char tmp_buf[MAX_FIELD_WIDTH], *tmp_ptr, *tmp_ptr2; + spider_string tmp_str(tmp_buf, MAX_FIELD_WIDTH, str->charset()); + tmp_str.init_calc_mem(125); + tmp_str.length(0); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(SPIDER_SQL_CAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); +#if MYSQL_VERSION_ID < 50500 + item_func->print(tmp_str.get_str(), QT_IS); +#else + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); +#endif + tmp_str.mem_calc(); + if (tmp_str.reserve(1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_ptr = tmp_str.c_ptr_quick(); + DBUG_PRINT("info",("spider tmp_ptr = %s", tmp_ptr)); + while ((tmp_ptr2 = strstr(tmp_ptr, SPIDER_SQL_AS_CHAR_STR))) + tmp_ptr = tmp_ptr2 + 1; + last_str = tmp_ptr - 1; + last_str_length = strlen(last_str) - SPIDER_SQL_CLOSE_PAREN_LEN; + } + } + break; + case Item_func::NOT_FUNC: + case Item_func::NEG_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + break; + case Item_func::IN_FUNC: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_IN_STR; + func_name_length = SPIDER_SQL_NOT_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } else { + func_name = SPIDER_SQL_IN_STR; + func_name_length = SPIDER_SQL_IN_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + } + break; + case Item_func::BETWEEN: + if (((Item_func_opt_neg *) item_func)->negated) + { + func_name = SPIDER_SQL_NOT_BETWEEN_STR; + func_name_length = SPIDER_SQL_NOT_BETWEEN_LEN; + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } else { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + separete_str = SPIDER_SQL_AND_STR; + separete_str_length = SPIDER_SQL_AND_LEN; + } + break; + case Item_func::UDF_FUNC: + use_pushdown_udf = spider_param_use_pushdown_udf(spider->trx->thd, + spider->share->use_pushdown_udf); + if (!use_pushdown_udf) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; +#ifdef MARIADB_BASE_VERSION + case Item_func::XOR_FUNC: +#else + case Item_func::COND_XOR_FUNC: +#endif + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN( + spider_db_open_item_cond((Item_cond *) item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::TRIG_COND_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::GUSERVAR_FUNC: + if (str) + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (item_func->result_type() == STRING_RESULT) + DBUG_RETURN(spider_db_open_item_string(item_func, spider, str, + alias, alias_length, dbton_id)); + else + DBUG_RETURN(spider_db_open_item_int(item_func, spider, str, + alias, alias_length, dbton_id)); + case Item_func::FT_FUNC: + if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + start_item = 1; + if (str) + { + if (str->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + } + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_EQUALS_FUNC: + if (str) + { + func_name = SPIDER_SQL_MBR_EQUAL_STR; + func_name_length = SPIDER_SQL_MBR_EQUAL_LEN; + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(func_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::SP_DISJOINT_FUNC: + case Item_func::SP_INTERSECTS_FUNC: + case Item_func::SP_TOUCHES_FUNC: + case Item_func::SP_CROSSES_FUNC: + case Item_func::SP_WITHIN_FUNC: + case Item_func::SP_CONTAINS_FUNC: + case Item_func::SP_OVERLAPS_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + if (str->reserve(SPIDER_SQL_MBR_LEN + func_name_length + + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MBR_STR, SPIDER_SQL_MBR_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + func_name = SPIDER_SQL_COMMA_STR; + func_name_length = SPIDER_SQL_COMMA_LEN; + separete_str = SPIDER_SQL_COMMA_STR; + separete_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + case Item_func::EQ_FUNC: + case Item_func::EQUAL_FUNC: + case Item_func::NE_FUNC: + case Item_func::LT_FUNC: + case Item_func::LE_FUNC: + case Item_func::GE_FUNC: + case Item_func::GT_FUNC: + case Item_func::LIKE_FUNC: + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + default: + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + if (spider_param_skip_default_condition(thd, + share->skip_default_condition)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + if (str) + { + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + } + break; + } + DBUG_PRINT("info",("spider func_name = %s", func_name)); + DBUG_PRINT("info",("spider func_name_length = %d", func_name_length)); + DBUG_PRINT("info",("spider separete_str = %s", separete_str)); + DBUG_PRINT("info",("spider separete_str_length = %d", separete_str_length)); + DBUG_PRINT("info",("spider last_str = %s", last_str)); + DBUG_PRINT("info",("spider last_str_length = %d", last_str_length)); + if (item_count) + { + item_count--; + for (roop_count = start_item; roop_count < item_count; roop_count++) + { + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (roop_count == 1) + { + func_name = separete_str; + func_name_length = separete_str_length; + } + if (str) + { + if (str->reserve(func_name_length + SPIDER_SQL_SPACE_LEN * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(func_name, func_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + } + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + } + if (item_func->functype() == Item_func::FT_FUNC) + { + Item_func_match *item_func_match = (Item_func_match *)item_func; + if (str) + { + if (str->reserve(SPIDER_SQL_AGAINST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); + } + item = item_list[0]; + if ((error_num = spider_db_print_item_type(item, spider, str, + alias, alias_length, dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve( + ((item_func_match->flags & FT_BOOL) ? + SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((item_func_match->flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (item_func_match->flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (item_func_match->flags & FT_EXPAND) + str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); + } + } else if (item_func->functype() == Item_func::UNKNOWN_FUNC) + { + if ( + func_name_length == 7 && + !strncasecmp("convert", func_name, func_name_length) + ) { + if (str) + { + Item_func_conv_charset *item_func_conv_charset = + (Item_func_conv_charset *)item_func; + CHARSET_INFO *conv_charset = item_func_conv_charset->conv_charset; + uint cset_length = strlen(conv_charset->csname); + if (str->reserve(SPIDER_SQL_USING_LEN + cset_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); + str->q_append(conv_charset->csname, cset_length); + } + } + } + if (str) + { + if (str->reserve(last_str_length + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(last_str, last_str_length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + DBUG_RETURN(0); +} + +size_t spider_db_oracle_util::escape_string( + char *to, + const char *from, + size_t from_length, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_oracle::escape_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(escape_quotes_for_mysql(access_charset, to, 0, + from, from_length)); +} + +int spider_db_oracle_util::append_escaped_util( + spider_string *to, + String *from +) { + size_t copy_length; + DBUG_ENTER("spider_db_oracle_util::append_escaped_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider to=%s", to->c_ptr_safe())); + DBUG_PRINT("info",("spider from=%s", from->c_ptr_safe())); + copy_length = escape_string((char *) to->ptr() + to->length(), from->ptr(), + from->length(), to->charset()); + DBUG_PRINT("info",("spider copy_length=%zu", copy_length)); + to->length(to->length() + copy_length); + to->mem_calc(); + DBUG_RETURN(0); +} + +spider_oracle_share::spider_oracle_share( + st_spider_share *share +) : spider_db_share( + share +), + table_select(NULL), + table_select_pos(0), + key_select(NULL), + key_select_pos(NULL), + key_hint(NULL), + show_table_status(NULL), + show_records(NULL), + show_autoinc(NULL), + show_last_insert_id(NULL), + show_index(NULL), + table_names_str(NULL), + db_names_str(NULL), + db_table_str(NULL), + nextval_str(NULL), +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value(NULL), +#endif + table_nm_max_length(0), + db_nm_max_length(0), + nextval_max_length(0), + column_name_str(NULL), + same_db_table_name(TRUE), + first_all_link_idx(-1) +{ + DBUG_ENTER("spider_oracle_share::spider_oracle_share"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 220); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_oracle_share::~spider_oracle_share() +{ + DBUG_ENTER("spider_oracle_share::~spider_oracle_share"); + DBUG_PRINT("info",("spider this=%p", this)); + if (table_select) + delete [] table_select; + if (key_select) + delete [] key_select; + if (key_hint) + delete [] key_hint; + free_show_table_status(); + free_show_records(); + free_show_autoinc(); + free_show_last_insert_id(); + free_show_index(); + free_column_name_str(); + free_table_names_str(); + if (key_select_pos) + { + spider_free(spider_current_trx, key_select_pos, MYF(0)); + } + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_oracle_share::init() +{ + int error_num; + uint roop_count; + TABLE_SHARE *table_share = spider_share->table_share; + uint keys = table_share ? table_share->keys : 0; + DBUG_ENTER("spider_oracle_share::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(key_select_pos = (int *) + spider_bulk_alloc_mem(spider_current_trx, 221, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &key_select_pos, + sizeof(int) * keys, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + &db_table_str_hash_value, + sizeof(my_hash_value_type) * spider_share->all_link_count, +#endif + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if (keys > 0 && + !(key_hint = new spider_string[keys]) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + for (roop_count = 0; roop_count < keys; roop_count++) + { + key_hint[roop_count].init_calc_mem(190); + key_hint[roop_count].set_charset(spider_share->access_charset); + } + DBUG_PRINT("info",("spider key_hint=%p", key_hint)); + + if ( + !(table_select = new spider_string[1]) || + (keys > 0 && + !(key_select = new spider_string[keys]) + ) || + (error_num = create_table_names_str()) || + (table_share && + ( + (error_num = create_column_name_str()) || + (error_num = convert_key_hint_str()) || + (error_num = append_show_table_status()) || + (error_num = append_show_records()) || + (error_num = append_show_autoinc()) || + (error_num = append_show_last_insert_id()) || + (error_num = append_show_index()) + ) + ) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + table_select->init_calc_mem(191); + if (table_share && (error_num = append_table_select())) + DBUG_RETURN(error_num); + + for (roop_count = 0; roop_count < keys; roop_count++) + { + key_select[roop_count].init_calc_mem(192); + if ((error_num = append_key_select(roop_count))) + DBUG_RETURN(error_num); + } + + DBUG_RETURN(error_num); +} + +uint spider_oracle_share::get_column_name_length( + uint field_index +) { + DBUG_ENTER("spider_oracle_share::get_column_name_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(column_name_str[field_index].length()); +} + +int spider_oracle_share::append_column_name( + spider_string *str, + uint field_index +) { + int error_num; + DBUG_ENTER("spider_oracle_share::append_column_name"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_oracle_utility.append_name(str, + column_name_str[field_index].ptr(), column_name_str[field_index].length()); + DBUG_RETURN(error_num); +} + +int spider_oracle_share::append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_oracle_share::append_column_name_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve( + alias_length + + column_name_str[field_index].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + append_column_name(str, field_index); + DBUG_RETURN(0); +} + +int spider_oracle_share::append_table_name( + spider_string *str, + int all_link_idx +) { + const char *db_nm = db_names_str[all_link_idx].ptr(); + uint db_nm_len = db_names_str[all_link_idx].length(); + const char *table_nm = table_names_str[all_link_idx].ptr(); + uint table_nm_len = table_names_str[all_link_idx].length(); + DBUG_ENTER("spider_oracle_share::append_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(db_nm_len + SPIDER_SQL_DOT_LEN + table_nm_len + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); + DBUG_RETURN(0); +} + +int spider_oracle_share::append_table_name_with_adjusting( + spider_string *str, + int all_link_idx +) { + const char *db_nm = db_names_str[all_link_idx].ptr(); + uint db_nm_len = db_names_str[all_link_idx].length(); + uint db_nm_max_len = db_nm_max_length; + const char *table_nm = table_names_str[all_link_idx].ptr(); + uint table_nm_len = table_names_str[all_link_idx].length(); + uint table_nm_max_len = table_nm_max_length; + DBUG_ENTER("spider_oracle_share::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); + uint length = + db_nm_max_len - db_nm_len + + table_nm_max_len - table_nm_len; + memset((char *) str->ptr() + str->length(), ' ', length); + str->length(str->length() + length); + DBUG_RETURN(0); +} + +int spider_oracle_share::append_from_with_adjusted_table_name( + spider_string *str, + int *table_name_pos +) { + const char *db_nm = db_names_str[0].ptr(); + uint db_nm_len = db_names_str[0].length(); + uint db_nm_max_len = db_nm_max_length; + const char *table_nm = table_names_str[0].ptr(); + uint table_nm_len = table_names_str[0].length(); + uint table_nm_max_len = table_nm_max_length; + DBUG_ENTER("spider_oracle_share::append_from_with_adjusted_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_FROM_LEN + db_nm_max_length + + SPIDER_SQL_DOT_LEN + table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + *table_name_pos = str->length(); + spider_db_oracle_utility.append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_oracle_utility.append_name(str, table_nm, table_nm_len); + uint length = + db_nm_max_len - db_nm_len + + table_nm_max_len - table_nm_len; + memset((char *) str->ptr() + str->length(), ' ', length); + str->length(str->length() + length); + DBUG_RETURN(0); +} + +int spider_oracle_share::create_table_names_str() +{ + int error_num, roop_count; + uint table_nm_len, db_nm_len; + spider_string *str, *first_tbl_nm_str, *first_db_nm_str, *first_db_tbl_str; + char *first_tbl_nm, *first_db_nm; + uint dbton_id = spider_dbton_oracle.dbton_id; + DBUG_ENTER("spider_oracle_share::create_table_names_str"); + table_names_str = NULL; + db_names_str = NULL; + db_table_str = NULL; + if ( + !(table_names_str = new spider_string[spider_share->all_link_count]) || + !(db_names_str = new spider_string[spider_share->all_link_count]) || + !(db_table_str = new spider_string[spider_share->all_link_count]) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + + same_db_table_name = TRUE; + first_tbl_nm = spider_share->tgt_table_names[0]; + first_db_nm = spider_share->tgt_dbs[0]; + table_nm_len = spider_share->tgt_table_names_lengths[0]; + db_nm_len = spider_share->tgt_dbs_lengths[0]; + first_tbl_nm_str = &table_names_str[0]; + first_db_nm_str = &db_names_str[0]; + first_db_tbl_str = &db_table_str[0]; + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + table_names_str[roop_count].init_calc_mem(193); + db_names_str[roop_count].init_calc_mem(194); + db_table_str[roop_count].init_calc_mem(195); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + if (first_all_link_idx == -1) + first_all_link_idx = roop_count; + + str = &table_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_table_names_lengths[roop_count] == table_nm_len && + !memcmp(first_tbl_nm, spider_share->tgt_table_names[roop_count], + table_nm_len) + ) { + if (str->copy(*first_tbl_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_table_names[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different table name %s", + spider_share->tgt_table_names[roop_count])); + if (str->length() > table_nm_max_length) + table_nm_max_length = str->length(); + } else + table_nm_max_length = str->length(); + } + + str = &db_names_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name && + spider_share->tgt_dbs_lengths[roop_count] == db_nm_len && + !memcmp(first_db_nm, spider_share->tgt_dbs[roop_count], + db_nm_len) + ) { + if (str->copy(*first_db_nm_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + spider_share->tgt_dbs[roop_count], dbton_id))) + goto error; + if (roop_count) + { + same_db_table_name = FALSE; + DBUG_PRINT("info", ("spider found different db name %s", + spider_share->tgt_dbs[roop_count])); + if (str->length() > db_nm_max_length) + db_nm_max_length = str->length(); + } else + db_nm_max_length = str->length(); + } + + str = &db_table_str[roop_count]; + if ( + roop_count != 0 && + same_db_table_name + ) { + if (str->copy(*first_db_tbl_str)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + } else { + str->set_charset(spider_share->access_charset); + if ((error_num = append_table_name(str, roop_count))) + goto error; + } +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + db_table_str_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) str->ptr(), str->length()); +#endif + } + DBUG_RETURN(0); + +error: + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_oracle_share::free_table_names_str() +{ + DBUG_ENTER("spider_oracle_share::free_table_names_str"); + if (db_table_str) + { + delete [] db_table_str; + db_table_str = NULL; + } + if (db_names_str) + { + delete [] db_names_str; + db_names_str = NULL; + } + if (table_names_str) + { + delete [] table_names_str; + table_names_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::create_column_name_str() +{ + spider_string *str; + int error_num; + Field **field; + TABLE_SHARE *table_share = spider_share->table_share; + uint dbton_id = spider_dbton_oracle.dbton_id; + DBUG_ENTER("spider_oracle_share::create_column_name_str"); + if ( + table_share->fields && + !(column_name_str = new spider_string[table_share->fields]) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + for (field = table_share->field, str = column_name_str; + *field; field++, str++) + { + str->init_calc_mem(196); + str->set_charset(spider_share->access_charset); + if ((error_num = spider_db_append_name_with_quote_str(str, + (char *) (*field)->field_name, dbton_id))) + goto error; + } + DBUG_RETURN(0); + +error: + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_RETURN(error_num); +} + +void spider_oracle_share::free_column_name_str() +{ + DBUG_ENTER("spider_oracle_share::free_column_name_str"); + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::convert_key_hint_str() +{ + spider_string *tmp_key_hint; + int roop_count; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_oracle_share::convert_key_hint_str"); + if (spider_share->access_charset->cset != system_charset_info->cset) + { + /* need convertion */ + for (roop_count = 0, tmp_key_hint = key_hint; + roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) + { + tmp_key_hint->length(0); + if (tmp_key_hint->append(spider_share->key_hint->ptr(), + spider_share->key_hint->length(), system_charset_info)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + for (roop_count = 0, tmp_key_hint = key_hint; + roop_count < (int) table_share->keys; roop_count++, tmp_key_hint++) + { + if (tmp_key_hint->copy(spider_share->key_hint[roop_count])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_share::append_show_table_status() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_oracle.dbton_id; + DBUG_ENTER("spider_oracle_append_show_table_status"); + if (!(show_table_status = + new spider_string[2 * spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_table_status[0 + (2 * roop_count)].init_calc_mem(197); + show_table_status[1 + (2 * roop_count)].init_calc_mem(207); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_table_status[0 + (2 * roop_count)].reserve( + SPIDER_SQL_SHOW_TABLE_STATUS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_LIKE_LEN + table_names_str[roop_count].length() + + ((SPIDER_SQL_NAME_QUOTE_LEN) * 2) + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 2)) || + show_table_status[1 + (2 * roop_count)].reserve( + SPIDER_SQL_SELECT_TABLES_STATUS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + + table_names_str[roop_count].length() + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4)) + ) + goto error; + str = &show_table_status[0 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SHOW_TABLE_STATUS_STR, SPIDER_SQL_SHOW_TABLE_STATUS_LEN); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + str->q_append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str = &show_table_status[1 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SELECT_TABLES_STATUS_STR, + SPIDER_SQL_SELECT_TABLES_STATUS_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + DBUG_RETURN(0); + +error: + if (show_table_status) + { + delete [] show_table_status; + show_table_status = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_oracle_share::free_show_table_status() +{ + DBUG_ENTER("spider_oracle_free_show_table_status"); + if (show_table_status) + { + delete [] show_table_status; + show_table_status = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::append_show_records() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_oracle.dbton_id; + DBUG_ENTER("spider_oracle_share::append_show_records"); + if (!(show_records = new spider_string[spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_records[roop_count].init_calc_mem(208); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_records[roop_count].reserve( + SPIDER_SQL_SHOW_RECORDS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) + ) + goto error; + str = &show_records[roop_count]; + str->q_append(SPIDER_SQL_SHOW_RECORDS_STR, SPIDER_SQL_SHOW_RECORDS_LEN); + append_table_name(str, roop_count); + } + DBUG_RETURN(0); + +error: + if (show_records) + { + delete [] show_records; + show_records = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_oracle_share::free_show_records() +{ + DBUG_ENTER("spider_oracle_share::free_show_records"); + if (show_records) + { + delete [] show_records; + show_records = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::append_show_autoinc() +{ + uint roop_count, field_length; + spider_string *str; + uint dbton_id = spider_dbton_oracle.dbton_id; + Field **found_next_number_field = + spider_share->table_share->found_next_number_field; + DBUG_ENTER("spider_oracle_share::append_show_autoinc"); + if (!found_next_number_field) + DBUG_RETURN(0); + + if (!(show_autoinc = new spider_string[spider_share->all_link_count])) + goto error; + + field_length = + column_name_str[(*found_next_number_field)->field_index].length(); + for (roop_count = 0; roop_count < spider_share->all_link_count; + roop_count++) + { + show_autoinc[roop_count].init_calc_mem(224); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_autoinc[roop_count].reserve( + SPIDER_SQL_SELECT_LEN + + SPIDER_SQL_MAX_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + + field_length + + SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_FROM_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 6) + ) + goto error; + str = &show_autoinc[roop_count]; + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + str->q_append(SPIDER_SQL_MAX_STR, SPIDER_SQL_MAX_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + append_column_name(str, (*found_next_number_field)->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + append_table_name(str, roop_count); + } + DBUG_RETURN(0); + +error: + if (show_autoinc) + { + delete [] show_autoinc; + show_autoinc = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_oracle_share::free_show_autoinc() +{ + DBUG_ENTER("spider_oracle_share::free_show_autoinc"); + if (show_autoinc) + { + delete [] show_autoinc; + show_autoinc = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::append_show_last_insert_id() +{ + uint roop_count; + spider_string *str; + uint dbton_id = spider_dbton_oracle.dbton_id; + Field **found_next_number_field = + spider_share->table_share->found_next_number_field; + uint seq_nm_max_length = 0; + DBUG_ENTER("spider_oracle_share::append_show_last_insert_id"); + if (!found_next_number_field) + DBUG_RETURN(0); + + if ( + !(show_last_insert_id = new spider_string[spider_share->all_link_count]) || + !(nextval_str = new spider_string[spider_share->all_link_count]) + ) + goto error; + + for (roop_count = 0; roop_count < spider_share->all_link_count; + roop_count++) + { + show_last_insert_id[roop_count].init_calc_mem(225); + nextval_str[roop_count].init_calc_mem(226); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_last_insert_id[roop_count].reserve( + SPIDER_SQL_SELECT_LEN + + spider_share->tgt_sequence_names_lengths[roop_count] + + SPIDER_SQL_CURRVAL_LEN + + SPIDER_SQL_FROM_DUAL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2) + ) + goto error; + str = &show_last_insert_id[roop_count]; + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + spider_db_oracle_utility.append_name(str, + spider_share->tgt_sequence_names[roop_count], + spider_share->tgt_sequence_names_lengths[roop_count]); + str->q_append(SPIDER_SQL_CURRVAL_STR, SPIDER_SQL_CURRVAL_LEN); + str->q_append(SPIDER_SQL_FROM_DUAL_STR, SPIDER_SQL_FROM_DUAL_LEN); + + if (seq_nm_max_length < + spider_share->tgt_sequence_names_lengths[roop_count]) + { + seq_nm_max_length = + spider_share->tgt_sequence_names_lengths[roop_count]; + } + } + for (roop_count = 0; roop_count < spider_share->all_link_count; + roop_count++) + { + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + nextval_str[roop_count].reserve( + seq_nm_max_length + + SPIDER_SQL_NEXTVAL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2) + ) + goto error; + str = &nextval_str[roop_count]; + spider_db_oracle_utility.append_name(str, + spider_share->tgt_sequence_names[roop_count], + spider_share->tgt_sequence_names_lengths[roop_count]); + str->q_append(SPIDER_SQL_NEXTVAL_STR, SPIDER_SQL_NEXTVAL_LEN); + uint length = + seq_nm_max_length - spider_share->tgt_sequence_names_lengths[roop_count]; + memset((char *) str->ptr() + str->length(), ' ', length); + str->length(str->length() + length); + nextval_max_length = str->length(); + } + DBUG_RETURN(0); + +error: + if (show_last_insert_id) + { + delete [] show_last_insert_id; + show_last_insert_id = NULL; + } + if (nextval_str) + { + delete [] nextval_str; + nextval_str = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_oracle_share::free_show_last_insert_id() +{ + DBUG_ENTER("spider_oracle_share::free_show_last_insert_id"); + if (show_last_insert_id) + { + delete [] show_last_insert_id; + show_last_insert_id = NULL; + } + if (nextval_str) + { + delete [] nextval_str; + nextval_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::append_show_index() +{ + int roop_count; + spider_string *str; + uint dbton_id = spider_dbton_oracle.dbton_id; + DBUG_ENTER("spider_oracle_share::append_show_index"); + if (!(show_index = new spider_string[2 * spider_share->all_link_count])) + goto error; + + for (roop_count = 0; roop_count < (int) spider_share->all_link_count; + roop_count++) + { + show_index[0 + (2 * roop_count)].init_calc_mem(209); + show_index[1 + (2 * roop_count)].init_calc_mem(210); + if (spider_share->sql_dbton_ids[roop_count] != dbton_id) + continue; + + if ( + show_index[0 + (2 * roop_count)].reserve( + SPIDER_SQL_SHOW_INDEX_LEN + db_names_str[roop_count].length() + + SPIDER_SQL_DOT_LEN + + table_names_str[roop_count].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4) || + show_index[1 + (2 * roop_count)].reserve( + SPIDER_SQL_SELECT_STATISTICS_LEN + + db_names_str[roop_count].length() + + SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN + + table_names_str[roop_count].length() + + ((SPIDER_SQL_VALUE_QUOTE_LEN) * 4) + + SPIDER_SQL_GROUP_LEN + SPIDER_SQL_COLUMN_NAME_LEN) + ) + goto error; + str = &show_index[0 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SHOW_INDEX_STR, SPIDER_SQL_SHOW_INDEX_LEN); + append_table_name(str, roop_count); + str = &show_index[1 + (2 * roop_count)]; + str->q_append( + SPIDER_SQL_SELECT_STATISTICS_STR, SPIDER_SQL_SELECT_STATISTICS_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + str->q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); + str->q_append(SPIDER_SQL_COLUMN_NAME_STR, SPIDER_SQL_COLUMN_NAME_LEN); + } + DBUG_RETURN(0); + +error: + if (show_index) + { + delete [] show_index; + show_index = NULL; + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +void spider_oracle_share::free_show_index() +{ + DBUG_ENTER("spider_oracle_share::free_show_index"); + if (show_index) + { + delete [] show_index; + show_index = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_share::append_table_select() +{ + Field **field; + uint field_length; + spider_string *str = table_select; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_oracle_share::append_table_select"); + for (field = table_share->field; *field; field++) + { + field_length = column_name_str[(*field)->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(append_from_with_adjusted_table_name(str, &table_select_pos)); +} + +int spider_oracle_share::append_key_select( + uint idx +) { + KEY_PART_INFO *key_part; + Field *field; + uint part_num; + uint field_length; + spider_string *str = &key_select[idx]; + TABLE_SHARE *table_share = spider_share->table_share; + const KEY *key_info = &table_share->key_info[idx]; + DBUG_ENTER("spider_oracle_share::append_key_select"); + for (key_part = key_info->key_part, part_num = 0; + part_num < key_info->key_parts; key_part++, part_num++) + { + field = key_part->field; + field_length = column_name_str[field->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(append_from_with_adjusted_table_name(str, &key_select_pos[idx])); +} + +bool spider_oracle_share::need_change_db_table_name() +{ + DBUG_ENTER("spider_oracle_share::need_change_db_table_name"); + DBUG_RETURN(!same_db_table_name); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_oracle_share::discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +) { + DBUG_ENTER("spider_oracle_share::discover_table_structure"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} +#endif + +spider_oracle_handler::spider_oracle_handler( + ha_spider *spider, + spider_oracle_share *db_share +) : spider_db_handler( + spider, + db_share +), + where_pos(0), + order_pos(0), + limit_pos(0), + table_name_pos(0), + update_set_pos(0), + ha_read_pos(0), + ha_next_pos(0), + ha_where_pos(0), + ha_limit_pos(0), + ha_table_name_pos(0), + insert_pos(0), + insert_table_name_pos(0), + upd_tmp_tbl(NULL), + tmp_sql_pos1(0), + tmp_sql_pos2(0), + tmp_sql_pos3(0), + tmp_sql_pos4(0), + tmp_sql_pos5(0), + table_lock_mode(0), + reading_from_bulk_tmp_table(FALSE), + filled_up(FALSE), + select_rownum_appended(FALSE), + update_rownum_appended(FALSE), + oracle_share(db_share), + link_for_hash(NULL) +{ + DBUG_ENTER("spider_oracle_handler::spider_oracle_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_alloc_calc_mem_init(mem_calc, 222); + spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this)); + DBUG_VOID_RETURN; +} + +spider_oracle_handler::~spider_oracle_handler() +{ + DBUG_ENTER("spider_oracle_handler::~spider_oracle_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (link_for_hash) + { + spider_free(spider_current_trx, link_for_hash, MYF(0)); + } + spider_free_mem_calc(spider_current_trx, mem_calc_id, sizeof(*this)); + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::init() +{ + uint roop_count; + THD *thd = spider->trx->thd; + st_spider_share *share = spider->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + DBUG_ENTER("spider_oracle_handler::init"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.init_calc_mem(67); + sql_part.init_calc_mem(68); + sql_part2.init_calc_mem(69); + ha_sql.init_calc_mem(70); + insert_sql.init_calc_mem(72); + update_sql.init_calc_mem(73); + tmp_sql.init_calc_mem(74); + dup_update_sql.init_calc_mem(167); + if ( + (sql.real_alloc(init_sql_alloc_size)) || + (insert_sql.real_alloc(init_sql_alloc_size)) || + (update_sql.real_alloc(init_sql_alloc_size)) || + (tmp_sql.real_alloc(init_sql_alloc_size)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.set_charset(share->access_charset); + sql_part.set_charset(share->access_charset); + ha_sql.set_charset(share->access_charset); + insert_sql.set_charset(share->access_charset); + update_sql.set_charset(share->access_charset); + tmp_sql.set_charset(share->access_charset); + upd_tmp_tbl_prm.init(); + upd_tmp_tbl_prm.field_count = 1; + if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *) + spider_bulk_alloc_mem(spider_current_trx, 223, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &link_for_hash, + sizeof(SPIDER_LINK_FOR_HASH) * share->link_count, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + link_for_hash[roop_count].spider = spider; + link_for_hash[roop_count].link_idx = roop_count; + link_for_hash[roop_count].db_table_str = + &oracle_share->db_table_str[roop_count]; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + link_for_hash[roop_count].db_table_str_hash_value = + oracle_share->db_table_str_hash_value[roop_count]; +#endif + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + hs_upds.init(); +#endif + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type +) { + int error_num = 0; + DBUG_ENTER("spider_oracle_handler::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + } else { + error_num = oracle_share->append_table_name_with_adjusting(str, + spider->conn_link_idx[link_idx]); + } + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_column_types( + const key_range *start_key, + spider_string *str +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + KEY *key_info = result_list->key_info; + uint key_name_length, key_count; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + char tmp_buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(tmp_buf, sizeof(tmp_buf), system_charset_info); + DBUG_ENTER("spider_oracle_handler::append_key_column_types"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_str.init_calc_mem(227); + + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + for ( + key_part = key_info->key_part, + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(key_name_length + SPIDER_SQL_SPACE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(tmp_buf, key_name_length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + + if (tmp_str.ptr() != tmp_buf) + tmp_str.set(tmp_buf, sizeof(tmp_buf), system_charset_info); + else + tmp_str.set_charset(system_charset_info); + field->sql_type(*tmp_str.get_str()); + tmp_str.mem_calc(); + str->append(tmp_str); + + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_join_columns_for_bka( + const key_range *start_key, + spider_string *str, + const char **table_aliases, + uint *table_alias_lengths +) { + KEY *key_info = spider->result_list.key_info; + uint length, key_name_length, key_count; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + char tmp_buf[MAX_FIELD_WIDTH]; + bool start_where = ((int) str->length() == where_pos); + DBUG_ENTER("spider_oracle_handler::append_key_join_columns_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + if (start_where) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + } else { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + + for ( + key_part = key_info->key_part, + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(length + table_alias_lengths[0] + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + table_alias_lengths[1] + SPIDER_SQL_PF_EQUAL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(table_aliases[0], table_alias_lengths[0]); + str->q_append(tmp_buf, length); + str->q_append(SPIDER_SQL_PF_EQUAL_STR, SPIDER_SQL_PF_EQUAL_LEN); + str->q_append(table_aliases[1], table_alias_lengths[1]); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + str->length(str->length() - SPIDER_SQL_AND_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_tmp_table_and_sql_for_bka( + const key_range *start_key +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + char tmp_table_name[MAX_FIELD_WIDTH * 2], + tgt_table_name[MAX_FIELD_WIDTH * 2]; + int tmp_table_name_length; + spider_string tgt_table_name_str(tgt_table_name, MAX_FIELD_WIDTH * 2, + oracle_share->db_names_str[0].charset()); + const char *table_names[2], *table_aliases[2], *table_dot_aliases[2]; + uint table_name_lengths[2], table_alias_lengths[2], + table_dot_alias_lengths[2]; + tgt_table_name_str.init_calc_mem(200); + tgt_table_name_str.length(0); + create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, + first_link_idx); + if ((error_num = append_table_name_with_adjusting(&tgt_table_name_str, + first_link_idx, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + table_names[0] = tmp_table_name; + table_names[1] = tgt_table_name_str.c_ptr_safe(); + table_name_lengths[0] = tmp_table_name_length; + table_name_lengths[1] = tgt_table_name_str.length(); + table_aliases[0] = SPIDER_SQL_A_STR; + table_aliases[1] = SPIDER_SQL_B_STR; + table_alias_lengths[0] = SPIDER_SQL_A_LEN; + table_alias_lengths[1] = SPIDER_SQL_B_LEN; + table_dot_aliases[0] = SPIDER_SQL_A_DOT_STR; + table_dot_aliases[1] = SPIDER_SQL_B_DOT_STR; + table_dot_alias_lengths[0] = SPIDER_SQL_A_DOT_LEN; + table_dot_alias_lengths[1] = SPIDER_SQL_B_DOT_LEN; + if ( + (error_num = append_drop_tmp_bka_table( + &tmp_sql, tmp_table_name, tmp_table_name_length, + &tmp_sql_pos1, &tmp_sql_pos5, TRUE)) || + (error_num = append_create_tmp_bka_table( + start_key, + &tmp_sql, tmp_table_name, + tmp_table_name_length, + &tmp_sql_pos2, spider->share->table_share->table_charset)) || + (error_num = append_insert_tmp_bka_table( + start_key, + &tmp_sql, tmp_table_name, + tmp_table_name_length, &tmp_sql_pos3)) + ) + DBUG_RETURN(error_num); + tmp_sql_pos4 = tmp_sql.length(); + if ((error_num = spider_db_append_select(spider))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_A_DOT_LEN + SPIDER_SQL_ID_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_A_DOT_STR, SPIDER_SQL_A_DOT_LEN); + sql.q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ( + (error_num = append_select_columns_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) || + (error_num = spider_db_oracle_utility.append_from_with_alias(&sql, + table_names, table_name_lengths, + table_aliases, table_alias_lengths, 2, + &table_name_pos, FALSE)) + ) + DBUG_RETURN(error_num); + if ( + oracle_share->key_hint && + (error_num = spider_db_append_hint_after_table(spider, + &sql, &oracle_share->key_hint[spider->active_index])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = sql.length(); + if ( + (error_num = append_key_join_columns_for_bka( + start_key, &sql, + table_dot_aliases, table_dot_alias_lengths)) || + (error_num = append_condition_part( + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, + SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) || + ( + spider->result_list.direct_order_limit && + (error_num = append_key_order_for_direct_order_limit_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) + ) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_oracle_handler::reuse_tmp_table_and_sql_for_bka() +{ + DBUG_ENTER("spider_oracle_handler::reuse_tmp_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_sql.length(tmp_sql_pos4); + sql.length(limit_pos); + ha_sql.length(ha_limit_pos); + DBUG_RETURN(0); +} + +void spider_oracle_handler::create_tmp_bka_table_name( + char *tmp_table_name, + int *tmp_table_name_length, + int link_idx +) { + uint adjust_length = + oracle_share->db_nm_max_length - + oracle_share->db_names_str[spider->conn_link_idx[link_idx]].length() + + oracle_share->table_nm_max_length - + oracle_share->table_names_str[spider->conn_link_idx[link_idx]].length(), + length; + DBUG_ENTER("spider_oracle_handler::create_tmp_bka_table_name"); + *tmp_table_name_length = oracle_share->db_nm_max_length + + oracle_share->table_nm_max_length; + memset(tmp_table_name, ' ', adjust_length); + tmp_table_name += adjust_length; + memcpy(tmp_table_name, oracle_share->db_names_str[link_idx].c_ptr(), + oracle_share->db_names_str[link_idx].length()); + tmp_table_name += oracle_share->db_names_str[link_idx].length(); + length = my_sprintf(tmp_table_name, (tmp_table_name, + "%s%s%p%s", SPIDER_SQL_DOT_STR, SPIDER_SQL_TMP_BKA_STR, spider, + SPIDER_SQL_UNDERSCORE_STR)); + *tmp_table_name_length += length; + tmp_table_name += length; + memcpy(tmp_table_name, + oracle_share->table_names_str[spider->conn_link_idx[link_idx]].c_ptr(), + oracle_share->table_names_str[spider->conn_link_idx[link_idx]].length()); + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::append_create_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + CHARSET_INFO *table_charset +) { + int error_num; + SPIDER_SHARE *share = spider->share; + THD *thd = spider->trx->thd; + char *bka_engine = spider_param_bka_engine(thd, share->bka_engine); + uint bka_engine_length = strlen(bka_engine), + cset_length = strlen(table_charset->csname); + DBUG_ENTER("spider_oracle_handler::append_create_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_CREATE_TMP_LEN + tmp_table_name_length + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + SPIDER_SQL_ID_TYPE_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CREATE_TMP_STR, SPIDER_SQL_CREATE_TMP_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + str->q_append(SPIDER_SQL_ID_TYPE_STR, SPIDER_SQL_ID_TYPE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ((error_num = append_key_column_types(start_key, str))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_ENGINE_LEN + bka_engine_length + + SPIDER_SQL_DEF_CHARSET_LEN + cset_length + SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ENGINE_STR, SPIDER_SQL_ENGINE_LEN); + str->q_append(bka_engine, bka_engine_length); + str->q_append(SPIDER_SQL_DEF_CHARSET_STR, SPIDER_SQL_DEF_CHARSET_LEN); + str->q_append(table_charset->csname, cset_length); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_drop_tmp_bka_table( + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + int *drop_table_end_pos, + bool with_semicolon +) { + DBUG_ENTER("spider_oracle_handler::append_drop_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_DROP_TMP_LEN + tmp_table_name_length + + (with_semicolon ? SPIDER_SQL_SEMICOLON_LEN : 0))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DROP_TMP_STR, SPIDER_SQL_DROP_TMP_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + *drop_table_end_pos = str->length(); + if (with_semicolon) + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_insert_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_insert_tmp_bka_table"); + if (str->reserve(SPIDER_SQL_INSERT_LEN + SPIDER_SQL_INTO_LEN + + tmp_table_name_length + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_ID_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + *db_name_pos = str->length(); + str->q_append(tmp_table_name, tmp_table_name_length); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if ((error_num = spider_db_append_key_columns(start_key, spider, str))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_insert_for_recovery( + ulong sql_type, + int link_idx +) { + const TABLE *table = spider->get_table(); + SPIDER_SHARE *share = spider->share; + Field **field; + uint field_name_length = 0; + bool add_value = FALSE; + spider_string *insert_sql; + DBUG_ENTER("spider_oracle_handler::append_insert_for_recovery"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) + { + insert_sql = &spider->result_list.insert_sqls[link_idx]; + insert_sql->length(0); + } else { + insert_sql = &spider->result_list.update_sqls[link_idx]; + } + if (insert_sql->reserve( + SPIDER_SQL_INSERT_LEN + SPIDER_SQL_SQL_IGNORE_LEN + + SPIDER_SQL_INTO_LEN + oracle_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + insert_sql->q_append(SPIDER_SQL_SQL_IGNORE_STR, SPIDER_SQL_SQL_IGNORE_LEN); + insert_sql->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + oracle_share->append_table_name(insert_sql, spider->conn_link_idx[link_idx]); + insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + field_name_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if (insert_sql->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(insert_sql, (*field)->field_index); + insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (field_name_length) + insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); + if (insert_sql->reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + insert_sql->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + add_value = TRUE; + if ((*field)->is_null()) + { + if (insert_sql->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if ( + spider_db_oracle_utility. + append_column_value(spider, insert_sql, *field, NULL, + share->access_charset) || + insert_sql->reserve(SPIDER_SQL_COMMA_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + insert_sql->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (add_value) + insert_sql->length(insert_sql->length() - SPIDER_SQL_COMMA_LEN); + if (insert_sql->reserve(SPIDER_SQL_CLOSE_PAREN_LEN, SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + if (sql_type == SPIDER_SQL_TYPE_INSERT_SQL) + { + exec_insert_sql = insert_sql; + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_oracle_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_update(str, 0)) || + (error_num = append_update_set(str)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.update_sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::append_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_update(str, link_idx)) || + (error_num = append_update_set(str)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + + if ( + spider->pk_update && + share->link_statuses[link_idx] == SPIDER_LINK_STATUS_RECOVERY + ) { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + if ((error_num = append_insert_for_recovery( + SPIDER_SQL_TYPE_UPDATE_SQL, link_idx))) + DBUG_RETURN(error_num); + } + + if (!filled_up) + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_oracle_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, + first_link_idx)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx +) { + int error_num; + spider_string *str = &spider->result_list.update_sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::append_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->length() > 0) + { + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + } + + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, SPIDER_SQL_TYPE_DELETE_SQL, link_idx)) || + (error_num = append_update_where(str, table, ptr_diff)) + ) + DBUG_RETURN(error_num); + if (!filled_up) + filled_up = (str->length() >= (uint) spider->result_list.bulk_update_size); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_insert_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_insert_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_insert(&insert_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_insert( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_oracle_handler::append_insert"); + if (str->reserve(SPIDER_SQL_INSERT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_update_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_update_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update(&update_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_update( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_oracle_handler::append_update"); + if (str->reserve(SPIDER_SQL_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_UPDATE_STR, SPIDER_SQL_UPDATE_LEN); + if (str->reserve(oracle_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, SPIDER_SQL_TYPE_UPDATE_SQL); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_delete_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_delete_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_delete(&update_sql); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_delete( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_delete"); + if (str->reserve(SPIDER_SQL_DELETE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DELETE_STR, SPIDER_SQL_DELETE_LEN); + str->length(str->length() - 1); + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_oracle_handler::append_increment_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_increment_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_increment_update_set(&update_sql); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_increment_update_set( + spider_string *str +) { + uint field_name_length; + uint roop_count; + Field *field; + DBUG_ENTER("spider_oracle_handler::append_increment_update_set"); + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + const SPIDER_HS_STRING_REF *value = hs_upds.ptr(); + for (roop_count = 0; roop_count < hs_upds.size(); + roop_count++) + { + DBUG_PRINT("info",("spider value_size[%u]=%zu", roop_count, + value[roop_count].size())); +#ifndef DBUG_OFF + char print_buf[MAX_FIELD_WIDTH]; + if (value[roop_count].size() < MAX_FIELD_WIDTH) + { + memcpy(print_buf, value[roop_count].begin(), value[roop_count].size()); + print_buf[value[roop_count].size()] = '\0'; + DBUG_PRINT("info",("spider value[%u]=%s", roop_count, print_buf)); + } +#endif + if ( + value[roop_count].size() == 1 && + *(value[roop_count].begin()) == '0' + ) + continue; + + Field *top_table_field = + spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); + if (!(field = spider->field_exchange(top_table_field))) + continue; + field_name_length = + oracle_share->column_name_str[field->field_index].length(); + + if (str->reserve(field_name_length * 2 + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 4 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_HS_INCREMENT_LEN + + SPIDER_SQL_COMMA_LEN + value[roop_count].size())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + oracle_share->append_column_name(str, field->field_index); + if (spider->hs_increment) + str->q_append(SPIDER_SQL_HS_INCREMENT_STR, + SPIDER_SQL_HS_INCREMENT_LEN); + else + str->q_append(SPIDER_SQL_HS_DECREMENT_STR, + SPIDER_SQL_HS_DECREMENT_LEN); + str->q_append(value[roop_count].begin(), value[roop_count].size()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} +#endif +#endif + +int spider_oracle_handler::append_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + update_set_pos = update_sql.length(); + error_num = append_update_set(&update_sql); + where_pos = update_sql.length(); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_update_set( + spider_string *str +) { + uint field_name_length; + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + Field **fields; + DBUG_ENTER("spider_oracle_handler::append_update_set"); + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + for (fields = table->field; *fields; fields++) + { + if (bitmap_is_set(table->write_set, (*fields)->field_index)) + { + field_name_length = + oracle_share->column_name_str[(*fields)->field_index].length(); + if ((*fields)->is_null()) + { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*fields)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*fields)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, + table->read_set); +#endif + if ( + spider_db_oracle_utility. + append_column_value(spider, str, *fields, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +int spider_oracle_handler::append_direct_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::append_direct_update_set_part"); + DBUG_PRINT("info",("spider this=%p", this)); + update_set_pos = update_sql.length(); + error_num = append_direct_update_set(&update_sql); + where_pos = update_sql.length(); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_direct_update_set( + spider_string *str +) { + uint field_name_length; + SPIDER_SHARE *share = spider->share; +#ifndef DBUG_OFF + TABLE *table = spider->get_table(); +#endif + DBUG_ENTER("spider_oracle_handler::append_direct_update_set"); + if ( + spider->direct_update_kinds == SPIDER_SQL_KIND_SQL && + spider->direct_update_fields + ) { + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + DBUG_RETURN(append_update_columns(str, NULL, 0)); + } + + if ( + (spider->direct_update_kinds & SPIDER_SQL_KIND_SQL) + ) { + size_t roop_count; + Field *field; + if (str->reserve(SPIDER_SQL_SET_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SET_STR, SPIDER_SQL_SET_LEN); + for (roop_count = 0; roop_count < spider->hs_pushed_ret_fields_num; + roop_count++) + { + Field *top_table_field = + spider->get_top_table_field(spider->hs_pushed_ret_fields[roop_count]); + if (!(field = spider->field_exchange(top_table_field))) + continue; + field_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (top_table_field->is_null()) + { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN + SPIDER_SQL_NULL_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if (str->reserve(field_name_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ + 2 + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = dbug_tmp_use_all_columns(table, + table->read_set); +#endif + if ( + spider_db_oracle_utility. + append_column_value(spider, str, top_table_field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_dup_update_pushdown_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_dup_update_pushdown_part"); + DBUG_PRINT("info",("spider this=%p", this)); + dup_update_sql.length(0); + error_num = append_update_columns(&dup_update_sql, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_update_columns_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update_columns(&update_sql, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::check_update_columns_part() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::check_update_columns_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update_columns(NULL, NULL, 0); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_update_columns( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + List_iterator_fast fi(*spider->direct_update_fields), + vi(*spider->direct_update_values); + Item *field, *value; + DBUG_ENTER("spider_oracle_handler::append_update_columns"); + while ((field = fi++)) + { + value = vi++; + if ((error_num = spider_db_print_item_type( + (Item *) field, spider, str, alias, alias_length, + spider_dbton_oracle.dbton_id))) + { + if ( + error_num == ER_SPIDER_COND_SKIP_NUM && + field->type() == Item::FIELD_ITEM && + ((Item_field *) field)->field + ) + continue; + DBUG_RETURN(error_num); + } + if (str) + { + if (str->reserve(SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + } + if ((error_num = spider_db_print_item_type( + (Item *) value, spider, str, alias, alias_length, + spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (str) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if (str) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +/* + error_num = spider_db_append_update_columns(spider, str, + alias, alias_length, spider_dbton_oracle.dbton_id); + DBUG_RETURN(error_num); +*/ +} +#endif + +int spider_oracle_handler::append_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_select(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_select( + spider_string *str, + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::append_select"); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + if (str->reserve(SPIDER_SQL_HANDLER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + } else { + if (str->reserve(SPIDER_SQL_SELECT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_table_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_table_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_table_select(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_table_select( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_table_select"); + table_name_pos = str->length() + oracle_share->table_select_pos; + if (str->append(*(oracle_share->table_select))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_select_part( + ulong sql_type, + uint idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_key_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_select(str, idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_select( + spider_string *str, + uint idx +) { + DBUG_ENTER("spider_oracle_handler::append_key_select"); + table_name_pos = str->length() + oracle_share->key_select_pos[idx]; + if (str->append(oracle_share->key_select[idx])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_minimum_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_minimum_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_minimum_select(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_minimum_select( + spider_string *str, + ulong sql_type +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + DBUG_ENTER("spider_oracle_handler::append_minimum_select"); + for (field = table->field; *field; field++) + { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + field_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + else { + if (str->reserve(SPIDER_SQL_ONE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); + } + DBUG_RETURN(append_from(str, sql_type, first_link_idx)); +} + +int spider_oracle_handler::append_table_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + DBUG_ENTER("spider_oracle_handler::append_table_select_with_alias"); + for (field = table->field; *field; field++) + { + field_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_select_with_alias( + spider_string *str, + const KEY *key_info, + const char *alias, + uint alias_length +) { + KEY_PART_INFO *key_part; + Field *field; + uint part_num; + int field_length; + DBUG_ENTER("spider_oracle_handler::append_key_select_with_alias"); + for (key_part = key_info->key_part, part_num = 0; + part_num < key_info->key_parts; key_part++, part_num++) + { + field = key_part->field; + field_length = oracle_share->column_name_str[field->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_minimum_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + DBUG_ENTER("spider_oracle_handler::append_minimum_select_with_alias"); + for (field = table->field; *field; field++) + { + if ( + spider_bit_is_set(spider->searched_bitmap, (*field)->field_index) | + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + ) { + field_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(alias_length + field_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + appended = TRUE; + } + } + if (appended) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + else { + if (str->reserve(SPIDER_SQL_ONE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_select_columns_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_oracle_handler::append_select_columns_with_alias"); + if ((error_num = append_match_select(str, alias, alias_length))) + DBUG_RETURN(error_num); + if (!spider->select_column_mode) + { + if (result_list->keyread) + DBUG_RETURN(append_key_select_with_alias( + str, result_list->key_info, alias, alias_length)); + else + DBUG_RETURN(append_table_select_with_alias( + str, alias, alias_length)); + } + DBUG_RETURN(append_minimum_select_with_alias(str, alias, alias_length)); +} + +int spider_oracle_handler::append_hint_after_table_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_hint_after_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_hint_after_table(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_hint_after_table( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_hint_after_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + oracle_share->key_hint && + (error_num = spider_db_append_hint_after_table(spider, + str, &oracle_share->key_hint[spider->active_index])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_RETURN(0); +} + +void spider_oracle_handler::set_where_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::set_where_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + where_pos = sql.length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + where_pos = update_sql.length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_read_pos = ha_sql.length(); + break; + default: + break; + } + DBUG_VOID_RETURN; +} + +void spider_oracle_handler::set_where_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::set_where_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + sql.length(where_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + update_sql.length(where_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_sql.length(ha_read_pos); + break; + default: + break; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::check_item_type( + Item *item +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::check_item_type"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_print_item_type(item, spider, NULL, NULL, 0, + spider_dbton_oracle.dbton_id); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_values_connector_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_values_connector_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_values_connector(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_values_connector( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_values_connector"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_COMMA_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_values_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_values_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_values_terminator(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_values_terminator( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_values_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - + SPIDER_SQL_COMMA_LEN - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_column_values_part( + const key_range *start_key, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_key_column_values_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_column_values(str, start_key); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_column_values( + spider_string *str, + const key_range *start_key +) { + int error_num; + const uchar *ptr; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; + KEY *key_info = result_list->key_info; + uint length; + uint store_length; + key_part_map full_key_part_map = make_prev_keypart_map(key_info->key_parts); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_oracle_handler::append_key_column_values"); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", key_info->key_parts)); + DBUG_PRINT("info", ("spider full_key_part_map=%lu", full_key_part_map)); + DBUG_PRINT("info", ("spider start_key_part_map=%lu", start_key_part_map)); + + if (!start_key_part_map) + DBUG_RETURN(0); + + for ( + key_part = key_info->key_part, + length = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + length += store_length + ) { + store_length = key_part->store_length; + ptr = start_key->key + length; + field = key_part->field; + if ((error_num = spider_db_append_null_value(str, key_part, &ptr))) + { + if (error_num > 0) + DBUG_RETURN(error_num); + } else { + if (spider_db_oracle_utility.append_column_value(spider, str, field, ptr, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + bool set_order; + DBUG_ENTER("spider_oracle_handler::append_key_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + set_order = FALSE; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + set_order = FALSE; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_read_pos = str->length(); + str_part = &sql_part; + str_part2 = &sql_part2; + str_part->length(0); + str_part2->length(0); + set_order = TRUE; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_where(str, str_part, str_part2, start_key, end_key, + sql_type, set_order); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_key_where"); + error_num = spider_db_append_key_where_internal(str, str_part, str_part2, + start_key, end_key, spider, set_order, sql_type, + spider_dbton_oracle.dbton_id); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + DBUG_ENTER("spider_oracle_handler::append_is_null_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str_part = &sql_part; + str_part2 = &sql_part2; + break; + default: + DBUG_RETURN(0); + } + error_num = append_is_null(sql_type, str, str_part, str_part2, + key_part, key, ptr, key_eq); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq +) { + DBUG_ENTER("spider_oracle_handler::append_is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + if (key_part->null_bit) + { + if (*(*ptr)++) + { + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + str = str_part; + if ( + key_eq || + key->flag == HA_READ_KEY_EXACT || + key->flag == HA_READ_KEY_OR_NEXT + ) { + if (str->reserve(SPIDER_SQL_IS_NULL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + ha_next_pos = str->length(); + if (str->reserve(SPIDER_SQL_FIRST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); + spider->result_list.ha_read_kind = 1; + } + str = str_part2; + } + if ( + key_eq || + key->flag == HA_READ_KEY_EXACT || + key->flag == HA_READ_KEY_OR_NEXT + ) { + if (str->reserve(SPIDER_SQL_IS_NULL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + oracle_share->column_name_str[key_part->field->field_index].length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, key_part->field->field_index); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + if (str->reserve(SPIDER_SQL_IS_NOT_NULL_LEN + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + oracle_share->column_name_str[key_part->field->field_index].length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, key_part->field->field_index); + str->q_append(SPIDER_SQL_IS_NOT_NULL_STR, SPIDER_SQL_IS_NOT_NULL_LEN); + } + DBUG_RETURN(-1); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + DBUG_ENTER("spider_oracle_handler::append_where_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str_part = &sql_part; + str_part2 = &sql_part2; + break; + default: + DBUG_RETURN(0); + } + error_num = append_where_terminator(sql_type, str, str_part, str_part2, + set_order, key_count); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_where_terminator( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + bool set_order, + int key_count +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_oracle_handler::append_where_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type != SPIDER_SQL_TYPE_HANDLER) + { + str->length(str->length() - SPIDER_SQL_AND_LEN); + if (!set_order) + result_list->key_order = key_count; + } else { + str_part2->length(str_part2->length() - SPIDER_SQL_AND_LEN); + + str_part->length(str_part->length() - SPIDER_SQL_COMMA_LEN); + if (!result_list->ha_read_kind) + str_part->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + if (str->append(*str_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + uint clause_length = str->length() - ha_next_pos; + if (clause_length < SPIDER_SQL_NEXT_LEN) + { + int roop_count; + clause_length = SPIDER_SQL_NEXT_LEN - clause_length; + if (str->reserve(clause_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + for (roop_count = 0; roop_count < (int) clause_length; roop_count++) + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_match_where_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_match_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_ASSERT(0); + DBUG_RETURN(0); + } + error_num = append_match_where(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_match_where( + spider_string *str +) { + int error_num; + bool first = TRUE; + st_spider_ft_info *ft_info = spider->ft_first; + DBUG_ENTER("spider_oracle_handler::append_match_where"); + if (spider->ft_current) + { + while (TRUE) + { + if (ft_info->used_in_where) + { + if (first) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + first = FALSE; + } + if ((error_num = append_match_against(str, ft_info, NULL, 0))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + + if (ft_info == spider->ft_current) + break; + ft_info = ft_info->next; + } + if (!first) + str->length(str->length() - SPIDER_SQL_AND_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_update_where( + spider_string *str, + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + uint field_name_length; + Field **field; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_oracle_handler::append_update_where"); + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + for (field = table->field; *field; field++) + { + if ( + table->s->primary_key == MAX_KEY || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { + field_name_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if ((*field)->is_null(ptr_diff)) + { + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_IS_NULL_LEN + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_IS_NULL_STR, SPIDER_SQL_IS_NULL_LEN); + } else { + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + (*field)->move_field_offset(ptr_diff); + if ( + spider_db_oracle_utility. + append_column_value(spider, str, *field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_AND_LEN) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + (*field)->move_field_offset(-ptr_diff); + } + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + } +/* + str->length(str->length() - SPIDER_SQL_AND_LEN); +*/ + if (str->reserve(SPIDER_SQL_LIMIT1_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LIMIT1_STR, SPIDER_SQL_LIMIT1_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg +) { + int error_num; + spider_string *str; + bool start_where = FALSE; + DBUG_ENTER("spider_oracle_handler::append_condition_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + DBUG_PRINT("info",("spider case1 sql_type=%lu", sql_type)); + if (test_flg) + { + str = NULL; + } else { + str = &sql; + start_where = ((int) str->length() == where_pos); + } + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + DBUG_PRINT("info",("spider case2 sql_type=%lu", sql_type)); + if (test_flg) + { + str = NULL; + } else { + str = &update_sql; + start_where = ((int) str->length() == where_pos); + } + break; + case SPIDER_SQL_TYPE_HANDLER: + DBUG_PRINT("info",("spider case3 sql_type=%lu", sql_type)); + if (test_flg) + { + str = NULL; + } else { + str = &ha_sql; + start_where = TRUE; + if (spider->active_index == MAX_KEY) + { + set_where_pos(SPIDER_SQL_TYPE_HANDLER); + if (str->reserve(SPIDER_SQL_READ_LEN + SPIDER_SQL_FIRST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_READ_STR, SPIDER_SQL_READ_LEN); + ha_next_pos = str->length(); + str->q_append(SPIDER_SQL_FIRST_STR, SPIDER_SQL_FIRST_LEN); + sql_part2.length(0); + } + ha_where_pos = str->length(); + + if (sql_part2.length()) + { + str->append(sql_part2); + start_where = FALSE; + } + } + break; + default: + DBUG_PRINT("info",("spider default sql_type=%lu", sql_type)); + DBUG_RETURN(0); + } + error_num = append_condition(str, alias, alias_length, start_where, + sql_type); + DBUG_PRINT("info",("spider str=%s", str ? str->c_ptr_safe() : "NULL")); + DBUG_PRINT("info",("spider length=%u", str ? str->length() : 0)); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_condition( + spider_string *str, + const char *alias, + uint alias_length, + bool start_where, + ulong sql_type +) { + int error_num, restart_pos = 0, start_where_pos; + SPIDER_CONDITION *tmp_cond = spider->condition; + DBUG_ENTER("spider_oracle_handler::append_condition"); + DBUG_PRINT("info",("spider str=%p", str)); + DBUG_PRINT("info",("spider alias=%p", alias)); + DBUG_PRINT("info",("spider alias_length=%u", alias_length)); + DBUG_PRINT("info",("spider start_where=%s", start_where ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); + if (str && start_where) + { + start_where_pos = str->length(); + } else { + start_where_pos = 0; + } + + if (spider->is_clone && !tmp_cond) + { + tmp_cond = spider->pt_clone_source_handler->condition; + } + + while (tmp_cond) + { + if (str) + { + restart_pos = str->length(); + if (start_where) + { + if (str->reserve(SPIDER_SQL_WHERE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + start_where = FALSE; + } else { + if (str->reserve(SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + } + } + if ((error_num = spider_db_print_item_type( + (Item *) tmp_cond->cond, spider, str, alias, alias_length, + spider_dbton_oracle.dbton_id))) + { + if (str && error_num == ER_SPIDER_COND_SKIP_NUM) + { + DBUG_PRINT("info",("spider COND skip")); + str->length(restart_pos); + start_where = (restart_pos == start_where_pos); + } else + DBUG_RETURN(error_num); + } + tmp_cond = tmp_cond->next; + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_match_against_part( + ulong sql_type, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_match_against_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_match_against(str, ft_info, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_match_against( + spider_string *str, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length +) { + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + String *ft_init_key; + KEY *key_info; + uint key_name_length; + int key_count; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_oracle_handler::append_match_against"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + + ft_init_key = ft_info->key; + key_info = &table->key_info[ft_info->inx]; + DBUG_PRINT("info", ("spider key_info->key_parts=%u", + key_info->key_parts)); + + for ( + key_part = key_info->key_part, + key_count = 0; + key_count < (int) key_info->key_parts; + key_part++, + key_count++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (alias_length) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + } else { + if (str->reserve(key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_AGAINST_LEN + SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AGAINST_STR, SPIDER_SQL_AGAINST_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, share->access_charset); + tmp_str.init_calc_mem(211); + tmp_str.length(0); + if ( + tmp_str.append(ft_init_key->ptr(), ft_init_key->length(), + ft_init_key->charset()) || + str->reserve(tmp_str.length() * 2) || + spider_db_oracle_utility.append_escaped_util(str, tmp_str.get_str()) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str->reserve( + SPIDER_SQL_VALUE_QUOTE_LEN + SPIDER_SQL_CLOSE_PAREN_LEN + + ((ft_info->flags & FT_BOOL) ? SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((ft_info->flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (ft_info->flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (ft_info->flags & FT_EXPAND) + str->q_append(SPIDER_SQL_WITH_QUERY_EXPANSION_STR, + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_match_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_match_select(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_match_select( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_match_select"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->ft_current) + { + st_spider_ft_info *ft_info = spider->ft_first; + while (TRUE) + { + if ((error_num = append_match_against(str, ft_info, + alias, alias_length))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if (ft_info == spider->ft_current) + break; + ft_info = ft_info->next; + } + } + DBUG_RETURN(0); +} + +void spider_oracle_handler::set_order_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::set_order_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + order_pos = sql.length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + order_pos = update_sql.length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_next_pos = ha_sql.length(); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +void spider_oracle_handler::set_order_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::set_order_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + sql.length(order_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + update_sql.length(order_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + ha_sql.length(ha_next_pos); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_key_order_for_merge_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_limit_pos = ha_sql.length(); + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_for_merge_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_order_for_merge_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + /* sort for index merge */ + TABLE *table = spider->get_table(); + int length; + Field *field; + uint key_name_length; + DBUG_ENTER("spider_oracle_handler::append_key_order_for_merge_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + spider->result_list.direct_order_limit || + spider->result_list.internal_limit < 9223372036854775807LL || + spider->result_list.split_read < 9223372036854775807LL || + spider->result_list.internal_offset + ) { + if (update_rownum_appended || select_rownum_appended) + { + if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + sql_part.length(0); + if (str == &update_sql) + { + if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(str->ptr(), where_pos); + sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); + } else { + if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + + SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); + sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, + SPIDER_SQL_ROW_NUMBER_HEAD_LEN); + } + if (table->s->primary_key < MAX_KEY) + { + /* sort by primary key */ + KEY *key_info = &table->key_info[table->s->primary_key]; + KEY_PART_INFO *key_part; + for ( + key_part = key_info->key_part, + length = 1; + length <= (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, field->field_index); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } else { + /* sort by all columns */ + Field **fieldp; + for ( + fieldp = table->field, length = 1; + *fieldp; + fieldp++, length++ + ) { + key_name_length = + oracle_share->column_name_str[(*fieldp)->field_index].length(); + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, (*fieldp)->field_index); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + uint pos_diff; + if (str == &update_sql) + { + uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - + table_name_pos; + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + + SPIDER_SQL_FROM_LEN + table_name_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + sql_part.q_append(str->ptr() + table_name_pos, table_name_size); + pos_diff = sql_part.length() - where_pos; + sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + update_rownum_appended = TRUE; + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; + sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, + str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + select_rownum_appended = TRUE; + table_name_pos = table_name_pos + pos_diff; + } + if (str->copy(sql_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = where_pos + pos_diff; + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + if (table->s->primary_key < MAX_KEY) + { + /* sort by primary key */ + KEY *key_info = &table->key_info[table->s->primary_key]; + KEY_PART_INFO *key_part; + for ( + key_part = key_info->key_part, + length = 1; + length <= (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (length > 1) + { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + } else { + /* sort by all columns */ + Field **fieldp; + for ( + fieldp = table->field, length = 1; + *fieldp; + fieldp++, length++ + ) { + key_name_length = + oracle_share->column_name_str[(*fieldp)->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, (*fieldp)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (length > 1) + { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_for_direct_order_limit_with_alias( + str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + ORDER *order; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + DBUG_ENTER("spider_oracle_handler::append_key_order_for_direct_order_limit_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_get_select_limit(spider, &select_lex, &select_limit, + &offset_limit); + if ( + spider->result_list.direct_order_limit || + spider->result_list.internal_limit < 9223372036854775807LL || + spider->result_list.split_read < 9223372036854775807LL || + spider->result_list.internal_offset + ) { + if (update_rownum_appended || select_rownum_appended) + { + if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + sql_part.length(0); + if (str == &update_sql) + { + if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(str->ptr(), where_pos); + sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); + } else { + if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + + SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); + sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, + SPIDER_SQL_ROW_NUMBER_HEAD_LEN); + } + bool all_desc = TRUE; + if (select_lex->order_list.first) + { + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if ((error_num = + spider_db_print_item_type((*order->item), spider, &sql_part, alias, + alias_length, spider_dbton_oracle.dbton_id))) + { + DBUG_PRINT("info",("spider error=%d", error_num)); + DBUG_RETURN(error_num); + } + if (order->asc) + { + if (sql_part.reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + all_desc = FALSE; + } else { + if (sql_part.reserve(SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } else { + all_desc = FALSE; + } + uint pos_diff; + if (str == &update_sql) + { + uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - + table_name_pos; + if (all_desc) + { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + + SPIDER_SQL_FROM_LEN + table_name_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + + SPIDER_SQL_FROM_LEN + table_name_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + } + sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + sql_part.q_append(str->ptr() + table_name_pos, table_name_size); + pos_diff = sql_part.length() - where_pos; + sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + update_rownum_appended = TRUE; + } else { + if (all_desc) + { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + } + pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; + sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, + str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + select_rownum_appended = TRUE; + table_name_pos = table_name_pos + pos_diff; + } + if (str->copy(sql_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = where_pos + pos_diff; + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + if (select_lex->order_list.first) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if ((error_num = + spider_db_print_item_type((*order->item), spider, str, alias, + alias_length, spider_dbton_oracle.dbton_id))) + { + DBUG_PRINT("info",("spider error=%d", error_num)); + DBUG_RETURN(error_num); + } + if (order->asc) + { + if (str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_key_order_with_alias_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + error_num = append_key_order_for_handler(str, alias, alias_length); + DBUG_RETURN(error_num); + default: + DBUG_RETURN(0); + } + error_num = append_key_order_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_key_order_for_handler( + spider_string *str, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_oracle_handler::append_key_order_for_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider ha_next_pos=%d", ha_next_pos)); + DBUG_PRINT("info",("spider ha_where_pos=%d", ha_where_pos)); + str->q_append(alias, alias_length); + memset((char *) str->ptr() + str->length(), ' ', + ha_where_pos - ha_next_pos - alias_length); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_key_order_with_alias( + spider_string *str, + const char *alias, + uint alias_length +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + KEY *key_info = result_list->key_info; + int length; + KEY_PART_INFO *key_part; + Field *field; + uint key_name_length; + DBUG_ENTER("spider_oracle_handler::append_key_order_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + spider->result_list.direct_order_limit || + spider->result_list.internal_limit < 9223372036854775807LL || + spider->result_list.split_read < 9223372036854775807LL || + spider->result_list.internal_offset + ) { + if (update_rownum_appended || select_rownum_appended) + { + if (str->reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + sql_part.length(0); + if (str == &update_sql) + { + if (sql_part.reserve(str->length() + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(str->ptr(), where_pos); + sql_part.q_append(SPIDER_SQL_UPDATE_WRAPPER_HEAD_STR, + SPIDER_SQL_UPDATE_WRAPPER_HEAD_LEN); + } else { + if (sql_part.reserve(str->length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + + SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); + sql_part.q_append(str->ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, + SPIDER_SQL_ROW_NUMBER_HEAD_LEN); + } + if (result_list->sorted == TRUE) + { + if (result_list->desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, field->field_index); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, field->field_index); + sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, field->field_index); + sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql_part.reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(alias, alias_length); + oracle_share->append_column_name(&sql_part, field->field_index); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } + } + uint pos_diff; + if (str == &update_sql) + { + uint table_name_size = (update_set_pos ? update_set_pos : where_pos) - + table_name_pos; + if (result_list->sorted == TRUE && result_list->desc_flg == TRUE) + { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + + SPIDER_SQL_FROM_LEN + table_name_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - where_pos + + SPIDER_SQL_FROM_LEN + table_name_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + } + sql_part.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + sql_part.q_append(str->ptr() + table_name_pos, + table_name_size); + pos_diff = sql_part.length() - where_pos; + sql_part.q_append(str->ptr() + where_pos, str->length() - where_pos); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + update_rownum_appended = TRUE; + } else { + if (result_list->sorted == TRUE && result_list->desc_flg == TRUE) + { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + str->length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + } + pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; + sql_part.q_append(str->ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, + str->length() - table_name_pos + SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + select_rownum_appended = TRUE; + table_name_pos = table_name_pos + pos_diff; + } + if (str->copy(sql_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = where_pos + pos_diff; + order_pos = str->length(); + limit_pos = str->length(); + DBUG_RETURN(0); + } + if (result_list->sorted == TRUE) + { + if (result_list->desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order < (int) key_info->key_parts && + length < result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ( + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + result_list->key_order, + length = 1; + length + result_list->key_order < (int) key_info->key_parts && + length < result_list->max_order; + key_part++, + length++ + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if ( + length + result_list->key_order <= (int) key_info->key_parts && + length <= result_list->max_order + ) { + field = key_part->field; + key_name_length = + oracle_share->column_name_str[field->field_index].length(); + if (length == 1) + { + if (str->reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + } + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_DESC_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + } else { + if (str->reserve(alias_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(alias, alias_length); + oracle_share->append_column_name(str, field->field_index); + } + } + } + } + limit_pos = str->length(); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + limit_pos = str->length(); + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + ha_limit_pos = str->length(); + break; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_PRINT("info",("spider str=%s", str->c_ptr_safe())); + DBUG_PRINT("info",("spider length=%u", str->length())); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::reappend_limit_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + str->length(limit_pos); + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + str->length(ha_limit_pos); + break; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_limit( + spider_string *str, + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_oracle_handler::append_limit"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info", ("spider offset=%lld", offset)); + DBUG_PRINT("info", ("spider limit=%lld", limit)); + if (offset || limit < 9223372036854775807LL) + { + if ((int) str->length() == where_pos) + { + if (offset) + { + int error_num; + if ((error_num = append_key_order_for_direct_order_limit_with_alias( + str, NULL, 0))) + DBUG_RETURN(error_num); + } else { + if (str->reserve(SPIDER_SQL_WHERE_LEN + SPIDER_SQL_ROWNUM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + str->q_append(SPIDER_SQL_ROWNUM_STR, SPIDER_SQL_ROWNUM_LEN); + } + } + if (offset) + { + if (str->reserve(SPIDER_SQL_BETWEEN_LEN + SPIDER_SQL_AND_LEN + + ((SPIDER_LONGLONG_LEN) * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_BETWEEN_STR, SPIDER_SQL_BETWEEN_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset + 1); + str->q_append(buf, length); + str->q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit + offset); + str->q_append(buf, length); + } else { + if (str->reserve(SPIDER_SQL_HS_LTEQUAL_LEN + + (SPIDER_LONGLONG_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HS_LTEQUAL_STR, SPIDER_SQL_HS_LTEQUAL_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + str->q_append(buf, length); + } + if (update_rownum_appended) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_select_lock_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_select_lock_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_select_lock(str); + DBUG_PRINT("info",("spider str=%s", str->c_ptr_safe())); + DBUG_PRINT("info",("spider length=%u", str->length())); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_select_lock( + spider_string *str +) { + int lock_mode = spider_conn_lock_mode(spider); + DBUG_ENTER("spider_oracle_handler::append_select_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + if (select_rownum_appended) + { + table_lock_mode = lock_mode; + } else { + if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (str->reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (str->reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_union_all_start_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_union_all_start_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all_start(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_union_all_start( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_union_all_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_union_all_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_union_all_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_union_all( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_union_all"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_UNION_ALL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_UNION_ALL_STR, SPIDER_SQL_UNION_ALL_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_union_all_end_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_union_all_end_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_union_all_end(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_union_all_end( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_union_all_end"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - + SPIDER_SQL_UNION_ALL_LEN + SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_multi_range_cnt(str, multi_range_cnt, with_comma); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_multi_range_cnt( + spider_string *str, + uint multi_range_cnt, + bool with_comma +) { + int range_cnt_length; + char range_cnt_str[SPIDER_SQL_INT_LEN]; + DBUG_ENTER("spider_oracle_handler::append_multi_range_cnt"); + DBUG_PRINT("info",("spider this=%p", this)); + range_cnt_length = my_sprintf(range_cnt_str, (range_cnt_str, "%u", + multi_range_cnt)); + if (with_comma) + { + if (str->reserve(range_cnt_length + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(range_cnt_str, range_cnt_length); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (str->reserve(range_cnt_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(range_cnt_str, range_cnt_length); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_open_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_open_handler(str, handler_id, conn, link_idx); + exec_ha_sql = str; + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_open_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + DBUG_PRINT("info",("spider m_handler_cid=%s", + spider->m_handler_cid[link_idx])); + if (str->reserve(SPIDER_SQL_HANDLER_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + if ((error_num = oracle_share->append_table_name(str, + spider->conn_link_idx[link_idx]))) + DBUG_RETURN(error_num); + if (str->reserve(SPIDER_SQL_OPEN_LEN + SPIDER_SQL_AS_LEN + + SPIDER_SQL_HANDLER_CID_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_STR, SPIDER_SQL_OPEN_LEN); + str->q_append(SPIDER_SQL_AS_STR, SPIDER_SQL_AS_LEN); + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_close_handler_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_close_handler_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_close_handler(str, link_idx); + exec_ha_sql = str; + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_close_handler( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_oracle_handler::append_close_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_HANDLER_LEN + SPIDER_SQL_CLOSE_LEN + + SPIDER_SQL_HANDLER_CID_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HANDLER_STR, SPIDER_SQL_HANDLER_LEN); + str->q_append(spider->m_handler_cid[link_idx], + SPIDER_SQL_HANDLER_CID_LEN); + str->q_append(SPIDER_SQL_CLOSE_STR, SPIDER_SQL_CLOSE_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_insert_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_insert_terminator_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_insert_terminator(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_insert_terminator( + spider_string *str +) { + DBUG_ENTER("spider_oracle_handler::append_insert_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->result_list.insert_dup_update_pushdown) + { + DBUG_PRINT("info",("spider add duplicate key update")); + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN + + dup_update_sql.length())) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_DUPLICATE_KEY_UPDATE_STR, + SPIDER_SQL_DUPLICATE_KEY_UPDATE_LEN); + if (str->append(dup_update_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } else { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_insert_values_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_insert_values_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_insert_values(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_insert_values( + spider_string *str +) { + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + Field **field; + bool add_value = FALSE; + DBUG_ENTER("spider_oracle_handler::append_insert_values"); + DBUG_PRINT("info",("spider this=%p", this)); + nextval_pos = 0; + if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + DBUG_PRINT("info",("spider field_index=%u", (*field)->field_index)); + if ( + bitmap_is_set(table->write_set, (*field)->field_index) || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { +#ifndef DBUG_OFF + my_bitmap_map *tmp_map = + dbug_tmp_use_all_columns(table, table->read_set); +#endif + add_value = TRUE; + DBUG_PRINT("info",("spider is_null()=%s", + (*field)->is_null() ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider table->next_number_field=%p", + table->next_number_field)); + DBUG_PRINT("info",("spider *field=%p", *field)); + DBUG_PRINT("info",("spider force_auto_increment=%s", + (table->next_number_field && spider->force_auto_increment) ? + "TRUE" : "FALSE")); + if ( + table->next_number_field == *field && + !table->auto_increment_field_not_null && + !spider->force_auto_increment + ) { + nextval_pos = str->length(); + if (str->reserve(oracle_share->nextval_max_length + + SPIDER_SQL_COMMA_LEN)) + { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->length(str->length() + oracle_share->nextval_max_length); + } else if ((*field)->is_null()) + { + if (str->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if ( + spider_db_oracle_utility. + append_column_value(spider, str, *field, NULL, + share->access_charset) || + str->reserve(SPIDER_SQL_COMMA_LEN) + ) { +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); +#ifndef DBUG_OFF + dbug_tmp_restore_column_map(table->read_set, tmp_map); +#endif + } + } + if (add_value) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + { + str->length(0); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_into_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_into_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + str = &insert_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_into(str); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_into( + spider_string *str +) { + const TABLE *table = spider->get_table(); + Field **field; + uint field_name_length = 0; + DBUG_ENTER("spider_oracle_handler::append_into"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_INTO_LEN + oracle_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + insert_table_name_pos = str->length(); + append_table_name_with_adjusting(str, first_link_idx, + SPIDER_SQL_TYPE_INSERT_SQL); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + for (field = table->field; *field; field++) + { + if ( + bitmap_is_set(table->write_set, (*field)->field_index) || + bitmap_is_set(table->read_set, (*field)->field_index) + ) { + field_name_length = + oracle_share->column_name_str[(*field)->field_index].length(); + if (str->reserve(field_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + oracle_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + if (field_name_length) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + if (str->reserve(SPIDER_SQL_VALUES_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + insert_pos = str->length(); + DBUG_RETURN(0); +} + +void spider_oracle_handler::set_insert_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::set_insert_to_pos"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + insert_sql.length(insert_pos); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::append_from_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_from_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + default: + str = &sql; + break; + } + error_num = append_from(str, sql_type, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_from( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_oracle_handler::append_from"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + if (sql_type == SPIDER_SQL_TYPE_HANDLER) + { + ha_table_name_pos = str->length(); + DBUG_PRINT("info",("spider ha_table_name_pos=%u", ha_table_name_pos)); + ha_sql_handler_id = spider->m_handler_id[link_idx]; + DBUG_PRINT("info",("spider ha_sql_handler_id=%u", ha_sql_handler_id)); + if (str->reserve(SPIDER_SQL_HANDLER_CID_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(spider->m_handler_cid[link_idx], SPIDER_SQL_HANDLER_CID_LEN); + DBUG_PRINT("info",("spider m_handler_cid=%s", + spider->m_handler_cid[link_idx])); + } else { + if (str->reserve(SPIDER_SQL_FROM_LEN + oracle_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, sql_type); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_flush_tables_part( + ulong sql_type, + int link_idx, + bool lock +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_flush_tables_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_flush_tables(str, link_idx, lock); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_flush_tables( + spider_string *str, + int link_idx, + bool lock +) { + DBUG_ENTER("spider_oracle_handler::append_flush_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if (lock) + { + if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN + + SPIDER_SQL_WITH_READ_LOCK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); + str->q_append(SPIDER_SQL_WITH_READ_LOCK_STR, + SPIDER_SQL_WITH_READ_LOCK_LEN); + } else { + if (str->reserve(SPIDER_SQL_FLUSH_TABLES_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FLUSH_TABLES_STR, SPIDER_SQL_FLUSH_TABLES_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_optimize_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_optimize_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_optimize_table(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_optimize_table( + spider_string *str, + int link_idx +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_oracle_handler::append_optimize_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_OPTIMIZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_OPTIMIZE_STR, SPIDER_SQL_SQL_OPTIMIZE_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_analyze_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_analyze_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_analyze_table(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_analyze_table( + spider_string *str, + int link_idx +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_oracle_handler::append_analyze_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ANALYZE_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ANALYZE_STR, SPIDER_SQL_SQL_ANALYZE_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_repair_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_repair_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_repair_table(str, link_idx, check_opt); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_repair_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt +) { + SPIDER_SHARE *share = spider->share; + int conn_link_idx = spider->conn_link_idx[link_idx]; + int local_length = spider_param_internal_optimize_local(spider->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_oracle_handler::append_repair_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_REPAIR_LEN + SPIDER_SQL_SQL_TABLE_LEN + + local_length + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_REPAIR_STR, SPIDER_SQL_SQL_REPAIR_LEN); + if (local_length) + str->q_append(SPIDER_SQL_SQL_LOCAL_STR, SPIDER_SQL_SQL_LOCAL_LEN); + str->q_append(SPIDER_SQL_SQL_TABLE_STR, SPIDER_SQL_SQL_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + if (check_opt->flags & T_QUICK) + { + if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (check_opt->flags & T_EXTEND) + { + if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); + } + if (check_opt->sql_flags & TT_USEFRM) + { + if (str->reserve(SPIDER_SQL_SQL_USE_FRM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_USE_FRM_STR, SPIDER_SQL_SQL_USE_FRM_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_check_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_check_table_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_check_table(str, link_idx, check_opt); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_check_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::append_check_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_CHECK_TABLE_LEN + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_CHECK_TABLE_STR, + SPIDER_SQL_SQL_CHECK_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + if (check_opt->flags & T_QUICK) + { + if (str->reserve(SPIDER_SQL_SQL_QUICK_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (check_opt->flags & T_FAST) + { + if (str->reserve(SPIDER_SQL_SQL_FAST_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_FAST_STR, SPIDER_SQL_SQL_FAST_LEN); + } + if (check_opt->flags & T_MEDIUM) + { + if (str->reserve(SPIDER_SQL_SQL_MEDIUM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_MEDIUM_STR, SPIDER_SQL_SQL_MEDIUM_LEN); + } + if (check_opt->flags & T_EXTEND) + { + if (str->reserve(SPIDER_SQL_SQL_EXTENDED_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, SPIDER_SQL_SQL_EXTENDED_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_enable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_enable_keys_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_enable_keys(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_enable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::append_enable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_ENABLE_KEYS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, + SPIDER_SQL_SQL_ALTER_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + str->q_append(SPIDER_SQL_SQL_ENABLE_KEYS_STR, + SPIDER_SQL_SQL_ENABLE_KEYS_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_disable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_disable_keys_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = append_disable_keys(str, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_disable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::append_disable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SQL_ALTER_TABLE_LEN + + oracle_share->db_names_str[conn_link_idx].length() + + SPIDER_SQL_DOT_LEN + + oracle_share->table_names_str[conn_link_idx].length() + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_SQL_DISABLE_KEYS_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SQL_ALTER_TABLE_STR, + SPIDER_SQL_SQL_ALTER_TABLE_LEN); + oracle_share->append_table_name(str, conn_link_idx); + str->q_append(SPIDER_SQL_SQL_DISABLE_KEYS_STR, + SPIDER_SQL_SQL_DISABLE_KEYS_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_delete_all_rows_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_delete_all_rows_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_DELETE_SQL: + str = &update_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_delete_all_rows(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_delete_all_rows( + spider_string *str, + ulong sql_type +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_delete_all_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->sql_command == SQLCOM_TRUNCATE) + { + if ((error_num = append_truncate(str, sql_type, first_link_idx))) + DBUG_RETURN(error_num); + } else { + if ( + (error_num = append_delete(str)) || + (error_num = append_from(str, sql_type, first_link_idx)) + ) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_truncate( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_oracle_handler::append_truncate"); + if (str->reserve(SPIDER_SQL_TRUNCATE_TABLE_LEN + + oracle_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + oracle_share->table_nm_max_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_TRUNCATE_TABLE_STR, SPIDER_SQL_TRUNCATE_TABLE_LEN); + table_name_pos = str->length(); + append_table_name_with_adjusting(str, link_idx, sql_type); + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_explain_select_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_OTHER_SQL: + str = &spider->result_list.sqls[link_idx]; + break; + default: + DBUG_RETURN(0); + } + error_num = + append_explain_select(str, start_key, end_key, sql_type, link_idx); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::append_explain_select( + spider_string *str, + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::append_explain_select"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_EXPLAIN_SELECT_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_EXPLAIN_SELECT_STR, SPIDER_SQL_EXPLAIN_SELECT_LEN); + if ( + (error_num = append_from(str, sql_type, link_idx)) || + (error_num = append_key_where(str, NULL, NULL, start_key, end_key, + sql_type, FALSE)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_RETURN(0); +} + +bool spider_oracle_handler::is_bulk_insert_exec_period( + bool bulk_end +) { + DBUG_ENTER("spider_oracle_handler::is_bulk_insert_exec_period"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider insert_sql.length=%u", insert_sql.length())); + DBUG_PRINT("info",("spider insert_pos=%d", insert_pos)); + DBUG_PRINT("info",("spider insert_sql=%s", insert_sql.c_ptr_safe())); + if ( +/* + (bulk_end || (int) insert_sql.length() >= spider->bulk_size) && +*/ + (int) insert_sql.length() > insert_pos + ) { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +bool spider_oracle_handler::sql_is_filled_up( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::sql_is_filled_up"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(filled_up); +} + +bool spider_oracle_handler::sql_is_empty( + ulong sql_type +) { + bool is_empty; + DBUG_ENTER("spider_oracle_handler::sql_is_empty"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + is_empty = (sql.length() == 0); + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + is_empty = (insert_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + is_empty = (update_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + is_empty = (tmp_sql.length() == 0); + break; + case SPIDER_SQL_TYPE_HANDLER: + is_empty = (ha_sql.length() == 0); + break; + default: + is_empty = TRUE; + break; + } + DBUG_RETURN(is_empty); +} + +bool spider_oracle_handler::support_multi_split_read() +{ + DBUG_ENTER("spider_oracle_handler::support_multi_split_read"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_oracle_handler::support_bulk_update() +{ + DBUG_ENTER("spider_oracle_handler::support_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_oracle_handler::bulk_tmp_table_insert() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = store_sql_to_bulk_tmp_table(&update_sql, upd_tmp_tbl); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::bulk_tmp_table_insert( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = store_sql_to_bulk_tmp_table( + &spider->result_list.update_sqls[link_idx], + spider->result_list.upd_tmp_tbls[link_idx]); + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::bulk_tmp_table_end_bulk_insert() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_end_bulk_insert"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = upd_tmp_tbl->file->ha_end_bulk_insert())) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::bulk_tmp_table_rnd_init() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_init"); + DBUG_PRINT("info",("spider this=%p", this)); + upd_tmp_tbl->file->extra(HA_EXTRA_CACHE); + if ((error_num = upd_tmp_tbl->file->ha_rnd_init(TRUE))) + { + DBUG_RETURN(error_num); + } + reading_from_bulk_tmp_table = TRUE; + DBUG_RETURN(0); +} + +int spider_oracle_handler::bulk_tmp_table_rnd_next() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); +#else + error_num = upd_tmp_tbl->file->rnd_next(upd_tmp_tbl->record[0]); +#endif + if (!error_num) + { + error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); + } + DBUG_RETURN(error_num); +} + +int spider_oracle_handler::bulk_tmp_table_rnd_end() +{ + int error_num; + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_rnd_end"); + DBUG_PRINT("info",("spider this=%p", this)); + reading_from_bulk_tmp_table = FALSE; + if ((error_num = upd_tmp_tbl->file->ha_rnd_end())) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +bool spider_oracle_handler::need_copy_for_update( + int link_idx +) { + int all_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::need_copy_for_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(!oracle_share->same_db_table_name || + spider->share->link_statuses[all_link_idx] == SPIDER_LINK_STATUS_RECOVERY); +} + +bool spider_oracle_handler::bulk_tmp_table_created() +{ + DBUG_ENTER("spider_oracle_handler::bulk_tmp_table_created"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(upd_tmp_tbl); +} + +int spider_oracle_handler::mk_bulk_tmp_table_and_bulk_start() +{ + THD *thd = spider->trx->thd; + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_oracle_handler::mk_bulk_tmp_table_and_bulk_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!upd_tmp_tbl) + { + if (!(upd_tmp_tbl = spider_mk_sys_tmp_table( + thd, table, &upd_tmp_tbl_prm, "a", update_sql.charset()))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + upd_tmp_tbl->file->extra(HA_EXTRA_WRITE_CACHE); + upd_tmp_tbl->file->ha_start_bulk_insert((ha_rows) 0); + } + DBUG_RETURN(0); +} + +void spider_oracle_handler::rm_bulk_tmp_table() +{ + DBUG_ENTER("spider_oracle_handler::rm_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (upd_tmp_tbl) + { + spider_rm_sys_tmp_table(spider->trx->thd, upd_tmp_tbl, &upd_tmp_tbl_prm); + upd_tmp_tbl = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_handler::store_sql_to_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::store_sql_to_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_table->field[0]->set_notnull(); + tmp_table->field[0]->store(str->ptr(), str->length(), str->charset()); + if ((error_num = tmp_table->file->ha_write_row(tmp_table->record[0]))) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_oracle_handler::restore_sql_from_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + DBUG_ENTER("spider_oracle_handler::restore_sql_from_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_table->field[0]->val_str(str->get_str()); + str->mem_calc(); + DBUG_RETURN(0); +} + +int spider_oracle_handler::insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash2 = &link_for_hash[link_idx]; + DBUG_ENTER("spider_oracle_handler::insert_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + uint old_elements = + db_conn->lock_table_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2)) +#else + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) +#endif + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->lock_table_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->lock_table_hash, + (db_conn->lock_table_hash.array.max_element - old_elements) * + db_conn->lock_table_hash.array.size_of_element); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended +) { + int error_num; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash, *tmp_link_for_hash2; + int conn_link_idx = spider->conn_link_idx[link_idx]; + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + DBUG_ENTER("spider_oracle_handler::append_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + tmp_link_for_hash2 = &link_for_hash[link_idx]; + tmp_link_for_hash2->db_table_str = + &oracle_share->db_table_str[conn_link_idx]; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + tmp_link_for_hash2->db_table_str_hash_value = + oracle_share->db_table_str_hash_value[conn_link_idx]; + if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) + my_hash_search_using_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2->db_table_str->ptr(), + tmp_link_for_hash2->db_table_str->length()))) +#else + if (!(tmp_link_for_hash = (SPIDER_LINK_FOR_HASH *) my_hash_search( + &db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2->db_table_str->ptr(), + tmp_link_for_hash2->db_table_str->length()))) +#endif + { + if ((error_num = insert_lock_tables_list(conn, link_idx))) + DBUG_RETURN(error_num); + *appended = 1; + } else { + if (tmp_link_for_hash->spider->lock_type < spider->lock_type) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash->db_table_str_hash_value, + (uchar*) tmp_link_for_hash); +#else + my_hash_delete(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash); +#endif + uint old_elements = + db_conn->lock_table_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value( + &db_conn->lock_table_hash, + tmp_link_for_hash2->db_table_str_hash_value, + (uchar*) tmp_link_for_hash2)) +#else + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) +#endif + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->lock_table_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->lock_table_hash, + (db_conn->lock_table_hash.array.max_element - old_elements) * + db_conn->lock_table_hash.array.size_of_element); + } + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::realloc_sql( + ulong *realloced +) { + THD *thd = spider->trx->thd; + st_spider_share *share = spider->share; + int init_sql_alloc_size = + spider_param_init_sql_alloc_size(thd, share->init_sql_alloc_size); + DBUG_ENTER("spider_oracle_handler::realloc_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((int) sql.alloced_length() > init_sql_alloc_size * 2) + { + sql.free(); + if (sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; + } + if ((int) ha_sql.alloced_length() > init_sql_alloc_size * 2) + { + ha_sql.free(); + if (ha_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_SELECT_SQL; + } + if ((int) dup_update_sql.alloced_length() > init_sql_alloc_size * 2) + { + dup_update_sql.free(); + if (dup_update_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if ((int) insert_sql.alloced_length() > init_sql_alloc_size * 2) + { + insert_sql.free(); + if (insert_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_INSERT_SQL; + } + if ((int) update_sql.alloced_length() > init_sql_alloc_size * 2) + { + update_sql.free(); + if (update_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL); + } + update_sql.length(0); + if ((int) tmp_sql.alloced_length() > init_sql_alloc_size * 2) + { + tmp_sql.free(); + if (tmp_sql.real_alloc(init_sql_alloc_size)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + *realloced |= SPIDER_SQL_TYPE_TMP_SQL; + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::reset_sql( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::reset_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + { + table_lock_mode = 0; + select_rownum_appended = FALSE; + sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) + { + insert_sql.length(0); + } + if (sql_type & (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL | + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + update_rownum_appended = FALSE; + update_set_pos = 0; + update_sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + { + tmp_sql.length(0); + } + if (sql_type & SPIDER_SQL_TYPE_HANDLER) + { + ha_sql.length(0); + } + DBUG_RETURN(0); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +int spider_oracle_handler::reset_keys( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::reset_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_oracle_handler::reset_upds( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::reset_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + hs_upds.clear(); + DBUG_RETURN(0); +} + +int spider_oracle_handler::reset_strs( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::reset_strs"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_oracle_handler::reset_strs_pos( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::reset_strs_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +int spider_oracle_handler::push_back_upds( + SPIDER_HS_STRING_REF &info +) { + int error_num; + DBUG_ENTER("spider_oracle_handler::push_back_upds"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = hs_upds.push_back(info); + DBUG_RETURN(error_num); +} +#endif + +bool spider_oracle_handler::need_lock_before_set_sql_for_exec( + ulong sql_type +) { + DBUG_ENTER("spider_oracle_handler::need_lock_before_set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_oracle_handler::set_sql_for_exec( + ulong sql_type, + int link_idx +) { + int error_num; + uint tmp_pos; + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + int all_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & (SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL)) + { + if (table_lock_mode) + { + spider_string *str = &result_list->insert_sqls[link_idx]; + str->length(0); + if (str->reserve(SPIDER_SQL_LOCK_TABLE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); + if ((error_num = oracle_share->append_table_name(str, all_link_idx))) + DBUG_RETURN(error_num); + if (table_lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (str->reserve(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR, + SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN); + } else if (table_lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (str->reserve(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR, + SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN); + } + exec_lock_sql = str; + } + + if (oracle_share->same_db_table_name || link_idx == first_link_idx) + { + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + exec_sql = &sql; + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + exec_tmp_sql = &tmp_sql; + } else { + char tmp_table_name[MAX_FIELD_WIDTH * 2], + tgt_table_name[MAX_FIELD_WIDTH * 2]; + int tmp_table_name_length; + spider_string tgt_table_name_str(tgt_table_name, + MAX_FIELD_WIDTH * 2, + oracle_share->db_names_str[link_idx].charset()); + const char *table_names[2], *table_aliases[2]; + uint table_name_lengths[2], table_alias_lengths[2]; + tgt_table_name_str.init_calc_mem(212); + tgt_table_name_str.length(0); + if (result_list->tmp_table_join) + { + create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length, + link_idx); + append_table_name_with_adjusting(&tgt_table_name_str, link_idx, + SPIDER_SQL_TYPE_TMP_SQL); + table_names[0] = tmp_table_name; + table_names[1] = tgt_table_name_str.c_ptr(); + table_name_lengths[0] = tmp_table_name_length; + table_name_lengths[1] = tgt_table_name_str.length(); + table_aliases[0] = SPIDER_SQL_A_STR; + table_aliases[1] = SPIDER_SQL_B_STR; + table_alias_lengths[0] = SPIDER_SQL_A_LEN; + table_alias_lengths[1] = SPIDER_SQL_B_LEN; + } + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + { + exec_sql = &result_list->sqls[link_idx]; + if (exec_sql->copy(sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_sql->length(); + exec_sql->length(table_name_pos); + if (result_list->tmp_table_join) + { + if ((error_num = spider_db_oracle_utility.append_from_with_alias( + exec_sql, table_names, table_name_lengths, + table_aliases, table_alias_lengths, 2, + &table_name_pos, TRUE)) + ) + DBUG_RETURN(error_num); + } else { + append_table_name_with_adjusting(exec_sql, link_idx, + SPIDER_SQL_TYPE_SELECT_SQL); + } + exec_sql->length(tmp_pos); + } + } + if (sql_type & SPIDER_SQL_TYPE_TMP_SQL) + { + exec_tmp_sql = &result_list->tmp_sqls[link_idx]; + if (result_list->tmp_table_join) + { + if (exec_tmp_sql->copy(tmp_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_tmp_sql->length(); + exec_tmp_sql->length(tmp_sql_pos1); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_sql_pos2); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_sql_pos3); + exec_tmp_sql->q_append(tmp_table_name, tmp_table_name_length); + exec_tmp_sql->length(tmp_pos); + } + } + } + } + } + if (sql_type & SPIDER_SQL_TYPE_INSERT_SQL) + { + if (oracle_share->same_db_table_name || link_idx == first_link_idx) + exec_insert_sql = &insert_sql; + else { + exec_insert_sql = &result_list->insert_sqls[link_idx]; + if (exec_insert_sql->copy(insert_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_PRINT("info",("spider exec_insert_sql=%s", + exec_insert_sql->c_ptr_safe())); + tmp_pos = exec_insert_sql->length(); + exec_insert_sql->length(insert_table_name_pos); + append_table_name_with_adjusting(exec_insert_sql, link_idx, + sql_type); + exec_insert_sql->length(tmp_pos); + DBUG_PRINT("info",("spider exec_insert_sql->length=%u", + exec_insert_sql->length())); + DBUG_PRINT("info",("spider exec_insert_sql=%s", + exec_insert_sql->c_ptr_safe())); + } + if (nextval_pos) + { + memcpy((uchar *) exec_insert_sql->ptr() + nextval_pos, + oracle_share->nextval_str[all_link_idx].ptr(), + oracle_share->nextval_max_length); + } + } + if (sql_type & SPIDER_SQL_TYPE_BULK_UPDATE_SQL) + { + if (reading_from_bulk_tmp_table) + { + if ( + oracle_share->same_db_table_name && + share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY + ) { + exec_update_sql = &insert_sql; + } else if (!spider->result_list.upd_tmp_tbls[link_idx]) + { + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } else { + exec_update_sql = &spider->result_list.insert_sqls[link_idx]; + if ((error_num = restore_sql_from_bulk_tmp_table(exec_update_sql, + spider->result_list.upd_tmp_tbls[link_idx]))) + { + DBUG_RETURN(error_num); + } + } + } else { + if ( + oracle_share->same_db_table_name && + share->link_statuses[all_link_idx] != SPIDER_LINK_STATUS_RECOVERY + ) { + exec_update_sql = &update_sql; + } else { + exec_update_sql = &spider->result_list.update_sqls[link_idx]; + } + } + DBUG_PRINT("info",("spider exec_update_sql=%s", + exec_update_sql->c_ptr_safe())); + } else if (sql_type & + (SPIDER_SQL_TYPE_UPDATE_SQL | SPIDER_SQL_TYPE_DELETE_SQL)) + { + if (oracle_share->same_db_table_name || link_idx == first_link_idx) + exec_update_sql = &update_sql; + else { + exec_update_sql = &spider->result_list.update_sqls[link_idx]; + if (exec_update_sql->copy(update_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_pos = exec_update_sql->length(); + exec_update_sql->length(table_name_pos); + append_table_name_with_adjusting(exec_update_sql, link_idx, + sql_type); + exec_update_sql->length(tmp_pos); + } + DBUG_PRINT("info",("spider exec_update_sql=%s", + exec_update_sql->c_ptr_safe())); + } + if (sql_type & SPIDER_SQL_TYPE_HANDLER) + { + if (spider->m_handler_id[link_idx] == ha_sql_handler_id) + exec_ha_sql = &ha_sql; + else { + exec_ha_sql = &result_list->sqls[link_idx]; + if (exec_ha_sql->copy(ha_sql)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + else { + tmp_pos = exec_ha_sql->length(); + exec_ha_sql->length(ha_table_name_pos); + append_table_name_with_adjusting(exec_ha_sql, link_idx, + SPIDER_SQL_TYPE_HANDLER); + exec_ha_sql->length(tmp_pos); + } + } + DBUG_PRINT("info",("spider exec_ha_sql=%s", + exec_ha_sql->c_ptr_safe())); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type +) { + spider_oracle_copy_table *oracle_ct = (spider_oracle_copy_table *) tgt_ct; + DBUG_ENTER("spider_oracle_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_INSERT_SQL: + exec_insert_sql = &oracle_ct->sql; + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + spider_string *tgt_sql; + uint tgt_length; + DBUG_ENTER("spider_oracle_handler::execute_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_SELECT_SQL")); + tgt_sql = exec_sql; + tgt_length = tgt_sql->length(); + if (table_lock_mode) + { + DBUG_PRINT("info",("spider table_lock_mode=%d", table_lock_mode)); + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + db_conn->table_lock_mode = table_lock_mode; + db_conn->exec_lock_sql = exec_lock_sql; + table_lock_mode = 0; + } + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_SELECT_SQL")); + tgt_sql = exec_insert_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + DBUG_PRINT("info",("spider %s", + sql_type == SPIDER_SQL_TYPE_UPDATE_SQL ? "SPIDER_SQL_TYPE_UPDATE_SQL" : + sql_type == SPIDER_SQL_TYPE_DELETE_SQL ? "SPIDER_SQL_TYPE_DELETE_SQL" : + "SPIDER_SQL_TYPE_BULK_UPDATE_SQL" + )); + tgt_sql = exec_update_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_TMP_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_TMP_SQL")); + tgt_sql = exec_tmp_sql; + tgt_length = tgt_sql->length(); + break; + case SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL")); + tgt_sql = exec_tmp_sql; + tgt_length = tmp_sql_pos5; + break; + case SPIDER_SQL_TYPE_HANDLER: + DBUG_PRINT("info",("spider SPIDER_SQL_TYPE_HANDLER")); + tgt_sql = exec_ha_sql; + tgt_length = tgt_sql->length(); + break; + default: + /* nothing to do */ + DBUG_PRINT("info",("spider default")); + DBUG_RETURN(0); + } + DBUG_RETURN(spider_db_query( + conn, + tgt_sql->ptr(), + tgt_length, + quick_mode, + need_mon + )); +} + +int spider_oracle_handler::reset() +{ + DBUG_ENTER("spider_oracle_handler::reset"); + DBUG_PRINT("info",("spider this=%p", this)); + update_sql.length(0); + DBUG_RETURN(0); +} + +int spider_oracle_handler::sts_mode_exchange( + int sts_mode +) { + DBUG_ENTER("spider_oracle_handler::sts_mode_exchange"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + DBUG_RETURN(1); +} + +int spider_oracle_handler::show_table_status( + int link_idx, + int sts_mode, + uint flag +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = spider->share; + uint pos = (2 * spider->conn_link_idx[link_idx]); + DBUG_ENTER("spider_oracle_handler::show_table_status"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + if ( + (flag & HA_STATUS_AUTO) && + (error_num = show_autoinc(link_idx)) + ) { + DBUG_RETURN(error_num); + } + + if (sts_mode == 1) + { +/* + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_table_status[0 + pos].ptr(), + oracle_share->show_table_status[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { +*/ + /* retry */ +/* + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_table_status[0 + pos].ptr(), + oracle_share->show_table_status[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + else { + my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + oracle_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), + oracle_share->table_names_str[spider->conn_link_idx[ + link_idx]].ptr()); + DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_status( + sts_mode, + share->records, + share->mean_rec_length, + share->data_file_length, + share->max_data_file_length, + share->index_file_length, + share->auto_increment_value, + share->create_time, + share->update_time, + share->check_time + ); + res->free_result(); + delete res; + if (error_num) + DBUG_RETURN(error_num); +*/ + if (!share->records) + share->records = 10000; + share->mean_rec_length = 65535; + share->data_file_length = 65535; + share->max_data_file_length = 65535; + share->index_file_length = 65535; +/* + share->auto_increment_value = 0; +*/ + share->create_time = (time_t) 0; + share->update_time = (time_t) 0; + share->check_time = (time_t) 0; + } else { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_table_status[1 + pos].ptr(), + oracle_share->show_table_status[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_table_status[1 + pos].ptr(), + oracle_share->show_table_status[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + else + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_status( + sts_mode, + share->records, + share->mean_rec_length, + share->data_file_length, + share->max_data_file_length, + share->index_file_length, + share->auto_increment_value, + share->create_time, + share->update_time, + share->check_time + ); + res->free_result(); + delete res; + if (error_num) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::crd_mode_exchange( + int crd_mode +) { + DBUG_ENTER("spider_oracle_handler::crd_mode_exchange"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + DBUG_RETURN(1); +} + +int spider_oracle_handler::show_index( + int link_idx, + int crd_mode +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_SHARE *share = spider->share; + TABLE *table = spider->get_table(); + SPIDER_DB_RESULT *res; + int roop_count; + longlong *tmp_cardinality; + uint pos = (2 * spider->conn_link_idx[link_idx]); + DBUG_ENTER("spider_oracle_handler::show_index"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + if (crd_mode == 1) + { +/* + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_index[0 + pos].ptr(), + oracle_share->show_index[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { +*/ + /* retry */ +/* + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_index[0 + pos].ptr(), + oracle_share->show_index[0 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } +*/ + /* no record is ok */ +/* + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (res) + { + error_num = res->fetch_table_cardinality( + crd_mode, + table, + share->cardinality, + share->cardinality_upd, + share->bitmap_size + ); + } +*/ + for (roop_count = 0, tmp_cardinality = share->cardinality; + roop_count < (int) table->s->fields; + roop_count++, tmp_cardinality++) + { + if (!spider_bit_is_set(share->cardinality_upd, roop_count)) + { + DBUG_PRINT("info", + ("spider init column cardinality id=%d", roop_count)); + *tmp_cardinality = 1; + } + } +/* + if (res) + { + res->free_result(); + delete res; + } + if (error_num) + DBUG_RETURN(error_num); +*/ + } else { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_index[1 + pos].ptr(), + oracle_share->show_index[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_index[1 + pos].ptr(), + oracle_share->show_index[1 + pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + /* no record is ok */ + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + if (res) + { + error_num = res->fetch_table_cardinality( + crd_mode, + table, + share->cardinality, + share->cardinality_upd, + share->bitmap_size + ); + } + for (roop_count = 0, tmp_cardinality = share->cardinality; + roop_count < (int) table->s->fields; + roop_count++, tmp_cardinality++) + { + if (!spider_bit_is_set(share->cardinality_upd, roop_count)) + { + DBUG_PRINT("info", + ("spider init column cardinality id=%d", roop_count)); + *tmp_cardinality = 1; + } + } + if (res) + { + res->free_result(); + delete res; + } + if (error_num) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::show_records( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = spider->share; + uint pos = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_oracle_handler::show_records"); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_records[pos].ptr(), + oracle_share->show_records[pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 1", error_num)); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 2", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_records[pos].ptr(), + oracle_share->show_records[pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 4", error_num)); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 6", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_records( + 1, + share->records + ); + res->free_result(); + delete res; + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); + DBUG_RETURN(error_num); + } + spider->trx->direct_aggregate_count++; + DBUG_RETURN(0); +} + +int spider_oracle_handler::show_autoinc( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + SPIDER_SHARE *share = spider->share; + uint pos = spider->conn_link_idx[link_idx]; + ulonglong auto_increment_value; + DBUG_ENTER("spider_oracle_handler::show_autoinc"); + if (!oracle_share->show_autoinc) + DBUG_RETURN(0); + + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + oracle_share->show_autoinc[pos].ptr(), + oracle_share->show_autoinc[pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 1", error_num)); + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 2", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + oracle_share->show_records[pos].ptr(), + oracle_share->show_records[pos].length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 4", error_num)); + DBUG_RETURN(error_num); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 6", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_records( + 1, + auto_increment_value + ); + res->free_result(); + delete res; + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); + DBUG_RETURN(error_num); + } + if (auto_increment_value >= share->auto_increment_value) + { + share->auto_increment_value = auto_increment_value + 1; + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::show_last_insert_id( + int link_idx, + ulonglong &last_insert_id +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_DB_RESULT *res; + uint pos = spider->conn_link_idx[link_idx]; + spider_db_oracle *db_oracle = (spider_db_oracle *) conn->db_conn; + DBUG_ENTER("spider_oracle_handler::show_last_insert_id"); + if (!oracle_share->show_last_insert_id) + { + DBUG_ASSERT(0); + last_insert_id = 0; + db_oracle->stored_last_insert_id = 0; + DBUG_RETURN(0); + } + + if ( + spider_db_query( + conn, + oracle_share->show_last_insert_id[pos].ptr(), + oracle_share->show_last_insert_id[pos].length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) { + DBUG_PRINT("info", ("spider error_num=%d 4", error_num)); + DBUG_RETURN(error_num); + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 6", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + error_num = res->fetch_table_records( + 1, + last_insert_id + ); + res->free_result(); + delete res; + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); + DBUG_RETURN(error_num); + } + db_oracle->stored_last_insert_id = last_insert_id; + DBUG_RETURN(0); +} + +ha_rows spider_oracle_handler::explain_select( + key_range *start_key, + key_range *end_key, + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + spider_string *str = &result_list->sqls[link_idx]; + SPIDER_DB_RESULT *res; + ha_rows rows; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + DBUG_ENTER("spider_oracle_handler::explain_select"); + if ((error_num = dbton_hdl->append_explain_select_part( + start_key, end_key, SPIDER_SQL_TYPE_OTHER_SQL, link_idx))) + { + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_queue_connect_rewrite(spider->share, conn, link_idx); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if ( + (error_num = spider_db_set_names(spider, conn, link_idx)) || + ( + spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) && + (error_num = spider_db_errorno(conn)) + ) + ) { + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !conn->disable_reconnect + ) { + /* retry */ + if ((error_num = spider_db_ping(spider, conn, link_idx))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } else { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } + st_spider_db_request_key request_key; + request_key.spider_thread_id = spider->trx->spider_thread_id; + request_key.query_id = spider->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + if (error_num || (error_num = spider_db_errorno(conn))) + { + if (spider->check_error_mode(error_num)) + my_errno = error_num; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } else { + my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(HA_POS_ERROR); + } + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + error_num = res->fetch_table_records( + 2, + rows + ); + res->free_result(); + delete res; + if (error_num) + { + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + DBUG_RETURN(rows); +} + +int spider_oracle_handler::lock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + spider_string *str = &sql; + DBUG_ENTER("spider_oracle_handler::lock_tables"); + do { + str->length(0); + if ((error_num = conn->db_conn->append_lock_tables(str))) + { + DBUG_RETURN(error_num); + } + if (str->length()) + { + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + if (!conn->table_locked) + { + conn->table_locked = TRUE; + spider->trx->locked_connections++; + } + } while (str->length()); + DBUG_RETURN(0); +} + +int spider_oracle_handler::unlock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_oracle_handler::unlock_tables"); + if (conn->table_locked) + { + if ((error_num = conn->db_conn->commit(&spider->need_mons[link_idx]))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::disable_keys( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::disable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_disable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::enable_keys( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::enable_keys"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_enable_keys_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::check_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_check_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, check_opt))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::repair_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_repair_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, check_opt))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::analyze_table( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::analyze_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_analyze_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::optimize_table( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::optimize_table"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_optimize_table_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx))) + { + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock +) { + int error_num; + SPIDER_SHARE *share = spider->share; + spider_string *str = &spider->result_list.sqls[link_idx]; + DBUG_ENTER("spider_oracle_handler::flush_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(0); + if ((error_num = append_flush_tables_part(SPIDER_SQL_TYPE_OTHER_HS, + link_idx, lock))) + { + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::flush_logs( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_oracle_handler::flush_logs"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, + share); + if (spider_db_query( + conn, + SPIDER_SQL_FLUSH_LOGS_STR, + SPIDER_SQL_FLUSH_LOGS_LEN, + -1, + &spider->need_mons[link_idx]) + ) { + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_oracle_handler::insert_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash = &link_for_hash[link_idx]; + DBUG_ASSERT(tmp_link_for_hash->spider == spider); + DBUG_ASSERT(tmp_link_for_hash->link_idx == link_idx); + uint old_elements = db_conn->handler_open_array.max_element; + DBUG_ENTER("spider_oracle_handler::insert_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + if (insert_dynamic(&db_conn->handler_open_array, + (uchar*) &tmp_link_for_hash)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (db_conn->handler_open_array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + db_conn->handler_open_array, + (db_conn->handler_open_array.max_element - old_elements) * + db_conn->handler_open_array.size_of_element); + } + DBUG_RETURN(0); +} + +int spider_oracle_handler::delete_opened_handler( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + uint roop_count, elements = db_conn->handler_open_array.elements; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash; + DBUG_ENTER("spider_oracle_handler::delete_opened_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + for (roop_count = 0; roop_count < elements; roop_count++) + { + get_dynamic(&db_conn->handler_open_array, (uchar *) &tmp_link_for_hash, + roop_count); + if (tmp_link_for_hash == &link_for_hash[link_idx]) + { + delete_dynamic_element(&db_conn->handler_open_array, roop_count); + break; + } + } + DBUG_ASSERT(roop_count < elements); + DBUG_RETURN(0); +} + +int spider_oracle_handler::sync_from_clone_source( + spider_db_handler *dbton_hdl +) { + DBUG_ENTER("spider_oracle_handler::sync_from_clone_source"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_oracle_handler::support_use_handler( + int use_handler +) { + DBUG_ENTER("spider_oracle_handler::support_use_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +spider_oracle_copy_table::spider_oracle_copy_table( + spider_oracle_share *db_share +) : spider_db_copy_table( + db_share +), + oracle_share(db_share), + pos(0), + table_name_pos(0), + pos_diff(0), + table_lock_mode(0), + select_rownum_appended(FALSE), + first_str(NULL), + current_str(NULL) +{ + DBUG_ENTER("spider_oracle_copy_table::spider_oracle_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_oracle_copy_table::~spider_oracle_copy_table() +{ + DBUG_ENTER("spider_oracle_copy_table::~spider_oracle_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + while (first_str) + { + current_str = first_str; + first_str = first_str->next; + delete [] current_str; + } + DBUG_VOID_RETURN; +} + +int spider_oracle_copy_table::init() +{ + DBUG_ENTER("spider_oracle_copy_table::init"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.init_calc_mem(213); + sql_part.init_calc_mem(215); + DBUG_RETURN(0); +} + +void spider_oracle_copy_table::set_sql_charset( + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_oracle_copy_table::set_sql_charset"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.set_charset(cs); + DBUG_VOID_RETURN; +} + +int spider_oracle_copy_table::append_select_str() +{ + DBUG_ENTER("spider_oracle_copy_table::append_select_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_SELECT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_insert_str( + int insert_flg +) { + DBUG_ENTER("spider_oracle_copy_table::append_insert_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_INSERT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_INSERT_STR, SPIDER_SQL_INSERT_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_table_columns( + TABLE_SHARE *table_share +) { + int error_num; + Field **field; + DBUG_ENTER("spider_oracle_copy_table::append_table_columns"); + DBUG_PRINT("info",("spider this=%p", this)); + for (field = table_share->field; *field; field++) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) (*field)->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_from_str() +{ + DBUG_ENTER("spider_oracle_copy_table::append_from_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_table_name( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_oracle_copy_table::append_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + table_name_pos = sql.length(); + error_num = oracle_share->append_table_name(&sql, link_idx); + store_link_idx = link_idx; + DBUG_RETURN(error_num); +} + +void spider_oracle_copy_table::set_sql_pos() +{ + DBUG_ENTER("spider_oracle_copy_table::set_sql_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + pos = sql.length(); + DBUG_VOID_RETURN; +} + +void spider_oracle_copy_table::set_sql_to_pos() +{ + DBUG_ENTER("spider_oracle_copy_table::set_sql_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.length(pos); + DBUG_VOID_RETURN; +} + +int spider_oracle_copy_table::append_copy_where( + spider_db_copy_table *source_ct, + KEY *key_info, + ulong *last_row_pos, + ulong *last_lengths +) { + int error_num, roop_count, roop_count2; + DBUG_ENTER("spider_oracle_copy_table::append_copy_where"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_WHERE_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + Field *field; + KEY_PART_INFO *key_part = key_info->key_part; + for (roop_count = key_info->key_parts - 1; roop_count >= 0; roop_count--) + { + for (roop_count2 = 0; roop_count2 < roop_count; roop_count2++) + { + field = key_part[roop_count2].field; + if ((error_num = copy_key_row(source_ct, + field, &last_row_pos[field->field_index], + &last_lengths[field->field_index], + SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN))) + { + DBUG_RETURN(error_num); + } + } + field = key_part[roop_count2].field; + if ((error_num = copy_key_row(source_ct, + field, &last_row_pos[field->field_index], + &last_lengths[field->field_index], + SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN))) + { + DBUG_RETURN(error_num); + } + sql.length(sql.length() - SPIDER_SQL_AND_LEN); + if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + + SPIDER_SQL_OR_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + sql.q_append(SPIDER_SQL_OR_STR, SPIDER_SQL_OR_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + sql.length(sql.length() - SPIDER_SQL_OR_LEN - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_key_order_str( + KEY *key_info, + int start_pos, + bool desc_flg +) { + int length, error_num; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_oracle_copy_table::append_key_order_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (select_rownum_appended) + { + if (sql.reserve(SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + DBUG_RETURN(0); + } + sql_part.length(0); + if (sql_part.reserve(sql.length() + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN + + SPIDER_SQL_ROW_NUMBER_HEAD_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_HEAD_STR, + SPIDER_SQL_SELECT_WRAPPER_HEAD_LEN); + sql_part.q_append(sql.ptr(), table_name_pos - SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_HEAD_STR, + SPIDER_SQL_ROW_NUMBER_HEAD_LEN); + if ((int) key_info->key_parts > start_pos) + { + if (desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql_part, + (char *) field->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql_part, + (char *) field->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + + SPIDER_SQL_DESC_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql_part.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_NAME_QUOTE_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql_part.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } + } + if (desc_flg == TRUE) + { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + sql.length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_DESC_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_DESC_TAIL_LEN); + } else { + if (sql_part.reserve(SPIDER_SQL_ROW_NUMBER_TAIL_LEN + + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN + sql.length() - table_name_pos + + SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_ROW_NUMBER_TAIL_STR, + SPIDER_SQL_ROW_NUMBER_TAIL_LEN); + } + pos_diff = sql_part.length() + SPIDER_SQL_FROM_LEN - table_name_pos; + sql_part.q_append(sql.ptr() + table_name_pos - SPIDER_SQL_FROM_LEN, + sql.length() - table_name_pos + SPIDER_SQL_FROM_LEN); + sql_part.q_append(SPIDER_SQL_SELECT_WRAPPER_TAIL_STR, + SPIDER_SQL_SELECT_WRAPPER_TAIL_LEN); + + if ((int) key_info->key_parts > start_pos) + { + if (sql.reserve(SPIDER_SQL_ORDER_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + if (desc_flg == TRUE) + { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } else { + for ( + key_part = key_info->key_part + start_pos, + length = 0; + length + start_pos < (int) key_info->key_parts; + key_part++, + length++ + ) { + field = key_part->field; + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (key_part->key_part_flag & HA_REVERSE_SORT) + { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_DESC_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_DESC_STR, SPIDER_SQL_DESC_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } else { + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, + SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + } + } + sql.length(sql.length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_limit( + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_oracle_copy_table::append_limit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (offset || limit < 9223372036854775807LL) + { + if (!select_rownum_appended) + { + select_rownum_appended = TRUE; + table_name_pos = table_name_pos + pos_diff; + if (sql.copy(sql_part)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + pos = pos + pos_diff; + } + if (offset) + { + if (sql.reserve(SPIDER_SQL_BETWEEN_LEN + SPIDER_SQL_AND_LEN + + ((SPIDER_LONGLONG_LEN) * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_BETWEEN_STR, SPIDER_SQL_BETWEEN_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, offset); + sql.q_append(buf, length); + sql.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + sql.q_append(buf, length); + } else { + if (sql.reserve(SPIDER_SQL_HS_LTEQUAL_LEN + + (SPIDER_LONGLONG_LEN))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_HS_LTEQUAL_STR, SPIDER_SQL_HS_LTEQUAL_LEN); + length = (uint32) (my_charset_bin.cset->longlong10_to_str)( + &my_charset_bin, buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + sql.q_append(buf, length); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_into_str() +{ + DBUG_ENTER("spider_oracle_copy_table::append_into_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_INTO_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_INTO_STR, SPIDER_SQL_INTO_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_open_paren_str() +{ + DBUG_ENTER("spider_oracle_copy_table::append_open_paren_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_values_str() +{ + DBUG_ENTER("spider_oracle_copy_table::append_values_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_VALUES_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_VALUES_STR, SPIDER_SQL_VALUES_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_select_lock_str( + int lock_mode +) { + DBUG_ENTER("spider_oracle_copy_table::append_select_lock_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (select_rownum_appended) + { + int error_num; + table_lock_mode = lock_mode; + sql_part.length(0); + if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_LOCK_TABLE_STR, SPIDER_SQL_LOCK_TABLE_LEN); + if ((error_num = oracle_share->append_table_name(&sql_part, + store_link_idx))) + DBUG_RETURN(error_num); + if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_STR, + SPIDER_SQL_LOCK_TABLE_EXCLUSIVE_MODE_LEN); + } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (sql_part.reserve(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_part.q_append(SPIDER_SQL_LOCK_TABLE_SHARE_MODE_STR, + SPIDER_SQL_LOCK_TABLE_SHARE_MODE_LEN); + } + } else { + if (lock_mode == SPIDER_LOCK_MODE_EXCLUSIVE) + { + if (sql.reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } else if (lock_mode == SPIDER_LOCK_MODE_SHARED) + { + if (sql.reserve(SPIDER_SQL_FOR_UPDATE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FOR_UPDATE_STR, SPIDER_SQL_FOR_UPDATE_LEN); + } + } + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + int error_num = 0; + DBUG_ENTER("spider_oracle_copy_table::exec_query"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_str) + { + spider_string *tmp_str = first_str; + while (tmp_str && tmp_str != current_str) + { + if ( + (error_num = spider_db_query(conn, tmp_str->ptr(), tmp_str->length(), + quick_mode, need_mon)) && + error_num != HA_ERR_FOUND_DUPP_KEY + ) { + break; + } + tmp_str = tmp_str->next; + } + if (tmp_str == current_str) + { + error_num = spider_db_query(conn, tmp_str->ptr(), tmp_str->length(), + quick_mode, need_mon); + } + if (error_num == HA_ERR_FOUND_DUPP_KEY) + error_num = 0; + current_str = NULL; + } else { + if (table_lock_mode) + { + DBUG_PRINT("info",("spider table_lock_mode=%d", table_lock_mode)); + spider_db_oracle *db_conn = (spider_db_oracle *) conn->db_conn; + db_conn->table_lock_mode = table_lock_mode; + db_conn->exec_lock_sql = &sql_part; + table_lock_mode = 0; + } + error_num = spider_db_query(conn, sql.ptr(), sql.length(), quick_mode, + need_mon); + } + DBUG_RETURN(error_num); +} + +int spider_oracle_copy_table::copy_key_row( + spider_db_copy_table *source_ct, + Field *field, + ulong *row_pos, + ulong *length, + const char *joint_str, + const int joint_length +) { + int error_num; + spider_string *source_str = &((spider_oracle_copy_table *) source_ct)->sql; + DBUG_ENTER("spider_oracle_copy_table::copy_key_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + if ((error_num = spider_db_append_name_with_quote_str(&sql, + (char *) field->field_name, spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_NAME_QUOTE_LEN + joint_length + *length + + SPIDER_SQL_AND_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql.q_append(joint_str, joint_length); + sql.q_append(source_str->ptr() + *row_pos, *length); + sql.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::copy_row( + Field *field, + SPIDER_DB_ROW *row +) { + int error_num; + DBUG_ENTER("spider_oracle_copy_table::copy_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (row->is_null()) + { + DBUG_PRINT("info",("spider column is null")); + if (current_str->reserve(SPIDER_SQL_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else if (field->str_needs_quotes()) + { + DBUG_PRINT("info",("spider str_needs_quotes")); + if (current_str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, + SPIDER_SQL_VALUE_QUOTE_LEN); + if ((error_num = row->append_escaped_to_str(current_str, + spider_dbton_oracle.dbton_id))) + DBUG_RETURN(error_num); + if (current_str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, + SPIDER_SQL_VALUE_QUOTE_LEN); + } else { + DBUG_PRINT("info",("spider without_quotes")); + if ((error_num = row->append_to_str(current_str))) + DBUG_RETURN(error_num); + if (current_str->reserve(SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + current_str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::copy_rows( + TABLE *table, + SPIDER_DB_ROW *row, + ulong **last_row_pos, + ulong **last_lengths +) { + int error_num; + Field **field; + ulong *lengths2, *row_pos2; + DBUG_ENTER("spider_oracle_copy_table::copy_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!current_str) + { + if (!first_str) + { + if (!(first_str = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + first_str->init_calc_mem(216); + first_str->set_charset(sql.charset()); + if (first_str->reserve(sql.length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + first_str->q_append(sql.ptr(), sql.length()); + } else { + first_str->length(sql.length()); + } + current_str = first_str; + } else { + if (!current_str->next) + { + if (!(current_str->next = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->next->init_calc_mem(217); + current_str->next->set_charset(sql.charset()); + if (current_str->next->reserve(sql.length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->next->q_append(sql.ptr(), sql.length()); + } else { + current_str->next->length(sql.length()); + } + current_str = current_str->next; + } + row_pos2 = *last_row_pos; + lengths2 = *last_lengths; + + for ( + field = table->field; + *field; + field++, + lengths2++ + ) { + *row_pos2 = current_str->length(); + if ((error_num = + copy_row(*field, row))) + DBUG_RETURN(error_num); + *lengths2 = current_str->length() - *row_pos2 - SPIDER_SQL_COMMA_LEN; + row->next(); + row_pos2++; + } + current_str->length(current_str->length() - SPIDER_SQL_COMMA_LEN); + if (current_str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + current_str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_PRINT("info",("spider current_str=%s", current_str->c_ptr_safe())); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::copy_rows( + TABLE *table, + SPIDER_DB_ROW *row +) { + int error_num; + Field **field; + DBUG_ENTER("spider_oracle_copy_table::copy_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!current_str) + { + if (!first_str) + { + if (!(first_str = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + first_str->init_calc_mem(218); + first_str->set_charset(sql.charset()); + if (first_str->reserve(sql.length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + first_str->q_append(sql.ptr(), sql.length()); + } else { + first_str->length(sql.length()); + } + current_str = first_str; + } else { + if (!current_str->next) + { + if (!(current_str->next = new spider_string[1])) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->next->init_calc_mem(219); + current_str->next->set_charset(sql.charset()); + if (current_str->next->reserve(sql.length())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + current_str->next->q_append(sql.ptr(), sql.length()); + } else { + current_str->next->length(sql.length()); + } + current_str = current_str->next; + } + + for ( + field = table->field; + *field; + field++ + ) { + if ((error_num = + copy_row(*field, row))) + DBUG_RETURN(error_num); + row->next(); + } + current_str->length(current_str->length() - SPIDER_SQL_COMMA_LEN); + if (current_str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + current_str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, + SPIDER_SQL_CLOSE_PAREN_LEN); + DBUG_PRINT("info",("spider current_str=%s", current_str->c_ptr_safe())); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::append_insert_terminator() +{ + DBUG_ENTER("spider_oracle_copy_table::append_insert_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +int spider_oracle_copy_table::copy_insert_values( + spider_db_copy_table *source_ct +) { + spider_oracle_copy_table *tmp_ct = (spider_oracle_copy_table *) source_ct; + spider_string *source_str = &tmp_ct->sql; + int values_length = source_str->length() - tmp_ct->pos; + const char *values_ptr = source_str->ptr() + tmp_ct->pos; + DBUG_ENTER("spider_oracle_copy_table::copy_insert_values"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(values_length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql.q_append(values_ptr, values_length); + DBUG_RETURN(0); +} +#endif diff --git a/storage/spider/spd_db_oracle.h b/storage/spider/spd_db_oracle.h new file mode 100644 index 00000000000..e6ebb90f601 --- /dev/null +++ b/storage/spider/spd_db_oracle.h @@ -0,0 +1,1389 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +class spider_db_oracle; +class spider_db_oracle_result; + +class spider_db_oracle_util: public spider_db_util +{ +public: + spider_db_oracle_util(); + ~spider_db_oracle_util(); + int append_name( + spider_string *str, + const char *name, + uint name_length + ); + int append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ); + bool is_name_quote( + const char head_code + ); + int append_escaped_name_quote( + spider_string *str + ); + int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + CHARSET_INFO *access_charset + ); + int append_from_with_alias( + spider_string *str, + const char **table_names, + uint *table_name_lengths, + const char **table_aliases, + uint *table_alias_lengths, + uint table_count, + int *table_name_pos, + bool over_write + ); + int append_trx_isolation( + spider_string *str, + int trx_isolation + ); + int append_autocommit( + spider_string *str, + bool autocommit + ); + int append_sql_log_off( + spider_string *str, + bool sql_log_off + ); + int append_time_zone( + spider_string *str, + Time_zone *time_zone + ); + int append_start_transaction( + spider_string *str + ); + int append_xa_start( + spider_string *str, + XID *xid + ); + int append_lock_table_head( + spider_string *str + ); + int append_lock_table_body( + spider_string *str, + const char *db_name, + uint db_name_length, + CHARSET_INFO *db_name_charset, + const char *table_name, + uint table_name_length, + CHARSET_INFO *table_name_charset, + int lock_type + ); + int append_lock_table_tail( + spider_string *str + ); + int append_unlock_table( + spider_string *str + ); + int open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length + ); + size_t escape_string( + char *to, + const char *from, + size_t from_length, + CHARSET_INFO *access_charset + ); + int append_escaped_util( + spider_string *to, + String *from + ); +}; + +class spider_db_oracle_row: public spider_db_row +{ +public: + spider_db_oracle *db_conn; + spider_db_oracle_result *result; + sb2 *ind; + char **val; + ub2 *rlen; + sb2 *ind_first; + char **val_first; + ub2 *rlen_first; + spider_string *val_str; + spider_string *val_str_first; + OCIDefine **defnp; + OCILobLocator **lobhp; + OCIParam **colhp; + ub2 *coltp; + ub2 *colsz; + uint field_count; + ulong *row_size; + ulong *row_size_first; + CHARSET_INFO *access_charset; + bool cloned; + spider_db_oracle_util util; + + spider_db_oracle_row(); + ~spider_db_oracle_row(); + int store_to_field( + Field *field, + CHARSET_INFO *access_charset + ); + int append_to_str( + spider_string *str + ); + int append_escaped_to_str( + spider_string *str, + uint dbton_id + ); + void first(); + void next(); + bool is_null(); + int val_int(); + double val_real(); + SPIDER_DB_ROW *clone(); + int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ); + /* for oracle */ + int init(); + void deinit(); + int define(); + int fetch(); +}; + +class spider_db_oracle_result: public spider_db_result +{ +public: + spider_db_oracle *db_conn; + OCIStmt *stmtp; + uint field_count; + CHARSET_INFO *access_charset; + bool fetched; + spider_db_oracle_row row; + int store_error_num; + + spider_db_oracle_result(); + ~spider_db_oracle_result(); + bool has_result(); + void free_result(); + SPIDER_DB_ROW *current_row(); + SPIDER_DB_ROW *fetch_row(); + SPIDER_DB_ROW *fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf + ); + SPIDER_DB_ROW *fetch_row_from_tmp_table( + TABLE *tmp_table + ); + int fetch_table_status( + int mode, + ha_rows &records, + ulong &mean_rec_length, + ulonglong &data_file_length, + ulonglong &max_data_file_length, + ulonglong &index_file_length, + ulonglong &auto_increment_value, + time_t &create_time, + time_t &update_time, + time_t &check_time + ); + int fetch_table_records( + int mode, + ha_rows &records + ); + int fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size + ); + int fetch_table_mon_status( + int &status + ); + longlong num_rows(); + uint num_fields(); + void move_to_pos( + longlong pos + ); + int get_errno(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); + int fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset + ); +#endif + /* for oracle */ + int set_column_info(); +}; + +class spider_db_oracle: public spider_db_conn +{ +public: + OCIEnv *envhp; + OCIError *errhp; + OCIServer *srvhp; + OCISvcCtx *svchp; + OCISession *usrhp; + OCIStmt *stmtp; + OCITrans *txnhp; + spider_db_oracle_result *result; + int stored_error_num; + const char *stored_error; + uint update_rows; + int table_lock_mode; + spider_string *exec_lock_sql; + spider_db_oracle_util util; + ulonglong stored_last_insert_id; + HASH lock_table_hash; + bool lock_table_hash_inited; + uint lock_table_hash_id; + const char *lock_table_hash_func_name; + const char *lock_table_hash_file_name; + ulong lock_table_hash_line_no; + DYNAMIC_ARRAY handler_open_array; + bool handler_open_array_inited; + uint handler_open_array_id; + const char *handler_open_array_func_name; + const char *handler_open_array_file_name; + ulong handler_open_array_line_no; + + /* for bg_connect */ + char stored_error_msg[MYSQL_ERRMSG_SIZE]; + char *tgt_host; + char *tgt_username; + char *tgt_password; + long tgt_port; + char *tgt_socket; + char *server_name; + int connect_retry_count; + longlong connect_retry_interval; + + spider_db_oracle( + SPIDER_CONN *conn + ); + ~spider_db_oracle(); + int init(); + bool is_connected(); + void bg_connect(); + int connect( + char *tgt_host, + char *tgt_username, + char *tgt_password, + long tgt_port, + char *tgt_socket, + char *server_name, + int connect_retry_count, + longlong connect_retry_interval + ); + int ping(); + void bg_disconnect(); + void disconnect(); + int set_net_timeout(); + int exec_query( + const char *query, + uint length, + int quick_mode + ); + int get_errno(); + const char *get_error(); + bool is_server_gone_error( + int error_num + ); + bool is_dup_entry_error( + int error_num + ); + bool is_xa_nota_error( + int error_num + ); + spider_db_result *store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num + ); + spider_db_result *use_result( + st_spider_db_request_key *request_key, + int *error_num + ); + int next_result(); + uint affected_rows(); + ulonglong last_insert_id(); + int set_character_set( + const char *csname + ); + int select_db( + const char *dbname + ); + int consistent_snapshot( + int *need_mon + ); + bool trx_start_in_bulk_sql(); + int start_transaction( + int *need_mon + ); + int commit( + int *need_mon + ); + int rollback( + int *need_mon + ); + bool xa_start_in_bulk_sql(); + int xa_start( + XID *xid, + int *need_mon + ); + int xa_end( + XID *xid, + int *need_mon + ); + int xa_prepare( + XID *xid, + int *need_mon + ); + int xa_commit( + XID *xid, + int *need_mon + ); + int xa_rollback( + XID *xid, + int *need_mon + ); + bool set_trx_isolation_in_bulk_sql(); + int set_trx_isolation( + int trx_isolation, + int *need_mon + ); + bool set_autocommit_in_bulk_sql(); + int set_autocommit( + bool autocommit, + int *need_mon + ); + bool set_sql_log_off_in_bulk_sql(); + int set_sql_log_off( + bool sql_log_off, + int *need_mon + ); + bool set_time_zone_in_bulk_sql(); + int set_time_zone( + Time_zone *time_zone, + int *need_mon + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int append_sql( + char *sql, + ulong sql_length, + st_spider_db_request_key *request_key + ); + int append_open_handler( + uint handler_id, + const char *db_name, + const char *table_name, + const char *index_name, + const char *sql, + st_spider_db_request_key *request_key + ); + int append_select( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + int append_insert( + uint handler_id, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + st_spider_db_request_key *request_key + ); + int append_update( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + SPIDER_DB_HS_STRING_REF_BUFFER *upds, + int limit, + int skip, + bool increment, + bool decrement, + st_spider_db_request_key *request_key + ); + int append_delete( + uint handler_id, + spider_string *sql, + SPIDER_DB_HS_STRING_REF_BUFFER *keys, + int limit, + int skip, + st_spider_db_request_key *request_key + ); + void reset_request_queue(); +#endif + size_t escape_string( + char *to, + const char *from, + size_t from_length + ); + bool have_lock_table_list(); + int append_lock_tables( + spider_string *str + ); + int append_unlock_tables( + spider_string *str + ); + uint get_lock_table_hash_count(); + void reset_lock_table_hash(); + uint get_opened_handler_count(); + void reset_opened_handler(); + void set_dup_key_idx( + ha_spider *spider, + int link_idx + ); + bool cmp_request_key_to_snd( + st_spider_db_request_key *request_key + ); +private: + int set_error( + sword res, + dvoid *hndlp, + int error_num, + const char *error1, + const char *error2 + ); +}; + +class spider_oracle_share: public spider_db_share +{ +public: + spider_string *table_select; + int table_select_pos; + spider_string *key_select; + int *key_select_pos; + spider_string *key_hint; + spider_string *show_table_status; + spider_string *show_records; + spider_string *show_autoinc; + spider_string *show_last_insert_id; + spider_string *show_index; + spider_string *table_names_str; + spider_string *db_names_str; + spider_string *db_table_str; + spider_string *nextval_str; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type *db_table_str_hash_value; +#endif + uint table_nm_max_length; + uint db_nm_max_length; + uint nextval_max_length; + spider_string *column_name_str; + bool same_db_table_name; + int first_all_link_idx; + + spider_oracle_share( + st_spider_share *share + ); + ~spider_oracle_share(); + int init(); + uint get_column_name_length( + uint field_index + ); + int append_column_name( + spider_string *str, + uint field_index + ); + int append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length + ); + int append_table_name( + spider_string *str, + int all_link_idx + ); + int append_table_name_with_adjusting( + spider_string *str, + int all_link_idx + ); + int append_from_with_adjusted_table_name( + spider_string *str, + int *table_name_pos + ); + bool need_change_db_table_name(); +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ); +#endif +private: + int create_table_names_str(); + void free_table_names_str(); + int create_column_name_str(); + void free_column_name_str(); + int convert_key_hint_str(); + int append_show_table_status(); + void free_show_table_status(); + int append_show_records(); + void free_show_records(); + int append_show_autoinc(); + void free_show_autoinc(); + int append_show_last_insert_id(); + void free_show_last_insert_id(); + int append_show_index(); + void free_show_index(); + int append_table_select(); + int append_key_select( + uint idx + ); +}; + +class spider_oracle_handler: public spider_db_handler +{ + spider_string sql; + spider_string sql_part; + spider_string sql_part2; + spider_string ha_sql; + int where_pos; + int order_pos; + int limit_pos; + int table_name_pos; + int update_set_pos; + int ha_read_pos; + int ha_next_pos; + int ha_where_pos; + int ha_limit_pos; + int ha_table_name_pos; + uint ha_sql_handler_id; + spider_string insert_sql; + int insert_pos; + int insert_table_name_pos; + int nextval_pos; + spider_string update_sql; + TABLE *upd_tmp_tbl; + TMP_TABLE_PARAM upd_tmp_tbl_prm; + spider_string tmp_sql; + int tmp_sql_pos1; /* drop db nm pos at tmp_table_join */ + int tmp_sql_pos2; /* create db nm pos at tmp_table_join */ + int tmp_sql_pos3; /* insert db nm pos at tmp_table_join */ + int tmp_sql_pos4; /* insert val pos at tmp_table_join */ + int tmp_sql_pos5; /* end of drop tbl at tmp_table_join */ + spider_string dup_update_sql; + spider_string *exec_sql; + spider_string *exec_insert_sql; + spider_string *exec_update_sql; + spider_string *exec_tmp_sql; + spider_string *exec_ha_sql; + spider_string *exec_lock_sql; + int table_lock_mode; + bool reading_from_bulk_tmp_table; + bool filled_up; + bool select_rownum_appended; + bool update_rownum_appended; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_DB_HS_STRING_REF_BUFFER hs_upds; +#endif +public: + spider_oracle_share *oracle_share; + SPIDER_LINK_FOR_HASH *link_for_hash; + spider_oracle_handler( + ha_spider *spider, + spider_oracle_share *share + ); + ~spider_oracle_handler(); + int init(); + int append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type + ); + int append_key_column_types( + const key_range *start_key, + spider_string *str + ); + int append_key_join_columns_for_bka( + const key_range *start_key, + spider_string *str, + const char **table_aliases, + uint *table_alias_lengths + ); + int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_tmp_table_and_sql_for_bka(); + void create_tmp_bka_table_name( + char *tmp_table_name, + int *tmp_table_name_length, + int link_idx + ); + int append_create_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + CHARSET_INFO *table_charset + ); + int append_drop_tmp_bka_table( + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos, + int *drop_table_end_pos, + bool with_semicolon + ); + int append_insert_tmp_bka_table( + const key_range *start_key, + spider_string *str, + char *tmp_table_name, + int tmp_table_name_length, + int *db_name_pos + ); + int append_insert_for_recovery( + ulong sql_type, + int link_idx + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff, + int link_idx + ); + int append_insert_part(); + int append_insert( + spider_string *str, + int link_idx + ); + int append_update_part(); + int append_update( + spider_string *str, + int link_idx + ); + int append_delete_part(); + int append_delete( + spider_string *str + ); + #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_increment_update_set_part(); + int append_increment_update_set( + spider_string *str + ); + #endif + #endif + int append_update_set_part(); + int append_update_set( + spider_string *str + ); + #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + int append_direct_update_set_part(); + int append_direct_update_set( + spider_string *str + ); + int append_dup_update_pushdown_part( + const char *alias, + uint alias_length + ); + int append_update_columns_part( + const char *alias, + uint alias_length + ); + int check_update_columns_part(); + int append_update_columns( + spider_string *str, + const char *alias, + uint alias_length + ); + #endif + int append_select_part( + ulong sql_type + ); + int append_select( + spider_string *str, + ulong sql_type + ); + int append_table_select_part( + ulong sql_type + ); + int append_table_select( + spider_string *str + ); + int append_key_select_part( + ulong sql_type, + uint idx + ); + int append_key_select( + spider_string *str, + uint idx + ); + int append_minimum_select_part( + ulong sql_type + ); + int append_minimum_select( + spider_string *str, + ulong sql_type + ); + int append_table_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_select_with_alias( + spider_string *str, + const KEY *key_info, + const char *alias, + uint alias_length + ); + int append_minimum_select_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_select_columns_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_hint_after_table_part( + ulong sql_type + ); + int append_hint_after_table( + spider_string *str + ); + void set_where_pos( + ulong sql_type + ); + void set_where_to_pos( + ulong sql_type + ); + int check_item_type( + Item *item + ); + int append_values_connector_part( + ulong sql_type + ); + int append_values_connector( + spider_string *str + ); + int append_values_terminator_part( + ulong sql_type + ); + int append_values_terminator( + spider_string *str + ); + int append_key_column_values_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_column_values( + spider_string *str, + const key_range *start_key + ); + int append_key_where_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type + ); + int append_key_where( + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + bool set_order + ); + int append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_is_null( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq + ); + int append_where_terminator_part( + ulong sql_type, + bool set_order, + int key_count + ); + int append_where_terminator( + ulong sql_type, + spider_string *str, + spider_string *str_part, + spider_string *str_part2, + bool set_order, + int key_count + ); + int append_match_where_part( + ulong sql_type + ); + int append_match_where( + spider_string *str + ); + int append_update_where( + spider_string *str, + const TABLE *table, + my_ptrdiff_t ptr_diff + ); + int append_condition_part( + const char *alias, + uint alias_length, + ulong sql_type, + bool test_flg + ); + int append_condition( + spider_string *str, + const char *alias, + uint alias_length, + bool start_where, + ulong sql_type + ); + int append_match_against_part( + ulong sql_type, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length + ); + int append_match_against( + spider_string *str, + st_spider_ft_info *ft_info, + const char *alias, + uint alias_length + ); + int append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + int append_match_select( + spider_string *str, + const char *alias, + uint alias_length + ); + void set_order_pos( + ulong sql_type + ); + void set_order_to_pos( + ulong sql_type + ); + int append_key_order_for_merge_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_merge_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_for_direct_order_limit_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_direct_order_limit_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_with_alias_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_key_order_for_handler( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_key_order_with_alias( + spider_string *str, + const char *alias, + uint alias_length + ); + int append_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type + ); + int append_limit( + spider_string *str, + longlong offset, + longlong limit + ); + int append_select_lock_part( + ulong sql_type + ); + int append_select_lock( + spider_string *str + ); + int append_union_all_start_part( + ulong sql_type + ); + int append_union_all_start( + spider_string *str + ); + int append_union_all_part( + ulong sql_type + ); + int append_union_all( + spider_string *str + ); + int append_union_all_end_part( + ulong sql_type + ); + int append_union_all_end( + spider_string *str + ); + int append_multi_range_cnt_part( + ulong sql_type, + uint multi_range_cnt, + bool with_comma + ); + int append_multi_range_cnt( + spider_string *str, + uint multi_range_cnt, + bool with_comma + ); + int append_open_handler_part( + ulong sql_type, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_open_handler( + spider_string *str, + uint handler_id, + SPIDER_CONN *conn, + int link_idx + ); + int append_close_handler_part( + ulong sql_type, + int link_idx + ); + int append_close_handler( + spider_string *str, + int link_idx + ); + int append_insert_terminator_part( + ulong sql_type + ); + int append_insert_terminator( + spider_string *str + ); + int append_insert_values_part( + ulong sql_type + ); + int append_insert_values( + spider_string *str + ); + int append_into_part( + ulong sql_type + ); + int append_into( + spider_string *str + ); + void set_insert_to_pos( + ulong sql_type + ); + int append_from_part( + ulong sql_type, + int link_idx + ); + int append_from( + spider_string *str, + ulong sql_type, + int link_idx + ); + int append_flush_tables_part( + ulong sql_type, + int link_idx, + bool lock + ); + int append_flush_tables( + spider_string *str, + int link_idx, + bool lock + ); + int append_optimize_table_part( + ulong sql_type, + int link_idx + ); + int append_optimize_table( + spider_string *str, + int link_idx + ); + int append_analyze_table_part( + ulong sql_type, + int link_idx + ); + int append_analyze_table( + spider_string *str, + int link_idx + ); + int append_repair_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_repair_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_check_table_part( + ulong sql_type, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_check_table( + spider_string *str, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int append_enable_keys_part( + ulong sql_type, + int link_idx + ); + int append_enable_keys( + spider_string *str, + int link_idx + ); + int append_disable_keys_part( + ulong sql_type, + int link_idx + ); + int append_disable_keys( + spider_string *str, + int link_idx + ); + int append_delete_all_rows_part( + ulong sql_type + ); + int append_delete_all_rows( + spider_string *str, + ulong sql_type + ); + int append_truncate( + spider_string *str, + ulong sql_type, + int link_idx + ); + int append_explain_select_part( + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ); + int append_explain_select( + spider_string *str, + key_range *start_key, + key_range *end_key, + ulong sql_type, + int link_idx + ); + bool is_bulk_insert_exec_period( + bool bulk_end + ); + bool sql_is_filled_up( + ulong sql_type + ); + bool sql_is_empty( + ulong sql_type + ); + bool support_multi_split_read(); + bool support_bulk_update(); + int bulk_tmp_table_insert(); + int bulk_tmp_table_insert( + int link_idx + ); + int bulk_tmp_table_end_bulk_insert(); + int bulk_tmp_table_rnd_init(); + int bulk_tmp_table_rnd_next(); + int bulk_tmp_table_rnd_end(); + bool need_copy_for_update( + int link_idx + ); + bool bulk_tmp_table_created(); + int mk_bulk_tmp_table_and_bulk_start(); + void rm_bulk_tmp_table(); + int store_sql_to_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table + ); + int restore_sql_from_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table + ); + int insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx + ); + int append_lock_tables_list( + SPIDER_CONN *conn, + int link_idx, + int *appended + ); + int realloc_sql( + ulong *realloced + ); + int reset_sql( + ulong sql_type + ); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int reset_keys( + ulong sql_type + ); + int reset_upds( + ulong sql_type + ); + int reset_strs( + ulong sql_type + ); + int reset_strs_pos( + ulong sql_type + ); + int push_back_upds( + SPIDER_HS_STRING_REF &info + ); +#endif + bool need_lock_before_set_sql_for_exec( + ulong sql_type + ); + int set_sql_for_exec( + ulong sql_type, + int link_idx + ); + int set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type + ); + int execute_sql( + ulong sql_type, + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ); + int reset(); + int sts_mode_exchange( + int sts_mode + ); + int show_table_status( + int link_idx, + int sts_mode, + uint flag + ); + int crd_mode_exchange( + int crd_mode + ); + int show_index( + int link_idx, + int crd_mode + ); + int show_records( + int link_idx + ); + int show_autoinc( + int link_idx + ); + int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ); + ha_rows explain_select( + key_range *start_key, + key_range *end_key, + int link_idx + ); + int lock_tables( + int link_idx + ); + int unlock_tables( + int link_idx + ); + int disable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int enable_keys( + SPIDER_CONN *conn, + int link_idx + ); + int check_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int repair_table( + SPIDER_CONN *conn, + int link_idx, + HA_CHECK_OPT* check_opt + ); + int analyze_table( + SPIDER_CONN *conn, + int link_idx + ); + int optimize_table( + SPIDER_CONN *conn, + int link_idx + ); + int flush_tables( + SPIDER_CONN *conn, + int link_idx, + bool lock + ); + int flush_logs( + SPIDER_CONN *conn, + int link_idx + ); + int insert_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int delete_opened_handler( + SPIDER_CONN *conn, + int link_idx + ); + int sync_from_clone_source( + spider_db_handler *dbton_hdl + ); + bool support_use_handler( + int use_handler + ); +}; + +class spider_oracle_copy_table: public spider_db_copy_table +{ +public: + spider_oracle_share *oracle_share; + spider_string sql; + spider_string sql_part; + uint pos; + uint table_name_pos; + uint pos_diff; + int table_lock_mode; + int store_link_idx; + bool select_rownum_appended; + spider_string *first_str; + spider_string *current_str; + spider_oracle_copy_table( + spider_oracle_share *db_share + ); + ~spider_oracle_copy_table(); + int init(); + void set_sql_charset( + CHARSET_INFO *cs + ); + int append_select_str(); + int append_insert_str( + int insert_flg + ); + int append_table_columns( + TABLE_SHARE *table_share + ); + int append_from_str(); + int append_table_name( + int link_idx + ); + void set_sql_pos(); + void set_sql_to_pos(); + int append_copy_where( + spider_db_copy_table *source_ct, + KEY *key_info, + ulong *last_row_pos, + ulong *last_lengths + ); + int append_key_order_str( + KEY *key_info, + int start_pos, + bool desc_flg + ); + int append_limit( + longlong offset, + longlong limit + ); + int append_into_str(); + int append_open_paren_str(); + int append_values_str(); + int append_select_lock_str( + int lock_mode + ); + int exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon + ); + int copy_key_row( + spider_db_copy_table *source_ct, + Field *field, + ulong *row_pos, + ulong *length, + const char *joint_str, + const int joint_length + ); + int copy_row( + Field *field, + SPIDER_DB_ROW *row + ); + int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row, + ulong **last_row_pos, + ulong **last_lengths + ); + int copy_rows( + TABLE *table, + SPIDER_DB_ROW *row + ); + int append_insert_terminator(); + int copy_insert_values( + spider_db_copy_table *source_ct + ); +}; diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc new file mode 100644 index 00000000000..2c844eb2da3 --- /dev/null +++ b/storage/spider/spd_direct_sql.cc @@ -0,0 +1,1877 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_base.h" +#include "sql_servers.h" +#endif +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_sys_table.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_table.h" +#include "spd_direct_sql.h" +#include "spd_udf.h" +#include "spd_malloc.h" + +extern const char **spd_defaults_extra_file; +extern const char **spd_defaults_file; + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key spd_key_mutex_mta_conn; +extern PSI_mutex_key spd_key_mutex_bg_direct_sql; +extern PSI_cond_key spd_key_cond_bg_direct_sql; +#endif + +extern HASH spider_open_connections; +extern pthread_mutex_t spider_conn_mutex; + +uint spider_udf_calc_hash( + char *key, + uint mod +) { + uint sum = 0; + DBUG_ENTER("spider_udf_calc_hash"); + while (*key != '\0') + { + sum += *key; + key++; + } + DBUG_PRINT("info",("spider calc hash = %u", sum % mod)); + DBUG_RETURN(sum % mod); +} + +int spider_udf_direct_sql_create_table_list( + SPIDER_DIRECT_SQL *direct_sql, + char *table_name_list, + uint table_name_list_length +) { + int table_count, roop_count, length; + char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *tmp_name_ptr; + THD *thd = direct_sql->trx->thd; + DBUG_ENTER("spider_udf_direct_sql_create_table_list"); + tmp_ptr = table_name_list; + while (*tmp_ptr == ' ') + tmp_ptr++; + if (*tmp_ptr) + table_count = 1; + else { + direct_sql->table_count = 0; + DBUG_RETURN(0); + } + + while (TRUE) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + { + table_count++; + tmp_ptr = tmp_ptr2 + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + } else + break; + } +#if MYSQL_VERSION_ID < 50500 + if (!(direct_sql->db_names = (char**) + spider_bulk_malloc(spider_current_trx, 31, MYF(MY_WME | MY_ZEROFILL), + &direct_sql->db_names, sizeof(char*) * table_count, + &direct_sql->table_names, sizeof(char*) * table_count, + &direct_sql->tables, sizeof(TABLE*) * table_count, + &tmp_name_ptr, sizeof(char) * ( + table_name_list_length + + thd->db_length * table_count + + 2 * table_count + ), + &direct_sql->iop, sizeof(int) * table_count, + NullS)) + ) +#else + if (!(direct_sql->db_names = (char**) + spider_bulk_malloc(spider_current_trx, 31, MYF(MY_WME | MY_ZEROFILL), + &direct_sql->db_names, sizeof(char*) * table_count, + &direct_sql->table_names, sizeof(char*) * table_count, + &direct_sql->tables, sizeof(TABLE*) * table_count, + &tmp_name_ptr, sizeof(char) * ( + table_name_list_length + + thd->db_length * table_count + + 2 * table_count + ), + &direct_sql->iop, sizeof(int) * table_count, + &direct_sql->table_list, sizeof(TABLE_LIST) * table_count, + &direct_sql->real_table_bitmap, sizeof(uchar) * ((table_count + 7) / 8), + NullS)) + ) +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + tmp_ptr = table_name_list; + while (*tmp_ptr == ' ') + tmp_ptr++; + roop_count = 0; + while (TRUE) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + *tmp_ptr2 = '\0'; + + direct_sql->db_names[roop_count] = tmp_name_ptr; + + if ((tmp_ptr3 = strchr(tmp_ptr, '.'))) + { + /* exist database name */ + *tmp_ptr3 = '\0'; + length = strlen(tmp_ptr); + memcpy(tmp_name_ptr, tmp_ptr, length + 1); + tmp_name_ptr += length + 1; + tmp_ptr = tmp_ptr3 + 1; + } else { + if (thd->db) + { + memcpy(tmp_name_ptr, thd->db, + thd->db_length + 1); + tmp_name_ptr += thd->db_length + 1; + } else { + direct_sql->db_names[roop_count] = (char *) ""; + } + } + + direct_sql->table_names[roop_count] = tmp_name_ptr; + length = strlen(tmp_ptr); + memcpy(tmp_name_ptr, tmp_ptr, length + 1); + tmp_name_ptr += length + 1; + + DBUG_PRINT("info",("spider db=%s", + direct_sql->db_names[roop_count])); + DBUG_PRINT("info",("spider table_name=%s", + direct_sql->table_names[roop_count])); + + if (!tmp_ptr2) + break; + tmp_ptr = tmp_ptr2 + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + roop_count++; + } + direct_sql->table_count = table_count; + DBUG_RETURN(0); +} + +int spider_udf_direct_sql_create_conn_key( + SPIDER_DIRECT_SQL *direct_sql +) { + char *tmp_name, port_str[6]; + DBUG_ENTER("spider_udf_direct_sql_create_conn_key"); + + /* tgt_db not use */ +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + direct_sql->conn_key_length + = 1 + + direct_sql->tgt_wrapper_length + 1 + + direct_sql->tgt_host_length + 1 + + 5 + 1 + + direct_sql->tgt_socket_length + 1 + + direct_sql->tgt_username_length + 1 + + direct_sql->tgt_password_length + 1 + + direct_sql->tgt_ssl_ca_length + 1 + + direct_sql->tgt_ssl_capath_length + 1 + + direct_sql->tgt_ssl_cert_length + 1 + + direct_sql->tgt_ssl_cipher_length + 1 + + direct_sql->tgt_ssl_key_length + 1 + + 1 + 1 + + direct_sql->tgt_default_file_length + 1 + + direct_sql->tgt_default_group_length; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + direct_sql->conn_key_length + = 1 + + direct_sql->tgt_wrapper_length + 1 + + direct_sql->tgt_host_length + 1 + + 5 + 1 + + direct_sql->tgt_socket_length; + } +#endif + if (!(direct_sql->conn_key = (char *) + spider_malloc(spider_current_trx, 9, direct_sql->conn_key_length + 1, + MYF(MY_WME | MY_ZEROFILL))) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (direct_sql->connection_channel > 48) + *direct_sql->conn_key = '0' + 48 - direct_sql->connection_channel; + else + *direct_sql->conn_key = '0' + direct_sql->connection_channel; + DBUG_PRINT("info",("spider tgt_wrapper=%s", direct_sql->tgt_wrapper)); + tmp_name = strmov(direct_sql->conn_key + 1, direct_sql->tgt_wrapper); + DBUG_PRINT("info",("spider tgt_host=%s", direct_sql->tgt_host)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_host); + my_sprintf(port_str, (port_str, "%05ld", direct_sql->tgt_port)); + DBUG_PRINT("info",("spider port_str=%s", port_str)); + tmp_name = strmov(tmp_name + 1, port_str); + if (direct_sql->tgt_socket) + { + DBUG_PRINT("info",("spider tgt_socket=%s", direct_sql->tgt_socket)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_socket); + } else + tmp_name++; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if (direct_sql->tgt_username) + { + DBUG_PRINT("info",("spider tgt_username=%s", direct_sql->tgt_username)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_username); + } else + tmp_name++; + if (direct_sql->tgt_password) + { + DBUG_PRINT("info",("spider tgt_password=%s", direct_sql->tgt_password)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_password); + } else + tmp_name++; + if (direct_sql->tgt_ssl_ca) + { + DBUG_PRINT("info",("spider tgt_ssl_ca=%s", direct_sql->tgt_ssl_ca)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_ssl_ca); + } else + tmp_name++; + if (direct_sql->tgt_ssl_capath) + { + DBUG_PRINT("info",("spider tgt_ssl_capath=%s", + direct_sql->tgt_ssl_capath)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_ssl_capath); + } else + tmp_name++; + if (direct_sql->tgt_ssl_cert) + { + DBUG_PRINT("info",("spider tgt_ssl_cert=%s", direct_sql->tgt_ssl_cert)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_ssl_cert); + } else + tmp_name++; + if (direct_sql->tgt_ssl_cipher) + { + DBUG_PRINT("info",("spider tgt_ssl_cipher=%s", + direct_sql->tgt_ssl_cipher)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_ssl_cipher); + } else + tmp_name++; + if (direct_sql->tgt_ssl_key) + { + DBUG_PRINT("info",("spider tgt_ssl_key=%s", direct_sql->tgt_ssl_key)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_ssl_key); + } else + tmp_name++; + tmp_name++; + *tmp_name = '0' + ((char) direct_sql->tgt_ssl_vsc); + if (direct_sql->tgt_default_file) + { + DBUG_PRINT("info",("spider tgt_default_file=%s", + direct_sql->tgt_default_file)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_default_file); + } else + tmp_name++; + if (direct_sql->tgt_default_group) + { + DBUG_PRINT("info",("spider tgt_default_group=%s", + direct_sql->tgt_default_group)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_default_group); + } else + tmp_name++; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + uint roop_count2; + direct_sql->dbton_id = SPIDER_DBTON_SIZE; + DBUG_PRINT("info",("spider direct_sql->tgt_wrapper=%s", + direct_sql->tgt_wrapper)); + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) + { + DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2, + spider_dbton[roop_count2].wrapper ? + spider_dbton[roop_count2].wrapper : "NULL")); + if ( + spider_dbton[roop_count2].wrapper && + !strcmp(direct_sql->tgt_wrapper, spider_dbton[roop_count2].wrapper) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { + direct_sql->dbton_id = roop_count2; + break; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_NOSQL) + { + direct_sql->dbton_id = roop_count2; + break; + } + } +#endif + } + } +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + direct_sql->conn_key_hash_value = my_calc_hash(&spider_open_connections, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length); +#endif + DBUG_RETURN(0); +} + +SPIDER_CONN *spider_udf_direct_sql_create_conn( + const SPIDER_DIRECT_SQL *direct_sql, + int *error_num +) { + SPIDER_CONN *conn; + char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket; + char *tmp_wrapper, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert; + char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group; + int *need_mon; + DBUG_ENTER("spider_udf_direct_sql_create_conn"); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 32, MYF(MY_WME | MY_ZEROFILL), + &conn, sizeof(*conn), + &tmp_name, direct_sql->conn_key_length + 1, + &tmp_host, direct_sql->tgt_host_length + 1, + &tmp_username, direct_sql->tgt_username_length + 1, + &tmp_password, direct_sql->tgt_password_length + 1, + &tmp_socket, direct_sql->tgt_socket_length + 1, + &tmp_wrapper, direct_sql->tgt_wrapper_length + 1, + &tmp_ssl_ca, direct_sql->tgt_ssl_ca_length + 1, + &tmp_ssl_capath, direct_sql->tgt_ssl_capath_length + 1, + &tmp_ssl_cert, direct_sql->tgt_ssl_cert_length + 1, + &tmp_ssl_cipher, direct_sql->tgt_ssl_cipher_length + 1, + &tmp_ssl_key, direct_sql->tgt_ssl_key_length + 1, + &tmp_default_file, + direct_sql->tgt_default_file_length + 1, + &tmp_default_group, + direct_sql->tgt_default_group_length + 1, + &need_mon, sizeof(int), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + conn->default_database.init_calc_mem(138); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 33, MYF(MY_WME | MY_ZEROFILL), + &conn, sizeof(*conn), + &tmp_name, direct_sql->conn_key_length + 1, + &tmp_host, direct_sql->tgt_host_length + 1, + &tmp_socket, direct_sql->tgt_socket_length + 1, + &tmp_wrapper, direct_sql->tgt_wrapper_length + 1, + &need_mon, sizeof(int), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + conn->default_database.init_calc_mem(103); + } +#endif + + conn->conn_key_length = direct_sql->conn_key_length; + conn->conn_key = tmp_name; + memcpy(conn->conn_key, direct_sql->conn_key, direct_sql->conn_key_length); + conn->tgt_wrapper_length = direct_sql->tgt_wrapper_length; + conn->tgt_wrapper = tmp_wrapper; + memcpy(conn->tgt_wrapper, direct_sql->tgt_wrapper, + direct_sql->tgt_wrapper_length); + conn->tgt_host_length = direct_sql->tgt_host_length; + conn->tgt_host = tmp_host; + memcpy(conn->tgt_host, direct_sql->tgt_host, direct_sql->tgt_host_length); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + conn->tgt_port = direct_sql->tgt_port; + conn->tgt_socket_length = direct_sql->tgt_socket_length; + conn->tgt_socket = tmp_socket; + memcpy(conn->tgt_socket, direct_sql->tgt_socket, + direct_sql->tgt_socket_length); + conn->tgt_username_length = direct_sql->tgt_username_length; + conn->tgt_username = tmp_username; + memcpy(conn->tgt_username, direct_sql->tgt_username, + direct_sql->tgt_username_length); + conn->tgt_password_length = direct_sql->tgt_password_length; + conn->tgt_password = tmp_password; + memcpy(conn->tgt_password, direct_sql->tgt_password, + direct_sql->tgt_password_length); + conn->tgt_ssl_ca_length = direct_sql->tgt_ssl_ca_length; + if (conn->tgt_ssl_ca_length) + { + conn->tgt_ssl_ca = tmp_ssl_ca; + memcpy(conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, + direct_sql->tgt_ssl_ca_length); + } else + conn->tgt_ssl_ca = NULL; + conn->tgt_ssl_capath_length = direct_sql->tgt_ssl_capath_length; + if (conn->tgt_ssl_capath_length) + { + conn->tgt_ssl_capath = tmp_ssl_capath; + memcpy(conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, + direct_sql->tgt_ssl_capath_length); + } else + conn->tgt_ssl_capath = NULL; + conn->tgt_ssl_cert_length = direct_sql->tgt_ssl_cert_length; + if (conn->tgt_ssl_cert_length) + { + conn->tgt_ssl_cert = tmp_ssl_cert; + memcpy(conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, + direct_sql->tgt_ssl_cert_length); + } else + conn->tgt_ssl_cert = NULL; + conn->tgt_ssl_cipher_length = direct_sql->tgt_ssl_cipher_length; + if (conn->tgt_ssl_cipher_length) + { + conn->tgt_ssl_cipher = tmp_ssl_cipher; + memcpy(conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, + direct_sql->tgt_ssl_cipher_length); + } else + conn->tgt_ssl_cipher = NULL; + conn->tgt_ssl_key_length = direct_sql->tgt_ssl_key_length; + if (conn->tgt_ssl_key_length) + { + conn->tgt_ssl_key = tmp_ssl_key; + memcpy(conn->tgt_ssl_key, direct_sql->tgt_ssl_key, + direct_sql->tgt_ssl_key_length); + } else + conn->tgt_ssl_key = NULL; + conn->tgt_default_file_length = direct_sql->tgt_default_file_length; + if (conn->tgt_default_file_length) + { + conn->tgt_default_file = tmp_default_file; + memcpy(conn->tgt_default_file, direct_sql->tgt_default_file, + direct_sql->tgt_default_file_length); + } else + conn->tgt_default_file = NULL; + conn->tgt_default_group_length = direct_sql->tgt_default_group_length; + if (conn->tgt_default_group_length) + { + conn->tgt_default_group = tmp_default_group; + memcpy(conn->tgt_default_group, direct_sql->tgt_default_group, + direct_sql->tgt_default_group_length); + } else + conn->tgt_default_group = NULL; + conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + conn->hs_port = direct_sql->tgt_port; + if (direct_sql->tgt_socket) + { + conn->hs_sock_length = direct_sql->tgt_socket_length; + conn->hs_sock = tmp_socket; + memcpy(conn->hs_sock, direct_sql->tgt_socket, + direct_sql->tgt_socket_length); + } + } +#endif + conn->dbton_id = direct_sql->dbton_id; + conn->conn_need_mon = need_mon; + conn->need_mon = need_mon; + if (!(conn->db_conn = spider_dbton[conn->dbton_id].create_db_conn(conn))) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_db_conn_create; + } + if ((*error_num = conn->db_conn->init())) + { + goto error_db_conn_init; + } + conn->join_trx = 0; + conn->thd = NULL; + conn->table_lock = 0; + conn->semi_trx_isolation = -2; + conn->semi_trx_isolation_chk = FALSE; + conn->semi_trx_chk = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + conn->conn_kind = SPIDER_CONN_KIND_MYSQL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (direct_sql->access_mode == 1) + { + conn->conn_kind = SPIDER_CONN_KIND_HS_READ; + } else { + conn->conn_kind = SPIDER_CONN_KIND_HS_WRITE; + } +#endif + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&conn->mta_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, + MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_mta_conn_mutex_init; + } + + if ((*error_num = spider_db_udf_direct_sql_connect(direct_sql, conn))) + goto error; + conn->ping_time = (time_t) time((time_t*) 0); + + DBUG_RETURN(conn); + +error: + DBUG_ASSERT(!conn->mta_conn_mutex_file_pos.file_name); + pthread_mutex_destroy(&conn->mta_conn_mutex); +error_mta_conn_mutex_init: +error_db_conn_init: + delete conn->db_conn; +error_db_conn_create: + spider_free(spider_current_trx, conn, MYF(0)); +error_alloc_conn: + DBUG_RETURN(NULL); +} + +SPIDER_CONN *spider_udf_direct_sql_get_conn( + const SPIDER_DIRECT_SQL *direct_sql, + SPIDER_TRX *trx, + int *error_num +) { + SPIDER_CONN *conn = NULL; + DBUG_ENTER("spider_udf_direct_sql_get_conn"); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + DBUG_PRINT("info",("spider direct_sql->access_mode=%d", + direct_sql->access_mode)); +#endif + +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (direct_sql->access_mode == 0 && +#endif + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_conn_hash, direct_sql->conn_key_hash_value, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + (direct_sql->access_mode == 1 && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_direct_hs_r_conn_hash, direct_sql->conn_key_hash_value, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) + ) || + (direct_sql->access_mode == 2 && + !(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &trx->trx_direct_hs_w_conn_hash, direct_sql->conn_key_hash_value, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) + ) +#endif + ) +#else + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (direct_sql->access_mode == 0 && +#endif + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_conn_hash, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + (direct_sql->access_mode == 1 && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_direct_hs_r_conn_hash, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) + ) || + (direct_sql->access_mode == 2 && + !(conn = (SPIDER_CONN*) my_hash_search(&trx->trx_direct_hs_w_conn_hash, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length)) + ) +#endif + ) +#endif + { + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (direct_sql->access_mode == 0 && +#endif + ( + (spider_param_conn_recycle_mode(trx->thd) & 1) || + spider_param_conn_recycle_strict(trx->thd) + ) +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + (direct_sql->access_mode == 1 && + ( + (spider_param_hs_r_conn_recycle_mode(trx->thd) & 1) || + spider_param_hs_r_conn_recycle_strict(trx->thd) + ) + ) || + (direct_sql->access_mode == 2 && + ( + (spider_param_hs_w_conn_recycle_mode(trx->thd) & 1) || + spider_param_hs_w_conn_recycle_strict(trx->thd) + ) + ) +#endif + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + pthread_mutex_lock(&spider_conn_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(conn = (SPIDER_CONN*) my_hash_search_using_hash_value( + &spider_open_connections, direct_sql->conn_key_hash_value, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length))) +#else + if (!(conn = (SPIDER_CONN*) my_hash_search(&spider_open_connections, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length))) +#endif + { + pthread_mutex_unlock(&spider_conn_mutex); + DBUG_PRINT("info",("spider create new conn")); + if(!(conn = spider_udf_direct_sql_create_conn(direct_sql, + error_num))) + goto error; + } else { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_open_connections, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_open_connections, (uchar*) conn); +#endif + pthread_mutex_unlock(&spider_conn_mutex); + DBUG_PRINT("info",("spider get global conn")); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } +#endif + } else { + DBUG_PRINT("info",("spider create new conn")); + /* conn_recycle_strict = 0 and conn_recycle_mode = 0 or 2 */ + if(!(conn = spider_udf_direct_sql_create_conn(direct_sql, error_num))) + goto error; + } + conn->thd = trx->thd; + conn->priority = direct_sql->priority; + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 0) + { +#endif + uint old_elements = trx->trx_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_conn_hash, + direct_sql->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_conn_hash, + (trx->trx_conn_hash.array.max_element - old_elements) * + trx->trx_conn_hash.array.size_of_element); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (direct_sql->access_mode == 1) + { + uint old_elements = trx->trx_direct_hs_r_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_direct_hs_r_conn_hash, + direct_sql->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_direct_hs_r_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_direct_hs_r_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_direct_hs_r_conn_hash, + (trx->trx_direct_hs_r_conn_hash.array.max_element - old_elements) * + trx->trx_direct_hs_r_conn_hash.array.size_of_element); + } + } else { + uint old_elements = trx->trx_direct_hs_w_conn_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_direct_hs_w_conn_hash, + direct_sql->conn_key_hash_value, (uchar*) conn)) +#else + if (my_hash_insert(&trx->trx_direct_hs_w_conn_hash, (uchar*) conn)) +#endif + { + spider_free_conn(conn); + *error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_direct_hs_w_conn_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_direct_hs_w_conn_hash, + (trx->trx_direct_hs_w_conn_hash.array.max_element - old_elements) * + trx->trx_direct_hs_w_conn_hash.array.size_of_element); + } + } +#endif + } + + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->conn_kind=%u", conn->conn_kind)); + DBUG_RETURN(conn); + +error: + DBUG_RETURN(NULL); +} + +int spider_udf_direct_sql_get_server( + SPIDER_DIRECT_SQL *direct_sql +) { + MEM_ROOT mem_root; + int error_num, length; + FOREIGN_SERVER *server, server_buf; + DBUG_ENTER("spider_udf_direct_sql_get_server"); + SPD_INIT_ALLOC_ROOT(&mem_root, 65, 0, MYF(MY_WME)); + + if (!(server + = get_server_by_name(&mem_root, direct_sql->server_name, &server_buf))) + { + error_num = ER_FOREIGN_SERVER_DOESNT_EXIST; + goto error_get_server; + } + + if (!direct_sql->tgt_wrapper && server->scheme) + { + direct_sql->tgt_wrapper_length = strlen(server->scheme); + if (!(direct_sql->tgt_wrapper = + spider_create_string(server->scheme, direct_sql->tgt_wrapper_length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_wrapper=%s", direct_sql->tgt_wrapper)); + } + + if (!direct_sql->tgt_host && server->host) + { + direct_sql->tgt_host_length = strlen(server->host); + if (!(direct_sql->tgt_host = + spider_create_string(server->host, direct_sql->tgt_host_length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_host=%s", direct_sql->tgt_host)); + } + + if (direct_sql->tgt_port == -1) + { + direct_sql->tgt_port = server->port; + DBUG_PRINT("info",("spider tgt_port=%ld", direct_sql->tgt_port)); + } + + if (!direct_sql->tgt_socket && server->socket) + { + direct_sql->tgt_socket_length = strlen(server->socket); + if (!(direct_sql->tgt_socket = + spider_create_string(server->socket, direct_sql->tgt_socket_length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_socket=%s", direct_sql->tgt_socket)); + } + + if (!direct_sql->tgt_default_db_name && server->db && + (length = strlen(server->db))) + { + direct_sql->tgt_default_db_name_length = length; + if (!(direct_sql->tgt_default_db_name = + spider_create_string(server->db, length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_default_db_name=%s", + direct_sql->tgt_default_db_name)); + } + + if (!direct_sql->tgt_username && server->username) + { + direct_sql->tgt_username_length = strlen(server->username); + if (!(direct_sql->tgt_username = + spider_create_string(server->username, direct_sql->tgt_username_length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_username=%s", direct_sql->tgt_username)); + } + + if (!direct_sql->tgt_password && server->password) + { + direct_sql->tgt_password_length = strlen(server->password); + if (!(direct_sql->tgt_password = + spider_create_string(server->password, direct_sql->tgt_password_length))) + { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + DBUG_PRINT("info",("spider tgt_password=%s", direct_sql->tgt_password)); + } + + free_root(&mem_root, MYF(0)); + DBUG_RETURN(0); + +error_get_server: + my_error(error_num, MYF(0), direct_sql->server_name); +error: + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); +} + +#define SPIDER_PARAM_STR_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!direct_sql->param_name) \ + { \ + if ((direct_sql->param_name = spider_get_string_between_quote( \ + start_ptr, TRUE))) \ + direct_sql->SPIDER_PARAM_STR_LEN(param_name) = \ + strlen(direct_sql->param_name); \ + else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%s", direct_sql->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_HINT_WITH_MAX(title_name, param_name, check_length, max_size, min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(tmp_ptr + check_length) - 1; \ + DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \ + DBUG_PRINT("info",("spider direct_sql->param_name=%p", \ + direct_sql->param_name)); \ + if (direct_sql->param_name) \ + { \ + if (hint_num < 0 || hint_num >= max_size) \ + { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } else if (direct_sql->param_name[hint_num] != -1) \ + break; \ + char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \ + if (hint_str) \ + { \ + direct_sql->param_name[hint_num] = atoi(hint_str); \ + if (direct_sql->param_name[hint_num] < min_val) \ + direct_sql->param_name[hint_num] = min_val; \ + else if (direct_sql->param_name[hint_num] > max_val) \ + direct_sql->param_name[hint_num] = max_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"[%d]=%d", hint_num, \ + direct_sql->param_name[hint_num])); \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (direct_sql->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + direct_sql->param_name = atoi(tmp_ptr2); \ + if (direct_sql->param_name < min_val) \ + direct_sql->param_name = min_val; \ + else if (direct_sql->param_name > max_val) \ + direct_sql->param_name = max_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", \ + (int) direct_sql->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (direct_sql->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + direct_sql->param_name = atoi(tmp_ptr2); \ + if (direct_sql->param_name < min_val) \ + direct_sql->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", direct_sql->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (direct_sql->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + direct_sql->param_name = \ + my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \ + if (direct_sql->param_name < min_val) \ + direct_sql->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%lld", \ + direct_sql->param_name)); \ + } \ + break; \ + } + +int spider_udf_parse_direct_sql_param( + SPIDER_TRX *trx, + SPIDER_DIRECT_SQL *direct_sql, + const char *param, + int param_length +) { + int error_num = 0, roop_count; + char *param_string = NULL; + char *sprit_ptr[2]; + char *tmp_ptr, *tmp_ptr2, *start_ptr; + int title_length; + DBUG_ENTER("spider_udf_parse_direct_sql_param"); + direct_sql->tgt_port = -1; + direct_sql->tgt_ssl_vsc = -1; + direct_sql->table_loop_mode = -1; + direct_sql->priority = -1; + direct_sql->connect_timeout = -1; + direct_sql->net_read_timeout = -1; + direct_sql->net_write_timeout = -1; + direct_sql->bulk_insert_rows = -1; + direct_sql->connection_channel = -1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + direct_sql->access_mode = -1; +#endif +#if MYSQL_VERSION_ID < 50500 +#else + direct_sql->use_real_table = -1; +#endif + for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) + direct_sql->iop[roop_count] = -1; + + if (param_length == 0) + goto set_default; + DBUG_PRINT("info",("spider create param_string string")); + if ( + !(param_string = spider_create_string( + param, + param_length)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error_alloc_param_string; + } + DBUG_PRINT("info",("spider param_string=%s", param_string)); + + sprit_ptr[0] = param_string; + while (sprit_ptr[0]) + { + if ((sprit_ptr[1] = strchr(sprit_ptr[0], ','))) + { + *sprit_ptr[1] = '\0'; + sprit_ptr[1]++; + } + tmp_ptr = sprit_ptr[0]; + sprit_ptr[0] = sprit_ptr[1]; + while (*tmp_ptr == ' ' || *tmp_ptr == '\r' || + *tmp_ptr == '\n' || *tmp_ptr == '\t') + tmp_ptr++; + + if (*tmp_ptr == '\0') + continue; + + title_length = 0; + start_ptr = tmp_ptr; + while (*start_ptr != ' ' && *start_ptr != '\'' && + *start_ptr != '"' && *start_ptr != '\0' && + *start_ptr != '\r' && *start_ptr != '\n' && + *start_ptr != '\t') + { + title_length++; + start_ptr++; + } + + switch (title_length) + { + case 0: + continue; + case 3: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_INT_WITH_MAX("acm", access_mode, 0, 2); +#endif + SPIDER_PARAM_LONGLONG("bir", bulk_insert_rows, 0); + SPIDER_PARAM_INT_WITH_MAX("cch", connection_channel, 0, 63); + SPIDER_PARAM_INT("cto", connect_timeout, 0); + SPIDER_PARAM_STR("dff", tgt_default_file); + SPIDER_PARAM_STR("dfg", tgt_default_group); + SPIDER_PARAM_LONGLONG("prt", priority, 0); + SPIDER_PARAM_INT("rto", net_read_timeout, 0); + SPIDER_PARAM_STR("sca", tgt_ssl_ca); + SPIDER_PARAM_STR("sch", tgt_ssl_cipher); + SPIDER_PARAM_STR("scp", tgt_ssl_capath); + SPIDER_PARAM_STR("scr", tgt_ssl_cert); + SPIDER_PARAM_STR("sky", tgt_ssl_key); + SPIDER_PARAM_STR("srv", server_name); + SPIDER_PARAM_INT_WITH_MAX("svc", tgt_ssl_vsc, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("tlm", table_loop_mode, 0, 2); +#if MYSQL_VERSION_ID < 50500 +#else + SPIDER_PARAM_INT_WITH_MAX("urt", use_real_table, 0, 1); +#endif + SPIDER_PARAM_INT("wto", net_write_timeout, 0); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 4: + SPIDER_PARAM_STR("host", tgt_host); + SPIDER_PARAM_STR("user", tgt_username); + SPIDER_PARAM_INT_WITH_MAX("port", tgt_port, 0, 65535); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 6: + SPIDER_PARAM_STR("server", server_name); + SPIDER_PARAM_STR("socket", tgt_socket); + SPIDER_PARAM_HINT_WITH_MAX("iop", iop, 3, direct_sql->table_count, 0, 2); + SPIDER_PARAM_STR("ssl_ca", tgt_ssl_ca); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 7: + SPIDER_PARAM_STR("wrapper", tgt_wrapper); + SPIDER_PARAM_STR("ssl_key", tgt_ssl_key); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 8: + SPIDER_PARAM_STR("database", tgt_default_db_name); + SPIDER_PARAM_STR("password", tgt_password); + SPIDER_PARAM_LONGLONG("priority", priority, 0); + SPIDER_PARAM_STR("ssl_cert", tgt_ssl_cert); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 10: + SPIDER_PARAM_STR("ssl_cipher", tgt_ssl_cipher); + SPIDER_PARAM_STR("ssl_capath", tgt_ssl_capath); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 11: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_INT_WITH_MAX("access_mode", access_mode, 0, 2); +#endif + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 12: + SPIDER_PARAM_STR("default_file", tgt_default_file); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 13: + SPIDER_PARAM_STR("default_group", tgt_default_group); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 14: +#if MYSQL_VERSION_ID < 50500 +#else + SPIDER_PARAM_INT_WITH_MAX("use_real_table", use_real_table, 0, 1); +#endif + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 15: + SPIDER_PARAM_INT_WITH_MAX("table_loop_mode", table_loop_mode, 0, 2); + SPIDER_PARAM_INT("connect_timeout", connect_timeout, 0); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 16: + SPIDER_PARAM_LONGLONG("bulk_insert_rows", bulk_insert_rows, 1); + SPIDER_PARAM_INT("net_read_timeout", net_read_timeout, 0); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 17: + SPIDER_PARAM_INT("net_write_timeout", net_write_timeout, 0); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 18: + SPIDER_PARAM_INT_WITH_MAX( + "connection_channel", connection_channel, 0, 63); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + case 22: + SPIDER_PARAM_INT_WITH_MAX("ssl_verify_server_cert", tgt_ssl_vsc, 0, 1); + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + default: + error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), tmp_ptr); + goto error; + } + } + +set_default: + if ((error_num = spider_udf_set_direct_sql_param_default( + trx, + direct_sql + ))) + goto error; + + if (param_string) + { + spider_free(spider_current_trx, param_string, MYF(0)); + } + DBUG_RETURN(0); + +error: + if (param_string) + { + spider_free(spider_current_trx, param_string, MYF(0)); + } +error_alloc_param_string: + DBUG_RETURN(error_num); +} + +int spider_udf_set_direct_sql_param_default( + SPIDER_TRX *trx, + SPIDER_DIRECT_SQL *direct_sql +) { + int error_num, roop_count; + DBUG_ENTER("spider_udf_set_direct_sql_param_default"); + if (direct_sql->server_name) + { + if ((error_num = spider_udf_direct_sql_get_server(direct_sql))) + DBUG_RETURN(error_num); + } + + if (!direct_sql->tgt_default_db_name) + { + DBUG_PRINT("info",("spider create default tgt_default_db_name")); + direct_sql->tgt_default_db_name_length = trx->thd->db_length; + if ( + !(direct_sql->tgt_default_db_name = spider_create_string( + trx->thd->db, + direct_sql->tgt_default_db_name_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!direct_sql->tgt_wrapper) + { + DBUG_PRINT("info",("spider create default tgt_wrapper")); + direct_sql->tgt_wrapper_length = SPIDER_DB_WRAPPER_LEN; + if ( + !(direct_sql->tgt_wrapper = spider_create_string( + SPIDER_DB_WRAPPER_STR, + direct_sql->tgt_wrapper_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!direct_sql->tgt_host) + { + DBUG_PRINT("info",("spider create default tgt_host")); + direct_sql->tgt_host_length = strlen(my_localhost); + if ( + !(direct_sql->tgt_host = spider_create_string( + my_localhost, + direct_sql->tgt_host_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if ( + !direct_sql->tgt_default_file && + direct_sql->tgt_default_group && + (*spd_defaults_file || *spd_defaults_extra_file) + ) { + DBUG_PRINT("info",("spider create default tgt_default_file")); + if (*spd_defaults_extra_file) + { + direct_sql->tgt_default_file_length = strlen(*spd_defaults_extra_file); + if ( + !(direct_sql->tgt_default_file = spider_create_string( + *spd_defaults_extra_file, + direct_sql->tgt_default_file_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + direct_sql->tgt_default_file_length = strlen(*spd_defaults_file); + if ( + !(direct_sql->tgt_default_file = spider_create_string( + *spd_defaults_file, + direct_sql->tgt_default_file_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == -1) + direct_sql->access_mode = 0; +#endif + + if (direct_sql->tgt_port == -1) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (direct_sql->access_mode == 1) + direct_sql->tgt_port = 9998; + else if (direct_sql->access_mode == 2) + direct_sql->tgt_port = 9999; + else +#endif + direct_sql->tgt_port = MYSQL_PORT; + } + else if (direct_sql->tgt_port < 0) + direct_sql->tgt_port = 0; + else if (direct_sql->tgt_port > 65535) + direct_sql->tgt_port = 65535; + + if (direct_sql->tgt_ssl_vsc == -1) + direct_sql->tgt_ssl_vsc = 0; + + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + direct_sql->access_mode == 0 && +#endif + !direct_sql->tgt_socket && + !strcmp(direct_sql->tgt_host, my_localhost) + ) { + DBUG_PRINT("info",("spider create default tgt_socket")); + direct_sql->tgt_socket_length = strlen((char *) MYSQL_UNIX_ADDR); + if ( + !(direct_sql->tgt_socket = spider_create_string( + (char *) MYSQL_UNIX_ADDR, + direct_sql->tgt_socket_length)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (direct_sql->table_loop_mode == -1) + direct_sql->table_loop_mode = 0; + if (direct_sql->priority == -1) + direct_sql->priority = 1000000; + if (direct_sql->connect_timeout == -1) + direct_sql->connect_timeout = 6; + if (direct_sql->net_read_timeout == -1) + direct_sql->net_read_timeout = 600; + if (direct_sql->net_write_timeout == -1) + direct_sql->net_write_timeout = 600; + if (direct_sql->bulk_insert_rows == -1) + direct_sql->bulk_insert_rows = 3000; + if (direct_sql->connection_channel == -1) + direct_sql->connection_channel = 0; +#if MYSQL_VERSION_ID < 50500 +#else + if (direct_sql->use_real_table == -1) + direct_sql->use_real_table = 0; +#endif + for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) + { + if (direct_sql->iop[roop_count] == -1) + direct_sql->iop[roop_count] = 0; + } + DBUG_RETURN(0); +} + +void spider_udf_free_direct_sql_alloc( + SPIDER_DIRECT_SQL *direct_sql, + my_bool bg +) { + SPIDER_BG_DIRECT_SQL *bg_direct_sql; + DBUG_ENTER("spider_udf_free_direct_sql_alloc"); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (bg) + { + pthread_mutex_lock(direct_sql->bg_mutex); + bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) direct_sql->parent; + if (bg_direct_sql->direct_sql == direct_sql) + bg_direct_sql->direct_sql = direct_sql->next; + if (direct_sql->next) + direct_sql->next->prev = direct_sql->prev; + if (direct_sql->prev) + direct_sql->prev->next = direct_sql->next; + pthread_cond_signal(direct_sql->bg_cond); + pthread_mutex_unlock(direct_sql->bg_mutex); + } +#endif +#if MYSQL_VERSION_ID < 50500 +#else + if (direct_sql->real_table_used && direct_sql->open_tables_thd) + { + spider_sys_close_table(direct_sql->open_tables_thd, + &direct_sql->open_tables_backup); + } +#endif + if (direct_sql->server_name) + { + spider_free(spider_current_trx, direct_sql->server_name, MYF(0)); + } + if (direct_sql->tgt_default_db_name) + { + spider_free(spider_current_trx, direct_sql->tgt_default_db_name, MYF(0)); + } + if (direct_sql->tgt_host) + { + spider_free(spider_current_trx, direct_sql->tgt_host, MYF(0)); + } + if (direct_sql->tgt_username) + { + spider_free(spider_current_trx, direct_sql->tgt_username, MYF(0)); + } + if (direct_sql->tgt_password) + { + spider_free(spider_current_trx, direct_sql->tgt_password, MYF(0)); + } + if (direct_sql->tgt_socket) + { + spider_free(spider_current_trx, direct_sql->tgt_socket, MYF(0)); + } + if (direct_sql->tgt_wrapper) + { + spider_free(spider_current_trx, direct_sql->tgt_wrapper, MYF(0)); + } + if (direct_sql->tgt_ssl_ca) + { + spider_free(spider_current_trx, direct_sql->tgt_ssl_ca, MYF(0)); + } + if (direct_sql->tgt_ssl_capath) + { + spider_free(spider_current_trx, direct_sql->tgt_ssl_capath, MYF(0)); + } + if (direct_sql->tgt_ssl_cert) + { + spider_free(spider_current_trx, direct_sql->tgt_ssl_cert, MYF(0)); + } + if (direct_sql->tgt_ssl_cipher) + { + spider_free(spider_current_trx, direct_sql->tgt_ssl_cipher, MYF(0)); + } + if (direct_sql->tgt_ssl_key) + { + spider_free(spider_current_trx, direct_sql->tgt_ssl_key, MYF(0)); + } + if (direct_sql->tgt_default_file) + { + spider_free(spider_current_trx, direct_sql->tgt_default_file, MYF(0)); + } + if (direct_sql->tgt_default_group) + { + spider_free(spider_current_trx, direct_sql->tgt_default_group, MYF(0)); + } + if (direct_sql->conn_key) + { + spider_free(spider_current_trx, direct_sql->conn_key, MYF(0)); + } + if (direct_sql->db_names) + { + spider_free(spider_current_trx, direct_sql->db_names, MYF(0)); + } + spider_free(spider_current_trx, direct_sql, MYF(0)); + DBUG_VOID_RETURN; +} + +long long spider_direct_sql_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error, + my_bool bg +) { + int error_num, roop_count; + SPIDER_DIRECT_SQL *direct_sql = NULL, *tmp_direct_sql; + THD *thd = current_thd; + SPIDER_TRX *trx; + SPIDER_CONN *conn; + char *sql; + TABLE_LIST table_list; + SPIDER_BG_DIRECT_SQL *bg_direct_sql; +#if MYSQL_VERSION_ID < 50500 +#else + TABLE_LIST *real_table_list_last = NULL; + uint use_real_table = 0; +#endif + DBUG_ENTER("spider_direct_sql_body"); + if (!(direct_sql = (SPIDER_DIRECT_SQL *) + spider_bulk_malloc(spider_current_trx, 34, MYF(MY_WME | MY_ZEROFILL), + &direct_sql, sizeof(SPIDER_DIRECT_SQL), + &sql, sizeof(char) * args->lengths[0], + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (bg) + { + bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) initid->ptr; + pthread_mutex_lock(&bg_direct_sql->bg_mutex); + tmp_direct_sql = (SPIDER_DIRECT_SQL *) bg_direct_sql->direct_sql; + bg_direct_sql->direct_sql = direct_sql; + if (tmp_direct_sql) + { + tmp_direct_sql->prev = direct_sql; + direct_sql->next = tmp_direct_sql; + } + pthread_mutex_unlock(&bg_direct_sql->bg_mutex); + direct_sql->bg_mutex = &bg_direct_sql->bg_mutex; + direct_sql->bg_cond = &bg_direct_sql->bg_cond; + direct_sql->parent = bg_direct_sql; + bg_direct_sql->called_cnt++; + } +#endif + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + direct_sql->trx = trx; + + if (args->args[1]) + { + if (spider_udf_direct_sql_create_table_list( + direct_sql, + args->args[1], + args->lengths[1] + )) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } else { + if (spider_udf_direct_sql_create_table_list( + direct_sql, + (char *) "", + 0 + )) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } + if (args->args[2]) + { + if (spider_udf_parse_direct_sql_param( + trx, + direct_sql, + args->args[2], + args->lengths[2] + )) { + goto error; + } + } else { + if (spider_udf_parse_direct_sql_param( + trx, + direct_sql, + "", + 0 + )) { + goto error; + } + } +#if MYSQL_VERSION_ID < 50500 +#else + use_real_table = spider_param_udf_ds_use_real_table(thd, + direct_sql->use_real_table); +#endif + for (roop_count = 0; roop_count < direct_sql->table_count; roop_count++) + { + table_list.db = direct_sql->db_names[roop_count]; + table_list.table_name = direct_sql->table_names[roop_count]; + if (!(direct_sql->tables[roop_count] = + find_temporary_table(thd, &table_list))) + { +#if MYSQL_VERSION_ID < 50500 +#else + if (!use_real_table) + { +#endif + my_printf_error(ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM, + ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR, + MYF(0), table_list.db, table_list.table_name); + goto error; +#if MYSQL_VERSION_ID < 50500 +#else + } + TABLE_LIST *tables = &direct_sql->table_list[roop_count]; + tables->init_one_table(table_list.db, strlen(table_list.db), + table_list.table_name, strlen(table_list.table_name), + table_list.table_name, TL_WRITE); + tables->mdl_request.init(MDL_key::TABLE, table_list.db, + table_list.table_name, MDL_SHARED_WRITE, MDL_TRANSACTION); + if (!direct_sql->table_list_first) + { + direct_sql->table_list_first = tables; + } else { + real_table_list_last->next_global = tables; + } + real_table_list_last = tables; + spider_set_bit(direct_sql->real_table_bitmap, roop_count); + direct_sql->real_table_used = TRUE; +#endif + } + } + if (spider_udf_direct_sql_create_conn_key(direct_sql)) + { + goto error; + } + if (!(conn = spider_udf_direct_sql_get_conn(direct_sql, trx, &error_num))) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + conn->error_mode = 0; + direct_sql->conn = conn; + if (spider_db_udf_check_and_set_set_names(trx)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + if (args->args[0]) + { + direct_sql->sql_length = args->lengths[0]; + memcpy(sql, args->args[0], direct_sql->sql_length); + } else + direct_sql->sql_length = 0; + direct_sql->sql = sql; + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (bg) + { + if (spider_udf_bg_direct_sql(direct_sql)) + { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } else { +#endif + if (conn->bg_init) + pthread_mutex_lock(&conn->bg_conn_mutex); + if (spider_db_udf_direct_sql(direct_sql)) + { + if (conn->bg_init) + pthread_mutex_unlock(&conn->bg_conn_mutex); + if (direct_sql->modified_non_trans_table) + thd->transaction.stmt.modified_non_trans_table = TRUE; + goto error; + } + if (conn->bg_init) + pthread_mutex_unlock(&conn->bg_conn_mutex); + if (direct_sql->modified_non_trans_table) + thd->transaction.stmt.modified_non_trans_table = TRUE; +#ifndef WITHOUT_SPIDER_BG_SEARCH + } + if (!bg) + { +#endif + spider_udf_free_direct_sql_alloc(direct_sql, FALSE); +#ifndef WITHOUT_SPIDER_BG_SEARCH + } +#endif + DBUG_RETURN(1); + +error: + if (direct_sql) + spider_udf_free_direct_sql_alloc(direct_sql, bg); + *error = 1; + DBUG_RETURN(0); +} + +my_bool spider_direct_sql_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message, + my_bool bg +) { + SPIDER_BG_DIRECT_SQL *bg_direct_sql; + DBUG_ENTER("spider_direct_sql_init_body"); + if (args->arg_count != 3) + { + strcpy(message, "spider_(bg)_direct_sql() requires 3 arguments"); + goto error; + } + if ( + args->arg_type[0] != STRING_RESULT || + args->arg_type[1] != STRING_RESULT || + args->arg_type[2] != STRING_RESULT + ) { + strcpy(message, "spider_(bg)_direct_sql() requires string arguments"); + goto error; + } +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (bg) + { + if (!(bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) + spider_malloc(spider_current_trx, 10, sizeof(SPIDER_BG_DIRECT_SQL), + MYF(MY_WME | MY_ZEROFILL))) + ) { + strcpy(message, "spider_bg_direct_sql() out of memory"); + goto error; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_bg_direct_sql, + &bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + strcpy(message, "spider_bg_direct_sql() out of memory"); + goto error_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&bg_direct_sql->bg_cond, NULL)) +#else + if (mysql_cond_init(spd_key_cond_bg_direct_sql, + &bg_direct_sql->bg_cond, NULL)) +#endif + { + strcpy(message, "spider_bg_direct_sql() out of memory"); + goto error_cond_init; + } + initid->ptr = (char *) bg_direct_sql; + } +#endif + DBUG_RETURN(FALSE); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +error_cond_init: + pthread_mutex_destroy(&bg_direct_sql->bg_mutex); +error_mutex_init: + spider_free(spider_current_trx, bg_direct_sql, MYF(0)); +#endif +error: + DBUG_RETURN(TRUE); +} + +void spider_direct_sql_deinit_body( + UDF_INIT *initid +) { + SPIDER_BG_DIRECT_SQL *bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) initid->ptr; + DBUG_ENTER("spider_direct_sql_deinit_body"); + if (bg_direct_sql) + { + pthread_cond_destroy(&bg_direct_sql->bg_cond); + pthread_mutex_destroy(&bg_direct_sql->bg_mutex); + spider_free(spider_current_trx, bg_direct_sql, MYF(0)); + } + DBUG_VOID_RETURN; +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +void spider_direct_sql_bg_start( + UDF_INIT *initid +) { + SPIDER_BG_DIRECT_SQL *bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) initid->ptr; + DBUG_ENTER("spider_direct_sql_bg_start"); + bg_direct_sql->called_cnt = 0; + bg_direct_sql->bg_error = 0; + DBUG_VOID_RETURN; +} + +long long spider_direct_sql_bg_end( + UDF_INIT *initid +) { + THD *thd = current_thd; + SPIDER_BG_DIRECT_SQL *bg_direct_sql = (SPIDER_BG_DIRECT_SQL *) initid->ptr; + DBUG_ENTER("spider_direct_sql_bg_end"); + pthread_mutex_lock(&bg_direct_sql->bg_mutex); + while (bg_direct_sql->direct_sql) + pthread_cond_wait(&bg_direct_sql->bg_cond, &bg_direct_sql->bg_mutex); + pthread_mutex_unlock(&bg_direct_sql->bg_mutex); + if (bg_direct_sql->modified_non_trans_table) + thd->transaction.stmt.modified_non_trans_table = TRUE; + if (bg_direct_sql->bg_error) + { + my_message(bg_direct_sql->bg_error, bg_direct_sql->bg_error_msg, MYF(0)); + DBUG_RETURN(0); + } + DBUG_RETURN(bg_direct_sql->called_cnt); +} + +int spider_udf_bg_direct_sql( + SPIDER_DIRECT_SQL *direct_sql +) { + int error_num; + SPIDER_CONN *conn = direct_sql->conn; + DBUG_ENTER("spider_udf_bg_direct_sql"); + if ((error_num = spider_create_conn_thread(conn))) + DBUG_RETURN(error_num); + if (!pthread_mutex_trylock(&conn->bg_conn_mutex)) + { + DBUG_PRINT("info",("spider get bg_conn_mutex")); + conn->bg_target = direct_sql; + conn->bg_direct_sql = TRUE; + conn->bg_caller_sync_wait = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_sync_wait = FALSE; + } else { + DBUG_PRINT("info",("spider get put job stack")); + bool bg_get_job_stack = FALSE; + pthread_mutex_lock(&conn->bg_job_stack_mutex); + uint old_elements = conn->bg_job_stack.max_element; + if (insert_dynamic(&conn->bg_job_stack, (uchar *) &direct_sql)) + { + pthread_mutex_unlock(&conn->bg_job_stack_mutex); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (conn->bg_job_stack.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + conn->bg_job_stack, + (conn->bg_job_stack.max_element - old_elements) * + conn->bg_job_stack.size_of_element); + } + if (!conn->bg_get_job_stack_off) + bg_get_job_stack = TRUE; + pthread_mutex_unlock(&conn->bg_job_stack_mutex); + if (bg_get_job_stack) + { + DBUG_PRINT("info",("spider get bg_conn_mutex")); + pthread_mutex_lock(&conn->bg_conn_mutex); + conn->bg_target = NULL; + conn->bg_get_job_stack = TRUE; + conn->bg_direct_sql = TRUE; + conn->bg_caller_sync_wait = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + pthread_cond_signal(&conn->bg_conn_cond); + pthread_mutex_unlock(&conn->bg_conn_mutex); + pthread_cond_wait(&conn->bg_conn_sync_cond, &conn->bg_conn_sync_mutex); + pthread_mutex_unlock(&conn->bg_conn_sync_mutex); + conn->bg_caller_sync_wait = FALSE; + } + } + DBUG_RETURN(0); +} +#endif diff --git a/storage/spider/spd_direct_sql.h b/storage/spider/spd_direct_sql.h new file mode 100644 index 00000000000..f20e9de6373 --- /dev/null +++ b/storage/spider/spd_direct_sql.h @@ -0,0 +1,67 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +uint spider_udf_calc_hash( + char *key, + uint mod +); + +int spider_udf_direct_sql_create_table_list( + SPIDER_DIRECT_SQL *direct_sql, + char *table_name_list, + uint table_name_list_length +); + +int spider_udf_direct_sql_create_conn_key( + SPIDER_DIRECT_SQL *direct_sql +); + +SPIDER_CONN *spider_udf_direct_sql_create_conn( + const SPIDER_DIRECT_SQL *direct_sql, + int *error_num +); + +SPIDER_CONN *spider_udf_direct_sql_get_conn( + const SPIDER_DIRECT_SQL *direct_sql, + SPIDER_TRX *trx, + int *error_num +); + +int spider_udf_direct_sql_get_server( + SPIDER_DIRECT_SQL *direct_sql +); + +int spider_udf_parse_direct_sql_param( + SPIDER_TRX *trx, + SPIDER_DIRECT_SQL *direct_sql, + const char *param, + int param_length +); + +int spider_udf_set_direct_sql_param_default( + SPIDER_TRX *trx, + SPIDER_DIRECT_SQL *direct_sql +); + +void spider_udf_free_direct_sql_alloc( + SPIDER_DIRECT_SQL *direct_sql, + my_bool bg +); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_udf_bg_direct_sql( + SPIDER_DIRECT_SQL *direct_sql +); +#endif diff --git a/storage/spider/spd_err.h b/storage/spider/spd_err.h new file mode 100644 index 00000000000..c644d6ebca5 --- /dev/null +++ b/storage/spider/spd_err.h @@ -0,0 +1,119 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define ER_SPIDER_INVALID_CONNECT_INFO_NUM 12501 +#define ER_SPIDER_INVALID_CONNECT_INFO_STR "The connect info '%-.64s' is invalid" +#define ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM 12502 +#define ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR "The connect info '%-.64s' for %s is too long" +#define ER_SPIDER_INVALID_UDF_PARAM_NUM 12503 +#define ER_SPIDER_INVALID_UDF_PARAM_STR "The UDF parameter '%-.64s' is invalid" +#define ER_SPIDER_DIFFERENT_LINK_COUNT_NUM 12504 +#define ER_SPIDER_DIFFERENT_LINK_COUNT_STR "Different multiple table link parameter's count" +#define ER_SPIDER_UDF_PING_TABLE_PARAM_TOO_LONG_NUM 12505 +#define ER_SPIDER_UDF_PING_TABLE_PARAM_TOO_LONG_STR "Server name or table name are too long" +#define ER_SPIDER_UDF_PING_TABLE_PARAM_REQIRED_NUM 12506 +#define ER_SPIDER_UDF_PING_TABLE_PARAM_REQIRED_STR "Server name or table name are required" +#define ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM 12507 +#define ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR "This UDF can't execute if other tables are opened" +#define ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM "This UDF can't execute if other tables are opened '%s'=%lld" +#define ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR "This UDF can't execute if other tables are opened '%s'=%p" +#define ER_SPIDER_UDF_PING_TABLE_NO_SERVER_ID_NUM 12508 +#define ER_SPIDER_UDF_PING_TABLE_NO_SERVER_ID_STR "Current server_id is not exist" +#define ER_SPIDER_UDF_PING_TABLE_DIFFERENT_MON_NUM 12509 +#define ER_SPIDER_UDF_PING_TABLE_DIFFERENT_MON_STR "Monitor count is different" +#define ER_SPIDER_LINK_MON_OK_NUM 12510 +#define ER_SPIDER_LINK_MON_OK_STR "Table '%s.%s' get a problem, but mon is OK" +#define ER_SPIDER_LINK_MON_NG_NUM 12511 +#define ER_SPIDER_LINK_MON_NG_STR "Table '%s.%s' get a problem" +#define ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM 12512 +#define ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR "Can not judge by enough monitor for table '%s.%s'" +#define ER_SPIDER_LINK_MON_DRAW_NUM 12513 +#define ER_SPIDER_LINK_MON_DRAW_STR "Can not judge status for table '%s.%s'" +#define ER_SPIDER_ALL_LINKS_FAILED_NUM 12514 +#define ER_SPIDER_ALL_LINKS_FAILED_STR "All links of '%s.%s' are failed" +#define ER_SPIDER_TMP_TABLE_MON_NUM 12515 +#define ER_SPIDER_TMP_TABLE_MON_STR "Can't use monitor by temporary table" +#define ER_SPIDER_MON_AT_ALTER_TABLE_NUM 12516 +#define ER_SPIDER_MON_AT_ALTER_TABLE_STR "Got an error in alter or drop table" +#define ER_SPIDER_BLANK_UDF_ARGUMENT_NUM 12517 +#define ER_SPIDER_BLANK_UDF_ARGUMENT_STR "The UDF no.%d argument can't be blank" +#define ER_SPIDER_READ_ONLY_NUM 12518 +#define ER_SPIDER_READ_ONLY_STR "Table '%s.%s' is read only" +#define ER_SPIDER_LINK_IS_FAILOVER_NUM 12519 +#define ER_SPIDER_LINK_IS_FAILOVER_STR "A link is fail-overed" +#define ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_NUM 12520 +#define ER_SPIDER_AUTOINC_VAL_IS_DIFFERENT_STR "Binlog's auto-inc value is probably different from linked table's auto-inc value" +#define ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM 12521 +#define ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR "Can't use wrapper '%s' for SQL connection" +#define ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM 12522 +#define ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_STR "Can't use wrapper '%s' for NOSQL connection" +#define ER_SPIDER_REQUEST_KEY_NUM 12523 +#define ER_SPIDER_REQUEST_KEY_STR "Request key not found" + +#define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_NUM 12601 +#define ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_STR "Can't use both spider_use_consistent_snapshot = 1 and spider_internal_xa = 1" +#define ER_SPIDER_XA_LOCKED_NUM 12602 +#define ER_SPIDER_XA_LOCKED_STR "This xid is now locked" +#define ER_SPIDER_XA_NOT_PREPARED_NUM 12603 +#define ER_SPIDER_XA_NOT_PREPARED_STR "This xid is not prepared" +#define ER_SPIDER_XA_PREPARED_NUM 12604 +#define ER_SPIDER_XA_PREPARED_STR "This xid is prepared" +#define ER_SPIDER_XA_EXISTS_NUM 12605 +#define ER_SPIDER_XA_EXISTS_STR "This xid is already exist" +#define ER_SPIDER_XA_MEMBER_EXISTS_NUM 12606 +#define ER_SPIDER_XA_MEMBER_EXISTS_STR "This xid member is already exist" +#define ER_SPIDER_XA_NOT_EXISTS_NUM 12607 +#define ER_SPIDER_XA_NOT_EXISTS_STR "This xid is not exist" +#define ER_SPIDER_XA_MEMBER_NOT_EXISTS_NUM 12608 +#define ER_SPIDER_XA_MEMBER_NOT_EXISTS_STR "This xid member is not exist" +#define ER_SPIDER_SYS_TABLE_VERSION_NUM 12609 +#define ER_SPIDER_SYS_TABLE_VERSION_STR "System table %s is different version" +#define ER_SPIDER_WRONG_CHARACTER_IN_NAME_NUM 12611 +#define ER_SPIDER_WRONG_CHARACTER_IN_NAME_STR "Wrong character in name string" +#define ER_SPIDER_LOW_MEM_READ_PREV_NUM 12621 +#define ER_SPIDER_LOW_MEM_READ_PREV_STR "Can't use this operation at low mem read mode" +#define ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM 12622 +#define ER_SPIDER_ALTER_BEFORE_UNLOCK_STR "Can't use this operation before executing 'unlock tables'" +#define ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM 12701 +#define ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR "Remote MySQL server has gone away" +#define ER_SPIDER_REMOTE_SERVER_GONE_AWAY_LEN (sizeof(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR) - 1) +#define ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM 12702 +#define ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR "Remote table '%s.%s' is not found" +#define ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM 12703 +#define ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR "Temporary table '%s.%s' is not found" +#define ER_SPIDER_UDF_COPY_TABLE_SRC_NOT_FOUND_NUM 12704 +#define ER_SPIDER_UDF_COPY_TABLE_SRC_NOT_FOUND_STR "Source table is not found" +#define ER_SPIDER_UDF_COPY_TABLE_DST_NOT_FOUND_NUM 12705 +#define ER_SPIDER_UDF_COPY_TABLE_DST_NOT_FOUND_STR "Destination table is not found" +#define ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_NUM 12706 +#define ER_SPIDER_UDF_COPY_TABLE_SRC_NG_STATUS_STR "Source table is NG status" +#define ER_SPIDER_UDF_COPY_TABLE_DST_NG_STATUS_NUM 12707 +#define ER_SPIDER_UDF_COPY_TABLE_DST_NG_STATUS_STR "Destination table is NG status" +#define ER_SPIDER_UDF_CANT_OPEN_TABLE_NUM 12708 +#define ER_SPIDER_UDF_CANT_OPEN_TABLE_STR "Can't open table %s.%s" +#define ER_SPIDER_UDF_COPY_TABLE_NEED_PK_NUM 12709 +#define ER_SPIDER_UDF_COPY_TABLE_NEED_PK_STR "Table %s.%s needs PK for copying" +#define ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM 12710 +#define ER_SPIDER_INVALID_REMOTE_TABLE_INFO_STR "Invalid information from remote table '%s.%s'" +#define ER_SPIDER_HS_STR "Error from HS %d %s" +#define ER_SPIDER_HS_NUM 12711 +#define ER_SPIDER_ORACLE_STR "Error from Oracle %d %d %s" +#define ER_SPIDER_ORACLE_NUM 12712 +#define ER_SPIDER_ORACLE_ERR "Oracle error" +#define ER_SPIDER_COND_SKIP_NUM 12801 + +#define ER_SPIDER_UNKNOWN_NUM 12500 +#define ER_SPIDER_UNKNOWN_STR "unknown" +#define ER_SPIDER_UNKNOWN_LEN (sizeof(ER_SPIDER_UNKNOWN_STR) - 1) diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc new file mode 100644 index 00000000000..c32745dae98 --- /dev/null +++ b/storage/spider/spd_i_s.cc @@ -0,0 +1,148 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_show.h" +#endif +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_table.h" + +extern pthread_mutex_t spider_mem_calc_mutex; + +extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; +extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; +extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; + +static struct st_mysql_storage_engine spider_i_s_info = +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + +static ST_FIELD_INFO spider_i_s_alloc_mem_fields_info[] = +{ + {"ID", 10, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "id", SKIP_OPEN_TABLE}, + {"FUNC_NAME", 64, MYSQL_TYPE_STRING, 0, + MY_I_S_MAYBE_NULL, "func_name", SKIP_OPEN_TABLE}, + {"FILE_NAME", 64, MYSQL_TYPE_STRING, 0, + MY_I_S_MAYBE_NULL, "file_name", SKIP_OPEN_TABLE}, + {"LINE_NO", 10, MYSQL_TYPE_LONG, 0, + MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "line_no", SKIP_OPEN_TABLE}, + {"TOTAL_ALLOC_MEM", 20, MYSQL_TYPE_LONGLONG, 0, + MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "total_alloc_mem", SKIP_OPEN_TABLE}, + {"CURRENT_ALLOC_MEM", 20, MYSQL_TYPE_LONGLONG, 0, + MY_I_S_MAYBE_NULL, "current_alloc_mem", SKIP_OPEN_TABLE}, + {"ALLOC_MEM_COUNT", 20, MYSQL_TYPE_LONGLONG, 0, + MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "alloc_mem_count", SKIP_OPEN_TABLE}, + {"FREE_MEM_COUNT", 20, MYSQL_TYPE_LONGLONG, 0, + MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL, "free_mem_count", SKIP_OPEN_TABLE}, + {NULL, 0, MYSQL_TYPE_STRING, 0, 0, NULL, 0} +}; + +static int spider_i_s_alloc_mem_fill_table( + THD *thd, + TABLE_LIST *tables, + COND *cond +) { + uint roop_count; + TABLE *table = tables->table; + DBUG_ENTER("spider_i_s_alloc_mem_fill_table"); + for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++) + { + table->field[0]->store(roop_count, TRUE); + if (spider_alloc_func_name[roop_count]) + { + table->field[1]->set_notnull(); + table->field[2]->set_notnull(); + table->field[3]->set_notnull(); + table->field[4]->set_notnull(); + table->field[5]->set_notnull(); + table->field[6]->set_notnull(); + table->field[7]->set_notnull(); + table->field[1]->store(spider_alloc_func_name[roop_count], + strlen(spider_alloc_func_name[roop_count]), system_charset_info); + table->field[2]->store(spider_alloc_file_name[roop_count], + strlen(spider_alloc_file_name[roop_count]), system_charset_info); + table->field[3]->store(spider_alloc_line_no[roop_count], TRUE); + pthread_mutex_lock(&spider_mem_calc_mutex); + table->field[4]->store(spider_total_alloc_mem[roop_count], TRUE); + table->field[5]->store(spider_current_alloc_mem[roop_count], FALSE); + table->field[6]->store(spider_alloc_mem_count[roop_count], TRUE); + table->field[7]->store(spider_free_mem_count[roop_count], TRUE); + pthread_mutex_unlock(&spider_mem_calc_mutex); + } else { + table->field[1]->set_null(); + table->field[2]->set_null(); + table->field[3]->set_null(); + table->field[4]->set_null(); + table->field[5]->set_null(); + table->field[6]->set_null(); + table->field[7]->set_null(); + } + if (schema_table_store_record(thd, table)) + { + DBUG_RETURN(1); + } + } + DBUG_RETURN(0); +} + +static int spider_i_s_alloc_mem_init( + void *p +) { + ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p; + DBUG_ENTER("spider_i_s_alloc_mem_init"); + schema->fields_info = spider_i_s_alloc_mem_fields_info; + schema->fill_table = spider_i_s_alloc_mem_fill_table; + schema->idx_field1 = 0; + DBUG_RETURN(0); +} + +static int spider_i_s_alloc_mem_deinit( + void *p +) { + DBUG_ENTER("spider_i_s_alloc_mem_deinit"); + DBUG_RETURN(0); +} + +struct st_mysql_plugin spider_i_s_alloc_mem = +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &spider_i_s_info, + "SPIDER_ALLOC_MEM", + "Kentoku Shiba", + "Spider memory allocating viewer", + PLUGIN_LICENSE_GPL, + spider_i_s_alloc_mem_init, + spider_i_s_alloc_mem_deinit, + 0x0001, + NULL, + NULL, + NULL, +#if MYSQL_VERSION_ID >= 50600 + 0, +#endif +}; diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h new file mode 100644 index 00000000000..4340339ac57 --- /dev/null +++ b/storage/spider/spd_include.h @@ -0,0 +1,1123 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#if MYSQL_VERSION_ID < 50500 +#else +#define my_free(A,B) my_free(A) +#ifdef pthread_mutex_t +#undef pthread_mutex_t +#endif +#define pthread_mutex_t mysql_mutex_t +#ifdef pthread_mutex_lock +#undef pthread_mutex_lock +#endif +#define pthread_mutex_lock mysql_mutex_lock +#ifdef pthread_mutex_trylock +#undef pthread_mutex_trylock +#endif +#define pthread_mutex_trylock mysql_mutex_trylock +#ifdef pthread_mutex_unlock +#undef pthread_mutex_unlock +#endif +#define pthread_mutex_unlock mysql_mutex_unlock +#ifdef pthread_mutex_destroy +#undef pthread_mutex_destroy +#endif +#define pthread_mutex_destroy mysql_mutex_destroy +#ifdef pthread_cond_t +#undef pthread_cond_t +#endif +#define pthread_cond_t mysql_cond_t +#ifdef pthread_cond_wait +#undef pthread_cond_wait +#endif +#define pthread_cond_wait mysql_cond_wait +#ifdef pthread_cond_signal +#undef pthread_cond_signal +#endif +#define pthread_cond_signal mysql_cond_signal +#ifdef pthread_cond_broadcast +#undef pthread_cond_broadcast +#endif +#define pthread_cond_broadcast mysql_cond_broadcast +#ifdef pthread_cond_destroy +#undef pthread_cond_destroy +#endif +#define pthread_cond_destroy mysql_cond_destroy +#define my_sprintf(A,B) sprintf B +#endif + +#if MYSQL_VERSION_ID >= 50500 +#define SPIDER_HAS_HASH_VALUE_TYPE +#endif + +#define spider_bitmap_size(A) ((A + 7) / 8) +#define spider_set_bit(BITMAP, BIT) \ + ((BITMAP)[(BIT) / 8] |= (1 << ((BIT) & 7))) +#define spider_clear_bit(BITMAP, BIT) \ + ((BITMAP)[(BIT) / 8] &= ~(1 << ((BIT) & 7))) +#define spider_bit_is_set(BITMAP, BIT) \ + (uint) ((BITMAP)[(BIT) / 8] & (1 << ((BIT) & 7))) + +#define SPIDER_LINK_STATUS_NO_CHANGE 0 +#define SPIDER_LINK_STATUS_OK 1 +#define SPIDER_LINK_STATUS_RECOVERY 2 +#define SPIDER_LINK_STATUS_NG 3 + +#define SPIDER_LINK_MON_OK 0 +#define SPIDER_LINK_MON_NG -1 +#define SPIDER_LINK_MON_DRAW_FEW_MON 1 +#define SPIDER_LINK_MON_DRAW 2 + +#define SPIDER_TMP_SHARE_CHAR_PTR_COUNT 19 +#define SPIDER_TMP_SHARE_UINT_COUNT 17 +#define SPIDER_TMP_SHARE_LONG_COUNT 15 +#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3 + +#define SPIDER_MEM_CALC_LIST_NUM 230 + +#define SPIDER_BACKUP_DASTATUS \ + bool da_status; if (thd) da_status = thd->is_error(); else da_status = FALSE; +#define SPIDER_RESTORE_DASTATUS \ + if (!da_status && thd->is_error()) thd->clear_error(); +#define SPIDER_CONN_RESTORE_DASTATUS \ + if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS;} +#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM \ + if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; error_num = 0;} +#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM \ + if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; tmp_error_num = 0;} + +#define SPIDER_SET_FILE_POS(A) \ + {(A)->thd = current_thd; (A)->func_name = __func__; (A)->file_name = __FILE__; (A)->line_no = __LINE__;} +#define SPIDER_CLEAR_FILE_POS(A) \ + {(A)->thd = NULL; (A)->func_name = NULL; (A)->file_name = NULL; (A)->line_no = 0;} + +class ha_spider; +typedef struct st_spider_share SPIDER_SHARE; + +typedef struct st_spider_file_pos +{ + THD *thd; + const char *func_name; + const char *file_name; + ulong line_no; +} SPIDER_FILE_POS; + +typedef struct st_spider_link_for_hash +{ + ha_spider *spider; + int link_idx; + spider_string *db_table_str; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type db_table_str_hash_value; +#endif +} SPIDER_LINK_FOR_HASH; + +/* alter table */ +typedef struct st_spider_alter_table +{ + bool now_create; + char *table_name; + uint table_name_length; + char *tmp_char; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type table_name_hash_value; +#endif + longlong tmp_priority; + uint link_count; + uint all_link_count; + + char **tmp_server_names; + char **tmp_tgt_table_names; + char **tmp_tgt_dbs; + char **tmp_tgt_hosts; + char **tmp_tgt_usernames; + char **tmp_tgt_passwords; + char **tmp_tgt_sockets; + char **tmp_tgt_wrappers; + char **tmp_tgt_ssl_cas; + char **tmp_tgt_ssl_capaths; + char **tmp_tgt_ssl_certs; + char **tmp_tgt_ssl_ciphers; + char **tmp_tgt_ssl_keys; + char **tmp_tgt_default_files; + char **tmp_tgt_default_groups; + long *tmp_tgt_ports; + long *tmp_tgt_ssl_vscs; + long *tmp_link_statuses; + + uint *tmp_server_names_lengths; + uint *tmp_tgt_table_names_lengths; + uint *tmp_tgt_dbs_lengths; + uint *tmp_tgt_hosts_lengths; + uint *tmp_tgt_usernames_lengths; + uint *tmp_tgt_passwords_lengths; + uint *tmp_tgt_sockets_lengths; + uint *tmp_tgt_wrappers_lengths; + uint *tmp_tgt_ssl_cas_lengths; + uint *tmp_tgt_ssl_capaths_lengths; + uint *tmp_tgt_ssl_certs_lengths; + uint *tmp_tgt_ssl_ciphers_lengths; + uint *tmp_tgt_ssl_keys_lengths; + uint *tmp_tgt_default_files_lengths; + uint *tmp_tgt_default_groups_lengths; + + uint tmp_server_names_charlen; + uint tmp_tgt_table_names_charlen; + uint tmp_tgt_dbs_charlen; + uint tmp_tgt_hosts_charlen; + uint tmp_tgt_usernames_charlen; + uint tmp_tgt_passwords_charlen; + uint tmp_tgt_sockets_charlen; + uint tmp_tgt_wrappers_charlen; + uint tmp_tgt_ssl_cas_charlen; + uint tmp_tgt_ssl_capaths_charlen; + uint tmp_tgt_ssl_certs_charlen; + uint tmp_tgt_ssl_ciphers_charlen; + uint tmp_tgt_ssl_keys_charlen; + uint tmp_tgt_default_files_charlen; + uint tmp_tgt_default_groups_charlen; + + uint tmp_server_names_length; + uint tmp_tgt_table_names_length; + uint tmp_tgt_dbs_length; + uint tmp_tgt_hosts_length; + uint tmp_tgt_usernames_length; + uint tmp_tgt_passwords_length; + uint tmp_tgt_sockets_length; + uint tmp_tgt_wrappers_length; + uint tmp_tgt_ssl_cas_length; + uint tmp_tgt_ssl_capaths_length; + uint tmp_tgt_ssl_certs_length; + uint tmp_tgt_ssl_ciphers_length; + uint tmp_tgt_ssl_keys_length; + uint tmp_tgt_default_files_length; + uint tmp_tgt_default_groups_length; + uint tmp_tgt_ports_length; + uint tmp_tgt_ssl_vscs_length; + uint tmp_link_statuses_length; +} SPIDER_ALTER_TABLE; + +/* database connection */ +typedef struct st_spider_conn +{ + uint conn_kind; + char *conn_key; + uint conn_key_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type conn_key_hash_value; +#endif + int link_idx; + spider_db_conn *db_conn; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + query_id_t hsc_query_id; + ulonglong hs_pre_age; + ulonglong hs_age; +#endif + uint opened_handlers; + ulonglong conn_id; + ulonglong connection_id; + pthread_mutex_t mta_conn_mutex; + volatile bool mta_conn_mutex_lock_already; + volatile bool mta_conn_mutex_unlock_later; + SPIDER_FILE_POS mta_conn_mutex_file_pos; + uint join_trx; + int trx_isolation; + bool semi_trx_isolation_chk; + int semi_trx_isolation; + bool semi_trx_chk; + bool semi_trx; + bool trx_start; + bool table_locked; + int table_lock; + bool disable_xa; + bool disable_reconnect; + int autocommit; + int sql_log_off; + THD *thd; + void *another_ha_first; + void *another_ha_last; + st_spider_conn *p_small; + st_spider_conn *p_big; + st_spider_conn *c_small; + st_spider_conn *c_big; + longlong priority; + bool server_lost; + bool ignore_dup_key; + char *error_str; + int error_length; + time_t ping_time; + CHARSET_INFO *access_charset; + Time_zone *time_zone; + uint connect_timeout; + uint net_read_timeout; + uint net_write_timeout; + int error_mode; + spider_string default_database; + + char *tgt_host; + char *tgt_username; + char *tgt_password; + char *tgt_socket; + char *tgt_wrapper; + char *tgt_ssl_ca; + char *tgt_ssl_capath; + char *tgt_ssl_cert; + char *tgt_ssl_cipher; + char *tgt_ssl_key; + char *tgt_default_file; + char *tgt_default_group; + long tgt_port; + long tgt_ssl_vsc; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char *hs_sock; + long hs_port; +#endif + + uint tgt_host_length; + uint tgt_username_length; + uint tgt_password_length; + uint tgt_socket_length; + uint tgt_wrapper_length; + uint tgt_ssl_ca_length; + uint tgt_ssl_capath_length; + uint tgt_ssl_cert_length; + uint tgt_ssl_cipher_length; + uint tgt_ssl_key_length; + uint tgt_default_file_length; + uint tgt_default_group_length; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint hs_sock_length; +#endif + uint dbton_id; + +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + void *quick_target; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile bool bg_init; + volatile bool bg_break; + volatile bool bg_kill; + volatile bool bg_caller_wait; + volatile bool bg_caller_sync_wait; + volatile bool bg_search; + volatile bool bg_discard_result; + volatile bool bg_direct_sql; + volatile bool bg_exec_sql; + volatile bool bg_get_job_stack; + volatile bool bg_get_job_stack_off; + volatile uint bg_simple_action; + THD *bg_thd; + pthread_t bg_thread; + pthread_cond_t bg_conn_cond; + pthread_mutex_t bg_conn_mutex; + pthread_cond_t bg_conn_sync_cond; + pthread_mutex_t bg_conn_sync_mutex; + pthread_mutex_t bg_conn_chain_mutex; + pthread_mutex_t *bg_conn_chain_mutex_ptr; + volatile void *bg_target; + volatile int *bg_error_num; + volatile ulong bg_sql_type; + pthread_mutex_t bg_job_stack_mutex; + DYNAMIC_ARRAY bg_job_stack; + uint bg_job_stack_id; + const char *bg_job_stack_func_name; + const char *bg_job_stack_file_name; + ulong bg_job_stack_line_no; + uint bg_job_stack_cur_pos; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile +#endif + int *need_mon; + int *conn_need_mon; + + bool use_for_active_standby; + bool in_before_query; + + bool queued_connect; + bool queued_ping; + bool queued_trx_isolation; + bool queued_semi_trx_isolation; + bool queued_autocommit; + bool queued_sql_log_off; + bool queued_time_zone; + bool queued_trx_start; + bool queued_xa_start; + bool queued_net_timeout; + SPIDER_SHARE *queued_connect_share; + int queued_connect_link_idx; + ha_spider *queued_ping_spider; + int queued_ping_link_idx; + int queued_trx_isolation_val; + int queued_semi_trx_isolation_val; + bool queued_autocommit_val; + bool queued_sql_log_off_val; + Time_zone *queued_time_zone_val; + XID *queued_xa_start_xid; + +#ifdef HA_CAN_BULK_ACCESS + uint bulk_access_requests; + uint bulk_access_sended; + int bulk_access_error_num; + st_spider_conn *bulk_access_next; +#endif +} SPIDER_CONN; + +#ifdef WITH_PARTITION_STORAGE_ENGINE +typedef struct st_spider_patition_handler_share +{ + uint use_count; + TABLE *table; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type table_hash_value; +#endif + void *creator; + void **handlers; + uchar *searched_bitmap; + uchar *idx_read_bitmap; + uchar *idx_write_bitmap; + uchar *rnd_read_bitmap; + uchar *rnd_write_bitmap; + bool between_flg; + bool idx_bitmap_is_set; + bool rnd_bitmap_is_set; +} SPIDER_PARTITION_HANDLER_SHARE; + +typedef struct st_spider_patition_share +{ + char *table_name; + uint table_name_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type table_path_hash_value; +#endif + uint use_count; + pthread_mutex_t sts_mutex; + pthread_mutex_t crd_mutex; + pthread_mutex_t pt_handler_mutex; + HASH pt_handler_hash; + uint pt_handler_hash_id; + const char *pt_handler_hash_func_name; + const char *pt_handler_hash_file_name; + ulong pt_handler_hash_line_no; + + volatile bool sts_init; + volatile bool crd_init; + volatile time_t sts_get_time; + volatile time_t crd_get_time; + ulonglong data_file_length; + ulonglong max_data_file_length; + ulonglong index_file_length; + ulonglong auto_increment_value; + ha_rows records; + ulong mean_rec_length; + time_t check_time; + time_t create_time; + time_t update_time; + + longlong *cardinality; +/* + volatile SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share; +*/ +} SPIDER_PARTITION_SHARE; +#endif + +typedef struct st_spider_transaction +{ + bool trx_start; + bool trx_xa; + bool trx_consistent_snapshot; + + bool use_consistent_snapshot; + bool internal_xa; + uint internal_xa_snapshot; + + query_id_t query_id; + bool tmp_flg; + bool registed_allocated_thds; + + THD *thd; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type thd_hash_value; +#endif + XID xid; + HASH trx_conn_hash; + uint trx_conn_hash_id; + const char *trx_conn_hash_func_name; + const char *trx_conn_hash_file_name; + ulong trx_conn_hash_line_no; + HASH trx_another_conn_hash; + uint trx_another_conn_hash_id; + const char *trx_another_conn_hash_func_name; + const char *trx_another_conn_hash_file_name; + ulong trx_another_conn_hash_line_no; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + HASH trx_hs_r_conn_hash; + uint trx_hs_r_conn_hash_id; + const char *trx_hs_r_conn_hash_func_name; + const char *trx_hs_r_conn_hash_file_name; + ulong trx_hs_r_conn_hash_line_no; + HASH trx_hs_w_conn_hash; + uint trx_hs_w_conn_hash_id; + const char *trx_hs_w_conn_hash_func_name; + const char *trx_hs_w_conn_hash_file_name; + ulong trx_hs_w_conn_hash_line_no; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + HASH trx_direct_hs_r_conn_hash; + uint trx_direct_hs_r_conn_hash_id; + const char *trx_direct_hs_r_conn_hash_func_name; + const char *trx_direct_hs_r_conn_hash_file_name; + ulong trx_direct_hs_r_conn_hash_line_no; + HASH trx_direct_hs_w_conn_hash; + uint trx_direct_hs_w_conn_hash_id; + const char *trx_direct_hs_w_conn_hash_func_name; + const char *trx_direct_hs_w_conn_hash_file_name; + ulong trx_direct_hs_w_conn_hash_line_no; +#endif + HASH trx_alter_table_hash; + uint trx_alter_table_hash_id; + const char *trx_alter_table_hash_func_name; + const char *trx_alter_table_hash_file_name; + ulong trx_alter_table_hash_line_no; + HASH trx_ha_hash; + uint trx_ha_hash_id; + const char *trx_ha_hash_func_name; + const char *trx_ha_hash_file_name; + ulong trx_ha_hash_line_no; + uint trx_ha_reuse_count; + XID_STATE internal_xid_state; + SPIDER_CONN *join_trx_top; + ulonglong spider_thread_id; + ulonglong trx_conn_adjustment; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ulonglong trx_hs_r_conn_adjustment; + ulonglong trx_hs_w_conn_adjustment; +#endif + uint locked_connections; + + ulonglong direct_update_count; + ulonglong direct_delete_count; + ulonglong direct_order_limit_count; + ulonglong direct_aggregate_count; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ulonglong hs_result_free_count; +#endif + +#ifdef HA_CAN_BULK_ACCESS + SPIDER_CONN *bulk_access_conn_first; + SPIDER_CONN *bulk_access_conn_last; +#endif + + pthread_mutex_t *udf_table_mutexes; + CHARSET_INFO *udf_access_charset; + spider_string *udf_set_names; + + time_t mem_calc_merge_time; + const char *alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; + const char *alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; + ulong alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; + longlong current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong total_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM]; + longlong current_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong alloc_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM]; + ulonglong free_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM]; +} SPIDER_TRX; + +typedef struct st_spider_share +{ + char *table_name; + uint table_name_length; + uint use_count; + uint link_count; + uint all_link_count; + uint link_bitmap_size; + pthread_mutex_t mutex; + pthread_mutex_t sts_mutex; + pthread_mutex_t crd_mutex; + pthread_mutex_t auto_increment_mutex; + THR_LOCK lock; + TABLE_SHARE *table_share; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type table_name_hash_value; +#ifdef WITH_PARTITION_STORAGE_ENGINE + my_hash_value_type table_path_hash_value; +#endif +#endif + + volatile bool init; + volatile bool init_error; + volatile time_t init_error_time; + volatile bool link_status_init; + volatile bool sts_init; + volatile time_t sts_get_time; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile time_t bg_sts_try_time; + volatile double bg_sts_interval; + volatile int bg_sts_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + volatile int bg_sts_sync; +#endif + volatile bool bg_sts_init; + volatile bool bg_sts_kill; + volatile bool bg_sts_thd_wait; + THD *bg_sts_thd; + pthread_t bg_sts_thread; + pthread_cond_t bg_sts_cond; + pthread_cond_t bg_sts_sync_cond; + volatile bool crd_init; +#endif + volatile time_t crd_get_time; +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile time_t bg_crd_try_time; + volatile double bg_crd_interval; + volatile int bg_crd_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + volatile int bg_crd_sync; +#endif + volatile bool bg_crd_init; + volatile bool bg_crd_kill; + volatile bool bg_crd_thd_wait; + THD *bg_crd_thd; + pthread_t bg_crd_thread; + pthread_cond_t bg_crd_cond; + pthread_cond_t bg_crd_sync_cond; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + volatile bool bg_mon_init; + volatile bool bg_mon_kill; + THD **bg_mon_thds; + pthread_t *bg_mon_threads; + pthread_mutex_t *bg_mon_mutexes; + pthread_cond_t *bg_mon_conds; +#endif + volatile bool auto_increment_init; + volatile ulonglong auto_increment_lclval; + ulonglong data_file_length; + ulonglong max_data_file_length; + ulonglong index_file_length; + ulonglong auto_increment_value; + ha_rows records; + ulong mean_rec_length; + time_t check_time; + time_t create_time; + time_t update_time; + + int bitmap_size; + spider_string *key_hint; + CHARSET_INFO *access_charset; + longlong *cardinality; + uchar *cardinality_upd; + longlong additional_table_flags; + bool have_recovery_link; + +#ifndef WITHOUT_SPIDER_BG_SEARCH + int sts_bg_mode; +#endif + double sts_interval; + int sts_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + int sts_sync; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + int crd_bg_mode; +#endif + double crd_interval; + int crd_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync; +#endif + int crd_type; + double crd_weight; + longlong internal_offset; + longlong internal_limit; + longlong split_read; + double semi_split_read; + longlong semi_split_read_limit; + int init_sql_alloc_size; + int reset_sql_alloc; + int multi_split_read; + int max_order; + int semi_table_lock; + int semi_table_lock_conn; + int selupd_lock_mode; + int query_cache; + int internal_delayed; + int bulk_size; + int bulk_update_mode; + int bulk_update_size; + int internal_optimize; + int internal_optimize_local; + double scan_rate; + double read_rate; + longlong priority; + int quick_mode; + longlong quick_page_size; + int low_mem_read; + int table_count_mode; + int select_column_mode; +#ifndef WITHOUT_SPIDER_BG_SEARCH + int bgs_mode; + longlong bgs_first_read; + longlong bgs_second_read; +#endif + longlong first_read; + longlong second_read; + int auto_increment_mode; + int use_table_charset; + int use_pushdown_udf; + int skip_default_condition; + int direct_dup_insert; + longlong direct_order_limit; + int read_only_mode; + int error_read_mode; + int error_write_mode; + int active_link_count; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + longlong hs_result_free_size; +#endif +#ifdef HA_CAN_BULK_ACCESS + int bulk_access_free; +#endif + + int bka_mode; + char *bka_engine; + int bka_engine_length; + +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type *conn_keys_hash_value; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + my_hash_value_type *hs_read_conn_keys_hash_value; + my_hash_value_type *hs_write_conn_keys_hash_value; +#endif +#endif + char **server_names; + char **tgt_table_names; + char **tgt_dbs; + char **tgt_hosts; + char **tgt_usernames; + char **tgt_passwords; + char **tgt_sockets; + char **tgt_wrappers; + char **tgt_ssl_cas; + char **tgt_ssl_capaths; + char **tgt_ssl_certs; + char **tgt_ssl_ciphers; + char **tgt_ssl_keys; + char **tgt_default_files; + char **tgt_default_groups; + char **tgt_pk_names; + char **tgt_sequence_names; + char **conn_keys; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char **hs_read_socks; + char **hs_write_socks; + char **hs_read_conn_keys; + char **hs_write_conn_keys; +#endif + long *tgt_ports; + long *tgt_ssl_vscs; + long *link_statuses; +#ifndef WITHOUT_SPIDER_BG_SEARCH + long *monitoring_bg_kind; +#endif + long *monitoring_kind; +#ifndef WITHOUT_SPIDER_BG_SEARCH + longlong *monitoring_bg_interval; +#endif + longlong *monitoring_limit; + longlong *monitoring_sid; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + long *use_hs_reads; + long *use_hs_writes; + long *hs_read_ports; + long *hs_write_ports; + long *hs_write_to_reads; +#endif + long *use_handlers; + long *connect_timeouts; + long *net_read_timeouts; + long *net_write_timeouts; + long *access_balances; + + uint *server_names_lengths; + uint *tgt_table_names_lengths; + uint *tgt_dbs_lengths; + uint *tgt_hosts_lengths; + uint *tgt_usernames_lengths; + uint *tgt_passwords_lengths; + uint *tgt_sockets_lengths; + uint *tgt_wrappers_lengths; + uint *tgt_ssl_cas_lengths; + uint *tgt_ssl_capaths_lengths; + uint *tgt_ssl_certs_lengths; + uint *tgt_ssl_ciphers_lengths; + uint *tgt_ssl_keys_lengths; + uint *tgt_default_files_lengths; + uint *tgt_default_groups_lengths; + uint *tgt_pk_names_lengths; + uint *tgt_sequence_names_lengths; + uint *conn_keys_lengths; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint *hs_read_socks_lengths; + uint *hs_write_socks_lengths; + uint *hs_read_conn_keys_lengths; + uint *hs_write_conn_keys_lengths; +#endif + uint *sql_dbton_ids; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint *hs_dbton_ids; +#endif + + uint server_names_charlen; + uint tgt_table_names_charlen; + uint tgt_dbs_charlen; + uint tgt_hosts_charlen; + uint tgt_usernames_charlen; + uint tgt_passwords_charlen; + uint tgt_sockets_charlen; + uint tgt_wrappers_charlen; + uint tgt_ssl_cas_charlen; + uint tgt_ssl_capaths_charlen; + uint tgt_ssl_certs_charlen; + uint tgt_ssl_ciphers_charlen; + uint tgt_ssl_keys_charlen; + uint tgt_default_files_charlen; + uint tgt_default_groups_charlen; + uint tgt_pk_names_charlen; + uint tgt_sequence_names_charlen; + uint conn_keys_charlen; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint hs_read_socks_charlen; + uint hs_write_socks_charlen; + uint hs_read_conn_keys_charlen; + uint hs_write_conn_keys_charlen; +#endif + + uint server_names_length; + uint tgt_table_names_length; + uint tgt_dbs_length; + uint tgt_hosts_length; + uint tgt_usernames_length; + uint tgt_passwords_length; + uint tgt_sockets_length; + uint tgt_wrappers_length; + uint tgt_ssl_cas_length; + uint tgt_ssl_capaths_length; + uint tgt_ssl_certs_length; + uint tgt_ssl_ciphers_length; + uint tgt_ssl_keys_length; + uint tgt_default_files_length; + uint tgt_default_groups_length; + uint tgt_pk_names_length; + uint tgt_sequence_names_length; + uint conn_keys_length; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint hs_read_socks_length; + uint hs_write_socks_length; + uint hs_read_conn_keys_length; + uint hs_write_conn_keys_length; +#endif + uint tgt_ports_length; + uint tgt_ssl_vscs_length; + uint link_statuses_length; +#ifndef WITHOUT_SPIDER_BG_SEARCH + uint monitoring_bg_kind_length; +#endif + uint monitoring_kind_length; +#ifndef WITHOUT_SPIDER_BG_SEARCH + uint monitoring_bg_interval_length; +#endif + uint monitoring_limit_length; + uint monitoring_sid_length; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint use_hs_reads_length; + uint use_hs_writes_length; + uint hs_read_ports_length; + uint hs_write_ports_length; + uint hs_write_to_reads_length; +#endif + uint use_handlers_length; + uint connect_timeouts_length; + uint net_read_timeouts_length; + uint net_write_timeouts_length; + uint access_balances_length; + + /* for dbton */ + uchar dbton_bitmap[spider_bitmap_size(SPIDER_DBTON_SIZE)]; + spider_db_share *dbton_share[SPIDER_DBTON_SIZE]; + uint use_dbton_count; + uint use_dbton_ids[SPIDER_DBTON_SIZE]; + uint dbton_id_to_seq[SPIDER_DBTON_SIZE]; + uint use_sql_dbton_count; + uint use_sql_dbton_ids[SPIDER_DBTON_SIZE]; + uint sql_dbton_id_to_seq[SPIDER_DBTON_SIZE]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint use_hs_dbton_count; + uint use_hs_dbton_ids[SPIDER_DBTON_SIZE]; + uint hs_dbton_id_to_seq[SPIDER_DBTON_SIZE]; +#endif + + SPIDER_ALTER_TABLE alter_table; +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_SHARE *partition_share; +#endif +} SPIDER_SHARE; + +typedef struct st_spider_link_pack +{ + SPIDER_SHARE *share; + int link_idx; +} SPIDER_LINK_PACK; + +typedef struct st_spider_init_error_table +{ + char *table_name; + uint table_name_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type table_name_hash_value; +#endif + bool init_error_with_message; + char init_error_msg[MYSQL_ERRMSG_SIZE]; + volatile int init_error; + volatile time_t init_error_time; +} SPIDER_INIT_ERROR_TABLE; + +typedef struct st_spider_direct_sql +{ + int table_count; + char **db_names; + char **table_names; + TABLE **tables; + int *iop; + +#if MYSQL_VERSION_ID < 50500 +#else + /* for using real table */ + bool real_table_used; + TABLE_LIST *table_list_first; + TABLE_LIST *table_list; + uchar *real_table_bitmap; + Open_tables_backup open_tables_backup; + THD *open_tables_thd; +#endif + + char *sql; + ulong sql_length; + + SPIDER_TRX *trx; + SPIDER_CONN *conn; + + bool modified_non_trans_table; + + int table_loop_mode; + longlong priority; + int connect_timeout; + int net_read_timeout; + int net_write_timeout; + longlong bulk_insert_rows; + int connection_channel; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + int access_mode; +#endif +#if MYSQL_VERSION_ID < 50500 +#else + int use_real_table; +#endif + + char *server_name; + char *tgt_default_db_name; + char *tgt_host; + char *tgt_username; + char *tgt_password; + char *tgt_socket; + char *tgt_wrapper; + char *tgt_ssl_ca; + char *tgt_ssl_capath; + char *tgt_ssl_cert; + char *tgt_ssl_cipher; + char *tgt_ssl_key; + char *tgt_default_file; + char *tgt_default_group; + char *conn_key; + long tgt_port; + long tgt_ssl_vsc; + + uint server_name_length; + uint tgt_default_db_name_length; + uint tgt_host_length; + uint tgt_username_length; + uint tgt_password_length; + uint tgt_socket_length; + uint tgt_wrapper_length; + uint tgt_ssl_ca_length; + uint tgt_ssl_capath_length; + uint tgt_ssl_cert_length; + uint tgt_ssl_cipher_length; + uint tgt_ssl_key_length; + uint tgt_default_file_length; + uint tgt_default_group_length; + uint conn_key_length; + uint dbton_id; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type conn_key_hash_value; +#endif + + pthread_mutex_t *bg_mutex; + pthread_cond_t *bg_cond; + volatile st_spider_direct_sql *prev; + volatile st_spider_direct_sql *next; + void *parent; +} SPIDER_DIRECT_SQL; + +typedef struct st_spider_bg_direct_sql +{ + longlong called_cnt; + char bg_error_msg[MYSQL_ERRMSG_SIZE]; + volatile int bg_error; + volatile bool modified_non_trans_table; + pthread_mutex_t bg_mutex; + pthread_cond_t bg_cond; + volatile SPIDER_DIRECT_SQL *direct_sql; +} SPIDER_BG_DIRECT_SQL; + +typedef struct st_spider_mon_table_result +{ + int result_status; + SPIDER_TRX *trx; +} SPIDER_MON_TABLE_RESULT; + +typedef struct st_spider_table_mon +{ + SPIDER_SHARE *share; + uint32 server_id; + st_spider_table_mon *next; +} SPIDER_TABLE_MON; + +typedef struct st_spider_table_mon_list +{ + char *key; + uint key_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type key_hash_value; +#endif + + uint use_count; + uint mutex_hash; + ulonglong mon_table_cache_version; + + char *table_name; + int link_id; + uint table_name_length; + + int list_size; + SPIDER_TABLE_MON *first; + SPIDER_TABLE_MON *current; + volatile int mon_status; + + SPIDER_SHARE *share; + + pthread_mutex_t caller_mutex; + pthread_mutex_t receptor_mutex; + pthread_mutex_t monitor_mutex; + pthread_mutex_t update_status_mutex; + volatile int last_caller_result; + volatile int last_receptor_result; + volatile int last_mon_result; +} SPIDER_TABLE_MON_LIST; + +typedef struct st_spider_copy_table_conn +{ + SPIDER_SHARE *share; + int link_idx; + SPIDER_CONN *conn; + spider_db_copy_table *copy_table; + ha_spider *spider; + int need_mon; +#ifndef WITHOUT_SPIDER_BG_SEARCH + int bg_error_num; +#endif + st_spider_copy_table_conn *next; +} SPIDER_COPY_TABLE_CONN; + +typedef struct st_spider_copy_tables +{ + SPIDER_TRX *trx; + char *spider_db_name; + int spider_db_name_length; + char *spider_table_name; + int spider_table_name_length; + char *spider_real_table_name; + int spider_real_table_name_length; + TABLE_LIST spider_table_list; + CHARSET_INFO *access_charset; + + SPIDER_COPY_TABLE_CONN *table_conn[2]; + bool use_auto_mode[2]; + int link_idx_count[2]; + int *link_idxs[2]; + + int bulk_insert_interval; + longlong bulk_insert_rows; + int use_table_charset; + int use_transaction; +#ifndef WITHOUT_SPIDER_BG_SEARCH + int bg_mode; +#endif + + char *database; + + int database_length; +} SPIDER_COPY_TABLES; + +class SPIDER_SORT +{ +public: + ulong sort; +}; + +typedef struct st_spider_trx_ha +{ + char *table_name; + uint table_name_length; + SPIDER_TRX *trx; + SPIDER_SHARE *share; + uint link_count; + uint link_bitmap_size; + uint *conn_link_idx; + uchar *conn_can_fo; + bool wait_for_reusing; +} SPIDER_TRX_HA; + +#ifdef HA_CAN_BULK_ACCESS +typedef struct st_spider_bulk_access_link +{ + ha_spider *spider; + uint sequence_num; + bool used; + bool called; + MEM_ROOT mem_root; + st_spider_bulk_access_link *next; +} SPIDER_BULK_ACCESS_LINK; +#endif + +char *spider_create_string( + const char *str, + uint length +); diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc new file mode 100644 index 00000000000..8cfa7e86357 --- /dev/null +++ b/storage/spider/spd_malloc.cc @@ -0,0 +1,1267 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#endif +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; + +pthread_mutex_t spider_mem_calc_mutex; + +const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; +const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; +ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; +ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; +ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; + +void spider_merge_mem_calc( + SPIDER_TRX *trx, + bool force +) { + uint roop_count; + time_t tmp_time; + DBUG_ENTER("spider_merge_mem_calc"); + if (force) + { + pthread_mutex_lock(&spider_mem_calc_mutex); + tmp_time = (time_t) time((time_t*) 0); + } else { + tmp_time = (time_t) time((time_t*) 0); + if ( + difftime(tmp_time, trx->mem_calc_merge_time) < 2 || + pthread_mutex_trylock(&spider_mem_calc_mutex) + ) + DBUG_VOID_RETURN; + } + for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++) + { + DBUG_ASSERT(!spider_alloc_func_name[roop_count] || + !trx->alloc_func_name[roop_count] || + spider_alloc_func_name[roop_count] == trx->alloc_func_name[roop_count]); + DBUG_ASSERT(!spider_alloc_file_name[roop_count] || + !trx->alloc_file_name[roop_count] || + spider_alloc_file_name[roop_count] == trx->alloc_file_name[roop_count]); + DBUG_ASSERT(!spider_alloc_line_no[roop_count] || + !trx->alloc_line_no[roop_count] || + spider_alloc_line_no[roop_count] == trx->alloc_line_no[roop_count]); + if (trx->alloc_func_name[roop_count]) + { + spider_alloc_func_name[roop_count] = trx->alloc_func_name[roop_count]; + spider_alloc_file_name[roop_count] = trx->alloc_file_name[roop_count]; + spider_alloc_line_no[roop_count] = trx->alloc_line_no[roop_count]; + spider_total_alloc_mem[roop_count] += + trx->total_alloc_mem_buffer[roop_count]; + trx->total_alloc_mem_buffer[roop_count] = 0; + spider_alloc_mem_count[roop_count] += + trx->alloc_mem_count_buffer[roop_count]; + trx->alloc_mem_count_buffer[roop_count] = 0; + } + spider_current_alloc_mem[roop_count] += + trx->current_alloc_mem_buffer[roop_count]; + trx->current_alloc_mem_buffer[roop_count] = 0; + spider_free_mem_count[roop_count] += + trx->free_mem_count_buffer[roop_count]; + trx->free_mem_count_buffer[roop_count] = 0; + } + pthread_mutex_unlock(&spider_mem_calc_mutex); + trx->mem_calc_merge_time = tmp_time; + DBUG_VOID_RETURN; +} + +void spider_free_mem_calc( + SPIDER_TRX *trx, + uint id, + size_t size +) { + DBUG_ENTER("spider_free_mem_calc"); + DBUG_ASSERT(id < SPIDER_MEM_CALC_LIST_NUM); + DBUG_PRINT("info",("spider trx=%p id=%u size=%llu", + trx, id, (ulonglong) size)); + if (trx) + { + DBUG_PRINT("info",("spider calc into trx")); + trx->current_alloc_mem[id] -= size; + trx->current_alloc_mem_buffer[id] -= size; + trx->free_mem_count[id] += 1; + trx->free_mem_count_buffer[id] += 1; + } else { + DBUG_PRINT("info",("spider calc into global")); + pthread_mutex_lock(&spider_mem_calc_mutex); + spider_current_alloc_mem[id] -= size; + spider_free_mem_count[id] += 1; + pthread_mutex_unlock(&spider_mem_calc_mutex); + } + DBUG_VOID_RETURN; +} + +void spider_alloc_mem_calc( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + size_t size +) { + DBUG_ENTER("spider_alloc_mem_calc"); + DBUG_ASSERT(id < SPIDER_MEM_CALC_LIST_NUM); + DBUG_PRINT("info",("spider trx=%p id=%u size=%llu", + trx, id, (ulonglong) size)); + if (trx) + { + DBUG_PRINT("info",("spider calc into trx")); + DBUG_ASSERT(!trx->alloc_func_name[id] || + trx->alloc_func_name[id] == func_name); + DBUG_ASSERT(!trx->alloc_file_name[id] || + trx->alloc_file_name[id] == file_name); + DBUG_ASSERT(!trx->alloc_line_no[id] || + trx->alloc_line_no[id] == line_no); + trx->alloc_func_name[id] = func_name; + trx->alloc_file_name[id] = file_name; + trx->alloc_line_no[id] = line_no; + trx->total_alloc_mem[id] += size; + trx->total_alloc_mem_buffer[id] += size; + trx->current_alloc_mem[id] += size; + trx->current_alloc_mem_buffer[id] += size; + trx->alloc_mem_count[id] += 1; + trx->alloc_mem_count_buffer[id] += 1; + } else { + DBUG_PRINT("info",("spider calc into global")); + pthread_mutex_lock(&spider_mem_calc_mutex); + DBUG_ASSERT(!spider_alloc_func_name[id] || + spider_alloc_func_name[id] == func_name); + DBUG_ASSERT(!spider_alloc_file_name[id] || + spider_alloc_file_name[id] == file_name); + DBUG_ASSERT(!spider_alloc_line_no[id] || + spider_alloc_line_no[id] == line_no); + spider_alloc_func_name[id] = func_name; + spider_alloc_file_name[id] = file_name; + spider_alloc_line_no[id] = line_no; + spider_total_alloc_mem[id] += size; + spider_current_alloc_mem[id] += size; + spider_alloc_mem_count[id] += 1; + pthread_mutex_unlock(&spider_mem_calc_mutex); + } + DBUG_VOID_RETURN; +} + +void spider_free_mem( + SPIDER_TRX *trx, + void *ptr, + myf my_flags +) { + uint id, size; + uchar *tmp_ptr = (uchar *) ptr; + DBUG_ENTER("spider_free_mem"); + tmp_ptr -= ALIGN_SIZE(sizeof(uint)); + size = *((uint *) tmp_ptr); + tmp_ptr -= ALIGN_SIZE(sizeof(uint)); + id = *((uint *) tmp_ptr); + my_free(tmp_ptr, my_flags); + + spider_free_mem_calc(trx, id, size); + DBUG_VOID_RETURN; +} + +void *spider_alloc_mem( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + size_t size, + myf my_flags +) { + uchar *ptr; + DBUG_ENTER("spider_alloc_mem"); + size += ALIGN_SIZE(sizeof(uint)) + ALIGN_SIZE(sizeof(uint)); + if (!(ptr = (uchar *) my_malloc(size, my_flags))) + DBUG_RETURN(NULL); + + spider_alloc_mem_calc(trx, id, func_name, file_name, line_no, size); + *((uint *) ptr) = id; + ptr += ALIGN_SIZE(sizeof(uint)); + *((uint *) ptr) = size; + ptr += ALIGN_SIZE(sizeof(uint)); + DBUG_RETURN(ptr); +} + +void *spider_bulk_alloc_mem( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + myf my_flags, + ... +) { + uchar **tmp_ptr, *top_ptr, *current_ptr; + uint total_size; + va_list args; + DBUG_ENTER("spider_bulk_alloc_mem"); + total_size = ALIGN_SIZE(sizeof(uint)) + ALIGN_SIZE(sizeof(uint)); + va_start(args, my_flags); + while (va_arg(args, char **)) + total_size += ALIGN_SIZE(va_arg(args, uint)); + va_end(args); + + if (!(top_ptr = (uchar *) my_malloc(total_size, my_flags))) + DBUG_RETURN(NULL); + + spider_alloc_mem_calc(trx, id, func_name, file_name, line_no, total_size); + *((uint *) top_ptr) = id; + top_ptr += ALIGN_SIZE(sizeof(uint)); + *((uint *) top_ptr) = total_size; + top_ptr += ALIGN_SIZE(sizeof(uint)); + + current_ptr = top_ptr; + va_start(args, my_flags); + while ((tmp_ptr = (uchar **) va_arg(args, char **))) + { + *tmp_ptr = current_ptr; + current_ptr += ALIGN_SIZE(va_arg(args, uint)); + } + va_end(args); + DBUG_RETURN((void *) top_ptr); +} + +#define SPIDER_STRING_CALC_MEM \ + if (mem_calc_inited) \ + { \ + uint32 new_alloc_mem = \ + (this->str.is_alloced() ? this->str.alloced_length() : 0); \ + if (new_alloc_mem != current_alloc_mem) \ + { \ + if (new_alloc_mem > current_alloc_mem) \ + spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, \ + line_no, new_alloc_mem - current_alloc_mem); \ + else \ + spider_free_mem_calc(spider_current_trx, id, \ + current_alloc_mem - new_alloc_mem); \ + current_alloc_mem = new_alloc_mem; \ + } \ + } + +spider_string::spider_string( +) : str(), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::spider_string( + uint32 length_arg +) : str(length_arg), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::spider_string( + const char *str, + CHARSET_INFO *cs +) : str(str, cs), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::spider_string( + const char *str, + uint32 len, + CHARSET_INFO *cs +) : str(str, len, cs), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::spider_string( + char *str, + uint32 len, + CHARSET_INFO *cs +) : str(str, len, cs), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::spider_string( + const String &str +) : str(str), next(NULL) +{ + DBUG_ENTER("spider_string::spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + mem_calc_inited = FALSE; + DBUG_VOID_RETURN; +} + +spider_string::~spider_string() +{ + DBUG_ENTER("spider_string::~spider_string"); + DBUG_PRINT("info",("spider this=%p", this)); + if (mem_calc_inited) + free(); + DBUG_VOID_RETURN; +} + +void spider_string::init_mem_calc( + uint id, + const char *func_name, + const char *file_name, + ulong line_no +) { + DBUG_ENTER("spider_string::init_mem_calc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(!mem_calc_inited); + this->id = id; + this->func_name = func_name; + this->file_name = file_name; + this->line_no = line_no; + if (str.is_alloced()) + { + current_alloc_mem = str.alloced_length(); + spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, + line_no, current_alloc_mem); + } else + current_alloc_mem = 0; + mem_calc_inited = TRUE; + DBUG_VOID_RETURN; +} + +void spider_string::mem_calc() +{ + DBUG_ENTER("spider_string::mem_calc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +String *spider_string::get_str() +{ + DBUG_ENTER("spider_string::get_str"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(&str); +} + +void spider_string::set_charset( + CHARSET_INFO *charset_arg +) { + DBUG_ENTER("spider_string::set_charset"); + DBUG_PRINT("info",("spider this=%p", this)); + str.set_charset(charset_arg); + DBUG_VOID_RETURN; +} + +CHARSET_INFO *spider_string::charset() const +{ + DBUG_ENTER("spider_string::charset"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.charset()); +} + +uint32 spider_string::length() const +{ + DBUG_ENTER("spider_string::length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.length()); +} + +uint32 spider_string::alloced_length() const +{ + DBUG_ENTER("spider_string::alloced_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.alloced_length()); +} + +char &spider_string::operator [] (uint32 i) const +{ + DBUG_ENTER("spider_string::operator []"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str[i]); +} + +void spider_string::length( + uint32 len +) { + DBUG_ENTER("spider_string::length"); + DBUG_PRINT("info",("spider this=%p", this)); + str.length(len); + DBUG_VOID_RETURN; +} + +bool spider_string::is_empty() const +{ + DBUG_ENTER("spider_string::is_empty"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.is_empty()); +} + +const char *spider_string::ptr() const +{ + DBUG_ENTER("spider_string::ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.ptr()); +} + +char *spider_string::c_ptr() +{ + DBUG_ENTER("spider_string::c_ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + char *res = str.c_ptr(); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +char *spider_string::c_ptr_quick() +{ + DBUG_ENTER("spider_string::c_ptr_quick"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.c_ptr_quick()); +} + +char *spider_string::c_ptr_safe() +{ + DBUG_ENTER("spider_string::c_ptr_safe"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + char *res = str.c_ptr_safe(); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +LEX_STRING spider_string::lex_string() const +{ + DBUG_ENTER("spider_string::lex_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.lex_string()); +} + +void spider_string::set( + String &str, + uint32 offset, + uint32 arg_length +) { + DBUG_ENTER("spider_string::set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + str.set(str, offset, arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +void spider_string::set( + char *str, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || + current_alloc_mem == this->str.alloced_length()); + this->str.set(str, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +void spider_string::set( + const char *str, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || + current_alloc_mem == this->str.alloced_length()); + this->str.set(str, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +bool spider_string::set_ascii( + const char *str, + uint32 arg_length +) { + DBUG_ENTER("spider_string::set_ascii"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || + current_alloc_mem == this->str.alloced_length()); + bool res = this->str.set_ascii(str, arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +void spider_string::set_quick( + char *str, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set_quick"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !this->str.is_alloced()) || + current_alloc_mem == this->str.alloced_length()); + this->str.set_quick(str, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +bool spider_string::set_int( + longlong num, + bool unsigned_flag, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set_int"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.set_int(num, unsigned_flag, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::set( + longlong num, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.set(num, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::set( + ulonglong num, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.set(num, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::set_real( + double num, + uint decimals, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set_real"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.set_real(num, decimals, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +void spider_string::chop() +{ + DBUG_ENTER("spider_string::chop"); + DBUG_PRINT("info",("spider this=%p", this)); + str.chop(); + DBUG_VOID_RETURN; +} + +void spider_string::free() +{ + DBUG_ENTER("spider_string::free"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + str.free(); + if (mem_calc_inited && current_alloc_mem) + { + spider_free_mem_calc(spider_current_trx, id, current_alloc_mem); + current_alloc_mem = 0; + } + DBUG_VOID_RETURN; +} + +bool spider_string::alloc(uint32 arg_length) +{ + bool res; + DBUG_ENTER("spider_string::alloc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + res = str.alloc(arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::real_alloc(uint32 arg_length) +{ + bool res; + DBUG_ENTER("spider_string::real_alloc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + res = str.real_alloc(arg_length); +/* + if (mem_calc_inited && !res && arg_length) +*/ + if (mem_calc_inited && !res) + { + DBUG_ASSERT(!current_alloc_mem); + spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, + line_no, str.alloced_length()); + current_alloc_mem = str.alloced_length(); + } + DBUG_RETURN(res); +} + +bool spider_string::realloc(uint32 arg_length) +{ + bool res; + DBUG_ENTER("spider_string::realloc"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + res = str.realloc(arg_length); + if (mem_calc_inited && !res && current_alloc_mem < str.alloced_length()) + { + spider_alloc_mem_calc(spider_current_trx, id, func_name, file_name, + line_no, str.alloced_length() - current_alloc_mem); + current_alloc_mem = str.alloced_length(); + } + DBUG_RETURN(res); +} + +void spider_string::shrink( + uint32 arg_length +) { + DBUG_ENTER("spider_string::shrink"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + str.shrink(arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +bool spider_string::is_alloced() +{ + DBUG_ENTER("spider_string::is_alloced"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.is_alloced()); +} + +spider_string &spider_string::operator = ( + const String &s +) { + DBUG_ENTER("spider_string::operator ="); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + str = s; + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(*this); +} + +bool spider_string::copy() +{ + DBUG_ENTER("spider_string::copy"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy(); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::copy( + const spider_string &s +) { + DBUG_ENTER("spider_string::copy"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy(s.str); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::copy( + const String &s +) { + DBUG_ENTER("spider_string::copy"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy(s); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::copy( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::copy"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy(s, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::needs_conversion( + uint32 arg_length, + CHARSET_INFO *cs_from, + CHARSET_INFO *cs_to, + uint32 *offset +) { + DBUG_ENTER("spider_string::needs_conversion"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.needs_conversion(arg_length, cs_from, cs_to, offset)); +} + +bool spider_string::copy_aligned( + const char *s, + uint32 arg_length, + uint32 offset, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::copy_aligned"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy_aligned(s, arg_length, offset, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::set_or_copy_aligned( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::set_or_copy_aligned"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.set_or_copy_aligned(s, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::copy( + const char *s, + uint32 arg_length, + CHARSET_INFO *csfrom, + CHARSET_INFO *csto, + uint *errors +) { + DBUG_ENTER("spider_string::copy"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.copy(s, arg_length, csfrom, csto, errors); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const spider_string &s +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s.str); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const String &s +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const char *s +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + LEX_STRING *ls +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(ls); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const char *s, + uint32 arg_length +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s, arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const char *s, + uint32 arg_length, + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s, arg_length, cs); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append_ulonglong( + ulonglong val +) { + DBUG_ENTER("spider_string::append_ulonglong"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append_ulonglong(val); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + IO_CACHE *file, + uint32 arg_length +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(file, arg_length); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append_with_prefill( + const char *s, + uint32 arg_length, + uint32 full_length, + char fill_char +) { + DBUG_ENTER("spider_string::append_with_prefill"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append_with_prefill(s, arg_length, full_length, + fill_char); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +int spider_string::strstr( + const String &search, + uint32 offset +) { + DBUG_ENTER("spider_string::strstr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.strstr(search, offset)); +} + +int spider_string::strrstr( + const String &search, + uint32 offset +) { + DBUG_ENTER("spider_string::strrstr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.strrstr(search, offset)); +} + +bool spider_string::replace( + uint32 offset, + uint32 arg_length, + const char *to, + uint32 length +) { + DBUG_ENTER("spider_string::replace"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.replace(offset, arg_length, to, length); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::replace( + uint32 offset, + uint32 arg_length, + const String &to +) { + DBUG_ENTER("spider_string::replace"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.replace(offset, arg_length, to); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + char chr +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(chr); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::fill( + uint32 max_length, + char fill +) { + DBUG_ENTER("spider_string::fill"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.fill(max_length, fill); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +void spider_string::strip_sp() +{ + DBUG_ENTER("spider_string::strip_sp"); + DBUG_PRINT("info",("spider this=%p", this)); + str.strip_sp(); + DBUG_VOID_RETURN; +} + +uint32 spider_string::numchars() +{ + DBUG_ENTER("spider_string::numchars"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.numchars()); +} + +int spider_string::charpos( + int i, + uint32 offset +) { + DBUG_ENTER("spider_string::charpos"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.charpos(i, offset)); +} + +int spider_string::reserve( + uint32 space_needed +) { + DBUG_ENTER("spider_string::reserve"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + int res = str.reserve(space_needed); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +int spider_string::reserve( + uint32 space_needed, + uint32 grow_by +) { + DBUG_ENTER("spider_string::reserve"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + int res = str.reserve(space_needed, grow_by); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +void spider_string::q_append( + const char c +) { + DBUG_ENTER("spider_string::q_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.q_append(c); + DBUG_VOID_RETURN; +} + +void spider_string::q_append( + const uint32 n +) { + DBUG_ENTER("spider_string::q_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.q_append(n); + DBUG_VOID_RETURN; +} + +void spider_string::q_append( + double d +) { + DBUG_ENTER("spider_string::q_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.q_append(d); + DBUG_VOID_RETURN; +} + +void spider_string::q_append( + double *d +) { + DBUG_ENTER("spider_string::q_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.q_append(d); + DBUG_VOID_RETURN; +} + +void spider_string::q_append( + const char *data, + uint32 data_len +) { + DBUG_ENTER("spider_string::q_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.q_append(data, data_len); + DBUG_VOID_RETURN; +} + +void spider_string::write_at_position( + int position, + uint32 value +) { + DBUG_ENTER("spider_string::write_at_position"); + DBUG_PRINT("info",("spider this=%p", this)); + str.write_at_position(position, value); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + const char *str, + uint32 len +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + this->str.qs_append(str, len); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + double d +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.qs_append(d); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + double *d +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.qs_append(d); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + const char c +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.qs_append(c); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + int i +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.qs_append(i); + DBUG_VOID_RETURN; +} + +void spider_string::qs_append( + uint i +) { + DBUG_ENTER("spider_string::qs_append"); + DBUG_PRINT("info",("spider this=%p", this)); + str.qs_append(i); + DBUG_VOID_RETURN; +} + +char *spider_string::prep_append( + uint32 arg_length, + uint32 step_alloc +) { + DBUG_ENTER("spider_string::prep_append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + char *res = str.prep_append(arg_length, step_alloc); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append( + const char *s, + uint32 arg_length, + uint32 step_alloc +) { + DBUG_ENTER("spider_string::append"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append(s, arg_length, step_alloc); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE +bool spider_string::append_for_single_quote( + const char *st, + uint len +) { + DBUG_ENTER("spider_string::append_for_single_quote"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + bool res = str.append_for_single_quote(st, len); + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} +#endif + +void spider_string::swap( + spider_string &s +) { + DBUG_ENTER("spider_string::swap"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(mem_calc_inited); + DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) || + current_alloc_mem == str.alloced_length()); + str.swap(s.str); + SPIDER_STRING_CALC_MEM; + DBUG_VOID_RETURN; +} + +bool spider_string::uses_buffer_owned_by( + const String *s +) const +{ + DBUG_ENTER("spider_string::uses_buffer_owned_by"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.uses_buffer_owned_by(s)); +} + +bool spider_string::is_ascii() const +{ + DBUG_ENTER("spider_string::is_ascii"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(str.is_ascii()); +} diff --git a/storage/spider/spd_malloc.h b/storage/spider/spd_malloc.h new file mode 100644 index 00000000000..e981eb3cae4 --- /dev/null +++ b/storage/spider/spd_malloc.h @@ -0,0 +1,79 @@ +/* Copyright (C) 2012-2013 Kentoku Shiba + + 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 */ + +#define spider_free(A,B,C) spider_free_mem(A,B,C) +#define spider_malloc(A,B,C,D) \ + spider_alloc_mem(A,B,__func__,__FILE__,__LINE__,C,D) +#define spider_bulk_malloc(A,B,C,...) \ + spider_bulk_alloc_mem(A,B,__func__,__FILE__,__LINE__,C,__VA_ARGS__) +#define spider_current_trx \ + (current_thd ? ((SPIDER_TRX *) *thd_ha_data(current_thd, spider_hton_ptr)) : NULL) + +#define init_calc_mem(A) init_mem_calc(A,__func__,__FILE__,__LINE__) + +#define SPIDER_CALC_MEM_ID(name) name ## _id +#define SPIDER_CALC_MEM_FUNC(name) name ## _func_name +#define SPIDER_CALC_MEM_FILE(name) name ## _file_name +#define SPIDER_CALC_MEM_LINE(name) name ## _line_no +#define spider_alloc_calc_mem_init(A,B) \ + {SPIDER_CALC_MEM_ID(A) = B; SPIDER_CALC_MEM_FUNC(A) = __func__; SPIDER_CALC_MEM_FILE(A) = __FILE__; SPIDER_CALC_MEM_LINE(A) = __LINE__;} +#define spider_alloc_calc_mem(A,B,C) \ + spider_alloc_mem_calc(A,SPIDER_CALC_MEM_ID(B),SPIDER_CALC_MEM_FUNC(B),SPIDER_CALC_MEM_FILE(B),SPIDER_CALC_MEM_LINE(B),C) + +void spider_merge_mem_calc( + SPIDER_TRX *trx, + bool force +); + +void spider_free_mem_calc( + SPIDER_TRX *trx, + uint id, + size_t size +); + +void spider_alloc_mem_calc( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + size_t size +); + +void spider_free_mem( + SPIDER_TRX *trx, + void *ptr, + myf my_flags +); + +void *spider_alloc_mem( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + size_t size, + myf my_flags +); + +void *spider_bulk_alloc_mem( + SPIDER_TRX *trx, + uint id, + const char *func_name, + const char *file_name, + ulong line_no, + myf my_flags, + ... +); diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc new file mode 100644 index 00000000000..22b15d41b95 --- /dev/null +++ b/storage/spider/spd_param.cc @@ -0,0 +1,2933 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#endif +#include +#include "spd_err.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_table.h" +#include "spd_trx.h" + +extern struct st_mysql_plugin spider_i_s_alloc_mem; + +extern volatile ulonglong spider_mon_table_cache_version; +extern volatile ulonglong spider_mon_table_cache_version_req; + +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +static int spider_direct_update(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_direct_update"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->direct_update_count; + DBUG_RETURN(error_num); +} + +static int spider_direct_delete(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_direct_delete"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->direct_delete_count; + DBUG_RETURN(error_num); +} +#endif + +static int spider_direct_order_limit(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_direct_order_limit"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->direct_order_limit_count; + DBUG_RETURN(error_num); +} + +static int spider_direct_aggregate(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_direct_aggregate"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->direct_aggregate_count; + DBUG_RETURN(error_num); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +static int spider_hs_result_free(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_hs_result_free"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->hs_result_free_count; + DBUG_RETURN(error_num); +} +#endif + +struct st_mysql_show_var spider_status_variables[] = +{ + {"Spider_mon_table_cache_version", + (char *) &spider_mon_table_cache_version, SHOW_LONGLONG}, + {"Spider_mon_table_cache_version_req", + (char *) &spider_mon_table_cache_version_req, SHOW_LONGLONG}, +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +#ifdef SPIDER_HAS_SHOW_SIMPLE_FUNC + {"Spider_direct_update", (char *) &spider_direct_update, SHOW_SIMPLE_FUNC}, + {"Spider_direct_delete", (char *) &spider_direct_delete, SHOW_SIMPLE_FUNC}, +#else + {"Spider_direct_update", (char *) &spider_direct_update, SHOW_FUNC}, + {"Spider_direct_delete", (char *) &spider_direct_delete, SHOW_FUNC}, +#endif +#endif +#ifdef SPIDER_HAS_SHOW_SIMPLE_FUNC + {"Spider_direct_order_limit", + (char *) &spider_direct_order_limit, SHOW_SIMPLE_FUNC}, + {"Spider_direct_aggregate", + (char *) &spider_direct_aggregate, SHOW_SIMPLE_FUNC}, +#else + {"Spider_direct_order_limit", + (char *) &spider_direct_order_limit, SHOW_FUNC}, + {"Spider_direct_aggregate", + (char *) &spider_direct_aggregate, SHOW_FUNC}, +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef SPIDER_HAS_SHOW_SIMPLE_FUNC + {"Spider_hs_result_free", (char *) &spider_hs_result_free, SHOW_SIMPLE_FUNC}, +#else + {"Spider_hs_result_free", (char *) &spider_hs_result_free, SHOW_FUNC}, +#endif +#endif + {NullS, NullS, SHOW_LONG} +}; + +typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int); +#if MYSQL_VERSION_ID < 50500 +extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd, + const char *name, long long val); +#else +extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, + bool is_unsignd, longlong v); +#endif + +static my_bool spider_support_xa; +static MYSQL_SYSVAR_BOOL( + support_xa, + spider_support_xa, + PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, + "XA support", + NULL, + NULL, + TRUE +); + +my_bool spider_param_support_xa() +{ + DBUG_ENTER("spider_param_support_xa"); + DBUG_RETURN(spider_support_xa); +} + +static my_bool spider_connect_mutex; +static MYSQL_SYSVAR_BOOL( + connect_mutex, + spider_connect_mutex, + PLUGIN_VAR_OPCMDARG, + "Use mutex at connecting", + NULL, + NULL, + FALSE +); + +my_bool spider_param_connect_mutex() +{ + DBUG_ENTER("spider_param_connect_mutex"); + DBUG_RETURN(spider_connect_mutex); +} + +static uint spider_table_init_error_interval; +/* + 0-: interval + */ +static MYSQL_SYSVAR_UINT( + table_init_error_interval, + spider_table_init_error_interval, + PLUGIN_VAR_RQCMDARG, + "Return same error code until interval passes if table init is failed", + NULL, + NULL, + 1, + 0, + 4294967295U, + 0 +); + +uint spider_param_table_init_error_interval() +{ + DBUG_ENTER("spider_param_table_init_error_interval"); + DBUG_RETURN(spider_table_init_error_interval); +} + +static int spider_use_table_charset; +/* + -1 :use table parameter + 0 :use utf8 + 1 :use table charset + */ +static MYSQL_SYSVAR_INT( + use_table_charset, + spider_use_table_charset, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Use table charset for remote access", + NULL, + NULL, + -1, + -1, + 1, + 0 +); + +int spider_param_use_table_charset( + int use_table_charset +) { + DBUG_ENTER("spider_param_use_table_charset"); + DBUG_RETURN(spider_use_table_charset == -1 ? + use_table_charset : spider_use_table_charset); +} + +/* + 0: no recycle + 1: recycle in instance + 2: recycle in thread + */ +static MYSQL_THDVAR_UINT( + conn_recycle_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Connection recycle mode", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 2, /* max */ + 0 /* blk */ +); + +uint spider_param_conn_recycle_mode( + THD *thd +) { + DBUG_ENTER("spider_param_conn_recycle_mode"); + DBUG_RETURN(THDVAR(thd, conn_recycle_mode)); +} + +/* + 0: weak + 1: strict + */ +static MYSQL_THDVAR_UINT( + conn_recycle_strict, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Strict connection recycle", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +uint spider_param_conn_recycle_strict( + THD *thd +) { + DBUG_ENTER("spider_param_conn_recycle_strict"); + DBUG_RETURN(THDVAR(thd, conn_recycle_strict)); +} + +/* + FALSE: no sync + TRUE: sync + */ +static MYSQL_THDVAR_BOOL( + sync_trx_isolation, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Sync transaction isolation level", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +bool spider_param_sync_trx_isolation( + THD *thd +) { + DBUG_ENTER("spider_param_sync_trx_isolation"); + DBUG_RETURN(THDVAR(thd, sync_trx_isolation)); +} + +/* + FALSE: no use + TRUE: use + */ +static MYSQL_THDVAR_BOOL( + use_consistent_snapshot, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Use start transaction with consistent snapshot", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_use_consistent_snapshot( + THD *thd +) { + DBUG_ENTER("spider_param_use_consistent_snapshot"); + DBUG_RETURN(THDVAR(thd, use_consistent_snapshot)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + internal_xa, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Use inner xa transaction", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_internal_xa( + THD *thd +) { + DBUG_ENTER("spider_param_internal_xa"); + DBUG_RETURN(THDVAR(thd, internal_xa)); +} + +/* + 0 :err when use a spider table + 1 :err when start trx + 2 :start trx with snapshot on remote server(not use xa) + 3 :start xa on remote server(not use trx with snapshot) + */ +static MYSQL_THDVAR_UINT( + internal_xa_snapshot, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Action of inner xa and snapshot both using", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 3, /* max */ + 0 /* blk */ +); + +uint spider_param_internal_xa_snapshot( + THD *thd +) { + DBUG_ENTER("spider_param_internal_xa_snapshot"); + DBUG_RETURN(THDVAR(thd, internal_xa_snapshot)); +} + +/* + 0 :off + 1 :continue prepare, commit, rollback if xid not found return + 2 :continue prepare, commit, rollback if all error return + */ +static MYSQL_THDVAR_UINT( + force_commit, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Force prepare, commit, rollback mode", /* comment */ + NULL, /* check */ + NULL, /* update */ + 1, /* def */ + 0, /* min */ + 2, /* max */ + 0 /* blk */ +); + +uint spider_param_force_commit( + THD *thd +) { + DBUG_ENTER("spider_param_force_commit"); + DBUG_RETURN(THDVAR(thd, force_commit)); +} + +/* + -1 :use table parameter + 0-:offset + */ +static MYSQL_THDVAR_LONGLONG( + internal_offset, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Internal offset", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_internal_offset( + THD *thd, + longlong internal_offset +) { + DBUG_ENTER("spider_param_internal_offset"); + DBUG_RETURN(THDVAR(thd, internal_offset) < 0 ? + internal_offset : THDVAR(thd, internal_offset)); +} + +/* + -1 :use table parameter + 0-:limit + */ +static MYSQL_THDVAR_LONGLONG( + internal_limit, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Internal limit", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_internal_limit( + THD *thd, + longlong internal_limit +) { + DBUG_ENTER("spider_param_internal_limit"); + DBUG_RETURN(THDVAR(thd, internal_limit) < 0 ? + internal_limit : THDVAR(thd, internal_limit)); +} + +/* + -1 :use table parameter + 0-:number of rows at a select + */ +static MYSQL_THDVAR_LONGLONG( + split_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of rows at a select", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_split_read( + THD *thd, + longlong split_read +) { + DBUG_ENTER("spider_param_split_read"); + DBUG_RETURN(THDVAR(thd, split_read) < 0 ? + split_read : THDVAR(thd, split_read)); +} + +/* + -1 :use table parameter + 0 :doesn't use "offset" and "limit" for "split_read" + 1-:magnification + */ +static MYSQL_THDVAR_INT( + semi_split_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use offset and limit parameter in SQL for split_read parameter.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_semi_split_read( + THD *thd, + double semi_split_read +) { + DBUG_ENTER("spider_param_semi_split_read"); + DBUG_RETURN(THDVAR(thd, semi_split_read) < 0 ? + semi_split_read : THDVAR(thd, semi_split_read)); +} + +/* + -1 :use table parameter + 0-:the limit value + */ +static MYSQL_THDVAR_LONGLONG( + semi_split_read_limit, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The limit value for semi_split_read", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_semi_split_read_limit( + THD *thd, + longlong semi_split_read_limit +) { + DBUG_ENTER("spider_param_semi_split_read_limit"); + DBUG_RETURN(THDVAR(thd, semi_split_read_limit) < 0 ? + semi_split_read_limit : THDVAR(thd, semi_split_read_limit)); +} + +/* + -1 :use table parameter + 0 :no alloc + 1-:alloc size + */ +static MYSQL_THDVAR_INT( + init_sql_alloc_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Initial sql string alloc size", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_init_sql_alloc_size( + THD *thd, + int init_sql_alloc_size +) { + DBUG_ENTER("spider_param_init_sql_alloc_size"); + DBUG_RETURN(THDVAR(thd, init_sql_alloc_size) < 0 ? + init_sql_alloc_size : THDVAR(thd, init_sql_alloc_size)); +} + +/* + -1 :use table parameter + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + reset_sql_alloc, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Reset sql string alloc after execute", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_reset_sql_alloc( + THD *thd, + int reset_sql_alloc +) { + DBUG_ENTER("spider_param_reset_sql_alloc"); + DBUG_RETURN(THDVAR(thd, reset_sql_alloc) < 0 ? + reset_sql_alloc : THDVAR(thd, reset_sql_alloc)); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +/* + -1 :use table parameter + 0-:result free size for handlersocket + */ +static MYSQL_THDVAR_LONGLONG( + hs_result_free_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Result free size for handlersocket", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_hs_result_free_size( + THD *thd, + longlong hs_result_free_size +) { + DBUG_ENTER("spider_param_hs_result_free_size"); + DBUG_RETURN(THDVAR(thd, hs_result_free_size) < 0 ? + hs_result_free_size : THDVAR(thd, hs_result_free_size)); +} +#endif + +/* + -1 :use table parameter + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + multi_split_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Sprit read mode for multi range", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_multi_split_read( + THD *thd, + int multi_split_read +) { + DBUG_ENTER("spider_param_multi_split_read"); + DBUG_RETURN(THDVAR(thd, multi_split_read) < 0 ? + multi_split_read : THDVAR(thd, multi_split_read)); +} + +/* + -1 :use table parameter + 0-:max order columns + */ +static MYSQL_THDVAR_INT( + max_order, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Max columns for order by", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 32767, /* max */ + 0 /* blk */ +); + +int spider_param_max_order( + THD *thd, + int max_order +) { + DBUG_ENTER("spider_param_max_order"); + DBUG_RETURN(THDVAR(thd, max_order) < 0 ? + max_order : THDVAR(thd, max_order)); +} + +/* + -1 :off + 0 :read uncommitted + 1 :read committed + 2 :repeatable read + 3 :serializable + */ +static MYSQL_THDVAR_INT( + semi_trx_isolation, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Transaction isolation level during execute a sql", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_semi_trx_isolation( + THD *thd +) { + DBUG_ENTER("spider_param_semi_trx_isolation"); + DBUG_RETURN(THDVAR(thd, semi_trx_isolation)); +} + +static int spider_param_semi_table_lock_check( + MYSQL_THD thd, + struct st_mysql_sys_var *var, + void *save, + struct st_mysql_value *value +) { + int error_num; + SPIDER_TRX *trx; + my_bool fixed; + long long tmp; + struct my_option options; + DBUG_ENTER("spider_param_semi_table_lock_check"); + if (!(trx = spider_get_trx((THD *) thd, TRUE, &error_num))) + DBUG_RETURN(error_num); + if (trx->locked_connections) + { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM); + } + value->val_int(value, &tmp); + options.sub_size = 0; + options.var_type = GET_INT; + options.def_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->def_val; + options.min_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->min_val; + options.max_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->max_val; + options.block_size = + (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; + options.arg_type = REQUIRED_ARG; + *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); +#if MYSQL_VERSION_ID < 50500 + DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); +#else + DBUG_RETURN(throw_bounds_warning(thd, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, + (longlong) tmp)); +#endif +} + +/* + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + semi_table_lock, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Table lock during execute a sql", /* comment */ + &spider_param_semi_table_lock_check, /* check */ + NULL, /* update */ + 1, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_semi_table_lock( + THD *thd, + int semi_table_lock +) { + DBUG_ENTER("spider_param_semi_table_lock"); + DBUG_RETURN((semi_table_lock & THDVAR(thd, semi_table_lock))); +} + +static int spider_param_semi_table_lock_connection_check( + MYSQL_THD thd, + struct st_mysql_sys_var *var, + void *save, + struct st_mysql_value *value +) { + int error_num; + SPIDER_TRX *trx; + my_bool fixed; + long long tmp; + struct my_option options; + DBUG_ENTER("spider_param_semi_table_lock_connection_check"); + if (!(trx = spider_get_trx((THD *) thd, TRUE, &error_num))) + DBUG_RETURN(error_num); + if (trx->locked_connections) + { + my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM, + ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM); + } + value->val_int(value, &tmp); + options.sub_size = 0; + options.var_type = GET_INT; + options.def_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->def_val; + options.min_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->min_val; + options.max_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->max_val; + options.block_size = + (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz; + options.arg_type = REQUIRED_ARG; + *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed); +#if MYSQL_VERSION_ID < 50500 + DBUG_RETURN(throw_bounds_warning(thd, fixed, FALSE, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, (long long) tmp)); +#else + DBUG_RETURN(throw_bounds_warning(thd, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, + (longlong) tmp)); +#endif +} + +/* + -1 :off + 0 :use same connection + 1 :use different connection + */ +static MYSQL_THDVAR_INT( + semi_table_lock_connection, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use different connection if semi_table_lock is enabled", /* comment */ + &spider_param_semi_table_lock_connection_check, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_semi_table_lock_connection( + THD *thd, + int semi_table_lock_connection +) { + DBUG_ENTER("spider_param_semi_table_lock_connection"); + DBUG_RETURN(THDVAR(thd, semi_table_lock_connection) == -1 ? + semi_table_lock_connection : THDVAR(thd, semi_table_lock_connection)); +} + +/* + 0-:block_size + */ +static MYSQL_THDVAR_UINT( + block_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Index block size", /* comment */ + NULL, /* check */ + NULL, /* update */ + 16384, /* def */ + 0, /* min */ + 4294967295U, /* max */ + 0 /* blk */ +); + +uint spider_param_block_size( + THD *thd +) { + DBUG_ENTER("spider_param_block_size"); + DBUG_RETURN(THDVAR(thd, block_size)); +} + +/* + -1 :use table parameter + 0 :off + 1 :lock in share mode + 2 :for update + */ +static MYSQL_THDVAR_INT( + selupd_lock_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Lock for select with update", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_selupd_lock_mode( + THD *thd, + int selupd_lock_mode +) { + DBUG_ENTER("spider_param_selupd_lock_mode"); + DBUG_RETURN(THDVAR(thd, selupd_lock_mode) == -1 ? + selupd_lock_mode : THDVAR(thd, selupd_lock_mode)); +} + +/* + FALSE: no sync + TRUE: sync + */ +static MYSQL_THDVAR_BOOL( + sync_autocommit, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Sync autocommit", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +bool spider_param_sync_autocommit( + THD *thd +) { + DBUG_ENTER("spider_param_sync_autocommit"); + DBUG_RETURN(THDVAR(thd, sync_autocommit)); +} + +/* + FALSE: no sync + TRUE: sync + */ +static MYSQL_THDVAR_BOOL( + sync_time_zone, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Sync time_zone", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_sync_time_zone( + THD *thd +) { + DBUG_ENTER("spider_param_sync_time_zone"); + DBUG_RETURN(THDVAR(thd, sync_time_zone)); +} + +/* + FALSE: not use + TRUE: use + */ +static MYSQL_THDVAR_BOOL( + use_default_database, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Use default database", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +bool spider_param_use_default_database( + THD *thd +) { + DBUG_ENTER("spider_param_use_default_database"); + DBUG_RETURN(THDVAR(thd, use_default_database)); +} + +/* + FALSE: sql_log_off = 0 + TRUE: sql_log_off = 1 + */ +static MYSQL_THDVAR_BOOL( + internal_sql_log_off, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Sync sql_log_off", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +bool spider_param_internal_sql_log_off( + THD *thd +) { + DBUG_ENTER("spider_param_internal_sql_log_off"); + DBUG_RETURN(THDVAR(thd, internal_sql_log_off)); +} + +/* + -1 :use table parameter + 0-:bulk insert size + */ +static MYSQL_THDVAR_INT( + bulk_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Bulk insert size", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_bulk_size( + THD *thd, + int bulk_size +) { + DBUG_ENTER("spider_param_bulk_size"); + DBUG_RETURN(THDVAR(thd, bulk_size) < 0 ? + bulk_size : THDVAR(thd, bulk_size)); +} + +/* + -1 :use table parameter + 0 : Send "update" and "delete" statements one by one. + 1 : Send collected multiple "update" and "delete" statements. + (Collected statements are sent one by one) + 2 : Send collected multiple "update" and "delete" statements. + (Collected statements are sent together) + */ +static MYSQL_THDVAR_INT( + bulk_update_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The mode of bulk updating and deleting", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_bulk_update_mode( + THD *thd, + int bulk_update_mode +) { + DBUG_ENTER("spider_param_bulk_update_mode"); + DBUG_RETURN(THDVAR(thd, bulk_update_mode) == -1 ? + bulk_update_mode : THDVAR(thd, bulk_update_mode)); +} + +/* + -1 :use table parameter + 0-:bulk update size + */ +static MYSQL_THDVAR_INT( + bulk_update_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Bulk update size", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_bulk_update_size( + THD *thd, + int bulk_update_size +) { + DBUG_ENTER("spider_param_bulk_update_size"); + DBUG_RETURN(THDVAR(thd, bulk_update_size) == -1 ? + bulk_update_size : THDVAR(thd, bulk_update_size)); +} + +/* + -1 :use table parameter + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + internal_optimize, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Execute optimize to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_internal_optimize( + THD *thd, + int internal_optimize +) { + DBUG_ENTER("spider_param_internal_optimize"); + DBUG_RETURN(THDVAR(thd, internal_optimize) == -1 ? + internal_optimize : THDVAR(thd, internal_optimize)); +} + +/* + -1 :use table parameter + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + internal_optimize_local, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Execute optimize to remote server with local", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_internal_optimize_local( + THD *thd, + int internal_optimize_local +) { + DBUG_ENTER("spider_param_internal_optimize_local"); + DBUG_RETURN(THDVAR(thd, internal_optimize_local) == -1 ? + internal_optimize_local : THDVAR(thd, internal_optimize_local)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + use_flash_logs, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Execute flush logs to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_use_flash_logs( + THD *thd +) { + DBUG_ENTER("spider_param_use_flash_logs"); + DBUG_RETURN(THDVAR(thd, use_flash_logs)); +} + +/* + 0 :off + 1 :flush tables with read lock + 2 :flush tables another connection + */ +static MYSQL_THDVAR_INT( + use_snapshot_with_flush_tables, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Execute optimize to remote server with local", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_use_snapshot_with_flush_tables( + THD *thd +) { + DBUG_ENTER("spider_param_use_snapshot_with_flush_tables"); + DBUG_RETURN(THDVAR(thd, use_snapshot_with_flush_tables)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + use_all_conns_snapshot, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "When start trx with snapshot, it send to all connections", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_use_all_conns_snapshot( + THD *thd +) { + DBUG_ENTER("spider_param_use_all_conns_snapshot"); + DBUG_RETURN(THDVAR(thd, use_all_conns_snapshot)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + lock_exchange, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Exchange select lock to lock tables", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_lock_exchange( + THD *thd +) { + DBUG_ENTER("spider_param_lock_exchange"); + DBUG_RETURN(THDVAR(thd, lock_exchange)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + internal_unlock, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Unlock tables for using connections in sql", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_internal_unlock( + THD *thd +) { + DBUG_ENTER("spider_param_internal_unlock"); + DBUG_RETURN(THDVAR(thd, internal_unlock)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + semi_trx, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Take a transaction during execute a sql", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +bool spider_param_semi_trx( + THD *thd +) { + DBUG_ENTER("spider_param_semi_trx"); + DBUG_RETURN(THDVAR(thd, semi_trx)); +} + +/* + -1 :use table parameter + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + connect_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout of connecting to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_connect_timeout( + THD *thd, + int connect_timeout +) { + DBUG_ENTER("spider_param_connect_timeout"); + if (thd) + DBUG_RETURN(THDVAR(thd, connect_timeout) == -1 ? + connect_timeout : THDVAR(thd, connect_timeout)); + DBUG_RETURN(connect_timeout); +} + +/* + -1 :use table parameter + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + net_read_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout of receiving data from remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_net_read_timeout( + THD *thd, + int net_read_timeout +) { + DBUG_ENTER("spider_param_net_read_timeout"); + if (thd) + DBUG_RETURN(THDVAR(thd, net_read_timeout) == -1 ? + net_read_timeout : THDVAR(thd, net_read_timeout)); + DBUG_RETURN(net_read_timeout); +} + +/* + -1 :use table parameter + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + net_write_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout of sending data to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_net_write_timeout( + THD *thd, + int net_write_timeout +) { + DBUG_ENTER("spider_param_net_write_timeout"); + if (thd) + DBUG_RETURN(THDVAR(thd, net_write_timeout) == -1 ? + net_write_timeout : THDVAR(thd, net_write_timeout)); + DBUG_RETURN(net_write_timeout); +} + +/* + -1 :use table parameter + 0 :It acquires it collectively. + 1 :Acquisition one by one.If it discontinues once, and it will need + it later, it retrieves it again when there is interrupt on the way. + 2 :Acquisition one by one.Interrupt is waited for until end of getting + result when there is interrupt on the way. + */ +static MYSQL_THDVAR_INT( + quick_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The retrieval result from a remote server is acquired by acquisition one by one", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_quick_mode( + THD *thd, + int quick_mode +) { + DBUG_ENTER("spider_param_quick_mode"); + DBUG_RETURN(THDVAR(thd, quick_mode) < 0 ? + quick_mode : THDVAR(thd, quick_mode)); +} + +/* + -1 :use table parameter + 0-:number of records + */ +static MYSQL_THDVAR_LONGLONG( + quick_page_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of records in a page when acquisition one by one", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_quick_page_size( + THD *thd, + longlong quick_page_size +) { + DBUG_ENTER("spider_param_quick_page_size"); + DBUG_RETURN(THDVAR(thd, quick_page_size) < 0 ? + quick_page_size : THDVAR(thd, quick_page_size)); +} + +/* + -1 :use table parameter + 0 :It doesn't use low memory mode. + 1 :It uses low memory mode. + */ +static MYSQL_THDVAR_INT( + low_mem_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use low memory mode when SQL(SELECT) internally issued to a remote server is executed and get a result list", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_low_mem_read( + THD *thd, + int low_mem_read +) { + DBUG_ENTER("spider_param_low_mem_read"); + DBUG_RETURN(THDVAR(thd, low_mem_read) < 0 ? + low_mem_read : THDVAR(thd, low_mem_read)); +} + +/* + -1 :use table parameter + 0 :Use index columns if select statement can solve by using index, + otherwise use all columns. + 1 :Use columns that are judged necessary. + */ +static MYSQL_THDVAR_INT( + select_column_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The mode of using columns at select clause", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_select_column_mode( + THD *thd, + int select_column_mode +) { + DBUG_ENTER("spider_param_select_column_mode"); + DBUG_RETURN(THDVAR(thd, select_column_mode) == -1 ? + select_column_mode : THDVAR(thd, select_column_mode)); +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +/* + -1 :use table parameter + 0 :background search is disabled + 1 :background search is used if search with no lock + 2 :background search is used if search with no lock or shared lock + 3 :background search is used regardless of the lock + */ +static MYSQL_THDVAR_INT( + bgs_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of background search", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_bgs_mode( + THD *thd, + int bgs_mode +) { + DBUG_ENTER("spider_param_bgs_mode"); + DBUG_RETURN(THDVAR(thd, bgs_mode) < 0 ? + bgs_mode : THDVAR(thd, bgs_mode)); +} + +/* + -1 :use table parameter + 0 :records is gotten usually + 1-:number of records + */ +static MYSQL_THDVAR_LONGLONG( + bgs_first_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of first read records when background search is used", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_bgs_first_read( + THD *thd, + longlong bgs_first_read +) { + DBUG_ENTER("spider_param_bgs_first_read"); + DBUG_RETURN(THDVAR(thd, bgs_first_read) < 0 ? + bgs_first_read : THDVAR(thd, bgs_first_read)); +} + +/* + -1 :use table parameter + 0 :records is gotten usually + 1-:number of records + */ +static MYSQL_THDVAR_LONGLONG( + bgs_second_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of second read records when background search is used", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_bgs_second_read( + THD *thd, + longlong bgs_second_read +) { + DBUG_ENTER("spider_param_bgs_second_read"); + DBUG_RETURN(THDVAR(thd, bgs_second_read) < 0 ? + bgs_second_read : THDVAR(thd, bgs_second_read)); +} +#endif + +/* + -1 :use table parameter + 0 :records is gotten usually + 1-:number of records + */ +static MYSQL_THDVAR_LONGLONG( + first_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of first read records", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_first_read( + THD *thd, + longlong first_read +) { + DBUG_ENTER("spider_param_first_read"); + DBUG_RETURN(THDVAR(thd, first_read) < 0 ? + first_read : THDVAR(thd, first_read)); +} + +/* + -1 :use table parameter + 0 :records is gotten usually + 1-:number of records + */ +static MYSQL_THDVAR_LONGLONG( + second_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of second read records", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_second_read( + THD *thd, + longlong second_read +) { + DBUG_ENTER("spider_param_second_read"); + DBUG_RETURN(THDVAR(thd, second_read) < 0 ? + second_read : THDVAR(thd, second_read)); +} + +/* + -1 :use table parameter + 0 :always get the newest information + 1-:interval + */ +static MYSQL_THDVAR_INT( + crd_interval, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Interval of cardinality confirmation.(second)", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_crd_interval( + THD *thd, + double crd_interval +) { + DBUG_ENTER("spider_param_crd_interval"); + DBUG_RETURN(THDVAR(thd, crd_interval) == -1 ? + crd_interval : THDVAR(thd, crd_interval)); +} + +/* + -1 :use table parameter + 0 :use table parameter + 1 :use show command + 2 :use information schema + 3 :use explain + */ +static MYSQL_THDVAR_INT( + crd_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of cardinality confirmation.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_crd_mode( + THD *thd, + int crd_mode +) { + DBUG_ENTER("spider_param_crd_mode"); + DBUG_RETURN(THDVAR(thd, crd_mode) <= 0 ? + crd_mode : THDVAR(thd, crd_mode)); +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +/* + -1 :use table parameter + 0 :No synchronization. + 1 :Cardinality is synchronized when opening a table. + Then no synchronization. + 2 :Synchronization. + */ +static MYSQL_THDVAR_INT( + crd_sync, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Cardinality synchronization in partitioned table.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_crd_sync( + THD *thd, + int crd_sync +) { + DBUG_ENTER("spider_param_crd_sync"); + DBUG_RETURN(THDVAR(thd, crd_sync) == -1 ? + crd_sync : THDVAR(thd, crd_sync)); +} +#endif + +/* + -1 :use table parameter + 0 :The crd_weight is used as a fixed value. + 1 :The crd_weight is used as an addition value. + 2 :The crd_weight is used as a multiplication value. + */ +static MYSQL_THDVAR_INT( + crd_type, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Type of cardinality calculation.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_crd_type( + THD *thd, + int crd_type +) { + DBUG_ENTER("spider_param_crd_type"); + DBUG_RETURN(THDVAR(thd, crd_type) == -1 ? + crd_type : THDVAR(thd, crd_type)); +} + +/* + -1 :use table parameter + 0-:weight + */ +static MYSQL_THDVAR_INT( + crd_weight, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Weight coefficient to calculate effectiveness of index from cardinality of column.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_crd_weight( + THD *thd, + double crd_weight +) { + DBUG_ENTER("spider_param_crd_weight"); + DBUG_RETURN(THDVAR(thd, crd_weight) == -1 ? + crd_weight : THDVAR(thd, crd_weight)); +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +/* + -1 :use table parameter + 0 :Background confirmation is disabled + 1 :Background confirmation is enabled + */ +static MYSQL_THDVAR_INT( + crd_bg_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of cardinality confirmation at background.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_crd_bg_mode( + THD *thd, + int crd_bg_mode +) { + DBUG_ENTER("spider_param_crd_bg_mode"); + DBUG_RETURN(THDVAR(thd, crd_bg_mode) == -1 ? + crd_bg_mode : THDVAR(thd, crd_bg_mode)); +} +#endif + +/* + -1 :use table parameter + 0 :always get the newest information + 1-:interval + */ +static MYSQL_THDVAR_INT( + sts_interval, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Interval of table state confirmation.(second)", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_sts_interval( + THD *thd, + double sts_interval +) { + DBUG_ENTER("spider_param_sts_interval"); + DBUG_RETURN(THDVAR(thd, sts_interval) == -1 ? + sts_interval : THDVAR(thd, sts_interval)); +} + +/* + -1 :use table parameter + 0 :use table parameter + 1 :use show command + 2 :use information schema + */ +static MYSQL_THDVAR_INT( + sts_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of table state confirmation.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_sts_mode( + THD *thd, + int sts_mode +) { + DBUG_ENTER("spider_param_sts_mode"); + DBUG_RETURN(THDVAR(thd, sts_mode) <= 0 ? + sts_mode : THDVAR(thd, sts_mode)); +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +/* + -1 :use table parameter + 0 :No synchronization. + 1 :Table state is synchronized when opening a table. + Then no synchronization. + 2 :Synchronization. + */ +static MYSQL_THDVAR_INT( + sts_sync, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Table state synchronization in partitioned table.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_sts_sync( + THD *thd, + int sts_sync +) { + DBUG_ENTER("spider_param_sts_sync"); + DBUG_RETURN(THDVAR(thd, sts_sync) == -1 ? + sts_sync : THDVAR(thd, sts_sync)); +} +#endif + +#ifndef WITHOUT_SPIDER_BG_SEARCH +/* + -1 :use table parameter + 0 :Background confirmation is disabled + 1 :Background confirmation is enabled + */ +static MYSQL_THDVAR_INT( + sts_bg_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of table state confirmation at background.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_sts_bg_mode( + THD *thd, + int sts_bg_mode +) { + DBUG_ENTER("spider_param_sts_bg_mode"); + DBUG_RETURN(THDVAR(thd, sts_bg_mode) == -1 ? + sts_bg_mode : THDVAR(thd, sts_bg_mode)); +} +#endif + +/* + 0 :always ping + 1-:interval + */ +static MYSQL_THDVAR_INT( + ping_interval_at_trx_start, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Ping interval at transaction start", /* comment */ + NULL, /* check */ + NULL, /* update */ + 3600, /* def */ + 0, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_ping_interval_at_trx_start( + THD *thd +) { + DBUG_ENTER("spider_param_ping_interval_at_trx_start"); + DBUG_RETURN(THDVAR(thd, ping_interval_at_trx_start)); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +/* + 0 :always ping + 1-:interval + */ +static MYSQL_THDVAR_INT( + hs_ping_interval, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Ping interval for handlersocket", /* comment */ + NULL, /* check */ + NULL, /* update */ + 30, /* def */ + 0, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +double spider_param_hs_ping_interval( + THD *thd +) { + DBUG_ENTER("spider_param_hs_ping_interval"); + DBUG_RETURN(THDVAR(thd, hs_ping_interval)); +} +#endif + +/* + -1 :use table parameter + 0 :normal mode + 1 :quick mode + 2 :set 0 value + */ +static MYSQL_THDVAR_INT( + auto_increment_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of auto increment.", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_auto_increment_mode( + THD *thd, + int auto_increment_mode +) { + DBUG_ENTER("spider_param_auto_increment_mode"); + DBUG_RETURN(THDVAR(thd, auto_increment_mode) == -1 ? + auto_increment_mode : THDVAR(thd, auto_increment_mode)); +} + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + same_server_link, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Permit to link same server's table", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_same_server_link( + THD *thd +) { + DBUG_ENTER("spider_param_same_server_link"); + DBUG_RETURN(THDVAR(thd, same_server_link)); +} + +/* + FALSE: transmits + TRUE: don't transmit + */ +static MYSQL_THDVAR_BOOL( + local_lock_table, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Remote server transmission when lock tables is executed at local", + /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +bool spider_param_local_lock_table( + THD *thd +) { + DBUG_ENTER("spider_param_local_lock_table"); + DBUG_RETURN(THDVAR(thd, local_lock_table)); +} + +/* + -1 :use table parameter + 0 :don't transmit + 1 :transmits + */ +static MYSQL_THDVAR_INT( + use_pushdown_udf, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Remote server transmission existence when UDF is used at condition and \"engine_condition_pushdown=1\"", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_use_pushdown_udf( + THD *thd, + int use_pushdown_udf +) { + DBUG_ENTER("spider_param_use_pushdown_udf"); + DBUG_RETURN(THDVAR(thd, use_pushdown_udf) == -1 ? + use_pushdown_udf : THDVAR(thd, use_pushdown_udf)); +} + +/* + -1 :use table parameter + 0 :duplicate check on local server + 1 :avoid duplicate check on local server + */ +static MYSQL_THDVAR_INT( + direct_dup_insert, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Execute \"REPLACE\" and \"INSERT IGNORE\" on remote server and avoid duplicate check on local server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_direct_dup_insert( + THD *thd, + int direct_dup_insert +) { + DBUG_ENTER("spider_param_direct_dup_insert"); + DBUG_RETURN(THDVAR(thd, direct_dup_insert) < 0 ? + direct_dup_insert : THDVAR(thd, direct_dup_insert)); +} + +static uint spider_udf_table_lock_mutex_count; +/* + 1-: mutex count + */ +static MYSQL_SYSVAR_UINT( + udf_table_lock_mutex_count, + spider_udf_table_lock_mutex_count, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Mutex count of table lock for Spider UDFs", + NULL, + NULL, + 20, + 1, + 4294967295U, + 0 +); + +uint spider_param_udf_table_lock_mutex_count() +{ + DBUG_ENTER("spider_param_udf_table_lock_mutex_count"); + DBUG_RETURN(spider_udf_table_lock_mutex_count); +} + +static uint spider_udf_table_mon_mutex_count; +/* + 1-: mutex count + */ +static MYSQL_SYSVAR_UINT( + udf_table_mon_mutex_count, + spider_udf_table_mon_mutex_count, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Mutex count of table mon for Spider UDFs", + NULL, + NULL, + 20, + 1, + 4294967295U, + 0 +); + +uint spider_param_udf_table_mon_mutex_count() +{ + DBUG_ENTER("spider_param_udf_table_mon_mutex_count"); + DBUG_RETURN(spider_udf_table_mon_mutex_count); +} + +/* + 1-:number of rows + */ +static MYSQL_THDVAR_LONGLONG( + udf_ds_bulk_insert_rows, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Number of rows for bulk inserting", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_udf_ds_bulk_insert_rows( + THD *thd, + longlong udf_ds_bulk_insert_rows +) { + DBUG_ENTER("spider_param_udf_ds_bulk_insert_rows"); + DBUG_RETURN(THDVAR(thd, udf_ds_bulk_insert_rows) <= 0 ? + udf_ds_bulk_insert_rows : THDVAR(thd, udf_ds_bulk_insert_rows)); +} + +/* + -1 :use table parameter + 0 :drop records + 1 :insert last table + 2 :insert first table and loop again + */ +static MYSQL_THDVAR_INT( + udf_ds_table_loop_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Table loop mode if the number of tables in table list are less than the number of result sets", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +int spider_param_udf_ds_table_loop_mode( + THD *thd, + int udf_ds_table_loop_mode +) { + DBUG_ENTER("spider_param_udf_ds_table_loop_mode"); + DBUG_RETURN(THDVAR(thd, udf_ds_table_loop_mode) == -1 ? + udf_ds_table_loop_mode : THDVAR(thd, udf_ds_table_loop_mode)); +} + +static char *spider_remote_access_charset; +/* + */ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +static MYSQL_SYSVAR_STR( + remote_access_charset, + spider_remote_access_charset, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote access charset at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +#ifdef PLUGIN_VAR_CAN_MEMALLOC +static MYSQL_SYSVAR_STR( + remote_access_charset, + spider_remote_access_charset, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote access charset at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +static MYSQL_SYSVAR_STR( + remote_access_charset, + spider_remote_access_charset, + PLUGIN_VAR_RQCMDARG, + "Set remote access charset at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#endif +#endif + +char *spider_param_remote_access_charset() +{ + DBUG_ENTER("spider_param_remote_access_charset"); + DBUG_RETURN(spider_remote_access_charset); +} + +static int spider_remote_autocommit; +/* + -1 :don't set + 0 :autocommit = 0 + 1 :autocommit = 1 + */ +static MYSQL_SYSVAR_INT( + remote_autocommit, + spider_remote_autocommit, + PLUGIN_VAR_RQCMDARG, + "Set autocommit mode at connecting for improvement performance of connection if you know", + NULL, + NULL, + -1, + -1, + 1, + 0 +); + +int spider_param_remote_autocommit() +{ + DBUG_ENTER("spider_param_remote_autocommit"); + DBUG_RETURN(spider_remote_autocommit); +} + +static char *spider_remote_time_zone; +/* + */ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +static MYSQL_SYSVAR_STR( + remote_time_zone, + spider_remote_time_zone, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote time_zone at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +#ifdef PLUGIN_VAR_CAN_MEMALLOC +static MYSQL_SYSVAR_STR( + remote_time_zone, + spider_remote_time_zone, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote time_zone at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +static MYSQL_SYSVAR_STR( + remote_time_zone, + spider_remote_time_zone, + PLUGIN_VAR_RQCMDARG, + "Set remote time_zone at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#endif +#endif + +char *spider_param_remote_time_zone() +{ + DBUG_ENTER("spider_param_remote_time_zone"); + DBUG_RETURN(spider_remote_time_zone); +} + +static int spider_remote_sql_log_off; +/* + -1 :don't set + 0 :sql_log_off = 0 + 1 :sql_log_off = 1 + */ +static MYSQL_SYSVAR_INT( + remote_sql_log_off, + spider_remote_sql_log_off, + PLUGIN_VAR_RQCMDARG, + "Set sql_log_off mode at connecting for improvement performance of connection if you know", + NULL, + NULL, + -1, + -1, + 1, + 0 +); + +int spider_param_remote_sql_log_off() +{ + DBUG_ENTER("spider_param_remote_sql_log_off"); + DBUG_RETURN(spider_remote_sql_log_off); +} + +static int spider_remote_trx_isolation; +/* + -1 :don't set + 0 :READ UNCOMMITTED + 1 :READ COMMITTED + 2 :REPEATABLE READ + 3 :SERIALIZABLE + */ +static MYSQL_SYSVAR_INT( + remote_trx_isolation, + spider_remote_trx_isolation, + PLUGIN_VAR_RQCMDARG, + "Set transaction isolation level at connecting for improvement performance of connection if you know", + NULL, + NULL, + -1, + -1, + 3, + 0 +); + +int spider_param_remote_trx_isolation() +{ + DBUG_ENTER("spider_param_remote_trx_isolation"); + DBUG_RETURN(spider_remote_trx_isolation); +} + +static char *spider_remote_default_database; +/* + */ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +static MYSQL_SYSVAR_STR( + remote_default_database, + spider_remote_default_database, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote database at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +#ifdef PLUGIN_VAR_CAN_MEMALLOC +static MYSQL_SYSVAR_STR( + remote_default_database, + spider_remote_default_database, + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Set remote database at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#else +static MYSQL_SYSVAR_STR( + remote_default_database, + spider_remote_default_database, + PLUGIN_VAR_RQCMDARG, + "Set remote database at connecting for improvement performance of connection if you know", + NULL, + NULL, + NULL +); +#endif +#endif + +char *spider_param_remote_default_database() +{ + DBUG_ENTER("spider_param_remote_default_database"); + DBUG_RETURN(spider_remote_default_database); +} + +/* + 0-:connect retry interval (micro second) + */ +static MYSQL_THDVAR_LONGLONG( + connect_retry_interval, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Connect retry interval", /* comment */ + NULL, /* check */ + NULL, /* update */ + 1000, /* def */ + 0, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_connect_retry_interval( + THD *thd +) { + DBUG_ENTER("spider_param_connect_retry_interval"); + if (thd) + DBUG_RETURN(THDVAR(thd, connect_retry_interval)); + DBUG_RETURN(0); +} + +/* + 0-:connect retry count + */ +static MYSQL_THDVAR_INT( + connect_retry_count, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Connect retry count", /* comment */ + NULL, /* check */ + NULL, /* update */ + 1000, /* def */ + 0, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_connect_retry_count( + THD *thd +) { + DBUG_ENTER("spider_param_connect_retry_count"); + if (thd) + DBUG_RETURN(THDVAR(thd, connect_retry_count)); + DBUG_RETURN(0); +} + +/* + */ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +static MYSQL_THDVAR_STR( + bka_engine, /* name */ + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Temporary table's engine for BKA", /* comment */ + NULL, /* check */ + NULL, /* update */ + NULL /* def */ +); +#else +#ifdef PLUGIN_VAR_CAN_MEMALLOC +static MYSQL_THDVAR_STR( + bka_engine, /* name */ + PLUGIN_VAR_MEMALLOC | + PLUGIN_VAR_RQCMDARG, + "Temporary table's engine for BKA", /* comment */ + NULL, /* check */ + NULL, /* update */ + NULL /* def */ +); +#else +static MYSQL_THDVAR_STR( + bka_engine, /* name */ + PLUGIN_VAR_RQCMDARG, + "Temporary table's engine for BKA", /* comment */ + NULL, /* check */ + NULL, /* update */ + NULL /* def */ +); +#endif +#endif + +char *spider_param_bka_engine( + THD *thd, + char *bka_engine +) { + DBUG_ENTER("spider_param_bka_engine"); + DBUG_RETURN(THDVAR(thd, bka_engine) ? + THDVAR(thd, bka_engine) : bka_engine); +} + +/* + -1 :use table parameter + 0 :use union all + 1 :use temporary table + */ +static MYSQL_THDVAR_INT( + bka_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of BKA for Spider", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_bka_mode( + THD *thd, + int bka_mode +) { + DBUG_ENTER("spider_param_bka_mode"); + DBUG_RETURN(THDVAR(thd, bka_mode) == -1 ? + bka_mode : THDVAR(thd, bka_mode)); +} + +static int spider_udf_ct_bulk_insert_interval; +/* + -1 : The UDF parameter is adopted. + 0 or more : Milliseconds. + */ +static MYSQL_SYSVAR_INT( + udf_ct_bulk_insert_interval, + spider_udf_ct_bulk_insert_interval, + PLUGIN_VAR_RQCMDARG, + "The interval time between bulk insert and next bulk insert at coping", + NULL, + NULL, + -1, + -1, + 2147483647, + 0 +); + +int spider_param_udf_ct_bulk_insert_interval( + int udf_ct_bulk_insert_interval +) { + DBUG_ENTER("spider_param_udf_ct_bulk_insert_interval"); + DBUG_RETURN(spider_udf_ct_bulk_insert_interval < 0 ? + udf_ct_bulk_insert_interval : spider_udf_ct_bulk_insert_interval); +} + +static longlong spider_udf_ct_bulk_insert_rows; +/* + -1,0 : The UDF parameter is adopted. + 1 or more : Number of rows. + */ +static MYSQL_SYSVAR_LONGLONG( + udf_ct_bulk_insert_rows, + spider_udf_ct_bulk_insert_rows, + PLUGIN_VAR_RQCMDARG, + "The number of rows inserted with bulk insert of one time at coping", + NULL, + NULL, + -1, + -1, + 9223372036854775807LL, + 0 +); + +longlong spider_param_udf_ct_bulk_insert_rows( + longlong udf_ct_bulk_insert_rows +) { + DBUG_ENTER("spider_param_udf_ct_bulk_insert_rows"); + DBUG_RETURN(spider_udf_ct_bulk_insert_rows <= 0 ? + udf_ct_bulk_insert_rows : spider_udf_ct_bulk_insert_rows); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +/* + 0: no recycle + 1: recycle in instance + 2: recycle in thread + */ +static MYSQL_THDVAR_UINT( + hs_r_conn_recycle_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Handlersocket connection recycle mode", /* comment */ + NULL, /* check */ + NULL, /* update */ + 2, /* def */ + 0, /* min */ + 2, /* max */ + 0 /* blk */ +); + +uint spider_param_hs_r_conn_recycle_mode( + THD *thd +) { + DBUG_ENTER("spider_param_hs_r_conn_recycle_mode"); + DBUG_RETURN(THDVAR(thd, hs_r_conn_recycle_mode)); +} + +/* + 0: weak + 1: strict + */ +static MYSQL_THDVAR_UINT( + hs_r_conn_recycle_strict, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Strict handlersocket connection recycle", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +uint spider_param_hs_r_conn_recycle_strict( + THD *thd +) { + DBUG_ENTER("spider_param_hs_r_conn_recycle_strict"); + DBUG_RETURN(THDVAR(thd, hs_r_conn_recycle_strict)); +} + +/* + 0: no recycle + 1: recycle in instance + 2: recycle in thread + */ +static MYSQL_THDVAR_UINT( + hs_w_conn_recycle_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Handlersocket connection recycle mode", /* comment */ + NULL, /* check */ + NULL, /* update */ + 2, /* def */ + 0, /* min */ + 2, /* max */ + 0 /* blk */ +); + +uint spider_param_hs_w_conn_recycle_mode( + THD *thd +) { + DBUG_ENTER("spider_param_hs_w_conn_recycle_mode"); + DBUG_RETURN(THDVAR(thd, hs_w_conn_recycle_mode)); +} + +/* + 0: weak + 1: strict + */ +static MYSQL_THDVAR_UINT( + hs_w_conn_recycle_strict, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Strict handlersocket connection recycle", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +uint spider_param_hs_w_conn_recycle_strict( + THD *thd +) { + DBUG_ENTER("spider_param_hs_w_conn_recycle_strict"); + DBUG_RETURN(THDVAR(thd, hs_w_conn_recycle_strict)); +} + +/* + -1 :use table parameter + 0 :not use + 1 :use handlersocket + */ +static MYSQL_THDVAR_INT( + use_hs_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use handlersocket for reading", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_use_hs_read( + THD *thd, + int use_hs_read +) { + DBUG_ENTER("spider_param_use_hs_read"); + DBUG_RETURN(THDVAR(thd, use_hs_read) == -1 ? + use_hs_read : THDVAR(thd, use_hs_read)); +} + +/* + -1 :use table parameter + 0 :not use + 1 :use handlersocket + */ +static MYSQL_THDVAR_INT( + use_hs_write, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use handlersocket for writing", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_use_hs_write( + THD *thd, + int use_hs_write +) { + DBUG_ENTER("spider_param_use_hs_write"); + DBUG_RETURN(THDVAR(thd, use_hs_write) == -1 ? + use_hs_write : THDVAR(thd, use_hs_write)); +} +#endif + +/* + -1 :use table parameter + 0 :not use + 1 :use handler + */ +static MYSQL_THDVAR_INT( + use_handler, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use handler for reading", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +int spider_param_use_handler( + THD *thd, + int use_handler +) { + DBUG_ENTER("spider_param_use_handler"); + DBUG_RETURN(THDVAR(thd, use_handler) == -1 ? + use_handler : THDVAR(thd, use_handler)); +} + +/* + -1 :use table parameter + 0 :return error if error + 1 :return 0 record if error + */ +static MYSQL_THDVAR_INT( + error_read_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Read error mode if error", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_error_read_mode( + THD *thd, + int error_read_mode +) { + DBUG_ENTER("spider_param_error_read_mode"); + DBUG_RETURN(THDVAR(thd, error_read_mode) == -1 ? + error_read_mode : THDVAR(thd, error_read_mode)); +} + +/* + -1 :use table parameter + 0 :return error if error + 1 :return 0 record if error + */ +static MYSQL_THDVAR_INT( + error_write_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Write error mode if error", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_error_write_mode( + THD *thd, + int error_write_mode +) { + DBUG_ENTER("spider_param_error_write_mode"); + DBUG_RETURN(THDVAR(thd, error_write_mode) == -1 ? + error_write_mode : THDVAR(thd, error_write_mode)); +} + +/* + -1 :use table parameter + 0 :not skip + 1 :skip + */ +static MYSQL_THDVAR_INT( + skip_default_condition, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Skip generating internal default condition", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_skip_default_condition( + THD *thd, + int skip_default_condition +) { + DBUG_ENTER("spider_param_skip_default_condition"); + DBUG_RETURN(THDVAR(thd, skip_default_condition) == -1 ? + skip_default_condition : THDVAR(thd, skip_default_condition)); +} + +/* + -1 :use table parameter + 0 :not send directly + 1-:send directly + */ +static MYSQL_THDVAR_LONGLONG( + direct_order_limit, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Send 'ORDER BY' and 'LIMIT' to remote server directly", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +longlong spider_param_direct_order_limit( + THD *thd, + longlong direct_order_limit +) { + DBUG_ENTER("spider_param_direct_order_limit"); + DBUG_RETURN(THDVAR(thd, direct_order_limit) == -1 ? + direct_order_limit : THDVAR(thd, direct_order_limit)); +} + +/* + -1 :use table parameter + 0 :writable + 1 :read only + */ +static MYSQL_THDVAR_INT( + read_only_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Read only", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_read_only_mode( + THD *thd, + int read_only_mode +) { + DBUG_ENTER("spider_param_read_only_mode"); + DBUG_RETURN(THDVAR(thd, read_only_mode) == -1 ? + read_only_mode : THDVAR(thd, read_only_mode)); +} + +#ifdef HA_CAN_BULK_ACCESS +static int spider_bulk_access_free; +/* + -1 :use table parameter + 0 :in reset + 1 :in close + */ +static MYSQL_SYSVAR_INT( + bulk_access_free, + spider_bulk_access_free, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Free mode of bulk access resources", + NULL, + NULL, + -1, + -1, + 1, + 0 +); + +int spider_param_bulk_access_free( + int bulk_access_free +) { + DBUG_ENTER("spider_param_bulk_access_free"); + DBUG_RETURN(spider_bulk_access_free == -1 ? + bulk_access_free : spider_bulk_access_free); +} +#endif + +#if MYSQL_VERSION_ID < 50500 +#else +/* + -1 :use UDF parameter + 0 :can not use + 1 :can use + */ +static MYSQL_THDVAR_INT( + udf_ds_use_real_table, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use real table for temporary table list", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +int spider_param_udf_ds_use_real_table( + THD *thd, + int udf_ds_use_real_table +) { + DBUG_ENTER("spider_param_udf_ds_use_real_table"); + DBUG_RETURN(THDVAR(thd, udf_ds_use_real_table) == -1 ? + udf_ds_use_real_table : THDVAR(thd, udf_ds_use_real_table)); +} +#endif + +static struct st_mysql_storage_engine spider_storage_engine = +{ MYSQL_HANDLERTON_INTERFACE_VERSION }; + +static struct st_mysql_sys_var* spider_system_variables[] = { + MYSQL_SYSVAR(support_xa), + MYSQL_SYSVAR(table_init_error_interval), + MYSQL_SYSVAR(use_table_charset), + MYSQL_SYSVAR(conn_recycle_mode), + MYSQL_SYSVAR(conn_recycle_strict), + MYSQL_SYSVAR(sync_trx_isolation), + MYSQL_SYSVAR(use_consistent_snapshot), + MYSQL_SYSVAR(internal_xa), + MYSQL_SYSVAR(internal_xa_snapshot), + MYSQL_SYSVAR(force_commit), + MYSQL_SYSVAR(internal_offset), + MYSQL_SYSVAR(internal_limit), + MYSQL_SYSVAR(split_read), + MYSQL_SYSVAR(semi_split_read), + MYSQL_SYSVAR(semi_split_read_limit), + MYSQL_SYSVAR(init_sql_alloc_size), + MYSQL_SYSVAR(reset_sql_alloc), +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + MYSQL_SYSVAR(hs_result_free_size), +#endif + MYSQL_SYSVAR(multi_split_read), + MYSQL_SYSVAR(max_order), + MYSQL_SYSVAR(semi_trx_isolation), + MYSQL_SYSVAR(semi_table_lock), + MYSQL_SYSVAR(semi_table_lock_connection), + MYSQL_SYSVAR(block_size), + MYSQL_SYSVAR(selupd_lock_mode), + MYSQL_SYSVAR(sync_autocommit), + MYSQL_SYSVAR(sync_time_zone), + MYSQL_SYSVAR(use_default_database), + MYSQL_SYSVAR(internal_sql_log_off), + MYSQL_SYSVAR(bulk_size), + MYSQL_SYSVAR(bulk_update_mode), + MYSQL_SYSVAR(bulk_update_size), + MYSQL_SYSVAR(internal_optimize), + MYSQL_SYSVAR(internal_optimize_local), + MYSQL_SYSVAR(use_flash_logs), + MYSQL_SYSVAR(use_snapshot_with_flush_tables), + MYSQL_SYSVAR(use_all_conns_snapshot), + MYSQL_SYSVAR(lock_exchange), + MYSQL_SYSVAR(internal_unlock), + MYSQL_SYSVAR(semi_trx), + MYSQL_SYSVAR(connect_timeout), + MYSQL_SYSVAR(net_read_timeout), + MYSQL_SYSVAR(net_write_timeout), + MYSQL_SYSVAR(quick_mode), + MYSQL_SYSVAR(quick_page_size), + MYSQL_SYSVAR(low_mem_read), + MYSQL_SYSVAR(select_column_mode), +#ifndef WITHOUT_SPIDER_BG_SEARCH + MYSQL_SYSVAR(bgs_mode), + MYSQL_SYSVAR(bgs_first_read), + MYSQL_SYSVAR(bgs_second_read), +#endif + MYSQL_SYSVAR(first_read), + MYSQL_SYSVAR(second_read), + MYSQL_SYSVAR(crd_interval), + MYSQL_SYSVAR(crd_mode), +#ifdef WITH_PARTITION_STORAGE_ENGINE + MYSQL_SYSVAR(crd_sync), +#endif + MYSQL_SYSVAR(crd_type), + MYSQL_SYSVAR(crd_weight), +#ifndef WITHOUT_SPIDER_BG_SEARCH + MYSQL_SYSVAR(crd_bg_mode), +#endif + MYSQL_SYSVAR(sts_interval), + MYSQL_SYSVAR(sts_mode), +#ifdef WITH_PARTITION_STORAGE_ENGINE + MYSQL_SYSVAR(sts_sync), +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + MYSQL_SYSVAR(sts_bg_mode), +#endif + MYSQL_SYSVAR(ping_interval_at_trx_start), +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + MYSQL_SYSVAR(hs_ping_interval), +#endif + MYSQL_SYSVAR(auto_increment_mode), + MYSQL_SYSVAR(same_server_link), + MYSQL_SYSVAR(local_lock_table), + MYSQL_SYSVAR(use_pushdown_udf), + MYSQL_SYSVAR(direct_dup_insert), + MYSQL_SYSVAR(udf_table_lock_mutex_count), + MYSQL_SYSVAR(udf_table_mon_mutex_count), + MYSQL_SYSVAR(udf_ds_bulk_insert_rows), + MYSQL_SYSVAR(udf_ds_table_loop_mode), + MYSQL_SYSVAR(remote_access_charset), + MYSQL_SYSVAR(remote_autocommit), + MYSQL_SYSVAR(remote_time_zone), + MYSQL_SYSVAR(remote_sql_log_off), + MYSQL_SYSVAR(remote_trx_isolation), + MYSQL_SYSVAR(remote_default_database), + MYSQL_SYSVAR(connect_retry_interval), + MYSQL_SYSVAR(connect_retry_count), + MYSQL_SYSVAR(connect_mutex), + MYSQL_SYSVAR(bka_engine), + MYSQL_SYSVAR(bka_mode), + MYSQL_SYSVAR(udf_ct_bulk_insert_interval), + MYSQL_SYSVAR(udf_ct_bulk_insert_rows), +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + MYSQL_SYSVAR(hs_r_conn_recycle_mode), + MYSQL_SYSVAR(hs_r_conn_recycle_strict), + MYSQL_SYSVAR(hs_w_conn_recycle_mode), + MYSQL_SYSVAR(hs_w_conn_recycle_strict), + MYSQL_SYSVAR(use_hs_read), + MYSQL_SYSVAR(use_hs_write), +#endif + MYSQL_SYSVAR(use_handler), + MYSQL_SYSVAR(error_read_mode), + MYSQL_SYSVAR(error_write_mode), + MYSQL_SYSVAR(skip_default_condition), + MYSQL_SYSVAR(direct_order_limit), + MYSQL_SYSVAR(read_only_mode), +#ifdef HA_CAN_BULK_ACCESS + MYSQL_SYSVAR(bulk_access_free), +#endif +#if MYSQL_VERSION_ID < 50500 +#else + MYSQL_SYSVAR(udf_ds_use_real_table), +#endif + NULL +}; + +mysql_declare_plugin(spider) +{ + MYSQL_STORAGE_ENGINE_PLUGIN, + &spider_storage_engine, + "SPIDER", + "Kentoku Shiba", + "Spider storage engine", + PLUGIN_LICENSE_GPL, + spider_db_init, + spider_db_done, + 0x0300, + spider_status_variables, + spider_system_variables, + NULL, +#if MYSQL_VERSION_ID >= 50600 + 0, +#endif +}, +spider_i_s_alloc_mem +mysql_declare_plugin_end; diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h new file mode 100644 index 00000000000..a3e1576cdf1 --- /dev/null +++ b/storage/spider/spd_param.h @@ -0,0 +1,370 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +my_bool spider_param_support_xa(); +my_bool spider_param_connect_mutex(); +uint spider_param_table_init_error_interval(); +int spider_param_use_table_charset( + int use_table_charset +); +uint spider_param_conn_recycle_mode( + THD *thd +); +uint spider_param_conn_recycle_strict( + THD *thd +); +bool spider_param_sync_trx_isolation( + THD *thd +); +bool spider_param_use_consistent_snapshot( + THD *thd +); +bool spider_param_internal_xa( + THD *thd +); +uint spider_param_internal_xa_snapshot( + THD *thd +); +uint spider_param_force_commit( + THD *thd +); +longlong spider_param_internal_offset( + THD *thd, + longlong internal_offset +); +longlong spider_param_internal_limit( + THD *thd, + longlong internal_limit +); +longlong spider_param_split_read( + THD *thd, + longlong split_read +); +double spider_param_semi_split_read( + THD *thd, + double semi_split_read +); +longlong spider_param_semi_split_read_limit( + THD *thd, + longlong semi_split_read_limit +); +int spider_param_init_sql_alloc_size( + THD *thd, + int init_sql_alloc_size +); +int spider_param_reset_sql_alloc( + THD *thd, + int reset_sql_alloc +); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +longlong spider_param_hs_result_free_size( + THD *thd, + longlong hs_result_free_size +); +#endif +int spider_param_multi_split_read( + THD *thd, + int multi_split_read +); +int spider_param_max_order( + THD *thd, + int max_order +); +int spider_param_semi_trx_isolation( + THD *thd +); +int spider_param_semi_table_lock( + THD *thd, + int semi_table_lock +); +int spider_param_semi_table_lock_connection( + THD *thd, + int semi_table_lock_connection +); +uint spider_param_block_size( + THD *thd +); +int spider_param_selupd_lock_mode( + THD *thd, + int selupd_lock_mode +); +bool spider_param_sync_autocommit( + THD *thd +); +bool spider_param_sync_time_zone( + THD *thd +); +bool spider_param_use_default_database( + THD *thd +); +bool spider_param_internal_sql_log_off( + THD *thd +); +int spider_param_bulk_size( + THD *thd, + int bulk_size +); +int spider_param_bulk_update_mode( + THD *thd, + int bulk_update_mode +); +int spider_param_bulk_update_size( + THD *thd, + int bulk_update_size +); +int spider_param_internal_optimize( + THD *thd, + int internal_optimize +); +int spider_param_internal_optimize_local( + THD *thd, + int internal_optimize_local +); +bool spider_param_use_flash_logs( + THD *thd +); +int spider_param_use_snapshot_with_flush_tables( + THD *thd +); +bool spider_param_use_all_conns_snapshot( + THD *thd +); +bool spider_param_lock_exchange( + THD *thd +); +bool spider_param_internal_unlock( + THD *thd +); +bool spider_param_semi_trx( + THD *thd +); +int spider_param_connect_timeout( + THD *thd, + int connect_timeout +); +int spider_param_net_read_timeout( + THD *thd, + int net_read_timeout +); +int spider_param_net_write_timeout( + THD *thd, + int net_write_timeout +); +int spider_param_quick_mode( + THD *thd, + int quick_mode +); +longlong spider_param_quick_page_size( + THD *thd, + longlong quick_page_size +); +int spider_param_low_mem_read( + THD *thd, + int low_mem_read +); +int spider_param_select_column_mode( + THD *thd, + int select_column_mode +); +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_param_bgs_mode( + THD *thd, + int bgs_mode +); +longlong spider_param_bgs_first_read( + THD *thd, + longlong bgs_first_read +); +longlong spider_param_bgs_second_read( + THD *thd, + longlong bgs_second_read +); +#endif +longlong spider_param_first_read( + THD *thd, + longlong first_read +); +longlong spider_param_second_read( + THD *thd, + longlong second_read +); +double spider_param_crd_interval( + THD *thd, + double crd_interval +); +int spider_param_crd_mode( + THD *thd, + int crd_mode +); +#ifdef WITH_PARTITION_STORAGE_ENGINE +int spider_param_crd_sync( + THD *thd, + int crd_sync +); +#endif +int spider_param_crd_type( + THD *thd, + int crd_type +); +double spider_param_crd_weight( + THD *thd, + double crd_weight +); +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_param_crd_bg_mode( + THD *thd, + int crd_bg_mode +); +#endif +double spider_param_sts_interval( + THD *thd, + double sts_interval +); +int spider_param_sts_mode( + THD *thd, + int sts_mode +); +#ifdef WITH_PARTITION_STORAGE_ENGINE +int spider_param_sts_sync( + THD *thd, + int sts_sync +); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH +int spider_param_sts_bg_mode( + THD *thd, + int sts_bg_mode +); +#endif +double spider_param_ping_interval_at_trx_start( + THD *thd +); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +double spider_param_hs_ping_interval( + THD *thd +); +#endif +int spider_param_auto_increment_mode( + THD *thd, + int auto_increment_mode +); +bool spider_param_same_server_link( + THD *thd +); +bool spider_param_local_lock_table( + THD *thd +); +int spider_param_use_pushdown_udf( + THD *thd, + int use_pushdown_udf +); +int spider_param_direct_dup_insert( + THD *thd, + int direct_dup_insert +); +uint spider_param_udf_table_lock_mutex_count(); +uint spider_param_udf_table_mon_mutex_count(); +longlong spider_param_udf_ds_bulk_insert_rows( + THD *thd, + longlong udf_ds_bulk_insert_rows +); +int spider_param_udf_ds_table_loop_mode( + THD *thd, + int udf_ds_table_loop_mode +); +char *spider_param_remote_access_charset(); +int spider_param_remote_autocommit(); +char *spider_param_remote_time_zone(); +int spider_param_remote_sql_log_off(); +int spider_param_remote_trx_isolation(); +char *spider_param_remote_default_database(); +longlong spider_param_connect_retry_interval( + THD *thd +); +int spider_param_connect_retry_count( + THD *thd +); +char *spider_param_bka_engine( + THD *thd, + char *bka_engine +); +int spider_param_bka_mode( + THD *thd, + int bka_mode +); +int spider_param_udf_ct_bulk_insert_interval( + int udf_ct_bulk_insert_interval +); +longlong spider_param_udf_ct_bulk_insert_rows( + longlong udf_ct_bulk_insert_rows +); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +uint spider_param_hs_r_conn_recycle_mode( + THD *thd +); +uint spider_param_hs_r_conn_recycle_strict( + THD *thd +); +uint spider_param_hs_w_conn_recycle_mode( + THD *thd +); +uint spider_param_hs_w_conn_recycle_strict( + THD *thd +); +int spider_param_use_hs_read( + THD *thd, + int use_hs_read +); +int spider_param_use_hs_write( + THD *thd, + int use_hs_write +); +#endif +int spider_param_use_handler( + THD *thd, + int use_handler +); +int spider_param_error_read_mode( + THD *thd, + int error_read_mode +); +int spider_param_error_write_mode( + THD *thd, + int error_write_mode +); +int spider_param_skip_default_condition( + THD *thd, + int skip_default_condition +); +longlong spider_param_direct_order_limit( + THD *thd, + longlong direct_order_limit +); +int spider_param_read_only_mode( + THD *thd, + int read_only_mode +); +#ifdef HA_CAN_BULK_ACCESS +int spider_param_bulk_access_free( + int bulk_access_free +); +#endif +#if MYSQL_VERSION_ID < 50500 +#else +int spider_param_udf_ds_use_real_table( + THD *thd, + int udf_ds_use_real_table +); +#endif diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc new file mode 100644 index 00000000000..34bd3fb3575 --- /dev/null +++ b/storage/spider/spd_ping_table.cc @@ -0,0 +1,1460 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_acl.h" +#endif +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_db_conn.h" +#include "spd_trx.h" +#include "spd_conn.h" +#include "spd_sys_table.h" +#include "spd_table.h" +#include "spd_ping_table.h" +#include "spd_direct_sql.h" +#include "spd_udf.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key spd_key_mutex_mon_list_caller; +extern PSI_mutex_key spd_key_mutex_mon_list_receptor; +extern PSI_mutex_key spd_key_mutex_mon_list_monitor; +extern PSI_mutex_key spd_key_mutex_mon_list_update_status; +extern PSI_mutex_key spd_key_mutex_mon_table_cache; +#endif + +#ifndef WITHOUT_SPIDER_BG_SEARCH +extern pthread_mutex_t spider_global_trx_mutex; +extern SPIDER_TRX *spider_global_trx; +#endif + +HASH *spider_udf_table_mon_list_hash; +uint spider_udf_table_mon_list_hash_id; +const char *spider_udf_table_mon_list_hash_func_name; +const char *spider_udf_table_mon_list_hash_file_name; +ulong spider_udf_table_mon_list_hash_line_no; +pthread_mutex_t *spider_udf_table_mon_mutexes; +pthread_cond_t *spider_udf_table_mon_conds; + +pthread_mutex_t spider_mon_table_cache_mutex; +DYNAMIC_ARRAY spider_mon_table_cache; +uint spider_mon_table_cache_id; +const char *spider_mon_table_cache_func_name; +const char *spider_mon_table_cache_file_name; +ulong spider_mon_table_cache_line_no; +volatile ulonglong spider_mon_table_cache_version = 0; +volatile ulonglong spider_mon_table_cache_version_req = 1; + +SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( + SPIDER_TRX *trx, + THD *thd, + spider_string *str, + uint conv_name_length, + int link_idx, + uint32 server_id, + bool need_lock, + int *error_num +) { + uint mutex_hash; + SPIDER_TABLE_MON_LIST *table_mon_list; + MEM_ROOT mem_root; + ulonglong mon_table_cache_version; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value; +#endif + DBUG_ENTER("spider_get_ping_table_mon_list"); + if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) + { + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ((*error_num = spider_init_ping_table_mon_cache(thd, &mem_root, + need_lock))) + { + free_root(&mem_root, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + } + + mutex_hash = spider_udf_calc_hash(str->c_ptr(), + spider_param_udf_table_mon_mutex_count()); + DBUG_PRINT("info",("spider hash key=%s", str->c_ptr())); + DBUG_PRINT("info",("spider hash key length=%u", str->length())); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value = my_calc_hash( + &spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) str->c_ptr(), str->length()); +#endif + pthread_mutex_lock(&spider_udf_table_mon_mutexes[mutex_hash]); + mon_table_cache_version = (ulonglong) spider_mon_table_cache_version; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(table_mon_list = (SPIDER_TABLE_MON_LIST *) + my_hash_search_using_hash_value( + &spider_udf_table_mon_list_hash[mutex_hash], hash_value, + (uchar*) str->c_ptr(), str->length())) || + table_mon_list->mon_table_cache_version != mon_table_cache_version + ) +#else + if (!(table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_search( + &spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) str->c_ptr(), str->length())) || + table_mon_list->mon_table_cache_version != mon_table_cache_version + ) +#endif + { + DBUG_ASSERT(trx != spider_global_trx); + if ( + table_mon_list && + table_mon_list->mon_table_cache_version != mon_table_cache_version + ) + spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); + + if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(), + conv_name_length, link_idx, server_id, str, need_lock, error_num))) + { + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[mutex_hash]); + goto error; + } + table_mon_list->mutex_hash = mutex_hash; + table_mon_list->mon_table_cache_version = mon_table_cache_version; + uint old_elements = + spider_udf_table_mon_list_hash[mutex_hash].array.max_element; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + table_mon_list->key_hash_value = hash_value; +#endif +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value( + &spider_udf_table_mon_list_hash[mutex_hash], + hash_value, (uchar*) table_mon_list)) +#else + if (my_hash_insert(&spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) table_mon_list)) +#endif + { + spider_ping_table_free_mon_list(table_mon_list); + *error_num = HA_ERR_OUT_OF_MEM; + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[mutex_hash]); + goto error; + } + if (spider_udf_table_mon_list_hash[mutex_hash].array.max_element > + old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_udf_table_mon_list_hash, + (spider_udf_table_mon_list_hash[mutex_hash].array.max_element - + old_elements) * + spider_udf_table_mon_list_hash[mutex_hash].array.size_of_element); + } + } + table_mon_list->use_count++; + DBUG_PRINT("info",("spider table_mon_list->use_count=%d", + table_mon_list->use_count)); + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[mutex_hash]); + DBUG_RETURN(table_mon_list); + +error: + DBUG_RETURN(NULL); +} + +void spider_free_ping_table_mon_list( + SPIDER_TABLE_MON_LIST *table_mon_list +) { + DBUG_ENTER("spider_free_ping_table_mon_list"); + pthread_mutex_lock(&spider_udf_table_mon_mutexes[ + table_mon_list->mutex_hash]); + table_mon_list->use_count--; + DBUG_PRINT("info",("spider table_mon_list->use_count=%d", table_mon_list->use_count)); + if (!table_mon_list->use_count) + pthread_cond_broadcast(&spider_udf_table_mon_conds[ + table_mon_list->mutex_hash]); + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[ + table_mon_list->mutex_hash]); + DBUG_VOID_RETURN; +} + +void spider_release_ping_table_mon_list_loop( + uint mutex_hash, + SPIDER_TABLE_MON_LIST *table_mon_list +) { + DBUG_ENTER("spider_release_ping_table_mon_list_loop"); +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_udf_table_mon_list_hash[mutex_hash], + table_mon_list->key_hash_value, (uchar*) table_mon_list); +#else + my_hash_delete(&spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) table_mon_list); +#endif + while (TRUE) + { + if (table_mon_list->use_count) + pthread_cond_wait(&spider_udf_table_mon_conds[mutex_hash], + &spider_udf_table_mon_mutexes[mutex_hash]); + else { + spider_ping_table_free_mon_list(table_mon_list); + break; + } + } + DBUG_VOID_RETURN; +} + +void spider_release_ping_table_mon_list( + const char *conv_name, + uint conv_name_length, + int link_idx +) { + uint mutex_hash; + SPIDER_TABLE_MON_LIST *table_mon_list; + char link_idx_str[SPIDER_SQL_INT_LEN]; + int link_idx_str_length; + DBUG_ENTER("spider_release_ping_table_mon_list"); + DBUG_PRINT("info", ("spider conv_name=%s", conv_name)); + DBUG_PRINT("info", ("spider conv_name_length=%u", conv_name_length)); + DBUG_PRINT("info", ("spider link_idx=%d", link_idx)); + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d", + link_idx)); +#ifdef _MSC_VER + spider_string conv_name_str(conv_name_length + link_idx_str_length + 1); + conv_name_str.set_charset(system_charset_info); +#else + char buf[conv_name_length + link_idx_str_length + 1]; + spider_string conv_name_str(buf, conv_name_length + link_idx_str_length + 1, + system_charset_info); +#endif + conv_name_str.init_calc_mem(134); + conv_name_str.length(0); + conv_name_str.q_append(conv_name, conv_name_length); + conv_name_str.q_append(link_idx_str, link_idx_str_length); + + mutex_hash = spider_udf_calc_hash(conv_name_str.c_ptr_safe(), + spider_param_udf_table_mon_mutex_count()); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value = my_calc_hash( + &spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) conv_name_str.c_ptr(), conv_name_str.length()); +#endif + pthread_mutex_lock(&spider_udf_table_mon_mutexes[mutex_hash]); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if ((table_mon_list = (SPIDER_TABLE_MON_LIST *) + my_hash_search_using_hash_value( + &spider_udf_table_mon_list_hash[mutex_hash], hash_value, + (uchar*) conv_name_str.c_ptr(), conv_name_str.length()))) +#else + if ((table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_search( + &spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) conv_name_str.c_ptr(), conv_name_str.length()))) +#endif + spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[mutex_hash]); + DBUG_VOID_RETURN; +} + +int spider_get_ping_table_mon( + THD *thd, + SPIDER_TABLE_MON_LIST *table_mon_list, + char *name, + uint name_length, + int link_idx, + uint32 server_id, + MEM_ROOT *mem_root, + bool need_lock +) { + int error_num; + TABLE *table_link_mon = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + char table_key[MAX_KEY_LENGTH]; + SPIDER_TABLE_MON *table_mon, *table_mon_prev = NULL; + SPIDER_SHARE *tmp_share; + char **tmp_connect_info, *tmp_ptr; + uint *tmp_connect_info_length; + long *tmp_long; + longlong *tmp_longlong; + int list_size = 0; + DBUG_ENTER("spider_get_ping_table_mon"); + + if ( + !(table_link_mon = spider_open_sys_table( + thd, SPIDER_SYS_LINK_MON_TABLE_NAME_STR, + SPIDER_SYS_LINK_MON_TABLE_NAME_LEN, FALSE, &open_tables_backup, + need_lock, &error_num)) + ) { + my_error(error_num, MYF(0)); + goto error; + } + spider_store_tables_name(table_link_mon, name, name_length); + spider_store_tables_link_idx(table_link_mon, link_idx); + if (!(error_num = spider_ping_table_cache_compare(table_link_mon, mem_root))) + goto create_table_mon; + if (error_num == HA_ERR_OUT_OF_MEM) + goto error; + if ((tmp_ptr = strstr(name, "#P#"))) + { + *tmp_ptr = '\0'; + spider_store_tables_name(table_link_mon, name, strlen(name)); + *tmp_ptr = '#'; + if (!(error_num = spider_ping_table_cache_compare(table_link_mon, + mem_root))) + goto create_table_mon; + if (error_num == HA_ERR_OUT_OF_MEM) + goto error; + } + error_num = HA_ERR_KEY_NOT_FOUND; + table_link_mon->file->print_error(error_num, MYF(0)); + goto error; + +create_table_mon: + if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key, + table_link_mon->s->primary_key, 3))) + { + table_link_mon->file->print_error(error_num, MYF(0)); + goto error; + } + + do { + if (!(table_mon = (SPIDER_TABLE_MON *) + spider_bulk_malloc(spider_current_trx, 35, MYF(MY_WME | MY_ZEROFILL), + &table_mon, sizeof(SPIDER_TABLE_MON), + &tmp_share, sizeof(SPIDER_SHARE), + &tmp_connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT, + &tmp_connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT, + &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT, + &tmp_longlong, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT, + NullS)) + ) { + spider_sys_index_end(table_link_mon); + error_num = HA_ERR_OUT_OF_MEM; + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + spider_set_tmp_share_pointer(tmp_share, tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + tmp_share->link_statuses[0] = -1; + table_mon->share = tmp_share; + if (table_mon_prev) + table_mon_prev->next = table_mon; + else + table_mon_list->first = table_mon; + table_mon_prev = table_mon; + if ( + (error_num = spider_get_sys_link_mon_server_id( + table_link_mon, &table_mon->server_id, mem_root)) || + (error_num = spider_get_sys_link_mon_connect_info( + table_link_mon, tmp_share, 0, mem_root)) + ) { + table_link_mon->file->print_error(error_num, MYF(0)); + spider_sys_index_end(table_link_mon); + goto error; + } + if ( + (error_num = spider_set_connect_info_default( + tmp_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + NULL, + NULL, +#endif + NULL + )) || + (error_num = spider_set_connect_info_default_dbtable( + tmp_share, name, name_length + )) || + (error_num = spider_create_conn_keys(tmp_share)) + ) { + spider_sys_index_end(table_link_mon); + goto error; + } + DBUG_PRINT("info",("spider table_mon->server_id=%u", + table_mon->server_id)); + DBUG_PRINT("info",("spider server_id=%u", server_id)); + if (table_mon->server_id == server_id) + table_mon_list->current = table_mon; + list_size++; + error_num = spider_sys_index_next_same(table_link_mon, table_key); + } while (error_num == 0); + spider_sys_index_end(table_link_mon); + spider_close_sys_table(thd, table_link_mon, + &open_tables_backup, need_lock); + table_link_mon = NULL; + table_mon_list->list_size = list_size; + + if (!table_mon_list->current) + { + error_num = ER_SPIDER_UDF_PING_TABLE_NO_SERVER_ID_NUM; + my_printf_error(ER_SPIDER_UDF_PING_TABLE_NO_SERVER_ID_NUM, + ER_SPIDER_UDF_PING_TABLE_NO_SERVER_ID_STR, MYF(0)); + goto error; + } + + DBUG_RETURN(0); + +error: + if (table_link_mon) + spider_close_sys_table(thd, table_link_mon, + &open_tables_backup, need_lock); + table_mon = table_mon_list->first; + table_mon_list->first = NULL; + table_mon_list->current = NULL; + while (table_mon) + { + spider_free_tmp_share_alloc(table_mon->share); + table_mon_prev = table_mon->next; + spider_free(spider_current_trx, table_mon, MYF(0)); + table_mon = table_mon_prev; + } + DBUG_RETURN(error_num); +} + +SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( + THD *thd, + char *name, + uint name_length, + int link_idx, + uint32 server_id, + spider_string *str, + bool need_lock, + int *error_num +) { + TABLE *table_tables = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + char table_key[MAX_KEY_LENGTH]; + + SPIDER_TABLE_MON_LIST *table_mon_list = NULL; + SPIDER_SHARE *tmp_share; + char **tmp_connect_info; + uint *tmp_connect_info_length; + long *tmp_long; + longlong *tmp_longlong; + char *key_str; + MEM_ROOT mem_root; + DBUG_ENTER("spider_get_ping_table_tgt"); + + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if (!(table_mon_list = (SPIDER_TABLE_MON_LIST *) + spider_bulk_malloc(spider_current_trx, 36, MYF(MY_WME | MY_ZEROFILL), + &table_mon_list, sizeof(SPIDER_TABLE_MON_LIST), + &tmp_share, sizeof(SPIDER_SHARE), + &tmp_connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT, + &tmp_connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT, + &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT, + &tmp_longlong, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT, + &key_str, str->length() + 1, + NullS)) + ) { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + spider_set_tmp_share_pointer(tmp_share, tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + table_mon_list->share = tmp_share; + table_mon_list->key = key_str; + table_mon_list->key_length = str->length(); + memcpy(key_str, str->ptr(), table_mon_list->key_length); + tmp_share->access_charset = thd->variables.character_set_client; + + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, need_lock, + error_num)) + ) { + my_error(*error_num, MYF(0)); + goto error; + } + spider_store_tables_name(table_tables, name, name_length); + spider_store_tables_link_idx(table_tables, link_idx); + if ( + (*error_num = spider_check_sys_table(table_tables, table_key)) || + (*error_num = spider_get_sys_tables_connect_info( + table_tables, tmp_share, 0, &mem_root)) || + (*error_num = spider_get_sys_tables_link_status( + table_tables, tmp_share, 0, &mem_root)) + ) { + table_tables->file->print_error(*error_num, MYF(0)); + goto error; + } + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + + if ( + (*error_num = spider_set_connect_info_default( + tmp_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + NULL, + NULL, +#endif + NULL + )) || + (*error_num = spider_set_connect_info_default_dbtable( + tmp_share, name, name_length + )) || + (*error_num = spider_create_conn_keys(tmp_share)) || +/* + (*error_num = spider_db_create_table_names_str(tmp_share)) || +*/ + (*error_num = spider_get_ping_table_mon( + thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root, + need_lock)) + ) + goto error; + + if (tmp_share->link_statuses[0] == SPIDER_LINK_STATUS_NG) + table_mon_list->mon_status = SPIDER_LINK_MON_NG; + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mon_list_caller, + &table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_caller_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mon_list_receptor, + &table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_receptor_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mon_list_monitor, + &table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_monitor_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&table_mon_list->update_status_mutex, + MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mon_list_update_status, + &table_mon_list->update_status_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_update_status_mutex_init; + } + + free_root(&mem_root, MYF(0)); + DBUG_RETURN(table_mon_list); + +error_update_status_mutex_init: + pthread_mutex_destroy(&table_mon_list->monitor_mutex); +error_monitor_mutex_init: + pthread_mutex_destroy(&table_mon_list->receptor_mutex); +error_receptor_mutex_init: + pthread_mutex_destroy(&table_mon_list->caller_mutex); +error_caller_mutex_init: +error: + if (table_tables) + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + free_root(&mem_root, MYF(0)); + if (table_mon_list) + { + spider_free_tmp_share_alloc(table_mon_list->share); + spider_free(spider_current_trx, table_mon_list, MYF(0)); + } + DBUG_RETURN(NULL); +} + +SPIDER_CONN *spider_get_ping_table_tgt_conn( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int *error_num +) { + SPIDER_CONN *conn; + DBUG_ENTER("spider_get_ping_table_tgt_conn"); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (trx == spider_global_trx) + pthread_mutex_lock(&spider_global_trx_mutex); +#endif + if ( + !(conn = spider_get_conn( + share, 0, share->conn_keys[0], trx, NULL, FALSE, FALSE, + SPIDER_CONN_KIND_MYSQL, error_num)) + ) { +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (trx == spider_global_trx) + pthread_mutex_unlock(&spider_global_trx_mutex); +#endif + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + share->server_names[0]); + *error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; + goto error; + } + conn->error_mode = 0; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (trx == spider_global_trx) + pthread_mutex_unlock(&spider_global_trx_mutex); +#endif + DBUG_RETURN(conn); + +error: + DBUG_RETURN(NULL); +} + +int spider_init_ping_table_mon_cache( + THD *thd, + MEM_ROOT *mem_root, + bool need_lock +) { + int error_num, same; + TABLE *table_link_mon = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + SPIDER_MON_KEY mon_key; + DBUG_ENTER("spider_init_ping_table_mon_cache"); + + if ( + !(table_link_mon = spider_open_sys_table( + thd, SPIDER_SYS_LINK_MON_TABLE_NAME_STR, + SPIDER_SYS_LINK_MON_TABLE_NAME_LEN, FALSE, &open_tables_backup, + need_lock, &error_num)) + ) { + my_error(error_num, MYF(0)); + goto error_open_sys_table; + } + + pthread_mutex_lock(&spider_mon_table_cache_mutex); + if (spider_mon_table_cache_version != spider_mon_table_cache_version_req) + { + /* reset */ + spider_mon_table_cache.elements = 0; + + if ((error_num = spider_sys_index_first(table_link_mon, + table_link_mon->s->primary_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_link_mon->file->print_error(error_num, MYF(0)); + goto error_sys_index_first; + } + } + + if (!error_num) + { + mon_key.db_name_length = SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE + 1; + mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1; + mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1; + do { + if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key, + mem_root, &same))) + goto error_get_sys_link_mon_key; + + if (!same) + { + mon_key.sort = spider_calc_for_sort(3, mon_key.db_name, + mon_key.table_name, mon_key.link_id); + if (push_dynamic(&spider_mon_table_cache, (uchar *) &mon_key)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_push_dynamic; + } + } + + if ((error_num = spider_sys_index_next(table_link_mon))) + { + if ( + error_num != HA_ERR_KEY_NOT_FOUND && + error_num != HA_ERR_END_OF_FILE + ) { + table_link_mon->file->print_error(error_num, MYF(0)); + goto error_sys_index_next; + } + } + } while (!error_num); + spider_sys_index_end(table_link_mon); + } + my_qsort( + (uchar *) dynamic_element(&spider_mon_table_cache, 0, SPIDER_MON_KEY *), + spider_mon_table_cache.elements, sizeof(SPIDER_MON_KEY), + (qsort_cmp) spider_compare_for_sort); + uint old_elements = spider_mon_table_cache.max_element; + freeze_size(&spider_mon_table_cache); + if (spider_mon_table_cache.max_element < old_elements) + { + spider_free_mem_calc(spider_current_trx, + spider_mon_table_cache_id, + spider_mon_table_cache.max_element * + spider_mon_table_cache.size_of_element); + } + spider_mon_table_cache_version = spider_mon_table_cache_version_req; + } + pthread_mutex_unlock(&spider_mon_table_cache_mutex); + spider_close_sys_table(thd, table_link_mon, &open_tables_backup, need_lock); + DBUG_RETURN(0); + +error_push_dynamic: +error_get_sys_link_mon_key: +error_sys_index_next: + spider_sys_index_end(table_link_mon); +error_sys_index_first: + pthread_mutex_unlock(&spider_mon_table_cache_mutex); + spider_close_sys_table(thd, table_link_mon, &open_tables_backup, need_lock); +error_open_sys_table: + DBUG_RETURN(error_num); +} + +int spider_ping_table_cache_compare( + TABLE *table, + MEM_ROOT *mem_root +) { + uint32 roop_count; + SPIDER_MON_KEY *mon_key; + char *db_name, *table_name, *link_id; + DBUG_ENTER("spider_ping_table_cache_compare"); + + if ( + !(db_name = get_field(mem_root, table->field[0])) || + !(table_name = get_field(mem_root, table->field[1])) || + !(link_id = get_field(mem_root, table->field[2])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_PRINT("info", ("spider db_name=%s", db_name)); + DBUG_PRINT("info", ("spider table_name=%s", table_name)); + DBUG_PRINT("info", ("spider link_id=%s", link_id)); + + pthread_mutex_lock(&spider_mon_table_cache_mutex); + for (roop_count = 0; roop_count < spider_mon_table_cache.elements; + roop_count++) + { + mon_key = dynamic_element(&spider_mon_table_cache, roop_count, + SPIDER_MON_KEY *); + DBUG_PRINT("info", ("spider roop_count=%d", roop_count)); + DBUG_PRINT("info", ("spider mon_key.db_name=%s", mon_key->db_name)); + DBUG_PRINT("info", ("spider mon_key.table_name=%s", mon_key->table_name)); + DBUG_PRINT("info", ("spider mon_key.link_id=%s", mon_key->link_id)); + if ( + !wild_case_compare(system_charset_info, db_name, mon_key->db_name) && + !wild_case_compare(system_charset_info, table_name, + mon_key->table_name) && + !wild_case_compare(system_charset_info, link_id, mon_key->link_id) + ) { + spider_store_db_and_table_name( + table, + mon_key->db_name, + mon_key->db_name_length, + mon_key->table_name, + mon_key->table_name_length + ); + spider_store_tables_link_idx_str( + table, + mon_key->link_id, + mon_key->link_id_length + ); + pthread_mutex_unlock(&spider_mon_table_cache_mutex); + DBUG_PRINT("info", ("spider found")); + DBUG_RETURN(0); + } + } + pthread_mutex_unlock(&spider_mon_table_cache_mutex); + DBUG_PRINT("info", ("spider not found")); + DBUG_RETURN(1); +} + +long long spider_ping_table_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + int error_num = 0, link_idx, flags, full_mon_count, current_mon_count, + success_count, fault_count, tmp_error_num = 0; + uint32 first_sid; + longlong limit, tmp_sid = -1; + SPIDER_MON_TABLE_RESULT *mon_table_result = + (SPIDER_MON_TABLE_RESULT *) initid->ptr; + SPIDER_TRX *trx = mon_table_result->trx; + THD *thd = trx->thd; + SPIDER_CONN *ping_conn = NULL, *mon_conn; + char *where_clause; + SPIDER_TABLE_MON_LIST *table_mon_list; + SPIDER_TABLE_MON *table_mon; + + char buf[MAX_FIELD_WIDTH]; + spider_string conv_name(buf, sizeof(buf), system_charset_info); + int conv_name_length; + char link_idx_str[SPIDER_SQL_INT_LEN]; + int link_idx_str_length; + bool get_lock = FALSE; + DBUG_ENTER("spider_ping_table_body"); + conv_name.init_calc_mem(135); + conv_name.length(0); + if ( + thd->open_tables != 0 || + thd->handler_tables_hash.records != 0 || + thd->derived_tables != 0 || + thd->lock != 0 || +#if MYSQL_VERSION_ID < 50500 + thd->locked_tables != 0 || + thd->prelocked_mode != NON_PRELOCKED +#else + thd->locked_tables_list.locked_tables() || + thd->locked_tables_mode != LTM_NONE +#endif + ) { + if (thd->open_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->open_tables", thd->open_tables); + } else if (thd->handler_tables_hash.records != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->handler_tables_hash.records", + (longlong) thd->handler_tables_hash.records); + } else if (thd->derived_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->derived_tables", thd->derived_tables); + } else if (thd->lock != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->lock", thd->lock); +#if MYSQL_VERSION_ID < 50500 + } else if (thd->locked_tables != 0) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->locked_tables", thd->locked_tables); + } else if (thd->prelocked_mode != NON_PRELOCKED) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->prelocked_mode", (longlong) thd->prelocked_mode); +#else + } else if (thd->locked_tables_list.locked_tables()) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_PTR, MYF(0), + "thd->locked_tables_list.locked_tables()", + thd->locked_tables_list.locked_tables()); + } else if (thd->locked_tables_mode != LTM_NONE) + { + my_printf_error(ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_USE_IF_OPEN_TABLE_STR_WITH_NUM, MYF(0), + "thd->locked_tables_mode", (longlong) thd->locked_tables_mode); +#endif + } + goto error; + } + + if ( + args->lengths[0] > SPIDER_CONNECT_INFO_MAX_LEN + ) { + my_printf_error(ER_SPIDER_UDF_PING_TABLE_PARAM_TOO_LONG_NUM, + ER_SPIDER_UDF_PING_TABLE_PARAM_TOO_LONG_STR, MYF(0)); + goto error; + } + if ( + args->lengths[0] == 0 + ) { + my_printf_error(ER_SPIDER_UDF_PING_TABLE_PARAM_REQIRED_NUM, + ER_SPIDER_UDF_PING_TABLE_PARAM_REQIRED_STR, MYF(0)); + goto error; + } + + link_idx = (int) (args->args[1] ? *((longlong *) args->args[1]) : 0); + flags = (int) (args->args[2] ? *((longlong *) args->args[2]) : 0); + limit = args->args[3] ? *((longlong *) args->args[3]) : 0; + where_clause = args->args[4] ? args->args[4] : (char *) ""; + + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d", + link_idx)); + + if (conv_name.append(args->args[0], args->lengths[0], + trx->thd->variables.character_set_client)) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + conv_name_length = conv_name.length(); + if (conv_name.reserve(link_idx_str_length + 1)) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + goto error; + } + conv_name.q_append(link_idx_str, link_idx_str_length + 1); + conv_name.length(conv_name.length() - 1); + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + if (!(table_mon_list = spider_get_ping_table_mon_list(trx, trx->thd, + &conv_name, conv_name_length, link_idx, global_system_variables.server_id, + TRUE, &error_num))) +#else + if (!(table_mon_list = spider_get_ping_table_mon_list(trx, trx->thd, + &conv_name, conv_name_length, link_idx, thd->server_id, TRUE, &error_num))) +#endif + goto error; + + if (table_mon_list->mon_status == SPIDER_LINK_MON_NG) + { + mon_table_result->result_status = SPIDER_LINK_MON_NG; + DBUG_PRINT("info", + ("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 1")); + goto end; + } + + if (args->args[5]) + tmp_sid = *((longlong *) args->args[5]); + + if (tmp_sid >= 0) + { + first_sid = (uint32) tmp_sid; + full_mon_count = (int) (args->args[6] ? *((longlong *) args->args[6]) : 0); + current_mon_count = + (int) (args->args[7] ? *((longlong *) args->args[7]) + 1 : 1); + if (full_mon_count != table_mon_list->list_size) + { + my_printf_error(ER_SPIDER_UDF_PING_TABLE_DIFFERENT_MON_NUM, + ER_SPIDER_UDF_PING_TABLE_DIFFERENT_MON_STR, MYF(0)); + goto error_with_free_table_mon_list; + } + } else { +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + first_sid = global_system_variables.server_id; +#else + first_sid = thd->server_id; +#endif + full_mon_count = table_mon_list->list_size; + current_mon_count = 1; + } + + success_count = (int) (args->args[8] ? *((longlong *) args->args[8]) : 0); + fault_count = (int) (args->args[9] ? *((longlong *) args->args[9]) : 0); + if ( + table_mon_list->mon_status != SPIDER_LINK_MON_NG && + !(ping_conn = spider_get_ping_table_tgt_conn(trx, + table_mon_list->share, &error_num)) + ) { + if (error_num == HA_ERR_OUT_OF_MEM) + goto error_with_free_table_mon_list; + else + thd->clear_error(); + } + if ( + table_mon_list->mon_status == SPIDER_LINK_MON_NG || + error_num || + (tmp_error_num = spider_db_udf_ping_table(table_mon_list, table_mon_list->share, trx, + ping_conn, where_clause, args->lengths[4], + (flags & SPIDER_UDF_PING_TABLE_PING_ONLY), + (flags & SPIDER_UDF_PING_TABLE_USE_WHERE), + limit + )) + ) { + if (tmp_error_num == HA_ERR_OUT_OF_MEM) + goto error_with_free_table_mon_list; + else if(tmp_error_num) + thd->clear_error(); + fault_count++; + error_num = 0; + if (fault_count > full_mon_count / 2) + { + mon_table_result->result_status = SPIDER_LINK_MON_NG; + DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2")); + if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) + { + pthread_mutex_lock(&table_mon_list->update_status_mutex); + if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) + { + table_mon_list->mon_status = SPIDER_LINK_MON_NG; + table_mon_list->share->link_statuses[0] = SPIDER_LINK_STATUS_NG; + spider_sys_update_tables_link_status(trx->thd, + conv_name.c_ptr(), conv_name_length, link_idx, + SPIDER_LINK_STATUS_NG, TRUE); + spider_sys_log_tables_link_failed(trx->thd, + conv_name.c_ptr(), conv_name_length, link_idx, TRUE); + } + pthread_mutex_unlock(&table_mon_list->update_status_mutex); + } + goto end; + } + } else { + success_count++; + if (success_count > full_mon_count / 2) + { + mon_table_result->result_status = SPIDER_LINK_MON_OK; + DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_OK 1")); + goto end; + } + } + + if (tmp_sid < 0) + { + if (!pthread_mutex_trylock(&table_mon_list->receptor_mutex)) + get_lock = TRUE; + } + + if ( + tmp_sid >= 0 || + get_lock + ) { + table_mon = table_mon_list->current->next; + while (TRUE) + { + if (!table_mon) + table_mon = table_mon_list->first; + if ( + table_mon->server_id == first_sid || + current_mon_count > full_mon_count + ) { + if (success_count + fault_count > full_mon_count / 2) + { + mon_table_result->result_status = SPIDER_LINK_MON_DRAW; + DBUG_PRINT("info",( + "spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW 1")); + } else { + mon_table_result->result_status = SPIDER_LINK_MON_DRAW_FEW_MON; + DBUG_PRINT("info",( + "spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW_FEW_MON 1")); + } + table_mon_list->last_receptor_result = mon_table_result->result_status; + break; + } + if ((mon_conn = spider_get_ping_table_tgt_conn(trx, + table_mon->share, &error_num)) + ) { + if (!spider_db_udf_ping_table_mon_next( + thd, table_mon, mon_conn, mon_table_result, args->args[0], + args->lengths[0], link_idx, + where_clause, args->lengths[4], first_sid, full_mon_count, + current_mon_count, success_count, fault_count, flags, limit)) + { + if ( + mon_table_result->result_status == SPIDER_LINK_MON_NG && + table_mon_list->mon_status != SPIDER_LINK_MON_NG + ) { + pthread_mutex_lock(&table_mon_list->update_status_mutex); + if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) + { + table_mon_list->mon_status = SPIDER_LINK_MON_NG; + table_mon_list->share->link_statuses[0] = SPIDER_LINK_STATUS_NG; + spider_sys_update_tables_link_status(trx->thd, + conv_name.c_ptr(), conv_name_length, link_idx, + SPIDER_LINK_STATUS_NG, TRUE); + spider_sys_log_tables_link_failed(trx->thd, + conv_name.c_ptr(), conv_name_length, link_idx, TRUE); + } + pthread_mutex_unlock(&table_mon_list->update_status_mutex); + } + table_mon_list->last_receptor_result = + mon_table_result->result_status; + break; + } + } + thd->clear_error(); + table_mon = table_mon->next; + current_mon_count++; + } + if (get_lock) + pthread_mutex_unlock(&table_mon_list->receptor_mutex); + } else { + pthread_mutex_lock(&table_mon_list->receptor_mutex); + mon_table_result->result_status = table_mon_list->last_receptor_result; + DBUG_PRINT("info",("spider mon_table_result->result_status=%d 1", + table_mon_list->last_receptor_result)); + pthread_mutex_unlock(&table_mon_list->receptor_mutex); + } + +end: + spider_free_ping_table_mon_list(table_mon_list); + DBUG_RETURN(mon_table_result->result_status); + +error_with_free_table_mon_list: + spider_free_ping_table_mon_list(table_mon_list); +error: + *error = 1; + DBUG_RETURN(0); +} + +my_bool spider_ping_table_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + int error_num; + THD *thd = current_thd; + SPIDER_TRX *trx; + SPIDER_MON_TABLE_RESULT *mon_table_result = NULL; + DBUG_ENTER("spider_ping_table_init_body"); + if (args->arg_count != 10) + { + strcpy(message, "spider_ping_table() requires 10 arguments"); + goto error; + } + if ( + args->arg_type[0] != STRING_RESULT || + args->arg_type[4] != STRING_RESULT + ) { + strcpy(message, "spider_ping_table() requires string 1st " + "and 5th arguments"); + goto error; + } + if ( + args->arg_type[1] != INT_RESULT || + args->arg_type[2] != INT_RESULT || + args->arg_type[3] != INT_RESULT || + args->arg_type[5] != INT_RESULT || + args->arg_type[6] != INT_RESULT || + args->arg_type[7] != INT_RESULT || + args->arg_type[8] != INT_RESULT || + args->arg_type[9] != INT_RESULT + ) { + strcpy(message, "spider_ping_table() requires integer 2nd, 3rd, 4,6,7,8," + "9th and 10th argument"); + goto error; + } + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + my_error(error_num, MYF(0)); +#if MYSQL_VERSION_ID < 50500 + strcpy(message, thd->main_da.message()); +#else + strcpy(message, thd->stmt_da->message()); +#endif + goto error; + } + + if (!(mon_table_result = (SPIDER_MON_TABLE_RESULT *) + spider_malloc(spider_current_trx, 11, sizeof(SPIDER_MON_TABLE_RESULT), + MYF(MY_WME | MY_ZEROFILL))) + ) { + strcpy(message, "spider_ping_table() out of memory"); + goto error; + } + mon_table_result->trx = trx; + initid->ptr = (char *) mon_table_result; + DBUG_RETURN(FALSE); + +error: + if (mon_table_result) + { + spider_free(spider_current_trx, mon_table_result, MYF(0)); + } + DBUG_RETURN(TRUE); +} + +void spider_ping_table_deinit_body( + UDF_INIT *initid +) { + SPIDER_MON_TABLE_RESULT *mon_table_result = + (SPIDER_MON_TABLE_RESULT *) initid->ptr; + DBUG_ENTER("spider_ping_table_deinit_body"); + if (mon_table_result) + { + spider_free(spider_current_trx, mon_table_result, MYF(0)); + } + DBUG_VOID_RETURN; +} + +long long spider_flush_table_mon_cache_body() +{ + DBUG_ENTER("spider_flush_table_mon_cache_body"); + spider_mon_table_cache_version_req++; + DBUG_RETURN(1); +} + +void spider_ping_table_free_mon_list( + SPIDER_TABLE_MON_LIST *table_mon_list +) { + DBUG_ENTER("spider_ping_table_free_mon_list"); + if (table_mon_list) + { + spider_ping_table_free_mon(table_mon_list->first); + spider_free_tmp_share_alloc(table_mon_list->share); + pthread_mutex_destroy(&table_mon_list->update_status_mutex); + pthread_mutex_destroy(&table_mon_list->monitor_mutex); + pthread_mutex_destroy(&table_mon_list->receptor_mutex); + pthread_mutex_destroy(&table_mon_list->caller_mutex); + spider_free(spider_current_trx, table_mon_list, MYF(0)); + } + DBUG_VOID_RETURN; +} + +void spider_ping_table_free_mon( + SPIDER_TABLE_MON *table_mon +) { + SPIDER_TABLE_MON *table_mon_next; + DBUG_ENTER("spider_ping_table_free_mon"); + while (table_mon) + { + spider_free_tmp_share_alloc(table_mon->share); + table_mon_next = table_mon->next; + spider_free(spider_current_trx, table_mon, MYF(0)); + table_mon = table_mon_next; + } + DBUG_VOID_RETURN; +} + +int spider_ping_table_mon_from_table( + SPIDER_TRX *trx, + THD *thd, + SPIDER_SHARE *share, + uint32 server_id, + char *conv_name, + uint conv_name_length, + int link_idx, + char *where_clause, + uint where_clause_length, + long monitoring_kind, + longlong monitoring_limit, + bool need_lock +) { + int error_num = 0, current_mon_count, flags; + uint32 first_sid; +/* + THD *thd = trx->thd; +*/ + SPIDER_TABLE_MON_LIST *table_mon_list; + SPIDER_TABLE_MON *table_mon; + SPIDER_MON_TABLE_RESULT mon_table_result; + SPIDER_CONN *mon_conn; + TABLE_SHARE *table_share = share->table_share; + char link_idx_str[SPIDER_SQL_INT_LEN]; + int link_idx_str_length; + uint sql_command = thd_sql_command(thd); + DBUG_ENTER("spider_ping_table_mon_from_table"); + if (table_share->tmp_table != NO_TMP_TABLE) + { + my_printf_error(ER_SPIDER_TMP_TABLE_MON_NUM, + ER_SPIDER_TMP_TABLE_MON_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_TMP_TABLE_MON_NUM); + } + if ( + sql_command == SQLCOM_DROP_TABLE || + sql_command == SQLCOM_ALTER_TABLE + ) { + my_printf_error(ER_SPIDER_MON_AT_ALTER_TABLE_NUM, + ER_SPIDER_MON_AT_ALTER_TABLE_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_MON_AT_ALTER_TABLE_NUM); + } + + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d", + link_idx)); +#ifdef _MSC_VER + spider_string conv_name_str(conv_name_length + link_idx_str_length + 1); + conv_name_str.set_charset(system_charset_info); + *((char *)(conv_name_str.ptr() + conv_name_length + link_idx_str_length)) = + '\0'; +#else + char buf[conv_name_length + link_idx_str_length + 1]; + buf[conv_name_length + link_idx_str_length] = '\0'; + spider_string conv_name_str(buf, conv_name_length + link_idx_str_length + 1, + system_charset_info); +#endif + conv_name_str.init_calc_mem(136); + conv_name_str.length(0); + conv_name_str.q_append(conv_name, conv_name_length); + conv_name_str.q_append(link_idx_str, link_idx_str_length + 1); + conv_name_str.length(conv_name_str.length() - 1); + + if (monitoring_kind == 1) + flags = SPIDER_UDF_PING_TABLE_PING_ONLY; + else if (monitoring_kind == 3) + flags = SPIDER_UDF_PING_TABLE_USE_WHERE; + else + flags = 0; + + if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, + &conv_name_str, conv_name_length, link_idx, server_id, need_lock, + &error_num))) + goto end; + + if (table_mon_list->mon_status == SPIDER_LINK_MON_NG) + { + DBUG_PRINT("info", + ("spider share->link_statuses[%d]=SPIDER_LINK_STATUS_NG", link_idx)); + share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG; + error_num = ER_SPIDER_LINK_MON_NG_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_NG_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + goto end_with_free_table_mon_list; + } + + if (!pthread_mutex_trylock(&table_mon_list->caller_mutex)) + { + table_mon = table_mon_list->current; + first_sid = table_mon->server_id; + current_mon_count = 1; + while (TRUE) + { + if (!table_mon) + table_mon = table_mon_list->first; + if ( + current_mon_count > table_mon_list->list_size || + (current_mon_count > 1 && table_mon->server_id == first_sid) + ) { + table_mon_list->last_caller_result = SPIDER_LINK_MON_DRAW_FEW_MON; + mon_table_result.result_status = SPIDER_LINK_MON_DRAW_FEW_MON; + DBUG_PRINT("info",( + "spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW_FEW_MON 1")); + error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + thd->clear_error(); + if ((mon_conn = spider_get_ping_table_tgt_conn(trx, + table_mon->share, &error_num)) + ) { + if (!spider_db_udf_ping_table_mon_next( + thd, table_mon, mon_conn, &mon_table_result, conv_name, + conv_name_length, link_idx, + where_clause, where_clause_length, -1, table_mon_list->list_size, + 0, 0, 0, flags, monitoring_limit)) + { + if ( + mon_table_result.result_status == SPIDER_LINK_MON_NG && + table_mon_list->mon_status != SPIDER_LINK_MON_NG + ) { + pthread_mutex_lock(&table_mon_list->update_status_mutex); + if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) + { + table_mon_list->mon_status = SPIDER_LINK_MON_NG; + table_mon_list->share->link_statuses[0] = SPIDER_LINK_STATUS_NG; + DBUG_PRINT("info", ( + "spider share->link_statuses[%d]=SPIDER_LINK_STATUS_NG", + link_idx)); + share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG; + spider_sys_update_tables_link_status(thd, conv_name, + conv_name_length, link_idx, SPIDER_LINK_STATUS_NG, need_lock); + spider_sys_log_tables_link_failed(thd, conv_name, + conv_name_length, link_idx, need_lock); + } + pthread_mutex_unlock(&table_mon_list->update_status_mutex); + } + table_mon_list->last_caller_result = mon_table_result.result_status; + if (mon_table_result.result_status == SPIDER_LINK_MON_OK) + { + error_num = ER_SPIDER_LINK_MON_OK_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_OK_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + if (mon_table_result.result_status == SPIDER_LINK_MON_NG) + { + error_num = ER_SPIDER_LINK_MON_NG_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_NG_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + if (mon_table_result.result_status == + SPIDER_LINK_MON_DRAW_FEW_MON) + { + error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + error_num = ER_SPIDER_LINK_MON_DRAW_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_DRAW_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + } + table_mon = table_mon->next; + current_mon_count++; + } + pthread_mutex_unlock(&table_mon_list->caller_mutex); + } else { + pthread_mutex_lock(&table_mon_list->caller_mutex); + switch (table_mon_list->last_caller_result) + { + case SPIDER_LINK_MON_OK: + error_num = ER_SPIDER_LINK_MON_OK_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_OK_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + case SPIDER_LINK_MON_NG: + error_num = ER_SPIDER_LINK_MON_NG_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_NG_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + case SPIDER_LINK_MON_DRAW_FEW_MON: + error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + default: + error_num = ER_SPIDER_LINK_MON_DRAW_NUM; + my_printf_error(error_num, + ER_SPIDER_LINK_MON_DRAW_STR, MYF(0), + table_mon_list->share->tgt_dbs[0], + table_mon_list->share->tgt_table_names[0]); + break; + } + pthread_mutex_unlock(&table_mon_list->caller_mutex); + } + +end_with_free_table_mon_list: + spider_free_ping_table_mon_list(table_mon_list); +end: + DBUG_RETURN(error_num); +} diff --git a/storage/spider/spd_ping_table.h b/storage/spider/spd_ping_table.h new file mode 100644 index 00000000000..aca93012d78 --- /dev/null +++ b/storage/spider/spd_ping_table.h @@ -0,0 +1,102 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list( + SPIDER_TRX *trx, + THD *thd, + spider_string *str, + uint conv_name_length, + int link_idx, + uint32 server_id, + bool need_lock, + int *error_num +); + +void spider_free_ping_table_mon_list( + SPIDER_TABLE_MON_LIST *table_mon_list +); + +void spider_release_ping_table_mon_list_loop( + uint mutex_hash, + SPIDER_TABLE_MON_LIST *table_mon_list +); + +void spider_release_ping_table_mon_list( + const char *conv_name, + uint conv_name_length, + int link_idx +); + +int spider_get_ping_table_mon( + THD *thd, + SPIDER_TABLE_MON_LIST *table_mon_list, + char *name, + uint name_length, + int link_idx, + uint32 server_id, + MEM_ROOT *mem_root, + bool need_lock +); + +SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt( + THD *thd, + char *name, + uint name_length, + int link_idx, + uint32 server_id, + spider_string *str, + bool need_lock, + int *error_num +); + +SPIDER_CONN *spider_get_ping_table_tgt_conn( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int *error_num +); + +int spider_init_ping_table_mon_cache( + THD *thd, + MEM_ROOT *mem_root, + bool need_lock +); + +int spider_ping_table_cache_compare( + TABLE *table, + MEM_ROOT *mem_root +); + +void spider_ping_table_free_mon_list( + SPIDER_TABLE_MON_LIST *table_mon_list +); + +void spider_ping_table_free_mon( + SPIDER_TABLE_MON *table_mon +); + +int spider_ping_table_mon_from_table( + SPIDER_TRX *trx, + THD *thd, + SPIDER_SHARE *share, + uint32 server_id, + char *conv_name, + uint conv_name_length, + int link_idx, + char *where_clause, + uint where_clause_length, + long monitoring_kind, + longlong monitoring_limit, + bool need_lock +); diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc new file mode 100644 index 00000000000..3e300bd21c9 --- /dev/null +++ b/storage/spider/spd_sys_table.cc @@ -0,0 +1,2417 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "key.h" +#include "sql_base.h" +#endif +#include "sql_select.h" +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_sys_table.h" +#include "spd_malloc.h" + +extern handlerton *spider_hton_ptr; + +#if MYSQL_VERSION_ID < 50500 +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + Open_tables_state *open_tables_backup, + bool need_lock, + int *error_num +) +#else +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + Open_tables_backup *open_tables_backup, + bool need_lock, + int *error_num +) +#endif +{ + TABLE *table; + TABLE_LIST tables; +#if MYSQL_VERSION_ID < 50500 + TABLE_SHARE *table_share; + char table_key[MAX_DBKEY_LENGTH]; + uint table_key_length; +#endif + DBUG_ENTER("spider_open_sys_table"); + +#if MYSQL_VERSION_ID < 50500 + memset(&tables, 0, sizeof(TABLE_LIST)); + tables.db = (char*)"mysql"; + tables.db_length = sizeof("mysql") - 1; + tables.alias = tables.table_name = (char *) table_name; + tables.table_name_length = table_name_length; + tables.lock_type = (write ? TL_WRITE : TL_READ); +#else + tables.init_one_table( + "mysql", sizeof("mysql") - 1, table_name, table_name_length, table_name, + (write ? TL_WRITE : TL_READ)); +#endif + +#if MYSQL_VERSION_ID < 50500 + if (need_lock) + { +#endif +#if MYSQL_VERSION_ID < 50500 + if (!(table = open_performance_schema_table(thd, &tables, + open_tables_backup))) +#else + if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup))) +#endif + { + *error_num = my_errno; + DBUG_RETURN(NULL); + } +#if MYSQL_VERSION_ID < 50500 + } else { + thd->reset_n_backup_open_tables_state(open_tables_backup); + + if (!(table = (TABLE*) spider_malloc(spider_current_trx, 12, + sizeof(*table), MYF(MY_WME)))) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_malloc; + } + + table_key_length = + create_table_def_key(thd, table_key, &tables, FALSE); + + if (!(table_share = get_table_share(thd, + &tables, table_key, table_key_length, 0, error_num))) + goto error; + if (open_table_from_share(thd, table_share, tables.alias, + (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX), + READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD, + (uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER, + table, FALSE) + ) { + release_table_share(table_share, RELEASE_NORMAL); + *error_num = my_errno; + goto error; + } + } +#endif + if (table_name_length == SPIDER_SYS_XA_TABLE_NAME_LEN) + { + if ( + !memcmp(table_name, + SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN) && + table->s->fields != SPIDER_SYS_XA_COL_CNT + ) { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + spider_free(spider_current_trx, table, MYF(0)); + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_XA_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + } else if (table_name_length == SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN) + { + if ( + !memcmp(table_name, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN) && + table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT + ) { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + spider_free(spider_current_trx, table, MYF(0)); + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + } else if (table_name_length == SPIDER_SYS_TABLES_TABLE_NAME_LEN) + { + if ( + !memcmp(table_name, + SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN) && + table->s->fields != SPIDER_SYS_TABLES_COL_CNT + ) { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + spider_free(spider_current_trx, table, MYF(0)); + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_TABLES_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + } else if (table_name_length == SPIDER_SYS_LINK_MON_TABLE_NAME_LEN) + { + if ( + !memcmp(table_name, + SPIDER_SYS_LINK_MON_TABLE_NAME_STR, + SPIDER_SYS_LINK_MON_TABLE_NAME_LEN) && + table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT + ) { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + spider_free(spider_current_trx, table, MYF(0)); + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_LINK_MON_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + } + DBUG_RETURN(table); + +#if MYSQL_VERSION_ID < 50500 +error: + spider_free(spider_current_trx, table, MYF(0)); +error_malloc: + thd->restore_backup_open_tables_state(open_tables_backup); +#endif +error_col_num_chk: + DBUG_RETURN(NULL); +} + +#if MYSQL_VERSION_ID < 50500 +void spider_close_sys_table( + THD *thd, + TABLE *table, + Open_tables_state *open_tables_backup, + bool need_lock +) +#else +void spider_close_sys_table( + THD *thd, + TABLE *table, + Open_tables_backup *open_tables_backup, + bool need_lock +) +#endif +{ + DBUG_ENTER("spider_close_sys_table"); +#if MYSQL_VERSION_ID < 50500 + if (need_lock) + { + close_performance_schema_table(thd, open_tables_backup); + } else { + table->file->ha_reset(); + closefrm(table, TRUE); + spider_free(spider_current_trx, table, MYF(0)); + thd->restore_backup_open_tables_state(open_tables_backup); + } +#else + spider_sys_close_table(thd, open_tables_backup); +#endif + DBUG_VOID_RETURN; +} + +#if MYSQL_VERSION_ID < 50500 +#else +bool spider_sys_open_tables( + THD *thd, + TABLE_LIST **tables, + Open_tables_backup *open_tables_backup +) { + uint counter; + ulonglong utime_after_lock_backup = thd->utime_after_lock; + DBUG_ENTER("spider_sys_open_tables"); + thd->reset_n_backup_open_tables_state(open_tables_backup); + if (open_tables(thd, tables, &counter, + MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE + )) { + thd->restore_backup_open_tables_state(open_tables_backup); + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(TRUE); + } + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(FALSE); +} + +TABLE *spider_sys_open_table( + THD *thd, + TABLE_LIST *tables, + Open_tables_backup *open_tables_backup +) { + TABLE *table; + ulonglong utime_after_lock_backup = thd->utime_after_lock; + DBUG_ENTER("spider_sys_open_table"); + thd->reset_n_backup_open_tables_state(open_tables_backup); + if ((table = open_ltable(thd, tables, tables->lock_type, + MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | + MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE + ))) { + table->use_all_columns(); + table->no_replicate = 1; + } else + thd->restore_backup_open_tables_state(open_tables_backup); + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(table); +} + +void spider_sys_close_table( + THD *thd, + Open_tables_backup *open_tables_backup +) { + DBUG_ENTER("spider_sys_close_table"); + close_thread_tables(thd); + thd->restore_backup_open_tables_state(open_tables_backup); + DBUG_VOID_RETURN; +} +#endif + +int spider_sys_index_init( + TABLE *table, + uint idx, + bool sorted +) { + DBUG_ENTER("spider_sys_index_init"); + DBUG_RETURN(table->file->ha_index_init(idx, sorted)); +} + +int spider_sys_index_end( + TABLE *table +) { + DBUG_ENTER("spider_sys_index_end"); + DBUG_RETURN(table->file->ha_index_end()); +} + +int spider_sys_rnd_init( + TABLE *table, + bool scan +) { + DBUG_ENTER("spider_sys_rnd_init"); + DBUG_RETURN(table->file->ha_rnd_init(scan)); +} + +int spider_sys_rnd_end( + TABLE *table +) { + DBUG_ENTER("spider_sys_rnd_end"); + DBUG_RETURN(table->file->ha_rnd_end()); +} + +int spider_check_sys_table( + TABLE *table, + char *table_key +) { + DBUG_ENTER("spider_check_sys_table"); + + key_copy( + (uchar *) table_key, + table->record[0], + table->key_info, + table->key_info->key_length); + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + DBUG_RETURN(table->file->ha_index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, HA_READ_KEY_EXACT)); +#else + DBUG_RETURN(table->file->index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, HA_READ_KEY_EXACT)); +#endif +} + +int spider_check_sys_table_with_find_flag( + TABLE *table, + char *table_key, + enum ha_rkey_function find_flag +) { + DBUG_ENTER("spider_check_sys_table"); + + key_copy( + (uchar *) table_key, + table->record[0], + table->key_info, + table->key_info->key_length); + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + DBUG_RETURN(table->file->ha_index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, find_flag)); +#else + DBUG_RETURN(table->file->index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, find_flag)); +#endif +} + +int spider_get_sys_table_by_idx( + TABLE *table, + char *table_key, + const int idx, + const int col_count +) { + int error_num; + DBUG_ENTER("spider_get_sys_table_by_idx"); + if ((error_num = spider_sys_index_init(table, idx, FALSE))) + DBUG_RETURN(error_num); + + key_copy( + (uchar *) table_key, + table->record[0], + table->key_info, + table->key_info->key_length); + + if ( +/* +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + (error_num = table->file->ha_index_read_idx_map( + table->record[0], idx, (uchar *) table_key, + make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) +#else + (error_num = table->file->index_read_idx_map( + table->record[0], idx, (uchar *) table_key, + make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) +#endif +*/ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + (error_num = table->file->ha_index_read_map( + table->record[0], (uchar *) table_key, + make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) +#else + (error_num = table->file->index_read_map( + table->record[0], (uchar *) table_key, + make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) +#endif + ) { + spider_sys_index_end(table); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_sys_index_next_same( + TABLE *table, + char *table_key +) { + DBUG_ENTER("spider_sys_index_next_same"); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + DBUG_RETURN(table->file->ha_index_next_same( + table->record[0], + (const uchar*) table_key, + table->key_info->key_length)); +#else + DBUG_RETURN(table->file->index_next_same( + table->record[0], + (const uchar*) table_key, + table->key_info->key_length)); +#endif +} + +int spider_sys_index_first( + TABLE *table, + const int idx +) { + int error_num; + DBUG_ENTER("spider_sys_index_first"); + if ((error_num = spider_sys_index_init(table, idx, FALSE))) + DBUG_RETURN(error_num); + + if ( +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + (error_num = table->file->ha_index_first(table->record[0])) +#else + (error_num = table->file->index_first(table->record[0])) +#endif + ) { + spider_sys_index_end(table); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_sys_index_next( + TABLE *table +) { + DBUG_ENTER("spider_sys_index_next"); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + DBUG_RETURN(table->file->ha_index_next(table->record[0])); +#else + DBUG_RETURN(table->file->index_next(table->record[0])); +#endif +} + +void spider_store_xa_pk( + TABLE *table, + XID *xid +) { + DBUG_ENTER("spider_store_xa_pk"); + table->field[0]->store(xid->formatID); + table->field[1]->store(xid->gtrid_length); + table->field[3]->store( + xid->data, + (uint) xid->gtrid_length + xid->bqual_length, + system_charset_info); + DBUG_VOID_RETURN; +} + +void spider_store_xa_bqual_length( + TABLE *table, + XID *xid +) { + DBUG_ENTER("spider_store_xa_bqual_length"); + table->field[2]->store(xid->bqual_length); + DBUG_VOID_RETURN; +} + +void spider_store_xa_status( + TABLE *table, + const char *status +) { + DBUG_ENTER("spider_store_xa_status"); + table->field[4]->store( + status, + (uint) strlen(status), + system_charset_info); + DBUG_VOID_RETURN; +} + +void spider_store_xa_member_pk( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_store_xa_member_pk"); + table->field[0]->store(xid->formatID); + table->field[1]->store(xid->gtrid_length); + table->field[3]->store( + xid->data, + (uint) xid->gtrid_length + xid->bqual_length, + system_charset_info); + table->field[5]->store( + conn->tgt_host, + (uint) conn->tgt_host_length, + system_charset_info); + table->field[6]->store( + conn->tgt_port); + table->field[7]->store( + conn->tgt_socket, + (uint) conn->tgt_socket_length, + system_charset_info); + DBUG_VOID_RETURN; +} + +void spider_store_xa_member_info( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_store_xa_member_info"); + table->field[2]->store(xid->bqual_length); + table->field[4]->store( + conn->tgt_wrapper, + (uint) conn->tgt_wrapper_length, + system_charset_info); + table->field[8]->store( + conn->tgt_username, + (uint) conn->tgt_username_length, + system_charset_info); + table->field[9]->store( + conn->tgt_password, + (uint) conn->tgt_password_length, + system_charset_info); + if (conn->tgt_ssl_ca) + { + table->field[10]->set_notnull(); + table->field[10]->store( + conn->tgt_ssl_ca, + (uint) conn->tgt_ssl_ca_length, + system_charset_info); + } else { + table->field[10]->set_null(); + table->field[10]->reset(); + } + if (conn->tgt_ssl_capath) + { + table->field[11]->set_notnull(); + table->field[11]->store( + conn->tgt_ssl_capath, + (uint) conn->tgt_ssl_capath_length, + system_charset_info); + } else { + table->field[11]->set_null(); + table->field[11]->reset(); + } + if (conn->tgt_ssl_cert) + { + table->field[12]->set_notnull(); + table->field[12]->store( + conn->tgt_ssl_cert, + (uint) conn->tgt_ssl_cert_length, + system_charset_info); + } else { + table->field[12]->set_null(); + table->field[12]->reset(); + } + if (conn->tgt_ssl_cipher) + { + table->field[13]->set_notnull(); + table->field[13]->store( + conn->tgt_ssl_cipher, + (uint) conn->tgt_ssl_cipher_length, + system_charset_info); + } else { + table->field[13]->set_null(); + table->field[13]->reset(); + } + if (conn->tgt_ssl_key) + { + table->field[14]->set_notnull(); + table->field[14]->store( + conn->tgt_ssl_key, + (uint) conn->tgt_ssl_key_length, + system_charset_info); + } else { + table->field[14]->set_null(); + table->field[14]->reset(); + } + if (conn->tgt_ssl_vsc >= 0) + { + table->field[15]->set_notnull(); + table->field[15]->store( + conn->tgt_ssl_vsc); + } else { + table->field[15]->set_null(); + table->field[15]->reset(); + } + if (conn->tgt_default_file) + { + table->field[16]->set_notnull(); + table->field[16]->store( + conn->tgt_default_file, + (uint) conn->tgt_default_file_length, + system_charset_info); + } else { + table->field[16]->set_null(); + table->field[16]->reset(); + } + if (conn->tgt_default_group) + { + table->field[17]->set_notnull(); + table->field[17]->store( + conn->tgt_default_group, + (uint) conn->tgt_default_group_length, + system_charset_info); + } else { + table->field[17]->set_null(); + table->field[17]->reset(); + } + DBUG_VOID_RETURN; +} + +void spider_store_tables_name( + TABLE *table, + const char *name, + const uint name_length +) { + const char *ptr_db, *ptr_table; + my_ptrdiff_t ptr_diff_db, ptr_diff_table; + DBUG_ENTER("spider_store_tables_name"); + if (name[0] == FN_CURLIB && name[1] == FN_LIBCHAR) + { + ptr_db = strchr(name, FN_LIBCHAR); + ptr_db++; + ptr_diff_db = PTR_BYTE_DIFF(ptr_db, name); + DBUG_PRINT("info",("spider ptr_diff_db = %lld", (longlong) ptr_diff_db)); + ptr_table = strchr(ptr_db, FN_LIBCHAR); + ptr_table++; + ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db); + DBUG_PRINT("info",("spider ptr_diff_table = %lld", + (longlong) ptr_diff_table)); + } else { + DBUG_PRINT("info",("spider temporary table")); + ptr_db = ""; + ptr_diff_db = 1; + ptr_table = ""; + ptr_diff_table = 1; + } + table->field[0]->store( + ptr_db, + ptr_diff_table - 1, + system_charset_info); + DBUG_PRINT("info",("spider field[0]->null_bit = %d", + table->field[0]->null_bit)); + table->field[1]->store( + ptr_table, + name_length - ptr_diff_db - ptr_diff_table, + system_charset_info); + DBUG_PRINT("info",("spider field[1]->null_bit = %d", + table->field[1]->null_bit)); + DBUG_VOID_RETURN; +} + +void spider_store_db_and_table_name( + TABLE *table, + const char *db_name, + const uint db_name_length, + const char *table_name, + const uint table_name_length +) { + DBUG_ENTER("spider_store_db_and_table_name"); + table->field[0]->store( + db_name, + db_name_length, + system_charset_info); + DBUG_PRINT("info",("spider field[0]->null_bit = %d", + table->field[0]->null_bit)); + table->field[1]->store( + table_name, + table_name_length, + system_charset_info); + DBUG_PRINT("info",("spider field[1]->null_bit = %d", + table->field[1]->null_bit)); + DBUG_VOID_RETURN; +} + +void spider_store_tables_link_idx( + TABLE *table, + int link_idx +) { + DBUG_ENTER("spider_store_tables_link_idx"); + table->field[2]->set_notnull(); + table->field[2]->store(link_idx); + DBUG_VOID_RETURN; +} + +void spider_store_tables_link_idx_str( + TABLE *table, + const char *link_idx, + const uint link_idx_length +) { + DBUG_ENTER("spider_store_tables_link_idx_str"); + table->field[2]->store( + link_idx, + link_idx_length, + system_charset_info); + DBUG_PRINT("info",("spider field[2]->null_bit = %d", + table->field[2]->null_bit)); + DBUG_VOID_RETURN; +} + +void spider_store_tables_priority( + TABLE *table, + longlong priority +) { + DBUG_ENTER("spider_store_tables_priority"); + DBUG_PRINT("info",("spider priority = %lld", priority)); + table->field[3]->store(priority, FALSE); + DBUG_VOID_RETURN; +} + +void spider_store_tables_connect_info( + TABLE *table, + SPIDER_ALTER_TABLE *alter_table, + int link_idx +) { + DBUG_ENTER("spider_store_tables_connect_info"); + if (alter_table->tmp_server_names[link_idx]) + { + table->field[4]->set_notnull(); + table->field[4]->store( + alter_table->tmp_server_names[link_idx], + (uint) alter_table->tmp_server_names_lengths[link_idx], + system_charset_info); + } else { + table->field[4]->set_null(); + table->field[4]->reset(); + } + if (alter_table->tmp_tgt_wrappers[link_idx]) + { + table->field[5]->set_notnull(); + table->field[5]->store( + alter_table->tmp_tgt_wrappers[link_idx], + (uint) alter_table->tmp_tgt_wrappers_lengths[link_idx], + system_charset_info); + } else { + table->field[5]->set_null(); + table->field[5]->reset(); + } + if (alter_table->tmp_tgt_hosts[link_idx]) + { + table->field[6]->set_notnull(); + table->field[6]->store( + alter_table->tmp_tgt_hosts[link_idx], + (uint) alter_table->tmp_tgt_hosts_lengths[link_idx], + system_charset_info); + } else { + table->field[6]->set_null(); + table->field[6]->reset(); + } + if (alter_table->tmp_tgt_ports[link_idx] >= 0) + { + table->field[7]->set_notnull(); + table->field[7]->store( + alter_table->tmp_tgt_ports[link_idx]); + } else { + table->field[7]->set_null(); + table->field[7]->reset(); + } + if (alter_table->tmp_tgt_sockets[link_idx]) + { + table->field[8]->set_notnull(); + table->field[8]->store( + alter_table->tmp_tgt_sockets[link_idx], + (uint) alter_table->tmp_tgt_sockets_lengths[link_idx], + system_charset_info); + } else { + table->field[8]->set_null(); + table->field[8]->reset(); + } + if (alter_table->tmp_tgt_usernames[link_idx]) + { + table->field[9]->set_notnull(); + table->field[9]->store( + alter_table->tmp_tgt_usernames[link_idx], + (uint) alter_table->tmp_tgt_usernames_lengths[link_idx], + system_charset_info); + } else { + table->field[9]->set_null(); + table->field[9]->reset(); + } + if (alter_table->tmp_tgt_passwords[link_idx]) + { + table->field[10]->set_notnull(); + table->field[10]->store( + alter_table->tmp_tgt_passwords[link_idx], + (uint) alter_table->tmp_tgt_passwords_lengths[link_idx], + system_charset_info); + } else { + table->field[10]->set_null(); + table->field[10]->reset(); + } + if (alter_table->tmp_tgt_ssl_cas[link_idx]) + { + table->field[11]->set_notnull(); + table->field[11]->store( + alter_table->tmp_tgt_ssl_cas[link_idx], + (uint) alter_table->tmp_tgt_ssl_cas_lengths[link_idx], + system_charset_info); + } else { + table->field[11]->set_null(); + table->field[11]->reset(); + } + if (alter_table->tmp_tgt_ssl_capaths[link_idx]) + { + table->field[12]->set_notnull(); + table->field[12]->store( + alter_table->tmp_tgt_ssl_capaths[link_idx], + (uint) alter_table->tmp_tgt_ssl_capaths_lengths[link_idx], + system_charset_info); + } else { + table->field[12]->set_null(); + table->field[12]->reset(); + } + if (alter_table->tmp_tgt_ssl_certs[link_idx]) + { + table->field[13]->set_notnull(); + table->field[13]->store( + alter_table->tmp_tgt_ssl_certs[link_idx], + (uint) alter_table->tmp_tgt_ssl_certs_lengths[link_idx], + system_charset_info); + } else { + table->field[13]->set_null(); + table->field[13]->reset(); + } + if (alter_table->tmp_tgt_ssl_ciphers[link_idx]) + { + table->field[14]->set_notnull(); + table->field[14]->store( + alter_table->tmp_tgt_ssl_ciphers[link_idx], + (uint) alter_table->tmp_tgt_ssl_ciphers_lengths[link_idx], + system_charset_info); + } else { + table->field[14]->set_null(); + table->field[14]->reset(); + } + if (alter_table->tmp_tgt_ssl_keys[link_idx]) + { + table->field[15]->set_notnull(); + table->field[15]->store( + alter_table->tmp_tgt_ssl_keys[link_idx], + (uint) alter_table->tmp_tgt_ssl_keys_lengths[link_idx], + system_charset_info); + } else { + table->field[15]->set_null(); + table->field[15]->reset(); + } + if (alter_table->tmp_tgt_ssl_vscs[link_idx] >= 0) + { + table->field[16]->set_notnull(); + table->field[16]->store( + alter_table->tmp_tgt_ssl_vscs[link_idx]); + } else { + table->field[16]->set_null(); + table->field[16]->reset(); + } + if (alter_table->tmp_tgt_default_files[link_idx]) + { + table->field[17]->set_notnull(); + table->field[17]->store( + alter_table->tmp_tgt_default_files[link_idx], + (uint) alter_table->tmp_tgt_default_files_lengths[link_idx], + system_charset_info); + } else { + table->field[17]->set_null(); + table->field[17]->reset(); + } + if (alter_table->tmp_tgt_default_groups[link_idx]) + { + table->field[18]->set_notnull(); + table->field[18]->store( + alter_table->tmp_tgt_default_groups[link_idx], + (uint) alter_table->tmp_tgt_default_groups_lengths[link_idx], + system_charset_info); + } else { + table->field[18]->set_null(); + table->field[18]->reset(); + } + if (alter_table->tmp_tgt_dbs[link_idx]) + { + table->field[19]->set_notnull(); + table->field[19]->store( + alter_table->tmp_tgt_dbs[link_idx], + (uint) alter_table->tmp_tgt_dbs_lengths[link_idx], + system_charset_info); + } else { + table->field[19]->set_null(); + table->field[19]->reset(); + } + if (alter_table->tmp_tgt_table_names[link_idx]) + { + table->field[20]->set_notnull(); + table->field[20]->store( + alter_table->tmp_tgt_table_names[link_idx], + (uint) alter_table->tmp_tgt_table_names_lengths[link_idx], + system_charset_info); + } else { + table->field[20]->set_null(); + table->field[20]->reset(); + } + DBUG_VOID_RETURN; +} + +void spider_store_tables_link_status( + TABLE *table, + long link_status +) { + DBUG_ENTER("spider_store_tables_link_status"); + DBUG_PRINT("info",("spider link_status = %ld", link_status)); + if (link_status > SPIDER_LINK_STATUS_NO_CHANGE) + table->field[21]->store(link_status, FALSE); + DBUG_VOID_RETURN; +} + +void spider_store_link_chk_server_id( + TABLE *table, + uint32 server_id +) { + DBUG_ENTER("spider_store_link_chk_server_id"); + table->field[3]->set_notnull(); + table->field[3]->store(server_id); + DBUG_VOID_RETURN; +} + +int spider_insert_xa( + TABLE *table, + XID *xid, + const char *status +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_insert_xa"); + table->use_all_columns(); + empty_record(table); + spider_store_xa_pk(table, xid); + + if ((error_num = spider_check_sys_table(table, table_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + table->use_all_columns(); + spider_store_xa_bqual_length(table, xid); + spider_store_xa_status(table, status); + if ((error_num = table->file->ha_write_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } else { + my_message(ER_SPIDER_XA_EXISTS_NUM, ER_SPIDER_XA_EXISTS_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_XA_EXISTS_NUM); + } + + DBUG_RETURN(0); +} + +int spider_insert_xa_member( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_insert_xa_member"); + table->use_all_columns(); + empty_record(table); + spider_store_xa_member_pk(table, xid, conn); + + if ((error_num = spider_check_sys_table(table, table_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + table->use_all_columns(); + spider_store_xa_member_info(table, xid, conn); + if ((error_num = table->file->ha_write_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } else { + my_message(ER_SPIDER_XA_MEMBER_EXISTS_NUM, ER_SPIDER_XA_MEMBER_EXISTS_STR, + MYF(0)); + DBUG_RETURN(ER_SPIDER_XA_MEMBER_EXISTS_NUM); + } + + DBUG_RETURN(0); +} + +int spider_insert_tables( + TABLE *table, + SPIDER_SHARE *share +) { + int error_num, roop_count; + DBUG_ENTER("spider_insert_tables"); + table->use_all_columns(); + empty_record(table); + + spider_store_tables_name(table, share->table_name, share->table_name_length); + spider_store_tables_priority(table, share->priority); + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + spider_store_tables_link_idx(table, roop_count); + spider_store_tables_connect_info(table, &share->alter_table, roop_count); + spider_store_tables_link_status(table, + share->alter_table.tmp_link_statuses[roop_count] > + SPIDER_LINK_STATUS_NO_CHANGE ? + share->alter_table.tmp_link_statuses[roop_count] : + SPIDER_LINK_STATUS_OK); + if ((error_num = table->file->ha_write_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_log_tables_link_failed( + TABLE *table, + char *name, + uint name_length, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_log_tables_link_failed"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + spider_store_tables_link_idx(table, link_idx); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 +#else + if (table->field[3] == table->timestamp_field) + table->timestamp_field->set_time(); +#endif + if ((error_num = table->file->ha_write_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_update_xa( + TABLE *table, + XID *xid, + const char *status +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_update_xa"); + table->use_all_columns(); + spider_store_xa_pk(table, xid); + + if ((error_num = spider_check_sys_table(table, table_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR, + MYF(0)); + DBUG_RETURN(ER_SPIDER_XA_NOT_EXISTS_NUM); + } else { + store_record(table, record[1]); + table->use_all_columns(); + spider_store_xa_status(table, status); + if ( + (error_num = table->file->ha_update_row( + table->record[1], table->record[0])) && + error_num != HA_ERR_RECORD_IS_THE_SAME + ) { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_update_tables_name( + TABLE *table, + const char *from, + const char *to, + int *old_link_count +) { + int error_num, roop_count = 0; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_update_tables_name"); + table->use_all_columns(); + while (TRUE) + { + spider_store_tables_name(table, from, strlen(from)); + spider_store_tables_link_idx(table, roop_count); + if ((error_num = spider_check_sys_table(table, table_key))) + { + if ( + roop_count && + (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + ) + break; + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } else { + store_record(table, record[1]); + table->use_all_columns(); + spider_store_tables_name(table, to, strlen(to)); + if ( + (error_num = table->file->ha_update_row( + table->record[1], table->record[0])) && + error_num != HA_ERR_RECORD_IS_THE_SAME + ) { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + roop_count++; + } + + *old_link_count = roop_count; + DBUG_RETURN(0); +} + +int spider_update_tables_priority( + TABLE *table, + SPIDER_ALTER_TABLE *alter_table, + const char *name, + int *old_link_count +) { + int error_num, roop_count; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_update_tables_priority"); + table->use_all_columns(); + for (roop_count = 0; roop_count < (int) alter_table->all_link_count; + roop_count++) + { + spider_store_tables_name(table, alter_table->table_name, + alter_table->table_name_length); + spider_store_tables_link_idx(table, roop_count); + if ((error_num = spider_check_sys_table(table, table_key))) + { + if ( + roop_count && + (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + ) { + *old_link_count = roop_count; + + /* insert for adding link */ + spider_store_tables_name(table, name, strlen(name)); + spider_store_tables_priority(table, alter_table->tmp_priority); + do { + spider_store_tables_link_idx(table, roop_count); + spider_store_tables_connect_info(table, alter_table, roop_count); + spider_store_tables_link_status(table, + alter_table->tmp_link_statuses[roop_count] != + SPIDER_LINK_STATUS_NO_CHANGE ? + alter_table->tmp_link_statuses[roop_count] : + SPIDER_LINK_STATUS_OK); + if ((error_num = table->file->ha_write_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + roop_count++; + } while (roop_count < (int) alter_table->all_link_count); + DBUG_RETURN(0); + } else { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } else { + store_record(table, record[1]); + table->use_all_columns(); + spider_store_tables_name(table, name, strlen(name)); + spider_store_tables_priority(table, alter_table->tmp_priority); + spider_store_tables_connect_info(table, alter_table, roop_count); + spider_store_tables_link_status(table, + alter_table->tmp_link_statuses[roop_count]); + if ( + (error_num = table->file->ha_update_row( + table->record[1], table->record[0])) && + error_num != HA_ERR_RECORD_IS_THE_SAME + ) { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + } + while (TRUE) + { + /* delete for subtracting link */ + spider_store_tables_link_idx(table, roop_count); + if ((error_num = spider_check_sys_table(table, table_key))) + { + if ( + roop_count && + (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + ) + break; + else { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + if ((error_num = table->file->ha_delete_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + roop_count++; + } + + *old_link_count = roop_count; + DBUG_RETURN(0); +} + +int spider_update_tables_link_status( + TABLE *table, + char *name, + uint name_length, + int link_idx, + long link_status +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_update_tables_link_status"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + spider_store_tables_link_idx(table, link_idx); + if ((error_num = spider_check_sys_table(table, table_key))) + { + if ( + (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + ) + DBUG_RETURN(0); + else { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } else { + store_record(table, record[1]); + table->use_all_columns(); + spider_store_tables_link_status(table, link_status); + if ( + (error_num = table->file->ha_update_row( + table->record[1], table->record[0])) && + error_num != HA_ERR_RECORD_IS_THE_SAME + ) { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_delete_xa( + TABLE *table, + XID *xid +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_delete_xa"); + table->use_all_columns(); + spider_store_xa_pk(table, xid); + + if ((error_num = spider_check_sys_table(table, table_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR, + MYF(0)); + DBUG_RETURN(ER_SPIDER_XA_NOT_EXISTS_NUM); + } else { + if ((error_num = table->file->ha_delete_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_delete_xa_member( + TABLE *table, + XID *xid +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_delete_xa_member"); + table->use_all_columns(); + spider_store_xa_pk(table, xid); + + if ((error_num = spider_get_sys_table_by_idx(table, table_key, 0, + SPIDER_SYS_XA_PK_COL_CNT))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); + } else { + do { + if ((error_num = table->file->ha_delete_row(table->record[0]))) + { + spider_sys_index_end(table); + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + error_num = spider_sys_index_next_same(table, table_key); + } while (error_num == 0); + } + if ((error_num = spider_sys_index_end(table))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + + DBUG_RETURN(0); +} + +int spider_delete_tables( + TABLE *table, + const char *name, + int *old_link_count +) { + int error_num, roop_count = 0; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_delete_tables"); + table->use_all_columns(); + spider_store_tables_name(table, name, strlen(name)); + + while (TRUE) + { + spider_store_tables_link_idx(table, roop_count); + if ((error_num = spider_check_sys_table(table, table_key))) + break; + else { + if ((error_num = table->file->ha_delete_row(table->record[0]))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + roop_count++; + } + + *old_link_count = roop_count; + DBUG_RETURN(0); +} + +int spider_get_sys_xid( + TABLE *table, + XID *xid, + MEM_ROOT *mem_root +) { + char *ptr; + DBUG_ENTER("spider_get_sys_xid"); + ptr = get_field(mem_root, table->field[0]); + if (ptr) + { + xid->formatID = atoi(ptr); + } else + xid->formatID = 0; + ptr = get_field(mem_root, table->field[1]); + if (ptr) + { + xid->gtrid_length = atoi(ptr); + } else + xid->gtrid_length = 0; + ptr = get_field(mem_root, table->field[2]); + if (ptr) + { + xid->bqual_length = atoi(ptr); + } else + xid->bqual_length = 0; + ptr = get_field(mem_root, table->field[3]); + if (ptr) + { + strmov(xid->data, ptr); + } + DBUG_RETURN(0); +} + +int spider_get_sys_server_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +) { + char *ptr; + DBUG_ENTER("spider_get_sys_server_info"); + if ((ptr = get_field(mem_root, table->field[4]))) + { + share->tgt_wrappers_lengths[link_idx] = strlen(ptr); + share->tgt_wrappers[link_idx] = spider_create_string(ptr, + share->tgt_wrappers_lengths[link_idx]); + } else { + share->tgt_wrappers_lengths[link_idx] = 0; + share->tgt_wrappers[link_idx] = NULL; + } + if ((ptr = get_field(mem_root, table->field[5]))) + { + share->tgt_hosts_lengths[link_idx] = strlen(ptr); + share->tgt_hosts[link_idx] = spider_create_string(ptr, + share->tgt_hosts_lengths[link_idx]); + } else { + share->tgt_hosts_lengths[link_idx] = 0; + share->tgt_hosts[link_idx] = NULL; + } + if ((ptr = get_field(mem_root, table->field[6]))) + { + share->tgt_ports[link_idx] = atol(ptr); + } else + share->tgt_ports[link_idx] = MYSQL_PORT; + if ((ptr = get_field(mem_root, table->field[7]))) + { + share->tgt_sockets_lengths[link_idx] = strlen(ptr); + share->tgt_sockets[link_idx] = spider_create_string(ptr, + share->tgt_sockets_lengths[link_idx]); + } else { + share->tgt_sockets_lengths[link_idx] = 0; + share->tgt_sockets[link_idx] = NULL; + } + if ((ptr = get_field(mem_root, table->field[8]))) + { + share->tgt_usernames_lengths[link_idx] = strlen(ptr); + share->tgt_usernames[link_idx] = + spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]); + } else { + share->tgt_usernames_lengths[link_idx] = 0; + share->tgt_usernames[link_idx] = NULL; + } + if ((ptr = get_field(mem_root, table->field[9]))) + { + share->tgt_passwords_lengths[link_idx] = strlen(ptr); + share->tgt_passwords[link_idx] = + spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]); + } else { + share->tgt_passwords_lengths[link_idx] = 0; + share->tgt_passwords[link_idx] = NULL; + } + if ( + !table->field[10]->is_null() && + (ptr = get_field(mem_root, table->field[10])) + ) { + share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_cas[link_idx] = + spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]); + } else { + share->tgt_ssl_cas_lengths[link_idx] = 0; + share->tgt_ssl_cas[link_idx] = NULL; + } + if ( + !table->field[11]->is_null() && + (ptr = get_field(mem_root, table->field[11])) + ) { + share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_capaths[link_idx] = + spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]); + } else { + share->tgt_ssl_capaths_lengths[link_idx] = 0; + share->tgt_ssl_capaths[link_idx] = NULL; + } + if ( + !table->field[12]->is_null() && + (ptr = get_field(mem_root, table->field[12])) + ) { + share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_certs[link_idx] = + spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]); + } else { + share->tgt_ssl_certs_lengths[link_idx] = 0; + share->tgt_ssl_certs[link_idx] = NULL; + } + if ( + !table->field[13]->is_null() && + (ptr = get_field(mem_root, table->field[13])) + ) { + share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_ciphers[link_idx] = + spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]); + } else { + share->tgt_ssl_ciphers_lengths[link_idx] = 0; + share->tgt_ssl_ciphers[link_idx] = NULL; + } + if ( + !table->field[14]->is_null() && + (ptr = get_field(mem_root, table->field[14])) + ) { + share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_keys[link_idx] = + spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]); + } else { + share->tgt_ssl_keys_lengths[link_idx] = 0; + share->tgt_ssl_keys[link_idx] = NULL; + } + if ( + !table->field[15]->is_null() && + (ptr = get_field(mem_root, table->field[15])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = 0; + if ( + !table->field[16]->is_null() && + (ptr = get_field(mem_root, table->field[16])) + ) { + share->tgt_default_files_lengths[link_idx] = strlen(ptr); + share->tgt_default_files[link_idx] = + spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]); + } else { + share->tgt_default_files_lengths[link_idx] = 0; + share->tgt_default_files[link_idx] = NULL; + } + if ( + !table->field[17]->is_null() && + (ptr = get_field(mem_root, table->field[17])) + ) { + share->tgt_default_groups_lengths[link_idx] = strlen(ptr); + share->tgt_default_groups[link_idx] = + spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]); + } else { + share->tgt_default_groups_lengths[link_idx] = 0; + share->tgt_default_groups[link_idx] = NULL; + } + DBUG_RETURN(0); +} + +int spider_check_sys_xa_status( + TABLE *table, + const char *status1, + const char *status2, + const char *status3, + const int check_error_num, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num; + DBUG_ENTER("spider_check_sys_xa_status"); + ptr = get_field(mem_root, table->field[4]); + if (ptr) + { + if ( + strcmp(ptr, status1) && + (status2 == NULL || strcmp(ptr, status2)) && + (status3 == NULL || strcmp(ptr, status3)) + ) + error_num = check_error_num; + else + error_num = 0; + } else + error_num = check_error_num; + DBUG_RETURN(error_num); +} + +int spider_get_sys_tables( + TABLE *table, + char **db_name, + char **table_name, + MEM_ROOT *mem_root +) { + char *ptr; + DBUG_ENTER("spider_get_sys_tables"); + if ((ptr = get_field(mem_root, table->field[0]))) + { + *db_name = spider_create_string(ptr, strlen(ptr)); + } else { + *db_name = NULL; + } + if ((ptr = get_field(mem_root, table->field[1]))) + { + *table_name = spider_create_string(ptr, strlen(ptr)); + } else { + *table_name = NULL; + } + DBUG_RETURN(0); +} + +int spider_get_sys_tables_connect_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_tables_connect_info"); + if ((ptr = get_field(mem_root, table->field[3]))) + { + share->priority = my_strtoll10(ptr, (char**) NULL, &error_num); + } else + share->priority = 1000000; + if ( + !table->field[4]->is_null() && + (ptr = get_field(mem_root, table->field[4])) + ) { + share->server_names_lengths[link_idx] = strlen(ptr); + share->server_names[link_idx] = + spider_create_string(ptr, share->server_names_lengths[link_idx]); + } else { + share->server_names_lengths[link_idx] = 0; + share->server_names[link_idx] = NULL; + } + if ( + !table->field[5]->is_null() && + (ptr = get_field(mem_root, table->field[5])) + ) { + share->tgt_wrappers_lengths[link_idx] = strlen(ptr); + share->tgt_wrappers[link_idx] = + spider_create_string(ptr, share->tgt_wrappers_lengths[link_idx]); + } else { + share->tgt_wrappers_lengths[link_idx] = 0; + share->tgt_wrappers[link_idx] = NULL; + } + if ( + !table->field[6]->is_null() && + (ptr = get_field(mem_root, table->field[6])) + ) { + share->tgt_hosts_lengths[link_idx] = strlen(ptr); + share->tgt_hosts[link_idx] = + spider_create_string(ptr, share->tgt_hosts_lengths[link_idx]); + } else { + share->tgt_hosts_lengths[link_idx] = 0; + share->tgt_hosts[link_idx] = NULL; + } + if ( + !table->field[7]->is_null() && + (ptr = get_field(mem_root, table->field[7])) + ) { + share->tgt_ports[link_idx] = atol(ptr); + } else { + share->tgt_ports[link_idx] = -1; + } + if ( + !table->field[8]->is_null() && + (ptr = get_field(mem_root, table->field[8])) + ) { + share->tgt_sockets_lengths[link_idx] = strlen(ptr); + share->tgt_sockets[link_idx] = + spider_create_string(ptr, share->tgt_sockets_lengths[link_idx]); + } else { + share->tgt_sockets_lengths[link_idx] = 0; + share->tgt_sockets[link_idx] = NULL; + } + if ( + !table->field[9]->is_null() && + (ptr = get_field(mem_root, table->field[9])) + ) { + share->tgt_usernames_lengths[link_idx] = strlen(ptr); + share->tgt_usernames[link_idx] = + spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]); + } else { + share->tgt_usernames_lengths[link_idx] = 0; + share->tgt_usernames[link_idx] = NULL; + } + if ( + !table->field[10]->is_null() && + (ptr = get_field(mem_root, table->field[10])) + ) { + share->tgt_passwords_lengths[link_idx] = strlen(ptr); + share->tgt_passwords[link_idx] = + spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]); + } else { + share->tgt_passwords_lengths[link_idx] = 0; + share->tgt_passwords[link_idx] = NULL; + } + if ( + !table->field[11]->is_null() && + (ptr = get_field(mem_root, table->field[11])) + ) { + share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_cas[link_idx] = + spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]); + } else { + share->tgt_ssl_cas_lengths[link_idx] = 0; + share->tgt_ssl_cas[link_idx] = NULL; + } + if ( + !table->field[12]->is_null() && + (ptr = get_field(mem_root, table->field[12])) + ) { + share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_capaths[link_idx] = + spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]); + } else { + share->tgt_ssl_capaths_lengths[link_idx] = 0; + share->tgt_ssl_capaths[link_idx] = NULL; + } + if ( + !table->field[13]->is_null() && + (ptr = get_field(mem_root, table->field[13])) + ) { + share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_certs[link_idx] = + spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]); + } else { + share->tgt_ssl_certs_lengths[link_idx] = 0; + share->tgt_ssl_certs[link_idx] = NULL; + } + if ( + !table->field[14]->is_null() && + (ptr = get_field(mem_root, table->field[14])) + ) { + share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_ciphers[link_idx] = + spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]); + } else { + share->tgt_ssl_ciphers_lengths[link_idx] = 0; + share->tgt_ssl_ciphers[link_idx] = NULL; + } + if ( + !table->field[15]->is_null() && + (ptr = get_field(mem_root, table->field[15])) + ) { + share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_keys[link_idx] = + spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]); + } else { + share->tgt_ssl_keys_lengths[link_idx] = 0; + share->tgt_ssl_keys[link_idx] = NULL; + } + if ( + !table->field[16]->is_null() && + (ptr = get_field(mem_root, table->field[16])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = -1; + if ( + !table->field[17]->is_null() && + (ptr = get_field(mem_root, table->field[17])) + ) { + share->tgt_default_files_lengths[link_idx] = strlen(ptr); + share->tgt_default_files[link_idx] = + spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]); + } else { + share->tgt_default_files_lengths[link_idx] = 0; + share->tgt_default_files[link_idx] = NULL; + } + if ( + !table->field[18]->is_null() && + (ptr = get_field(mem_root, table->field[18])) + ) { + share->tgt_default_groups_lengths[link_idx] = strlen(ptr); + share->tgt_default_groups[link_idx] = + spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]); + } else { + share->tgt_default_groups_lengths[link_idx] = 0; + share->tgt_default_groups[link_idx] = NULL; + } + if ( + !table->field[19]->is_null() && + (ptr = get_field(mem_root, table->field[19])) + ) { + share->tgt_dbs_lengths[link_idx] = strlen(ptr); + share->tgt_dbs[link_idx] = + spider_create_string(ptr, share->tgt_dbs_lengths[link_idx]); + } else { + share->tgt_dbs_lengths[link_idx] = 0; + share->tgt_dbs[link_idx] = NULL; + } + if ( + !table->field[20]->is_null() && + (ptr = get_field(mem_root, table->field[20])) + ) { + share->tgt_table_names_lengths[link_idx] = strlen(ptr); + share->tgt_table_names[link_idx] = + spider_create_string(ptr, share->tgt_table_names_lengths[link_idx]); + } else { + share->tgt_table_names_lengths[link_idx] = 0; + share->tgt_table_names[link_idx] = NULL; + } + DBUG_RETURN(error_num); +} + +int spider_get_sys_tables_link_status( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_tables_link_status"); + if ((ptr = get_field(mem_root, table->field[21]))) + { + share->link_statuses[link_idx] = + (long) my_strtoll10(ptr, (char**) NULL, &error_num); + } else + share->link_statuses[link_idx] = 1; + DBUG_PRINT("info",("spider link_statuses[%d]=%ld", + link_idx, share->link_statuses[link_idx])); + DBUG_RETURN(error_num); +} + +int spider_get_sys_tables_link_idx( + TABLE *table, + int *link_idx, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_tables_link_status"); + if ((ptr = get_field(mem_root, table->field[2]))) + *link_idx = (int) my_strtoll10(ptr, (char**) NULL, &error_num); + else + *link_idx = 1; + DBUG_PRINT("info",("spider link_idx=%d", *link_idx)); + DBUG_RETURN(error_num); +} + +int spider_sys_update_tables_link_status( + THD *thd, + char *name, + uint name_length, + int link_idx, + long link_status, + bool need_lock +) { + int error_num; + TABLE *table_tables = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + DBUG_ENTER("spider_sys_update_tables_link_status"); + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock, + &error_num)) + ) { + my_error(error_num, MYF(0)); + goto error; + } + if ((error_num = spider_update_tables_link_status(table_tables, + name, name_length, link_idx, link_status))) + goto error; + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_log_tables_link_failed( + THD *thd, + char *name, + uint name_length, + int link_idx, + bool need_lock +) { + int error_num; + TABLE *table_tables = NULL; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + DBUG_ENTER("spider_sys_log_tables_link_failed"); + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR, + SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN, TRUE, &open_tables_backup, + need_lock, &error_num)) + ) { + my_error(error_num, MYF(0)); + goto error; + } + empty_record(table_tables); + if ((error_num = spider_log_tables_link_failed(table_tables, + name, name_length, link_idx))) + goto error; + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + table_tables = NULL; + DBUG_RETURN(0); + +error: + if (table_tables) + spider_close_sys_table(thd, table_tables, + &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_get_sys_link_mon_key( + TABLE *table, + SPIDER_MON_KEY *mon_key, + MEM_ROOT *mem_root, + int *same +) { + char *db_name, *table_name, *link_id; + uint db_name_length, table_name_length, link_id_length; + DBUG_ENTER("spider_get_sys_link_mon_key"); + if ( + table->field[0]->is_null() || + table->field[1]->is_null() || + table->field[2]->is_null() + ) { + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_LINK_MON_TABLE_NAME_STR); + DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); + } + + if ( + !(db_name = get_field(mem_root, table->field[0])) || + !(table_name = get_field(mem_root, table->field[1])) || + !(link_id = get_field(mem_root, table->field[2])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + db_name_length = strlen(db_name); + table_name_length = strlen(table_name); + link_id_length = strlen(link_id); + + if ( + db_name_length > SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE || + table_name_length > SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE || + link_id_length > SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + ) { + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_LINK_MON_TABLE_NAME_STR); + DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); + } + + if ( + db_name_length == mon_key->db_name_length && + table_name_length == mon_key->table_name_length && + link_id_length == mon_key->link_id_length && + !memcmp(db_name, mon_key->db_name, db_name_length) && + !memcmp(table_name, mon_key->table_name, table_name_length) && + !memcmp(link_id, mon_key->link_id, link_id_length) + ) { + /* same key */ + *same = 1; + DBUG_RETURN(0); + } + + *same = 0; + mon_key->db_name_length = db_name_length; + memcpy(mon_key->db_name, db_name, db_name_length + 1); + mon_key->table_name_length = table_name_length; + memcpy(mon_key->table_name, table_name, table_name_length + 1); + mon_key->link_id_length = link_id_length; + memcpy(mon_key->link_id, link_id, link_id_length + 1); + DBUG_RETURN(0); +} + +int spider_get_sys_link_mon_server_id( + TABLE *table, + uint32 *server_id, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_link_mon_server_id"); + if ((ptr = get_field(mem_root, table->field[3]))) + *server_id = (uint32) my_strtoll10(ptr, (char**) NULL, &error_num); + else + *server_id = ~(uint32) 0; + DBUG_RETURN(error_num); +} + +int spider_get_sys_link_mon_connect_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_link_mon_connect_info"); + if ( + !table->field[4]->is_null() && + (ptr = get_field(mem_root, table->field[4])) + ) { + share->server_names_lengths[link_idx] = strlen(ptr); + share->server_names[link_idx] = + spider_create_string(ptr, share->server_names_lengths[link_idx]); + } else { + share->server_names_lengths[link_idx] = 0; + share->server_names[link_idx] = NULL; + } + if ( + !table->field[5]->is_null() && + (ptr = get_field(mem_root, table->field[5])) + ) { + share->tgt_wrappers_lengths[link_idx] = strlen(ptr); + share->tgt_wrappers[link_idx] = + spider_create_string(ptr, share->tgt_wrappers_lengths[link_idx]); + } else { + share->tgt_wrappers_lengths[link_idx] = 0; + share->tgt_wrappers[link_idx] = NULL; + } + if ( + !table->field[6]->is_null() && + (ptr = get_field(mem_root, table->field[6])) + ) { + share->tgt_hosts_lengths[link_idx] = strlen(ptr); + share->tgt_hosts[link_idx] = + spider_create_string(ptr, share->tgt_hosts_lengths[link_idx]); + } else { + share->tgt_hosts_lengths[link_idx] = 0; + share->tgt_hosts[link_idx] = NULL; + } + if ( + !table->field[7]->is_null() && + (ptr = get_field(mem_root, table->field[7])) + ) { + share->tgt_ports[link_idx] = atol(ptr); + } else { + share->tgt_ports[link_idx] = -1; + } + if ( + !table->field[8]->is_null() && + (ptr = get_field(mem_root, table->field[8])) + ) { + share->tgt_sockets_lengths[link_idx] = strlen(ptr); + share->tgt_sockets[link_idx] = + spider_create_string(ptr, share->tgt_sockets_lengths[link_idx]); + } else { + share->tgt_sockets_lengths[link_idx] = 0; + share->tgt_sockets[link_idx] = NULL; + } + if ( + !table->field[9]->is_null() && + (ptr = get_field(mem_root, table->field[9])) + ) { + share->tgt_usernames_lengths[link_idx] = strlen(ptr); + share->tgt_usernames[link_idx] = + spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]); + } else { + share->tgt_usernames_lengths[link_idx] = 0; + share->tgt_usernames[link_idx] = NULL; + } + if ( + !table->field[10]->is_null() && + (ptr = get_field(mem_root, table->field[10])) + ) { + share->tgt_passwords_lengths[link_idx] = strlen(ptr); + share->tgt_passwords[link_idx] = + spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]); + } else { + share->tgt_passwords_lengths[link_idx] = 0; + share->tgt_passwords[link_idx] = NULL; + } + if ( + !table->field[11]->is_null() && + (ptr = get_field(mem_root, table->field[11])) + ) { + share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_cas[link_idx] = + spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]); + } else { + share->tgt_ssl_cas_lengths[link_idx] = 0; + share->tgt_ssl_cas[link_idx] = NULL; + } + if ( + !table->field[12]->is_null() && + (ptr = get_field(mem_root, table->field[12])) + ) { + share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_capaths[link_idx] = + spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]); + } else { + share->tgt_ssl_capaths_lengths[link_idx] = 0; + share->tgt_ssl_capaths[link_idx] = NULL; + } + if ( + !table->field[13]->is_null() && + (ptr = get_field(mem_root, table->field[13])) + ) { + share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_certs[link_idx] = + spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]); + } else { + share->tgt_ssl_certs_lengths[link_idx] = 0; + share->tgt_ssl_certs[link_idx] = NULL; + } + if ( + !table->field[14]->is_null() && + (ptr = get_field(mem_root, table->field[14])) + ) { + share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_ciphers[link_idx] = + spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]); + } else { + share->tgt_ssl_ciphers_lengths[link_idx] = 0; + share->tgt_ssl_ciphers[link_idx] = NULL; + } + if ( + !table->field[15]->is_null() && + (ptr = get_field(mem_root, table->field[15])) + ) { + share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr); + share->tgt_ssl_keys[link_idx] = + spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]); + } else { + share->tgt_ssl_keys_lengths[link_idx] = 0; + share->tgt_ssl_keys[link_idx] = NULL; + } + if ( + !table->field[16]->is_null() && + (ptr = get_field(mem_root, table->field[16])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = -1; + if ( + !table->field[17]->is_null() && + (ptr = get_field(mem_root, table->field[17])) + ) { + share->tgt_default_files_lengths[link_idx] = strlen(ptr); + share->tgt_default_files[link_idx] = + spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]); + } else { + share->tgt_default_files_lengths[link_idx] = 0; + share->tgt_default_files[link_idx] = NULL; + } + if ( + !table->field[18]->is_null() && + (ptr = get_field(mem_root, table->field[18])) + ) { + share->tgt_default_groups_lengths[link_idx] = strlen(ptr); + share->tgt_default_groups[link_idx] = + spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]); + } else { + share->tgt_default_groups_lengths[link_idx] = 0; + share->tgt_default_groups[link_idx] = NULL; + } + DBUG_RETURN(error_num); +} + +int spider_get_link_statuses( + TABLE *table, + SPIDER_SHARE *share, + MEM_ROOT *mem_root +) { + int error_num, roop_count; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_get_link_statuses"); + table->use_all_columns(); + spider_store_tables_name(table, share->table_name, + share->table_name_length); + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + spider_store_tables_link_idx(table, roop_count); + if ((error_num = spider_check_sys_table(table, table_key))) + { + if ( + (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + ) { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } else if ((error_num = + spider_get_sys_tables_link_status(table, share, roop_count, mem_root))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_sys_replace( + TABLE *table, + bool *modified_non_trans_table +) { + int error_num, key_num; + bool last_uniq_key; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_sys_replace"); + + while ((error_num = table->file->ha_write_row(table->record[0]))) + { + if ( + table->file->is_fatal_error(error_num, HA_CHECK_DUP) || + (key_num = table->file->get_dup_key(error_num)) < 0 + ) + goto error; + + if (table->file->ha_table_flags() & HA_DUPLICATE_POS) + { +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + error_num = table->file->ha_rnd_pos(table->record[1], + table->file->dup_ref); +#else + error_num = table->file->rnd_pos(table->record[1], table->file->dup_ref); +#endif + if (error_num) + { + if (error_num == HA_ERR_RECORD_DELETED) + error_num = HA_ERR_KEY_NOT_FOUND; + goto error; + } + } else { + if ((error_num = table->file->extra(HA_EXTRA_FLUSH_CACHE))) + goto error; + + key_copy((uchar*)table_key, table->record[0], + table->key_info + key_num, 0); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200 + error_num = table->file->ha_index_read_idx_map(table->record[1], key_num, + (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); +#else + error_num = table->file->index_read_idx_map(table->record[1], key_num, + (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT); +#endif + if (error_num) + { + if (error_num == HA_ERR_RECORD_DELETED) + error_num = HA_ERR_KEY_NOT_FOUND; + goto error; + } + } + + last_uniq_key = TRUE; + while (++key_num < (int) table->s->keys) + if (table->key_info[key_num].flags & HA_NOSAME) + last_uniq_key = FALSE; + + if ( + last_uniq_key && + !table->file->referenced_by_foreign_key() + ) { + error_num = table->file->ha_update_row(table->record[1], + table->record[0]); + if (error_num && error_num != HA_ERR_RECORD_IS_THE_SAME) + goto error; + DBUG_RETURN(0); + } else { + if ((error_num = table->file->ha_delete_row(table->record[1]))) + goto error; + *modified_non_trans_table = TRUE; + } + } + + DBUG_RETURN(0); + +error: + DBUG_RETURN(error_num); +} + +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name, + CHARSET_INFO *cs +) { + Field_blob *field; + Item_field *i_field; + List i_list; + TABLE *tmp_table; + DBUG_ENTER("spider_mk_sys_tmp_table"); + + if (!(field = new Field_blob( + 4294967295U, FALSE, field_name, cs, TRUE))) + goto error_alloc_field; + field->init(table); + + if (!(i_field = new Item_field((Field *) field))) + goto error_alloc_item_field; + + if (i_list.push_back(i_field)) + goto error_push_item; + + if (!(tmp_table = create_tmp_table(thd, tmp_tbl_prm, + i_list, (ORDER*) NULL, FALSE, FALSE, TMP_TABLE_FORCE_MYISAM, + HA_POS_ERROR, (char *) ""))) + goto error_create_tmp_table; + DBUG_RETURN(tmp_table); + +error_create_tmp_table: +error_push_item: + delete i_field; +error_alloc_item_field: + delete field; +error_alloc_field: + DBUG_RETURN(NULL); +} + +void spider_rm_sys_tmp_table( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +) { + DBUG_ENTER("spider_rm_sys_tmp_table"); + free_tmp_table(thd, tmp_table); + tmp_tbl_prm->cleanup(); + tmp_tbl_prm->field_count = 1; + DBUG_VOID_RETURN; +} + +TABLE *spider_mk_sys_tmp_table_for_result( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name1, + const char *field_name2, + const char *field_name3, + CHARSET_INFO *cs +) { + Field_blob *field1, *field2, *field3; + Item_field *i_field1, *i_field2, *i_field3; + List i_list; + TABLE *tmp_table; + DBUG_ENTER("spider_mk_sys_tmp_table_for_result"); + + if (!(field1 = new Field_blob( + 4294967295U, FALSE, field_name1, cs, TRUE))) + goto error_alloc_field1; + field1->init(table); + + if (!(i_field1 = new Item_field((Field *) field1))) + goto error_alloc_item_field1; + + if (i_list.push_back(i_field1)) + goto error_push_item1; + + if (!(field2 = new Field_blob( + 4294967295U, FALSE, field_name2, cs, TRUE))) + goto error_alloc_field2; + field2->init(table); + + if (!(i_field2 = new Item_field((Field *) field2))) + goto error_alloc_item_field2; + + if (i_list.push_back(i_field2)) + goto error_push_item2; + + if (!(field3 = new Field_blob( + 4294967295U, FALSE, field_name3, cs, TRUE))) + goto error_alloc_field3; + field3->init(table); + + if (!(i_field3 = new Item_field((Field *) field3))) + goto error_alloc_item_field3; + + if (i_list.push_back(i_field3)) + goto error_push_item3; + + if (!(tmp_table = create_tmp_table(thd, tmp_tbl_prm, + i_list, (ORDER*) NULL, FALSE, FALSE, TMP_TABLE_FORCE_MYISAM, + HA_POS_ERROR, (char *) ""))) + goto error_create_tmp_table; + DBUG_RETURN(tmp_table); + +error_create_tmp_table: +error_push_item3: + delete i_field3; +error_alloc_item_field3: + delete field3; +error_alloc_field3: +error_push_item2: + delete i_field2; +error_alloc_item_field2: + delete field2; +error_alloc_field2: +error_push_item1: + delete i_field1; +error_alloc_item_field1: + delete field1; +error_alloc_field1: + DBUG_RETURN(NULL); +} + +void spider_rm_sys_tmp_table_for_result( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +) { + DBUG_ENTER("spider_rm_sys_tmp_table_for_result"); + free_tmp_table(thd, tmp_table); + tmp_tbl_prm->cleanup(); + tmp_tbl_prm->field_count = 3; + DBUG_VOID_RETURN; +} diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h new file mode 100644 index 00000000000..5b83738bd59 --- /dev/null +++ b/storage/spider/spd_sys_table.h @@ -0,0 +1,427 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define SPIDER_SYS_XA_TABLE_NAME_STR "spider_xa" +#define SPIDER_SYS_XA_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_TABLE_NAME_STR) - 1) +#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR "spider_xa_member" +#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR) - 1) +#define SPIDER_SYS_TABLES_TABLE_NAME_STR "spider_tables" +#define SPIDER_SYS_TABLES_TABLE_NAME_LEN (sizeof(SPIDER_SYS_TABLES_TABLE_NAME_STR) - 1) +#define SPIDER_SYS_LINK_MON_TABLE_NAME_STR "spider_link_mon_servers" +#define SPIDER_SYS_LINK_MON_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_MON_TABLE_NAME_STR) - 1) +#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR "spider_link_failed_log" +#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR) - 1) + +#define SPIDER_SYS_XA_PREPARED_STR "PREPARED" +#define SPIDER_SYS_XA_NOT_YET_STR "NOT YET" +#define SPIDER_SYS_XA_COMMIT_STR "COMMIT" +#define SPIDER_SYS_XA_ROLLBACK_STR "ROLLBACK" + +#define SPIDER_SYS_XA_COL_CNT 5 +#define SPIDER_SYS_XA_PK_COL_CNT 3 +#define SPIDER_SYS_XA_IDX1_COL_CNT 1 +#define SPIDER_SYS_XA_MEMBER_COL_CNT 18 +#define SPIDER_SYS_XA_MEMBER_PK_COL_CNT 6 +#define SPIDER_SYS_TABLES_COL_CNT 22 +#define SPIDER_SYS_TABLES_PK_COL_CNT 2 +#define SPIDER_SYS_TABLES_IDX1_COL_CNT 1 +#define SPIDER_SYS_LINK_MON_TABLE_COL_CNT 19 + +#define SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE 64 +#define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64 +#define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 10 + +class SPIDER_MON_KEY: public SPIDER_SORT +{ +public: + char db_name[SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE + 1]; + char table_name[SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1]; + char link_id[SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1]; + uint db_name_length; + uint table_name_length; + uint link_id_length; +}; + +#if MYSQL_VERSION_ID < 50500 +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + Open_tables_state *open_tables_backup, + bool need_lock, + int *error_num +); + +void spider_close_sys_table( + THD *thd, + TABLE *table, + Open_tables_state *open_tables_backup, + bool need_lock +); +#else +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + Open_tables_backup *open_tables_backup, + bool need_lock, + int *error_num +); + +void spider_close_sys_table( + THD *thd, + TABLE *table, + Open_tables_backup *open_tables_backup, + bool need_lock +); + +bool spider_sys_open_tables( + THD *thd, + TABLE_LIST **tables, + Open_tables_backup *open_tables_backup +); + +TABLE *spider_sys_open_table( + THD *thd, + TABLE_LIST *tables, + Open_tables_backup *open_tables_backup +); + +void spider_sys_close_table( + THD *thd, + Open_tables_backup *open_tables_backup +); +#endif + +int spider_sys_index_init( + TABLE *table, + uint idx, + bool sorted +); + +int spider_sys_index_end( + TABLE *table +); + +int spider_sys_rnd_init( + TABLE *table, + bool scan +); + +int spider_sys_rnd_end( + TABLE *table +); + +int spider_check_sys_table( + TABLE *table, + char *table_key +); + +int spider_check_sys_table_with_find_flag( + TABLE *table, + char *table_key, + enum ha_rkey_function find_flag +); + +int spider_get_sys_table_by_idx( + TABLE *table, + char *table_key, + const int idx, + const int col_count +); + +int spider_sys_index_next_same( + TABLE *table, + char *table_key +); + +int spider_sys_index_first( + TABLE *table, + const int idx +); + +int spider_sys_index_next( + TABLE *table +); + +void spider_store_xa_pk( + TABLE *table, + XID *xid +); + +void spider_store_xa_bqual_length( + TABLE *table, + XID *xid +); + +void spider_store_xa_status( + TABLE *table, + const char *status +); + +void spider_store_xa_member_pk( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +); + +void spider_store_xa_member_info( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +); + +void spider_store_tables_name( + TABLE *table, + const char *name, + const uint name_length +); + +void spider_store_db_and_table_name( + TABLE *table, + const char *db_name, + const uint db_name_length, + const char *table_name, + const uint table_name_length +); + +void spider_store_tables_link_idx( + TABLE *table, + int link_idx +); + +void spider_store_tables_link_idx_str( + TABLE *table, + const char *link_idx, + const uint link_idx_length +); + +void spider_store_tables_priority( + TABLE *table, + longlong priority +); + +void spider_store_tables_connect_info( + TABLE *table, + SPIDER_ALTER_TABLE *alter_table, + int link_idx +); + +void spider_store_tables_link_status( + TABLE *table, + long link_status +); + +void spider_store_link_chk_server_id( + TABLE *table, + uint32 server_id +); + +int spider_insert_xa( + TABLE *table, + XID *xid, + const char *status +); + +int spider_insert_xa_member( + TABLE *table, + XID *xid, + SPIDER_CONN *conn +); + +int spider_insert_tables( + TABLE *table, + SPIDER_SHARE *share +); + +int spider_log_tables_link_failed( + TABLE *table, + char *name, + uint name_length, + int link_idx +); + +int spider_update_xa( + TABLE *table, + XID *xid, + const char *status +); + +int spider_update_tables_name( + TABLE *table, + const char *from, + const char *to, + int *old_link_count +); + +int spider_update_tables_priority( + TABLE *table, + SPIDER_ALTER_TABLE *alter_table, + const char *name, + int *old_link_count +); + +int spider_update_tables_link_status( + TABLE *table, + char *name, + uint name_length, + int link_idx, + long link_status +); + +int spider_delete_xa( + TABLE *table, + XID *xid +); + +int spider_delete_xa_member( + TABLE *table, + XID *xid +); + +int spider_delete_tables( + TABLE *table, + const char *name, + int *old_link_count +); + +int spider_get_sys_xid( + TABLE *table, + XID *xid, + MEM_ROOT *mem_root +); + +int spider_get_sys_server_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +); + +int spider_check_sys_xa_status( + TABLE *table, + const char *status1, + const char *status2, + const char *status3, + const int check_error_num, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables( + TABLE *table, + char **db_name, + char **table_name, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables_connect_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables_link_status( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables_link_idx( + TABLE *table, + int *link_idx, + MEM_ROOT *mem_root +); + +int spider_sys_update_tables_link_status( + THD *thd, + char *name, + uint name_length, + int link_idx, + long link_status, + bool need_lock +); + +int spider_sys_log_tables_link_failed( + THD *thd, + char *name, + uint name_length, + int link_idx, + bool need_lock +); + +int spider_get_sys_link_mon_key( + TABLE *table, + SPIDER_MON_KEY *mon_key, + MEM_ROOT *mem_root, + int *same +); + +int spider_get_sys_link_mon_server_id( + TABLE *table, + uint32 *server_id, + MEM_ROOT *mem_root +); + +int spider_get_sys_link_mon_connect_info( + TABLE *table, + SPIDER_SHARE *share, + int link_idx, + MEM_ROOT *mem_root +); + +int spider_get_link_statuses( + TABLE *table, + SPIDER_SHARE *share, + MEM_ROOT *mem_root +); + +int spider_sys_replace( + TABLE *table, + bool *modified_non_trans_table +); + +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name, + CHARSET_INFO *cs +); + +void spider_rm_sys_tmp_table( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +); + +TABLE *spider_mk_sys_tmp_table_for_result( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name1, + const char *field_name2, + const char *field_name3, + CHARSET_INFO *cs +); + +void spider_rm_sys_tmp_table_for_result( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc new file mode 100644 index 00000000000..40704f74437 --- /dev/null +++ b/storage/spider/spd_table.cc @@ -0,0 +1,7837 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_servers.h" +#endif +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_sys_table.h" +#include "ha_spider.h" +#include "spd_trx.h" +#include "spd_db_conn.h" +#include "spd_table.h" +#include "spd_conn.h" +#include "spd_ping_table.h" +#include "spd_malloc.h" + +ulong *spd_db_att_thread_id; +pthread_mutex_t *spd_db_att_LOCK_xid_cache; +HASH *spd_db_att_xid_cache; +struct charset_info_st *spd_charset_utf8_bin; +const char **spd_defaults_extra_file; +const char **spd_defaults_file; + +handlerton *spider_hton_ptr; +SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern SPIDER_DBTON spider_dbton_mysql; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +extern SPIDER_DBTON spider_dbton_handlersocket; +#endif +#ifdef HAVE_ORACLE_OCI +extern SPIDER_DBTON spider_dbton_oracle; +#endif + +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key spd_key_mutex_tbl; +PSI_mutex_key spd_key_mutex_init_error_tbl; +#ifdef WITH_PARTITION_STORAGE_ENGINE +PSI_mutex_key spd_key_mutex_pt_share; +#endif +PSI_mutex_key spd_key_mutex_conn; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +PSI_mutex_key spd_key_mutex_hs_r_conn; +PSI_mutex_key spd_key_mutex_hs_w_conn; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH +PSI_mutex_key spd_key_mutex_global_trx; +#endif +PSI_mutex_key spd_key_mutex_open_conn; +PSI_mutex_key spd_key_mutex_allocated_thds; +PSI_mutex_key spd_key_mutex_mon_table_cache; +PSI_mutex_key spd_key_mutex_udf_table_mon; +PSI_mutex_key spd_key_mutex_mta_conn; +#ifndef WITHOUT_SPIDER_BG_SEARCH +PSI_mutex_key spd_key_mutex_bg_conn_chain; +PSI_mutex_key spd_key_mutex_bg_conn_sync; +PSI_mutex_key spd_key_mutex_bg_conn; +PSI_mutex_key spd_key_mutex_bg_job_stack; +PSI_mutex_key spd_key_mutex_bg_mon; +PSI_mutex_key spd_key_mutex_bg_direct_sql; +#endif +PSI_mutex_key spd_key_mutex_mon_list_caller; +PSI_mutex_key spd_key_mutex_mon_list_receptor; +PSI_mutex_key spd_key_mutex_mon_list_monitor; +PSI_mutex_key spd_key_mutex_mon_list_update_status; +PSI_mutex_key spd_key_mutex_share; +PSI_mutex_key spd_key_mutex_share_sts; +PSI_mutex_key spd_key_mutex_share_crd; +PSI_mutex_key spd_key_mutex_share_auto_increment; +#ifdef WITH_PARTITION_STORAGE_ENGINE +PSI_mutex_key spd_key_mutex_pt_share_sts; +PSI_mutex_key spd_key_mutex_pt_share_crd; +PSI_mutex_key spd_key_mutex_pt_handler; +#endif +PSI_mutex_key spd_key_mutex_udf_table; +PSI_mutex_key spd_key_mutex_mem_calc; +PSI_mutex_key spd_key_thread_id; +PSI_mutex_key spd_key_conn_id; + +static PSI_mutex_info all_spider_mutexes[]= +{ + { &spd_key_mutex_tbl, "tbl", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_init_error_tbl, "init_error_tbl", PSI_FLAG_GLOBAL}, +#ifdef WITH_PARTITION_STORAGE_ENGINE + { &spd_key_mutex_pt_share, "pt_share", PSI_FLAG_GLOBAL}, +#endif + { &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL}, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + { &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_hs_w_conn, "hs_w_conn", PSI_FLAG_GLOBAL}, +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + { &spd_key_mutex_global_trx, "global_trx", PSI_FLAG_GLOBAL}, +#endif + { &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_mon_table_cache, "mon_table_cache", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_udf_table_mon, "udf_table_mon", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_mem_calc, "mem_calc", PSI_FLAG_GLOBAL}, + { &spd_key_thread_id, "thread_id", PSI_FLAG_GLOBAL}, + { &spd_key_conn_id, "conn_id", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_mta_conn, "mta_conn", 0}, +#ifndef WITHOUT_SPIDER_BG_SEARCH + { &spd_key_mutex_bg_conn_chain, "bg_conn_chain", 0}, + { &spd_key_mutex_bg_conn_sync, "bg_conn_sync", 0}, + { &spd_key_mutex_bg_conn, "bg_conn", 0}, + { &spd_key_mutex_bg_job_stack, "bg_job_stack", 0}, + { &spd_key_mutex_bg_mon, "bg_mon", 0}, + { &spd_key_mutex_bg_direct_sql, "bg_direct_sql", 0}, +#endif + { &spd_key_mutex_mon_list_caller, "mon_list_caller", 0}, + { &spd_key_mutex_mon_list_receptor, "mon_list_receptor", 0}, + { &spd_key_mutex_mon_list_monitor, "mon_list_monitor", 0}, + { &spd_key_mutex_mon_list_update_status, "mon_list_update_status", 0}, + { &spd_key_mutex_share, "share", 0}, + { &spd_key_mutex_share_sts, "share_sts", 0}, + { &spd_key_mutex_share_crd, "share_crd", 0}, + { &spd_key_mutex_share_auto_increment, "share_auto_increment", 0}, +#ifdef WITH_PARTITION_STORAGE_ENGINE + { &spd_key_mutex_pt_share_sts, "pt_share_sts", 0}, + { &spd_key_mutex_pt_share_crd, "pt_share_crd", 0}, + { &spd_key_mutex_pt_handler, "pt_handler", 0}, +#endif + { &spd_key_mutex_udf_table, "udf_table", 0}, +}; + +#ifndef WITHOUT_SPIDER_BG_SEARCH +PSI_cond_key spd_key_cond_bg_conn_sync; +PSI_cond_key spd_key_cond_bg_conn; +PSI_cond_key spd_key_cond_bg_sts; +PSI_cond_key spd_key_cond_bg_sts_sync; +PSI_cond_key spd_key_cond_bg_crd; +PSI_cond_key spd_key_cond_bg_crd_sync; +PSI_cond_key spd_key_cond_bg_mon; +PSI_cond_key spd_key_cond_bg_direct_sql; +#endif +PSI_cond_key spd_key_cond_udf_table_mon; + +static PSI_cond_info all_spider_conds[] = { +#ifndef WITHOUT_SPIDER_BG_SEARCH + {&spd_key_cond_bg_conn_sync, "bg_conn_sync", 0}, + {&spd_key_cond_bg_conn, "bg_conn", 0}, + {&spd_key_cond_bg_sts, "bg_sts", 0}, + {&spd_key_cond_bg_sts_sync, "bg_sts_sync", 0}, + {&spd_key_cond_bg_crd, "bg_crd", 0}, + {&spd_key_cond_bg_crd_sync, "bg_crd_sync", 0}, + {&spd_key_cond_bg_mon, "bg_mon", 0}, + {&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0}, +#endif + {&spd_key_cond_udf_table_mon, "udf_table_mon", 0}, +}; + +#ifndef WITHOUT_SPIDER_BG_SEARCH +PSI_thread_key spd_key_thd_bg; +PSI_thread_key spd_key_thd_bg_sts; +PSI_thread_key spd_key_thd_bg_crd; +PSI_thread_key spd_key_thd_bg_mon; +#endif + +static PSI_thread_info all_spider_threads[] = { +#ifndef WITHOUT_SPIDER_BG_SEARCH + {&spd_key_thd_bg, "bg", 0}, + {&spd_key_thd_bg_sts, "bg_sts", 0}, + {&spd_key_thd_bg_crd, "bg_crd", 0}, + {&spd_key_thd_bg_mon, "bg_mon", 0}, +#endif +}; +#endif + +extern HASH spider_open_connections; +extern uint spider_open_connections_id; +extern const char *spider_open_connections_func_name; +extern const char *spider_open_connections_file_name; +extern ulong spider_open_connections_line_no; +extern pthread_mutex_t spider_conn_mutex; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +extern HASH spider_hs_r_conn_hash; +extern uint spider_hs_r_conn_hash_id; +extern const char *spider_hs_r_conn_hash_func_name; +extern const char *spider_hs_r_conn_hash_file_name; +extern ulong spider_hs_r_conn_hash_line_no; +extern pthread_mutex_t spider_hs_r_conn_mutex; +extern HASH spider_hs_w_conn_hash; +extern uint spider_hs_w_conn_hash_id; +extern const char *spider_hs_w_conn_hash_func_name; +extern const char *spider_hs_w_conn_hash_file_name; +extern ulong spider_hs_w_conn_hash_line_no; +extern pthread_mutex_t spider_hs_w_conn_mutex; +#endif +extern HASH *spider_udf_table_mon_list_hash; +extern uint spider_udf_table_mon_list_hash_id; +extern const char *spider_udf_table_mon_list_hash_func_name; +extern const char *spider_udf_table_mon_list_hash_file_name; +extern ulong spider_udf_table_mon_list_hash_line_no; +extern pthread_mutex_t *spider_udf_table_mon_mutexes; +extern pthread_cond_t *spider_udf_table_mon_conds; +extern pthread_mutex_t spider_open_conn_mutex; +extern pthread_mutex_t spider_mon_table_cache_mutex; +extern DYNAMIC_ARRAY spider_mon_table_cache; +extern uint spider_mon_table_cache_id; +extern const char *spider_mon_table_cache_func_name; +extern const char *spider_mon_table_cache_file_name; +extern ulong spider_mon_table_cache_line_no; + +HASH spider_open_tables; +uint spider_open_tables_id; +const char *spider_open_tables_func_name; +const char *spider_open_tables_file_name; +ulong spider_open_tables_line_no; +pthread_mutex_t spider_tbl_mutex; +HASH spider_init_error_tables; +uint spider_init_error_tables_id; +const char *spider_init_error_tables_func_name; +const char *spider_init_error_tables_file_name; +ulong spider_init_error_tables_line_no; +pthread_mutex_t spider_init_error_tbl_mutex; + +extern pthread_mutex_t spider_thread_id_mutex; +extern pthread_mutex_t spider_conn_id_mutex; + +#ifdef WITH_PARTITION_STORAGE_ENGINE +HASH spider_open_pt_share; +uint spider_open_pt_share_id; +const char *spider_open_pt_share_func_name; +const char *spider_open_pt_share_file_name; +ulong spider_open_pt_share_line_no; +pthread_mutex_t spider_pt_share_mutex; +#endif + +HASH spider_allocated_thds; +uint spider_allocated_thds_id; +const char *spider_allocated_thds_func_name; +const char *spider_allocated_thds_file_name; +ulong spider_allocated_thds_line_no; +pthread_mutex_t spider_allocated_thds_mutex; + +#ifndef WITHOUT_SPIDER_BG_SEARCH +pthread_attr_t spider_pt_attr; + +pthread_mutex_t spider_global_trx_mutex; +SPIDER_TRX *spider_global_trx; +#endif + +extern pthread_mutex_t spider_mem_calc_mutex; + +extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; +extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; +extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; +extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; + +static char spider_wild_many = '%', spider_wild_one = '_', + spider_wild_prefix='\\'; + +// for spider_open_tables +uchar *spider_tbl_get_key( + SPIDER_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_tbl_get_key"); + *length = share->table_name_length; + DBUG_RETURN((uchar*) share->table_name); +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +uchar *spider_pt_share_get_key( + SPIDER_PARTITION_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_pt_share_get_key"); + *length = share->table_name_length; + DBUG_RETURN((uchar*) share->table_name); +} + +uchar *spider_pt_handler_share_get_key( + SPIDER_PARTITION_HANDLER_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_pt_handler_share_get_key"); + *length = sizeof(TABLE *); + DBUG_RETURN((uchar*) &share->table); +} +#endif + +uchar *spider_link_get_key( + SPIDER_LINK_FOR_HASH *link_for_hash, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_link_get_key"); + *length = link_for_hash->db_table_str->length(); + DBUG_RETURN((uchar*) link_for_hash->db_table_str->ptr()); +} + +uchar *spider_ha_get_key( + ha_spider *spider, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_ha_get_key"); + *length = spider->share->table_name_length; + DBUG_RETURN((uchar*) spider->share->table_name); +} + +uchar *spider_udf_tbl_mon_list_key( + SPIDER_TABLE_MON_LIST *table_mon_list, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_udf_tbl_mon_list_key"); + DBUG_PRINT("info",("spider hash key=%s", table_mon_list->key)); + DBUG_PRINT("info",("spider hash key length=%u", table_mon_list->key_length)); + *length = table_mon_list->key_length; + DBUG_RETURN((uchar*) table_mon_list->key); +} + +uchar *spider_allocated_thds_get_key( + THD *thd, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_allocated_thds_get_key"); + *length = sizeof(THD *); + DBUG_RETURN((uchar*) thd); +} + +#ifdef HAVE_PSI_INTERFACE +static void init_spider_psi_keys() +{ + DBUG_ENTER("init_spider_psi_keys"); + if (PSI_server == NULL) + DBUG_VOID_RETURN; + + PSI_server->register_mutex("spider", all_spider_mutexes, + array_elements(all_spider_mutexes)); + PSI_server->register_cond("spider", all_spider_conds, + array_elements(all_spider_conds)); + PSI_server->register_thread("spider", all_spider_threads, + array_elements(all_spider_threads)); + DBUG_VOID_RETURN; +} +#endif + +int spider_get_server( + SPIDER_SHARE *share, + int link_idx +) { + MEM_ROOT mem_root; + int error_num, length; + FOREIGN_SERVER *server, server_buf; + DBUG_ENTER("spider_get_server"); + SPD_INIT_ALLOC_ROOT(&mem_root, 128, 0, MYF(MY_WME)); + + if (!(server + = get_server_by_name(&mem_root, share->server_names[link_idx], + &server_buf))) + { + error_num = ER_FOREIGN_SERVER_DOESNT_EXIST; + goto error; + } + + if (!share->tgt_wrappers[link_idx] && server->scheme) + { + share->tgt_wrappers_lengths[link_idx] = strlen(server->scheme); + if (!(share->tgt_wrappers[link_idx] = + spider_create_string(server->scheme, + share->tgt_wrappers_lengths[link_idx]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_wrappers=%s", + share->tgt_wrappers[link_idx])); + } + + if (!share->tgt_hosts[link_idx] && server->host) + { + share->tgt_hosts_lengths[link_idx] = strlen(server->host); + if (!(share->tgt_hosts[link_idx] = + spider_create_string(server->host, share->tgt_hosts_lengths[link_idx]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_hosts=%s", share->tgt_hosts[link_idx])); + } + + if (share->tgt_ports[link_idx] == -1) + { + share->tgt_ports[link_idx] = server->port; + DBUG_PRINT("info",("spider tgt_ports=%ld", share->tgt_ports[link_idx])); + } + + if (!share->tgt_sockets[link_idx] && server->socket) + { + share->tgt_sockets_lengths[link_idx] = strlen(server->socket); + if (!(share->tgt_sockets[link_idx] = + spider_create_string(server->socket, + share->tgt_sockets_lengths[link_idx]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_sockets=%s", share->tgt_sockets[link_idx])); + } + + if (!share->tgt_dbs[link_idx] && server->db && (length = strlen(server->db))) + { + share->tgt_dbs_lengths[link_idx] = length; + if (!(share->tgt_dbs[link_idx] = + spider_create_string(server->db, length))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_dbs=%s", share->tgt_dbs[link_idx])); + } + + if (!share->tgt_usernames[link_idx] && server->username) + { + share->tgt_usernames_lengths[link_idx] = strlen(server->username); + if (!(share->tgt_usernames[link_idx] = + spider_create_string(server->username, + share->tgt_usernames_lengths[link_idx]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_usernames=%s", + share->tgt_usernames[link_idx])); + } + + if (!share->tgt_passwords[link_idx] && server->password) + { + share->tgt_passwords_lengths[link_idx] = strlen(server->password); + if (!(share->tgt_passwords[link_idx] = + spider_create_string(server->password, + share->tgt_passwords_lengths[link_idx]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + DBUG_PRINT("info",("spider tgt_passwords=%s", + share->tgt_passwords[link_idx])); + } + + free_root(&mem_root, MYF(0)); + DBUG_RETURN(0); + +error: + free_root(&mem_root, MYF(0)); + my_error(error_num, MYF(0), share->server_names[link_idx]); + DBUG_RETURN(error_num); +} + +int spider_free_share_alloc( + SPIDER_SHARE *share +) { + int roop_count; + DBUG_ENTER("spider_free_share_alloc"); + if (share->dbton_bitmap) + { + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--) + { + if (share->dbton_share[roop_count]) + { + delete share->dbton_share[roop_count]; + share->dbton_share[roop_count] = NULL; + } + } + } + if (share->server_names) + { + for (roop_count = 0; roop_count < (int) share->server_names_length; + roop_count++) + { + if (share->server_names[roop_count]) + spider_free(spider_current_trx, share->server_names[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->server_names, MYF(0)); + } + if (share->tgt_table_names) + { + for (roop_count = 0; roop_count < (int) share->tgt_table_names_length; + roop_count++) + { + if (share->tgt_table_names[roop_count]) + spider_free(spider_current_trx, share->tgt_table_names[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_table_names, MYF(0)); + } + if (share->tgt_dbs) + { + for (roop_count = 0; roop_count < (int) share->tgt_dbs_length; + roop_count++) + { + if (share->tgt_dbs[roop_count]) + spider_free(spider_current_trx, share->tgt_dbs[roop_count], MYF(0)); + } + spider_free(spider_current_trx, share->tgt_dbs, MYF(0)); + } + if (share->tgt_hosts) + { + for (roop_count = 0; roop_count < (int) share->tgt_hosts_length; + roop_count++) + { + if (share->tgt_hosts[roop_count]) + spider_free(spider_current_trx, share->tgt_hosts[roop_count], MYF(0)); + } + spider_free(spider_current_trx, share->tgt_hosts, MYF(0)); + } + if (share->tgt_usernames) + { + for (roop_count = 0; roop_count < (int) share->tgt_usernames_length; + roop_count++) + { + if (share->tgt_usernames[roop_count]) + spider_free(spider_current_trx, share->tgt_usernames[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_usernames, MYF(0)); + } + if (share->tgt_passwords) + { + for (roop_count = 0; roop_count < (int) share->tgt_passwords_length; + roop_count++) + { + if (share->tgt_passwords[roop_count]) + spider_free(spider_current_trx, share->tgt_passwords[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_passwords, MYF(0)); + } + if (share->tgt_sockets) + { + for (roop_count = 0; roop_count < (int) share->tgt_sockets_length; + roop_count++) + { + if (share->tgt_sockets[roop_count]) + spider_free(spider_current_trx, share->tgt_sockets[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_sockets, MYF(0)); + } + if (share->tgt_wrappers) + { + for (roop_count = 0; roop_count < (int) share->tgt_wrappers_length; + roop_count++) + { + if (share->tgt_wrappers[roop_count]) + spider_free(spider_current_trx, share->tgt_wrappers[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_wrappers, MYF(0)); + } + if (share->tgt_ssl_cas) + { + for (roop_count = 0; roop_count < (int) share->tgt_ssl_cas_length; + roop_count++) + { + if (share->tgt_ssl_cas[roop_count]) + spider_free(spider_current_trx, share->tgt_ssl_cas[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_ssl_cas, MYF(0)); + } + if (share->tgt_ssl_capaths) + { + for (roop_count = 0; roop_count < (int) share->tgt_ssl_capaths_length; + roop_count++) + { + if (share->tgt_ssl_capaths[roop_count]) + spider_free(spider_current_trx, share->tgt_ssl_capaths[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_ssl_capaths, MYF(0)); + } + if (share->tgt_ssl_certs) + { + for (roop_count = 0; roop_count < (int) share->tgt_ssl_certs_length; + roop_count++) + { + if (share->tgt_ssl_certs[roop_count]) + spider_free(spider_current_trx, share->tgt_ssl_certs[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_ssl_certs, MYF(0)); + } + if (share->tgt_ssl_ciphers) + { + for (roop_count = 0; roop_count < (int) share->tgt_ssl_ciphers_length; + roop_count++) + { + if (share->tgt_ssl_ciphers[roop_count]) + spider_free(spider_current_trx, share->tgt_ssl_ciphers[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_ssl_ciphers, MYF(0)); + } + if (share->tgt_ssl_keys) + { + for (roop_count = 0; roop_count < (int) share->tgt_ssl_keys_length; + roop_count++) + { + if (share->tgt_ssl_keys[roop_count]) + spider_free(spider_current_trx, share->tgt_ssl_keys[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_ssl_keys, MYF(0)); + } + if (share->tgt_default_files) + { + for (roop_count = 0; roop_count < (int) share->tgt_default_files_length; + roop_count++) + { + if (share->tgt_default_files[roop_count]) + spider_free(spider_current_trx, share->tgt_default_files[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_default_files, MYF(0)); + } + if (share->tgt_default_groups) + { + for (roop_count = 0; roop_count < (int) share->tgt_default_groups_length; + roop_count++) + { + if (share->tgt_default_groups[roop_count]) + spider_free(spider_current_trx, share->tgt_default_groups[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_default_groups, MYF(0)); + } + if (share->tgt_pk_names) + { + for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length; + roop_count++) + { + if (share->tgt_pk_names[roop_count]) + spider_free(spider_current_trx, share->tgt_pk_names[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_pk_names, MYF(0)); + } + if (share->tgt_sequence_names) + { + for (roop_count = 0; roop_count < (int) share->tgt_sequence_names_length; + roop_count++) + { + if (share->tgt_sequence_names[roop_count]) + spider_free(spider_current_trx, share->tgt_sequence_names[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_sequence_names, MYF(0)); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->hs_read_socks) + { + for (roop_count = 0; roop_count < (int) share->hs_read_socks_length; + roop_count++) + { + if (share->hs_read_socks[roop_count]) + spider_free(spider_current_trx, share->hs_read_socks[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->hs_read_socks, MYF(0)); + } + if (share->hs_write_socks) + { + for (roop_count = 0; roop_count < (int) share->hs_write_socks_length; + roop_count++) + { + if (share->hs_write_socks[roop_count]) + spider_free(spider_current_trx, share->hs_write_socks[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->hs_write_socks, MYF(0)); + } +#endif + if (share->bka_engine) + spider_free(spider_current_trx, share->bka_engine, MYF(0)); + if (share->conn_keys) + spider_free(spider_current_trx, share->conn_keys, MYF(0)); + if (share->tgt_ports) + spider_free(spider_current_trx, share->tgt_ports, MYF(0)); + if (share->tgt_ssl_vscs) + spider_free(spider_current_trx, share->tgt_ssl_vscs, MYF(0)); + if (share->link_statuses) + spider_free(spider_current_trx, share->link_statuses, MYF(0)); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->monitoring_bg_kind) + spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0)); +#endif + if (share->monitoring_kind) + spider_free(spider_current_trx, share->monitoring_kind, MYF(0)); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->use_hs_reads) + spider_free(spider_current_trx, share->use_hs_reads, MYF(0)); + if (share->use_hs_writes) + spider_free(spider_current_trx, share->use_hs_writes, MYF(0)); + if (share->hs_read_ports) + spider_free(spider_current_trx, share->hs_read_ports, MYF(0)); + if (share->hs_write_ports) + spider_free(spider_current_trx, share->hs_write_ports, MYF(0)); + if (share->hs_write_to_reads) + spider_free(spider_current_trx, share->hs_write_to_reads, MYF(0)); +#endif + if (share->use_handlers) + spider_free(spider_current_trx, share->use_handlers, MYF(0)); + if (share->connect_timeouts) + spider_free(spider_current_trx, share->connect_timeouts, MYF(0)); + if (share->net_read_timeouts) + spider_free(spider_current_trx, share->net_read_timeouts, MYF(0)); + if (share->net_write_timeouts) + spider_free(spider_current_trx, share->net_write_timeouts, MYF(0)); + if (share->access_balances) + spider_free(spider_current_trx, share->access_balances, MYF(0)); +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->monitoring_bg_interval) + spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0)); +#endif + if (share->monitoring_limit) + spider_free(spider_current_trx, share->monitoring_limit, MYF(0)); + if (share->monitoring_sid) + spider_free(spider_current_trx, share->monitoring_sid, MYF(0)); + if (share->alter_table.tmp_server_names) + spider_free(spider_current_trx, share->alter_table.tmp_server_names, + MYF(0)); + if (share->key_hint) + { + delete [] share->key_hint; + share->key_hint = NULL; + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (share->partition_share) + spider_free_pt_share(share->partition_share); +#endif + DBUG_RETURN(0); +} + +void spider_free_tmp_share_alloc( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_free_tmp_share_alloc"); + if (share->server_names && share->server_names[0]) + { + spider_free(spider_current_trx, share->server_names[0], MYF(0)); + share->server_names[0] = NULL; + } + if (share->tgt_table_names && share->tgt_table_names[0]) + { + spider_free(spider_current_trx, share->tgt_table_names[0], MYF(0)); + share->tgt_table_names[0] = NULL; + } + if (share->tgt_dbs && share->tgt_dbs[0]) + { + spider_free(spider_current_trx, share->tgt_dbs[0], MYF(0)); + share->tgt_dbs[0] = NULL; + } + if (share->tgt_hosts && share->tgt_hosts[0]) + { + spider_free(spider_current_trx, share->tgt_hosts[0], MYF(0)); + share->tgt_hosts[0] = NULL; + } + if (share->tgt_usernames && share->tgt_usernames[0]) + { + spider_free(spider_current_trx, share->tgt_usernames[0], MYF(0)); + share->tgt_usernames[0] = NULL; + } + if (share->tgt_passwords && share->tgt_passwords[0]) + { + spider_free(spider_current_trx, share->tgt_passwords[0], MYF(0)); + share->tgt_passwords[0] = NULL; + } + if (share->tgt_sockets && share->tgt_sockets[0]) + { + spider_free(spider_current_trx, share->tgt_sockets[0], MYF(0)); + share->tgt_sockets[0] = NULL; + } + if (share->tgt_wrappers && share->tgt_wrappers[0]) + { + spider_free(spider_current_trx, share->tgt_wrappers[0], MYF(0)); + share->tgt_wrappers[0] = NULL; + } + if (share->tgt_ssl_cas && share->tgt_ssl_cas[0]) + { + spider_free(spider_current_trx, share->tgt_ssl_cas[0], MYF(0)); + share->tgt_ssl_cas[0] = NULL; + } + if (share->tgt_ssl_capaths && share->tgt_ssl_capaths[0]) + { + spider_free(spider_current_trx, share->tgt_ssl_capaths[0], MYF(0)); + share->tgt_ssl_capaths[0] = NULL; + } + if (share->tgt_ssl_certs && share->tgt_ssl_certs[0]) + { + spider_free(spider_current_trx, share->tgt_ssl_certs[0], MYF(0)); + share->tgt_ssl_certs[0] = NULL; + } + if (share->tgt_ssl_ciphers && share->tgt_ssl_ciphers[0]) + { + spider_free(spider_current_trx, share->tgt_ssl_ciphers[0], MYF(0)); + share->tgt_ssl_ciphers[0] = NULL; + } + if (share->tgt_ssl_keys && share->tgt_ssl_keys[0]) + { + spider_free(spider_current_trx, share->tgt_ssl_keys[0], MYF(0)); + share->tgt_ssl_keys[0] = NULL; + } + if (share->tgt_default_files && share->tgt_default_files[0]) + { + spider_free(spider_current_trx, share->tgt_default_files[0], MYF(0)); + share->tgt_default_files[0] = NULL; + } + if (share->tgt_default_groups && share->tgt_default_groups[0]) + { + spider_free(spider_current_trx, share->tgt_default_groups[0], MYF(0)); + share->tgt_default_groups[0] = NULL; + } + if (share->tgt_pk_names && share->tgt_pk_names[0]) + { + spider_free(spider_current_trx, share->tgt_pk_names[0], MYF(0)); + share->tgt_pk_names[0] = NULL; + } + if (share->tgt_sequence_names && share->tgt_sequence_names[0]) + { + spider_free(spider_current_trx, share->tgt_sequence_names[0], MYF(0)); + share->tgt_sequence_names[0] = NULL; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->hs_read_socks && share->hs_read_socks[0]) + { + spider_free(spider_current_trx, share->hs_read_socks[0], MYF(0)); + share->hs_read_socks[0] = NULL; + } + if (share->hs_write_socks && share->hs_write_socks[0]) + { + spider_free(spider_current_trx, share->hs_write_socks[0], MYF(0)); + share->hs_write_socks[0] = NULL; + } +#endif + if (share->bka_engine) + { + spider_free(spider_current_trx, share->bka_engine, MYF(0)); + share->bka_engine = NULL; + } + if (share->conn_keys) + { + spider_free(spider_current_trx, share->conn_keys, MYF(0)); + share->conn_keys = NULL; + } + if (share->key_hint) + { + delete [] share->key_hint; + share->key_hint = NULL; + } + DBUG_VOID_RETURN; +} + +char *spider_get_string_between_quote( + char *ptr, + bool alloc +) { + char *start_ptr, *end_ptr, *tmp_ptr, *esc_ptr; + bool find_flg = FALSE, esc_flg = FALSE; + DBUG_ENTER("spider_get_string_between_quote"); + + start_ptr = strchr(ptr, '\''); + end_ptr = strchr(ptr, '"'); + if (start_ptr && (!end_ptr || start_ptr < end_ptr)) + { + tmp_ptr = ++start_ptr; + while (!find_flg) + { + if (!(end_ptr = strchr(tmp_ptr, '\''))) + DBUG_RETURN(NULL); + esc_ptr = tmp_ptr; + while (!find_flg) + { + esc_ptr = strchr(esc_ptr, '\\'); + if (!esc_ptr || esc_ptr > end_ptr) + find_flg = TRUE; + else if (esc_ptr == end_ptr - 1) + { + esc_flg = TRUE; + tmp_ptr = end_ptr + 1; + break; + } else { + esc_flg = TRUE; + esc_ptr += 2; + } + } + } + } else if (end_ptr) + { + start_ptr = end_ptr; + tmp_ptr = ++start_ptr; + while (!find_flg) + { + if (!(end_ptr = strchr(tmp_ptr, '"'))) + DBUG_RETURN(NULL); + esc_ptr = tmp_ptr; + while (!find_flg) + { + esc_ptr = strchr(esc_ptr, '\\'); + if (!esc_ptr || esc_ptr > end_ptr) + find_flg = TRUE; + else if (esc_ptr == end_ptr - 1) + { + esc_flg = TRUE; + tmp_ptr = end_ptr + 1; + break; + } else { + esc_flg = TRUE; + esc_ptr += 2; + } + } + } + } else + DBUG_RETURN(NULL); + + *end_ptr = '\0'; + if (esc_flg) + { + esc_ptr = start_ptr; + while (TRUE) + { + esc_ptr = strchr(esc_ptr, '\\'); + if (!esc_ptr) + break; + switch(*(esc_ptr + 1)) + { + case 'b': + *esc_ptr = '\b'; + break; + case 'n': + *esc_ptr = '\n'; + break; + case 'r': + *esc_ptr = '\r'; + break; + case 't': + *esc_ptr = '\t'; + break; + default: + *esc_ptr = *(esc_ptr + 1); + break; + } + esc_ptr++; + strcpy(esc_ptr, esc_ptr + 1); + } + } + if (alloc) + { + DBUG_RETURN( + spider_create_string( + start_ptr, + strlen(start_ptr)) + ); + } else { + DBUG_RETURN(start_ptr); + } +} + +int spider_create_string_list( + char ***string_list, + uint **string_length_list, + uint *list_length, + char *str, + uint length +) { + int roop_count; + char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *esc_ptr; + bool find_flg = FALSE; + DBUG_ENTER("spider_create_string_list"); + + *list_length = 0; + if (!str) + { + *string_list = NULL; + DBUG_RETURN(0); + } + + tmp_ptr = str; + while (*tmp_ptr == ' ') + tmp_ptr++; + if (*tmp_ptr) + *list_length = 1; + else { + *string_list = NULL; + DBUG_RETURN(0); + } + + while (TRUE) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + { + esc_ptr = tmp_ptr; + while (!find_flg) + { + esc_ptr = strchr(esc_ptr, '\\'); + if (!esc_ptr || esc_ptr > tmp_ptr2) + find_flg = TRUE; + else if (esc_ptr == tmp_ptr2 - 1) + { + tmp_ptr = tmp_ptr2 + 1; + break; + } else + esc_ptr += 2; + } + if (find_flg) + { + (*list_length)++; + tmp_ptr = tmp_ptr2 + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + } + } else + break; + } + + if (!(*string_list = (char**) + spider_bulk_malloc(spider_current_trx, 37, MYF(MY_WME | MY_ZEROFILL), + string_list, sizeof(char*) * (*list_length), + string_length_list, sizeof(int) * (*list_length), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + tmp_ptr = str; + while (*tmp_ptr == ' ') + { + *tmp_ptr = '\0'; + tmp_ptr++; + } + tmp_ptr3 = tmp_ptr; + + for (roop_count = 0; roop_count < (int) *list_length - 1; roop_count++) + { + while (TRUE) + { + tmp_ptr2 = strchr(tmp_ptr, ' '); + + esc_ptr = tmp_ptr; + while (!find_flg) + { + esc_ptr = strchr(esc_ptr, '\\'); + if (!esc_ptr || esc_ptr > tmp_ptr2) + find_flg = TRUE; + else if (esc_ptr == tmp_ptr2 - 1) + { + tmp_ptr = tmp_ptr2 + 1; + break; + } else + esc_ptr += 2; + } + if (find_flg) + break; + } + tmp_ptr = tmp_ptr2; + + while (*tmp_ptr == ' ') + { + *tmp_ptr = '\0'; + tmp_ptr++; + } + + (*string_length_list)[roop_count] = strlen(tmp_ptr3); + if (!((*string_list)[roop_count] = spider_create_string( + tmp_ptr3, (*string_length_list)[roop_count])) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count, + (*string_list)[roop_count])); + tmp_ptr3 = tmp_ptr; + } + (*string_length_list)[roop_count] = strlen(tmp_ptr3); + if (!((*string_list)[roop_count] = spider_create_string( + tmp_ptr3, (*string_length_list)[roop_count])) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count, + (*string_list)[roop_count])); + + DBUG_RETURN(0); +} + +int spider_create_long_list( + long **long_list, + uint *list_length, + char *str, + uint length, + long min_val, + long max_val +) { + int roop_count; + char *tmp_ptr; + DBUG_ENTER("spider_create_long_list"); + + *list_length = 0; + if (!str) + { + *long_list = NULL; + DBUG_RETURN(0); + } + + tmp_ptr = str; + while (*tmp_ptr == ' ') + tmp_ptr++; + if (*tmp_ptr) + *list_length = 1; + else { + *long_list = NULL; + DBUG_RETURN(0); + } + + while (TRUE) + { + if ((tmp_ptr = strchr(tmp_ptr, ' '))) + { + (*list_length)++; + tmp_ptr = tmp_ptr + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + } else + break; + } + + if (!(*long_list = (long*) + spider_bulk_malloc(spider_current_trx, 38, MYF(MY_WME | MY_ZEROFILL), + long_list, sizeof(long) * (*list_length), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + tmp_ptr = str; + for (roop_count = 0; roop_count < (int) *list_length; roop_count++) + { + if (roop_count != 0) + tmp_ptr = strchr(tmp_ptr, ' '); + + while (*tmp_ptr == ' ') + { + *tmp_ptr = '\0'; + tmp_ptr++; + } + (*long_list)[roop_count] = atol(tmp_ptr); + if ((*long_list)[roop_count] < min_val) + (*long_list)[roop_count] = min_val; + else if ((*long_list)[roop_count] > max_val) + (*long_list)[roop_count] = max_val; + } + +#ifndef DBUG_OFF + for (roop_count = 0; roop_count < (int) *list_length; roop_count++) + { + DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count, + (*long_list)[roop_count])); + } +#endif + + DBUG_RETURN(0); +} + +int spider_create_longlong_list( + longlong **longlong_list, + uint *list_length, + char *str, + uint length, + longlong min_val, + longlong max_val +) { + int error_num, roop_count; + char *tmp_ptr; + DBUG_ENTER("spider_create_longlong_list"); + + *list_length = 0; + if (!str) + { + *longlong_list = NULL; + DBUG_RETURN(0); + } + + tmp_ptr = str; + while (*tmp_ptr == ' ') + tmp_ptr++; + if (*tmp_ptr) + *list_length = 1; + else { + *longlong_list = NULL; + DBUG_RETURN(0); + } + + while (TRUE) + { + if ((tmp_ptr = strchr(tmp_ptr, ' '))) + { + (*list_length)++; + tmp_ptr = tmp_ptr + 1; + while (*tmp_ptr == ' ') + tmp_ptr++; + } else + break; + } + + if (!(*longlong_list = (longlong *) + spider_bulk_malloc(spider_current_trx, 39, MYF(MY_WME | MY_ZEROFILL), + longlong_list, sizeof(longlong) * (*list_length), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + tmp_ptr = str; + for (roop_count = 0; roop_count < (int) *list_length; roop_count++) + { + if (roop_count != 0) + tmp_ptr = strchr(tmp_ptr, ' '); + + while (*tmp_ptr == ' ') + { + *tmp_ptr = '\0'; + tmp_ptr++; + } + (*longlong_list)[roop_count] = my_strtoll10(tmp_ptr, (char**) NULL, + &error_num); + if ((*longlong_list)[roop_count] < min_val) + (*longlong_list)[roop_count] = min_val; + else if ((*longlong_list)[roop_count] > max_val) + (*longlong_list)[roop_count] = max_val; + } + +#ifndef DBUG_OFF + for (roop_count = 0; roop_count < (int) *list_length; roop_count++) + { + DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count, + (*longlong_list)[roop_count])); + } +#endif + + DBUG_RETURN(0); +} + +int spider_increase_string_list( + char ***string_list, + uint **string_length_list, + uint *list_length, + uint *list_charlen, + uint link_count +) { + int roop_count; + char **tmp_str_list, *tmp_str; + uint *tmp_length_list, tmp_length; + DBUG_ENTER("spider_increase_string_list"); + if (*list_length == link_count) + DBUG_RETURN(0); + if (*list_length > 1) + { + my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, + ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); + } + + if (*string_list) + { + tmp_str = (*string_list)[0]; + tmp_length = (*string_length_list)[0]; + } else { + tmp_str = NULL; + tmp_length = 0; + } + + if (!(tmp_str_list = (char**) + spider_bulk_malloc(spider_current_trx, 40, MYF(MY_WME | MY_ZEROFILL), + &tmp_str_list, sizeof(char*) * link_count, + &tmp_length_list, sizeof(uint) * link_count, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + for (roop_count = 0; roop_count < (int) link_count; roop_count++) + { + tmp_length_list[roop_count] = tmp_length; + if (tmp_str) + { + if (!(tmp_str_list[roop_count] = spider_create_string( + tmp_str, tmp_length)) + ) + goto error; + DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count, + tmp_str_list[roop_count])); + } else + tmp_str_list[roop_count] = NULL; + } + if (*string_list) + { + if ((*string_list)[0]) + spider_free(spider_current_trx, (*string_list)[0], MYF(0)); + spider_free(spider_current_trx, *string_list, MYF(0)); + } + *list_charlen = (tmp_length + 1) * link_count - 1; + *list_length = link_count; + *string_list = tmp_str_list; + *string_length_list = tmp_length_list; + + DBUG_RETURN(0); + +error: + for (roop_count = 0; roop_count < (int) link_count; roop_count++) + { + if (tmp_str_list[roop_count]) + spider_free(spider_current_trx, tmp_str_list[roop_count], MYF(0)); + } + if (tmp_str_list) + spider_free(spider_current_trx, tmp_str_list, MYF(0)); + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +} + +int spider_increase_long_list( + long **long_list, + uint *list_length, + uint link_count +) { + int roop_count; + long *tmp_long_list, tmp_long; + DBUG_ENTER("spider_increase_long_list"); + if (*list_length == link_count) + DBUG_RETURN(0); + if (*list_length > 1) + { + my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, + ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); + } + + if (*long_list) + tmp_long = (*long_list)[0]; + else + tmp_long = -1; + + if (!(tmp_long_list = (long*) + spider_bulk_malloc(spider_current_trx, 41, MYF(MY_WME | MY_ZEROFILL), + &tmp_long_list, sizeof(long) * link_count, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + for (roop_count = 0; roop_count < (int) link_count; roop_count++) + { + tmp_long_list[roop_count] = tmp_long; + DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count, + tmp_long)); + } + if (*long_list) + spider_free(spider_current_trx, *long_list, MYF(0)); + *list_length = link_count; + *long_list = tmp_long_list; + + DBUG_RETURN(0); +} + +int spider_increase_longlong_list( + longlong **longlong_list, + uint *list_length, + uint link_count +) { + int roop_count; + longlong *tmp_longlong_list, tmp_longlong; + DBUG_ENTER("spider_increase_longlong_list"); + if (*list_length == link_count) + DBUG_RETURN(0); + if (*list_length > 1) + { + my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, + ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); + } + + if (*longlong_list) + tmp_longlong = (*longlong_list)[0]; + else + tmp_longlong = -1; + + if (!(tmp_longlong_list = (longlong*) + spider_bulk_malloc(spider_current_trx, 42, MYF(MY_WME | MY_ZEROFILL), + &tmp_longlong_list, sizeof(longlong) * link_count, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + for (roop_count = 0; roop_count < (int) link_count; roop_count++) + { + tmp_longlong_list[roop_count] = tmp_longlong; + DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count, + tmp_longlong)); + } + if (*longlong_list) + spider_free(spider_current_trx, *longlong_list, MYF(0)); + *list_length = link_count; + *longlong_list = tmp_longlong_list; + + DBUG_RETURN(0); +} + +#define SPIDER_PARAM_STR_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!share->param_name) \ + { \ + if ((share->param_name = spider_get_string_between_quote( \ + start_ptr, TRUE))) \ + share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \ + else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%s", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_STR_LENS(name) name ## _lengths +#define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen +#define SPIDER_PARAM_STR_LIST(title_name, param_name) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!share->param_name) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + share->SPIDER_PARAM_STR_CHARLEN(param_name) = strlen(tmp_ptr2); \ + if ((error_num = spider_create_string_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_STR_LENS(param_name), \ + &share->SPIDER_PARAM_STR_LEN(param_name), \ + tmp_ptr2, \ + share->SPIDER_PARAM_STR_CHARLEN(param_name)))) \ + goto error; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + } \ + break; \ + } +#define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \ + if (!strncasecmp(tmp_ptr, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(tmp_ptr + check_length); \ + DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \ + DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \ + if (share->param_name) \ + { \ + if (hint_num < 0 || hint_num >= max_size) \ + { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } else if (share->param_name[hint_num].length() > 0) \ + break; \ + char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \ + if ((error_num = \ + append_method(&share->param_name[hint_num], hint_str))) \ + goto error; \ + DBUG_PRINT("info",("spider "title_name"[%d]=%s", hint_num, \ + share->param_name[hint_num].ptr())); \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_LONG_LEN(name) name ## _length +#define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ + min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!share->param_name) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + if ((error_num = spider_create_long_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LONG_LEN(param_name), \ + tmp_ptr2, \ + strlen(tmp_ptr2), \ + min_val, max_val))) \ + goto error; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length +#define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \ + min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (!share->param_name) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + if ((error_num = spider_create_longlong_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LONGLONG_LEN(param_name), \ + tmp_ptr2, \ + strlen(tmp_ptr2), \ + min_val, max_val))) \ + goto error; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (share->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + share->param_name = atoi(tmp_ptr2); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + else if (share->param_name > max_val) \ + share->param_name = max_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (share->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + share->param_name = atoi(tmp_ptr2); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%d", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_DOUBLE(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (share->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + share->param_name = my_atof(tmp_ptr2); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%f", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(tmp_ptr, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider "title_name" start")); \ + if (share->param_name == -1) \ + { \ + if ((tmp_ptr2 = spider_get_string_between_quote( \ + start_ptr, FALSE))) \ + { \ + share->param_name = my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + } else { \ + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \ + MYF(0), tmp_ptr); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider "title_name"=%lld", share->param_name)); \ + } \ + break; \ + } + +int spider_parse_connect_info( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info, +#endif + uint create_table +) { + int error_num = 0; + char *connect_string = NULL; + char *sprit_ptr[2]; + char *tmp_ptr, *tmp_ptr2, *start_ptr; + int roop_count; + int title_length; + SPIDER_ALTER_TABLE *share_alter; +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_element *part_elem; + partition_element *sub_elem; +#endif + DBUG_ENTER("spider_parse_connect_info"); +#if MYSQL_VERSION_ID < 50500 + DBUG_PRINT("info",("spider partition_info=%s", table_share->partition_info)); +#else + DBUG_PRINT("info",("spider partition_info=%s", + table_share->partition_info_str)); +#endif +#ifdef WITH_PARTITION_STORAGE_ENGINE + DBUG_PRINT("info",("spider part_info=%p", part_info)); +#endif + DBUG_PRINT("info",("spider s->db=%s", table_share->db.str)); + DBUG_PRINT("info",("spider s->table_name=%s", table_share->table_name.str)); + DBUG_PRINT("info",("spider s->path=%s", table_share->path.str)); + DBUG_PRINT("info", + ("spider s->normalized_path=%s", table_share->normalized_path.str)); +#ifdef WITH_PARTITION_STORAGE_ENGINE + spider_get_partition_info(share->table_name, share->table_name_length, + table_share, part_info, &part_elem, &sub_elem); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + share->sts_bg_mode = -1; +#endif + share->sts_interval = -1; + share->sts_mode = -1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->sts_sync = -1; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + share->crd_bg_mode = -1; +#endif + share->crd_interval = -1; + share->crd_mode = -1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->crd_sync = -1; +#endif + share->crd_type = -1; + share->crd_weight = -1; + share->internal_offset = -1; + share->internal_limit = -1; + share->split_read = -1; + share->semi_split_read = -1; + share->semi_split_read_limit = -1; + share->init_sql_alloc_size = -1; + share->reset_sql_alloc = -1; + share->multi_split_read = -1; + share->max_order = -1; + share->semi_table_lock = -1; + share->semi_table_lock_conn = -1; + share->selupd_lock_mode = -1; + share->query_cache = -1; + share->internal_delayed = -1; + share->bulk_size = -1; + share->bulk_update_mode = -1; + share->bulk_update_size = -1; + share->internal_optimize = -1; + share->internal_optimize_local = -1; + share->scan_rate = -1; + share->read_rate = -1; + share->priority = -1; + share->quick_mode = -1; + share->quick_page_size = -1; + share->low_mem_read = -1; + share->table_count_mode = -1; + share->select_column_mode = -1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + share->bgs_mode = -1; + share->bgs_first_read = -1; + share->bgs_second_read = -1; +#endif + share->first_read = -1; + share->second_read = -1; + share->auto_increment_mode = -1; + share->use_table_charset = -1; + share->use_pushdown_udf = -1; + share->skip_default_condition = -1; + share->direct_dup_insert = -1; + share->direct_order_limit = -1; + share->bka_mode = -1; + share->read_only_mode = -1; + share->error_read_mode = -1; + share->error_write_mode = -1; + share->active_link_count = -1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + share->hs_result_free_size = -1; +#endif +#ifdef HA_CAN_BULK_ACCESS + share->bulk_access_free = -1; +#endif + +#ifdef WITH_PARTITION_STORAGE_ENGINE + for (roop_count = 4; roop_count > 0; roop_count--) +#else + for (roop_count = 2; roop_count > 0; roop_count--) +#endif + { + if (connect_string) + { + spider_free(spider_current_trx, connect_string, MYF(0)); + connect_string = NULL; + } + switch (roop_count) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + case 4: + if (!sub_elem || !sub_elem->part_comment) + continue; + DBUG_PRINT("info",("spider create sub comment string")); + if ( + !(connect_string = spider_create_string( + sub_elem->part_comment, + strlen(sub_elem->part_comment))) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn_string; + } + DBUG_PRINT("info",("spider sub comment string=%s", connect_string)); + break; + case 3: + if (!part_elem || !part_elem->part_comment) + continue; + DBUG_PRINT("info",("spider create part comment string")); + if ( + !(connect_string = spider_create_string( + part_elem->part_comment, + strlen(part_elem->part_comment))) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn_string; + } + DBUG_PRINT("info",("spider part comment string=%s", connect_string)); + break; +#endif + case 2: + if (table_share->comment.length == 0) + continue; + DBUG_PRINT("info",("spider create comment string")); + if ( + !(connect_string = spider_create_string( + table_share->comment.str, + table_share->comment.length)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn_string; + } + DBUG_PRINT("info",("spider comment string=%s", connect_string)); + break; + default: + if (table_share->connect_string.length == 0) + continue; + DBUG_PRINT("info",("spider create connect_string string")); + if ( + !(connect_string = spider_create_string( + table_share->connect_string.str, + table_share->connect_string.length)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn_string; + } + DBUG_PRINT("info",("spider connect_string=%s", connect_string)); + break; + } + + sprit_ptr[0] = connect_string; + while (sprit_ptr[0]) + { + if ((sprit_ptr[1] = strchr(sprit_ptr[0], ','))) + { + *sprit_ptr[1] = '\0'; + sprit_ptr[1]++; + } + tmp_ptr = sprit_ptr[0]; + sprit_ptr[0] = sprit_ptr[1]; + while (*tmp_ptr == ' ' || *tmp_ptr == '\r' || + *tmp_ptr == '\n' || *tmp_ptr == '\t') + tmp_ptr++; + + if (*tmp_ptr == '\0') + continue; + + title_length = 0; + start_ptr = tmp_ptr; + while (*start_ptr != ' ' && *start_ptr != '\'' && + *start_ptr != '"' && *start_ptr != '\0' && + *start_ptr != '\r' && *start_ptr != '\n' && + *start_ptr != '\t') + { + title_length++; + start_ptr++; + } + + switch (title_length) + { + case 0: + continue; + case 3: + SPIDER_PARAM_LONG_LIST_WITH_MAX("abl", access_balances, 0, + 2147483647); + SPIDER_PARAM_INT_WITH_MAX("aim", auto_increment_mode, 0, 3); + SPIDER_PARAM_INT("alc", active_link_count, 1); +#ifdef HA_CAN_BULK_ACCESS + SPIDER_PARAM_INT_WITH_MAX("baf", bulk_access_free, 0, 1); +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONGLONG("bfr", bgs_first_read, 0); + SPIDER_PARAM_INT("bmd", bgs_mode, 0); + SPIDER_PARAM_LONGLONG("bsr", bgs_second_read, 0); +#endif + SPIDER_PARAM_STR("bke", bka_engine); + SPIDER_PARAM_INT_WITH_MAX("bkm", bka_mode, 0, 1); + SPIDER_PARAM_INT("bsz", bulk_size, 0); + SPIDER_PARAM_INT_WITH_MAX("bum", bulk_update_mode, 0, 2); + SPIDER_PARAM_INT("bus", bulk_update_size, 0); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_INT_WITH_MAX("cbm", crd_bg_mode, 0, 1); +#endif + SPIDER_PARAM_DOUBLE("civ", crd_interval, 0); + SPIDER_PARAM_INT_WITH_MAX("cmd", crd_mode, 0, 3); +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARAM_INT_WITH_MAX("csy", crd_sync, 0, 2); +#endif + SPIDER_PARAM_LONG_LIST_WITH_MAX("cto", connect_timeouts, 0, + 2147483647); + SPIDER_PARAM_INT_WITH_MAX("ctp", crd_type, 0, 2); + SPIDER_PARAM_DOUBLE("cwg", crd_weight, 1); + SPIDER_PARAM_INT_WITH_MAX("ddi", direct_dup_insert, 0, 1); + SPIDER_PARAM_STR_LIST("dff", tgt_default_files); + SPIDER_PARAM_STR_LIST("dfg", tgt_default_groups); + SPIDER_PARAM_LONGLONG("dol", direct_order_limit, 0); + SPIDER_PARAM_INT_WITH_MAX("erm", error_read_mode, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("ewm", error_write_mode, 0, 1); + SPIDER_PARAM_LONGLONG("frd", first_read, 0); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONGLONG("hrf", hs_result_free_size, 0); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hrp", hs_read_ports, 0, 65535); + SPIDER_PARAM_STR_LIST("hrs", hs_read_socks); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hwp", hs_write_ports, 0, 65535); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hwr", hs_write_to_reads, 0, 1); + SPIDER_PARAM_STR_LIST("hws", hs_write_socks); +#endif + SPIDER_PARAM_INT("isa", init_sql_alloc_size, 0); + SPIDER_PARAM_INT_WITH_MAX("idl", internal_delayed, 0, 1); + SPIDER_PARAM_LONGLONG("ilm", internal_limit, 0); + SPIDER_PARAM_LONGLONG("ios", internal_offset, 0); + SPIDER_PARAM_INT_WITH_MAX("iom", internal_optimize, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("iol", internal_optimize_local, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("lmr", low_mem_read, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("lst", link_statuses, 0, 3); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "mbi", monitoring_bg_interval, 0, 4294967295LL); + SPIDER_PARAM_LONG_LIST_WITH_MAX("mbk", monitoring_bg_kind, 0, 3); +#endif + SPIDER_PARAM_LONG_LIST_WITH_MAX("mkd", monitoring_kind, 0, 3); + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "mlt", monitoring_limit, 0, 9223372036854775807LL); + SPIDER_PARAM_INT("mod", max_order, 0); + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "msi", monitoring_sid, 0, 4294967295LL); + SPIDER_PARAM_INT_WITH_MAX("msr", multi_split_read, 0, 2147483647); + SPIDER_PARAM_LONG_LIST_WITH_MAX("nrt", net_read_timeouts, 0, + 2147483647); + SPIDER_PARAM_LONG_LIST_WITH_MAX("nwt", net_write_timeouts, 0, + 2147483647); + SPIDER_PARAM_STR_LIST("pkn", tgt_pk_names); + SPIDER_PARAM_LONGLONG("prt", priority, 0); + SPIDER_PARAM_INT_WITH_MAX("qch", query_cache, 0, 2); + SPIDER_PARAM_INT_WITH_MAX("qmd", quick_mode, 0, 3); + SPIDER_PARAM_LONGLONG("qps", quick_page_size, 0); + SPIDER_PARAM_INT_WITH_MAX("rom", read_only_mode, 0, 1); + SPIDER_PARAM_DOUBLE("rrt", read_rate, 0); + SPIDER_PARAM_INT_WITH_MAX("rsa", reset_sql_alloc, 0, 1); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_INT_WITH_MAX("sbm", sts_bg_mode, 0, 1); +#endif + SPIDER_PARAM_STR_LIST("sca", tgt_ssl_cas); + SPIDER_PARAM_STR_LIST("sch", tgt_ssl_ciphers); + SPIDER_PARAM_INT_WITH_MAX("scm", select_column_mode, 0, 1); + SPIDER_PARAM_STR_LIST("scp", tgt_ssl_capaths); + SPIDER_PARAM_STR_LIST("scr", tgt_ssl_certs); + SPIDER_PARAM_INT_WITH_MAX("sdc", skip_default_condition, 0, 1); + SPIDER_PARAM_DOUBLE("siv", sts_interval, 0); + SPIDER_PARAM_STR_LIST("sky", tgt_ssl_keys); + SPIDER_PARAM_INT_WITH_MAX("slm", selupd_lock_mode, 0, 2); + SPIDER_PARAM_INT_WITH_MAX("smd", sts_mode, 1, 2); + SPIDER_PARAM_LONGLONG("spr", split_read, 0); + SPIDER_PARAM_STR_LIST("sqn", tgt_sequence_names); + SPIDER_PARAM_LONGLONG("srd", second_read, 0); + SPIDER_PARAM_DOUBLE("srt", scan_rate, 0); + SPIDER_PARAM_STR_LIST("srv", server_names); + SPIDER_PARAM_DOUBLE("ssr", semi_split_read, 0); + SPIDER_PARAM_LONGLONG("ssl", semi_split_read_limit, 0); +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARAM_INT_WITH_MAX("ssy", sts_sync, 0, 2); +#endif + SPIDER_PARAM_INT_WITH_MAX("stc", semi_table_lock_conn, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("stl", semi_table_lock, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("svc", tgt_ssl_vscs, 0, 1); + SPIDER_PARAM_STR_LIST("tbl", tgt_table_names); + SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("uhd", use_handlers, 0, 3); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "uhr", use_hs_reads, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "uhw", use_hs_writes, 0, 1); +#endif + SPIDER_PARAM_INT_WITH_MAX("upu", use_pushdown_udf, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("utc", use_table_charset, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 4: + SPIDER_PARAM_STR_LIST("host", tgt_hosts); + SPIDER_PARAM_STR_LIST("user", tgt_usernames); + SPIDER_PARAM_LONG_LIST_WITH_MAX("port", tgt_ports, 0, 65535); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 5: + SPIDER_PARAM_STR_LIST("table", tgt_table_names); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 6: + SPIDER_PARAM_STR_LIST("server", server_names); + SPIDER_PARAM_STR_LIST("socket", tgt_sockets); + SPIDER_PARAM_HINT("idx", key_hint, 3, (int) table_share->keys, + spider_db_append_key_hint); + SPIDER_PARAM_STR_LIST("ssl_ca", tgt_ssl_cas); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 7: + SPIDER_PARAM_STR_LIST("wrapper", tgt_wrappers); + SPIDER_PARAM_STR_LIST("ssl_key", tgt_ssl_keys); + SPIDER_PARAM_STR_LIST("pk_name", tgt_pk_names); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 8: + SPIDER_PARAM_STR_LIST("database", tgt_dbs); + SPIDER_PARAM_STR_LIST("password", tgt_passwords); + SPIDER_PARAM_INT_WITH_MAX("sts_mode", sts_mode, 1, 2); +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARAM_INT_WITH_MAX("sts_sync", sts_sync, 0, 2); +#endif + SPIDER_PARAM_INT_WITH_MAX("crd_mode", crd_mode, 0, 3); +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARAM_INT_WITH_MAX("crd_sync", crd_sync, 0, 2); +#endif + SPIDER_PARAM_INT_WITH_MAX("crd_type", crd_type, 0, 2); + SPIDER_PARAM_LONGLONG("priority", priority, 0); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_INT("bgs_mode", bgs_mode, 0); +#endif + SPIDER_PARAM_STR_LIST("ssl_cert", tgt_ssl_certs); + SPIDER_PARAM_INT_WITH_MAX("bka_mode", bka_mode, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 9: + SPIDER_PARAM_INT("max_order", max_order, 0); + SPIDER_PARAM_INT("bulk_size", bulk_size, 0); + SPIDER_PARAM_DOUBLE("scan_rate", scan_rate, 0); + SPIDER_PARAM_DOUBLE("read_rate", read_rate, 0); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 10: + SPIDER_PARAM_DOUBLE("crd_weight", crd_weight, 1); + SPIDER_PARAM_LONGLONG("split_read", split_read, 0); + SPIDER_PARAM_INT_WITH_MAX("quick_mode", quick_mode, 0, 3); + SPIDER_PARAM_STR_LIST("ssl_cipher", tgt_ssl_ciphers); + SPIDER_PARAM_STR_LIST("ssl_capath", tgt_ssl_capaths); + SPIDER_PARAM_STR("bka_engine", bka_engine); + SPIDER_PARAM_LONGLONG("first_read", first_read, 0); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 11: + SPIDER_PARAM_INT_WITH_MAX("query_cache", query_cache, 0, 2); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_INT_WITH_MAX("crd_bg_mode", crd_bg_mode, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("sts_bg_mode", sts_bg_mode, 0, 1); +#endif + SPIDER_PARAM_LONG_LIST_WITH_MAX("link_status", link_statuses, 0, 3); + SPIDER_PARAM_LONG_LIST_WITH_MAX("use_handler", use_handlers, 0, 3); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONG_LIST_WITH_MAX("use_hs_read", use_hs_reads, 0, 1); +#endif + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 12: + SPIDER_PARAM_DOUBLE("sts_interval", sts_interval, 0); + SPIDER_PARAM_DOUBLE("crd_interval", crd_interval, 0); + SPIDER_PARAM_INT_WITH_MAX("low_mem_read", low_mem_read, 0, 1); + SPIDER_PARAM_STR_LIST("default_file", tgt_default_files); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "use_hs_write", use_hs_writes, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hs_read_port", hs_read_ports, 0, 65535); +#endif + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 13: + SPIDER_PARAM_STR_LIST("default_group", tgt_default_groups); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hs_write_port", hs_write_ports, 0, 65535); +#endif + SPIDER_PARAM_STR_LIST("sequence_name", tgt_sequence_names); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 14: + SPIDER_PARAM_LONGLONG("internal_limit", internal_limit, 0); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONGLONG("bgs_first_read", bgs_first_read, 0); +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_STR_LIST( + "hs_read_socket", hs_read_socks); +#endif + SPIDER_PARAM_INT_WITH_MAX("read_only_mode", read_only_mode, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("access_balance", access_balances, 0, + 2147483647); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 15: + SPIDER_PARAM_LONGLONG("internal_offset", internal_offset, 0); + SPIDER_PARAM_INT_WITH_MAX("reset_sql_alloc", reset_sql_alloc, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("semi_table_lock", semi_table_lock, 0, 1); + SPIDER_PARAM_LONGLONG("quick_page_size", quick_page_size, 0); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONGLONG("bgs_second_read", bgs_second_read, 0); +#endif + SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_kind", monitoring_kind, 0, 3); + SPIDER_PARAM_DOUBLE("semi_split_read", semi_split_read, 0); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_STR_LIST( + "hs_write_socket", hs_write_socks); +#endif + SPIDER_PARAM_LONG_LIST_WITH_MAX("connect_timeout", connect_timeouts, + 0, 2147483647); + SPIDER_PARAM_INT_WITH_MAX("error_read_mode", error_read_mode, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 16: + SPIDER_PARAM_INT_WITH_MAX( + "multi_split_read", multi_split_read, 0, 2147483647); + SPIDER_PARAM_INT_WITH_MAX( + "selupd_lock_mode", selupd_lock_mode, 0, 2); + SPIDER_PARAM_INT_WITH_MAX( + "internal_delayed", internal_delayed, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "table_count_mode", table_count_mode, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "use_pushdown_udf", use_pushdown_udf, 0, 1); + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "monitoring_limit", monitoring_limit, 0, 9223372036854775807LL); + SPIDER_PARAM_INT_WITH_MAX( + "bulk_update_mode", bulk_update_mode, 0, 2); + SPIDER_PARAM_INT("bulk_update_size", bulk_update_size, 0); + SPIDER_PARAM_LONG_LIST_WITH_MAX("net_read_timeout", + net_read_timeouts, 0, 2147483647); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "hs_write_to_read", hs_write_to_reads, 0, 1); +#endif + SPIDER_PARAM_INT_WITH_MAX( + "error_write_mode", error_write_mode, 0, 1); +#ifdef HA_CAN_BULK_ACCESS + SPIDER_PARAM_INT_WITH_MAX( + "bulk_access_free", bulk_access_free, 0, 1); +#endif + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 17: + SPIDER_PARAM_INT_WITH_MAX( + "internal_optimize", internal_optimize, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "use_table_charset", use_table_charset, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "direct_dup_insert", direct_dup_insert, 0, 1); + SPIDER_PARAM_INT("active_link_count", active_link_count, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("net_write_timeout", + net_write_timeouts, 0, 2147483647); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 18: + SPIDER_PARAM_INT_WITH_MAX( + "select_column_mode", select_column_mode, 0, 1); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "monitoring_bg_kind", monitoring_bg_kind, 0, 3); +#endif + SPIDER_PARAM_LONGLONG( + "direct_order_limit", direct_order_limit, 0); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 19: + SPIDER_PARAM_INT("init_sql_alloc_size", init_sql_alloc_size, 0); + SPIDER_PARAM_INT_WITH_MAX( + "auto_increment_mode", auto_increment_mode, 0, 3); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + SPIDER_PARAM_LONGLONG("hs_result_free_size", hs_result_free_size, 0); +#endif + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 20: + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "monitoring_server_id", monitoring_sid, 0, 4294967295LL); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 21: + SPIDER_PARAM_LONGLONG( + "semi_split_read_limit", semi_split_read_limit, 0); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 22: + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "ssl_verify_server_cert", tgt_ssl_vscs, 0, 1); +#ifndef WITHOUT_SPIDER_BG_SEARCH + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "monitoring_bg_interval", monitoring_bg_interval, 0, 4294967295LL); +#endif + SPIDER_PARAM_INT_WITH_MAX( + "skip_default_condition", skip_default_condition, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 23: + SPIDER_PARAM_INT_WITH_MAX( + "internal_optimize_local", internal_optimize_local, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + case 26: + SPIDER_PARAM_INT_WITH_MAX( + "semi_table_lock_connection", semi_table_lock_conn, 0, 1); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + default: + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), tmp_ptr); + goto error; + } + } + } + + /* check all_link_count */ + share->all_link_count = 1; + if (share->all_link_count < share->server_names_length) + share->all_link_count = share->server_names_length; + if (share->all_link_count < share->tgt_table_names_length) + share->all_link_count = share->tgt_table_names_length; + if (share->all_link_count < share->tgt_dbs_length) + share->all_link_count = share->tgt_dbs_length; + if (share->all_link_count < share->tgt_hosts_length) + share->all_link_count = share->tgt_hosts_length; + if (share->all_link_count < share->tgt_usernames_length) + share->all_link_count = share->tgt_usernames_length; + if (share->all_link_count < share->tgt_passwords_length) + share->all_link_count = share->tgt_passwords_length; + if (share->all_link_count < share->tgt_sockets_length) + share->all_link_count = share->tgt_sockets_length; + if (share->all_link_count < share->tgt_wrappers_length) + share->all_link_count = share->tgt_wrappers_length; + if (share->all_link_count < share->tgt_ssl_cas_length) + share->all_link_count = share->tgt_ssl_cas_length; + if (share->all_link_count < share->tgt_ssl_capaths_length) + share->all_link_count = share->tgt_ssl_capaths_length; + if (share->all_link_count < share->tgt_ssl_certs_length) + share->all_link_count = share->tgt_ssl_certs_length; + if (share->all_link_count < share->tgt_ssl_ciphers_length) + share->all_link_count = share->tgt_ssl_ciphers_length; + if (share->all_link_count < share->tgt_ssl_keys_length) + share->all_link_count = share->tgt_ssl_keys_length; + if (share->all_link_count < share->tgt_default_files_length) + share->all_link_count = share->tgt_default_files_length; + if (share->all_link_count < share->tgt_default_groups_length) + share->all_link_count = share->tgt_default_groups_length; + if (share->all_link_count < share->tgt_pk_names_length) + share->all_link_count = share->tgt_pk_names_length; + if (share->all_link_count < share->tgt_sequence_names_length) + share->all_link_count = share->tgt_sequence_names_length; + if (share->all_link_count < share->tgt_ports_length) + share->all_link_count = share->tgt_ports_length; + if (share->all_link_count < share->tgt_ssl_vscs_length) + share->all_link_count = share->tgt_ssl_vscs_length; + if (share->all_link_count < share->link_statuses_length) + share->all_link_count = share->link_statuses_length; + if (share->all_link_count < share->monitoring_kind_length) + share->all_link_count = share->monitoring_kind_length; + if (share->all_link_count < share->monitoring_limit_length) + share->all_link_count = share->monitoring_limit_length; + if (share->all_link_count < share->monitoring_sid_length) + share->all_link_count = share->monitoring_sid_length; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->all_link_count < share->monitoring_bg_kind_length) + share->all_link_count = share->monitoring_bg_kind_length; + if (share->all_link_count < share->monitoring_bg_interval_length) + share->all_link_count = share->monitoring_bg_interval_length; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->all_link_count < share->use_hs_reads_length) + share->all_link_count = share->use_hs_reads_length; + if (share->all_link_count < share->use_hs_writes_length) + share->all_link_count = share->use_hs_writes_length; + if (share->all_link_count < share->hs_read_ports_length) + share->all_link_count = share->hs_read_ports_length; + if (share->all_link_count < share->hs_write_ports_length) + share->all_link_count = share->hs_write_ports_length; + if (share->all_link_count < share->hs_read_socks_length) + share->all_link_count = share->hs_read_socks_length; + if (share->all_link_count < share->hs_write_socks_length) + share->all_link_count = share->hs_write_socks_length; + if (share->all_link_count < share->hs_write_to_reads_length) + share->all_link_count = share->hs_write_to_reads_length; +#endif + if (share->all_link_count < share->use_handlers_length) + share->all_link_count = share->use_handlers_length; + if (share->all_link_count < share->connect_timeouts_length) + share->all_link_count = share->connect_timeouts_length; + if (share->all_link_count < share->net_read_timeouts_length) + share->all_link_count = share->net_read_timeouts_length; + if (share->all_link_count < share->net_write_timeouts_length) + share->all_link_count = share->net_write_timeouts_length; + if (share->all_link_count < share->access_balances_length) + share->all_link_count = share->access_balances_length; + if ((error_num = spider_increase_string_list( + &share->server_names, + &share->server_names_lengths, + &share->server_names_length, + &share->server_names_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_table_names, + &share->tgt_table_names_lengths, + &share->tgt_table_names_length, + &share->tgt_table_names_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_dbs, + &share->tgt_dbs_lengths, + &share->tgt_dbs_length, + &share->tgt_dbs_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_hosts, + &share->tgt_hosts_lengths, + &share->tgt_hosts_length, + &share->tgt_hosts_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_usernames, + &share->tgt_usernames_lengths, + &share->tgt_usernames_length, + &share->tgt_usernames_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_passwords, + &share->tgt_passwords_lengths, + &share->tgt_passwords_length, + &share->tgt_passwords_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_sockets, + &share->tgt_sockets_lengths, + &share->tgt_sockets_length, + &share->tgt_sockets_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_wrappers, + &share->tgt_wrappers_lengths, + &share->tgt_wrappers_length, + &share->tgt_wrappers_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_ssl_cas, + &share->tgt_ssl_cas_lengths, + &share->tgt_ssl_cas_length, + &share->tgt_ssl_cas_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_ssl_capaths, + &share->tgt_ssl_capaths_lengths, + &share->tgt_ssl_capaths_length, + &share->tgt_ssl_capaths_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_ssl_certs, + &share->tgt_ssl_certs_lengths, + &share->tgt_ssl_certs_length, + &share->tgt_ssl_certs_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_ssl_ciphers, + &share->tgt_ssl_ciphers_lengths, + &share->tgt_ssl_ciphers_length, + &share->tgt_ssl_ciphers_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_ssl_keys, + &share->tgt_ssl_keys_lengths, + &share->tgt_ssl_keys_length, + &share->tgt_ssl_keys_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_default_files, + &share->tgt_default_files_lengths, + &share->tgt_default_files_length, + &share->tgt_default_files_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_default_groups, + &share->tgt_default_groups_lengths, + &share->tgt_default_groups_length, + &share->tgt_default_groups_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_pk_names, + &share->tgt_pk_names_lengths, + &share->tgt_pk_names_length, + &share->tgt_pk_names_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_sequence_names, + &share->tgt_sequence_names_lengths, + &share->tgt_sequence_names_length, + &share->tgt_sequence_names_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->tgt_ports, + &share->tgt_ports_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->tgt_ssl_vscs, + &share->tgt_ssl_vscs_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->link_statuses, + &share->link_statuses_length, + share->all_link_count))) + goto error; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_increase_long_list( + &share->monitoring_bg_kind, + &share->monitoring_bg_kind_length, + share->all_link_count))) + goto error; +#endif + if ((error_num = spider_increase_long_list( + &share->monitoring_kind, + &share->monitoring_kind_length, + share->all_link_count))) + goto error; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ((error_num = spider_increase_longlong_list( + &share->monitoring_bg_interval, + &share->monitoring_bg_interval_length, + share->all_link_count))) + goto error; +#endif + if ((error_num = spider_increase_longlong_list( + &share->monitoring_limit, + &share->monitoring_limit_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_longlong_list( + &share->monitoring_sid, + &share->monitoring_sid_length, + share->all_link_count))) + goto error; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ((error_num = spider_increase_long_list( + &share->use_hs_reads, + &share->use_hs_reads_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->use_hs_writes, + &share->use_hs_writes_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->hs_read_ports, + &share->hs_read_ports_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->hs_write_ports, + &share->hs_write_ports_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->hs_read_socks, + &share->hs_read_socks_lengths, + &share->hs_read_socks_length, + &share->hs_read_socks_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->hs_write_socks, + &share->hs_write_socks_lengths, + &share->hs_write_socks_length, + &share->hs_write_socks_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->hs_write_to_reads, + &share->hs_write_to_reads_length, + share->all_link_count))) + goto error; +#endif + if ((error_num = spider_increase_long_list( + &share->use_handlers, + &share->use_handlers_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->connect_timeouts, + &share->connect_timeouts_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->net_read_timeouts, + &share->net_read_timeouts_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->net_write_timeouts, + &share->net_write_timeouts_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->access_balances, + &share->access_balances_length, + share->all_link_count))) + goto error; + + /* copy for tables start */ + share_alter = &share->alter_table; + share_alter->all_link_count = share->all_link_count; + if (!(share_alter->tmp_server_names = (char **) + spider_bulk_malloc(spider_current_trx, 43, MYF(MY_WME | MY_ZEROFILL), + &share_alter->tmp_server_names, + sizeof(char *) * 15 * share->all_link_count, + &share_alter->tmp_server_names_lengths, + sizeof(uint *) * 15 * share->all_link_count, + &share_alter->tmp_tgt_ports, + sizeof(long) * share->all_link_count, + &share_alter->tmp_tgt_ssl_vscs, + sizeof(long) * share->all_link_count, + &share_alter->tmp_link_statuses, + sizeof(long) * share->all_link_count, + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + + + memcpy(share_alter->tmp_server_names, share->server_names, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_table_names = + share_alter->tmp_server_names + share->all_link_count; + memcpy(share_alter->tmp_tgt_table_names, share->tgt_table_names, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_dbs = + share_alter->tmp_tgt_table_names + share->all_link_count; + memcpy(share_alter->tmp_tgt_dbs, share->tgt_dbs, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_hosts = + share_alter->tmp_tgt_dbs + share->all_link_count; + memcpy(share_alter->tmp_tgt_hosts, share->tgt_hosts, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_usernames = + share_alter->tmp_tgt_hosts + share->all_link_count; + memcpy(share_alter->tmp_tgt_usernames, share->tgt_usernames, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_passwords = + share_alter->tmp_tgt_usernames + share->all_link_count; + memcpy(share_alter->tmp_tgt_passwords, share->tgt_passwords, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_sockets = + share_alter->tmp_tgt_passwords + share->all_link_count; + memcpy(share_alter->tmp_tgt_sockets, share->tgt_sockets, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_wrappers = + share_alter->tmp_tgt_sockets + share->all_link_count; + memcpy(share_alter->tmp_tgt_wrappers, share->tgt_wrappers, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_ssl_cas = + share_alter->tmp_tgt_wrappers + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_cas, share->tgt_ssl_cas, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_ssl_capaths = + share_alter->tmp_tgt_ssl_cas + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_capaths, share->tgt_ssl_capaths, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_ssl_certs = + share_alter->tmp_tgt_ssl_capaths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_certs, share->tgt_ssl_certs, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_ssl_ciphers = + share_alter->tmp_tgt_ssl_certs + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_ciphers, share->tgt_ssl_ciphers, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_ssl_keys = + share_alter->tmp_tgt_ssl_ciphers + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_keys, share->tgt_ssl_keys, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_default_files = + share_alter->tmp_tgt_ssl_keys + share->all_link_count; + memcpy(share_alter->tmp_tgt_default_files, share->tgt_default_files, + sizeof(char *) * share->all_link_count); + share_alter->tmp_tgt_default_groups = + share_alter->tmp_tgt_default_files + share->all_link_count; + memcpy(share_alter->tmp_tgt_default_groups, share->tgt_default_groups, + sizeof(char *) * share->all_link_count); + + memcpy(share_alter->tmp_tgt_ports, share->tgt_ports, + sizeof(long) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_vscs, share->tgt_ssl_vscs, + sizeof(long) * share->all_link_count); + memcpy(share_alter->tmp_link_statuses, share->link_statuses, + sizeof(long) * share->all_link_count); + + memcpy(share_alter->tmp_server_names_lengths, + share->server_names_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_table_names_lengths = + share_alter->tmp_server_names_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_table_names_lengths, + share->tgt_table_names_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_dbs_lengths = + share_alter->tmp_tgt_table_names_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_dbs_lengths, share->tgt_dbs_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_hosts_lengths = + share_alter->tmp_tgt_dbs_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_hosts_lengths, share->tgt_hosts_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_usernames_lengths = + share_alter->tmp_tgt_hosts_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_usernames_lengths, + share->tgt_usernames_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_passwords_lengths = + share_alter->tmp_tgt_usernames_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_passwords_lengths, + share->tgt_passwords_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_sockets_lengths = + share_alter->tmp_tgt_passwords_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_sockets_lengths, share->tgt_sockets_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_wrappers_lengths = + share_alter->tmp_tgt_sockets_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_wrappers_lengths, + share->tgt_wrappers_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_ssl_cas_lengths = + share_alter->tmp_tgt_wrappers_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_cas_lengths, + share->tgt_ssl_cas_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_ssl_capaths_lengths = + share_alter->tmp_tgt_ssl_cas_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_capaths_lengths, + share->tgt_ssl_capaths_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_ssl_certs_lengths = + share_alter->tmp_tgt_ssl_capaths_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_certs_lengths, + share->tgt_ssl_certs_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_ssl_ciphers_lengths = + share_alter->tmp_tgt_ssl_certs_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_ciphers_lengths, + share->tgt_ssl_ciphers_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_ssl_keys_lengths = + share_alter->tmp_tgt_ssl_ciphers_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_ssl_keys_lengths, + share->tgt_ssl_keys_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_default_files_lengths = + share_alter->tmp_tgt_ssl_keys_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_default_files_lengths, + share->tgt_default_files_lengths, + sizeof(uint) * share->all_link_count); + share_alter->tmp_tgt_default_groups_lengths = + share_alter->tmp_tgt_default_files_lengths + share->all_link_count; + memcpy(share_alter->tmp_tgt_default_groups_lengths, + share->tgt_default_groups_lengths, + sizeof(uint) * share->all_link_count); + + share_alter->tmp_server_names_charlen = share->server_names_charlen; + share_alter->tmp_tgt_table_names_charlen = share->tgt_table_names_charlen; + share_alter->tmp_tgt_dbs_charlen = share->tgt_dbs_charlen; + share_alter->tmp_tgt_hosts_charlen = share->tgt_hosts_charlen; + share_alter->tmp_tgt_usernames_charlen = share->tgt_usernames_charlen; + share_alter->tmp_tgt_passwords_charlen = share->tgt_passwords_charlen; + share_alter->tmp_tgt_sockets_charlen = share->tgt_sockets_charlen; + share_alter->tmp_tgt_wrappers_charlen = share->tgt_wrappers_charlen; + share_alter->tmp_tgt_ssl_cas_charlen = share->tgt_ssl_cas_charlen; + share_alter->tmp_tgt_ssl_capaths_charlen = share->tgt_ssl_capaths_charlen; + share_alter->tmp_tgt_ssl_certs_charlen = share->tgt_ssl_certs_charlen; + share_alter->tmp_tgt_ssl_ciphers_charlen = share->tgt_ssl_ciphers_charlen; + share_alter->tmp_tgt_ssl_keys_charlen = share->tgt_ssl_keys_charlen; + share_alter->tmp_tgt_default_files_charlen = + share->tgt_default_files_charlen; + share_alter->tmp_tgt_default_groups_charlen = + share->tgt_default_groups_charlen; + + share_alter->tmp_server_names_length = share->server_names_length; + share_alter->tmp_tgt_table_names_length = share->tgt_table_names_length; + share_alter->tmp_tgt_dbs_length = share->tgt_dbs_length; + share_alter->tmp_tgt_hosts_length = share->tgt_hosts_length; + share_alter->tmp_tgt_usernames_length = share->tgt_usernames_length; + share_alter->tmp_tgt_passwords_length = share->tgt_passwords_length; + share_alter->tmp_tgt_sockets_length = share->tgt_sockets_length; + share_alter->tmp_tgt_wrappers_length = share->tgt_wrappers_length; + share_alter->tmp_tgt_ssl_cas_length = share->tgt_ssl_cas_length; + share_alter->tmp_tgt_ssl_capaths_length = share->tgt_ssl_capaths_length; + share_alter->tmp_tgt_ssl_certs_length = share->tgt_ssl_certs_length; + share_alter->tmp_tgt_ssl_ciphers_length = share->tgt_ssl_ciphers_length; + share_alter->tmp_tgt_ssl_keys_length = share->tgt_ssl_keys_length; + share_alter->tmp_tgt_default_files_length = share->tgt_default_files_length; + share_alter->tmp_tgt_default_groups_length = + share->tgt_default_groups_length; + share_alter->tmp_tgt_ports_length = share->tgt_ports_length; + share_alter->tmp_tgt_ssl_vscs_length = share->tgt_ssl_vscs_length; + share_alter->tmp_link_statuses_length = share->link_statuses_length; + /* copy for tables end */ + + if ((error_num = spider_set_connect_info_default( + share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + part_elem, + sub_elem, +#endif + table_share + ))) + goto error; + + if (create_table) + { + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + int roop_count2; + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) + { + if ( + spider_dbton[roop_count2].wrapper && + !strcmp(share->tgt_wrappers[roop_count], + spider_dbton[roop_count2].wrapper) + ) { + break; + } + } + if (roop_count2 == SPIDER_DBTON_SIZE) + { + DBUG_PRINT("info",("spider err tgt_wrappers[%d]=%s", roop_count, + share->tgt_wrappers[roop_count])); + error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), share->tgt_wrappers[roop_count]); + goto error; + } + + DBUG_PRINT("info", + ("spider server_names_lengths[%d] = %u", roop_count, + share->server_names_lengths[roop_count])); + if (share->server_names_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->server_names[roop_count], "server"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_table_names_lengths[%d] = %u", roop_count, + share->tgt_table_names_lengths[roop_count])); + if (share->tgt_table_names_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_table_names[roop_count], "table"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_dbs_lengths[%d] = %u", roop_count, + share->tgt_dbs_lengths[roop_count])); + if (share->tgt_dbs_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_dbs[roop_count], "database"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_hosts_lengths[%d] = %u", roop_count, + share->tgt_hosts_lengths[roop_count])); + if (share->tgt_hosts_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_hosts[roop_count], "host"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_usernames_lengths[%d] = %u", roop_count, + share->tgt_usernames_lengths[roop_count])); + if (share->tgt_usernames_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_usernames[roop_count], "user"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_passwords_lengths[%d] = %u", roop_count, + share->tgt_passwords_lengths[roop_count])); + if (share->tgt_passwords_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_passwords[roop_count], "password"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_sockets_lengths[%d] = %u", roop_count, + share->tgt_sockets_lengths[roop_count])); + if (share->tgt_sockets_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_sockets[roop_count], "socket"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_wrappers_lengths[%d] = %u", roop_count, + share->tgt_wrappers_lengths[roop_count])); + if (share->tgt_wrappers_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_wrappers[roop_count], "wrapper"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_ssl_cas_lengths[%d] = %u", roop_count, + share->tgt_ssl_cas_lengths[roop_count])); + if (share->tgt_ssl_cas_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_ssl_cas[roop_count], "ssl_ca"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_ssl_capaths_lengths[%d] = %u", roop_count, + share->tgt_ssl_capaths_lengths[roop_count])); + if (share->tgt_ssl_capaths_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_ssl_capaths[roop_count], "ssl_capath"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_ssl_certs_lengths[%d] = %u", roop_count, + share->tgt_ssl_certs_lengths[roop_count])); + if (share->tgt_ssl_certs_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_ssl_certs[roop_count], "ssl_cert"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_ssl_ciphers_lengths[%d] = %u", roop_count, + share->tgt_ssl_ciphers_lengths[roop_count])); + if (share->tgt_ssl_ciphers_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_ssl_ciphers[roop_count], "ssl_cipher"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_ssl_keys_lengths[%d] = %u", roop_count, + share->tgt_ssl_keys_lengths[roop_count])); + if (share->tgt_ssl_keys_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_ssl_keys[roop_count], "ssl_key"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_default_files_lengths[%d] = %u", roop_count, + share->tgt_default_files_lengths[roop_count])); + if (share->tgt_default_files_lengths[roop_count] > + SPIDER_CONNECT_INFO_PATH_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_default_files[roop_count], "default_file"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_default_groups_lengths[%d] = %u", roop_count, + share->tgt_default_groups_lengths[roop_count])); + if (share->tgt_default_groups_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_default_groups[roop_count], "default_group"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_pk_names_lengths[%d] = %u", roop_count, + share->tgt_pk_names_lengths[roop_count])); + if (share->tgt_pk_names_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_pk_names[roop_count], "pk_name"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_sequence_names_lengths[%d] = %u", roop_count, + share->tgt_sequence_names_lengths[roop_count])); + if (share->tgt_sequence_names_lengths[roop_count] > + SPIDER_CONNECT_INFO_MAX_LEN) + { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, + MYF(0), share->tgt_sequence_names[roop_count], "sequence_name"); + goto error; + } + } + } + + DBUG_PRINT("info", ("spider share->active_link_count = %d", + share->active_link_count)); + share->link_count = (uint) share->active_link_count; + share_alter->link_count = share->link_count; + share->link_bitmap_size = (share->link_count + 7) / 8; + + if (connect_string) + spider_free(spider_current_trx, connect_string, MYF(0)); + DBUG_RETURN(0); + +error: + if (connect_string) + spider_free(spider_current_trx, connect_string, MYF(0)); +error_alloc_conn_string: + DBUG_RETURN(error_num); +} + +int spider_set_connect_info_default( + SPIDER_SHARE *share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_element *part_elem, + partition_element *sub_elem, +#endif + TABLE_SHARE *table_share +) { + int error_num, roop_count; + DBUG_ENTER("spider_set_connect_info_default"); + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + if (share->server_names[roop_count]) + { + if ((error_num = spider_get_server(share, roop_count))) + DBUG_RETURN(error_num); + } + + if (!share->tgt_wrappers[roop_count]) + { + DBUG_PRINT("info",("spider create default tgt_wrappers")); + share->tgt_wrappers_lengths[roop_count] = SPIDER_DB_WRAPPER_LEN; + if ( + !(share->tgt_wrappers[roop_count] = spider_create_string( + SPIDER_DB_WRAPPER_STR, + share->tgt_wrappers_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!share->tgt_hosts[roop_count]) + { + DBUG_PRINT("info",("spider create default tgt_hosts")); + share->tgt_hosts_lengths[roop_count] = strlen(my_localhost); + if ( + !(share->tgt_hosts[roop_count] = spider_create_string( + my_localhost, + share->tgt_hosts_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!share->tgt_dbs[roop_count] && table_share) + { + DBUG_PRINT("info",("spider create default tgt_dbs")); + share->tgt_dbs_lengths[roop_count] = table_share->db.length; + if ( + !(share->tgt_dbs[roop_count] = spider_create_string( + table_share->db.str, + table_share->db.length)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!share->tgt_table_names[roop_count] && table_share) + { + DBUG_PRINT("info",("spider create default tgt_table_names")); + share->tgt_table_names_lengths[roop_count] = share->table_name_length; + if ( + !(share->tgt_table_names[roop_count] = spider_create_table_name_string( + table_share->table_name.str, +#ifdef WITH_PARTITION_STORAGE_ENGINE + (part_elem ? part_elem->partition_name : NULL), + (sub_elem ? sub_elem->partition_name : NULL) +#else + NULL, + NULL +#endif + )) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if ( + !share->tgt_default_files[roop_count] && + share->tgt_default_groups[roop_count] && + (*spd_defaults_file || *spd_defaults_extra_file) + ) { + DBUG_PRINT("info",("spider create default tgt_default_files")); + if (*spd_defaults_extra_file) + { + share->tgt_default_files_lengths[roop_count] = + strlen(*spd_defaults_extra_file); + if ( + !(share->tgt_default_files[roop_count] = spider_create_string( + *spd_defaults_extra_file, + share->tgt_default_files_lengths[roop_count])) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + share->tgt_default_files_lengths[roop_count] = + strlen(*spd_defaults_file); + if ( + !(share->tgt_default_files[roop_count] = spider_create_string( + *spd_defaults_file, + share->tgt_default_files_lengths[roop_count])) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + + if (!share->tgt_pk_names[roop_count]) + { + DBUG_PRINT("info",("spider create default tgt_pk_names")); + share->tgt_pk_names_lengths[roop_count] = SPIDER_DB_PK_NAME_LEN; + if ( + !(share->tgt_pk_names[roop_count] = spider_create_string( + SPIDER_DB_PK_NAME_STR, + share->tgt_pk_names_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!share->tgt_sequence_names[roop_count]) + { + DBUG_PRINT("info",("spider create default tgt_sequence_names")); + share->tgt_sequence_names_lengths[roop_count] = + SPIDER_DB_SEQUENCE_NAME_LEN; + if ( + !(share->tgt_sequence_names[roop_count] = spider_create_string( + SPIDER_DB_SEQUENCE_NAME_STR, + share->tgt_sequence_names_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (share->tgt_ports[roop_count] == -1) + { + share->tgt_ports[roop_count] = MYSQL_PORT; + } else if (share->tgt_ports[roop_count] < 0) + { + share->tgt_ports[roop_count] = 0; + } else if (share->tgt_ports[roop_count] > 65535) + { + share->tgt_ports[roop_count] = 65535; + } + + if (share->tgt_ssl_vscs[roop_count] == -1) + share->tgt_ssl_vscs[roop_count] = 0; + + if ( + !share->tgt_sockets[roop_count] && + !strcmp(share->tgt_hosts[roop_count], my_localhost) + ) { + DBUG_PRINT("info",("spider create default tgt_sockets")); + share->tgt_sockets_lengths[roop_count] = + strlen((char *) MYSQL_UNIX_ADDR); + if ( + !(share->tgt_sockets[roop_count] = spider_create_string( + (char *) MYSQL_UNIX_ADDR, + share->tgt_sockets_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (share->link_statuses[roop_count] == -1) + share->link_statuses[roop_count] = SPIDER_LINK_STATUS_NO_CHANGE; + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->monitoring_bg_kind[roop_count] == -1) + share->monitoring_bg_kind[roop_count] = 0; +#endif + if (share->monitoring_kind[roop_count] == -1) + share->monitoring_kind[roop_count] = 0; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->monitoring_bg_interval[roop_count] == -1) + share->monitoring_bg_interval[roop_count] = 10000000; +#endif + if (share->monitoring_limit[roop_count] == -1) + share->monitoring_limit[roop_count] = 1; + if (share->monitoring_sid[roop_count] == -1) +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + share->monitoring_sid[roop_count] = global_system_variables.server_id; +#else + share->monitoring_sid[roop_count] = current_thd->server_id; +#endif + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->use_hs_reads[roop_count] == -1) + share->use_hs_reads[roop_count] = 0; + if (share->use_hs_writes[roop_count] == -1) + share->use_hs_writes[roop_count] = 0; + if (share->hs_read_ports[roop_count] == -1) + { + share->hs_read_ports[roop_count] = 9998; + } else if (share->hs_read_ports[roop_count] < 0) + { + share->hs_read_ports[roop_count] = 0; + } else if (share->hs_read_ports[roop_count] > 65535) + { + share->hs_read_ports[roop_count] = 65535; + } + if (share->hs_write_ports[roop_count] == -1) + { + share->hs_write_ports[roop_count] = 9999; + } else if (share->hs_write_ports[roop_count] < 0) + { + share->hs_write_ports[roop_count] = 0; + } else if (share->hs_write_ports[roop_count] > 65535) + { + share->hs_write_ports[roop_count] = 65535; + } + if (share->hs_write_to_reads[roop_count] == -1) + { + share->hs_write_to_reads[roop_count] = 1; + } else if (share->hs_write_to_reads[roop_count] < 0) + { + share->hs_write_to_reads[roop_count] = 0; + } else if (share->hs_write_to_reads[roop_count] > 1) + { + share->hs_write_to_reads[roop_count] = 1; + } +#endif + if (share->use_handlers[roop_count] == -1) + share->use_handlers[roop_count] = 0; + if (share->connect_timeouts[roop_count] == -1) + share->connect_timeouts[roop_count] = 6; + if (share->net_read_timeouts[roop_count] == -1) + share->net_read_timeouts[roop_count] = 600; + if (share->net_write_timeouts[roop_count] == -1) + share->net_write_timeouts[roop_count] = 600; + if (share->access_balances[roop_count] == -1) + share->access_balances[roop_count] = 100; + } + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->sts_bg_mode == -1) + share->sts_bg_mode = 1; +#endif + if (share->sts_interval == -1) + share->sts_interval = 10; + if (share->sts_mode == -1) + share->sts_mode = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (share->sts_sync == -1) + share->sts_sync = 0; +#endif +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->crd_bg_mode == -1) + share->crd_bg_mode = 1; +#endif + if (share->crd_interval == -1) + share->crd_interval = 51; + if (share->crd_mode == -1) + share->crd_mode = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (share->crd_sync == -1) + share->crd_sync = 0; +#endif + if (share->crd_type == -1) + share->crd_type = 2; + if (share->crd_weight == -1) + share->crd_weight = 2; + if (share->internal_offset == -1) + share->internal_offset = 0; + if (share->internal_limit == -1) + share->internal_limit = 9223372036854775807LL; + if (share->split_read == -1) + share->split_read = 9223372036854775807LL; + if (share->semi_split_read == -1) + share->semi_split_read = 2; + if (share->semi_split_read_limit == -1) + share->semi_split_read_limit = 9223372036854775807LL; + if (share->init_sql_alloc_size == -1) + share->init_sql_alloc_size = 1024; + if (share->reset_sql_alloc == -1) + share->reset_sql_alloc = 1; + if (share->multi_split_read == -1) + share->multi_split_read = 100; + if (share->max_order == -1) + share->max_order = 32767; + if (share->semi_table_lock == -1) + share->semi_table_lock = 0; + if (share->semi_table_lock_conn == -1) + share->semi_table_lock_conn = 1; + if (share->selupd_lock_mode == -1) + share->selupd_lock_mode = 1; + if (share->query_cache == -1) + share->query_cache = 0; + if (share->internal_delayed == -1) + share->internal_delayed = 0; + if (share->bulk_size == -1) + share->bulk_size = 16000; + if (share->bulk_update_mode == -1) + share->bulk_update_mode = 0; + if (share->bulk_update_size == -1) + share->bulk_update_size = 16000; + if (share->internal_optimize == -1) + share->internal_optimize = 0; + if (share->internal_optimize_local == -1) + share->internal_optimize_local = 0; + if (share->scan_rate == -1) + share->scan_rate = 1; + if (share->read_rate == -1) + share->read_rate = 0.0002; + if (share->priority == -1) + share->priority = 1000000; + if (share->quick_mode == -1) + share->quick_mode = 0; + if (share->quick_page_size == -1) + share->quick_page_size = 100; + if (share->low_mem_read == -1) + share->low_mem_read = 1; + if (share->table_count_mode == -1) + share->table_count_mode = 0; + if (share->select_column_mode == -1) + share->select_column_mode = 1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (share->bgs_mode == -1) + share->bgs_mode = 0; + if (share->bgs_first_read == -1) + share->bgs_first_read = 2; + if (share->bgs_second_read == -1) + share->bgs_second_read = 100; +#endif + if (share->first_read == -1) + share->first_read = 0; + if (share->second_read == -1) + share->second_read = 0; + if (share->auto_increment_mode == -1) + share->auto_increment_mode = 0; + if (share->use_table_charset == -1) + share->use_table_charset = 1; + if (share->use_pushdown_udf == -1) + share->use_pushdown_udf = 1; + if (share->skip_default_condition == -1) + share->skip_default_condition = 0; + if (share->direct_dup_insert == -1) + share->direct_dup_insert = 0; + if (share->direct_order_limit == -1) + share->direct_order_limit = 9223372036854775807LL; + if (share->read_only_mode == -1) + share->read_only_mode = 0; + if (share->error_read_mode == -1) + share->error_read_mode = 0; + if (share->error_write_mode == -1) + share->error_write_mode = 0; + if (share->active_link_count == -1) + share->active_link_count = share->all_link_count; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (share->hs_result_free_size == -1) + share->hs_result_free_size = 1048576; +#endif +#ifdef HA_CAN_BULK_ACCESS + if (share->bulk_access_free == -1) + share->bulk_access_free = 0; +#endif + if (share->bka_mode == -1) + share->bka_mode = 1; + if (!share->bka_engine) + { + DBUG_PRINT("info",("spider create default bka_engine")); + share->bka_engine_length = SPIDER_SQL_TMP_BKA_ENGINE_LEN; + if ( + !(share->bka_engine = spider_create_string( + SPIDER_SQL_TMP_BKA_ENGINE_STR, + SPIDER_SQL_TMP_BKA_ENGINE_LEN)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + DBUG_RETURN(0); +} + +int spider_set_connect_info_default_db_table( + SPIDER_SHARE *share, + const char *db_name, + uint db_name_length, + const char *table_name, + uint table_name_length +) { + int roop_count; + DBUG_ENTER("spider_set_connect_info_default_db_table"); + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if (!share->tgt_dbs[roop_count] && db_name) + { + DBUG_PRINT("info",("spider create default tgt_dbs")); + share->tgt_dbs_lengths[roop_count] = db_name_length; + if ( + !(share->tgt_dbs[roop_count] = spider_create_string( + db_name, + db_name_length)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (!share->tgt_table_names[roop_count] && table_name) + { + const char *tmp_ptr; + DBUG_PRINT("info",("spider create default tgt_table_names")); + if ((tmp_ptr = strstr(table_name, "#P#"))) + table_name_length = (uint) PTR_BYTE_DIFF(tmp_ptr, table_name); + share->tgt_table_names_lengths[roop_count] = table_name_length; + if ( + !(share->tgt_table_names[roop_count] = spider_create_string( + table_name, + table_name_length)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } + DBUG_RETURN(0); +} + +int spider_set_connect_info_default_dbtable( + SPIDER_SHARE *share, + const char *dbtable_name, + int dbtable_name_length +) { + const char *ptr_db, *ptr_table; + my_ptrdiff_t ptr_diff_db, ptr_diff_table; + DBUG_ENTER("spider_set_connect_info_default_dbtable"); + ptr_db = strchr(dbtable_name, FN_LIBCHAR); + ptr_db++; + ptr_diff_db = PTR_BYTE_DIFF(ptr_db, dbtable_name); + DBUG_PRINT("info",("spider ptr_diff_db = %lld", (longlong) ptr_diff_db)); + ptr_table = strchr(ptr_db, FN_LIBCHAR); + ptr_table++; + ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db); + DBUG_PRINT("info",("spider ptr_diff_table = %lld", (longlong) ptr_diff_table)); + DBUG_RETURN(spider_set_connect_info_default_db_table( + share, + ptr_db, + (uint)(ptr_diff_table - 1), + ptr_table, + (uint)(dbtable_name_length - ptr_diff_db - ptr_diff_table) + )); +} + +#ifndef DBUG_OFF +void spider_print_keys( + const char *key, + uint length +) { + const char *end_ptr; + uint roop_count = 1; + DBUG_ENTER("spider_print_keys"); + DBUG_PRINT("info",("spider key_length=%u", length)); + end_ptr = key + length; + while (key < end_ptr) + { + DBUG_PRINT("info",("spider key[%u]=%s", roop_count, key)); + key = strchr(key, '\0') + 1; + roop_count++; + } + DBUG_VOID_RETURN; +} +#endif + +int spider_create_conn_keys( + SPIDER_SHARE *share +) { + int roop_count, roop_count2; + char *tmp_name, port_str[6]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char *tmp_hs_r_name, *tmp_hs_w_name; +#endif +#ifdef _MSC_VER + uint *conn_keys_lengths; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint *hs_r_conn_keys_lengths; + uint *hs_w_conn_keys_lengths; +#endif +#else + uint conn_keys_lengths[share->all_link_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + uint hs_r_conn_keys_lengths[share->all_link_count]; + uint hs_w_conn_keys_lengths[share->all_link_count]; +#endif +#endif + DBUG_ENTER("spider_create_conn_keys"); +#ifdef _MSC_VER + if (!(conn_keys_lengths = + (uint *) spider_bulk_alloc_mem(spider_current_trx, 44, + __func__, __FILE__, __LINE__, MYF(MY_WME), + &conn_keys_lengths, sizeof(uint) * share->all_link_count, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &hs_r_conn_keys_lengths, sizeof(uint) * share->all_link_count, + &hs_w_conn_keys_lengths, sizeof(uint) * share->all_link_count, +#endif + NullS))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); +#endif + + share->conn_keys_charlen = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + share->hs_read_conn_keys_charlen = 0; + share->hs_write_conn_keys_charlen = 0; +#endif + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + /* tgt_db not use */ + conn_keys_lengths[roop_count] + = 1 + + share->tgt_wrappers_lengths[roop_count] + 1 + + share->tgt_hosts_lengths[roop_count] + 1 + + 5 + 1 + + share->tgt_sockets_lengths[roop_count] + 1 + + share->tgt_usernames_lengths[roop_count] + 1 + + share->tgt_passwords_lengths[roop_count] + 1 + + share->tgt_ssl_cas_lengths[roop_count] + 1 + + share->tgt_ssl_capaths_lengths[roop_count] + 1 + + share->tgt_ssl_certs_lengths[roop_count] + 1 + + share->tgt_ssl_ciphers_lengths[roop_count] + 1 + + share->tgt_ssl_keys_lengths[roop_count] + 1 + + 1 + 1 + + share->tgt_default_files_lengths[roop_count] + 1 + + share->tgt_default_groups_lengths[roop_count]; + share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + hs_r_conn_keys_lengths[roop_count] + = 1 + + share->tgt_wrappers_lengths[roop_count] + 1 + + share->tgt_hosts_lengths[roop_count] + 1 + + 5 + 1 + + share->hs_read_socks_lengths[roop_count]; + share->hs_read_conn_keys_charlen += + hs_r_conn_keys_lengths[roop_count] + 2; + hs_w_conn_keys_lengths[roop_count] + = 1 + + share->tgt_wrappers_lengths[roop_count] + 1 + + share->tgt_hosts_lengths[roop_count] + 1 + + 5 + 1 + + share->hs_write_socks_lengths[roop_count]; + share->hs_write_conn_keys_charlen += + hs_w_conn_keys_lengths[roop_count] + 2; +#endif + } + if (!(share->conn_keys = (char **) + spider_bulk_alloc_mem(spider_current_trx, 45, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &share->conn_keys, sizeof(char *) * share->all_link_count, + &share->conn_keys_lengths, sizeof(uint) * share->all_link_count, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + &share->conn_keys_hash_value, + sizeof(my_hash_value_type) * share->all_link_count, +#endif + &tmp_name, sizeof(char) * share->conn_keys_charlen, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &share->hs_read_conn_keys, sizeof(char *) * share->all_link_count, + &share->hs_read_conn_keys_lengths, sizeof(uint) * share->all_link_count, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + &share->hs_read_conn_keys_hash_value, + sizeof(my_hash_value_type) * share->all_link_count, +#endif + &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, + &share->hs_write_conn_keys, sizeof(char *) * share->all_link_count, + &share->hs_write_conn_keys_lengths, sizeof(uint) * share->all_link_count, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + &share->hs_write_conn_keys_hash_value, + sizeof(my_hash_value_type) * share->all_link_count, +#endif + &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, +#endif + &share->sql_dbton_ids, sizeof(uint) * share->all_link_count, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &share->hs_dbton_ids, sizeof(uint) * share->all_link_count, +#endif + NullS)) + ) { +#ifdef _MSC_VER + spider_free(spider_current_trx, conn_keys_lengths, MYF(MY_WME)); +#endif + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + share->conn_keys_length = share->all_link_count; + memcpy(share->conn_keys_lengths, conn_keys_lengths, + sizeof(uint) * share->all_link_count); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + share->hs_read_conn_keys_length = share->all_link_count; + share->hs_write_conn_keys_length = share->all_link_count; + memcpy(share->hs_read_conn_keys_lengths, hs_r_conn_keys_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share->hs_write_conn_keys_lengths, hs_w_conn_keys_lengths, + sizeof(uint) * share->all_link_count); +#endif + +#ifdef _MSC_VER + spider_free(spider_current_trx, conn_keys_lengths, MYF(MY_WME)); +#endif + + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + share->conn_keys[roop_count] = tmp_name; + *tmp_name = '0'; + DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count, + share->tgt_wrappers[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_wrappers[roop_count]); + DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count, + share->tgt_hosts[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_hosts[roop_count]); + my_sprintf(port_str, (port_str, "%05ld", share->tgt_ports[roop_count])); + DBUG_PRINT("info",("spider port_str=%s", port_str)); + tmp_name = strmov(tmp_name + 1, port_str); + if (share->tgt_sockets[roop_count]) + { + DBUG_PRINT("info",("spider tgt_sockets[%d]=%s", roop_count, + share->tgt_sockets[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_sockets[roop_count]); + } else + tmp_name++; + if (share->tgt_usernames[roop_count]) + { + DBUG_PRINT("info",("spider tgt_usernames[%d]=%s", roop_count, + share->tgt_usernames[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_usernames[roop_count]); + } else + tmp_name++; + if (share->tgt_passwords[roop_count]) + { + DBUG_PRINT("info",("spider tgt_passwords[%d]=%s", roop_count, + share->tgt_passwords[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_passwords[roop_count]); + } else + tmp_name++; + if (share->tgt_ssl_cas[roop_count]) + { + DBUG_PRINT("info",("spider tgt_ssl_cas[%d]=%s", roop_count, + share->tgt_ssl_cas[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_ssl_cas[roop_count]); + } else + tmp_name++; + if (share->tgt_ssl_capaths[roop_count]) + { + DBUG_PRINT("info",("spider tgt_ssl_capaths[%d]=%s", roop_count, + share->tgt_ssl_capaths[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_ssl_capaths[roop_count]); + } else + tmp_name++; + if (share->tgt_ssl_certs[roop_count]) + { + DBUG_PRINT("info",("spider tgt_ssl_certs[%d]=%s", roop_count, + share->tgt_ssl_certs[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_ssl_certs[roop_count]); + } else + tmp_name++; + if (share->tgt_ssl_ciphers[roop_count]) + { + DBUG_PRINT("info",("spider tgt_ssl_ciphers[%d]=%s", roop_count, + share->tgt_ssl_ciphers[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_ssl_ciphers[roop_count]); + } else + tmp_name++; + if (share->tgt_ssl_keys[roop_count]) + { + DBUG_PRINT("info",("spider tgt_ssl_keys[%d]=%s", roop_count, + share->tgt_ssl_keys[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_ssl_keys[roop_count]); + } else + tmp_name++; + tmp_name++; + *tmp_name = '0' + ((char) share->tgt_ssl_vscs[roop_count]); + if (share->tgt_default_files[roop_count]) + { + DBUG_PRINT("info",("spider tgt_default_files[%d]=%s", roop_count, + share->tgt_default_files[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_default_files[roop_count]); + } else + tmp_name++; + if (share->tgt_default_groups[roop_count]) + { + DBUG_PRINT("info",("spider tgt_default_groups[%d]=%s", roop_count, + share->tgt_default_groups[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_default_groups[roop_count]); + } else + tmp_name++; + tmp_name++; + tmp_name++; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + share->conn_keys_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) share->conn_keys[roop_count], + share->conn_keys_lengths[roop_count]); +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + share->hs_read_conn_keys[roop_count] = tmp_hs_r_name; + *tmp_hs_r_name = '0'; + DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count, + share->tgt_wrappers[roop_count])); + tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_wrappers[roop_count]); + DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count, + share->tgt_hosts[roop_count])); + tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_hosts[roop_count]); + my_sprintf(port_str, (port_str, "%05ld", + share->hs_read_ports[roop_count])); + DBUG_PRINT("info",("spider port_str=%s", port_str)); + tmp_hs_r_name = strmov(tmp_hs_r_name + 1, port_str); + if (share->hs_read_socks[roop_count]) + { + DBUG_PRINT("info",("spider hs_read_socks[%d]=%s", roop_count, + share->hs_read_socks[roop_count])); + tmp_hs_r_name = strmov(tmp_hs_r_name + 1, + share->hs_read_socks[roop_count]); + } else + tmp_hs_r_name++; + tmp_hs_r_name++; + tmp_hs_r_name++; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + share->hs_read_conn_keys_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) share->hs_read_conn_keys[roop_count], + share->hs_read_conn_keys_lengths[roop_count]); +#endif + share->hs_write_conn_keys[roop_count] = tmp_hs_w_name; + *tmp_hs_w_name = '0'; + DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count, + share->tgt_wrappers[roop_count])); + tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_wrappers[roop_count]); + DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count, + share->tgt_hosts[roop_count])); + tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_hosts[roop_count]); + my_sprintf(port_str, (port_str, "%05ld", + share->hs_write_ports[roop_count])); + DBUG_PRINT("info",("spider port_str=%s", port_str)); + tmp_hs_w_name = strmov(tmp_hs_w_name + 1, port_str); + if (share->hs_write_socks[roop_count]) + { + DBUG_PRINT("info",("spider hs_write_socks[%d]=%s", roop_count, + share->hs_write_socks[roop_count])); + tmp_hs_w_name = strmov(tmp_hs_w_name + 1, + share->hs_write_socks[roop_count]); + } else + tmp_hs_w_name++; + tmp_hs_w_name++; + tmp_hs_w_name++; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + share->hs_write_conn_keys_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) share->hs_write_conn_keys[roop_count], + share->hs_write_conn_keys_lengths[roop_count]); +#endif +#endif + + bool get_sql_id = FALSE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + bool get_nosql_id = FALSE; +#endif + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) + { + DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count, + share->tgt_wrappers[roop_count])); + DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2, + spider_dbton[roop_count2].wrapper ? + spider_dbton[roop_count2].wrapper : "NULL")); + if ( + spider_dbton[roop_count2].wrapper && + !strcmp(share->tgt_wrappers[roop_count], + spider_dbton[roop_count2].wrapper) + ) { + spider_set_bit(share->dbton_bitmap, roop_count2); + if ( + !get_sql_id && + spider_dbton[roop_count2].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL + ) { + share->sql_dbton_ids[roop_count] = roop_count2; + get_sql_id = TRUE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (get_nosql_id) +#endif + break; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + else + continue; +#endif + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + !get_nosql_id && + spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_NOSQL + ) { + share->hs_dbton_ids[roop_count] = roop_count2; + get_nosql_id = TRUE; + if (get_sql_id) + break; + } +#endif + } + } + if (!get_sql_id) + share->sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!get_nosql_id) + share->hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE; +#endif + } + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) + { + if (spider_bit_is_set(share->dbton_bitmap, roop_count2)) + { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { +#endif + share->use_sql_dbton_ids[share->use_dbton_count] = roop_count2; + share->sql_dbton_id_to_seq[roop_count2] = share->use_dbton_count; + share->use_sql_dbton_count++; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else { + share->use_hs_dbton_ids[share->use_hs_dbton_count] = roop_count2; + share->hs_dbton_id_to_seq[roop_count2] = share->use_hs_dbton_count; + share->use_hs_dbton_count++; + } +#endif + share->use_dbton_ids[share->use_dbton_count] = roop_count2; + share->dbton_id_to_seq[roop_count2] = share->use_dbton_count; + share->use_dbton_count++; + } + } + DBUG_RETURN(0); +} + +SPIDER_SHARE *spider_create_share( + const char *table_name, + TABLE_SHARE *table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info, +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value, +#endif + int *error_num +) { + int bitmap_size, roop_count; + uint length; + int use_table_charset; + SPIDER_SHARE *share; + char *tmp_name; + longlong *tmp_cardinality; + uchar *tmp_cardinality_upd; + DBUG_ENTER("spider_create_share"); + length = (uint) strlen(table_name); + bitmap_size = spider_bitmap_size(table_share->fields); + if (!(share = (SPIDER_SHARE *) + spider_bulk_malloc(spider_current_trx, 46, MYF(MY_WME | MY_ZEROFILL), + &share, sizeof(*share), + &tmp_name, length + 1, + &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields, + &tmp_cardinality_upd, sizeof(*tmp_cardinality_upd) * bitmap_size, + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_share; + } + + share->use_count = 0; + share->use_dbton_count = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + share->use_hs_dbton_count = 0; +#endif + share->table_name_length = length; + share->table_name = tmp_name; + strmov(share->table_name, table_name); + share->cardinality = tmp_cardinality; + share->cardinality_upd = tmp_cardinality_upd; + share->bitmap_size = bitmap_size; + share->table_share = table_share; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + share->table_name_hash_value = hash_value; +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->table_path_hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_share->path.str, table_share->path.length); +#endif +#endif + + if (table_share->keys > 0 && + !(share->key_hint = new spider_string[table_share->keys]) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_hint_string; + } + for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++) + share->key_hint[roop_count].init_calc_mem(95); + DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint)); + + if ((*error_num = spider_parse_connect_info(share, table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + part_info, +#endif + 0))) + goto error_parse_connect_string; + + use_table_charset = spider_param_use_table_charset( + share->use_table_charset); + if (use_table_charset) + share->access_charset = table_share->table_charset; + else + share->access_charset = system_charset_info; + + if ((*error_num = spider_create_conn_keys(share))) + goto error_create_conn_keys; + + if (share->table_count_mode) + share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT; + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_share, + &share->mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_mutex; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_share_sts, + &share->sts_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_sts_mutex; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_share_crd, + &share->crd_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_crd_mutex; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_share_auto_increment, + &share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_auto_increment_mutex; + } + + thr_lock_init(&share->lock); + +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (!(share->partition_share = + spider_get_pt_share(share, table_share, error_num))) + goto error_get_pt_share; +#endif + + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + if (spider_bit_is_set(share->dbton_bitmap, roop_count)) + { + if (!(share->dbton_share[roop_count] = + spider_dbton[roop_count].create_db_share(share))) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_dbton; + } + if ((*error_num = share->dbton_share[roop_count]->init())) + { + goto error_init_dbton; + } + } + } + DBUG_RETURN(share); + +/* + roop_count = SPIDER_DBTON_SIZE - 1; +*/ +error_init_dbton: + for (; roop_count >= 0; roop_count--) + { + if (share->dbton_share[roop_count]) + { + delete share->dbton_share[roop_count]; + share->dbton_share[roop_count] = NULL; + } + } +#ifdef WITH_PARTITION_STORAGE_ENGINE +error_get_pt_share: +#endif + thr_lock_delete(&share->lock); + pthread_mutex_destroy(&share->auto_increment_mutex); +error_init_auto_increment_mutex: + pthread_mutex_destroy(&share->crd_mutex); +error_init_crd_mutex: + pthread_mutex_destroy(&share->sts_mutex); +error_init_sts_mutex: + pthread_mutex_destroy(&share->mutex); +error_init_mutex: +error_create_conn_keys: +error_parse_connect_string: +error_init_hint_string: + spider_free_share_alloc(share); + spider_free(spider_current_trx, share, MYF(0)); +error_alloc_share: + DBUG_RETURN(NULL); +} + +SPIDER_SHARE *spider_get_share( + const char *table_name, + TABLE *table, + THD *thd, + ha_spider *spider, + int *error_num +) { + SPIDER_SHARE *share; + TABLE_SHARE *table_share = table->s; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + uint length, tmp_conn_link_idx = 0; + char *tmp_name, *tmp_cid; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + char *tmp_hs_r_name, *tmp_hs_w_name; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + uint32 *tmp_hs_r_ret_fields, *tmp_hs_w_ret_fields; +#endif +#endif + int roop_count; + double sts_interval; + int sts_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + int sts_sync; + int auto_increment_mode; +#endif + double crd_interval; + int crd_mode; +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync; +#endif + char first_byte; + int semi_table_lock_conn; + int search_link_idx; + uint sql_command = thd_sql_command(thd); +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + MEM_ROOT mem_root; + TABLE *table_tables = NULL; + bool init_mem_root = FALSE; + DBUG_ENTER("spider_get_share"); + + length = (uint) strlen(table_name); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_name, length); +#endif + pthread_mutex_lock(&spider_tbl_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(share = (SPIDER_SHARE*) my_hash_search_using_hash_value( + &spider_open_tables, hash_value, (uchar*) table_name, length))) +#else + if (!(share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables, + (uchar*) table_name, length))) +#endif + { + if (!(share = spider_create_share( + table_name, table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + table->part_info, +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value, +#endif + error_num + ))) { + goto error_alloc_share; + } + + uint old_elements = spider_open_tables.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_open_tables, hash_value, + (uchar*) share)) +#else + if (my_hash_insert(&spider_open_tables, (uchar*) share)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_hash_insert; + } + if (spider_open_tables.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_open_tables, + (spider_open_tables.array.max_element - old_elements) * + spider_open_tables.array.size_of_element); + } + + spider->share = share; + spider->conn_link_idx = &tmp_conn_link_idx; + + share->use_count++; + pthread_mutex_unlock(&spider_tbl_mutex); + + if (!share->link_status_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->link_status_init) + { + if ( + table_share->tmp_table == NO_TMP_TABLE && + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE + ) { + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + init_mem_root = TRUE; + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, + FALSE, error_num)) + ) { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_open_sys_table; + } + *error_num = spider_get_link_statuses(table_tables, share, + &mem_root); + if (*error_num) + { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_get_link_statuses; + } + } + share->have_recovery_link = spider_conn_check_recovery_link(share); + if (table_tables) + { + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } + if (init_mem_root) + { + free_root(&mem_root, MYF(0)); + init_mem_root = FALSE; + } + } + pthread_mutex_unlock(&share->mutex); + } + + semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, + share->semi_table_lock_conn); + if (semi_table_lock_conn) + first_byte = '0' + + spider_param_semi_table_lock(thd, share->semi_table_lock); + else + first_byte = '0'; + + if (!(spider->trx = spider_get_trx(thd, TRUE, error_num))) + { + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } + spider->set_error_mode(); + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + (*error_num = spider_create_mon_threads(spider->trx, share)) + ) { + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } +#endif + + if (!(spider->conn_keys = (char **) + spider_bulk_alloc_mem(spider_current_trx, 47, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &spider->conn_keys, sizeof(char *) * share->link_count, + &tmp_name, sizeof(char) * share->conn_keys_charlen, + &spider->conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->conn_link_idx, sizeof(uint) * share->link_count, + &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &spider->hs_r_conn_keys, sizeof(char *) * share->link_count, + &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, + &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count, + &spider->hs_w_conn_keys, sizeof(char *) * share->link_count, + &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, + &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count, +#endif + &spider->sql_kind, sizeof(uint) * share->link_count, + &spider->connection_ids, sizeof(ulonglong) * share->link_count, + &spider->conn_kind, sizeof(uint) * share->link_count, + &spider->db_request_id, sizeof(ulonglong) * share->link_count, + &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size, + &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->m_handler_id, sizeof(uint) * share->link_count, + &spider->m_handler_cid, sizeof(char *) * share->link_count, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->r_handler_id, sizeof(uint) * share->link_count, + &spider->r_handler_index, sizeof(uint) * share->link_count, + &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->w_handler_id, sizeof(uint) * share->link_count, + &spider->w_handler_index, sizeof(uint) * share->link_count, +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size, + &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count, + &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count, + &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count, + &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count, + &tmp_hs_r_ret_fields, + sizeof(uint32) * share->link_count * table_share->fields, + &tmp_hs_w_ret_fields, + sizeof(uint32) * share->link_count * table_share->fields, + &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size, +#endif +#endif + &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) * + share->link_count, + &spider->need_mons, sizeof(int) * share->link_count, + &spider->quick_targets, sizeof(void *) * share->link_count, + &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count, + &result_list->upd_tmp_tbl_prms, + sizeof(TMP_TABLE_PARAM) * share->link_count, + &result_list->tmp_table_join_first, + sizeof(uchar) * share->link_bitmap_size, + &result_list->tmp_table_created, + sizeof(uchar) * share->link_bitmap_size, +#ifdef HA_CAN_BULK_ACCESS + &result_list->hs_r_bulk_open_index, + sizeof(uchar) * share->link_bitmap_size, + &result_list->hs_w_bulk_open_index, + sizeof(uchar) * share->link_bitmap_size, +#endif + &result_list->sql_kind_backup, sizeof(uint) * share->link_count, + &spider->dbton_handler, + sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) { + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } + memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0], + share->hs_read_conn_keys_charlen); + memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0], + share->hs_write_conn_keys_charlen); +#endif + + spider->conn_keys_first_ptr = tmp_name; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + spider->conn_keys[roop_count] = tmp_name; + *tmp_name = first_byte; + tmp_name += share->conn_keys_lengths[roop_count] + 1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name; + tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1; + spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name; + tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields; + tmp_hs_r_ret_fields += table_share->fields; + spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields; + tmp_hs_w_ret_fields += table_share->fields; +#endif +#endif + spider->m_handler_cid[roop_count] = tmp_cid; + tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1; + result_list->upd_tmp_tbl_prms[roop_count].init(); + result_list->upd_tmp_tbl_prms[roop_count].field_count = 1; + spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + spider_trx_set_link_idx_for_all(spider); + + for (roop_count = 0; roop_count < (int) share->use_dbton_count; + roop_count++) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if (!(spider->dbton_handler[dbton_id] = + spider_dbton[dbton_id].create_db_handler(spider, + share->dbton_share[dbton_id]))) + { + *error_num = HA_ERR_OUT_OF_MEM; + break; + } + if ((*error_num = spider->dbton_handler[dbton_id]->init())) + { + break; + } + } + if (roop_count < (int) share->use_dbton_count) + { + for (; roop_count >= 0; roop_count--) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if (spider->dbton_handler[dbton_id]) + { + delete spider->dbton_handler[dbton_id]; + spider->dbton_handler[dbton_id] = NULL; + } + } + goto error_but_no_delete; + } + + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ( + !(spider->conns[roop_count] = + spider_get_conn(share, roop_count, spider->conn_keys[roop_count], + spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, + error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + *error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + FALSE + ); + } + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } + spider->conns[roop_count]->error_mode &= spider->error_mode; + } + } + search_link_idx = spider_conn_first_link_idx(thd, + share->link_statuses, share->access_balances, spider->conn_link_idx, + share->link_count, SPIDER_LINK_STATUS_OK); + if (search_link_idx == -1) + { +#ifdef _MSC_VER + char *db, *table_name; + if (!(db = (char *) + spider_bulk_malloc(spider_current_trx, 48, MYF(MY_WME), + &db, table_share->db.length + 1, + &table_name, table_share->table_name.length + 1, + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } +#else + char db[table_share->db.length + 1], + table_name[table_share->table_name.length + 1]; +#endif + memcpy(db, table_share->db.str, table_share->db.length); + db[table_share->db.length] = '\0'; + memcpy(table_name, table_share->table_name.str, + table_share->table_name.length); + table_name[table_share->table_name.length] = '\0'; + my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM, + ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name); +#ifdef _MSC_VER + spider_free(spider->trx, db, MYF(MY_WME)); +#endif + *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM; + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } + spider->search_link_idx = search_link_idx; + + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + !spider->error_mode && + !spider_param_same_server_link(thd) + ) { + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + sts_interval = spider_param_sts_interval(thd, share->sts_interval); + sts_mode = spider_param_sts_mode(thd, share->sts_mode); +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync = spider_param_sts_sync(thd, share->sts_sync); + auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + if (auto_increment_mode == 1) + sts_sync = 0; +#endif + crd_interval = spider_param_crd_interval(thd, share->crd_interval); + crd_mode = spider_param_crd_mode(thd, share->crd_mode); + if (crd_mode == 3) + crd_mode = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync = spider_param_crd_sync(thd, share->crd_sync); +#endif + time_t tmp_time = (time_t) time((time_t*) 0); + pthread_mutex_lock(&share->sts_mutex); + pthread_mutex_lock(&share->crd_mutex); + if ((spider_init_error_table = + spider_get_init_error_table(spider->trx, share, FALSE))) + { + DBUG_PRINT("info",("spider diff1=%f", + difftime(tmp_time, spider_init_error_table->init_error_time))); + if (difftime(tmp_time, + spider_init_error_table->init_error_time) < + spider_param_table_init_error_interval()) + { + *error_num = spider_init_error_table->init_error; + if (spider_init_error_table->init_error_with_message) + my_message(spider_init_error_table->init_error, + spider_init_error_table->init_error_msg, MYF(0)); + share->init_error = TRUE; + share->init = TRUE; + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + spider_free_share(share); + goto error_but_no_delete; + } + } + + spider_get_sts(share, spider->search_link_idx, tmp_time, + spider, sts_interval, sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync, +#endif + 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO); + spider_get_crd(share, spider->search_link_idx, tmp_time, + spider, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + 1); +/* + if ( + (*error_num = spider_get_sts(share, spider->search_link_idx, tmp_time, + spider, sts_interval, sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync, +#endif + 1)) || + (*error_num = spider_get_crd(share, spider->search_link_idx, tmp_time, + spider, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + 1)) + ) { + if ( + share->monitoring_kind[spider->search_link_idx] && + spider->need_mons[spider->search_link_idx] + ) { + *error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + share->monitoring_sid[spider->search_link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[spider->search_link_idx], + NULL, + 0, + share->monitoring_kind[spider->search_link_idx], + share->monitoring_limit[spider->search_link_idx], + FALSE + ); + } + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(spider->trx, share, TRUE)) + ) { + spider_init_error_table->init_error = *error_num; + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(spider_init_error_table->init_error_msg, + thd->main_da.message()); +#else + strmov(spider_init_error_table->init_error_msg, + thd->stmt_da->message()); +#endif + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + spider_free_share(share); + goto error_but_no_delete; + } +*/ + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + } + + share->init = TRUE; + } else { + share->use_count++; + pthread_mutex_unlock(&spider_tbl_mutex); + + while (!share->init) + { + my_sleep(10); + } + + if (!share->link_status_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->link_status_init) + { + if ( + table_share->tmp_table == NO_TMP_TABLE && + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE + ) { + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + init_mem_root = TRUE; + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, + FALSE, error_num)) + ) { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_open_sys_table; + } + *error_num = spider_get_link_statuses(table_tables, share, + &mem_root); + if (*error_num) + { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_get_link_statuses; + } + } + share->have_recovery_link = spider_conn_check_recovery_link(share); + if (table_tables) + { + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } + if (init_mem_root) + { + free_root(&mem_root, MYF(0)); + init_mem_root = FALSE; + } + } + pthread_mutex_unlock(&share->mutex); + } + + semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, + share->semi_table_lock_conn); + if (semi_table_lock_conn) + first_byte = '0' + + spider_param_semi_table_lock(thd, share->semi_table_lock); + else + first_byte = '0'; + + spider->share = share; + if (!(spider->trx = spider_get_trx(thd, TRUE, error_num))) + { + spider_free_share(share); + goto error_but_no_delete; + } + spider->set_error_mode(); + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + (*error_num = spider_create_mon_threads(spider->trx, share)) + ) { + spider_free_share(share); + goto error_but_no_delete; + } +#endif + + if (!(spider->conn_keys = (char **) + spider_bulk_alloc_mem(spider_current_trx, 49, + __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), + &spider->conn_keys, sizeof(char *) * share->link_count, + &tmp_name, sizeof(char) * share->conn_keys_charlen, + &spider->conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->conn_link_idx, sizeof(uint) * share->link_count, + &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &spider->hs_r_conn_keys, sizeof(char *) * share->link_count, + &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, + &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count, + &spider->hs_w_conn_keys, sizeof(char *) * share->link_count, + &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, + &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count, + &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count, +#endif + &spider->sql_kind, sizeof(uint) * share->link_count, + &spider->connection_ids, sizeof(ulonglong) * share->link_count, + &spider->conn_kind, sizeof(uint) * share->link_count, + &spider->db_request_id, sizeof(ulonglong) * share->link_count, + &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size, + &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->m_handler_id, sizeof(uint) * share->link_count, + &spider->m_handler_cid, sizeof(char *) * share->link_count, +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->r_handler_id, sizeof(uint) * share->link_count, + &spider->r_handler_index, sizeof(uint) * share->link_count, + &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size, + &spider->w_handler_id, sizeof(uint) * share->link_count, + &spider->w_handler_index, sizeof(uint) * share->link_count, +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size, + &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count, + &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count, + &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count, + &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count, + &tmp_hs_r_ret_fields, + sizeof(uint32) * share->link_count * table_share->fields, + &tmp_hs_w_ret_fields, + sizeof(uint32) * share->link_count * table_share->fields, + &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size, +#endif +#endif + &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) * + share->link_count, + &spider->need_mons, sizeof(int) * share->link_count, + &spider->quick_targets, sizeof(void *) * share->link_count, + &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count, + &result_list->upd_tmp_tbl_prms, + sizeof(TMP_TABLE_PARAM) * share->link_count, + &result_list->tmp_table_join_first, + sizeof(uchar) * share->link_bitmap_size, + &result_list->tmp_table_created, + sizeof(uchar) * share->link_bitmap_size, +#ifdef HA_CAN_BULK_ACCESS + &result_list->hs_r_bulk_open_index, + sizeof(uchar) * share->link_bitmap_size, + &result_list->hs_w_bulk_open_index, + sizeof(uchar) * share->link_bitmap_size, +#endif + &result_list->sql_kind_backup, sizeof(uint) * share->link_count, + &spider->dbton_handler, + sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, + NullS)) + ) { + spider_free_share(share); + goto error_but_no_delete; + } + memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0], + share->hs_read_conn_keys_charlen); + memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0], + share->hs_write_conn_keys_charlen); +#endif + + spider->conn_keys_first_ptr = tmp_name; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + spider->conn_keys[roop_count] = tmp_name; + *tmp_name = first_byte; + tmp_name += share->conn_keys_lengths[roop_count] + 1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name; + tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1; + spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name; + tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1; +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields; + tmp_hs_r_ret_fields += table_share->fields; + spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields; + tmp_hs_w_ret_fields += table_share->fields; +#endif +#endif + spider->m_handler_cid[roop_count] = tmp_cid; + tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1; + result_list->upd_tmp_tbl_prms[roop_count].init(); + result_list->upd_tmp_tbl_prms[roop_count].field_count = 1; + spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + spider_trx_set_link_idx_for_all(spider); + + for (roop_count = 0; roop_count < (int) share->use_dbton_count; + roop_count++) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if (!(spider->dbton_handler[dbton_id] = + spider_dbton[dbton_id].create_db_handler(spider, + share->dbton_share[dbton_id]))) + { + *error_num = HA_ERR_OUT_OF_MEM; + break; + } + if ((*error_num = spider->dbton_handler[dbton_id]->init())) + { + break; + } + } + if (roop_count < (int) share->use_dbton_count) + { + for (; roop_count >= 0; roop_count--) + { + uint dbton_id = share->use_dbton_ids[roop_count]; + if (spider->dbton_handler[dbton_id]) + { + delete spider->dbton_handler[dbton_id]; + spider->dbton_handler[dbton_id] = NULL; + } + } + goto error_but_no_delete; + } + + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE + ) { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + if ( + !(spider->conns[roop_count] = + spider_get_conn(share, roop_count, spider->conn_keys[roop_count], + spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, + error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + *error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + FALSE + ); + } + spider_free_share(share); + goto error_but_no_delete; + } + spider->conns[roop_count]->error_mode &= spider->error_mode; + } + } + search_link_idx = spider_conn_first_link_idx(thd, + share->link_statuses, share->access_balances, spider->conn_link_idx, + share->link_count, SPIDER_LINK_STATUS_OK); + if (search_link_idx == -1) + { +#ifdef _MSC_VER + char *db, *table_name; + if (!(db = (char *) + spider_bulk_malloc(spider_current_trx, 50, MYF(MY_WME), + &db, table_share->db.length + 1, + &table_name, table_share->table_name.length + 1, + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + spider_free_share(share); + goto error_but_no_delete; + } +#else + char db[table_share->db.length + 1], + table_name[table_share->table_name.length + 1]; +#endif + memcpy(db, table_share->db.str, table_share->db.length); + db[table_share->db.length] = '\0'; + memcpy(table_name, table_share->table_name.str, + table_share->table_name.length); + table_name[table_share->table_name.length] = '\0'; + my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM, + ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name); +#ifdef _MSC_VER + spider_free(spider->trx, db, MYF(MY_WME)); +#endif + *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM; + spider_free_share(share); + goto error_but_no_delete; + } + spider->search_link_idx = search_link_idx; + + if (share->init_error) + { + pthread_mutex_lock(&share->sts_mutex); + pthread_mutex_lock(&share->crd_mutex); + if (share->init_error) + { + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + !spider->error_mode && + !spider_param_same_server_link(thd) + ) { + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + sts_interval = spider_param_sts_interval(thd, share->sts_interval); + sts_mode = spider_param_sts_mode(thd, share->sts_mode); +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync = spider_param_sts_sync(thd, share->sts_sync); + auto_increment_mode = spider_param_auto_increment_mode(thd, + share->auto_increment_mode); + if (auto_increment_mode == 1) + sts_sync = 0; +#endif + crd_interval = spider_param_crd_interval(thd, share->crd_interval); + crd_mode = spider_param_crd_mode(thd, share->crd_mode); + if (crd_mode == 3) + crd_mode = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync = spider_param_crd_sync(thd, share->crd_sync); +#endif + time_t tmp_time = (time_t) time((time_t*) 0); + if ((spider_init_error_table = + spider_get_init_error_table(spider->trx, share, FALSE))) + { + DBUG_PRINT("info",("spider diff2=%f", + difftime(tmp_time, spider_init_error_table->init_error_time))); + if (difftime(tmp_time, + spider_init_error_table->init_error_time) < + spider_param_table_init_error_interval()) + { + *error_num = spider_init_error_table->init_error; + if (spider_init_error_table->init_error_with_message) + my_message(spider_init_error_table->init_error, + spider_init_error_table->init_error_msg, MYF(0)); + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + spider_free_share(share); + goto error_but_no_delete; + } + } + + spider_get_sts(share, spider->search_link_idx, + tmp_time, spider, sts_interval, sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync, +#endif + 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO); + spider_get_crd(share, spider->search_link_idx, + tmp_time, spider, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + 1); +/* + if ( + (*error_num = spider_get_sts(share, spider->search_link_idx, + tmp_time, spider, sts_interval, sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + sts_sync, +#endif + 1)) || + (*error_num = spider_get_crd(share, spider->search_link_idx, + tmp_time, spider, table, crd_interval, crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + crd_sync, +#endif + 1)) + ) { + if ( + share->monitoring_kind[spider->search_link_idx] && + spider->need_mons[spider->search_link_idx] + ) { + *error_num = spider_ping_table_mon_from_table( + spider->trx, + spider->trx->thd, + share, + share->monitoring_sid[spider->search_link_idx], + share->table_name, + share->table_name_length, + spider->conn_link_idx[spider->search_link_idx], + NULL, + 0, + share->monitoring_kind[spider->search_link_idx], + share->monitoring_limit[spider->search_link_idx], + FALSE + ); + } + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(spider->trx, share, TRUE)) + ) { + spider_init_error_table->init_error = *error_num; + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) +#if MYSQL_VERSION_ID < 50500 + strmov(spider_init_error_table->init_error_msg, + thd->main_da.message()); +#else + strmov(spider_init_error_table->init_error_msg, + thd->stmt_da->message()); +#endif + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + spider_free_share(share); + goto error_but_no_delete; + } +*/ + } + share->init_error = FALSE; + } + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + } + } + + DBUG_PRINT("info",("spider share=%p", share)); + DBUG_RETURN(share); + +error_hash_insert: + spider_free_share_resource_only(share); +error_alloc_share: + pthread_mutex_unlock(&spider_tbl_mutex); +error_get_link_statuses: + if (table_tables) + { + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } +error_open_sys_table: + if (init_mem_root) + { + free_root(&mem_root, MYF(0)); + init_mem_root = FALSE; + } +error_but_no_delete: + DBUG_RETURN(NULL); +} + +void spider_free_share_resource_only( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_free_share_resource_only"); + spider_free_share_alloc(share); + thr_lock_delete(&share->lock); + pthread_mutex_destroy(&share->auto_increment_mutex); + pthread_mutex_destroy(&share->crd_mutex); + pthread_mutex_destroy(&share->sts_mutex); + pthread_mutex_destroy(&share->mutex); + spider_free(spider_current_trx, share, MYF(0)); + DBUG_VOID_RETURN; +} + +int spider_free_share( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_free_share"); + pthread_mutex_lock(&spider_tbl_mutex); + if (!--share->use_count) + { +#ifndef WITHOUT_SPIDER_BG_SEARCH + spider_free_sts_thread(share); + spider_free_crd_thread(share); + spider_free_mon_threads(share); +#endif + spider_free_share_alloc(share); +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_open_tables, + share->table_name_hash_value, (uchar*) share); +#else + my_hash_delete(&spider_open_tables, (uchar*) share); +#endif + thr_lock_delete(&share->lock); + pthread_mutex_destroy(&share->auto_increment_mutex); + pthread_mutex_destroy(&share->crd_mutex); + pthread_mutex_destroy(&share->sts_mutex); + pthread_mutex_destroy(&share->mutex); + spider_free(spider_current_trx, share, MYF(0)); + } + pthread_mutex_unlock(&spider_tbl_mutex); + DBUG_RETURN(0); +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +SPIDER_PARTITION_SHARE *spider_get_pt_share( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, + int *error_num +) { + SPIDER_PARTITION_SHARE *partition_share; + char *tmp_name; + longlong *tmp_cardinality; + DBUG_ENTER("spider_get_pt_share"); + + pthread_mutex_lock(&spider_pt_share_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(partition_share = (SPIDER_PARTITION_SHARE*) + my_hash_search_using_hash_value( + &spider_open_pt_share, share->table_path_hash_value, + (uchar*) table_share->path.str, table_share->path.length))) +#else + if (!(partition_share = (SPIDER_PARTITION_SHARE*) my_hash_search( + &spider_open_pt_share, + (uchar*) table_share->path.str, table_share->path.length))) +#endif + { + DBUG_PRINT("info",("spider create new pt share")); + if (!(partition_share = (SPIDER_PARTITION_SHARE *) + spider_bulk_malloc(spider_current_trx, 51, MYF(MY_WME | MY_ZEROFILL), + &partition_share, sizeof(*partition_share), + &tmp_name, table_share->path.length + 1, + &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields, + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_share; + } + + partition_share->use_count = 0; + partition_share->table_name_length = table_share->path.length; + partition_share->table_name = tmp_name; + memcpy(partition_share->table_name, table_share->path.str, + partition_share->table_name_length); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + partition_share->table_path_hash_value = share->table_path_hash_value; +#endif + partition_share->cardinality = tmp_cardinality; + + partition_share->crd_get_time = partition_share->sts_get_time = + share->crd_get_time; + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_pt_share_sts, + &partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_sts_mutex; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_pt_share_crd, + &partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_crd_mutex; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&partition_share->pt_handler_mutex, + MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_pt_handler, + &partition_share->pt_handler_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_pt_handler_mutex; + } + + if( + my_hash_init(&partition_share->pt_handler_hash, spd_charset_utf8_bin, + 32, 0, 0, (my_hash_get_key) spider_pt_handler_share_get_key, 0, 0) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_pt_handler_hash; + } + spider_alloc_calc_mem_init(partition_share->pt_handler_hash, 142); + spider_alloc_calc_mem(spider_current_trx, + partition_share->pt_handler_hash, + partition_share->pt_handler_hash.array.max_element * + partition_share->pt_handler_hash.array.size_of_element); + + uint old_elements = spider_open_pt_share.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_open_pt_share, + share->table_path_hash_value, + (uchar*) partition_share)) +#else + if (my_hash_insert(&spider_open_pt_share, (uchar*) partition_share)) +#endif + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_hash_insert; + } + if (spider_open_pt_share.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_open_pt_share, + (spider_open_pt_share.array.max_element - old_elements) * + spider_open_pt_share.array.size_of_element); + } + } + partition_share->use_count++; + pthread_mutex_unlock(&spider_pt_share_mutex); + + DBUG_PRINT("info",("spider partition_share=%p", partition_share)); + DBUG_RETURN(partition_share); + +error_hash_insert: + spider_free_mem_calc(spider_current_trx, + partition_share->pt_handler_hash_id, + partition_share->pt_handler_hash.array.max_element * + partition_share->pt_handler_hash.array.size_of_element); + my_hash_free(&partition_share->pt_handler_hash); +error_init_pt_handler_hash: + pthread_mutex_destroy(&partition_share->pt_handler_mutex); +error_init_pt_handler_mutex: + pthread_mutex_destroy(&partition_share->crd_mutex); +error_init_crd_mutex: + pthread_mutex_destroy(&partition_share->sts_mutex); +error_init_sts_mutex: + spider_free(spider_current_trx, partition_share, MYF(0)); +error_alloc_share: + pthread_mutex_unlock(&spider_pt_share_mutex); + DBUG_RETURN(NULL); +} + +int spider_free_pt_share( + SPIDER_PARTITION_SHARE *partition_share +) { + DBUG_ENTER("spider_free_pt_share"); + pthread_mutex_lock(&spider_pt_share_mutex); + if (!--partition_share->use_count) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_open_pt_share, + partition_share->table_path_hash_value, (uchar*) partition_share); +#else + my_hash_delete(&spider_open_pt_share, (uchar*) partition_share); +#endif + spider_free_mem_calc(spider_current_trx, + partition_share->pt_handler_hash_id, + partition_share->pt_handler_hash.array.max_element * + partition_share->pt_handler_hash.array.size_of_element); + my_hash_free(&partition_share->pt_handler_hash); + pthread_mutex_destroy(&partition_share->pt_handler_mutex); + pthread_mutex_destroy(&partition_share->crd_mutex); + pthread_mutex_destroy(&partition_share->sts_mutex); + spider_free(spider_current_trx, partition_share, MYF(0)); + } + pthread_mutex_unlock(&spider_pt_share_mutex); + DBUG_RETURN(0); +} + +void spider_copy_sts_to_pt_share( + SPIDER_PARTITION_SHARE *partition_share, + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_copy_sts_to_pt_share"); + memcpy(&partition_share->data_file_length, &share->data_file_length, + sizeof(ulonglong) * 4 + sizeof(ha_rows) + + sizeof(ulong) + sizeof(time_t) * 3); +/* + partition_share->data_file_length = share->data_file_length; + partition_share->max_data_file_length = share->max_data_file_length; + partition_share->index_file_length = share->index_file_length; + partition_share->auto_increment_value = share->auto_increment_value; + partition_share->records = share->records; + partition_share->mean_rec_length = share->mean_rec_length; + partition_share->check_time = share->check_time; + partition_share->create_time = share->create_time; + partition_share->update_time = share->update_time; +*/ + DBUG_VOID_RETURN; +} + +void spider_copy_sts_to_share( + SPIDER_SHARE *share, + SPIDER_PARTITION_SHARE *partition_share +) { + DBUG_ENTER("spider_copy_sts_to_share"); + memcpy(&share->data_file_length, &partition_share->data_file_length, + sizeof(ulonglong) * 4 + sizeof(ha_rows) + + sizeof(ulong) + sizeof(time_t) * 3); +/* + share->data_file_length = partition_share->data_file_length; + share->max_data_file_length = partition_share->max_data_file_length; + share->index_file_length = partition_share->index_file_length; + share->auto_increment_value = partition_share->auto_increment_value; + share->records = partition_share->records; + share->mean_rec_length = partition_share->mean_rec_length; + share->check_time = partition_share->check_time; + share->create_time = partition_share->create_time; + share->update_time = partition_share->update_time; +*/ + DBUG_VOID_RETURN; +} + +void spider_copy_crd_to_pt_share( + SPIDER_PARTITION_SHARE *partition_share, + SPIDER_SHARE *share, + int fields +) { + DBUG_ENTER("spider_copy_crd_to_pt_share"); + memcpy(partition_share->cardinality, share->cardinality, + sizeof(longlong) * fields); + DBUG_VOID_RETURN; +} + +void spider_copy_crd_to_share( + SPIDER_SHARE *share, + SPIDER_PARTITION_SHARE *partition_share, + int fields +) { + DBUG_ENTER("spider_copy_crd_to_share"); + memcpy(share->cardinality, partition_share->cardinality, + sizeof(longlong) * fields); + DBUG_VOID_RETURN; +} +#endif + +int spider_open_all_tables( + SPIDER_TRX *trx, + bool lock +) { + THD *thd = trx->thd; + TABLE *table_tables; + int error_num, *need_mon, mon_val; + SPIDER_SHARE tmp_share; + char *db_name, *table_name; + uint db_name_length, table_name_length; + char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT]; + uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT]; + long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT]; + longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT]; + SPIDER_CONN *conn, **conns; + ha_spider *spider; + SPIDER_SHARE *share; + char **connect_info; + uint *connect_info_length; + long *long_info; + longlong *longlong_info; + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + DBUG_ENTER("spider_open_all_tables"); + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) + DBUG_RETURN(error_num); + if ( + (error_num = spider_sys_index_first(table_tables, 1)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_tables->file->print_error(error_num, MYF(0)); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + DBUG_RETURN(error_num); + } else { + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + DBUG_RETURN(0); + } + } + + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); + memset(&tmp_connect_info, 0, + sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT); + memset(tmp_connect_info_length, 0, + sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT); + memset(tmp_long, 0, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT); + memset(tmp_longlong, 0, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT); + spider_set_tmp_share_pointer(&tmp_share, (char **) &tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + tmp_share.link_statuses[0] = -1; + + do { + if ( + (error_num = spider_get_sys_tables( + table_tables, &db_name, &table_name, &mem_root)) || + (error_num = spider_get_sys_tables_connect_info( + table_tables, &tmp_share, 0, &mem_root)) || + (error_num = spider_set_connect_info_default( + &tmp_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + NULL, + NULL, +#endif + NULL + )) + ) { + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + db_name_length = strlen(db_name); + table_name_length = strlen(table_name); + + if ( + (error_num = spider_set_connect_info_default_db_table( + &tmp_share, + db_name, + db_name_length, + table_name, + table_name_length + )) || + (error_num = spider_create_conn_keys(&tmp_share)) || +/* + (error_num = spider_db_create_table_names_str(&tmp_share)) || +*/ + (error_num = spider_create_tmp_dbton_share(&tmp_share)) + ) { + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + + /* create conn */ + if ( + !(conn = spider_get_conn( + &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE, + SPIDER_CONN_KIND_MYSQL, &error_num)) + ) { + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + conn->error_mode &= spider_param_error_read_mode(thd, 0); + conn->error_mode &= spider_param_error_write_mode(thd, 0); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &mon_val; + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_before_query(conn, &mon_val))) + { + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + + if (lock && spider_param_use_snapshot_with_flush_tables(thd) == 2) + { + if (!(spider = new ha_spider())) + { + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider->lock_type = TL_READ_NO_INSERT; + + if (!(share = (SPIDER_SHARE *) + spider_bulk_malloc(spider_current_trx, 52, MYF(MY_WME | MY_ZEROFILL), + &share, sizeof(*share), + &connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT, + &connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT, + &long_info, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT, + &longlong_info, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT, + &conns, sizeof(SPIDER_CONN *), + &need_mon, sizeof(int), + &spider->conn_link_idx, sizeof(uint), + &spider->conn_can_fo, sizeof(uchar), + NullS)) + ) { + delete spider; + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + memcpy(share, &tmp_share, sizeof(*share)); + spider_set_tmp_share_pointer(share, connect_info, + connect_info_length, long_info, longlong_info); + memcpy(connect_info, &tmp_connect_info, sizeof(char *) * + SPIDER_TMP_SHARE_CHAR_PTR_COUNT); + memcpy(connect_info_length, &tmp_connect_info_length, sizeof(uint) * + SPIDER_TMP_SHARE_UINT_COUNT); + memcpy(long_info, &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT); + memcpy(longlong_info, &tmp_longlong, sizeof(longlong) * + SPIDER_TMP_SHARE_LONGLONG_COUNT); + spider->share = share; + spider->trx = trx; + spider->conns = conns; + spider->need_mons = need_mon; + spider->conn_link_idx[0] = 0; + spider->conn_can_fo[0] = 0; + if ((error_num = spider_create_tmp_dbton_handler(spider))) + { + spider_free(trx, share, MYF(0)); + delete spider; + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + + /* create another conn */ + if ( + (!(conn = spider_get_conn( + &tmp_share, 0, tmp_share.conn_keys[0], trx, spider, TRUE, FALSE, + SPIDER_CONN_KIND_MYSQL, &error_num))) + ) { + spider_free_tmp_dbton_handler(spider); + spider_free(trx, share, MYF(0)); + delete spider; + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + conn->error_mode &= spider_param_error_read_mode(thd, 0); + conn->error_mode &= spider_param_error_write_mode(thd, 0); + + spider->next = NULL; + if (conn->another_ha_last) + { + ((ha_spider*) conn->another_ha_last)->next = spider; + } else { + conn->another_ha_first = (void*) spider; + } + conn->another_ha_last = (void*) spider; + + int appended = 0; + if ((error_num = spider->dbton_handler[conn->dbton_id]-> + append_lock_tables_list(conn, 0, &appended))) + { + spider_free_tmp_dbton_handler(spider); + spider_free(trx, share, MYF(0)); + delete spider; + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + DBUG_RETURN(error_num); + } + } else { + spider_free_tmp_dbton_share(&tmp_share); + spider_free_tmp_share_alloc(&tmp_share); + } + error_num = spider_sys_index_next(table_tables); + } while (error_num == 0); + free_root(&mem_root, MYF(0)); + + spider_sys_index_end(table_tables); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, TRUE); + DBUG_RETURN(0); +} + +bool spider_flush_logs( + handlerton *hton +) { + int error_num; + THD* thd = current_thd; + SPIDER_TRX *trx; + DBUG_ENTER("spider_flush_logs"); + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + my_errno = error_num; + DBUG_RETURN(TRUE); + } + if ( + spider_param_use_flash_logs(trx->thd) && + ( + !trx->trx_consistent_snapshot || + !spider_param_use_all_conns_snapshot(trx->thd) || + !spider_param_use_snapshot_with_flush_tables(trx->thd) + ) + ) { + if ( + (error_num = spider_open_all_tables(trx, FALSE)) || + (error_num = spider_trx_all_flush_logs(trx)) + ) { + my_errno = error_num; + DBUG_RETURN(TRUE); + } + } + + DBUG_RETURN(FALSE); +} + +handler* spider_create_handler( + handlerton *hton, + TABLE_SHARE *table, + MEM_ROOT *mem_root +) { + DBUG_ENTER("spider_create_handler"); + DBUG_RETURN(new (mem_root) ha_spider(hton, table)); +} + +int spider_close_connection( + handlerton* hton, + THD* thd +) { + int roop_count = 0, need_mon = 0; + SPIDER_CONN *conn; + SPIDER_TRX *trx; + ha_spider tmp_spider; + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin); + DBUG_ENTER("spider_close_connection"); + tmp_str.init_calc_mem(121); + if (!(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + tmp_spider.trx = trx; + tmp_spider.result_list.sqls = &tmp_str; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + SPIDER_BACKUP_DASTATUS; + DBUG_PRINT("info",("spider conn->table_lock=%d", conn->table_lock)); + if (conn->table_lock > 0) + { + if (!conn->trx_start) + conn->disable_reconnect = FALSE; + if (conn->table_lock != 2) + { + spider_db_unlock_tables(&tmp_spider, 0); + } + conn->table_lock = 0; + } + roop_count++; + SPIDER_CONN_RESTORE_DASTATUS; + } + + spider_rollback(spider_hton_ptr, thd, TRUE); + spider_free_trx(trx, TRUE); + + DBUG_RETURN(0); +} + +void spider_drop_database( + handlerton *hton, + char* path +) { + DBUG_ENTER("spider_drop_database"); + DBUG_VOID_RETURN; +} + +bool spider_show_status( + handlerton *hton, + THD *thd, + stat_print_fn *stat_print, + enum ha_stat_type stat_type +) { + DBUG_ENTER("spider_show_status"); + switch (stat_type) { + case HA_ENGINE_STATUS: + default: + DBUG_RETURN(FALSE); + } +} + +int spider_db_done( + void *p +) { + int roop_count; + THD *thd = current_thd, *tmp_thd; + SPIDER_CONN *conn; + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + SPIDER_TABLE_MON_LIST *table_mon_list; + DBUG_ENTER("spider_db_done"); + +#ifndef WITHOUT_SPIDER_BG_SEARCH + spider_free_trx(spider_global_trx, TRUE); +#endif + + for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--) + { + if (spider_dbton[roop_count].deinit) + { + spider_dbton[roop_count].deinit(); + } + } + + for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; + roop_count >= 0; roop_count--) + { + while ((table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_element( + &spider_udf_table_mon_list_hash[roop_count], 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value( + &spider_udf_table_mon_list_hash[roop_count], + table_mon_list->key_hash_value, (uchar*) table_mon_list); +#else + my_hash_delete(&spider_udf_table_mon_list_hash[roop_count], + (uchar*) table_mon_list); +#endif + spider_ping_table_free_mon_list(table_mon_list); + } + spider_free_mem_calc(spider_current_trx, + spider_udf_table_mon_list_hash_id, + spider_udf_table_mon_list_hash[roop_count].array.max_element * + spider_udf_table_mon_list_hash[roop_count].array.size_of_element); + my_hash_free(&spider_udf_table_mon_list_hash[roop_count]); + } + for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; + roop_count >= 0; roop_count--) + pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]); + for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; + roop_count >= 0; roop_count--) + pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]); + spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0)); + + if (thd && thd_sql_command(thd) == SQLCOM_UNINSTALL_PLUGIN) { + pthread_mutex_lock(&spider_allocated_thds_mutex); + while ((tmp_thd = (THD *) my_hash_element(&spider_allocated_thds, 0))) + { + SPIDER_TRX *trx = (SPIDER_TRX *) *thd_ha_data(tmp_thd, spider_hton_ptr); + if (trx) + { + DBUG_ASSERT(tmp_thd == trx->thd); + spider_free_trx(trx, FALSE); + *thd_ha_data(tmp_thd, spider_hton_ptr) = (void *) NULL; + } else + my_hash_delete(&spider_allocated_thds, (uchar *) tmp_thd); + } + pthread_mutex_unlock(&spider_allocated_thds_mutex); + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + pthread_mutex_lock(&spider_hs_w_conn_mutex); + while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_w_conn_hash, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_hs_w_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_hs_w_conn_hash, (uchar*) conn); +#endif + spider_free_conn(conn); + } + pthread_mutex_unlock(&spider_hs_w_conn_mutex); + pthread_mutex_lock(&spider_hs_r_conn_mutex); + while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_r_conn_hash, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_hs_r_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_hs_r_conn_hash, (uchar*) conn); +#endif + spider_free_conn(conn); + } + pthread_mutex_unlock(&spider_hs_r_conn_mutex); +#endif + pthread_mutex_lock(&spider_conn_mutex); + while ((conn = (SPIDER_CONN*) my_hash_element(&spider_open_connections, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_open_connections, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&spider_open_connections, (uchar*) conn); +#endif + spider_free_conn(conn); + } + pthread_mutex_unlock(&spider_conn_mutex); + spider_free_mem_calc(spider_current_trx, + spider_mon_table_cache_id, + spider_mon_table_cache.max_element * + spider_mon_table_cache.size_of_element); + delete_dynamic(&spider_mon_table_cache); + spider_free_mem_calc(spider_current_trx, + spider_allocated_thds_id, + spider_allocated_thds.array.max_element * + spider_allocated_thds.array.size_of_element); + my_hash_free(&spider_allocated_thds); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc(spider_current_trx, + spider_hs_w_conn_hash_id, + spider_hs_w_conn_hash.array.max_element * + spider_hs_w_conn_hash.array.size_of_element); + my_hash_free(&spider_hs_w_conn_hash); + spider_free_mem_calc(spider_current_trx, + spider_hs_r_conn_hash_id, + spider_hs_r_conn_hash.array.max_element * + spider_hs_r_conn_hash.array.size_of_element); + my_hash_free(&spider_hs_r_conn_hash); +#endif + spider_free_mem_calc(spider_current_trx, + spider_open_connections_id, + spider_open_connections.array.max_element * + spider_open_connections.array.size_of_element); + my_hash_free(&spider_open_connections); +#ifdef WITH_PARTITION_STORAGE_ENGINE + spider_free_mem_calc(spider_current_trx, + spider_open_pt_share_id, + spider_open_pt_share.array.max_element * + spider_open_pt_share.array.size_of_element); + my_hash_free(&spider_open_pt_share); +#endif + pthread_mutex_lock(&spider_init_error_tbl_mutex); + while ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE*) + my_hash_element(&spider_init_error_tables, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_init_error_tables, + spider_init_error_table->table_name_hash_value, + (uchar*) spider_init_error_table); +#else + my_hash_delete(&spider_init_error_tables, + (uchar*) spider_init_error_table); +#endif + spider_free(NULL, spider_init_error_table, MYF(0)); + } + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + spider_free_mem_calc(spider_current_trx, + spider_init_error_tables_id, + spider_init_error_tables.array.max_element * + spider_init_error_tables.array.size_of_element); + my_hash_free(&spider_init_error_tables); + spider_free_mem_calc(spider_current_trx, + spider_open_tables_id, + spider_open_tables.array.max_element * + spider_open_tables.array.size_of_element); + my_hash_free(&spider_open_tables); + pthread_mutex_destroy(&spider_mem_calc_mutex); + pthread_mutex_destroy(&spider_mon_table_cache_mutex); + pthread_mutex_destroy(&spider_allocated_thds_mutex); + pthread_mutex_destroy(&spider_open_conn_mutex); +#ifndef WITHOUT_SPIDER_BG_SEARCH + pthread_mutex_destroy(&spider_global_trx_mutex); +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + pthread_mutex_destroy(&spider_hs_w_conn_mutex); + pthread_mutex_destroy(&spider_hs_r_conn_mutex); +#endif + pthread_mutex_destroy(&spider_conn_mutex); +#ifdef WITH_PARTITION_STORAGE_ENGINE + pthread_mutex_destroy(&spider_pt_share_mutex); +#endif + pthread_mutex_destroy(&spider_init_error_tbl_mutex); + pthread_mutex_destroy(&spider_conn_id_mutex); + pthread_mutex_destroy(&spider_thread_id_mutex); + pthread_mutex_destroy(&spider_tbl_mutex); +#ifndef WITHOUT_SPIDER_BG_SEARCH + pthread_attr_destroy(&spider_pt_attr); +#endif + + for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++) + { + if (spider_alloc_func_name[roop_count]) + DBUG_PRINT("info",("spider %d %s %s %lu %llu %lld %llu %llu %s", + roop_count, + spider_alloc_func_name[roop_count], + spider_alloc_file_name[roop_count], + spider_alloc_line_no[roop_count], + spider_total_alloc_mem[roop_count], + spider_current_alloc_mem[roop_count], + spider_alloc_mem_count[roop_count], + spider_free_mem_count[roop_count], + spider_current_alloc_mem[roop_count] ? "NG" : "OK" + )); + } +/* +DBUG_ASSERT(0); +*/ + DBUG_RETURN(0); +} + +int spider_panic( + handlerton *hton, + ha_panic_function type +) { + DBUG_ENTER("spider_panic"); + DBUG_RETURN(0); +} + +int spider_db_init( + void *p +) { + int error_num, roop_count; + uint dbton_id = 0; + handlerton *spider_hton = (handlerton *)p; + DBUG_ENTER("spider_db_init"); + spider_hton_ptr = spider_hton; + + spider_hton->state = SHOW_OPTION_YES; + spider_hton->flags = HTON_NO_FLAGS; + /* spider_hton->db_type = DB_TYPE_SPIDER; */ + /* + spider_hton->savepoint_offset; + spider_hton->savepoint_set = spider_savepoint_set; + spider_hton->savepoint_rollback = spider_savepoint_rollback; + spider_hton->savepoint_release = spider_savepoint_release; + spider_hton->create_cursor_read_view = spider_create_cursor_read_view; + spider_hton->set_cursor_read_view = spider_set_cursor_read_view; + spider_hton->close_cursor_read_view = spider_close_cursor_read_view; + */ + spider_hton->panic = spider_panic; + spider_hton->close_connection = spider_close_connection; + spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot; + spider_hton->flush_logs = spider_flush_logs; + spider_hton->commit = spider_commit; + spider_hton->rollback = spider_rollback; +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE + spider_hton->discover_table_structure = spider_discover_table_structure; +#endif + if (spider_param_support_xa()) + { + spider_hton->prepare = spider_xa_prepare; + spider_hton->recover = spider_xa_recover; + spider_hton->commit_by_xid = spider_xa_commit_by_xid; + spider_hton->rollback_by_xid = spider_xa_rollback_by_xid; + } + spider_hton->create = spider_create_handler; + spider_hton->drop_database = spider_drop_database; + spider_hton->show_status = spider_show_status; + + memset(&spider_alloc_func_name, 0, sizeof(spider_alloc_func_name)); + memset(&spider_alloc_file_name, 0, sizeof(spider_alloc_file_name)); + memset(&spider_alloc_line_no, 0, sizeof(spider_alloc_line_no)); + memset(&spider_total_alloc_mem, 0, sizeof(spider_total_alloc_mem)); + memset(&spider_current_alloc_mem, 0, sizeof(spider_current_alloc_mem)); + memset(&spider_alloc_mem_count, 0, sizeof(spider_alloc_mem_count)); + memset(&spider_free_mem_count, 0, sizeof(spider_free_mem_count)); + +#ifdef _WIN32 + HMODULE current_module = GetModuleHandle(NULL); + spd_db_att_thread_id = (ulong *) + GetProcAddress(current_module, "?thread_id@@3KA"); + spd_db_att_LOCK_xid_cache = (pthread_mutex_t *) +#if MYSQL_VERSION_ID < 50500 + GetProcAddress(current_module, + "?LOCK_xid_cache@@3U_RTL_CRITICAL_SECTION@@A"); +#else + GetProcAddress(current_module, + "?LOCK_xid_cache@@3Ust_mysql_mutex@@A"); +#endif + spd_db_att_xid_cache = (HASH *) + GetProcAddress(current_module, "?xid_cache@@3Ust_hash@@A"); + spd_charset_utf8_bin = (struct charset_info_st *) + GetProcAddress(current_module, "my_charset_utf8_bin"); + spd_defaults_extra_file = (const char **) + GetProcAddress(current_module, "my_defaults_extra_file"); + spd_defaults_file = (const char **) + GetProcAddress(current_module, "my_defaults_file"); +#else + spd_db_att_thread_id = &thread_id; + spd_db_att_LOCK_xid_cache = &LOCK_xid_cache; + spd_db_att_xid_cache = &xid_cache; + spd_charset_utf8_bin = &my_charset_utf8_bin; + spd_defaults_extra_file = &my_defaults_extra_file; + spd_defaults_file = &my_defaults_file; +#endif + +#ifdef HAVE_PSI_INTERFACE + init_spider_psi_keys(); +#endif + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (pthread_attr_init(&spider_pt_attr)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_pt_attr_init; + } +/* + if (pthread_attr_setdetachstate(&spider_pt_attr, PTHREAD_CREATE_DETACHED)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_pt_attr_setstate; + } +*/ +#endif + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_tbl, + &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_tbl_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_thread_id, + &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_id_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_conn_id, + &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_conn_id_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_init_error_tbl, + &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_error_tbl_mutex_init; + } +#ifdef WITH_PARTITION_STORAGE_ENGINE +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_pt_share, + &spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_pt_share_mutex_init; + } +#endif +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_conn, + &spider_conn_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_conn_mutex_init; + } +#ifndef WITHOUT_SPIDER_BG_SEARCH +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_global_trx_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_global_trx, + &spider_global_trx_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_global_trx_mutex_init; + } +#endif +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_open_conn, + &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_open_conn_mutex_init; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_hs_r_conn, + &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_hs_r_conn_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_hs_w_conn, + &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_hs_w_conn_mutex_init; + } +#endif +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_allocated_thds, + &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_allocated_thds_mutex_init; + } +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mon_table_cache, + &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mon_table_cache_mutex_init; + } + +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_mem_calc, + &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mem_calc_mutex_init; + } + + if( + my_hash_init(&spider_open_tables, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_tbl_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_open_tables_hash_init; + } + spider_alloc_calc_mem_init(spider_open_tables, 143); + spider_alloc_calc_mem(NULL, + spider_open_tables, + spider_open_tables.array.max_element * + spider_open_tables.array.size_of_element); + if( + my_hash_init(&spider_init_error_tables, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_tbl_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_error_tables_hash_init; + } + spider_alloc_calc_mem_init(spider_init_error_tables, 144); + spider_alloc_calc_mem(NULL, + spider_init_error_tables, + spider_init_error_tables.array.max_element * + spider_init_error_tables.array.size_of_element); +#ifdef WITH_PARTITION_STORAGE_ENGINE + if( + my_hash_init(&spider_open_pt_share, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_pt_share_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_open_pt_share_hash_init; + } + spider_alloc_calc_mem_init(spider_open_pt_share, 145); + spider_alloc_calc_mem(NULL, + spider_open_pt_share, + spider_open_pt_share.array.max_element * + spider_open_pt_share.array.size_of_element); +#endif + if( + my_hash_init(&spider_open_connections, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_open_connections_hash_init; + } + spider_alloc_calc_mem_init(spider_open_connections, 146); + spider_alloc_calc_mem(NULL, + spider_open_connections, + spider_open_connections.array.max_element * + spider_open_connections.array.size_of_element); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if( + my_hash_init(&spider_hs_r_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_hs_r_conn_hash_init; + } + spider_alloc_calc_mem_init(spider_hs_r_conn_hash, 147); + spider_alloc_calc_mem(NULL, + spider_hs_r_conn_hash, + spider_hs_r_conn_hash.array.max_element * + spider_hs_r_conn_hash.array.size_of_element); + if( + my_hash_init(&spider_hs_w_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_hs_w_conn_hash_init; + } + spider_alloc_calc_mem_init(spider_hs_w_conn_hash, 148); + spider_alloc_calc_mem(NULL, + spider_hs_w_conn_hash, + spider_hs_w_conn_hash.array.max_element * + spider_hs_w_conn_hash.array.size_of_element); +#endif + if( + my_hash_init(&spider_allocated_thds, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_allocated_thds_get_key, 0, 0) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_allocated_thds_hash_init; + } + spider_alloc_calc_mem_init(spider_allocated_thds, 149); + spider_alloc_calc_mem(NULL, + spider_allocated_thds, + spider_allocated_thds.array.max_element * + spider_allocated_thds.array.size_of_element); + + if( + SPD_INIT_DYNAMIC_ARRAY2(&spider_mon_table_cache, sizeof(SPIDER_MON_KEY), + NULL, 64, 64, MYF(MY_WME)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mon_table_cache_array_init; + } + spider_alloc_calc_mem_init(spider_mon_table_cache, 165); + spider_alloc_calc_mem(NULL, + spider_mon_table_cache, + spider_mon_table_cache.max_element * + spider_mon_table_cache.size_of_element); + + if (!(spider_udf_table_mon_mutexes = (pthread_mutex_t *) + spider_bulk_malloc(NULL, 53, MYF(MY_WME | MY_ZEROFILL), + &spider_udf_table_mon_mutexes, sizeof(pthread_mutex_t) * + spider_param_udf_table_mon_mutex_count(), + &spider_udf_table_mon_conds, sizeof(pthread_cond_t) * + spider_param_udf_table_mon_mutex_count(), + &spider_udf_table_mon_list_hash, sizeof(HASH) * + spider_param_udf_table_mon_mutex_count(), + NullS)) + ) + goto error_alloc_mon_mutxes; + + for (roop_count = 0; + roop_count < (int) spider_param_udf_table_mon_mutex_count(); + roop_count++) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count], + MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_udf_table_mon, + &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_udf_table_mon_mutex; + } + } + for (roop_count = 0; + roop_count < (int) spider_param_udf_table_mon_mutex_count(); + roop_count++) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL)) +#else + if (mysql_cond_init(spd_key_cond_udf_table_mon, + &spider_udf_table_mon_conds[roop_count], NULL)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_udf_table_mon_cond; + } + } + for (roop_count = 0; + roop_count < (int) spider_param_udf_table_mon_mutex_count(); + roop_count++) + { + if (my_hash_init(&spider_udf_table_mon_list_hash[roop_count], + spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_udf_table_mon_list_hash; + } + spider_alloc_calc_mem_init(spider_udf_table_mon_list_hash, 150); + spider_alloc_calc_mem(NULL, + spider_udf_table_mon_list_hash, + spider_udf_table_mon_list_hash[roop_count].array.max_element * + spider_udf_table_mon_list_hash[roop_count].array.size_of_element); + } + + spider_dbton_mysql.dbton_id = dbton_id; + spider_dbton[dbton_id] = spider_dbton_mysql; + ++dbton_id; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_dbton_handlersocket.dbton_id = dbton_id; + spider_dbton[dbton_id] = spider_dbton_handlersocket; + ++dbton_id; +#endif +#ifdef HAVE_ORACLE_OCI + spider_dbton_oracle.dbton_id = dbton_id; + spider_dbton[dbton_id] = spider_dbton_oracle; + ++dbton_id; +#endif + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + if (spider_dbton[roop_count].init) + { + if ((error_num = spider_dbton[roop_count].init())) + { + goto error_init_dbton; + } + } + } + +#ifndef WITHOUT_SPIDER_BG_SEARCH + if (!(spider_global_trx = spider_get_trx(NULL, FALSE, &error_num))) + goto error; +#endif + + DBUG_RETURN(0); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +error: + roop_count = SPIDER_DBTON_SIZE; +error_init_dbton: + for (roop_count--; roop_count >= 0; roop_count--) + { + if (spider_dbton[roop_count].deinit) + { + spider_dbton[roop_count].deinit(); + } + } + roop_count = spider_param_udf_table_mon_mutex_count() - 1; +#endif +error_init_udf_table_mon_list_hash: + for (; roop_count >= 0; roop_count--) + { + spider_free_mem_calc(NULL, + spider_udf_table_mon_list_hash_id, + spider_udf_table_mon_list_hash[roop_count].array.max_element * + spider_udf_table_mon_list_hash[roop_count].array.size_of_element); + my_hash_free(&spider_udf_table_mon_list_hash[roop_count]); + } + roop_count = spider_param_udf_table_mon_mutex_count() - 1; +error_init_udf_table_mon_cond: + for (; roop_count >= 0; roop_count--) + pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]); + roop_count = spider_param_udf_table_mon_mutex_count() - 1; +error_init_udf_table_mon_mutex: + for (; roop_count >= 0; roop_count--) + pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]); + spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0)); +error_alloc_mon_mutxes: + spider_free_mem_calc(NULL, + spider_mon_table_cache_id, + spider_mon_table_cache.max_element * + spider_mon_table_cache.size_of_element); + delete_dynamic(&spider_mon_table_cache); +error_mon_table_cache_array_init: + spider_free_mem_calc(NULL, + spider_allocated_thds_id, + spider_allocated_thds.array.max_element * + spider_allocated_thds.array.size_of_element); + my_hash_free(&spider_allocated_thds); +error_allocated_thds_hash_init: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc(NULL, + spider_hs_w_conn_hash_id, + spider_hs_w_conn_hash.array.max_element * + spider_hs_w_conn_hash.array.size_of_element); + my_hash_free(&spider_hs_w_conn_hash); +error_hs_w_conn_hash_init: + spider_free_mem_calc(NULL, + spider_hs_r_conn_hash_id, + spider_hs_r_conn_hash.array.max_element * + spider_hs_r_conn_hash.array.size_of_element); + my_hash_free(&spider_hs_r_conn_hash); +error_hs_r_conn_hash_init: +#endif + spider_free_mem_calc(NULL, + spider_open_connections_id, + spider_open_connections.array.max_element * + spider_open_connections.array.size_of_element); + my_hash_free(&spider_open_connections); +error_open_connections_hash_init: +#ifdef WITH_PARTITION_STORAGE_ENGINE + spider_free_mem_calc(NULL, + spider_open_pt_share_id, + spider_open_pt_share.array.max_element * + spider_open_pt_share.array.size_of_element); + my_hash_free(&spider_open_pt_share); +error_open_pt_share_hash_init: +#endif + spider_free_mem_calc(NULL, + spider_init_error_tables_id, + spider_init_error_tables.array.max_element * + spider_init_error_tables.array.size_of_element); + my_hash_free(&spider_init_error_tables); +error_init_error_tables_hash_init: + spider_free_mem_calc(NULL, + spider_open_tables_id, + spider_open_tables.array.max_element * + spider_open_tables.array.size_of_element); + my_hash_free(&spider_open_tables); +error_open_tables_hash_init: + pthread_mutex_destroy(&spider_mem_calc_mutex); +error_mem_calc_mutex_init: + pthread_mutex_destroy(&spider_mon_table_cache_mutex); +error_mon_table_cache_mutex_init: + pthread_mutex_destroy(&spider_allocated_thds_mutex); +error_allocated_thds_mutex_init: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + pthread_mutex_destroy(&spider_hs_w_conn_mutex); +error_hs_w_conn_mutex_init: + pthread_mutex_destroy(&spider_hs_r_conn_mutex); +error_hs_r_conn_mutex_init: +#endif + pthread_mutex_destroy(&spider_open_conn_mutex); +error_open_conn_mutex_init: +#ifndef WITHOUT_SPIDER_BG_SEARCH + pthread_mutex_destroy(&spider_global_trx_mutex); +error_global_trx_mutex_init: +#endif + pthread_mutex_destroy(&spider_conn_mutex); +error_conn_mutex_init: +#ifdef WITH_PARTITION_STORAGE_ENGINE + pthread_mutex_destroy(&spider_pt_share_mutex); +error_pt_share_mutex_init: +#endif + pthread_mutex_destroy(&spider_init_error_tbl_mutex); +error_init_error_tbl_mutex_init: + pthread_mutex_destroy(&spider_conn_id_mutex); +error_conn_id_mutex_init: + pthread_mutex_destroy(&spider_thread_id_mutex); +error_thread_id_mutex_init: + pthread_mutex_destroy(&spider_tbl_mutex); +error_tbl_mutex_init: +#ifndef WITHOUT_SPIDER_BG_SEARCH +/* +error_pt_attr_setstate: +*/ + pthread_attr_destroy(&spider_pt_attr); +error_pt_attr_init: +#endif + DBUG_RETURN(error_num); +} + +char *spider_create_string( + const char *str, + uint length +) { + char *res; + DBUG_ENTER("spider_create_string"); + if (!(res = (char*) spider_malloc(spider_current_trx, 13, length + 1, + MYF(MY_WME)))) + DBUG_RETURN(NULL); + memcpy(res, str, length); + res[length] = '\0'; + DBUG_RETURN(res); +} + +char *spider_create_table_name_string( + const char *table_name, + const char *part_name, + const char *sub_name +) { + char *res, *tmp; + uint length = strlen(table_name); + DBUG_ENTER("spider_create_table_name_string"); + if (part_name) + { + length += sizeof("#P#") - 1 + strlen(part_name); + if (sub_name) + length += sizeof("#SP#") - 1 + strlen(sub_name); + } + if (!(res = (char*) spider_malloc(spider_current_trx, 14, length + 1, + MYF(MY_WME)))) + DBUG_RETURN(NULL); + tmp = strmov(res, table_name); + if (part_name) + { + tmp = strmov(tmp, "#P#"); + tmp = strmov(tmp, part_name); + if (sub_name) + { + tmp = strmov(tmp, "#SP#"); + tmp = strmov(tmp, sub_name); + } + } + DBUG_RETURN(res); +} + +#ifdef WITH_PARTITION_STORAGE_ENGINE +void spider_get_partition_info( + const char *table_name, + uint table_name_length, + const TABLE_SHARE *table_share, + partition_info *part_info, + partition_element **part_elem, + partition_element **sub_elem +) { + char tmp_name[FN_LEN]; + partition_element *tmp_part_elem = NULL, *tmp_sub_elem = NULL; + bool tmp_flg = FALSE, tmp_find_flg = FALSE; + DBUG_ENTER("spider_get_partition_info"); + *part_elem = NULL; + *sub_elem = NULL; + if (!part_info) + DBUG_VOID_RETURN; + + if (!memcmp(table_name + table_name_length - 5, "#TMP#", 5)) + tmp_flg = TRUE; + + DBUG_PRINT("info",("spider table_name=%s", table_name)); + List_iterator part_it(part_info->partitions); + while ((*part_elem = part_it++)) + { + if ((*part_elem)->subpartitions.elements) + { + List_iterator sub_it((*part_elem)->subpartitions); + while ((*sub_elem = sub_it++)) + { + create_subpartition_name(tmp_name, table_share->path.str, + (*part_elem)->partition_name, (*sub_elem)->partition_name, + NORMAL_PART_NAME); + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!memcmp(table_name, tmp_name, table_name_length + 1)) + DBUG_VOID_RETURN; + if ( + tmp_flg && + *(tmp_name + table_name_length - 5) == '\0' && + !memcmp(table_name, tmp_name, table_name_length - 5) + ) { + tmp_part_elem = *part_elem; + tmp_sub_elem = *sub_elem; + tmp_flg = FALSE; + tmp_find_flg = TRUE; + } + } + } else { + create_partition_name(tmp_name, table_share->path.str, + (*part_elem)->partition_name, NORMAL_PART_NAME, TRUE); + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!memcmp(table_name, tmp_name, table_name_length + 1)) + DBUG_VOID_RETURN; + if ( + tmp_flg && + *(tmp_name + table_name_length - 5) == '\0' && + !memcmp(table_name, tmp_name, table_name_length - 5) + ) { + tmp_part_elem = *part_elem; + tmp_flg = FALSE; + tmp_find_flg = TRUE; + } + } + } + if (tmp_find_flg) + { + *part_elem = tmp_part_elem; + *sub_elem = tmp_sub_elem; + DBUG_PRINT("info",("spider tmp find")); + DBUG_VOID_RETURN; + } + *part_elem = NULL; + *sub_elem = NULL; + DBUG_PRINT("info",("spider no hit")); + DBUG_VOID_RETURN; +} +#endif + +int spider_get_sts( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + double sts_interval, + int sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + int sts_sync, +#endif + int sts_sync_level, + uint flag +) { + int get_type; + int error_num = 0; + DBUG_ENTER("spider_get_sts"); + +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + sts_sync == 0 + ) { +#endif + /* get */ + get_type = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + } else if ( + !share->partition_share->sts_init + ) { + pthread_mutex_lock(&share->partition_share->sts_mutex); + if (!share->partition_share->sts_init) + { + /* get after mutex_lock */ + get_type = 2; + } else { + pthread_mutex_unlock(&share->partition_share->sts_mutex); + /* copy */ + get_type = 0; + } + } else if ( + difftime(share->sts_get_time, share->partition_share->sts_get_time) < + sts_interval + ) { + /* copy */ + get_type = 0; + } else if ( + !pthread_mutex_trylock(&share->partition_share->sts_mutex) + ) { + /* get after mutex_trylock */ + get_type = 3; + } else { + /* copy */ + get_type = 0; + } + if (get_type == 0) + spider_copy_sts_to_share(share, share->partition_share); + else +#endif + error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag); +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (get_type >= 2) + pthread_mutex_unlock(&share->partition_share->sts_mutex); +#endif + if (error_num) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share = + spider->partition_handler_share; + if ( + !share->partition_share->sts_init && + sts_sync >= sts_sync_level && + get_type > 1 && + partition_handler_share && + partition_handler_share->handlers && + partition_handler_share->handlers[0] == spider + ) { + int roop_count; + ha_spider *tmp_spider; + SPIDER_SHARE *tmp_share; + double tmp_sts_interval; + int tmp_sts_mode; + int tmp_sts_sync; + THD *thd = spider->trx->thd; + for (roop_count = 1; + roop_count < (int) partition_handler_share->use_count; + roop_count++) + { + tmp_spider = + (ha_spider *) partition_handler_share->handlers[roop_count]; + tmp_share = tmp_spider->share; + tmp_sts_interval = spider_param_sts_interval(thd, share->sts_interval); + tmp_sts_mode = spider_param_sts_mode(thd, share->sts_mode); + tmp_sts_sync = spider_param_sts_sync(thd, share->sts_sync); + spider_get_sts(tmp_share, tmp_spider->search_link_idx, + tmp_time, tmp_spider, tmp_sts_interval, tmp_sts_mode, tmp_sts_sync, + 1, flag); + if (share->partition_share->sts_init) + { + error_num = 0; + thd->clear_error(); + get_type = 0; + spider_copy_sts_to_share(share, share->partition_share); + break; + } + } + } + if (error_num) +#endif + DBUG_RETURN(error_num); + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (sts_sync >= sts_sync_level && get_type > 0) + { + spider_copy_sts_to_pt_share(share->partition_share, share); + share->partition_share->sts_get_time = tmp_time; + share->partition_share->sts_init = TRUE; + } +#endif + share->sts_get_time = tmp_time; + share->sts_init = TRUE; + DBUG_RETURN(0); +} + +int spider_get_crd( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + TABLE *table, + double crd_interval, + int crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync, +#endif + int crd_sync_level +) { + int get_type; + int error_num = 0; + DBUG_ENTER("spider_get_crd"); + +#ifdef WITH_PARTITION_STORAGE_ENGINE + if ( + crd_sync == 0 + ) { +#endif + /* get */ + get_type = 1; +#ifdef WITH_PARTITION_STORAGE_ENGINE + } else if ( + !share->partition_share->crd_init + ) { + pthread_mutex_lock(&share->partition_share->crd_mutex); + if (!share->partition_share->crd_init) + { + /* get after mutex_lock */ + get_type = 2; + } else { + pthread_mutex_unlock(&share->partition_share->crd_mutex); + /* copy */ + get_type = 0; + } + } else if ( + difftime(share->crd_get_time, share->partition_share->crd_get_time) < + crd_interval + ) { + /* copy */ + get_type = 0; + } else if ( + !pthread_mutex_trylock(&share->partition_share->crd_mutex) + ) { + /* get after mutex_trylock */ + get_type = 3; + } else { + /* copy */ + get_type = 0; + } + if (get_type == 0) + spider_copy_crd_to_share(share, share->partition_share, + table->s->fields); + else +#endif + error_num = spider_db_show_index(spider, link_idx, table, crd_mode); +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (get_type >= 2) + pthread_mutex_unlock(&share->partition_share->crd_mutex); +#endif + if (error_num) + { +#ifdef WITH_PARTITION_STORAGE_ENGINE + SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share = + spider->partition_handler_share; + if ( + !share->partition_share->crd_init && + crd_sync >= crd_sync_level && + get_type > 1 && + partition_handler_share && + partition_handler_share->handlers && + partition_handler_share->handlers[0] == spider + ) { + int roop_count; + ha_spider *tmp_spider; + SPIDER_SHARE *tmp_share; + double tmp_crd_interval; + int tmp_crd_mode; + int tmp_crd_sync; + THD *thd = spider->trx->thd; + for (roop_count = 1; + roop_count < (int) partition_handler_share->use_count; + roop_count++) + { + tmp_spider = + (ha_spider *) partition_handler_share->handlers[roop_count]; + tmp_share = tmp_spider->share; + tmp_crd_interval = spider_param_crd_interval(thd, share->crd_interval); + tmp_crd_mode = spider_param_crd_mode(thd, share->crd_mode); + tmp_crd_sync = spider_param_crd_sync(thd, share->crd_sync); + spider_get_crd(tmp_share, tmp_spider->search_link_idx, + tmp_time, tmp_spider, table, tmp_crd_interval, tmp_crd_mode, + tmp_crd_sync, 1); + if (share->partition_share->crd_init) + { + error_num = 0; + thd->clear_error(); + get_type = 0; + spider_copy_crd_to_share(share, share->partition_share, + table->s->fields); + break; + } + } + } + if (error_num) +#endif + DBUG_RETURN(error_num); + } +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (crd_sync >= crd_sync_level && get_type > 0) + { + spider_copy_crd_to_pt_share(share->partition_share, share, + table->s->fields); + share->partition_share->crd_get_time = tmp_time; + share->partition_share->crd_init = TRUE; + } +#endif + share->crd_get_time = tmp_time; + share->crd_init = TRUE; + DBUG_RETURN(0); +} + +void spider_set_result_list_param( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; + THD *thd = spider->trx->thd; + DBUG_ENTER("spider_set_result_list_param"); + result_list->internal_offset = + spider_param_internal_offset(thd, share->internal_offset); + result_list->internal_limit = +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + spider->info_limit < 9223372036854775807LL ? + spider->info_limit : +#endif + spider_param_internal_limit(thd, share->internal_limit); + result_list->split_read = spider_split_read_param(spider); + if (spider->support_multi_split_read_sql()) + { + result_list->multi_split_read = + spider_param_multi_split_read(thd, share->multi_split_read); + } else { + result_list->multi_split_read = 1; + } + result_list->max_order = + spider_param_max_order(thd, share->max_order); + result_list->quick_mode = + spider_param_quick_mode(thd, share->quick_mode); + result_list->quick_page_size = + spider_param_quick_page_size(thd, share->quick_page_size); + result_list->low_mem_read = + spider_param_low_mem_read(thd, share->low_mem_read); + DBUG_VOID_RETURN; +} + +SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + bool create +) { + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + char *tmp_name; + DBUG_ENTER("spider_get_init_error_table"); + pthread_mutex_lock(&spider_init_error_tbl_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) + my_hash_search_using_hash_value( + &spider_init_error_tables, share->table_name_hash_value, + (uchar*) share->table_name, share->table_name_length))) +#else + if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search( + &spider_init_error_tables, + (uchar*) share->table_name, share->table_name_length))) +#endif + { + if (!create) + { + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + DBUG_RETURN(NULL); + } + if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) + spider_bulk_malloc(spider_current_trx, 54, MYF(MY_WME | MY_ZEROFILL), + &spider_init_error_table, sizeof(*spider_init_error_table), + &tmp_name, share->table_name_length + 1, + NullS)) + ) { + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + DBUG_RETURN(NULL); + } + memcpy(tmp_name, share->table_name, share->table_name_length); + spider_init_error_table->table_name = tmp_name; + spider_init_error_table->table_name_length = share->table_name_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + spider_init_error_table->table_name_hash_value = + share->table_name_hash_value; +#endif + uint old_elements = spider_init_error_tables.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_init_error_tables, + share->table_name_hash_value, (uchar*) spider_init_error_table)) +#else + if (my_hash_insert(&spider_init_error_tables, + (uchar*) spider_init_error_table)) +#endif + { + spider_free(trx, spider_init_error_table, MYF(0)); + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + DBUG_RETURN(NULL); + } + if (spider_init_error_tables.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_init_error_tables, + (spider_init_error_tables.array.max_element - old_elements) * + spider_init_error_tables.array.size_of_element); + } + } + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + DBUG_RETURN(spider_init_error_table); +} + +void spider_delete_init_error_table( + const char *name +) { + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + uint length = strlen(name); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) name, length); +#endif + DBUG_ENTER("spider_delete_init_error_table"); + pthread_mutex_lock(&spider_init_error_tbl_mutex); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) + my_hash_search_using_hash_value(&spider_init_error_tables, hash_value, + (uchar*) name, length))) +#else + if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search( + &spider_init_error_tables, (uchar*) name, length))) +#endif + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_init_error_tables, + spider_init_error_table->table_name_hash_value, + (uchar*) spider_init_error_table); +#else + my_hash_delete(&spider_init_error_tables, + (uchar*) spider_init_error_table); +#endif + spider_free(spider_current_trx, spider_init_error_table, MYF(0)); + } + pthread_mutex_unlock(&spider_init_error_tbl_mutex); + DBUG_VOID_RETURN; +} + +bool spider_check_pk_update( + TABLE *table +) { + int roop_count; + TABLE_SHARE *table_share = table->s; + KEY *key_info; + KEY_PART_INFO *key_part; + DBUG_ENTER("spider_check_pk_update"); + if (table_share->primary_key == MAX_KEY) + DBUG_RETURN(FALSE); + + key_info = &table_share->key_info[table_share->primary_key]; + key_part = key_info->key_part; + for (roop_count = 0; roop_count < (int) key_info->key_parts; roop_count++) + { + if (bitmap_is_set(table->write_set, + key_part[roop_count].field->field_index)) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +bool spider_check_hs_pk_update( + ha_spider *spider, + key_range *key +) { + uint roop_count, field_index, set_count = 0; + TABLE *table = spider->get_table(); + TABLE_SHARE *table_share = table->s; + SPIDER_SHARE *share = spider->share; + KEY *key_info; + KEY_PART_INFO *key_part; + char buf[MAX_FIELD_WIDTH], buf2[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin), + tmp_str2(buf2, MAX_FIELD_WIDTH, &my_charset_bin); + String *str, *str2; + DBUG_ENTER("spider_check_hs_pk_update"); + tmp_str.init_calc_mem(137); + + if (table_share->primary_key == MAX_KEY) + DBUG_RETURN(FALSE); + memset(spider->tmp_column_bitmap, 0, sizeof(uchar) * share->bitmap_size); + key_info = &table->key_info[table_share->primary_key]; + key_part = key_info->key_part; + for (roop_count = 0; roop_count < key_info->key_parts; roop_count++) + { + field_index = key_part[roop_count].field->field_index; + if (bitmap_is_set(table->write_set, field_index)) + { + DBUG_PRINT("info", ("spider set key_part=%u field_index=%u", + roop_count, field_index)); + spider_set_bit(spider->tmp_column_bitmap, field_index); + set_count++; + } + } + DBUG_PRINT("info", ("spider set_count=%u", set_count)); + + Field *field; + uint store_length, length, var_len; + const uchar *ptr; + bool key_eq; + key_part_map tgt_key_part_map = key->keypart_map; + key_info = &table->key_info[spider->active_index]; + for ( + key_part = key_info->key_part, + length = 0; + tgt_key_part_map; + length += store_length, + tgt_key_part_map >>= 1, + key_part++ + ) { + store_length = key_part->store_length; + field = key_part->field; + field_index = field->field_index; + if (spider_bit_is_set(spider->tmp_column_bitmap, field_index)) + { + ptr = key->key + length; + key_eq = (tgt_key_part_map > 1); + if (key_part->null_bit && *ptr++) + { + if (key->flag != HA_READ_KEY_EXACT || !field->is_null()) + { + DBUG_PRINT("info", ("spider flag=%u is_null=%s", + key->flag, field->is_null() ? "TRUE" : "FALSE")); + DBUG_RETURN(TRUE); + } + } else { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR || + field->type() == MYSQL_TYPE_GEOMETRY + ) { + var_len = uint2korr(ptr); + tmp_str.set_quick((char *) ptr + HA_KEY_BLOB_LENGTH, var_len, + &my_charset_bin); + str = tmp_str.get_str(); + } else { + str = field->val_str(tmp_str.get_str(), ptr); + tmp_str.mem_calc(); + } + str2 = field->val_str(tmp_str2.get_str()); + tmp_str2.mem_calc(); + if ( + str->length() != str2->length() || + memcmp(str->ptr(), str2->ptr(), str->length()) + ) { + DBUG_PRINT("info", ("spider length=%u %u", + str->length(), str2->length())); + DBUG_PRINT("info", ("spider length=%s %s", + str->c_ptr_safe(), str2->c_ptr_safe())); + DBUG_RETURN(TRUE); + } + } + set_count--; + } + } + DBUG_PRINT("info", ("spider set_count=%u", set_count)); + if (set_count) + { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} +#endif +#endif + +void spider_set_tmp_share_pointer( + SPIDER_SHARE *tmp_share, + char **tmp_connect_info, + uint *tmp_connect_info_length, + long *tmp_long, + longlong *tmp_longlong +) { + DBUG_ENTER("spider_set_tmp_share_pointer"); + tmp_share->link_count = 1; + tmp_share->all_link_count = 1; + tmp_share->server_names = &tmp_connect_info[0]; + tmp_share->tgt_table_names = &tmp_connect_info[1]; + tmp_share->tgt_dbs = &tmp_connect_info[2]; + tmp_share->tgt_hosts = &tmp_connect_info[3]; + tmp_share->tgt_usernames = &tmp_connect_info[4]; + tmp_share->tgt_passwords = &tmp_connect_info[5]; + tmp_share->tgt_sockets = &tmp_connect_info[6]; + tmp_share->tgt_wrappers = &tmp_connect_info[7]; + tmp_share->tgt_ssl_cas = &tmp_connect_info[8]; + tmp_share->tgt_ssl_capaths = &tmp_connect_info[9]; + tmp_share->tgt_ssl_certs = &tmp_connect_info[10]; + tmp_share->tgt_ssl_ciphers = &tmp_connect_info[11]; + tmp_share->tgt_ssl_keys = &tmp_connect_info[12]; + tmp_share->tgt_default_files = &tmp_connect_info[13]; + tmp_share->tgt_default_groups = &tmp_connect_info[14]; + tmp_share->tgt_pk_names = &tmp_connect_info[15]; + tmp_share->tgt_sequence_names = &tmp_connect_info[16]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + tmp_share->hs_read_socks = &tmp_connect_info[17]; + tmp_share->hs_write_socks = &tmp_connect_info[18]; +#endif + tmp_share->tgt_ports = &tmp_long[0]; + tmp_share->tgt_ssl_vscs = &tmp_long[1]; + tmp_share->link_statuses = &tmp_long[2]; + tmp_share->monitoring_kind = &tmp_long[3]; +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_kind = &tmp_long[4]; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + tmp_share->use_hs_reads = &tmp_long[5]; + tmp_share->use_hs_writes = &tmp_long[6]; + tmp_share->hs_read_ports = &tmp_long[7]; + tmp_share->hs_write_ports = &tmp_long[8]; + tmp_share->hs_write_to_reads = &tmp_long[9]; +#endif + tmp_share->use_handlers = &tmp_long[10]; + tmp_share->connect_timeouts = &tmp_long[11]; + tmp_long[11] = -1; + tmp_share->net_read_timeouts = &tmp_long[12]; + tmp_long[12] = -1; + tmp_share->net_write_timeouts = &tmp_long[13]; + tmp_long[13] = -1; + tmp_share->access_balances = &tmp_long[14]; + tmp_share->monitoring_limit = &tmp_longlong[0]; + tmp_share->monitoring_sid = &tmp_longlong[1]; +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_interval = &tmp_longlong[2]; +#endif + tmp_share->server_names_lengths = &tmp_connect_info_length[0]; + tmp_share->tgt_table_names_lengths = &tmp_connect_info_length[1]; + tmp_share->tgt_dbs_lengths = &tmp_connect_info_length[2]; + tmp_share->tgt_hosts_lengths = &tmp_connect_info_length[3]; + tmp_share->tgt_usernames_lengths = &tmp_connect_info_length[4]; + tmp_share->tgt_passwords_lengths = &tmp_connect_info_length[5]; + tmp_share->tgt_sockets_lengths = &tmp_connect_info_length[6]; + tmp_share->tgt_wrappers_lengths = &tmp_connect_info_length[7]; + tmp_share->tgt_ssl_cas_lengths = &tmp_connect_info_length[8]; + tmp_share->tgt_ssl_capaths_lengths = &tmp_connect_info_length[9]; + tmp_share->tgt_ssl_certs_lengths = &tmp_connect_info_length[10]; + tmp_share->tgt_ssl_ciphers_lengths = &tmp_connect_info_length[11]; + tmp_share->tgt_ssl_keys_lengths = &tmp_connect_info_length[12]; + tmp_share->tgt_default_files_lengths = &tmp_connect_info_length[13]; + tmp_share->tgt_default_groups_lengths = &tmp_connect_info_length[14]; + tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[15]; + tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[16]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + tmp_share->hs_read_socks_lengths = &tmp_connect_info_length[17]; + tmp_share->hs_write_socks_lengths = &tmp_connect_info_length[18]; +#endif + tmp_share->server_names_length = 1; + tmp_share->tgt_table_names_length = 1; + tmp_share->tgt_dbs_length = 1; + tmp_share->tgt_hosts_length = 1; + tmp_share->tgt_usernames_length = 1; + tmp_share->tgt_passwords_length = 1; + tmp_share->tgt_sockets_length = 1; + tmp_share->tgt_wrappers_length = 1; + tmp_share->tgt_ssl_cas_length = 1; + tmp_share->tgt_ssl_capaths_length = 1; + tmp_share->tgt_ssl_certs_length = 1; + tmp_share->tgt_ssl_ciphers_length = 1; + tmp_share->tgt_ssl_keys_length = 1; + tmp_share->tgt_default_files_length = 1; + tmp_share->tgt_default_groups_length = 1; + tmp_share->tgt_pk_names_length = 1; + tmp_share->tgt_sequence_names_length = 1; + tmp_share->tgt_ports_length = 1; + tmp_share->tgt_ssl_vscs_length = 1; + tmp_share->link_statuses_length = 1; + tmp_share->monitoring_kind_length = 1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_kind_length = 1; +#endif + tmp_share->monitoring_limit_length = 1; + tmp_share->monitoring_sid_length = 1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_interval_length = 1; +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + tmp_share->hs_read_socks_length = 1; + tmp_share->hs_write_socks_length = 1; + tmp_share->use_hs_reads_length = 1; + tmp_share->use_hs_writes_length = 1; + tmp_share->hs_read_ports_length = 1; + tmp_share->hs_write_ports_length = 1; + tmp_share->hs_write_to_reads_length = 1; +#endif + tmp_share->use_handlers_length = 1; + tmp_share->connect_timeouts_length = 1; + tmp_share->net_read_timeouts_length = 1; + tmp_share->net_write_timeouts_length = 1; + tmp_share->access_balances_length = 1; + +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_kind[0] = -1; +#endif + tmp_share->monitoring_kind[0] = -1; +#ifndef WITHOUT_SPIDER_BG_SEARCH + tmp_share->monitoring_bg_interval[0] = -1; +#endif + tmp_share->monitoring_limit[0] = -1; + tmp_share->monitoring_sid[0] = -1; + tmp_share->bka_engine = NULL; + tmp_share->use_dbton_count = 0; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + tmp_share->use_hs_dbton_count = 0; +#endif + DBUG_VOID_RETURN; +} + +int spider_create_tmp_dbton_share( + SPIDER_SHARE *tmp_share +) { + int error_num; + uint dbton_id = tmp_share->use_dbton_ids[0]; + DBUG_ENTER("spider_create_tmp_dbton_share"); + if (!(tmp_share->dbton_share[dbton_id] = + spider_dbton[dbton_id].create_db_share(tmp_share))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if ((error_num = tmp_share->dbton_share[dbton_id]->init())) + { + delete tmp_share->dbton_share[dbton_id]; + tmp_share->dbton_share[dbton_id] = NULL; + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +void spider_free_tmp_dbton_share( + SPIDER_SHARE *tmp_share +) { + uint dbton_id = tmp_share->use_dbton_ids[0]; + DBUG_ENTER("spider_free_tmp_dbton_share"); + if (tmp_share->dbton_share[dbton_id]) + { + delete tmp_share->dbton_share[dbton_id]; + tmp_share->dbton_share[dbton_id] = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_create_tmp_dbton_handler( + ha_spider *tmp_spider +) { + int error_num; + SPIDER_SHARE *tmp_share = tmp_spider->share; + uint dbton_id = tmp_share->use_dbton_ids[0]; + DBUG_ENTER("spider_create_tmp_dbton_handler"); + if (!(tmp_spider->dbton_handler[dbton_id] = + spider_dbton[dbton_id].create_db_handler(tmp_spider, + tmp_share->dbton_share[dbton_id]))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if ((error_num = tmp_spider->dbton_handler[dbton_id]->init())) + { + delete tmp_spider->dbton_handler[dbton_id]; + tmp_spider->dbton_handler[dbton_id] = NULL; + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +void spider_free_tmp_dbton_handler( + ha_spider *tmp_spider +) { + SPIDER_SHARE *tmp_share = tmp_spider->share; + uint dbton_id = tmp_share->use_dbton_ids[0]; + DBUG_ENTER("spider_create_tmp_dbton_handler"); + if (tmp_spider->dbton_handler[dbton_id]) + { + delete tmp_spider->dbton_handler[dbton_id]; + tmp_spider->dbton_handler[dbton_id] = NULL; + } + DBUG_VOID_RETURN; +} + +void spider_get_select_limit( + ha_spider *spider, + st_select_lex **select_lex, + longlong *select_limit, + longlong *offset_limit +) { + TABLE *table = spider->get_table(); + TABLE_LIST *table_list = table->pos_in_table_list; + DBUG_ENTER("spider_get_select_limit"); + *select_lex = NULL; + *select_limit = 9223372036854775807LL; + *offset_limit = 0; + if (table_list) + { + while (table_list->parent_l) + table_list = table_list->parent_l; + *select_lex = table_list->select_lex; + if (*select_lex && (*select_lex)->explicit_limit) + { + *select_limit = (*select_lex)->select_limit ? + (*select_lex)->select_limit->val_int() : 0; + *offset_limit = (*select_lex)->offset_limit ? + (*select_lex)->offset_limit->val_int() : 0; + } + } + DBUG_VOID_RETURN; +} + +longlong spider_split_read_param( + ha_spider *spider +) { + SPIDER_SHARE *share = spider->share; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + THD *thd = spider->trx->thd; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + double semi_split_read; + longlong split_read; + DBUG_ENTER("spider_split_read_param"); + result_list->set_split_read_count = 1; +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + if (spider->info_limit < 9223372036854775807LL) + { + DBUG_PRINT("info",("spider info_limit=%lld", spider->info_limit)); + longlong info_limit = spider->info_limit; + result_list->split_read_base = info_limit; + result_list->semi_split_read = 0; + result_list->first_read = info_limit; + result_list->second_read = info_limit; + result_list->semi_split_read_base = 0; + result_list->set_split_read = FALSE; + DBUG_RETURN(info_limit); + } +#endif + if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) + { + DBUG_RETURN(result_list->semi_split_read_base); + } + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + if (!result_list->set_split_read) + { + result_list->split_read_base = + spider_param_split_read(thd, share->split_read); + result_list->semi_split_read = + spider_param_semi_split_read(thd, share->semi_split_read); + result_list->semi_split_read_limit = + spider_param_semi_split_read_limit(thd, share->semi_split_read_limit); + result_list->first_read = + spider_param_first_read(thd, share->first_read); + result_list->second_read = + spider_param_second_read(thd, share->second_read); + result_list->semi_split_read_base = 0; + result_list->set_split_read = TRUE; + } + if ( + result_list->semi_split_read > 0 && + select_lex && select_lex->explicit_limit && + !(select_lex->options & OPTION_FOUND_ROWS) && + !select_lex->group_list.elements && + !select_lex->with_sum_func + ) { + semi_split_read = result_list->semi_split_read * + (select_limit + offset_limit); + DBUG_PRINT("info",("spider semi_split_read=%f", semi_split_read)); + if (semi_split_read >= result_list->semi_split_read_limit) + { + result_list->semi_split_read_base = result_list->semi_split_read_limit; + DBUG_RETURN(result_list->semi_split_read_limit); + } else { + split_read = (longlong) semi_split_read; + if (split_read < 0) + { + result_list->semi_split_read_base = result_list->semi_split_read_limit; + DBUG_RETURN(result_list->semi_split_read_limit); + } else if (split_read == 0) + { + result_list->semi_split_read_base = 1; + DBUG_RETURN(1); + } else { + result_list->semi_split_read_base = split_read; + DBUG_RETURN(split_read); + } + } + } else if (result_list->first_read > 0) + DBUG_RETURN(result_list->first_read); + DBUG_RETURN(result_list->split_read_base); +} + +longlong spider_bg_split_read_param( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_bg_split_read_param"); + if (result_list->semi_split_read_base) + DBUG_RETURN(result_list->semi_split_read_base); + DBUG_RETURN(result_list->split_read_base); +} + +void spider_first_split_read_param( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_first_split_read_param"); + if (result_list->semi_split_read_base) + result_list->split_read = result_list->semi_split_read_base; + else if (result_list->second_read > 0) + result_list->split_read = result_list->first_read; + else + result_list->split_read = result_list->split_read_base; + result_list->set_split_read_count = 1; + DBUG_VOID_RETURN; +} + +void spider_next_split_read_param( + ha_spider *spider +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_next_split_read_param"); + if (result_list->semi_split_read_base) + result_list->split_read = result_list->semi_split_read_base; + else if ( + result_list->set_split_read_count == 1 && + result_list->second_read > 0 + ) + result_list->split_read = result_list->second_read; + else + result_list->split_read = result_list->split_read_base; + result_list->set_split_read_count++; + DBUG_VOID_RETURN; +} + +bool spider_check_direct_order_limit( + ha_spider *spider +) { + THD *thd = spider->trx->thd; + SPIDER_SHARE *share = spider->share; + longlong direct_order_limit = spider_param_direct_order_limit(thd, + share->direct_order_limit); + DBUG_ENTER("spider_check_direct_order_limit"); + if ( + direct_order_limit && + spider->sql_command != SQLCOM_HA_READ + ) { + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + DBUG_PRINT("info",("spider select_limit=%lld", select_limit)); + DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); + if ( +#if MYSQL_VERSION_ID < 50500 + !thd->variables.engine_condition_pushdown || +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + !select_lex || + !select_lex->explicit_limit || + (select_lex->options & OPTION_FOUND_ROWS) || + select_lex->group_list.elements || + select_lex->with_sum_func || + select_lex->having || + select_lex->table_list.elements != 1 || + !select_lex->order_list.elements || + select_limit > direct_order_limit - offset_limit + ) { + DBUG_PRINT("info",("spider FALSE by select_lex")); + DBUG_RETURN(FALSE); + } + ORDER *order; + for (order = (ORDER *) select_lex->order_list.first; order; + order = order->next) + { + if (spider->print_item_type((*order->item), NULL, NULL, 0)) + { + DBUG_PRINT("info",("spider FALSE by order")); + DBUG_RETURN(FALSE); + } + } + if (spider_db_append_condition(spider, NULL, 0, TRUE)) + { + DBUG_PRINT("info",("spider FALSE by condition")); + DBUG_RETURN(FALSE); + } + DBUG_PRINT("info",("spider TRUE")); + spider->result_list.internal_limit = select_limit + offset_limit; + spider->result_list.split_read = select_limit + offset_limit; + spider->trx->direct_order_limit_count++; + DBUG_RETURN(TRUE); + } + DBUG_PRINT("info",("spider FALSE by parameter")); + DBUG_RETURN(FALSE); +} + +int spider_compare_for_sort( + SPIDER_SORT *a, + SPIDER_SORT *b +) { + DBUG_ENTER("spider_compare_for_sort"); + if (a->sort > b->sort) + DBUG_RETURN(-1); + if (a->sort < b->sort) + DBUG_RETURN(1); + DBUG_RETURN(0); +} + +ulong spider_calc_for_sort( + uint count, + ... +) { + ulong sort = 0; + va_list args; + va_start(args, count); + DBUG_ENTER("spider_calc_for_sort"); + while (count--) + { + char *start = va_arg(args, char *), *str; + uint wild_pos = 0; + + if ((str = start)) + { + wild_pos = 128; + for (; *str; str++) + { + if (*str == spider_wild_prefix && str[1]) + str++; + else if (*str == spider_wild_many || *str == spider_wild_one) + { + wild_pos = (uint) (str - start) + 1; + if (wild_pos > 127) + wild_pos = 127; + break; + } + } + } + sort = (sort << 8) + wild_pos; + } + va_end(args); + DBUG_RETURN(sort); +} + +double spider_rand( + uint32 rand_source +) { +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + struct my_rnd_struct rand; +#else + struct rand_struct rand; +#endif + DBUG_ENTER("spider_rand"); + /* generate same as rand function for applications */ +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), + (uint32) (rand_source * 268435457L)); +#else + randominit(&rand, (uint32) (rand_source * 65537L + 55555555L), + (uint32) (rand_source * 268435457L)); +#endif + DBUG_RETURN(my_rnd(&rand)); +} + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_discover_table_structure_internal( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +) { + int error_num, roop_count; + DBUG_ENTER("spider_discover_table_structure"); + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + if (spider_bit_is_set(spider_share->dbton_bitmap, roop_count)) + { + if ((error_num = spider_share->dbton_share[roop_count]-> + discover_table_structure(trx, spider_share, str))) + { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_discover_table_structure( + handlerton *hton, + THD* thd, + TABLE_SHARE *share, + HA_CREATE_INFO *info +) { + int error_num = HA_ERR_WRONG_COMMAND; + SPIDER_SHARE *spider_share; + const char *table_name = share->path.str; + uint table_name_length = (uint) strlen(table_name); + SPIDER_TRX *trx; +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info = thd->work_part_info; +#endif + uint str_len; + char buf[MAX_FIELD_WIDTH]; + spider_string str(buf, sizeof(buf), system_charset_info); + DBUG_ENTER("spider_discover_table_structure"); + str.init_calc_mem(229); + str.length(0); + if (str.reserve( + SPIDER_SQL_CREATE_TABLE_LEN + share->db.length + + SPIDER_SQL_DOT_LEN + share->table_name.length + + /* SPIDER_SQL_LCL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN + )) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str.q_append(SPIDER_SQL_CREATE_TABLE_STR, SPIDER_SQL_CREATE_TABLE_LEN); + str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); + str.q_append(share->db.str, share->db.length); + str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); + str.q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); + str.q_append(share->table_name.str, share->table_name.length); + str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); + str.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str_len = str.length(); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_name, table_name_length); +#endif + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + DBUG_PRINT("info",("spider spider_get_trx error")); + my_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + share->table_charset = info->default_table_charset; + share->comment = info->comment; +#ifdef WITH_PARTITION_STORAGE_ENGINE + if (!part_info) + { +#endif + if (!(spider_share = spider_create_share(table_name, share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + NULL, +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value, +#endif + &error_num + ))) { + DBUG_RETURN(error_num); + } + + error_num = spider_discover_table_structure_internal(trx, spider_share, &str); + + spider_free_share_resource_only(spider_share); +#ifdef WITH_PARTITION_STORAGE_ENGINE + } else { + char tmp_name[FN_LEN]; + List_iterator part_it(part_info->partitions); + partition_element *part_elem, *sub_elem; + while ((part_elem = part_it++)) + { + if ((part_elem)->subpartitions.elements) + { + List_iterator sub_it((part_elem)->subpartitions); + while ((sub_elem = sub_it++)) + { + str.length(str_len); + create_subpartition_name(tmp_name, table_name, + (part_elem)->partition_name, (sub_elem)->partition_name, + NORMAL_PART_NAME); + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(table_name, share, + part_info, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value, +#endif + &error_num + ))) { + continue; + } + + error_num = spider_discover_table_structure_internal( + trx, spider_share, &str); + + spider_free_share_resource_only(spider_share); + if (!error_num) + break; + } + if (!error_num) + break; + } else { + str.length(str_len); + create_partition_name(tmp_name, table_name, + (part_elem)->partition_name, NORMAL_PART_NAME, TRUE); + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(table_name, share, + part_info, +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + hash_value, +#endif + &error_num + ))) { + continue; + } + + error_num = spider_discover_table_structure_internal( + trx, spider_share, &str); + + spider_free_share_resource_only(spider_share); + if (!error_num) + break; + } + } + } +#endif + + if (!error_num) + thd->clear_error(); + else + DBUG_RETURN(error_num); + + str.length(str.length() - SPIDER_SQL_COMMA_LEN); + uint csnamelen = strlen(share->table_charset->csname); + uint collatelen = strlen(share->table_charset->name); + if (str.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_DEFAULT_CHARSET_LEN + + csnamelen + SPIDER_SQL_COLLATE_LEN + collatelen + + SPIDER_SQL_CONNECTION_LEN + SPIDER_SQL_VALUE_QUOTE_LEN + )) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + str.q_append(SPIDER_SQL_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN); + str.q_append(share->table_charset->csname, csnamelen); + str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str.q_append(share->table_charset->name, collatelen); + str.q_append(SPIDER_SQL_COMMENT_STR, SPIDER_SQL_COMMENT_LEN); + str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (str.append_for_single_quote(share->comment.str, share->comment.length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str.reserve(SPIDER_SQL_CONNECTION_LEN + + (SPIDER_SQL_VALUE_QUOTE_LEN * 2))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str.q_append(SPIDER_SQL_CONNECTION_STR, SPIDER_SQL_CONNECTION_LEN); + str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + if (str.append_for_single_quote(share->connect_string.str, + share->connect_string.length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str.reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); +#ifdef WITH_PARTITION_STORAGE_ENGINE + DBUG_PRINT("info",("spider part_info=%p", part_info)); + if (part_info) + { + uint part_syntax_len; + char *part_syntax; + List_iterator part_it(part_info->partitions); + partition_element *part_elem, *sub_elem; + while ((part_elem = part_it++)) + { + part_elem->engine_type = hton; + if ((part_elem)->subpartitions.elements) + { + List_iterator sub_it((part_elem)->subpartitions); + while ((sub_elem = sub_it++)) + { + sub_elem->engine_type = hton; + } + } + } + if (part_info->fix_parser_data(thd)) + { + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } +#ifdef SPIDER_GENERATE_PARTITION_SYNTAX_HAS_CURRENT_COMMENT_START + if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len, + FALSE, TRUE, info, NULL, NULL))) +#else + if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len, + FALSE, TRUE, info, NULL))) +#endif + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str.reserve(part_syntax_len)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str.q_append(part_syntax, part_syntax_len); + my_free(part_syntax, MYF(0)); + } +#endif + DBUG_PRINT("info",("spider str=%s", str.c_ptr_safe())); + + error_num = share->init_from_sql_statement_string(thd, TRUE, str.ptr(), + str.length()); + DBUG_RETURN(error_num); +} +#endif diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h new file mode 100644 index 00000000000..7a0732276dc --- /dev/null +++ b/storage/spider/spd_table.h @@ -0,0 +1,412 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +uchar *spider_tbl_get_key( + SPIDER_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +#ifdef WITH_PARTITION_STORAGE_ENGINE +uchar *spider_pt_share_get_key( + SPIDER_PARTITION_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +uchar *spider_pt_handler_share_get_key( + SPIDER_PARTITION_HANDLER_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); +#endif + +uchar *spider_link_get_key( + SPIDER_LINK_FOR_HASH *link_for_hash, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +uchar *spider_ha_get_key( + ha_spider *spider, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +int spider_get_server( + SPIDER_SHARE *share, + int link_idx +); + +int spider_free_share_alloc( + SPIDER_SHARE *share +); + +void spider_free_tmp_share_alloc( + SPIDER_SHARE *share +); + +char *spider_get_string_between_quote( + char *ptr, + bool alloc +); + +int spider_create_string_list( + char ***string_list, + uint **string_length_list, + uint *list_length, + char *str, + uint length +); + +int spider_create_long_list( + long **long_list, + uint *list_length, + char *str, + uint length, + long min_val, + long max_val +); + +int spider_create_longlong_list( + longlong **longlong_list, + uint *list_length, + char *str, + uint length, + longlong min_val, + longlong max_val +); + +int spider_increase_string_list( + char ***string_list, + uint **string_length_list, + uint *list_length, + uint *list_charlen, + uint link_count +); + +int spider_increase_long_list( + long **long_list, + uint *list_length, + uint link_count +); + +int spider_increase_longlong_list( + longlong **longlong_list, + uint *list_length, + uint link_count +); + +int spider_parse_connect_info( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info, +#endif + uint create_table +); + +int spider_set_connect_info_default( + SPIDER_SHARE *share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_element *part_elem, + partition_element *sub_elem, +#endif + TABLE_SHARE *table_share +); + +int spider_set_connect_info_default_db_table( + SPIDER_SHARE *share, + const char *db_name, + uint db_name_length, + const char *table_name, + uint table_name_length +); + +int spider_set_connect_info_default_dbtable( + SPIDER_SHARE *share, + const char *dbtable_name, + int dbtable_name_length +); + +#ifndef DBUG_OFF +void spider_print_keys( + const char *key, + uint length +); +#endif + +int spider_create_conn_keys( + SPIDER_SHARE *share +); + +SPIDER_SHARE *spider_create_share( + const char *table_name, + TABLE_SHARE *table_share, +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info, +#endif +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value, +#endif + int *error_num +); + +SPIDER_SHARE *spider_get_share( + const char *table_name, + TABLE *table, + THD *thd, + ha_spider *spider, + int *error_num +); + +void spider_free_share_resource_only( + SPIDER_SHARE *share +); + +int spider_free_share( + SPIDER_SHARE *share +); + +#ifdef WITH_PARTITION_STORAGE_ENGINE +SPIDER_PARTITION_SHARE *spider_get_pt_share( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, + int *error_num +); + +int spider_free_pt_share( + SPIDER_PARTITION_SHARE *partition_share +); + +void spider_copy_sts_to_pt_share( + SPIDER_PARTITION_SHARE *partition_share, + SPIDER_SHARE *share +); + +void spider_copy_sts_to_share( + SPIDER_SHARE *share, + SPIDER_PARTITION_SHARE *partition_share +); + +void spider_copy_crd_to_pt_share( + SPIDER_PARTITION_SHARE *partition_share, + SPIDER_SHARE *share, + int fields +); + +void spider_copy_crd_to_share( + SPIDER_SHARE *share, + SPIDER_PARTITION_SHARE *partition_share, + int fields +); +#endif + +int spider_open_all_tables( + SPIDER_TRX *trx, + bool lock +); + +bool spider_flush_logs( + handlerton *hton +); + +handler* spider_create_handler( + handlerton *hton, + TABLE_SHARE *table, + MEM_ROOT *mem_root +); + +int spider_close_connection( + handlerton* hton, + THD* thd +); + +void spider_drop_database( + handlerton *hton, + char* path +); + +bool spider_show_status( + handlerton *hton, + THD *thd, + stat_print_fn *stat_print, + enum ha_stat_type stat_type +); + +int spider_db_done( + void *p +); + +int spider_panic( + handlerton *hton, + ha_panic_function type +); + +int spider_db_init( + void *p +); + +char *spider_create_table_name_string( + const char *table_name, + const char *part_name, + const char *sub_name +); + +#ifdef WITH_PARTITION_STORAGE_ENGINE +void spider_get_partition_info( + const char *table_name, + uint table_name_length, + const TABLE_SHARE *table_share, + partition_info *part_info, + partition_element **part_elem, + partition_element **sub_elem +); +#endif + +int spider_get_sts( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + double sts_interval, + int sts_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + int sts_sync, +#endif + int sts_sync_level, + uint flag +); + +int spider_get_crd( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + TABLE *table, + double crd_interval, + int crd_mode, +#ifdef WITH_PARTITION_STORAGE_ENGINE + int crd_sync, +#endif + int crd_sync_level +); + +void spider_set_result_list_param( + ha_spider *spider +); + +SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + bool create +); + +void spider_delete_init_error_table( + const char *name +); + +bool spider_check_pk_update( + TABLE *table +); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +bool spider_check_hs_pk_update( + ha_spider *spider, + key_range *key +); +#endif +#endif + +void spider_set_tmp_share_pointer( + SPIDER_SHARE *tmp_share, + char **tmp_connect_info, + uint *tmp_connect_info_length, + long *tmp_long, + longlong *tmp_longlong +); + +int spider_create_tmp_dbton_share( + SPIDER_SHARE *tmp_share +); + +void spider_free_tmp_dbton_share( + SPIDER_SHARE *tmp_share +); + +int spider_create_tmp_dbton_handler( + ha_spider *tmp_spider +); + +void spider_free_tmp_dbton_handler( + ha_spider *tmp_spider +); + +void spider_get_select_limit( + ha_spider *spider, + st_select_lex **select_lex, + longlong *select_limit, + longlong *offset_limit +); + +longlong spider_split_read_param( + ha_spider *spider +); + +longlong spider_bg_split_read_param( + ha_spider *spider +); + +void spider_first_split_read_param( + ha_spider *spider +); + +void spider_next_split_read_param( + ha_spider *spider +); + +bool spider_check_direct_order_limit( + ha_spider *spider +); + +int spider_compare_for_sort( + SPIDER_SORT *a, + SPIDER_SORT *b +); + +ulong spider_calc_for_sort( + uint count, + ... +); + +double spider_rand( + uint32 rand_source +); + +#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE +int spider_discover_table_structure_internal( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +); + +int spider_discover_table_structure( + handlerton *hton, + THD* thd, + TABLE_SHARE *share, + HA_CREATE_INFO *info +); +#endif diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc new file mode 100644 index 00000000000..4bd1cbcae99 --- /dev/null +++ b/storage/spider/spd_trx.cc @@ -0,0 +1,4049 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include "mysql_version.h" +#if MYSQL_VERSION_ID < 50500 +#include "mysql_priv.h" +#include +#else +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "records.h" +#endif +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_sys_table.h" +#include "ha_spider.h" +#include "spd_trx.h" +#include "spd_db_conn.h" +#include "spd_table.h" +#include "spd_conn.h" +#include "spd_ping_table.h" +#include "spd_malloc.h" + +extern pthread_mutex_t *spd_db_att_LOCK_xid_cache; +extern HASH *spd_db_att_xid_cache; +extern struct charset_info_st *spd_charset_utf8_bin; + +extern handlerton *spider_hton_ptr; +pthread_mutex_t spider_thread_id_mutex; +ulonglong spider_thread_id = 1; + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key spd_key_mutex_udf_table; +#endif + +extern HASH spider_allocated_thds; +extern uint spider_allocated_thds_id; +extern const char *spider_allocated_thds_func_name; +extern const char *spider_allocated_thds_file_name; +extern ulong spider_allocated_thds_line_no; +extern pthread_mutex_t spider_allocated_thds_mutex; + +// for spider_alter_tables +uchar *spider_alter_tbl_get_key( + SPIDER_ALTER_TABLE *alter_table, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_alter_tbl_get_key"); + *length = alter_table->table_name_length; + DBUG_PRINT("info",("spider table_name_length=%zu", *length)); + DBUG_PRINT("info",("spider table_name=%s", alter_table->table_name)); + DBUG_RETURN((uchar*) alter_table->table_name); +} + +// for SPIDER_TRX_HA +uchar *spider_trx_ha_get_key( + SPIDER_TRX_HA *trx_ha, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_trx_ha_get_key"); + *length = trx_ha->table_name_length; + DBUG_PRINT("info",("spider table_name_length=%zu", *length)); + DBUG_PRINT("info",("spider table_name=%s", trx_ha->table_name)); + DBUG_RETURN((uchar*) trx_ha->table_name); +} + +int spider_free_trx_conn( + SPIDER_TRX *trx, + bool trx_free +) { + int roop_count; + SPIDER_CONN *conn; + DBUG_ENTER("spider_free_trx_conn"); + roop_count = 0; + if ( + trx_free || + spider_param_conn_recycle_mode(trx->thd) != 2 + ) { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + spider_conn_clear_queue_at_commit(conn); + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + roop_count++; + } else + spider_free_conn_from_trx(trx, conn, FALSE, trx_free, &roop_count); + } + trx->trx_conn_adjustment++; + } else { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + spider_conn_clear_queue_at_commit(conn); + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + } else + conn->error_mode = 1; + roop_count++; + } + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + roop_count = 0; + if ( + trx_free || + spider_param_hs_r_conn_recycle_mode(trx->thd) != 2 + ) { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_hs_r_conn_hash, + roop_count))) + { + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + roop_count++; + } else + spider_free_conn_from_trx(trx, conn, FALSE, trx_free, &roop_count); + } + trx->trx_hs_r_conn_adjustment++; + } else { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_hs_r_conn_hash, + roop_count))) + { + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + } else + conn->error_mode = 1; + roop_count++; + } + } + roop_count = 0; + if ( + trx_free || + spider_param_hs_w_conn_recycle_mode(trx->thd) != 2 + ) { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_hs_w_conn_hash, + roop_count))) + { + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + roop_count++; + } else + spider_free_conn_from_trx(trx, conn, FALSE, trx_free, &roop_count); + } + trx->trx_hs_w_conn_adjustment++; + } else { + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_hs_w_conn_hash, + roop_count))) + { + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + } else + conn->error_mode = 1; + roop_count++; + } + } +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (trx_free) + { + while ((conn = (SPIDER_CONN*) my_hash_element( + &trx->trx_direct_hs_r_conn_hash, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_direct_hs_r_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_direct_hs_r_conn_hash, (uchar*) conn); +#endif + spider_free_conn(conn); + } + while ((conn = (SPIDER_CONN*) my_hash_element( + &trx->trx_direct_hs_w_conn_hash, 0))) + { +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_direct_hs_w_conn_hash, + conn->conn_key_hash_value, (uchar*) conn); +#else + my_hash_delete(&trx->trx_direct_hs_w_conn_hash, (uchar*) conn); +#endif + spider_free_conn(conn); + } + } +#endif + DBUG_RETURN(0); +} + +int spider_free_trx_another_conn( + SPIDER_TRX *trx, + bool lock +) { + int error_num, tmp_error_num; + int roop_count = 0, need_mon = 0; + SPIDER_CONN *conn; + ha_spider tmp_spider; + DBUG_ENTER("spider_free_trx_another_conn"); + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + error_num = 0; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_another_conn_hash, + roop_count))) + { + tmp_spider.trx = trx; + if (lock && (tmp_error_num = spider_db_unlock_tables(&tmp_spider, 0))) + error_num = tmp_error_num; + spider_free_conn_from_trx(trx, conn, TRUE, TRUE, &roop_count); + } + DBUG_RETURN(error_num); +} + +int spider_trx_another_lock_tables( + SPIDER_TRX *trx +) { + int error_num; + int roop_count = 0, need_mon = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + SPIDER_SHARE tmp_share; + char sql_buf[MAX_FIELD_WIDTH]; + spider_string sql_str(sql_buf, sizeof(sql_buf), system_charset_info); + DBUG_ENTER("spider_trx_another_lock_tables"); + SPIDER_BACKUP_DASTATUS; + sql_str.init_calc_mem(188); + sql_str.length(0); + memset(&tmp_spider, 0, sizeof(ha_spider)); + memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); + tmp_spider.share = &tmp_share; + tmp_spider.trx = trx; + tmp_share.access_charset = system_charset_info; +/* + if ((error_num = spider_db_append_set_names(&tmp_share))) + DBUG_RETURN(error_num); +*/ + tmp_spider.conns = &conn; + tmp_spider.result_list.sqls = &sql_str; + tmp_spider.need_mons = &need_mon; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_another_conn_hash, + roop_count))) + { + if ((error_num = spider_db_lock_tables(&tmp_spider, 0))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + { +/* + spider_db_free_set_names(&tmp_share); +*/ + DBUG_RETURN(error_num); + } + } + roop_count++; + } +/* + spider_db_free_set_names(&tmp_share); +*/ + DBUG_RETURN(0); +} + +int spider_trx_another_flush_tables( + SPIDER_TRX *trx +) { + int error_num; + int roop_count = 0, need_mon = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + SPIDER_SHARE tmp_share; + long tmp_link_statuses = SPIDER_LINK_STATUS_OK; + DBUG_ENTER("spider_trx_another_flush_tables"); + SPIDER_BACKUP_DASTATUS; + memset(&tmp_spider, 0, sizeof(ha_spider)); + tmp_share.link_count = 1; + tmp_share.all_link_count = 1; + tmp_share.link_statuses = &tmp_link_statuses; + tmp_share.link_statuses_length = 1; + tmp_spider.share = &tmp_share; + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_another_conn_hash, + roop_count))) + { + if ((error_num = spider_db_flush_tables(&tmp_spider, FALSE))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + DBUG_RETURN(error_num); + } + roop_count++; + } + DBUG_RETURN(0); +} + +int spider_trx_all_flush_tables( + SPIDER_TRX *trx +) { + int error_num; + int roop_count = 0, need_mon = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + SPIDER_SHARE tmp_share; + long tmp_link_statuses = SPIDER_LINK_STATUS_OK; + DBUG_ENTER("spider_trx_all_flush_tables"); + SPIDER_BACKUP_DASTATUS; + memset(&tmp_spider, 0, sizeof(ha_spider)); + tmp_share.link_count = 1; + tmp_share.all_link_count = 1; + tmp_share.link_statuses = &tmp_link_statuses; + tmp_share.link_statuses_length = 1; + tmp_spider.share = &tmp_share; + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + if ((error_num = spider_db_flush_tables(&tmp_spider, TRUE))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + DBUG_RETURN(error_num); + } + roop_count++; + } + DBUG_RETURN(0); +} + +int spider_trx_all_unlock_tables( + SPIDER_TRX *trx +) { + int error_num; + int roop_count = 0, need_mon = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + DBUG_ENTER("spider_trx_all_unlock_tables"); + SPIDER_BACKUP_DASTATUS; + memset(&tmp_spider, 0, sizeof(ha_spider)); + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + tmp_spider.trx = trx; + if ((error_num = spider_db_unlock_tables(&tmp_spider, 0))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + DBUG_RETURN(error_num); + } + roop_count++; + } + DBUG_RETURN(0); +} + +int spider_trx_all_start_trx( + SPIDER_TRX *trx +) { + int error_num, need_mon = 0; + int roop_count = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + DBUG_ENTER("spider_trx_all_start_trx"); + SPIDER_BACKUP_DASTATUS; + memset(&tmp_spider, 0, sizeof(ha_spider)); + tmp_spider.trx = trx; + tmp_spider.need_mons = &need_mon; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + if ( + (spider_param_sync_trx_isolation(trx->thd) && + (error_num = spider_check_and_set_trx_isolation(conn, &need_mon))) || + (error_num = spider_internal_start_trx(&tmp_spider, conn, 0)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + DBUG_RETURN(error_num); + } + roop_count++; + } + DBUG_RETURN(0); +} + +int spider_trx_all_flush_logs( + SPIDER_TRX *trx +) { + int error_num; + int roop_count = 0, need_mon = 0; + THD *thd = trx->thd; + SPIDER_CONN *conn; + ha_spider tmp_spider; + SPIDER_SHARE tmp_share; + long tmp_link_statuses = SPIDER_LINK_STATUS_OK; + uint conn_link_idx = 0; + long net_read_timeout = 600; + long net_write_timeout = 600; + DBUG_ENTER("spider_trx_all_flush_logs"); + SPIDER_BACKUP_DASTATUS; + memset(&tmp_spider, 0, sizeof(ha_spider)); + tmp_share.link_count = 1; + tmp_share.all_link_count = 1; + tmp_share.link_statuses = &tmp_link_statuses; + tmp_share.link_statuses_length = 1; + tmp_share.net_read_timeouts = &net_read_timeout; + tmp_share.net_read_timeouts_length = 1; + tmp_share.net_write_timeouts = &net_write_timeout; + tmp_share.net_write_timeouts_length = 1; + tmp_spider.share = &tmp_share; + tmp_spider.conns = &conn; + tmp_spider.need_mons = &need_mon; + tmp_spider.conn_link_idx = &conn_link_idx; + tmp_spider.trx = trx; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + if ((error_num = spider_db_flush_logs(&tmp_spider))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + DBUG_RETURN(error_num); + } + roop_count++; + } + DBUG_RETURN(0); +} + +void spider_free_trx_alter_table_alloc( + SPIDER_TRX *trx, + SPIDER_ALTER_TABLE *alter_table +) { + DBUG_ENTER("spider_free_trx_alter_table_alloc"); +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_alter_table_hash, + alter_table->table_name_hash_value, (uchar*) alter_table); +#else + my_hash_delete(&trx->trx_alter_table_hash, (uchar*) alter_table); +#endif + if (alter_table->tmp_char) + spider_free(trx, alter_table->tmp_char, MYF(0)); + spider_free(trx, alter_table, MYF(0)); + DBUG_VOID_RETURN; +} + +int spider_free_trx_alter_table( + SPIDER_TRX *trx +) { + SPIDER_ALTER_TABLE *alter_table; + DBUG_ENTER("spider_free_trx_alter_table"); + while ((alter_table = + (SPIDER_ALTER_TABLE*) my_hash_element(&trx->trx_alter_table_hash, 0))) + { + spider_free_trx_alter_table_alloc(trx, alter_table); + } + DBUG_RETURN(0); +} + +int spider_create_trx_alter_table( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + bool now_create +) { + int error_num, roop_count; + SPIDER_ALTER_TABLE *alter_table, *share_alter; + char *tmp_name; + char **tmp_server_names; + char **tmp_tgt_table_names; + char **tmp_tgt_dbs; + char **tmp_tgt_hosts; + char **tmp_tgt_usernames; + char **tmp_tgt_passwords; + char **tmp_tgt_sockets; + char **tmp_tgt_wrappers; + char **tmp_tgt_ssl_cas; + char **tmp_tgt_ssl_capaths; + char **tmp_tgt_ssl_certs; + char **tmp_tgt_ssl_ciphers; + char **tmp_tgt_ssl_keys; + char **tmp_tgt_default_files; + char **tmp_tgt_default_groups; + uint *tmp_server_names_lengths; + uint *tmp_tgt_table_names_lengths; + uint *tmp_tgt_dbs_lengths; + uint *tmp_tgt_hosts_lengths; + uint *tmp_tgt_usernames_lengths; + uint *tmp_tgt_passwords_lengths; + uint *tmp_tgt_sockets_lengths; + uint *tmp_tgt_wrappers_lengths; + uint *tmp_tgt_ssl_cas_lengths; + uint *tmp_tgt_ssl_capaths_lengths; + uint *tmp_tgt_ssl_certs_lengths; + uint *tmp_tgt_ssl_ciphers_lengths; + uint *tmp_tgt_ssl_keys_lengths; + uint *tmp_tgt_default_files_lengths; + uint *tmp_tgt_default_groups_lengths; + long *tmp_tgt_ports; + long *tmp_tgt_ssl_vscs; + long *tmp_link_statuses; + char *tmp_server_names_char; + char *tmp_tgt_table_names_char; + char *tmp_tgt_dbs_char; + char *tmp_tgt_hosts_char; + char *tmp_tgt_usernames_char; + char *tmp_tgt_passwords_char; + char *tmp_tgt_sockets_char; + char *tmp_tgt_wrappers_char; + char *tmp_tgt_ssl_cas_char; + char *tmp_tgt_ssl_capaths_char; + char *tmp_tgt_ssl_certs_char; + char *tmp_tgt_ssl_ciphers_char; + char *tmp_tgt_ssl_keys_char; + char *tmp_tgt_default_files_char; + char *tmp_tgt_default_groups_char; + uint old_elements; + + DBUG_ENTER("spider_create_trx_alter_table"); + share_alter = &share->alter_table; + + if (!(alter_table = (SPIDER_ALTER_TABLE *) + spider_bulk_malloc(spider_current_trx, 55, MYF(MY_WME | MY_ZEROFILL), + &alter_table, sizeof(*alter_table), + &tmp_name, sizeof(char) * (share->table_name_length + 1), + + &tmp_server_names, sizeof(char *) * share->all_link_count, + &tmp_tgt_table_names, sizeof(char *) * share->all_link_count, + &tmp_tgt_dbs, sizeof(char *) * share->all_link_count, + &tmp_tgt_hosts, sizeof(char *) * share->all_link_count, + &tmp_tgt_usernames, sizeof(char *) * share->all_link_count, + &tmp_tgt_passwords, sizeof(char *) * share->all_link_count, + &tmp_tgt_sockets, sizeof(char *) * share->all_link_count, + &tmp_tgt_wrappers, sizeof(char *) * share->all_link_count, + &tmp_tgt_ssl_cas, sizeof(char *) * share->all_link_count, + &tmp_tgt_ssl_capaths, sizeof(char *) * share->all_link_count, + &tmp_tgt_ssl_certs, sizeof(char *) * share->all_link_count, + &tmp_tgt_ssl_ciphers, sizeof(char *) * share->all_link_count, + &tmp_tgt_ssl_keys, sizeof(char *) * share->all_link_count, + &tmp_tgt_default_files, sizeof(char *) * share->all_link_count, + &tmp_tgt_default_groups, sizeof(char *) * share->all_link_count, + + &tmp_server_names_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_table_names_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_dbs_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_hosts_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_usernames_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_passwords_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_sockets_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_wrappers_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_ssl_cas_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_ssl_capaths_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_ssl_certs_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_ssl_ciphers_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_ssl_keys_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_default_files_lengths, sizeof(uint) * share->all_link_count, + &tmp_tgt_default_groups_lengths, sizeof(uint) * share->all_link_count, + + &tmp_tgt_ports, sizeof(long) * share->all_link_count, + &tmp_tgt_ssl_vscs, sizeof(long) * share->all_link_count, + &tmp_link_statuses, sizeof(long) * share->all_link_count, + + &tmp_server_names_char, sizeof(char) * + (share_alter->tmp_server_names_charlen + 1), + &tmp_tgt_table_names_char, sizeof(char) * + (share_alter->tmp_tgt_table_names_charlen + 1), + &tmp_tgt_dbs_char, sizeof(char) * + (share_alter->tmp_tgt_dbs_charlen + 1), + &tmp_tgt_hosts_char, sizeof(char) * + (share_alter->tmp_tgt_hosts_charlen + 1), + &tmp_tgt_usernames_char, sizeof(char) * + (share_alter->tmp_tgt_usernames_charlen + 1), + &tmp_tgt_passwords_char, sizeof(char) * + (share_alter->tmp_tgt_passwords_charlen + 1), + &tmp_tgt_sockets_char, sizeof(char) * + (share_alter->tmp_tgt_sockets_charlen + 1), + &tmp_tgt_wrappers_char, sizeof(char) * + (share_alter->tmp_tgt_wrappers_charlen + 1), + &tmp_tgt_ssl_cas_char, sizeof(char) * + (share_alter->tmp_tgt_ssl_cas_charlen + 1), + &tmp_tgt_ssl_capaths_char, sizeof(char) * + (share_alter->tmp_tgt_ssl_capaths_charlen + 1), + &tmp_tgt_ssl_certs_char, sizeof(char) * + (share_alter->tmp_tgt_ssl_certs_charlen + 1), + &tmp_tgt_ssl_ciphers_char, sizeof(char) * + (share_alter->tmp_tgt_ssl_ciphers_charlen + 1), + &tmp_tgt_ssl_keys_char, sizeof(char) * + (share_alter->tmp_tgt_ssl_keys_charlen + 1), + &tmp_tgt_default_files_char, sizeof(char) * + (share_alter->tmp_tgt_default_files_charlen + 1), + &tmp_tgt_default_groups_char, sizeof(char) * + (share_alter->tmp_tgt_default_groups_charlen + 1), + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_alter_table; + } + alter_table->now_create = now_create; + alter_table->table_name = tmp_name; + memcpy(alter_table->table_name, share->table_name, share->table_name_length); + alter_table->table_name_length = share->table_name_length; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + DBUG_PRINT("info",("spider table_name_hash_value=%u", + share->table_name_hash_value)); + alter_table->table_name_hash_value = share->table_name_hash_value; +#endif + alter_table->tmp_priority = share->priority; + alter_table->link_count = share->link_count; + alter_table->all_link_count = share->all_link_count; + + alter_table->tmp_server_names = tmp_server_names; + alter_table->tmp_tgt_table_names = tmp_tgt_table_names; + alter_table->tmp_tgt_dbs = tmp_tgt_dbs; + alter_table->tmp_tgt_hosts = tmp_tgt_hosts; + alter_table->tmp_tgt_usernames = tmp_tgt_usernames; + alter_table->tmp_tgt_passwords = tmp_tgt_passwords; + alter_table->tmp_tgt_sockets = tmp_tgt_sockets; + alter_table->tmp_tgt_wrappers = tmp_tgt_wrappers; + alter_table->tmp_tgt_ssl_cas = tmp_tgt_ssl_cas; + alter_table->tmp_tgt_ssl_capaths = tmp_tgt_ssl_capaths; + alter_table->tmp_tgt_ssl_certs = tmp_tgt_ssl_certs; + alter_table->tmp_tgt_ssl_ciphers = tmp_tgt_ssl_ciphers; + alter_table->tmp_tgt_ssl_keys = tmp_tgt_ssl_keys; + alter_table->tmp_tgt_default_files = tmp_tgt_default_files; + alter_table->tmp_tgt_default_groups = tmp_tgt_default_groups; + + alter_table->tmp_tgt_ports = tmp_tgt_ports; + alter_table->tmp_tgt_ssl_vscs = tmp_tgt_ssl_vscs; + alter_table->tmp_link_statuses = tmp_link_statuses; + + alter_table->tmp_server_names_lengths = tmp_server_names_lengths; + alter_table->tmp_tgt_table_names_lengths = tmp_tgt_table_names_lengths; + alter_table->tmp_tgt_dbs_lengths = tmp_tgt_dbs_lengths; + alter_table->tmp_tgt_hosts_lengths = tmp_tgt_hosts_lengths; + alter_table->tmp_tgt_usernames_lengths = tmp_tgt_usernames_lengths; + alter_table->tmp_tgt_passwords_lengths = tmp_tgt_passwords_lengths; + alter_table->tmp_tgt_sockets_lengths = tmp_tgt_sockets_lengths; + alter_table->tmp_tgt_wrappers_lengths = tmp_tgt_wrappers_lengths; + alter_table->tmp_tgt_ssl_cas_lengths = tmp_tgt_ssl_cas_lengths; + alter_table->tmp_tgt_ssl_capaths_lengths = tmp_tgt_ssl_capaths_lengths; + alter_table->tmp_tgt_ssl_certs_lengths = tmp_tgt_ssl_certs_lengths; + alter_table->tmp_tgt_ssl_ciphers_lengths = tmp_tgt_ssl_ciphers_lengths; + alter_table->tmp_tgt_ssl_keys_lengths = tmp_tgt_ssl_keys_lengths; + alter_table->tmp_tgt_default_files_lengths = tmp_tgt_default_files_lengths; + alter_table->tmp_tgt_default_groups_lengths = tmp_tgt_default_groups_lengths; + + for(roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + tmp_server_names[roop_count] = tmp_server_names_char; + memcpy(tmp_server_names_char, + share_alter->tmp_server_names[roop_count], + sizeof(char) * share_alter->tmp_server_names_lengths[roop_count]); + tmp_server_names_char += + share_alter->tmp_server_names_lengths[roop_count] + 1; + + tmp_tgt_table_names[roop_count] = tmp_tgt_table_names_char; + memcpy(tmp_tgt_table_names_char, + share_alter->tmp_tgt_table_names[roop_count], + sizeof(char) * share_alter->tmp_tgt_table_names_lengths[roop_count]); + tmp_tgt_table_names_char += + share_alter->tmp_tgt_table_names_lengths[roop_count] + 1; + + tmp_tgt_dbs[roop_count] = tmp_tgt_dbs_char; + memcpy(tmp_tgt_dbs_char, share_alter->tmp_tgt_dbs[roop_count], + sizeof(char) * share_alter->tmp_tgt_dbs_lengths[roop_count]); + tmp_tgt_dbs_char += + share_alter->tmp_tgt_dbs_lengths[roop_count] + 1; + + tmp_tgt_hosts[roop_count] = tmp_tgt_hosts_char; + memcpy(tmp_tgt_hosts_char, share_alter->tmp_tgt_hosts[roop_count], + sizeof(char) * share_alter->tmp_tgt_hosts_lengths[roop_count]); + tmp_tgt_hosts_char += + share_alter->tmp_tgt_hosts_lengths[roop_count] + 1; + + tmp_tgt_usernames[roop_count] = tmp_tgt_usernames_char; + memcpy(tmp_tgt_usernames_char, share_alter->tmp_tgt_usernames[roop_count], + sizeof(char) * share_alter->tmp_tgt_usernames_lengths[roop_count]); + tmp_tgt_usernames_char += + share_alter->tmp_tgt_usernames_lengths[roop_count] + 1; + + tmp_tgt_passwords[roop_count] = tmp_tgt_passwords_char; + memcpy(tmp_tgt_passwords_char, share_alter->tmp_tgt_passwords[roop_count], + sizeof(char) * share_alter->tmp_tgt_passwords_lengths[roop_count]); + tmp_tgt_passwords_char += + share_alter->tmp_tgt_passwords_lengths[roop_count] + 1; + + tmp_tgt_sockets[roop_count] = tmp_tgt_sockets_char; + memcpy(tmp_tgt_sockets_char, share_alter->tmp_tgt_sockets[roop_count], + sizeof(char) * share_alter->tmp_tgt_sockets_lengths[roop_count]); + tmp_tgt_sockets_char += + share_alter->tmp_tgt_sockets_lengths[roop_count] + 1; + + tmp_tgt_wrappers[roop_count] = tmp_tgt_wrappers_char; + memcpy(tmp_tgt_wrappers_char, share_alter->tmp_tgt_wrappers[roop_count], + sizeof(char) * share_alter->tmp_tgt_wrappers_lengths[roop_count]); + tmp_tgt_wrappers_char += + share_alter->tmp_tgt_wrappers_lengths[roop_count] + 1; + + tmp_tgt_ssl_cas[roop_count] = tmp_tgt_ssl_cas_char; + memcpy(tmp_tgt_ssl_cas_char, share_alter->tmp_tgt_ssl_cas[roop_count], + sizeof(char) * share_alter->tmp_tgt_ssl_cas_lengths[roop_count]); + tmp_tgt_ssl_cas_char += + share_alter->tmp_tgt_ssl_cas_lengths[roop_count] + 1; + + tmp_tgt_ssl_capaths[roop_count] = tmp_tgt_ssl_capaths_char; + memcpy(tmp_tgt_ssl_capaths_char, + share_alter->tmp_tgt_ssl_capaths[roop_count], + sizeof(char) * share_alter->tmp_tgt_ssl_capaths_lengths[roop_count]); + tmp_tgt_ssl_capaths_char += + share_alter->tmp_tgt_ssl_capaths_lengths[roop_count] + 1; + + tmp_tgt_ssl_certs[roop_count] = tmp_tgt_ssl_certs_char; + memcpy(tmp_tgt_ssl_certs_char, share_alter->tmp_tgt_ssl_certs[roop_count], + sizeof(char) * share_alter->tmp_tgt_ssl_certs_lengths[roop_count]); + tmp_tgt_ssl_certs_char += + share_alter->tmp_tgt_ssl_certs_lengths[roop_count] + 1; + + tmp_tgt_ssl_ciphers[roop_count] = tmp_tgt_ssl_ciphers_char; + memcpy(tmp_tgt_ssl_ciphers_char, + share_alter->tmp_tgt_ssl_ciphers[roop_count], + sizeof(char) * share_alter->tmp_tgt_ssl_ciphers_lengths[roop_count]); + tmp_tgt_ssl_ciphers_char += + share_alter->tmp_tgt_ssl_ciphers_lengths[roop_count] + 1; + + tmp_tgt_ssl_keys[roop_count] = tmp_tgt_ssl_keys_char; + memcpy(tmp_tgt_ssl_keys_char, share_alter->tmp_tgt_ssl_keys[roop_count], + sizeof(char) * share_alter->tmp_tgt_ssl_keys_lengths[roop_count]); + tmp_tgt_ssl_keys_char += + share_alter->tmp_tgt_ssl_keys_lengths[roop_count] + 1; + + tmp_tgt_default_files[roop_count] = tmp_tgt_default_files_char; + memcpy(tmp_tgt_default_files_char, + share_alter->tmp_tgt_default_files[roop_count], + sizeof(char) * share_alter->tmp_tgt_default_files_lengths[roop_count]); + tmp_tgt_default_files_char += + share_alter->tmp_tgt_default_files_lengths[roop_count] + 1; + + tmp_tgt_default_groups[roop_count] = tmp_tgt_default_groups_char; + memcpy(tmp_tgt_default_groups_char, + share_alter->tmp_tgt_default_groups[roop_count], + sizeof(char) * share_alter->tmp_tgt_default_groups_lengths[roop_count]); + tmp_tgt_default_groups_char += + share_alter->tmp_tgt_default_groups_lengths[roop_count] + 1; + } + + memcpy(tmp_tgt_ports, share_alter->tmp_tgt_ports, + sizeof(long) * share->all_link_count); + memcpy(tmp_tgt_ssl_vscs, share_alter->tmp_tgt_ssl_vscs, + sizeof(long) * share->all_link_count); + memcpy(tmp_link_statuses, share_alter->tmp_link_statuses, + sizeof(long) * share->all_link_count); + + memcpy(tmp_server_names_lengths, share_alter->tmp_server_names_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_table_names_lengths, share_alter->tmp_tgt_table_names_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_dbs_lengths, share_alter->tmp_tgt_dbs_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_hosts_lengths, share_alter->tmp_tgt_hosts_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_usernames_lengths, share_alter->tmp_tgt_usernames_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_passwords_lengths, share_alter->tmp_tgt_passwords_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_sockets_lengths, share_alter->tmp_tgt_sockets_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_wrappers_lengths, share_alter->tmp_tgt_wrappers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_ssl_cas_lengths, share_alter->tmp_tgt_ssl_cas_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_ssl_capaths_lengths, share_alter->tmp_tgt_ssl_capaths_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_ssl_certs_lengths, share_alter->tmp_tgt_ssl_certs_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_ssl_ciphers_lengths, share_alter->tmp_tgt_ssl_ciphers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_ssl_keys_lengths, share_alter->tmp_tgt_ssl_keys_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_default_files_lengths, + share_alter->tmp_tgt_default_files_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_default_groups_lengths, + share_alter->tmp_tgt_default_groups_lengths, + sizeof(uint) * share->all_link_count); + + alter_table->tmp_server_names_length = + share_alter->tmp_server_names_length; + alter_table->tmp_tgt_table_names_length = + share_alter->tmp_tgt_table_names_length; + alter_table->tmp_tgt_dbs_length = + share_alter->tmp_tgt_dbs_length; + alter_table->tmp_tgt_hosts_length = + share_alter->tmp_tgt_hosts_length; + alter_table->tmp_tgt_usernames_length = + share_alter->tmp_tgt_usernames_length; + alter_table->tmp_tgt_passwords_length = + share_alter->tmp_tgt_passwords_length; + alter_table->tmp_tgt_sockets_length = + share_alter->tmp_tgt_sockets_length; + alter_table->tmp_tgt_wrappers_length = + share_alter->tmp_tgt_wrappers_length; + alter_table->tmp_tgt_ssl_cas_length = + share_alter->tmp_tgt_ssl_cas_length; + alter_table->tmp_tgt_ssl_capaths_length = + share_alter->tmp_tgt_ssl_capaths_length; + alter_table->tmp_tgt_ssl_certs_length = + share_alter->tmp_tgt_ssl_certs_length; + alter_table->tmp_tgt_ssl_ciphers_length = + share_alter->tmp_tgt_ssl_ciphers_length; + alter_table->tmp_tgt_ssl_keys_length = + share_alter->tmp_tgt_ssl_keys_length; + alter_table->tmp_tgt_default_files_length = + share_alter->tmp_tgt_default_files_length; + alter_table->tmp_tgt_default_groups_length = + share_alter->tmp_tgt_default_groups_length; + alter_table->tmp_tgt_ports_length = + share_alter->tmp_tgt_ports_length; + alter_table->tmp_tgt_ssl_vscs_length = + share_alter->tmp_tgt_ssl_vscs_length; + alter_table->tmp_link_statuses_length = + share_alter->tmp_link_statuses_length; + + old_elements = trx->trx_alter_table_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_alter_table_hash, + alter_table->table_name_hash_value, (uchar*) alter_table)) +#else + if (my_hash_insert(&trx->trx_alter_table_hash, (uchar*) alter_table)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (trx->trx_alter_table_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_alter_table_hash, + (trx->trx_alter_table_hash.array.max_element - old_elements) * + trx->trx_alter_table_hash.array.size_of_element); + } + DBUG_RETURN(0); + +error: + spider_free(trx, alter_table, MYF(0)); +error_alloc_alter_table: + DBUG_RETURN(error_num); +} + +bool spider_cmp_trx_alter_table( + SPIDER_ALTER_TABLE *cmp1, + SPIDER_ALTER_TABLE *cmp2 +) { + int roop_count; + DBUG_ENTER("spider_cmp_trx_alter_table"); + if ( + cmp1->tmp_priority != cmp2->tmp_priority || + cmp1->link_count != cmp2->link_count || + cmp1->all_link_count != cmp2->all_link_count + ) + DBUG_RETURN(TRUE); + + for (roop_count = 0; roop_count < (int) cmp1->all_link_count; roop_count++) + { + if ( + ( + cmp1->tmp_server_names[roop_count] != + cmp2->tmp_server_names[roop_count] && + ( + !cmp1->tmp_server_names[roop_count] || + !cmp2->tmp_server_names[roop_count] || + strcmp(cmp1->tmp_server_names[roop_count], + cmp2->tmp_server_names[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_table_names[roop_count] != + cmp2->tmp_tgt_table_names[roop_count] && + ( + !cmp1->tmp_tgt_table_names[roop_count] || + !cmp2->tmp_tgt_table_names[roop_count] || + strcmp(cmp1->tmp_tgt_table_names[roop_count], + cmp2->tmp_tgt_table_names[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_dbs[roop_count] != + cmp2->tmp_tgt_dbs[roop_count] && + ( + !cmp1->tmp_tgt_dbs[roop_count] || + !cmp2->tmp_tgt_dbs[roop_count] || + strcmp(cmp1->tmp_tgt_dbs[roop_count], + cmp2->tmp_tgt_dbs[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_hosts[roop_count] != + cmp2->tmp_tgt_hosts[roop_count] && + ( + !cmp1->tmp_tgt_hosts[roop_count] || + !cmp2->tmp_tgt_hosts[roop_count] || + strcmp(cmp1->tmp_tgt_hosts[roop_count], + cmp2->tmp_tgt_hosts[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_usernames[roop_count] != + cmp2->tmp_tgt_usernames[roop_count] && + ( + !cmp1->tmp_tgt_usernames[roop_count] || + !cmp2->tmp_tgt_usernames[roop_count] || + strcmp(cmp1->tmp_tgt_usernames[roop_count], + cmp2->tmp_tgt_usernames[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_passwords[roop_count] != + cmp2->tmp_tgt_passwords[roop_count] && + ( + !cmp1->tmp_tgt_passwords[roop_count] || + !cmp2->tmp_tgt_passwords[roop_count] || + strcmp(cmp1->tmp_tgt_passwords[roop_count], + cmp2->tmp_tgt_passwords[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_sockets[roop_count] != + cmp2->tmp_tgt_sockets[roop_count] && + ( + !cmp1->tmp_tgt_sockets[roop_count] || + !cmp2->tmp_tgt_sockets[roop_count] || + strcmp(cmp1->tmp_tgt_sockets[roop_count], + cmp2->tmp_tgt_sockets[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_wrappers[roop_count] != + cmp2->tmp_tgt_wrappers[roop_count] && + ( + !cmp1->tmp_tgt_wrappers[roop_count] || + !cmp2->tmp_tgt_wrappers[roop_count] || + strcmp(cmp1->tmp_tgt_wrappers[roop_count], + cmp2->tmp_tgt_wrappers[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_ssl_cas[roop_count] != + cmp2->tmp_tgt_ssl_cas[roop_count] && + ( + !cmp1->tmp_tgt_ssl_cas[roop_count] || + !cmp2->tmp_tgt_ssl_cas[roop_count] || + strcmp(cmp1->tmp_tgt_ssl_cas[roop_count], + cmp2->tmp_tgt_ssl_cas[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_ssl_capaths[roop_count] != + cmp2->tmp_tgt_ssl_capaths[roop_count] && + ( + !cmp1->tmp_tgt_ssl_capaths[roop_count] || + !cmp2->tmp_tgt_ssl_capaths[roop_count] || + strcmp(cmp1->tmp_tgt_ssl_capaths[roop_count], + cmp2->tmp_tgt_ssl_capaths[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_ssl_certs[roop_count] != + cmp2->tmp_tgt_ssl_certs[roop_count] && + ( + !cmp1->tmp_tgt_ssl_certs[roop_count] || + !cmp2->tmp_tgt_ssl_certs[roop_count] || + strcmp(cmp1->tmp_tgt_ssl_certs[roop_count], + cmp2->tmp_tgt_ssl_certs[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_ssl_ciphers[roop_count] != + cmp2->tmp_tgt_ssl_ciphers[roop_count] && + ( + !cmp1->tmp_tgt_ssl_ciphers[roop_count] || + !cmp2->tmp_tgt_ssl_ciphers[roop_count] || + strcmp(cmp1->tmp_tgt_ssl_ciphers[roop_count], + cmp2->tmp_tgt_ssl_ciphers[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_ssl_keys[roop_count] != + cmp2->tmp_tgt_ssl_keys[roop_count] && + ( + !cmp1->tmp_tgt_ssl_keys[roop_count] || + !cmp2->tmp_tgt_ssl_keys[roop_count] || + strcmp(cmp1->tmp_tgt_ssl_keys[roop_count], + cmp2->tmp_tgt_ssl_keys[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_default_files[roop_count] != + cmp2->tmp_tgt_default_files[roop_count] && + ( + !cmp1->tmp_tgt_default_files[roop_count] || + !cmp2->tmp_tgt_default_files[roop_count] || + strcmp(cmp1->tmp_tgt_default_files[roop_count], + cmp2->tmp_tgt_default_files[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_default_groups[roop_count] != + cmp2->tmp_tgt_default_groups[roop_count] && + ( + !cmp1->tmp_tgt_default_groups[roop_count] || + !cmp2->tmp_tgt_default_groups[roop_count] || + strcmp(cmp1->tmp_tgt_default_groups[roop_count], + cmp2->tmp_tgt_default_groups[roop_count]) + ) + ) || + cmp1->tmp_tgt_ports[roop_count] != cmp2->tmp_tgt_ports[roop_count] || + cmp1->tmp_tgt_ssl_vscs[roop_count] != + cmp2->tmp_tgt_ssl_vscs[roop_count] || + cmp1->tmp_link_statuses[roop_count] != + cmp2->tmp_link_statuses[roop_count] + ) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +int spider_free_trx_alloc( + SPIDER_TRX *trx +) { + int roop_count; + DBUG_ENTER("spider_free_trx_alloc"); + spider_db_udf_free_set_names(trx); + for (roop_count = spider_param_udf_table_lock_mutex_count() - 1; + roop_count >= 0; roop_count--) + pthread_mutex_destroy(&trx->udf_table_mutexes[roop_count]); + spider_free_trx_ha(trx); + spider_free_trx_conn(trx, TRUE); + spider_free_trx_alter_table(trx); + spider_free_mem_calc(spider_current_trx, + trx->trx_conn_hash_id, + trx->trx_conn_hash.array.max_element * + trx->trx_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_conn_hash); + spider_free_mem_calc(spider_current_trx, + trx->trx_another_conn_hash_id, + trx->trx_another_conn_hash.array.max_element * + trx->trx_another_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_another_conn_hash); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc(spider_current_trx, + trx->trx_direct_hs_r_conn_hash_id, + trx->trx_direct_hs_r_conn_hash.array.max_element * + trx->trx_direct_hs_r_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_direct_hs_r_conn_hash); + spider_free_mem_calc(spider_current_trx, + trx->trx_direct_hs_w_conn_hash_id, + trx->trx_direct_hs_w_conn_hash.array.max_element * + trx->trx_direct_hs_w_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_direct_hs_w_conn_hash); +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc(spider_current_trx, + trx->trx_hs_r_conn_hash_id, + trx->trx_hs_r_conn_hash.array.max_element * + trx->trx_hs_r_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_hs_r_conn_hash); + spider_free_mem_calc(spider_current_trx, + trx->trx_hs_w_conn_hash_id, + trx->trx_hs_w_conn_hash.array.max_element * + trx->trx_hs_w_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_hs_w_conn_hash); +#endif + spider_free_mem_calc(spider_current_trx, + trx->trx_ha_hash_id, + trx->trx_ha_hash.array.max_element * + trx->trx_ha_hash.array.size_of_element); + my_hash_free(&trx->trx_ha_hash); + spider_free_mem_calc(spider_current_trx, + trx->trx_alter_table_hash_id, + trx->trx_alter_table_hash.array.max_element * + trx->trx_alter_table_hash.array.size_of_element); + my_hash_free(&trx->trx_alter_table_hash); + DBUG_RETURN(0); +} + +SPIDER_TRX *spider_get_trx( + THD *thd, + bool regist_allocated_thds, + int *error_num +) { + int roop_count = 0; + SPIDER_TRX *trx; + pthread_mutex_t *udf_table_mutexes; + DBUG_ENTER("spider_get_trx"); + + if ( + !thd || + !(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr)) + ) { + DBUG_PRINT("info",("spider create new trx")); + if (!(trx = (SPIDER_TRX *) + spider_bulk_malloc(NULL, 56, MYF(MY_WME | MY_ZEROFILL), + &trx, sizeof(*trx), + &udf_table_mutexes, sizeof(pthread_mutex_t) * + spider_param_udf_table_lock_mutex_count(), + NullS)) + ) + goto error_alloc_trx; + + trx->udf_table_mutexes = udf_table_mutexes; + + for (roop_count = 0; + roop_count < (int) spider_param_udf_table_lock_mutex_count(); + roop_count++) + { +#if MYSQL_VERSION_ID < 50500 + if (pthread_mutex_init(&trx->udf_table_mutexes[roop_count], + MY_MUTEX_INIT_FAST)) +#else + if (mysql_mutex_init(spd_key_mutex_udf_table, + &trx->udf_table_mutexes[roop_count], MY_MUTEX_INIT_FAST)) +#endif + goto error_init_udf_table_mutex; + } + + if ( + my_hash_init(&trx->trx_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_init_hash; + spider_alloc_calc_mem_init(trx->trx_conn_hash, 151); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_conn_hash, + trx->trx_conn_hash.array.max_element * + trx->trx_conn_hash.array.size_of_element); + + if ( + my_hash_init(&trx->trx_another_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_init_another_hash; + spider_alloc_calc_mem_init(trx->trx_another_conn_hash, 152); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_another_conn_hash, + trx->trx_another_conn_hash.array.max_element * + trx->trx_another_conn_hash.array.size_of_element); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + my_hash_init(&trx->trx_hs_r_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_hs_r_init_hash; + spider_alloc_calc_mem_init(trx->trx_hs_r_conn_hash, 153); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_hs_r_conn_hash, + trx->trx_hs_r_conn_hash.array.max_element * + trx->trx_hs_r_conn_hash.array.size_of_element); + + if ( + my_hash_init(&trx->trx_hs_w_conn_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_hs_w_init_hash; + spider_alloc_calc_mem_init(trx->trx_hs_w_conn_hash, 154); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_hs_w_conn_hash, + trx->trx_hs_w_conn_hash.array.max_element * + trx->trx_hs_w_conn_hash.array.size_of_element); +#endif + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + my_hash_init(&trx->trx_direct_hs_r_conn_hash, spd_charset_utf8_bin, 32, + 0, 0, (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_direct_hs_r_init_hash; + spider_alloc_calc_mem_init(trx->trx_direct_hs_r_conn_hash, 155); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_direct_hs_r_conn_hash, + trx->trx_direct_hs_r_conn_hash.array.max_element * + trx->trx_direct_hs_r_conn_hash.array.size_of_element); + + if ( + my_hash_init(&trx->trx_direct_hs_w_conn_hash, spd_charset_utf8_bin, 32, + 0, 0, (my_hash_get_key) spider_conn_get_key, 0, 0) + ) + goto error_direct_hs_w_init_hash; + spider_alloc_calc_mem_init(trx->trx_direct_hs_w_conn_hash, 156); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_direct_hs_w_conn_hash, + trx->trx_direct_hs_w_conn_hash.array.max_element * + trx->trx_direct_hs_w_conn_hash.array.size_of_element); +#endif + + if ( + my_hash_init(&trx->trx_alter_table_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_alter_tbl_get_key, 0, 0) + ) + goto error_init_alter_hash; + spider_alloc_calc_mem_init(trx->trx_alter_table_hash, 157); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_alter_table_hash, + trx->trx_alter_table_hash.array.max_element * + trx->trx_alter_table_hash.array.size_of_element); + + if ( + my_hash_init(&trx->trx_ha_hash, spd_charset_utf8_bin, 32, 0, 0, + (my_hash_get_key) spider_trx_ha_get_key, 0, 0) + ) + goto error_init_trx_ha_hash; + spider_alloc_calc_mem_init(trx->trx_ha_hash, 158); + spider_alloc_calc_mem( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_ha_hash, + trx->trx_ha_hash.array.max_element * + trx->trx_ha_hash.array.size_of_element); + + trx->thd = (THD*) thd; +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (thd) + trx->thd_hash_value = my_calc_hash(&spider_allocated_thds, + (uchar*) thd, sizeof(THD *)); + else + trx->thd_hash_value = 0; +#endif + pthread_mutex_lock(&spider_thread_id_mutex); + trx->spider_thread_id = spider_thread_id; + ++spider_thread_id; + pthread_mutex_unlock(&spider_thread_id_mutex); + trx->trx_conn_adjustment = 1; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + trx->trx_hs_r_conn_adjustment = 1; + trx->trx_hs_w_conn_adjustment = 1; +#endif + + if (thd) + { + if (regist_allocated_thds) + { + pthread_mutex_lock(&spider_allocated_thds_mutex); + uint old_elements = spider_allocated_thds.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&spider_allocated_thds, + trx->thd_hash_value, (uchar*) thd)) +#else + if (my_hash_insert(&spider_allocated_thds, (uchar*) thd)) +#endif + { + pthread_mutex_unlock(&spider_allocated_thds_mutex); + goto error_allocated_thds_insert; + } + if (spider_allocated_thds.array.max_element > old_elements) + { + spider_alloc_calc_mem(trx, + spider_allocated_thds, + (spider_allocated_thds.array.max_element - old_elements) * + spider_allocated_thds.array.size_of_element); + } + pthread_mutex_unlock(&spider_allocated_thds_mutex); + trx->registed_allocated_thds = TRUE; + } + *thd_ha_data(thd, spider_hton_ptr) = (void *) trx; + } + } + + DBUG_PRINT("info",("spider trx=%p", trx)); + DBUG_RETURN(trx); + +error_allocated_thds_insert: + spider_free_mem_calc(trx, + trx->trx_ha_hash_id, + trx->trx_ha_hash.array.max_element * + trx->trx_ha_hash.array.size_of_element); + my_hash_free(&trx->trx_ha_hash); +error_init_trx_ha_hash: + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_alter_table_hash_id, + trx->trx_alter_table_hash.array.max_element * + trx->trx_alter_table_hash.array.size_of_element); + my_hash_free(&trx->trx_alter_table_hash); +error_init_alter_hash: +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_direct_hs_w_conn_hash_id, + trx->trx_direct_hs_w_conn_hash.array.max_element * + trx->trx_direct_hs_w_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_direct_hs_w_conn_hash); +error_direct_hs_w_init_hash: + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_direct_hs_r_conn_hash_id, + trx->trx_direct_hs_r_conn_hash.array.max_element * + trx->trx_direct_hs_r_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_direct_hs_r_conn_hash); +error_direct_hs_r_init_hash: +#endif +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_hs_w_conn_hash_id, + trx->trx_hs_w_conn_hash.array.max_element * + trx->trx_hs_w_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_hs_w_conn_hash); +error_hs_w_init_hash: + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_hs_r_conn_hash_id, + trx->trx_hs_r_conn_hash.array.max_element * + trx->trx_hs_r_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_hs_r_conn_hash); +error_hs_r_init_hash: +#endif + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_another_conn_hash_id, + trx->trx_another_conn_hash.array.max_element * + trx->trx_another_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_another_conn_hash); +error_init_another_hash: + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) *thd_ha_data(thd, spider_hton_ptr)) : NULL, + trx->trx_conn_hash_id, + trx->trx_conn_hash.array.max_element * + trx->trx_conn_hash.array.size_of_element); + my_hash_free(&trx->trx_conn_hash); +error_init_hash: + if (roop_count > 0) + { + for (roop_count--; roop_count >= 0; roop_count--) + pthread_mutex_destroy(&trx->udf_table_mutexes[roop_count]); + } +error_init_udf_table_mutex: + spider_free(NULL, trx, MYF(0)); +error_alloc_trx: + *error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); +} + +int spider_free_trx( + SPIDER_TRX *trx, + bool need_lock +) { + DBUG_ENTER("spider_free_trx"); + if (trx->thd) + { + if (trx->registed_allocated_thds) + { + if (need_lock) + pthread_mutex_lock(&spider_allocated_thds_mutex); +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&spider_allocated_thds, + trx->thd_hash_value, (uchar*) trx->thd); +#else + my_hash_delete(&spider_allocated_thds, (uchar*) trx->thd); +#endif + if (need_lock) + pthread_mutex_unlock(&spider_allocated_thds_mutex); + } + *thd_ha_data(trx->thd, spider_hton_ptr) = (void *) NULL; + } + spider_free_trx_alloc(trx); + spider_merge_mem_calc(trx, TRUE); + spider_free(NULL, trx, MYF(0)); + DBUG_RETURN(0); +} + +int spider_check_and_set_trx_isolation( + SPIDER_CONN *conn, + int *need_mon +) { + int trx_isolation; + DBUG_ENTER("spider_check_and_set_trx_isolation"); + + trx_isolation = thd_tx_isolation(conn->thd); + DBUG_PRINT("info",("spider local trx_isolation=%d", trx_isolation)); +/* + DBUG_PRINT("info",("spider conn->trx_isolation=%d", conn->trx_isolation)); + if (conn->trx_isolation != trx_isolation) + { +*/ + spider_conn_queue_trx_isolation(conn, trx_isolation); +/* + conn->trx_isolation = trx_isolation; + } +*/ + DBUG_RETURN(0); +} + +int spider_check_and_set_autocommit( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + bool autocommit; + DBUG_ENTER("spider_check_and_set_autocommit"); + + autocommit = !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT); + if (autocommit) + { + spider_conn_queue_autocommit(conn, TRUE); + } else { + spider_conn_queue_autocommit(conn, FALSE); + } +/* + if (autocommit && conn->autocommit != 1) + { + spider_conn_queue_autocommit(conn, TRUE); + conn->autocommit = 1; + } else if (!autocommit && conn->autocommit != 0) + { + spider_conn_queue_autocommit(conn, FALSE); + conn->autocommit = 0; + } +*/ + DBUG_RETURN(0); +} + +int spider_check_and_set_sql_log_off( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + bool internal_sql_log_off; + DBUG_ENTER("spider_check_and_set_sql_log_off"); + + internal_sql_log_off = spider_param_internal_sql_log_off(thd); + if (internal_sql_log_off) + { + spider_conn_queue_sql_log_off(conn, TRUE); + } else { + spider_conn_queue_sql_log_off(conn, FALSE); + } +/* + if (internal_sql_log_off && conn->sql_log_off != 1) + { + spider_conn_queue_sql_log_off(conn, TRUE); + conn->sql_log_off = 1; + } else if (!internal_sql_log_off && conn->sql_log_off != 0) + { + spider_conn_queue_sql_log_off(conn, FALSE); + conn->sql_log_off = 0; + } +*/ + DBUG_RETURN(0); +} + +int spider_check_and_set_time_zone( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + Time_zone *time_zone; + DBUG_ENTER("spider_check_and_set_time_zone"); + + time_zone = thd->variables.time_zone; + DBUG_PRINT("info",("spider local time_zone=%p", time_zone)); +/* + DBUG_PRINT("info",("spider conn->time_zone=%p", conn->time_zone)); + if (time_zone != conn->time_zone) + { +*/ + spider_conn_queue_time_zone(conn, time_zone); +/* + conn->time_zone = time_zone; + } +*/ + DBUG_RETURN(0); +} + +int spider_xa_lock( + XID_STATE *xid_state +) { + int error_num; + DBUG_ENTER("spider_xa_lock"); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache, + (uchar*) xid_state->xid.key(), xid_state->xid.key_length()); +#endif + pthread_mutex_lock(spd_db_att_LOCK_xid_cache); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if (my_hash_search_using_hash_value(spd_db_att_xid_cache, hash_value, + xid_state->xid.key(), xid_state->xid.key_length())) +#else + if (my_hash_search(spd_db_att_xid_cache, + xid_state->xid.key(), xid_state->xid.key_length())) +#endif + { + error_num = ER_SPIDER_XA_LOCKED_NUM; + goto error; + } +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(spd_db_att_xid_cache, hash_value, + (uchar*)xid_state)) +#else + if (my_hash_insert(spd_db_att_xid_cache, (uchar*)xid_state)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + pthread_mutex_unlock(spd_db_att_LOCK_xid_cache); + DBUG_RETURN(0); + +error: + pthread_mutex_unlock(spd_db_att_LOCK_xid_cache); + DBUG_RETURN(error_num); +} + +int spider_xa_unlock( + XID_STATE *xid_state +) { + DBUG_ENTER("spider_xa_unlock"); +#if defined(SPIDER_HAS_HASH_VALUE_TYPE) && defined(HASH_UPDATE_WITH_HASH_VALUE) + my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache, + (uchar*) xid_state->xid.key(), xid_state->xid.key_length()); +#endif + pthread_mutex_lock(spd_db_att_LOCK_xid_cache); +#if defined(SPIDER_HAS_HASH_VALUE_TYPE) && defined(HASH_UPDATE_WITH_HASH_VALUE) + my_hash_delete_with_hash_value(spd_db_att_xid_cache, hash_value, (uchar *)xid_state); +#else + my_hash_delete(spd_db_att_xid_cache, (uchar *)xid_state); +#endif + pthread_mutex_unlock(spd_db_att_LOCK_xid_cache); + DBUG_RETURN(0); +} + +int spider_start_internal_consistent_snapshot( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + int *need_mon +) { + DBUG_ENTER("spider_start_internal_consistent_snapshot"); + if (trx->trx_consistent_snapshot) + DBUG_RETURN(spider_db_consistent_snapshot(conn, need_mon)); + DBUG_RETURN(0); +} + +int spider_internal_start_trx( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_TRX *trx = spider->trx; + bool sync_autocommit = spider_param_sync_autocommit(trx->thd); + bool sync_time_zone = spider_param_sync_time_zone(trx->thd); + double ping_interval_at_trx_start = + spider_param_ping_interval_at_trx_start(trx->thd); + bool xa_lock = FALSE; + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_ENTER("spider_internal_start_trx"); + + if ( + conn->server_lost || + difftime(tmp_time, conn->ping_time) >= ping_interval_at_trx_start + ) { + spider_conn_queue_ping(spider, conn, link_idx); + } + conn->disable_reconnect = TRUE; + if (!trx->trx_start) + { + if (!trx->trx_consistent_snapshot) + { + trx->use_consistent_snapshot = + spider_param_use_consistent_snapshot(trx->thd); + trx->internal_xa = spider_param_internal_xa(trx->thd); + trx->internal_xa_snapshot = spider_param_internal_xa_snapshot(trx->thd); + } + } + if ( + (error_num = spider_check_and_set_sql_log_off(trx->thd, conn, + &spider->need_mons[link_idx])) || + (sync_time_zone && + (error_num = spider_check_and_set_time_zone(trx->thd, conn, + &spider->need_mons[link_idx]))) || + (sync_autocommit && + (error_num = spider_check_and_set_autocommit(trx->thd, conn, + &spider->need_mons[link_idx]))) + ) + goto error; + if (trx->trx_consistent_snapshot) + { + if (trx->internal_xa && trx->internal_xa_snapshot < 2) + { + error_num = ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_NUM; + my_message(error_num, ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_STR, + MYF(0)); + goto error; + } else if (!trx->internal_xa || trx->internal_xa_snapshot == 2) + { + if ((error_num = spider_start_internal_consistent_snapshot(trx, conn, + &spider->need_mons[link_idx]))) + goto error; + } + } + if (!trx->trx_start) + { + if ( + trx->thd->transaction.xid_state.xa_state == XA_ACTIVE && + spider_param_support_xa() + ) { + trx->trx_xa = TRUE; + thd_get_xid(trx->thd, (MYSQL_XID*) &trx->xid); + } + + if (!trx->trx_xa && trx->internal_xa) + { + if (!trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3) + { + trx->trx_xa = TRUE; + trx->xid.formatID = 1; + trx->xid.gtrid_length + = my_sprintf(trx->xid.data, + (trx->xid.data, "%lx", thd_get_thread_id(trx->thd))); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 + trx->xid.bqual_length + = my_sprintf(trx->xid.data + trx->xid.gtrid_length, + (trx->xid.data + trx->xid.gtrid_length, "%lx", + trx->thd->variables.server_id)); +#else + trx->xid.bqual_length + = my_sprintf(trx->xid.data + trx->xid.gtrid_length, + (trx->xid.data + trx->xid.gtrid_length, "%x", + trx->thd->server_id)); +#endif + + trx->internal_xid_state.xa_state = XA_ACTIVE; + trx->internal_xid_state.xid.set(&trx->xid); + trx->internal_xid_state.in_thd = 1; + while ((error_num = spider_xa_lock(&trx->internal_xid_state))) + { + if (error_num != ER_SPIDER_XA_LOCKED_NUM) + goto error; + else if (trx->xid.formatID == 0) + { + my_message(error_num, ER_SPIDER_XA_LOCKED_STR, MYF(0)); + goto error; + } + /* retry */ + trx->xid.formatID++; + trx->internal_xid_state.xid.set(&trx->xid); + } + xa_lock = TRUE; + } + } + + if (!trx->trx_consistent_snapshot) + { + trans_register_ha(trx->thd, FALSE, spider_hton_ptr); + if (thd_test_options(trx->thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + trans_register_ha(trx->thd, TRUE, spider_hton_ptr); + } + trx->trx_start = TRUE; + } + + DBUG_PRINT("info",("spider sync_autocommit = %d", sync_autocommit)); + DBUG_PRINT("info",("spider conn->semi_trx_chk = %d", conn->semi_trx_chk)); + DBUG_PRINT("info",("spider conn->table_lock = %d", conn->table_lock)); + DBUG_PRINT("info",("spider conn->autocommit = %d", conn->autocommit)); + DBUG_PRINT("info",("spider semi_trx = %d", spider_param_semi_trx(trx->thd))); + conn->semi_trx = FALSE; + if (conn->table_lock == 3) + { + DBUG_PRINT("info",("spider conn->table_lock == 3")); + conn->disable_xa = TRUE; + } else if (trx->trx_xa) + { + DBUG_PRINT("info",("spider trx->trx_xa")); + if ( + sync_autocommit && + conn->semi_trx_chk && + !conn->table_lock && + ( + (!conn->queued_autocommit && conn->autocommit == 1) || + (conn->queued_autocommit && conn->queued_autocommit_val == TRUE) + ) && + spider_param_semi_trx(trx->thd) + ) { + DBUG_PRINT("info",("spider semi_trx is set")); + conn->semi_trx = TRUE; + } + spider_conn_queue_xa_start(conn, &trx->xid); + conn->disable_xa = FALSE; + } else if ( + !trx->trx_consistent_snapshot && + !thd_test_options(trx->thd, OPTION_BEGIN) && + sync_autocommit && + conn->semi_trx_chk && + !conn->table_lock && + ( + (!conn->queued_autocommit && conn->autocommit == 1) || + (conn->queued_autocommit && conn->queued_autocommit_val == TRUE) + ) && + spider_param_semi_trx(trx->thd) + ) { + DBUG_PRINT("info",("spider semi_trx is set")); + spider_conn_queue_start_transaction(conn); + conn->semi_trx = TRUE; + } else if ( + !trx->trx_consistent_snapshot && + thd_test_options(trx->thd, OPTION_BEGIN) + ) { + DBUG_PRINT("info",("spider start transaction")); + spider_conn_queue_start_transaction(conn); + } + + conn->join_trx = 1; + if (trx->join_trx_top) + spider_tree_insert(trx->join_trx_top, conn); + else { + conn->p_small = NULL; + conn->p_big = NULL; + conn->c_small = NULL; + conn->c_big = NULL; + trx->join_trx_top = conn; + } + DBUG_RETURN(0); + +error: + if (xa_lock) + spider_xa_unlock(&trx->internal_xid_state); + DBUG_RETURN(error_num); +} + +int spider_internal_xa_commit( + THD* thd, + SPIDER_TRX *trx, + XID* xid, + TABLE *table_xa, + TABLE *table_xa_member +) { + int error_num, tmp_error_num; + char xa_key[MAX_KEY_LENGTH]; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_commit"); + + /* + select + status + from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + spider_store_xa_pk(table_xa, &trx->xid); + if ( + (error_num = spider_check_sys_table(table_xa, xa_key)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_xa->file->print_error(error_num, MYF(0)); + goto error; + } + my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR, + MYF(0)); + error_num = ER_SPIDER_XA_NOT_EXISTS_NUM; + goto error; + } + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ( + force_commit != 2 && + (error_num = spider_check_sys_xa_status( + table_xa, + SPIDER_SYS_XA_PREPARED_STR, + SPIDER_SYS_XA_COMMIT_STR, + NULL, + ER_SPIDER_XA_NOT_PREPARED_NUM, + &mem_root)) + ) { + free_root(&mem_root, MYF(0)); + if (error_num == ER_SPIDER_XA_NOT_PREPARED_NUM) + my_message(error_num, ER_SPIDER_XA_NOT_PREPARED_STR, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + + /* + update + mysql.spider_xa + set + status = 'COMMIT' + where + format_id = trx->xid.format_id and + gtrid_length = trx->xid.gtrid_length and + data = trx->xid.data + */ + if ( + (error_num = spider_update_xa( + table_xa, &trx->xid, SPIDER_SYS_XA_COMMIT_STR)) + ) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + + SPIDER_BACKUP_DASTATUS; + if ((conn = spider_tree_first(trx->join_trx_top))) + { + do { + if (conn->join_trx) + { + if ((tmp_error_num = spider_db_xa_commit(conn, &trx->xid))) + { + if (force_commit == 0 || + (force_commit == 1 && tmp_error_num != ER_XAER_NOTA)) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + } + if ((tmp_error_num = spider_end_trx(trx, conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + conn->join_trx = 0; + } + } while ((conn = spider_tree_next(conn))); + trx->join_trx_top = NULL; + } + if (error_num) + goto error_in_commit; + + /* + delete from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa_member = spider_open_sys_table( + thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) + goto error_open_table; + table_xa_member_opened = TRUE; + if ((error_num = spider_delete_xa_member(table_xa_member, &trx->xid))) + goto error; + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + + /* + delete from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ((error_num = spider_delete_xa(table_xa, &trx->xid))) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + spider_xa_unlock(&trx->internal_xid_state); + trx->internal_xid_state.xa_state = XA_NOTR; + DBUG_RETURN(0); + +error: + if (table_xa_opened) + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + if (table_xa_member_opened) + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); +error_in_commit: +error_open_table: + spider_xa_unlock(&trx->internal_xid_state); + trx->internal_xid_state.xa_state = XA_NOTR; + DBUG_RETURN(error_num); +} + +int spider_internal_xa_rollback( + THD* thd, + SPIDER_TRX *trx +) { + int error_num = 0, tmp_error_num; + TABLE *table_xa, *table_xa_member; + char xa_key[MAX_KEY_LENGTH]; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool server_lost = FALSE; + bool prepared = (thd->transaction.xid_state.xa_state == XA_PREPARED); + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_rollback"); + + if (prepared) + { + /* + select + status + from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + spider_store_xa_pk(table_xa, &trx->xid); + if ( + (error_num = spider_check_sys_table(table_xa, xa_key)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_xa->file->print_error(error_num, MYF(0)); + goto error; + } + my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR, + MYF(0)); + error_num = ER_SPIDER_XA_NOT_EXISTS_NUM; + goto error; + } + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ( + force_commit != 2 && + (error_num = spider_check_sys_xa_status( + table_xa, + SPIDER_SYS_XA_PREPARED_STR, + SPIDER_SYS_XA_ROLLBACK_STR, + NULL, + ER_SPIDER_XA_NOT_PREPARED_NUM, + &mem_root)) + ) { + free_root(&mem_root, MYF(0)); + if (error_num == ER_SPIDER_XA_NOT_PREPARED_NUM) + my_message(error_num, ER_SPIDER_XA_NOT_PREPARED_STR, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + + /* + update + mysql.spider_xa + set + status = 'COMMIT' + where + format_id = trx->xid.format_id and + gtrid_length = trx->xid.gtrid_length and + data = trx->xid.data + */ + if ( + (error_num = spider_update_xa( + table_xa, &trx->xid, SPIDER_SYS_XA_ROLLBACK_STR)) + ) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + } + + SPIDER_BACKUP_DASTATUS; + if ((conn = spider_tree_first(trx->join_trx_top))) + { + do { + if (conn->join_trx) + { + if (conn->disable_xa) + { + if (conn->table_lock != 3 && !prepared) + { + if ( + !conn->server_lost && + (tmp_error_num = spider_db_rollback(conn)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + } + } else { + if (!conn->server_lost) + { + if ( + !prepared && + (tmp_error_num = spider_db_xa_end(conn, &trx->xid)) + ) { + if ( + force_commit == 0 || + (force_commit == 1 && + ( + tmp_error_num != ER_XAER_NOTA && + tmp_error_num != ER_XA_RBTIMEOUT && + tmp_error_num != ER_XA_RBDEADLOCK + ) + ) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + } + if ((tmp_error_num = spider_db_xa_rollback(conn, &trx->xid))) + { + if ( + force_commit == 0 || + (force_commit == 1 && + ( + tmp_error_num != ER_XAER_NOTA && + tmp_error_num != ER_XA_RBTIMEOUT && + tmp_error_num != ER_XA_RBDEADLOCK + ) + ) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + } + } + } + if ((tmp_error_num = spider_end_trx(trx, conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (!error_num && tmp_error_num) + error_num = tmp_error_num; + } + conn->join_trx = 0; + if (conn->server_lost) + server_lost = TRUE; + } + } while ((conn = spider_tree_next(conn))); + trx->join_trx_top = NULL; + } + if (error_num) + goto error_in_rollback; + + if ( + prepared && + !server_lost + ) { + /* + delete from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa_member = spider_open_sys_table( + thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) + goto error_open_table; + table_xa_member_opened = TRUE; + if ((error_num = spider_delete_xa_member(table_xa_member, &trx->xid))) + goto error; + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + + /* + delete from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ((error_num = spider_delete_xa(table_xa, &trx->xid))) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + } + spider_xa_unlock(&trx->internal_xid_state); + trx->internal_xid_state.xa_state = XA_NOTR; + DBUG_RETURN(0); + +error: + if (table_xa_opened) + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + if (table_xa_member_opened) + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); +error_in_rollback: +error_open_table: + spider_xa_unlock(&trx->internal_xid_state); + trx->internal_xid_state.xa_state = XA_NOTR; + DBUG_RETURN(error_num); +} + +int spider_internal_xa_prepare( + THD* thd, + SPIDER_TRX *trx, + TABLE *table_xa, + TABLE *table_xa_member, + bool internal_xa +) { + int error_num; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_prepare"); + /* + insert into mysql.spider_xa + (format_id, gtrid_length, bqual_length, data, status) values + (trx->xid.format_id, trx->xid.gtrid_length, trx->xid.bqual_length, + trx->xid.data, 'NOT YET') + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ( + (error_num = spider_insert_xa( + table_xa, &trx->xid, SPIDER_SYS_XA_NOT_YET_STR)) + ) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + + if ( + !(table_xa_member = spider_open_sys_table( + thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) + goto error_open_table; + table_xa_member_opened = TRUE; + SPIDER_BACKUP_DASTATUS; + if ((conn = spider_tree_first(trx->join_trx_top))) + { + do { + if (conn->disable_xa) + { + if (conn->table_lock != 3) + { + if ((error_num = spider_db_rollback(conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + goto error; + } + } + if ((error_num = spider_end_trx(trx, conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + goto error; + } + conn->join_trx = 0; + } else { + /* + insert into mysql.spider_xa_member + (format_id, gtrid_length, bqual_length, data, + scheme, host, port, socket, username, password) values + (trx->xid.format_id, trx->xid.gtrid_length, + trx->xid.bqual_length, trx->xid.data, + conn->tgt_wrapper, + conn->tgt_host, + conn->tgt_port, + conn->tgt_socket, + conn->tgt_username, + conn->tgt_password) + */ + if ( + (error_num = spider_insert_xa_member( + table_xa_member, &trx->xid, conn)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + goto error; + } + + if ((error_num = spider_db_xa_end(conn, &trx->xid))) + { + if (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + goto error; + } + } + if ((error_num = spider_db_xa_prepare(conn, &trx->xid))) + { + if (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + goto error; + } + } +/* + if (!internal_xa) + { + if ((error_num = spider_end_trx(trx, conn))) + DBUG_RETURN(error_num); + conn->join_trx = 0; + } +*/ + } + } while ((conn = spider_tree_next(conn))); +/* + if (!internal_xa) + trx->join_trx_top = NULL; +*/ + } + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + + /* + update + mysql.spider_xa + set + status = 'PREPARED' + where + format_id = trx->xid.format_id and + gtrid_length = trx->xid.gtrid_length and + data = trx->xid.data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ( + (error_num = spider_update_xa( + table_xa, &trx->xid, SPIDER_SYS_XA_PREPARED_STR)) + ) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + if (internal_xa) + trx->internal_xid_state.xa_state = XA_PREPARED; + DBUG_RETURN(0); + +error: + if (table_xa_opened) + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + if (table_xa_member_opened) + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); +error_open_table: + DBUG_RETURN(error_num); +} + +int spider_internal_xa_recover( + THD* thd, + XID* xid_list, + uint len +) { + TABLE *table_xa; + int cnt = 0; + char xa_key[MAX_KEY_LENGTH]; + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + DBUG_ENTER("spider_internal_xa_recover"); + /* + select + format_id, + gtrid_length, + bqual_length, + data + from + mysql.spider_xa + where + status = 'PREPARED' + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + FALSE, &open_tables_backup, TRUE, &my_errno)) + ) + goto error_open_table; + spider_store_xa_status(table_xa, SPIDER_SYS_XA_PREPARED_STR); + if ( + (my_errno = spider_get_sys_table_by_idx(table_xa, xa_key, 1, + SPIDER_SYS_XA_IDX1_COL_CNT)) + ) { + spider_sys_index_end(table_xa); + if (my_errno != HA_ERR_KEY_NOT_FOUND && my_errno != HA_ERR_END_OF_FILE) + { + table_xa->file->print_error(my_errno, MYF(0)); + goto error; + } + goto error; + } + + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + do { + spider_get_sys_xid(table_xa, &xid_list[cnt], &mem_root); + cnt++; + my_errno = spider_sys_index_next_same(table_xa, xa_key); + } while (my_errno == 0 && cnt < (int) len); + free_root(&mem_root, MYF(0)); + spider_sys_index_end(table_xa); + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + DBUG_RETURN(cnt); + +error: + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); +error_open_table: + DBUG_RETURN(0); +} + +int spider_initinal_xa_recover( + XID* xid_list, + uint len +) { + int error_num; + static THD *thd = NULL; + static TABLE *table_xa = NULL; + static READ_RECORD *read_record = NULL; +#if MYSQL_VERSION_ID < 50500 + static Open_tables_state *open_tables_backup = NULL; +#else + static Open_tables_backup *open_tables_backup = NULL; +#endif + int cnt = 0; + MEM_ROOT mem_root; + DBUG_ENTER("spider_initinal_xa_recover"); + if (!open_tables_backup) + { +#if MYSQL_VERSION_ID < 50500 + if (!(open_tables_backup = new Open_tables_state)) +#else + if (!(open_tables_backup = new Open_tables_backup)) +#endif + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_state; + } + } + if (!read_record) + { + if (!(read_record = new READ_RECORD)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_read_record; + } + } + + if (!thd) + { + if (!(thd = spider_create_tmp_thd())) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_thd; + } + } + + /* + select + format_id, + gtrid_length, + bqual_length, + data + from + mysql.spider_xa + */ + if (!table_xa) + { + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + FALSE, open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + init_read_record(read_record, thd, table_xa, NULL, TRUE, FALSE, FALSE); + } + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + while ((!(read_record->read_record(read_record))) && cnt < (int) len) + { + spider_get_sys_xid(table_xa, &xid_list[cnt], &mem_root); + cnt++; + } + free_root(&mem_root, MYF(0)); + + if (cnt < (int) len) + { + end_read_record(read_record); + spider_close_sys_table(thd, table_xa, open_tables_backup, TRUE); + table_xa = NULL; + spider_free_tmp_thd(thd); + thd = NULL; + delete read_record; + read_record = NULL; + delete open_tables_backup; + open_tables_backup = NULL; + } + DBUG_RETURN(cnt); + +/* +error: + end_read_record(&read_record_info); + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa = NULL; +*/ +error_open_table: + spider_free_tmp_thd(thd); + thd = NULL; +error_create_thd: + delete read_record; + read_record = NULL; +error_create_read_record: + delete open_tables_backup; + open_tables_backup = NULL; +error_create_state: + DBUG_RETURN(0); +} + +int spider_internal_xa_commit_by_xid( + THD* thd, + SPIDER_TRX *trx, + XID* xid +) { + TABLE *table_xa, *table_xa_member; + int error_num; + char xa_key[MAX_KEY_LENGTH]; + char xa_member_key[MAX_KEY_LENGTH]; + SPIDER_SHARE tmp_share; + char *tmp_connect_info[8]; + uint tmp_connect_info_length[8]; + long tmp_tgt_port, tmp_link_statuses; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_commit_by_xid"); + /* + select + status + from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + spider_store_xa_pk(table_xa, xid); + if ( + (error_num = spider_check_sys_table(table_xa, xa_key)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_xa->file->print_error(error_num, MYF(0)); + goto error; + } + my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR, + MYF(0)); + error_num = ER_SPIDER_XA_NOT_EXISTS_NUM; + goto error; + } + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ( + force_commit != 2 && + (error_num = spider_check_sys_xa_status( + table_xa, + SPIDER_SYS_XA_PREPARED_STR, + SPIDER_SYS_XA_COMMIT_STR, + NULL, + ER_SPIDER_XA_NOT_PREPARED_NUM, + &mem_root)) + ) { + free_root(&mem_root, MYF(0)); + if (error_num == ER_SPIDER_XA_NOT_PREPARED_NUM) + my_message(error_num, ER_SPIDER_XA_NOT_PREPARED_STR, MYF(0)); + goto error; + } + + /* + update + mysql.spider_xa + set + status = 'COMMIT' + where + format_id = trx->xid.format_id and + gtrid_length = trx->xid.gtrid_length and + data = trx->xid.data + */ + if ( + (error_num = spider_update_xa( + table_xa, xid, SPIDER_SYS_XA_COMMIT_STR)) + ) { + free_root(&mem_root, MYF(0)); + goto error; + } + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + + /* + select + scheme tmp_share.tgt_wrappers, + host tmp_share.tgt_hosts, + port tmp_share.tgt_ports, + socket tmp_share.tgt_sockets, + username tmp_share.tgt_usernames, + password tmp_share.tgt_passwords + from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa_member = spider_open_sys_table( + thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) { + free_root(&mem_root, MYF(0)); + goto error_open_table; + } + table_xa_member_opened = TRUE; + spider_store_xa_pk(table_xa_member, xid); + if ( + (error_num = spider_get_sys_table_by_idx(table_xa_member, xa_member_key, 0, + SPIDER_SYS_XA_PK_COL_CNT)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + free_root(&mem_root, MYF(0)); + table_xa_member->file->print_error(error_num, MYF(0)); + goto error; + } else { + free_root(&mem_root, MYF(0)); + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + goto xa_delete; + } + } + + memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); + tmp_share.link_count = 1; + tmp_share.all_link_count = 1; + tmp_share.server_names = &tmp_connect_info[0]; + tmp_share.tgt_table_names = &tmp_connect_info[1]; + tmp_share.tgt_dbs = &tmp_connect_info[2]; + tmp_share.tgt_hosts = &tmp_connect_info[3]; + tmp_share.tgt_usernames = &tmp_connect_info[4]; + tmp_share.tgt_passwords = &tmp_connect_info[5]; + tmp_share.tgt_sockets = &tmp_connect_info[6]; + tmp_share.tgt_wrappers = &tmp_connect_info[7]; + tmp_share.tgt_ports = &tmp_tgt_port; + tmp_share.link_statuses = &tmp_link_statuses; + tmp_share.server_names_lengths = &tmp_connect_info_length[0]; + tmp_share.tgt_table_names_lengths = &tmp_connect_info_length[1]; + tmp_share.tgt_dbs_lengths = &tmp_connect_info_length[2]; + tmp_share.tgt_hosts_lengths = &tmp_connect_info_length[3]; + tmp_share.tgt_usernames_lengths = &tmp_connect_info_length[4]; + tmp_share.tgt_passwords_lengths = &tmp_connect_info_length[5]; + tmp_share.tgt_sockets_lengths = &tmp_connect_info_length[6]; + tmp_share.tgt_wrappers_lengths = &tmp_connect_info_length[7]; + tmp_share.server_names_length = 1; + tmp_share.tgt_table_names_length = 1; + tmp_share.tgt_dbs_length = 1; + tmp_share.tgt_hosts_length = 1; + tmp_share.tgt_usernames_length = 1; + tmp_share.tgt_passwords_length = 1; + tmp_share.tgt_sockets_length = 1; + tmp_share.tgt_wrappers_length = 1; + tmp_share.tgt_ports_length = 1; + tmp_share.link_statuses_length = 1; + do { + SPIDER_BACKUP_DASTATUS; + spider_get_sys_server_info(table_xa_member, &tmp_share, 0, &mem_root); + if ((error_num = spider_create_conn_keys(&tmp_share))) + { + spider_sys_index_end(table_xa_member); + free_root(&mem_root, MYF(0)); + goto error; + } + + if ( + !(conn = spider_get_conn( + &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE, + SPIDER_CONN_KIND_MYSQL, &error_num)) && + (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + ) { + spider_sys_index_end(table_xa_member); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + goto error; + } + conn->error_mode &= spider_param_error_read_mode(thd, 0); + conn->error_mode &= spider_param_error_write_mode(thd, 0); + if ( + (error_num = spider_db_xa_commit(conn, xid)) && + (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + { + spider_sys_index_end(table_xa_member); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + goto error; + } + } + spider_free_tmp_share_alloc(&tmp_share); + error_num = spider_sys_index_next_same(table_xa_member, xa_member_key); + } while (error_num == 0); + if ((error_num = spider_sys_index_end(table_xa_member))) + { + free_root(&mem_root, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + spider_reuse_trx_ha(trx); + spider_free_trx_conn(trx, FALSE); + + /* + delete from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ((error_num = spider_delete_xa_member(table_xa_member, xid))) + goto error; + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + +xa_delete: + /* + delete from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ((error_num = spider_delete_xa(table_xa, xid))) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + DBUG_RETURN(0); + +error: + if (table_xa_opened) + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + if (table_xa_member_opened) + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); +error_open_table: + DBUG_RETURN(error_num); +} + +int spider_internal_xa_rollback_by_xid( + THD* thd, + SPIDER_TRX *trx, + XID* xid +) { + TABLE *table_xa, *table_xa_member; + int error_num; + char xa_key[MAX_KEY_LENGTH]; + char xa_member_key[MAX_KEY_LENGTH]; + SPIDER_SHARE tmp_share; + char *tmp_connect_info[8]; + uint tmp_connect_info_length[8]; + long tmp_tgt_port, tmp_link_statuses; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; +#if MYSQL_VERSION_ID < 50500 + Open_tables_state open_tables_backup; +#else + Open_tables_backup open_tables_backup; +#endif + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_rollback_by_xid"); + /* + select + status + from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + spider_store_xa_pk(table_xa, xid); + if ( + (error_num = spider_check_sys_table(table_xa, xa_key)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_xa->file->print_error(error_num, MYF(0)); + goto error; + } + error_num = ER_SPIDER_XA_NOT_EXISTS_NUM; + goto error; + } + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + if ( + force_commit != 2 && + (error_num = spider_check_sys_xa_status( + table_xa, + SPIDER_SYS_XA_NOT_YET_STR, + SPIDER_SYS_XA_PREPARED_STR, + SPIDER_SYS_XA_ROLLBACK_STR, + ER_SPIDER_XA_PREPARED_NUM, + &mem_root)) + ) { + free_root(&mem_root, MYF(0)); + if (error_num == ER_SPIDER_XA_PREPARED_NUM) + my_message(error_num, ER_SPIDER_XA_PREPARED_STR, MYF(0)); + goto error; + } + + /* + update + mysql.spider_xa + set + status = 'ROLLBACK' + where + format_id = trx->xid.format_id and + gtrid_length = trx->xid.gtrid_length and + data = trx->xid.data + */ + if ( + (error_num = spider_update_xa( + table_xa, xid, SPIDER_SYS_XA_ROLLBACK_STR)) + ) { + free_root(&mem_root, MYF(0)); + goto error; + } + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + + /* + select + scheme tmp_share.tgt_wrappers, + host tmp_share.tgt_hosts, + port tmp_share.tgt_ports, + socket tmp_share.tgt_sockets, + username tmp_share.tgt_usernames, + password tmp_share.tgt_passwords + from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa_member = spider_open_sys_table( + thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, + &error_num)) + ) { + free_root(&mem_root, MYF(0)); + goto error_open_table; + } + table_xa_member_opened = TRUE; + spider_store_xa_pk(table_xa_member, xid); + if ( + (error_num = spider_get_sys_table_by_idx(table_xa_member, xa_member_key, 0, + SPIDER_SYS_XA_PK_COL_CNT)) + ) { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + free_root(&mem_root, MYF(0)); + table_xa_member->file->print_error(error_num, MYF(0)); + goto error; + } else { + free_root(&mem_root, MYF(0)); + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + goto xa_delete; + } + } + + memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); + tmp_share.link_count = 1; + tmp_share.all_link_count = 1; + tmp_share.server_names = &tmp_connect_info[0]; + tmp_share.tgt_table_names = &tmp_connect_info[1]; + tmp_share.tgt_dbs = &tmp_connect_info[2]; + tmp_share.tgt_hosts = &tmp_connect_info[3]; + tmp_share.tgt_usernames = &tmp_connect_info[4]; + tmp_share.tgt_passwords = &tmp_connect_info[5]; + tmp_share.tgt_sockets = &tmp_connect_info[6]; + tmp_share.tgt_wrappers = &tmp_connect_info[7]; + tmp_share.tgt_ports = &tmp_tgt_port; + tmp_share.link_statuses = &tmp_link_statuses; + tmp_share.server_names_lengths = &tmp_connect_info_length[0]; + tmp_share.tgt_table_names_lengths = &tmp_connect_info_length[1]; + tmp_share.tgt_dbs_lengths = &tmp_connect_info_length[2]; + tmp_share.tgt_hosts_lengths = &tmp_connect_info_length[3]; + tmp_share.tgt_usernames_lengths = &tmp_connect_info_length[4]; + tmp_share.tgt_passwords_lengths = &tmp_connect_info_length[5]; + tmp_share.tgt_sockets_lengths = &tmp_connect_info_length[6]; + tmp_share.tgt_wrappers_lengths = &tmp_connect_info_length[7]; + tmp_share.server_names_length = 1; + tmp_share.tgt_table_names_length = 1; + tmp_share.tgt_dbs_length = 1; + tmp_share.tgt_hosts_length = 1; + tmp_share.tgt_usernames_length = 1; + tmp_share.tgt_passwords_length = 1; + tmp_share.tgt_sockets_length = 1; + tmp_share.tgt_wrappers_length = 1; + tmp_share.tgt_ports_length = 1; + tmp_share.link_statuses_length = 1; + do { + SPIDER_BACKUP_DASTATUS; + spider_get_sys_server_info(table_xa_member, &tmp_share, 0, &mem_root); + if ((error_num = spider_create_conn_keys(&tmp_share))) + { + spider_sys_index_end(table_xa_member); + free_root(&mem_root, MYF(0)); + goto error; + } + + if ( + !(conn = spider_get_conn( + &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE, + SPIDER_CONN_KIND_MYSQL, &error_num)) && + (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + ) { + spider_sys_index_end(table_xa_member); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + goto error; + } + conn->error_mode &= spider_param_error_read_mode(thd, 0); + conn->error_mode &= spider_param_error_write_mode(thd, 0); + if ( + (error_num = spider_db_xa_rollback(conn, xid)) && + (force_commit == 0 || + (force_commit == 1 && error_num != ER_XAER_NOTA)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; + if (error_num) + { + spider_sys_index_end(table_xa_member); + spider_free_tmp_share_alloc(&tmp_share); + free_root(&mem_root, MYF(0)); + goto error; + } + } + spider_free_tmp_share_alloc(&tmp_share); + error_num = spider_sys_index_next_same(table_xa_member, xa_member_key); + } while (error_num == 0); + if ((error_num = spider_sys_index_end(table_xa_member))) + { + free_root(&mem_root, MYF(0)); + goto error; + } + free_root(&mem_root, MYF(0)); + spider_reuse_trx_ha(trx); + spider_free_trx_conn(trx, FALSE); + + /* + delete from + mysql.spider_xa_member + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ((error_num = spider_delete_xa_member(table_xa_member, xid))) + goto error; + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); + table_xa_member_opened = FALSE; + +xa_delete: + /* + delete from + mysql.spider_xa + where + format_id = xid->format_id and + gtrid_length = xid->gtrid_length and + data = xid->data + */ + if ( + !(table_xa = spider_open_sys_table( + thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN, + TRUE, &open_tables_backup, TRUE, &error_num)) + ) + goto error_open_table; + table_xa_opened = TRUE; + if ((error_num = spider_delete_xa(table_xa, xid))) + goto error; + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + table_xa_opened = FALSE; + DBUG_RETURN(0); + +error: + if (table_xa_opened) + spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE); + if (table_xa_member_opened) + spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE); +error_open_table: + DBUG_RETURN(error_num); +} + +int spider_start_consistent_snapshot( + handlerton *hton, + THD* thd +) { + int error_num; + SPIDER_TRX *trx; + DBUG_ENTER("spider_start_consistent_snapshot"); + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + DBUG_RETURN(error_num); + if (spider_param_use_consistent_snapshot(trx->thd)) + { + if (spider_param_internal_xa(trx->thd) && + spider_param_internal_xa_snapshot(trx->thd) == 1) + { + error_num = ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_NUM; + my_message(error_num, ER_SPIDER_CANT_USE_BOTH_INNER_XA_AND_SNAPSHOT_STR, + MYF(0)); + goto error; + } else { + trx->trx_consistent_snapshot = TRUE; + trx->use_consistent_snapshot = TRUE; + trx->internal_xa_snapshot = spider_param_internal_xa_snapshot(trx->thd); + trans_register_ha(trx->thd, FALSE, spider_hton_ptr); + trans_register_ha(trx->thd, TRUE, spider_hton_ptr); + if (spider_param_use_all_conns_snapshot(trx->thd)) + { + trx->internal_xa = FALSE; + if ((error_num = spider_open_all_tables(trx, TRUE))) + goto error_open_all_tables; + if ( + spider_param_use_snapshot_with_flush_tables(trx->thd) == 1 && + (error_num = spider_trx_all_flush_tables(trx)) + ) + goto error_trx_all_flush_tables; + if (spider_param_use_snapshot_with_flush_tables(trx->thd) == 2) + { + if ((error_num = spider_trx_another_lock_tables(trx))) + goto error_trx_another_lock_tables; + if ((error_num = spider_trx_another_flush_tables(trx))) + goto error_trx_another_flush_tables; + } + if ((error_num = spider_trx_all_start_trx(trx))) + goto error_trx_all_start_trx; + if (spider_param_use_snapshot_with_flush_tables(trx->thd) == 1) + { + if ( + spider_param_use_flash_logs(trx->thd) && + (error_num = spider_trx_all_flush_logs(trx)) + ) + goto error_trx_all_flush_logs; + if ((error_num = spider_trx_all_unlock_tables(trx))) + goto error_trx_all_unlock_tables; + } + if (spider_param_use_snapshot_with_flush_tables(trx->thd) == 2) + { + if ( + spider_param_use_flash_logs(trx->thd) && + (error_num = spider_trx_all_flush_logs(trx)) + ) + goto error_trx_all_flush_logs2; + if ((error_num = spider_free_trx_another_conn(trx, TRUE))) + goto error_free_trx_another_conn; + } + } else + trx->internal_xa = spider_param_internal_xa(trx->thd); + } + } + + DBUG_RETURN(0); + +error_trx_all_flush_logs: +error_trx_all_start_trx: +error_trx_another_flush_tables: +error_trx_another_lock_tables: +error_trx_all_flush_tables: + if (spider_param_use_snapshot_with_flush_tables(trx->thd) == 1) + spider_trx_all_unlock_tables(trx); +error_trx_all_flush_logs2: +error_trx_all_unlock_tables: +error_open_all_tables: + if (spider_param_use_snapshot_with_flush_tables(trx->thd) == 2) + spider_free_trx_another_conn(trx, TRUE); +error_free_trx_another_conn: +error: + DBUG_RETURN(error_num); +} + +int spider_commit( + handlerton *hton, + THD *thd, + bool all +) { + SPIDER_TRX *trx; + TABLE *table_xa = NULL; + TABLE *table_xa_member = NULL; + int error_num = 0; + SPIDER_CONN *conn; + DBUG_ENTER("spider_commit"); + + if (!(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + +#ifdef HA_CAN_BULK_ACCESS + DBUG_PRINT("info",("spider trx->bulk_access_conn_first=%p", + trx->bulk_access_conn_first)); + trx->bulk_access_conn_first = NULL; +#endif + + if (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) + { + if (trx->trx_start) + { + if (trx->trx_xa) + { + if ( + trx->internal_xa && + (error_num = spider_internal_xa_prepare( + thd, trx, table_xa, table_xa_member, TRUE)) + ) { +/* + if (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + { +*/ + /* rollback for semi_trx */ + spider_rollback(hton, thd, all); +/* + } +*/ + DBUG_RETURN(error_num); + } + if ( + (error_num = spider_internal_xa_commit( + thd, trx, &trx->xid, table_xa, table_xa_member)) + ) { + DBUG_RETURN(error_num); + } + trx->trx_xa = FALSE; + } else { + if ((conn = spider_tree_first(trx->join_trx_top))) + { + SPIDER_BACKUP_DASTATUS; + int tmp_error_num; + do { + if ( + (conn->autocommit != 1 || conn->trx_start) && + (tmp_error_num = spider_db_commit(conn)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (tmp_error_num) + error_num = tmp_error_num; + } + if ((tmp_error_num = spider_end_trx(trx, conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (tmp_error_num) + error_num = tmp_error_num; + } + conn->join_trx = 0; + } while ((conn = spider_tree_next(conn))); + trx->join_trx_top = NULL; + } + } + trx->trx_start = FALSE; + } + spider_reuse_trx_ha(trx); + spider_free_trx_conn(trx, FALSE); + trx->trx_consistent_snapshot = FALSE; + } + spider_merge_mem_calc(trx, FALSE); + DBUG_RETURN(error_num); +} + +int spider_rollback( + handlerton *hton, + THD *thd, + bool all +) { + SPIDER_TRX *trx; + int error_num = 0; + SPIDER_CONN *conn; + DBUG_ENTER("spider_rollback"); + + if (!(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + +#ifdef HA_CAN_BULK_ACCESS + DBUG_PRINT("info",("spider trx->bulk_access_conn_first=%p", + trx->bulk_access_conn_first)); + trx->bulk_access_conn_first = NULL; +#endif + + if (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) + { + if (trx->trx_start) + { + if (trx->trx_xa) + { + if ( + (error_num = spider_internal_xa_rollback(thd, trx)) + ) + DBUG_RETURN(error_num); + trx->trx_xa = FALSE; + } else { + if ((conn = spider_tree_first(trx->join_trx_top))) + { + SPIDER_BACKUP_DASTATUS; + int tmp_error_num; + do { + if ( + !conn->server_lost && + (conn->autocommit != 1 || conn->trx_start) && + (tmp_error_num = spider_db_rollback(conn)) + ) { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (tmp_error_num) + error_num = tmp_error_num; + } + if ((tmp_error_num = spider_end_trx(trx, conn))) + { + SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM; + if (tmp_error_num) + error_num = tmp_error_num; + } + conn->join_trx = 0; + } while ((conn = spider_tree_next(conn))); + trx->join_trx_top = NULL; + } + } + trx->trx_start = FALSE; + } + spider_reuse_trx_ha(trx); + spider_free_trx_conn(trx, FALSE); + trx->trx_consistent_snapshot = FALSE; + } + + spider_merge_mem_calc(trx, FALSE); + DBUG_RETURN(error_num); +} + +int spider_xa_prepare( + handlerton *hton, + THD* thd, + bool all +) { + int error_num; + SPIDER_TRX *trx; + TABLE *table_xa = NULL; + TABLE *table_xa_member = NULL; + DBUG_ENTER("spider_xa_prepare"); + + if (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) + { + if (!(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + + DBUG_PRINT("info",("spider trx_start=%s", + trx->trx_start ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider trx_xa=%s", + trx->trx_xa ? "TRUE" : "FALSE")); + if (trx->trx_start && trx->trx_xa) + { + if ((error_num = spider_internal_xa_prepare( + thd, trx, table_xa, table_xa_member, FALSE))) + goto error; + } + } + + DBUG_RETURN(0); + +error: + DBUG_RETURN(error_num); +} + +int spider_xa_recover( + handlerton *hton, + XID* xid_list, + uint len +) { + THD* thd = current_thd; + DBUG_ENTER("spider_xa_recover"); + if (len == 0 || xid_list == NULL) + DBUG_RETURN(0); + + if (thd) + DBUG_RETURN(spider_internal_xa_recover(thd, xid_list, len)); + else + DBUG_RETURN(spider_initinal_xa_recover(xid_list, len)); +} + +int spider_xa_commit_by_xid( + handlerton *hton, + XID* xid +) { + SPIDER_TRX *trx; + int error_num; + THD* thd = current_thd; + DBUG_ENTER("spider_xa_commit_by_xid"); + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + goto error_get_trx; + + if ((error_num = spider_internal_xa_commit_by_xid(thd, trx, xid))) + goto error; + + DBUG_RETURN(0); + +error: +error_get_trx: + DBUG_RETURN(error_num); +} + +int spider_xa_rollback_by_xid( + handlerton *hton, + XID* xid +) { + SPIDER_TRX *trx; + int error_num; + THD* thd = current_thd; + DBUG_ENTER("spider_xa_rollback_by_xid"); + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + goto error_get_trx; + + if ((error_num = spider_internal_xa_rollback_by_xid(thd, trx, xid))) + goto error; + + DBUG_RETURN(0); + +error: +error_get_trx: + DBUG_RETURN(error_num); +} + +int spider_end_trx( + SPIDER_TRX *trx, + SPIDER_CONN *conn +) { + int error_num = 0, need_mon = 0; + ha_spider tmp_spider; + DBUG_ENTER("spider_end_trx"); + tmp_spider.conns = &conn; + if (conn->table_lock == 3) + { + conn->table_lock = 0; + conn->disable_reconnect = FALSE; + tmp_spider.trx = trx; + if ( + !conn->server_lost && + (error_num = spider_db_unlock_tables(&tmp_spider, 0)) + ) { + if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) + error_num = 0; + } + } else if (!conn->table_lock) + conn->disable_reconnect = FALSE; + if ( + conn->semi_trx_isolation >= 0 && + conn->trx_isolation != conn->semi_trx_isolation + ) { + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->trx_isolation=%d", conn->trx_isolation)); + if ( + !conn->server_lost && + !conn->queued_semi_trx_isolation && + (error_num = spider_db_set_trx_isolation( + conn, conn->trx_isolation, &need_mon)) + ) { + if ( + !conn->disable_reconnect && + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM + ) + error_num = 0; + } + } + conn->semi_trx_isolation = -2; + conn->semi_trx_isolation_chk = FALSE; + conn->semi_trx_chk = FALSE; + DBUG_RETURN(error_num); +} + +int spider_check_trx_and_get_conn( + THD *thd, + ha_spider *spider, + bool use_conn_kind +) { + int error_num, roop_count, search_link_idx; + SPIDER_TRX *trx; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + char first_byte, first_byte_bak; + int semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, + share->semi_table_lock_conn); + DBUG_ENTER("spider_check_trx_and_get_conn"); + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + DBUG_PRINT("info",("spider get trx error")); + DBUG_RETURN(error_num); + } + spider->trx = trx; + spider->set_error_mode(); + if ( + spider->sql_command != SQLCOM_DROP_TABLE && + spider->sql_command != SQLCOM_ALTER_TABLE + ) { + SPIDER_TRX_HA *trx_ha = spider_check_trx_ha(trx, spider); + if (!trx_ha || trx_ha->wait_for_reusing) + spider_trx_set_link_idx_for_all(spider); + +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if (use_conn_kind) + { + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if ( +/* + spider->conn_kind[roop_count] != SPIDER_CONN_KIND_MYSQL && +*/ + share->hs_dbton_ids[spider->conn_link_idx[roop_count]] == + SPIDER_DBTON_SIZE + ) { + /* can't use hs interface */ + spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + spider_clear_bit(spider->do_hs_direct_update, roop_count); + } + } + } +#endif +#endif + + if (semi_table_lock_conn) + first_byte = '0' + + spider_param_semi_table_lock(thd, share->semi_table_lock); + else + first_byte = '0'; + DBUG_PRINT("info",("spider semi_table_lock_conn = %d", + semi_table_lock_conn)); + DBUG_PRINT("info",("spider semi_table_lock = %d", + spider_param_semi_table_lock(thd, share->semi_table_lock))); + DBUG_PRINT("info",("spider first_byte = %d", first_byte)); + DBUG_PRINT("info",("spider link_status = %ld", + share->link_statuses[spider->conn_link_idx[spider->search_link_idx]])); + if ( + !trx_ha || + trx_ha->wait_for_reusing || + trx->spider_thread_id != spider->spider_thread_id || + trx->trx_conn_adjustment != spider->trx_conn_adjustment || +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + (use_conn_kind && + ( + trx->trx_hs_r_conn_adjustment != spider->trx_hs_r_conn_adjustment || + trx->trx_hs_w_conn_adjustment != spider->trx_hs_w_conn_adjustment + ) + ) || +#endif + first_byte != *spider->conn_keys[0] || + share->link_statuses[spider->conn_link_idx[spider->search_link_idx]] == + SPIDER_LINK_STATUS_NG + ) { + DBUG_PRINT("info",(first_byte != *spider->conn_keys[0] ? + "spider change conn type" : trx != spider->trx ? "spider change thd" : + "spider next trx")); + spider->trx = trx; + spider->trx_conn_adjustment = trx->trx_conn_adjustment; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (use_conn_kind) + { + spider->trx_hs_r_conn_adjustment = trx->trx_hs_r_conn_adjustment; + spider->trx_hs_w_conn_adjustment = trx->trx_hs_w_conn_adjustment; + } +#endif + if ( + spider->spider_thread_id != trx->spider_thread_id || + spider->search_link_query_id != thd->query_id + ) { + search_link_idx = spider_conn_first_link_idx(thd, + share->link_statuses, share->access_balances, spider->conn_link_idx, + share->link_count, SPIDER_LINK_STATUS_OK); + if (search_link_idx == -1) + { + TABLE *table = spider->get_table(); + TABLE_SHARE *table_share = table->s; +#ifdef _MSC_VER + char *db, *table_name; + if (!(db = (char *) + spider_bulk_malloc(spider_current_trx, 57, MYF(MY_WME), + &db, table_share->db.length + 1, + &table_name, table_share->table_name.length + 1, + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } +#else + char db[table_share->db.length + 1], + table_name[table_share->table_name.length + 1]; +#endif + memcpy(db, table_share->db.str, table_share->db.length); + db[table_share->db.length] = '\0'; + memcpy(table_name, table_share->table_name.str, + table_share->table_name.length); + table_name[table_share->table_name.length] = '\0'; + my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM, + ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name); +#ifdef _MSC_VER + spider_free(trx, db, MYF(MY_WME)); +#endif + DBUG_RETURN(ER_SPIDER_ALL_LINKS_FAILED_NUM); + } + spider->search_link_idx = search_link_idx; + spider->search_link_query_id = thd->query_id; + } + spider->spider_thread_id = trx->spider_thread_id; + + first_byte_bak = *spider->conn_keys[0]; + *spider->conn_keys[0] = first_byte; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + if (!spider->handler_opened(roop_count, SPIDER_CONN_KIND_MYSQL)) + spider->conns[roop_count] = NULL; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if (!spider->handler_opened(roop_count, SPIDER_CONN_KIND_HS_READ)) + spider->hs_r_conns[roop_count] = NULL; + if (!spider->handler_opened(roop_count, SPIDER_CONN_KIND_HS_WRITE)) + spider->hs_w_conns[roop_count] = NULL; +#endif + } + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { + uint tgt_conn_kind = (use_conn_kind ? spider->conn_kind[roop_count] : + SPIDER_CONN_KIND_MYSQL); + if ( +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ( +#endif + tgt_conn_kind == SPIDER_CONN_KIND_MYSQL && + !spider->conns[roop_count] +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + ) || + (tgt_conn_kind == SPIDER_CONN_KIND_HS_READ && + !spider->hs_r_conns[roop_count]) || + (tgt_conn_kind == SPIDER_CONN_KIND_HS_WRITE && + !spider->hs_w_conns[roop_count]) +#endif + ) { + *spider->conn_keys[roop_count] = first_byte; + if ( + !(conn = + spider_get_conn(share, roop_count, + spider->conn_keys[roop_count], trx, + spider, FALSE, TRUE, + use_conn_kind ? spider->conn_kind[roop_count] : + SPIDER_CONN_KIND_MYSQL, + &error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + *spider->conn_keys[0] = first_byte_bak; + spider->spider_thread_id = 0; + DBUG_RETURN(error_num); + } + conn->error_mode &= spider->error_mode; + } +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->do_direct_update && + spider_bit_is_set(spider->do_hs_direct_update, roop_count) && + !spider->hs_w_conns[roop_count] + ) { + if ( + !(conn = + spider_get_conn(share, roop_count, + spider->conn_keys[roop_count], trx, + spider, FALSE, TRUE, + SPIDER_CONN_KIND_HS_WRITE, + &error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + *spider->conn_keys[0] = first_byte_bak; + spider->spider_thread_id = 0; + DBUG_RETURN(error_num); + } + conn->error_mode &= spider->error_mode; + } +#endif +#endif + } + } else { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + roop_count < (int) share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + SPIDER_LINK_STATUS_RECOVERY) + ) { +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + if ( + !use_conn_kind || + spider->conn_kind[roop_count] == SPIDER_CONN_KIND_MYSQL + ) { +#endif + conn = spider->conns[roop_count]; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + } else if (spider->conn_kind[roop_count] == SPIDER_CONN_KIND_HS_READ) + { + conn = spider->hs_r_conns[roop_count]; + } else { + conn = spider->hs_w_conns[roop_count]; + } +#endif + + if (!conn) + { + DBUG_PRINT("info",("spider get conn %d", roop_count)); + if ( + !(conn = + spider_get_conn(share, roop_count, + spider->conn_keys[roop_count], trx, + spider, FALSE, TRUE, + use_conn_kind ? spider->conn_kind[roop_count] : + SPIDER_CONN_KIND_MYSQL, + &error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + DBUG_RETURN(error_num); + } + } + conn->error_mode &= spider->error_mode; +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS + if ( + spider->do_direct_update && + spider_bit_is_set(spider->do_hs_direct_update, roop_count) + ) { + conn = spider->hs_w_conns[roop_count]; + if (!conn) + { + DBUG_PRINT("info",("spider get hs_w_conn %d", roop_count)); + if ( + !(conn = + spider_get_conn(share, roop_count, + spider->conn_keys[roop_count], trx, + spider, FALSE, TRUE, + SPIDER_CONN_KIND_HS_WRITE, + &error_num)) + ) { + if ( + share->monitoring_kind[roop_count] && + spider->need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + trx, + trx->thd, + share, + (uint32) share->monitoring_sid[roop_count], + share->table_name, + share->table_name_length, + spider->conn_link_idx[roop_count], + NULL, + 0, + share->monitoring_kind[roop_count], + share->monitoring_limit[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + DBUG_RETURN(error_num); + } + } + } + conn->error_mode &= spider->error_mode; +#endif +#endif + } + } + spider->set_first_link_idx(); + DBUG_RETURN(spider_create_trx_ha(trx, spider, trx_ha)); + } + spider->spider_thread_id = trx->spider_thread_id; + DBUG_RETURN(0); +} + +THD *spider_create_tmp_thd() +{ + THD *thd; + DBUG_ENTER("spider_create_tmp_thd"); + if (!(thd = new THD)) + DBUG_RETURN(NULL); +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 + thd->killed = NOT_KILLED; +#else + thd->killed = THD::NOT_KILLED; +#endif +#if MYSQL_VERSION_ID < 50500 + thd->locked_tables = FALSE; +#endif + thd->proc_info = ""; + thd->thread_id = thd->variables.pseudo_thread_id = 0; + thd->thread_stack = (char*) &thd; + if (thd->store_globals()) + DBUG_RETURN(NULL); + lex_start(thd); + DBUG_RETURN(thd); +} + +void spider_free_tmp_thd( + THD *thd +) { + DBUG_ENTER("spider_free_tmp_thd"); + thd->cleanup(); + delete thd; + DBUG_VOID_RETURN; +} + +int spider_create_trx_ha( + SPIDER_TRX *trx, + ha_spider *spider, + SPIDER_TRX_HA *trx_ha +) { + bool need_create; + char *tmp_name; + uint *conn_link_idx; + uchar *conn_can_fo; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_create_trx_ha"); + if (!trx_ha) + { + DBUG_PRINT("info",("spider need create")); + need_create = TRUE; + } else if ( + trx_ha->share != share || + trx_ha->link_count != share->link_count || + trx_ha->link_bitmap_size != share->link_bitmap_size + ) { + DBUG_PRINT("info",("spider need recreate")); + need_create = TRUE; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + my_hash_delete_with_hash_value(&trx->trx_ha_hash, + share->table_name_hash_value, (uchar*) trx_ha); +#else + my_hash_delete(&trx->trx_ha_hash, (uchar*) trx_ha); +#endif + spider_free(trx, trx_ha, MYF(0)); + } else { + DBUG_PRINT("info",("spider use this")); + trx_ha->wait_for_reusing = FALSE; + need_create = FALSE; + } + if (need_create) + { + if (!(trx_ha = (SPIDER_TRX_HA *) + spider_bulk_malloc(spider_current_trx, 58, MYF(MY_WME), + &trx_ha, sizeof(SPIDER_TRX_HA), + &tmp_name, sizeof(char *) * (share->table_name_length + 1), + &conn_link_idx, sizeof(uint) * share->link_count, + &conn_can_fo, sizeof(uchar) * share->link_bitmap_size, + NullS)) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + trx_ha->table_name = tmp_name; + memcpy(trx_ha->table_name, share->table_name, share->table_name_length); + trx_ha->table_name[share->table_name_length] = '\0'; + trx_ha->table_name_length = share->table_name_length; + trx_ha->trx = trx; + trx_ha->share = share; + trx_ha->link_count = share->link_count; + trx_ha->link_bitmap_size = share->link_bitmap_size; + trx_ha->conn_link_idx = conn_link_idx; + trx_ha->conn_can_fo = conn_can_fo; + trx_ha->wait_for_reusing = FALSE; + uint old_elements = trx->trx_ha_hash.array.max_element; +#ifdef HASH_UPDATE_WITH_HASH_VALUE + if (my_hash_insert_with_hash_value(&trx->trx_ha_hash, + share->table_name_hash_value, (uchar*) trx_ha)) +#else + if (my_hash_insert(&trx->trx_ha_hash, (uchar*) trx_ha)) +#endif + { + spider_free(trx, trx_ha, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (trx->trx_ha_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + trx->trx_ha_hash, + (trx->trx_ha_hash.array.max_element - old_elements) * + trx->trx_ha_hash.array.size_of_element); + } + } + memcpy(trx_ha->conn_link_idx, spider->conn_link_idx, + sizeof(uint) * share->link_count); + memcpy(trx_ha->conn_can_fo, spider->conn_can_fo, + sizeof(uint) * share->link_bitmap_size); + DBUG_RETURN(0); +} + +SPIDER_TRX_HA *spider_check_trx_ha( + SPIDER_TRX *trx, + ha_spider *spider +) { + SPIDER_TRX_HA *trx_ha; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_check_trx_ha"); +#ifdef SPIDER_HAS_HASH_VALUE_TYPE + if ((trx_ha = (SPIDER_TRX_HA *) my_hash_search_using_hash_value( + &trx->trx_ha_hash, share->table_name_hash_value, + (uchar*) share->table_name, share->table_name_length))) +#else + if ((trx_ha = (SPIDER_TRX_HA *) my_hash_search(&trx->trx_ha_hash, + (uchar*) share->table_name, share->table_name_length))) +#endif + { + memcpy(spider->conn_link_idx, trx_ha->conn_link_idx, + sizeof(uint) * share->link_count); + memcpy(spider->conn_can_fo, trx_ha->conn_can_fo, + sizeof(uint) * share->link_bitmap_size); + DBUG_RETURN(trx_ha); + } + DBUG_RETURN(NULL); +} + +void spider_free_trx_ha( + SPIDER_TRX *trx +) { + ulong roop_count; + SPIDER_TRX_HA *trx_ha; + DBUG_ENTER("spider_free_trx_ha"); + for (roop_count = 0; roop_count < trx->trx_ha_hash.records; roop_count++) + { + trx_ha = (SPIDER_TRX_HA *) my_hash_element(&trx->trx_ha_hash, roop_count); + spider_free(spider_current_trx, trx_ha, MYF(0)); + } + my_hash_reset(&trx->trx_ha_hash); + DBUG_VOID_RETURN; +} + +void spider_reuse_trx_ha( + SPIDER_TRX *trx +) { + ulong roop_count; + SPIDER_TRX_HA *trx_ha; + DBUG_ENTER("spider_reuse_trx_ha"); + if (trx->trx_ha_reuse_count < 10000) + { + trx->trx_ha_reuse_count++; + for (roop_count = 0; roop_count < trx->trx_ha_hash.records; roop_count++) + { + trx_ha = (SPIDER_TRX_HA *) my_hash_element(&trx->trx_ha_hash, + roop_count); + trx_ha->wait_for_reusing = TRUE; + } + } else { + trx->trx_ha_reuse_count = 0; + spider_free_trx_ha(trx); + } + DBUG_VOID_RETURN; +} + +void spider_trx_set_link_idx_for_all( + ha_spider *spider +) { + int roop_count, roop_count2; + SPIDER_SHARE *share = spider->share; + long *link_statuses = share->link_statuses; + uint *conn_link_idx = spider->conn_link_idx; + int link_count = share->link_count; + int all_link_count = share->all_link_count; + uchar *conn_can_fo = spider->conn_can_fo; + DBUG_ENTER("spider_trx_set_link_idx_for_all"); + DBUG_PRINT("info",("spider set link_count=%d", link_count)); + DBUG_PRINT("info",("spider set all_link_count=%d", all_link_count)); + memset(conn_can_fo, 0, sizeof(uchar) * share->link_bitmap_size); + for (roop_count = 0; roop_count < link_count; roop_count++) + { + for (roop_count2 = roop_count; roop_count2 < all_link_count; + roop_count2 += link_count) + { + if (link_statuses[roop_count2] <= SPIDER_LINK_STATUS_RECOVERY) + break; + } + if (roop_count2 < all_link_count) + { + conn_link_idx[roop_count] = roop_count2; + if (roop_count2 + link_count < all_link_count) + spider_set_bit(conn_can_fo, roop_count); + DBUG_PRINT("info",("spider set conn_link_idx[%d]=%d", + roop_count, roop_count2)); + } else { + conn_link_idx[roop_count] = roop_count; + DBUG_PRINT("info",("spider set2 conn_link_idx[%d]=%d", + roop_count, roop_count)); + } + spider->conn_keys[roop_count] = + ADD_TO_PTR(spider->conn_keys_first_ptr, + PTR_BYTE_DIFF(share->conn_keys[conn_link_idx[roop_count]], + share->conn_keys[0]), char*); + DBUG_PRINT("info",("spider conn_keys[%d]=%s", + roop_count, spider->conn_keys[roop_count])); +#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) + spider->hs_r_conn_keys[roop_count] = + ADD_TO_PTR(spider->conn_keys_first_ptr, + PTR_BYTE_DIFF(share->hs_read_conn_keys[conn_link_idx[roop_count]], + share->conn_keys[0]), char*); + DBUG_PRINT("info",("spider hs_r_conn_keys[%d]=%s", + roop_count, spider->hs_r_conn_keys[roop_count])); + spider->hs_w_conn_keys[roop_count] = + ADD_TO_PTR(spider->conn_keys_first_ptr, + PTR_BYTE_DIFF(share->hs_write_conn_keys[conn_link_idx[roop_count]], + share->conn_keys[0]), char*); + DBUG_PRINT("info",("spider hs_w_conn_keys[%d]=%s", + roop_count, spider->hs_w_conn_keys[roop_count])); +#endif + } + DBUG_VOID_RETURN; +} + +int spider_trx_check_link_idx_failed( + ha_spider *spider +) { + int roop_count; + SPIDER_SHARE *share = spider->share; + long *link_statuses = share->link_statuses; + uint *conn_link_idx = spider->conn_link_idx; + int link_count = share->link_count; + uchar *conn_can_fo = spider->conn_can_fo; + DBUG_ENTER("spider_trx_set_link_idx_for_all"); + for (roop_count = 0; roop_count < link_count; roop_count++) + { + if ( + link_statuses[conn_link_idx[roop_count]] == SPIDER_LINK_STATUS_NG && + spider_bit_is_set(conn_can_fo, roop_count) + ) { + my_message(ER_SPIDER_LINK_IS_FAILOVER_NUM, + ER_SPIDER_LINK_IS_FAILOVER_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_LINK_IS_FAILOVER_NUM); + } + } + DBUG_RETURN(0); +} + +#ifdef HA_CAN_BULK_ACCESS +void spider_trx_add_bulk_access_conn( + SPIDER_TRX *trx, + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_trx_add_bulk_access_conn"); + DBUG_PRINT("info",("spider trx=%p", trx)); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->bulk_access_requests=%u", + conn->bulk_access_requests)); + DBUG_PRINT("info",("spider conn->bulk_access_sended=%u", + conn->bulk_access_sended)); + DBUG_PRINT("info",("spider trx->bulk_access_conn_first=%p", + trx->bulk_access_conn_first)); + if (!conn->bulk_access_requests && !conn->bulk_access_sended) + { + if (!trx->bulk_access_conn_first) + { + trx->bulk_access_conn_first = conn; + } else { + trx->bulk_access_conn_last->bulk_access_next = conn; + } + trx->bulk_access_conn_last = conn; + conn->bulk_access_next = NULL; + } + conn->bulk_access_requests++; + DBUG_PRINT("info",("spider conn->bulk_access_requests=%u", + conn->bulk_access_requests)); + DBUG_VOID_RETURN; +} +#endif diff --git a/storage/spider/spd_trx.h b/storage/spider/spd_trx.h new file mode 100644 index 00000000000..95814a4b95c --- /dev/null +++ b/storage/spider/spd_trx.h @@ -0,0 +1,260 @@ +/* Copyright (C) 2008-2013 Kentoku Shiba + + 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 */ + +int spider_free_trx_conn( + SPIDER_TRX *trx, + bool trx_free +); + +int spider_free_trx_another_conn( + SPIDER_TRX *trx, + bool lock +); + +int spider_trx_another_lock_tables( + SPIDER_TRX *trx +); + +int spider_trx_another_flush_tables( + SPIDER_TRX *trx +); + +int spider_trx_all_flush_tables( + SPIDER_TRX *trx +); + +int spider_trx_all_unlock_tables( + SPIDER_TRX *trx +); + +int spider_trx_all_start_trx( + SPIDER_TRX *trx +); + +int spider_trx_all_flush_logs( + SPIDER_TRX *trx +); + +int spider_free_trx_alloc( + SPIDER_TRX *trx +); + +void spider_free_trx_alter_table_alloc( + SPIDER_TRX *trx, + SPIDER_ALTER_TABLE *alter_table +); + +int spider_free_trx_alter_table( + SPIDER_TRX *trx +); + +int spider_create_trx_alter_table( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + bool now_create +); + +bool spider_cmp_trx_alter_table( + SPIDER_ALTER_TABLE *cmp1, + SPIDER_ALTER_TABLE *cmp2 +); + +SPIDER_TRX *spider_get_trx( + THD *thd, + bool regist_allocated_thds, + int *error_num +); + +int spider_free_trx( + SPIDER_TRX *trx, + bool need_lock +); + +int spider_check_and_set_trx_isolation( + SPIDER_CONN *conn, + int *need_mon +); + +int spider_check_and_set_autocommit( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_check_and_set_sql_log_off( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_check_and_set_time_zone( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_xa_lock( + XID_STATE *xid_state +); + +int spider_xa_unlock( + XID_STATE *xid_state +); + +int spider_start_internal_consistent_snapshot( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_internal_start_trx( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +); + +int spider_internal_xa_commit( + THD* thd, + SPIDER_TRX *trx, + XID* xid, + TABLE *table_xa, + TABLE *table_xa_member +); + +int spider_internal_xa_rollback( + THD* thd, + SPIDER_TRX *trx +); + +int spider_internal_xa_prepare( + THD* thd, + SPIDER_TRX *trx, + TABLE *table_xa, + TABLE *table_xa_member, + bool internal_xa +); + +int spider_internal_xa_recover( + THD* thd, + XID* xid_list, + uint len +); + +int spider_initinal_xa_recover( + XID* xid_list, + uint len +); + +int spider_internal_xa_commit_by_xid( + THD* thd, + SPIDER_TRX *trx, + XID* xid +); + +int spider_internal_xa_rollback_by_xid( + THD* thd, + SPIDER_TRX *trx, + XID* xid +); + +int spider_start_consistent_snapshot( + handlerton *hton, + THD* thd +); + +int spider_commit( + handlerton *hton, + THD *thd, + bool all +); + +int spider_rollback( + handlerton *hton, + THD *thd, + bool all +); + +int spider_xa_prepare( + handlerton *hton, + THD* thd, + bool all +); + +int spider_xa_recover( + handlerton *hton, + XID* xid_list, + uint len +); + +int spider_xa_commit_by_xid( + handlerton *hton, + XID* xid +); + +int spider_xa_rollback_by_xid( + handlerton *hton, + XID* xid +); + +int spider_end_trx( + SPIDER_TRX *trx, + SPIDER_CONN *conn +); + +int spider_check_trx_and_get_conn( + THD *thd, + ha_spider *spider, + bool use_conn_kind +); + +THD *spider_create_tmp_thd(); + +void spider_free_tmp_thd( + THD *thd +); + +int spider_create_trx_ha( + SPIDER_TRX *trx, + ha_spider *spider, + SPIDER_TRX_HA *trx_ha +); + +SPIDER_TRX_HA *spider_check_trx_ha( + SPIDER_TRX *trx, + ha_spider *spider +); + +void spider_free_trx_ha( + SPIDER_TRX *trx +); + +void spider_reuse_trx_ha( + SPIDER_TRX *trx +); + +void spider_trx_set_link_idx_for_all( + ha_spider *spider +); + +int spider_trx_check_link_idx_failed( + ha_spider *spider +); + +#ifdef HA_CAN_BULK_ACCESS +void spider_trx_add_bulk_access_conn( + SPIDER_TRX *trx, + SPIDER_CONN *conn +); +#endif diff --git a/storage/spider/spd_udf.cc b/storage/spider/spd_udf.cc new file mode 100644 index 00000000000..c116bd13805 --- /dev/null +++ b/storage/spider/spd_udf.cc @@ -0,0 +1,154 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +#define MYSQL_SERVER 1 +#include +#include "mysql.h" +#include "spd_udf.h" + +extern "C" { +long long spider_direct_sql( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + return spider_direct_sql_body(initid, args, is_null, error, FALSE); +} + +my_bool spider_direct_sql_init( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + return spider_direct_sql_init_body(initid, args, message, FALSE); +} + +void spider_direct_sql_deinit( + UDF_INIT *initid +) { + spider_direct_sql_deinit_body(initid); +} + +#ifndef WITHOUT_SPIDER_BG_SEARCH +long long spider_bg_direct_sql( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + return spider_direct_sql_bg_end(initid); +} + +my_bool spider_bg_direct_sql_init( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + return spider_direct_sql_init_body(initid, args, message, TRUE); +} + +void spider_bg_direct_sql_deinit( + UDF_INIT *initid +) { + spider_direct_sql_deinit_body(initid); +} + +void spider_bg_direct_sql_clear( + UDF_INIT *initid, + char *is_null, + char *error +) { + spider_direct_sql_bg_start(initid); +} + +void spider_bg_direct_sql_add( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + spider_direct_sql_body(initid, args, is_null, error, TRUE); +} +#endif + +long long spider_ping_table( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + return spider_ping_table_body(initid, args, is_null, error); +} + +my_bool spider_ping_table_init( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + return spider_ping_table_init_body(initid, args, message); +} + +void spider_ping_table_deinit( + UDF_INIT *initid +) { + spider_ping_table_deinit_body(initid); +} + +long long spider_flush_table_mon_cache( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + return spider_flush_table_mon_cache_body(); +} + +my_bool spider_flush_table_mon_cache_init( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + return FALSE; +} + +void spider_flush_table_mon_cache_deinit( + UDF_INIT *initid +) { +} + +long long spider_copy_tables( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +) { + return spider_copy_tables_body(initid, args, is_null, error); +} + +my_bool spider_copy_tables_init( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +) { + return spider_copy_tables_init_body(initid, args, message); +} + +void spider_copy_tables_deinit( + UDF_INIT *initid +) { + spider_copy_tables_deinit_body(initid); +} +} diff --git a/storage/spider/spd_udf.def b/storage/spider/spd_udf.def new file mode 100644 index 00000000000..d0d7d53e3fe --- /dev/null +++ b/storage/spider/spd_udf.def @@ -0,0 +1,20 @@ +LIBRARY ha_spider +VERSION 1.0 +EXPORTS + spider_direct_sql + spider_direct_sql_init + spider_direct_sql_deinit + spider_bg_direct_sql + spider_bg_direct_sql_init + spider_bg_direct_sql_deinit + spider_bg_direct_sql_clear + spider_bg_direct_sql_add + spider_ping_table + spider_ping_table_init + spider_ping_table_deinit + spider_flush_table_mon_cache + spider_flush_table_mon_cache_init + spider_flush_table_mon_cache_deinit + spider_copy_tables + spider_copy_tables_init + spider_copy_tables_deinit diff --git a/storage/spider/spd_udf.h b/storage/spider/spd_udf.h new file mode 100644 index 00000000000..eb70055247c --- /dev/null +++ b/storage/spider/spd_udf.h @@ -0,0 +1,79 @@ +/* Copyright (C) 2009-2013 Kentoku Shiba + + 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 */ + +long long spider_direct_sql_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error, + my_bool bg +); + +my_bool spider_direct_sql_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message, + my_bool bg +); + +void spider_direct_sql_deinit_body( + UDF_INIT *initid +); + +#ifndef WITHOUT_SPIDER_BG_SEARCH +void spider_direct_sql_bg_start( + UDF_INIT *initid +); + +long long spider_direct_sql_bg_end( + UDF_INIT *initid +); +#endif + +long long spider_ping_table_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +); + +my_bool spider_ping_table_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +); + +void spider_ping_table_deinit_body( + UDF_INIT *initid +); + +long long spider_flush_table_mon_cache_body(); + +long long spider_copy_tables_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +); + +my_bool spider_copy_tables_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +); + +void spider_copy_tables_deinit_body( + UDF_INIT *initid +); diff --git a/storage/xtradb/btr/btr0btr.c b/storage/xtradb/btr/btr0btr.c index a3e57d632a0..79a8eb9dcc6 100644 --- a/storage/xtradb/btr/btr0btr.c +++ b/storage/xtradb/btr/btr0btr.c @@ -688,7 +688,7 @@ btr_root_fseg_validate( { ulint offset = mach_read_from_2(seg_header + FSEG_HDR_OFFSET); - if (UNIV_UNLIKELY(srv_pass_corrupt_table)) { + if (UNIV_UNLIKELY(srv_pass_corrupt_table != 0)) { return (mach_read_from_4(seg_header + FSEG_HDR_SPACE) == space) && (offset >= FIL_PAGE_DATA) && (offset <= UNIV_PAGE_SIZE - FIL_PAGE_DATA_END); @@ -723,17 +723,14 @@ btr_root_block_get( block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, index, mtr); - if (srv_pass_corrupt_table && !block) { - return(0); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(0);); btr_assert_not_corrupted(block, index); #ifdef UNIV_BTR_DEBUG if (!dict_index_is_ibuf(index)) { const page_t* root = buf_block_get_frame(block); - if (UNIV_UNLIKELY(srv_pass_corrupt_table)) { + if (UNIV_UNLIKELY(srv_pass_corrupt_table != 0)) { if (!btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_LEAF + root, space)) @@ -1063,11 +1060,11 @@ btr_get_size( root = btr_root_get(index, mtr); - if (srv_pass_corrupt_table && !root) { + SRV_CORRUPT_TABLE_CHECK(root, + { mtr_commit(mtr); return(0); - } - ut_a(root); + }); if (flag == BTR_N_LEAF_PAGES) { seg_header = root + PAGE_HEADER + PAGE_BTR_SEG_LEAF; @@ -1525,11 +1522,11 @@ leaf_loop: root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH, NULL, &mtr); - if (srv_pass_corrupt_table && !root) { + SRV_CORRUPT_TABLE_CHECK(root, + { mtr_commit(&mtr); return; - } - ut_a(root); + }); #ifdef UNIV_BTR_DEBUG ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_LEAF @@ -1555,11 +1552,12 @@ top_loop: root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH, NULL, &mtr); - if (srv_pass_corrupt_table && !root) { + SRV_CORRUPT_TABLE_CHECK(root, + { mtr_commit(&mtr); return; - } - ut_a(root); + }); + #ifdef UNIV_BTR_DEBUG ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_TOP + root, space)); @@ -1593,10 +1591,7 @@ btr_free_root( block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, NULL, mtr); - if (srv_pass_corrupt_table && !block) { - return; - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return;); btr_search_drop_page_hash_index(block); @@ -4565,10 +4560,11 @@ btr_validate_index( root = btr_root_get(index, &mtr); - if (UNIV_UNLIKELY(srv_pass_corrupt_table && !root)) { + SRV_CORRUPT_TABLE_CHECK(root, + { mtr_commit(&mtr); return(FALSE); - } + }); n = btr_page_get_level(root, &mtr); diff --git a/storage/xtradb/btr/btr0cur.c b/storage/xtradb/btr/btr0cur.c index d089fb5ad22..488212f087c 100644 --- a/storage/xtradb/btr/btr0cur.c +++ b/storage/xtradb/btr/btr0cur.c @@ -258,10 +258,8 @@ btr_cur_latch_leaves( get_block = btr_block_get( space, zip_size, page_no, mode, cursor->index, mtr); - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); #endif /* UNIV_BTR_DEBUG */ @@ -283,10 +281,8 @@ btr_cur_latch_leaves( space, zip_size, left_page_no, sibling_mode, cursor->index, mtr); - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); @@ -309,10 +305,8 @@ btr_cur_latch_leaves( space, zip_size, page_no, mode, cursor->index, mtr); - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); #endif /* UNIV_BTR_DEBUG */ @@ -325,10 +319,8 @@ btr_cur_latch_leaves( space, zip_size, right_page_no, sibling_mode, cursor->index, mtr); - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); @@ -357,10 +349,8 @@ btr_cur_latch_leaves( left_page_no, mode, cursor->index, mtr); cursor->left_block = get_block; - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); @@ -373,10 +363,8 @@ btr_cur_latch_leaves( get_block = btr_block_get( space, zip_size, page_no, mode, cursor->index, mtr); - if (srv_pass_corrupt_table && !get_block) { - return; - } - ut_a(get_block); + SRV_CORRUPT_TABLE_CHECK(get_block, return;); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(get_block->frame) == page_is_comp(page)); #endif /* UNIV_BTR_DEBUG */ @@ -652,18 +640,19 @@ retry_page_get: file, line, mtr); if (block == NULL) { - if (srv_pass_corrupt_table - && buf_mode != BUF_GET_IF_IN_POOL - && buf_mode != BUF_GET_IF_IN_POOL_OR_WATCH) { - page_cursor->block = 0; - page_cursor->rec = 0; - if (estimate) { - cursor->path_arr->nth_rec = ULINT_UNDEFINED; - } - goto func_exit; - } - ut_a(buf_mode == BUF_GET_IF_IN_POOL - || buf_mode == BUF_GET_IF_IN_POOL_OR_WATCH); + SRV_CORRUPT_TABLE_CHECK(buf_mode == BUF_GET_IF_IN_POOL || + buf_mode == BUF_GET_IF_IN_POOL_OR_WATCH, + { + page_cursor->block = 0; + page_cursor->rec = 0; + if (estimate) { + + cursor->path_arr->nth_rec = + ULINT_UNDEFINED; + } + + goto func_exit; + }); /* This must be a search to perform an insert/delete mark/ delete; try using the insert/delete buffer */ @@ -739,15 +728,18 @@ retry_page_get: block->check_index_page_at_flush = TRUE; page = buf_block_get_frame(block); - if (srv_pass_corrupt_table && !page) { + SRV_CORRUPT_TABLE_CHECK(page, + { page_cursor->block = 0; page_cursor->rec = 0; + if (estimate) { + cursor->path_arr->nth_rec = ULINT_UNDEFINED; } + goto func_exit; - } - ut_a(page); + }); if (rw_latch != RW_NO_LATCH) { #ifdef UNIV_ZIP_DEBUG @@ -943,15 +935,19 @@ btr_cur_open_at_index_side_func( file, line, mtr); page = buf_block_get_frame(block); - if (srv_pass_corrupt_table && !page) { + SRV_CORRUPT_TABLE_CHECK(page, + { page_cursor->block = 0; page_cursor->rec = 0; + if (estimate) { - cursor->path_arr->nth_rec = ULINT_UNDEFINED; + + cursor->path_arr->nth_rec = + ULINT_UNDEFINED; } - break; - } - ut_a(page); + /* Can't use break with the macro */ + goto exit_loop; + }); ut_ad(index->id == btr_page_get_index_id(page)); @@ -1021,6 +1017,7 @@ btr_cur_open_at_index_side_func( page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets); } +exit_loop: if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } @@ -1074,12 +1071,13 @@ btr_cur_open_at_rnd_pos_func( file, line, mtr); page = buf_block_get_frame(block); - if (srv_pass_corrupt_table && !page) { + SRV_CORRUPT_TABLE_CHECK(page, + { page_cursor->block = 0; page_cursor->rec = 0; - break; - } - ut_a(page); + + goto exit_loop; + }); ut_ad(index->id == btr_page_get_index_id(page)); @@ -1112,6 +1110,7 @@ btr_cur_open_at_rnd_pos_func( page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets); } +exit_loop: if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } @@ -1300,10 +1299,7 @@ btr_cur_optimistic_insert( block = btr_cur_get_block(cursor); - if (srv_pass_corrupt_table && !block) { - return(DB_CORRUPTION); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(DB_CORRUPTION);); page = buf_block_get_frame(block); index = cursor->index; @@ -3149,10 +3145,7 @@ btr_cur_optimistic_delete( block = btr_cur_get_block(cursor); - if (srv_pass_corrupt_table && !block) { - return(DB_CORRUPTION); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(DB_CORRUPTION);); ut_ad(page_is_leaf(buf_block_get_frame(block))); @@ -3868,10 +3861,7 @@ btr_estimate_number_of_different_key_vals( page = btr_cur_get_page(&cursor); - if (srv_pass_corrupt_table && !page) { - break; - } - ut_a(page); + SRV_CORRUPT_TABLE_CHECK(page, goto exit_loop;); rec = page_rec_get_next(page_get_infimum_rec(page)); @@ -3957,6 +3947,7 @@ btr_estimate_number_of_different_key_vals( mtr_commit(&mtr); } +exit_loop: /* If we saw k borders between different key values on n_sample_pages leaf pages, we can estimate how many there will be in index->stat_n_leaf_pages */ diff --git a/storage/xtradb/btr/btr0pcur.c b/storage/xtradb/btr/btr0pcur.c index a1b7affdeb7..7c4ec2dd1ac 100644 --- a/storage/xtradb/btr/btr0pcur.c +++ b/storage/xtradb/btr/btr0pcur.c @@ -116,10 +116,7 @@ btr_pcur_store_position( block = btr_pcur_get_block(cursor); - if (srv_pass_corrupt_table && !block) { - return; - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return;); index = btr_cur_get_index(btr_pcur_get_btr_cur(cursor)); @@ -439,14 +436,16 @@ btr_pcur_move_to_next_page( btr_pcur_get_btr_cur(cursor)->index, mtr); next_page = buf_block_get_frame(next_block); - if (srv_pass_corrupt_table && !next_page) { + SRV_CORRUPT_TABLE_CHECK(next_page, + { btr_leaf_page_release(btr_pcur_get_block(cursor), cursor->latch_mode, mtr); btr_pcur_get_page_cur(cursor)->block = 0; btr_pcur_get_page_cur(cursor)->rec = 0; + return; - } - ut_a(next_page); + }); + #ifdef UNIV_BTR_DEBUG ut_a(page_is_comp(next_page) == page_is_comp(page)); ut_a(btr_page_get_prev(next_page, mtr) diff --git a/storage/xtradb/btr/btr0sea.c b/storage/xtradb/btr/btr0sea.c index 7e9449a6474..d53452bb959 100644 --- a/storage/xtradb/btr/btr0sea.c +++ b/storage/xtradb/btr/btr0sea.c @@ -649,10 +649,7 @@ btr_search_info_update_slow( block = btr_cur_get_block(cursor); - if (srv_pass_corrupt_table && !block) { - return; - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return;); /* NOTE that the following two function calls do NOT protect info or block->n_fields etc. with any semaphore, to save CPU time! diff --git a/storage/xtradb/buf/buf0buf.c b/storage/xtradb/buf/buf0buf.c index 5bcfb0f51b9..ae4b2fba98d 100644 --- a/storage/xtradb/buf/buf0buf.c +++ b/storage/xtradb/buf/buf0buf.c @@ -2002,27 +2002,6 @@ lookup: #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */ } - if (UNIV_UNLIKELY(bpage->space_was_being_deleted)) { - /* This page is obsoleted, should discard and retry */ - rw_lock_s_unlock(&buf_pool->page_hash_latch); - - mutex_enter(&buf_pool->LRU_list_mutex); - block_mutex = buf_page_get_mutex_enter(bpage); - - if (UNIV_UNLIKELY(!block_mutex)) { - mutex_exit(&buf_pool->LRU_list_mutex); - goto lookup; - } - - buf_LRU_free_block(bpage, TRUE, TRUE); - - mutex_exit(&buf_pool->LRU_list_mutex); - mutex_exit(block_mutex); - block_mutex = NULL; - - goto lookup; - } - if (UNIV_UNLIKELY(!bpage->zip.data)) { /* There is no compressed page. */ err_exit: @@ -2031,11 +2010,11 @@ err_exit: return(NULL); } - if (srv_pass_corrupt_table <= 1) { - if (bpage->is_corrupt) { - rw_lock_s_unlock(&buf_pool->page_hash_latch); - return(NULL); - } + if (UNIV_UNLIKELY(bpage->is_corrupt && srv_pass_corrupt_table <= 1)) { + + rw_lock_s_unlock(&buf_pool->page_hash_latch); + + return(NULL); } block_mutex = buf_page_get_mutex_enter(bpage); @@ -2533,26 +2512,6 @@ loop: block = (buf_block_t*) buf_page_hash_get_low( buf_pool, space, offset, fold); if (block) { - if (UNIV_UNLIKELY(block->page.space_was_being_deleted)) { - /* This page is obsoleted, should discard and retry */ - rw_lock_s_unlock(&buf_pool->page_hash_latch); - - mutex_enter(&buf_pool->LRU_list_mutex); - block_mutex = buf_page_get_mutex_enter((buf_page_t*)block); - - if (UNIV_UNLIKELY(!block_mutex)) { - mutex_exit(&buf_pool->LRU_list_mutex); - goto loop; - } - - buf_LRU_free_block((buf_page_t*)block, TRUE, TRUE); - - mutex_exit(&buf_pool->LRU_list_mutex); - mutex_exit(block_mutex); - block_mutex = NULL; - - goto loop; - } block_mutex = buf_page_get_mutex_enter((buf_page_t*)block); ut_a(block_mutex); @@ -2640,11 +2599,12 @@ got_block: return(NULL); } - if (srv_pass_corrupt_table <= 1) { - if (block->page.is_corrupt) { - mutex_exit(block_mutex); - return(NULL); - } + if (UNIV_UNLIKELY(block->page.is_corrupt && + srv_pass_corrupt_table <= 1)) { + + mutex_exit(block_mutex); + + return(NULL); } switch (buf_block_get_state(block)) { @@ -3487,28 +3447,12 @@ buf_page_init_for_read( fold = buf_page_address_fold(space, offset); -retry: //buf_pool_mutex_enter(buf_pool); mutex_enter(&buf_pool->LRU_list_mutex); rw_lock_x_lock(&buf_pool->page_hash_latch); watch_page = buf_page_hash_get_low(buf_pool, space, offset, fold); - if (UNIV_UNLIKELY(watch_page && watch_page->space_was_being_deleted)) { - mutex_t* block_mutex = buf_page_get_mutex_enter(watch_page); - - /* This page is obsoleted, should discard and retry */ - rw_lock_x_unlock(&buf_pool->page_hash_latch); - ut_a(block_mutex); - - buf_LRU_free_block(watch_page, TRUE, TRUE); - - mutex_exit(&buf_pool->LRU_list_mutex); - mutex_exit(block_mutex); - - goto retry; - } - if (watch_page && !buf_pool_watch_is_sentinel(buf_pool, watch_page)) { /* The page is already in the buffer pool. */ watch_page = NULL; @@ -3637,7 +3581,6 @@ err_exit: bpage->state = BUF_BLOCK_ZIP_PAGE; bpage->space = space; bpage->offset = offset; - bpage->space_was_being_deleted = FALSE; #ifdef UNIV_DEBUG bpage->in_page_hash = FALSE; @@ -3722,7 +3665,6 @@ buf_page_create( fold = buf_page_address_fold(space, offset); -retry: //buf_pool_mutex_enter(buf_pool); mutex_enter(&buf_pool->LRU_list_mutex); rw_lock_x_lock(&buf_pool->page_hash_latch); @@ -3730,21 +3672,6 @@ retry: block = (buf_block_t*) buf_page_hash_get_low( buf_pool, space, offset, fold); - if (UNIV_UNLIKELY(block && block->page.space_was_being_deleted)) { - mutex_t* block_mutex = buf_page_get_mutex_enter((buf_page_t*)block); - - /* This page is obsoleted, should discard and retry */ - rw_lock_x_unlock(&buf_pool->page_hash_latch); - ut_a(block_mutex); - - buf_LRU_free_block((buf_page_t*)block, TRUE, TRUE); - - mutex_exit(&buf_pool->LRU_list_mutex); - mutex_exit(block_mutex); - - goto retry; - } - if (block && buf_page_in_file(&block->page) && !buf_pool_watch_is_sentinel(buf_pool, &block->page)) { @@ -4001,7 +3928,8 @@ buf_page_io_complete( (ulong) bpage->offset); } - if (!srv_pass_corrupt_table || !bpage->is_corrupt) { + if (UNIV_LIKELY(!bpage->is_corrupt || + !srv_pass_corrupt_table)) { /* From version 3.23.38 up we store the page checksum to the 4 first bytes of the page end lsn field */ @@ -4086,13 +4014,26 @@ corrupt: } if (uncompressed && !recv_no_ibuf_operations) { + + buf_block_t* block; + ibool update_ibuf_bitmap; + + if (UNIV_UNLIKELY(bpage->is_corrupt && + srv_pass_corrupt_table)) { + + block = NULL; + update_ibuf_bitmap = FALSE; + + } else { + + block = (buf_block_t *) bpage; + update_ibuf_bitmap = TRUE; + } + ibuf_merge_or_delete_for_page( - /* Delete possible entries, if bpage is_corrupt */ - (srv_pass_corrupt_table && bpage->is_corrupt) ? NULL : - (buf_block_t*) bpage, bpage->space, + block, bpage->space, bpage->offset, buf_page_get_zip_size(bpage), - (srv_pass_corrupt_table && bpage->is_corrupt) ? FALSE : - TRUE); + update_ibuf_bitmap); } } diff --git a/storage/xtradb/buf/buf0flu.c b/storage/xtradb/buf/buf0flu.c index 663e2d8f537..9452b53df38 100644 --- a/storage/xtradb/buf/buf0flu.c +++ b/storage/xtradb/buf/buf0flu.c @@ -459,7 +459,7 @@ buf_flush_ready_for_replace( if (UNIV_LIKELY(bpage->in_LRU_list && buf_page_in_file(bpage))) { - return((bpage->oldest_modification == 0 || bpage->space_was_being_deleted) + return(bpage->oldest_modification == 0 && buf_page_get_io_fix(bpage) == BUF_IO_NONE && bpage->buf_fix_count == 0); } @@ -501,13 +501,6 @@ buf_flush_ready_for_flush( && buf_page_get_io_fix(bpage) == BUF_IO_NONE) { ut_ad(bpage->in_flush_list); - if (bpage->space_was_being_deleted) { - /* should be removed from flush_list here */ - /* because buf_flush_try_neighbors() cannot flush without fil_space_get_size(space) */ - buf_flush_remove(bpage); - return(FALSE); - } - if (flush_type != BUF_FLUSH_LRU) { return(TRUE); diff --git a/storage/xtradb/buf/buf0lru.c b/storage/xtradb/buf/buf0lru.c index cd99d3e4e13..8a35c87c92f 100644 --- a/storage/xtradb/buf/buf0lru.c +++ b/storage/xtradb/buf/buf0lru.c @@ -884,42 +884,6 @@ buf_LRU_flush_or_remove_pages( } } -/******************************************************************//** -*/ -UNIV_INTERN -void -buf_LRU_mark_space_was_deleted( -/*===========================*/ - ulint id) /*!< in: space id */ -{ - ulint i; - - for (i = 0; i < srv_buf_pool_instances; i++) { - buf_pool_t* buf_pool; - buf_page_t* bpage; - - buf_pool = buf_pool_from_array(i); - - mutex_enter(&buf_pool->LRU_list_mutex); - - bpage = UT_LIST_GET_FIRST(buf_pool->LRU); - - while (bpage != NULL) { - if (buf_page_get_space(bpage) == id) { - bpage->space_was_being_deleted = TRUE; - } - bpage = UT_LIST_GET_NEXT(LRU, bpage); - } - - mutex_exit(&buf_pool->LRU_list_mutex); - - /* The AHI entries for the tablespace being deleted should be - removed by now. */ - ut_ad(buf_LRU_drop_page_hash_for_tablespace(buf_pool, id) - == 0); - } -} - #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG /********************************************************************//** Insert a compressed block into buf_pool->zip_clean in the LRU order. */ @@ -1891,10 +1855,6 @@ buf_LRU_free_block( return(FALSE); } - if (bpage->space_was_being_deleted && bpage->oldest_modification != 0) { - buf_flush_remove(bpage); - } - #ifdef UNIV_IBUF_COUNT_DEBUG ut_a(ibuf_count_get(bpage->space, bpage->offset) == 0); #endif /* UNIV_IBUF_COUNT_DEBUG */ diff --git a/storage/xtradb/buf/buf0rea.c b/storage/xtradb/buf/buf0rea.c index cf0a029df92..5edbeadb64e 100644 --- a/storage/xtradb/buf/buf0rea.c +++ b/storage/xtradb/buf/buf0rea.c @@ -245,13 +245,7 @@ not_to_recover: return(0); } - if (srv_pass_corrupt_table) { - if (*err != DB_SUCCESS) { - bpage->is_corrupt = TRUE; - } - } else { - ut_a(*err == DB_SUCCESS); - } + SRV_CORRUPT_TABLE_CHECK(*err == DB_SUCCESS, bpage->is_corrupt = TRUE;); if (sync) { /* The i/o is already completed when we arrive from diff --git a/storage/xtradb/dict/dict0dict.c b/storage/xtradb/dict/dict0dict.c index 4c6875bca10..e07cc69aded 100644 --- a/storage/xtradb/dict/dict0dict.c +++ b/storage/xtradb/dict/dict0dict.c @@ -4438,7 +4438,7 @@ dict_reload_statistics( while (index) { mtr_t mtr; - if (table->is_corrupt) { + if (UNIV_UNLIKELY(table->is_corrupt)) { ut_a(srv_pass_corrupt_table); mem_heap_free(heap); return(FALSE); @@ -4596,7 +4596,7 @@ dict_store_statistics( heap = mem_heap_create(1000); while (index) { - if (table->is_corrupt) { + if (UNIV_UNLIKELY(table->is_corrupt)) { ut_a(srv_pass_corrupt_table); mem_heap_free(heap); return; @@ -4790,7 +4790,7 @@ dict_update_statistics( mtr_t mtr; ulint size; - if (table->is_corrupt) { + if (UNIV_UNLIKELY(table->is_corrupt)) { ut_a(srv_pass_corrupt_table); dict_table_stats_unlock(table, RW_X_LATCH); return; diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 397c4de4b6e..ff4e5b1b033 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -2426,15 +2426,11 @@ try_again: To deal with potential read requests by checking the ::stop_new_ops flag in fil_io() */ - if (srv_lazy_drop_table) { - buf_LRU_mark_space_was_deleted(id); - } else { buf_LRU_flush_or_remove_pages( id, evict_all ? BUF_REMOVE_ALL_NO_WRITE : BUF_REMOVE_FLUSH_NO_WRITE); - } #endif /* printf("Deleting tablespace %s id %lu\n", space->name, id); */ @@ -5326,22 +5322,6 @@ _fil_io( srv_data_written+= len; } - /* if the table space was already deleted, space might not exist already. */ - if (message - && space_id < SRV_LOG_SPACE_FIRST_ID - && ((buf_page_t*)message)->space_was_being_deleted) { - - if (mode == OS_AIO_NORMAL) { - buf_page_io_complete(message); - return(DB_SUCCESS); /*fake*/ - } - if (type == OS_FILE_READ) { - return(DB_TABLESPACE_DELETED); - } else { - return(DB_SUCCESS); /*fake*/ - } - } - /* Reserve the fil_system mutex and make sure that we can open at least one file while holding it, if the file is not already open */ @@ -5445,35 +5425,38 @@ _fil_io( ut_a(byte_offset % OS_MIN_LOG_BLOCK_SIZE == 0); ut_a((len % OS_MIN_LOG_BLOCK_SIZE) == 0); - if (srv_pass_corrupt_table == 1 && space->is_corrupt) { +#ifndef UNIV_HOTBACKUP + if (UNIV_UNLIKELY(space->is_corrupt && srv_pass_corrupt_table)) { + /* should ignore i/o for the crashed space */ - mutex_enter(&fil_system->mutex); - fil_node_complete_io(node, fil_system, type); - mutex_exit(&fil_system->mutex); - if (mode == OS_AIO_NORMAL) { - ut_a(space->purpose == FIL_TABLESPACE); - buf_page_io_complete(message); - } - if (type == OS_FILE_READ) { - return(DB_TABLESPACE_DELETED); - } else { - return(DB_SUCCESS); - } - } else { - if (srv_pass_corrupt_table > 1 && space->is_corrupt) { - /* should ignore write i/o for the crashed space */ - if (type == OS_FILE_WRITE) { - mutex_enter(&fil_system->mutex); - fil_node_complete_io(node, fil_system, type); - mutex_exit(&fil_system->mutex); - if (mode == OS_AIO_NORMAL) { - ut_a(space->purpose == FIL_TABLESPACE); - buf_page_io_complete(message); - } - return(DB_SUCCESS); + if (srv_pass_corrupt_table == 1 || + type == OS_FILE_WRITE) { + + mutex_enter(&fil_system->mutex); + fil_node_complete_io(node, fil_system, type); + mutex_exit(&fil_system->mutex); + if (mode == OS_AIO_NORMAL) { + ut_a(space->purpose == FIL_TABLESPACE); + buf_page_io_complete(message); } } -#ifdef UNIV_HOTBACKUP + + if (srv_pass_corrupt_table == 1 && type == OS_FILE_READ) { + + return(DB_TABLESPACE_DELETED); + + } else if (type == OS_FILE_WRITE) { + + return(DB_SUCCESS); + } + } /**/ + + /* Queue the aio request */ + ret = os_aio(type, mode | wake_later, node->name, node->handle, buf, + offset_low, offset_high, len, node, message, space_id, + trx); + +#else /* In ibbackup do normal i/o, not aio */ if (type == OS_FILE_READ) { ret = os_file_read(node->handle, buf, offset_low, offset_high, @@ -5482,26 +5465,7 @@ _fil_io( ret = os_file_write(node->name, node->handle, buf, offset_low, offset_high, len); } -#else - /* Queue the aio request */ - ret = os_aio(type, mode | wake_later, node->name, node->handle, buf, - offset_low, offset_high, len, node, message, space_id, trx); #endif - } /**/ - - /* if the table space was already deleted, space might not exist already. */ - if (message - && space_id < SRV_LOG_SPACE_FIRST_ID - && ((buf_page_t*)message)->space_was_being_deleted) { - - if (mode == OS_AIO_SYNC) { - if (type == OS_FILE_READ) { - return(DB_TABLESPACE_DELETED); - } else { - return(DB_SUCCESS); /*fake*/ - } - } - } ut_a(ret); @@ -5625,21 +5589,6 @@ fil_aio_wait( &message, &type, &space_id); } - /* if the table space was already deleted, fil_node might not exist already. */ - if (message - && space_id < SRV_LOG_SPACE_FIRST_ID - && ((buf_page_t*)message)->space_was_being_deleted) { - - /* intended not to be uncompress read page */ - ut_a(buf_page_get_io_fix_unlocked(message) == BUF_IO_WRITE - || !buf_page_get_zip_size(message) - || buf_page_get_state(message) != BUF_BLOCK_FILE_PAGE); - - srv_set_io_thread_op_info(segment, "complete io for buf page"); - buf_page_io_complete(message); - return; - } - ut_a(ret); if (UNIV_UNLIKELY(fil_node == NULL)) { ut_ad(srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS); diff --git a/storage/xtradb/fsp/fsp0fsp.c b/storage/xtradb/fsp/fsp0fsp.c index 5cbc74b0862..d5717638f29 100644 --- a/storage/xtradb/fsp/fsp0fsp.c +++ b/storage/xtradb/fsp/fsp0fsp.c @@ -317,10 +317,7 @@ fsp_get_space_header( block = buf_page_get(id, zip_size, 0, RW_X_LATCH, mtr); - if (srv_pass_corrupt_table && !block) { - return(0); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(0);); header = FSP_HEADER_OFFSET + buf_block_get_frame(block); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); @@ -728,10 +725,7 @@ xdes_get_descriptor( block = buf_page_get(space, zip_size, 0, RW_X_LATCH, mtr); - if (srv_pass_corrupt_table && !block) { - return(0); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(0);); buf_block_dbg_add_level(block, SYNC_FSP_PAGE); @@ -1879,10 +1873,7 @@ fsp_seg_inode_page_find_free( { fseg_inode_t* inode; - if (srv_pass_corrupt_table && !page) { - return(ULINT_UNDEFINED); - } - ut_a(page); + SRV_CORRUPT_TABLE_CHECK(page, return(ULINT_UNDEFINED);); for (; i < FSP_SEG_INODES_PER_PAGE(zip_size); i++) { @@ -1996,10 +1987,7 @@ fsp_alloc_seg_inode( page = buf_block_get_frame(block); - if (srv_pass_corrupt_table && !page) { - return(0); - } - ut_a(page); + SRV_CORRUPT_TABLE_CHECK(page, return(0);); n = fsp_seg_inode_page_find_free(page, 0, zip_size, mtr); @@ -2094,10 +2082,7 @@ fseg_inode_try_get( inode = fut_get_ptr(space, zip_size, inode_addr, RW_X_LATCH, mtr); - if (srv_pass_corrupt_table && !inode) { - return(0); - } - ut_a(inode); + SRV_CORRUPT_TABLE_CHECK(inode, return(0);); if (UNIV_UNLIKELY(!mach_read_from_8(inode + FSEG_ID))) { @@ -2125,7 +2110,7 @@ fseg_inode_get( { fseg_inode_t* inode = fseg_inode_try_get(header, space, zip_size, mtr); - ut_a(srv_pass_corrupt_table || inode); + SRV_CORRUPT_TABLE_CHECK(inode, ; /* do nothing */); return(inode); } @@ -3317,12 +3302,12 @@ fseg_free_page_low( descr = xdes_get_descriptor(space, zip_size, page, mtr); - if (srv_pass_corrupt_table && !descr) { + SRV_CORRUPT_TABLE_CHECK(descr, + { /* The page may be corrupt. pass it. */ return; - } + }); - ut_a(descr); if (xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)) { fputs("InnoDB: Dump of the tablespace extent descriptor: ", stderr); @@ -3571,15 +3556,15 @@ fseg_free_step( descr = xdes_get_descriptor(space, zip_size, header_page, mtr); - if (srv_pass_corrupt_table && !descr) { + SRV_CORRUPT_TABLE_CHECK(descr, + { /* The page may be corrupt. pass it. */ return(TRUE); - } + }); /* Check that the header resides on a page which has not been freed yet */ - ut_a(descr); ut_a(xdes_get_bit(descr, XDES_FREE_BIT, header_page % FSP_EXTENT_SIZE, mtr) == FALSE); inode = fseg_inode_try_get(header, space, zip_size, mtr); @@ -3660,11 +3645,11 @@ fseg_free_step_not_header( inode = fseg_inode_get(header, space, zip_size, mtr); - if (srv_pass_corrupt_table && !inode) { + SRV_CORRUPT_TABLE_CHECK(inode, + { /* ignore the corruption */ return(TRUE); - } - ut_a(inode); + }); descr = fseg_get_first_extent(inode, space, zip_size, mtr); diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index fdef9e104c5..6b800238aae 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -236,6 +236,8 @@ static ulong innobase_sys_stats_root_page = 0; #endif static my_bool innobase_buffer_pool_shm_checksum = TRUE; static uint innobase_buffer_pool_shm_key = 0; +static ulint srv_lazy_drop_table = 0; + static char* internal_innobase_data_file_path = NULL; @@ -1947,7 +1949,7 @@ trx_is_started( /*===========*/ trx_t* trx) /* in: transaction */ { - return(trx->conc_state != TRX_NOT_STARTED); + return(trx->state != TRX_NOT_STARTED); } /*********************************************************************//** @@ -3072,6 +3074,12 @@ innobase_change_buffering_inited_ok: "InnoDB: innodb_buffer_pool_shm_key was ignored.\n"); } + if (srv_lazy_drop_table) { + fprintf(stderr, + "InnoDB: Warning: " + "innodb_lazy_drop_table is deprecated and ignored.\n"); + } + srv_mem_pool_size = (ulint) innobase_additional_mem_pool_size; srv_n_file_io_threads = (ulint) innobase_file_io_threads; @@ -4806,7 +4814,8 @@ ha_innobase::open( DBUG_RETURN(1); } - if (srv_pass_corrupt_table <= 1 && share->ib_table && share->ib_table->is_corrupt) { + if (UNIV_UNLIKELY(share->ib_table && share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { free_share(share); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); @@ -4831,7 +4840,8 @@ retry: /* Get pointer to a table object in InnoDB dictionary cache */ ib_table = dict_table_get(norm_name, TRUE); - if (srv_pass_corrupt_table <= 1 && ib_table && ib_table->is_corrupt) { + if (UNIV_UNLIKELY(ib_table && ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { free_share(share); my_free(upd_buf); upd_buf = NULL; @@ -7612,7 +7622,10 @@ ha_innobase::index_read( ut_a(prebuilt->trx == thd_to_trx(user_thd)); ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); - if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) { + ha_statistic_increment(&SSV::ha_read_key_count); + + if (UNIV_UNLIKELY(share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { DBUG_RETURN(HA_ERR_CRASHED); } @@ -7683,7 +7696,8 @@ ha_innobase::index_read( ret = DB_UNSUPPORTED; } - if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) { + if (UNIV_UNLIKELY(share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { DBUG_RETURN(HA_ERR_CRASHED); } @@ -7801,7 +7815,8 @@ ha_innobase::change_active_index( { DBUG_ENTER("change_active_index"); - if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) { + if (UNIV_UNLIKELY(share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { DBUG_RETURN(HA_ERR_CRASHED); } @@ -7919,7 +7934,8 @@ ha_innobase::general_fetch( DBUG_ENTER("general_fetch"); - if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) { + if (UNIV_UNLIKELY(share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { DBUG_RETURN(HA_ERR_CRASHED); } @@ -7932,7 +7948,8 @@ ha_innobase::general_fetch( innodb_srv_conc_exit_innodb(prebuilt->trx); - if (srv_pass_corrupt_table <= 1 && share->ib_table->is_corrupt) { + if (UNIV_UNLIKELY(share->ib_table->is_corrupt && + srv_pass_corrupt_table <= 1)) { DBUG_RETURN(HA_ERR_CRASHED); } @@ -10324,7 +10341,7 @@ ha_innobase::info_low( prebuilt->trx->op_info = "confirming rows of SYS_STATS to store statistics"; - ut_a(prebuilt->trx->conc_state == TRX_NOT_STARTED); + ut_a(!trx_is_started(prebuilt->trx)); for (index = dict_table_get_first_index(ib_table); index != NULL; @@ -10337,7 +10354,7 @@ ha_innobase::info_low( innobase_commit_low(prebuilt->trx); } - ut_a(prebuilt->trx->conc_state == TRX_NOT_STARTED); + ut_a(!trx_is_started(prebuilt->trx)); } prebuilt->trx->op_info = "updating table statistics"; @@ -14660,8 +14677,7 @@ static MYSQL_SYSVAR_ENUM(corrupt_table_action, srv_pass_corrupt_table, static MYSQL_SYSVAR_ULINT(lazy_drop_table, srv_lazy_drop_table, PLUGIN_VAR_RQCMDARG, - "At deleting tablespace, only miminum needed processes at the time are done. " - "e.g. for http://bugs.mysql.com/51325", + "[Deprecated option] no effect", NULL, NULL, 0, 0, 1, 0); static MYSQL_SYSVAR_BOOL(locking_fake_changes, srv_fake_changes_locks, diff --git a/storage/xtradb/include/btr0btr.ic b/storage/xtradb/include/btr0btr.ic index 53c8159c448..798107628d7 100644 --- a/storage/xtradb/include/btr0btr.ic +++ b/storage/xtradb/include/btr0btr.ic @@ -59,7 +59,7 @@ btr_block_get_func( block = buf_page_get_gen(space, zip_size, page_no, mode, NULL, BUF_GET, file, line, mtr); - ut_a(srv_pass_corrupt_table || block); + SRV_CORRUPT_TABLE_CHECK(block, ; /* do nothing */); if (block && mode != RW_NO_LATCH) { diff --git a/storage/xtradb/include/buf0buf.h b/storage/xtradb/include/buf0buf.h index e0d7a974fc3..f00a06c8805 100644 --- a/storage/xtradb/include/buf0buf.h +++ b/storage/xtradb/include/buf0buf.h @@ -1589,7 +1589,6 @@ struct buf_page_struct{ 0 if the block was never accessed in the buffer pool. Protected by block mutex */ - ibool space_was_being_deleted; ibool is_corrupt; # if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG ibool file_page_was_freed; diff --git a/storage/xtradb/include/buf0buf.ic b/storage/xtradb/include/buf0buf.ic index 8d5c3edeef8..18c46b6412e 100644 --- a/storage/xtradb/include/buf0buf.ic +++ b/storage/xtradb/include/buf0buf.ic @@ -430,7 +430,6 @@ buf_block_set_file_page( buf_block_set_state(block, BUF_BLOCK_FILE_PAGE); block->page.space = space; block->page.offset = page_no; - block->page.space_was_being_deleted = FALSE; } /*********************************************************************//** @@ -712,13 +711,7 @@ buf_block_get_frame( /*================*/ const buf_block_t* block) /*!< in: pointer to the control block */ { - ut_a(srv_pass_corrupt_table || block); - - if (srv_pass_corrupt_table && !block) { - return(0); - } - - ut_ad(block); + SRV_CORRUPT_TABLE_CHECK(block, return(0);); switch (buf_block_get_state(block)) { case BUF_BLOCK_ZIP_FREE: diff --git a/storage/xtradb/include/buf0flu.ic b/storage/xtradb/include/buf0flu.ic index 30e2cc8efe8..8228c025d23 100644 --- a/storage/xtradb/include/buf0flu.ic +++ b/storage/xtradb/include/buf0flu.ic @@ -70,7 +70,7 @@ buf_flush_note_modification( ut_ad(!buf_pool_mutex_own(buf_pool)); ut_ad(!buf_flush_list_mutex_own(buf_pool)); - ut_ad(log_flush_order_mutex_own()); + ut_ad(!mtr->made_dirty || log_flush_order_mutex_own()); ut_ad(mtr->start_lsn != 0); ut_ad(mtr->modifications); diff --git a/storage/xtradb/include/buf0lru.h b/storage/xtradb/include/buf0lru.h index 2ea4f9b1ecf..8bb3aed4059 100644 --- a/storage/xtradb/include/buf0lru.h +++ b/storage/xtradb/include/buf0lru.h @@ -73,13 +73,6 @@ buf_LRU_flush_or_remove_pages( enum buf_remove_t buf_remove);/*!< in: remove or flush strategy */ -/******************************************************************//** -*/ -UNIV_INTERN -void -buf_LRU_mark_space_was_deleted( -/*===========================*/ - ulint id); /*!< in: space id */ #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG /********************************************************************//** Insert a compressed block into buf_pool->zip_clean in the LRU order. */ diff --git a/storage/xtradb/include/fut0fut.ic b/storage/xtradb/include/fut0fut.ic index 529f2a516d3..63e5736d99e 100644 --- a/storage/xtradb/include/fut0fut.ic +++ b/storage/xtradb/include/fut0fut.ic @@ -50,10 +50,7 @@ fut_get_ptr( block = buf_page_get(space, zip_size, addr.page, rw_latch, mtr); - if (srv_pass_corrupt_table && !block) { - return(0); - } - ut_a(block); + SRV_CORRUPT_TABLE_CHECK(block, return(0);); ptr = buf_block_get_frame(block) + addr.boffset; diff --git a/storage/xtradb/include/log0log.h b/storage/xtradb/include/log0log.h index 4f017e01dfd..59dfb457d56 100644 --- a/storage/xtradb/include/log0log.h +++ b/storage/xtradb/include/log0log.h @@ -122,16 +122,24 @@ UNIV_INLINE void log_free_check(void); /*================*/ -/************************************************************//** -Opens the log for log_write_low. The log must be closed with log_close and -released with log_release. -@return start lsn of the log record */ -UNIV_INTERN +/**************************************************************************//** +Locks the log mutex and opens the log for log_write_low. The log must be closed +with log_close and released with log_release. +@return start lsn of the log record */ +UNIV_INLINE ib_uint64_t log_reserve_and_open( /*=================*/ ulint len); /*!< in: length of data to be catenated */ /************************************************************//** +Opens the log for log_write_low. The log must be closed with log_close. +@return start lsn of the log record */ +UNIV_INTERN +ib_uint64_t +log_open( +/*=====*/ + ulint len); /*!< in: length of data to be catenated */ +/************************************************************//** Writes to the log the string given. It is assumed that the caller holds the log mutex. */ UNIV_INTERN diff --git a/storage/xtradb/include/log0log.ic b/storage/xtradb/include/log0log.ic index b54697637b0..5b864f3d7d4 100644 --- a/storage/xtradb/include/log0log.ic +++ b/storage/xtradb/include/log0log.ic @@ -332,10 +332,10 @@ log_reserve_and_write_fast( if (data_len >= OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE) { - /* The string does not fit within the current log block - or the log block would become full */ - - mutex_exit(&log_sys->mutex); + /* The string does not fit within the current log block or the + log block would become full. Do not release the log mutex, + because it has to be reacquired immediately for the "slow" write + procedure via log_write_low(). */ return(0); } @@ -382,6 +382,21 @@ log_reserve_and_write_fast( return(log_sys->lsn); } +/**************************************************************************//** +Locks the log mutex and opens the log for log_write_low. The log must be closed +with log_close and released with log_release. +@return start lsn of the log record */ +UNIV_INLINE +ib_uint64_t +log_reserve_and_open( +/*=================*/ + ulint len) /*!< in: length of data to be catenated */ +{ + mutex_enter(&(log_sys->mutex)); + + return log_open(len); +} + /***********************************************************************//** Releases the log mutex. */ UNIV_INLINE diff --git a/storage/xtradb/include/mtr0mtr.h b/storage/xtradb/include/mtr0mtr.h index 46f1ff9310c..c51632e0ed5 100644 --- a/storage/xtradb/include/mtr0mtr.h +++ b/storage/xtradb/include/mtr0mtr.h @@ -375,6 +375,8 @@ struct mtr_struct{ ibool modifications; /* TRUE if the mtr made modifications to buffer pool pages */ + ibool made_dirty;/*!< TRUE if mtr has made at least + one buffer pool page dirty */ ulint n_log_recs; /* count of how many page initial log records have been written to the mtr log */ diff --git a/storage/xtradb/include/mtr0mtr.ic b/storage/xtradb/include/mtr0mtr.ic index a03a0271535..7b5d268b70f 100644 --- a/storage/xtradb/include/mtr0mtr.ic +++ b/storage/xtradb/include/mtr0mtr.ic @@ -29,6 +29,17 @@ Created 11/26/1995 Heikki Tuuri #endif /* !UNIV_HOTBACKUP */ #include "mach0data.h" +/***************************************************//** +Checks if a mini-transaction is dirtying a clean page. +@return TRUE if the mtr is dirtying a clean page. */ +UNIV_INTERN +ibool +mtr_block_dirtied( +/*==============*/ + const buf_block_t* block) /*!< in: block being x-fixed */ + __attribute__((nonnull,warn_unused_result)); + + /***************************************************************//** Starts a mini-transaction. */ UNIV_INLINE @@ -47,6 +58,7 @@ mtr_start( mtr->inside_ibuf = FALSE; mtr->n_log_recs = 0; mtr->n_freed_pages = 0; + mtr->made_dirty = FALSE; ut_d(mtr->state = MTR_ACTIVE); ut_d(mtr->magic_n = MTR_MAGIC_N); @@ -65,6 +77,15 @@ mtr_memo_push( dyn_array_t* memo; mtr_memo_slot_t* slot; + /* If this mtr has x-fixed a clean page then we set + the made_dirty flag. This tells us if we need to + grab log_flush_order_mutex at mtr_commit so that we + can insert the dirtied page to the flush list. */ + if (type == MTR_MEMO_PAGE_X_FIX && !mtr->made_dirty) { + mtr->made_dirty = + mtr_block_dirtied((const buf_block_t *)object); + } + ut_ad(object); ut_ad(type >= MTR_MEMO_PAGE_S_FIX); ut_ad(type <= MTR_MEMO_X_LOCK); diff --git a/storage/xtradb/include/read0read.h b/storage/xtradb/include/read0read.h index 0c9468d985e..dd378ecc997 100644 --- a/storage/xtradb/include/read0read.h +++ b/storage/xtradb/include/read0read.h @@ -32,6 +32,7 @@ Created 2/16/1997 Heikki Tuuri #include "ut0byte.h" #include "ut0lst.h" #include "trx0trx.h" +#include "trx0sys.h" #include "read0types.h" /*********************************************************************//** @@ -44,8 +45,11 @@ read_view_open_now( /*===============*/ trx_id_t cr_trx_id, /*!< in: trx_id of creating transaction, or 0 used in purge */ - mem_heap_t* heap); /*!< in: memory heap from which - allocated */ + read_view_t* view, /*!< in: current read view or NULL if it + doesn't exist yet */ + ibool exclude_self); /*!< in: TRUE, if cr_trx_id should be + excluded from the resulting view */ + /*********************************************************************//** Makes a copy of the oldest existing read view, or opens a new. The view must be closed with ..._close. @@ -56,8 +60,8 @@ read_view_oldest_copy_or_open_new( /*==============================*/ trx_id_t cr_trx_id, /*!< in: trx_id of creating transaction, or 0 used in purge */ - mem_heap_t* heap); /*!< in: memory heap from which - allocated */ + read_view_t* view); /*!< in: pre-allocated view array or + NULL if a new one needs to be created */ /*********************************************************************//** Closes a read view. */ UNIV_INTERN @@ -66,6 +70,13 @@ read_view_close( /*============*/ read_view_t* view); /*!< in: read view */ /*********************************************************************//** +Frees memory allocated by a read view. */ +UNIV_INTERN +void +read_view_free( +/*===========*/ + read_view_t* view); /*< in: read view */ +/*********************************************************************//** Closes a consistent read view for MySQL. This function is called at an SQL statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */ UNIV_INTERN @@ -143,16 +154,20 @@ struct read_view_struct{ are strictly smaller (<) than this value. In other words, this is the "low water mark". */ - ulint n_trx_ids; + ulint n_descr; /*!< Number of cells in the trx_ids array */ - trx_id_t* trx_ids;/*!< Additional trx ids which the read should - not see: typically, these are the active + ulint max_descr; + /*!< Maximum number of cells in the trx_ids + array */ + trx_id_t* descriptors; + /*!< Array of trx descriptors which the read + should not see: typically, these are the active transactions at the time when the read is serialized, except the reading transaction itself; the trx ids in this array are in a descending order. These trx_ids should be - between the "low" and "high" water marks, - that is, up_limit_id and low_limit_id. */ + between the "low" and "high" water marks, that + is, up_limit_id and low_limit_id. */ trx_id_t creator_trx_id; /*!< trx id of creating transaction, or 0 used in purge */ diff --git a/storage/xtradb/include/read0read.ic b/storage/xtradb/include/read0read.ic index 5bb5249b591..ebcdb767406 100644 --- a/storage/xtradb/include/read0read.ic +++ b/storage/xtradb/include/read0read.ic @@ -25,6 +25,11 @@ Created 2/16/1997 Heikki Tuuri /*********************************************************************//** Gets the nth trx id in a read view. + +Upstream code stores array of trx_ids in the descending order. Percona Server +keeps it in the ascending order for performance reasons. Let us keep the +semantics. + @return trx id */ UNIV_INLINE trx_id_t @@ -33,13 +38,17 @@ read_view_get_nth_trx_id( const read_view_t* view, /*!< in: read view */ ulint n) /*!< in: position */ { - ut_ad(n < view->n_trx_ids); + ut_ad(n < view->n_descr); - return(*(view->trx_ids + n)); + return(view->descriptors[view->n_descr - 1 - n]); } /*********************************************************************//** -Sets the nth trx id in a read view. */ +Sets the nth trx id in a read view. + +Upstream code stores array of trx_ids in the descending order. Percona Server +keeps it in the ascending order for performance reasons. Let us keep the +semantics. */ UNIV_INLINE void read_view_set_nth_trx_id( @@ -48,9 +57,9 @@ read_view_set_nth_trx_id( ulint n, /*!< in: position */ trx_id_t trx_id) /*!< in: trx id to set */ { - ut_ad(n < view->n_trx_ids); + ut_ad(n < view->n_descr); - *(view->trx_ids + n) = trx_id; + view->descriptors[view->n_descr - 1 - n] = trx_id; } /*********************************************************************//** @@ -63,9 +72,6 @@ read_view_sees_trx_id( const read_view_t* view, /*!< in: read view */ trx_id_t trx_id) /*!< in: trx id */ { - ulint n_ids; - ulint i; - if (trx_id < view->up_limit_id) { return(TRUE); @@ -76,21 +82,8 @@ read_view_sees_trx_id( return(FALSE); } - /* We go through the trx ids in the array smallest first: this order - may save CPU time, because if there was a very long running - transaction in the trx id array, its trx id is looked at first, and - the first two comparisons may well decide the visibility of trx_id. */ + /* Do a binary search over this view's descriptors array */ - n_ids = view->n_trx_ids; - - for (i = 0; i < n_ids; i++) { - trx_id_t view_trx_id - = read_view_get_nth_trx_id(view, n_ids - i - 1); - - if (trx_id <= view_trx_id) { - return(trx_id != view_trx_id); - } - } - - return(TRUE); + return(trx_find_descriptor(view->descriptors, view->n_descr, + trx_id) == NULL); } diff --git a/storage/xtradb/include/srv0srv.h b/storage/xtradb/include/srv0srv.h index 17b32dff3be..52b625d8a76 100644 --- a/storage/xtradb/include/srv0srv.h +++ b/storage/xtradb/include/srv0srv.h @@ -278,9 +278,22 @@ extern ulong srv_adaptive_flushing_method; extern ulong srv_expand_import; extern ulong srv_pass_corrupt_table; -extern ulint srv_dict_size_limit; +/* Helper macro to support srv_pass_corrupt_table checks. If 'cond' is FALSE, +execute 'code' if srv_pass_corrupt_table is non-zero, or trigger a fatal error +otherwise. The break statement in 'code' will obviously not work as expected. */ -extern ulint srv_lazy_drop_table; +#define SRV_CORRUPT_TABLE_CHECK(cond,code) \ + do { \ + if (UNIV_UNLIKELY(!(cond))) { \ + if (srv_pass_corrupt_table) { \ + code \ + } else { \ + ut_error; \ + } \ + } \ + } while(0) + +extern ulint srv_dict_size_limit; /*-------------------------------------------*/ extern ulint srv_n_rows_inserted; diff --git a/storage/xtradb/include/trx0purge.h b/storage/xtradb/include/trx0purge.h index 2bd9e64476b..1d10d8cceab 100644 --- a/storage/xtradb/include/trx0purge.h +++ b/storage/xtradb/include/trx0purge.h @@ -143,6 +143,7 @@ struct trx_purge_struct{ obtaining an s-latch here. */ read_view_t* view; /*!< The purge will not remove undo logs which are >= this view (purge view) */ + read_view_t* prebuilt_view; /*!< Pre-built view array */ ulonglong n_pages_handled;/*!< Approximate number of undo log pages processed in purge */ ulonglong handle_limit; /*!< Target of how many pages to get diff --git a/storage/xtradb/include/trx0sys.h b/storage/xtradb/include/trx0sys.h index 7ae3ba74478..4683c097b53 100644 --- a/storage/xtradb/include/trx0sys.h +++ b/storage/xtradb/include/trx0sys.h @@ -252,6 +252,17 @@ trx_id_t trx_sys_get_new_trx_id(void); /*========================*/ +/*************************************************************//** +Find a slot for a given trx ID in a descriptors array. +@return: slot pointer */ +UNIV_INLINE +trx_id_t* +trx_find_descriptor( +/*================*/ + const trx_id_t* descriptors, /*!< in: descriptors array */ + ulint n_descr, /*!< in: array size */ + trx_id_t trx_id); /*!< in: trx pointer */ + #ifdef UNIV_DEBUG /* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ extern uint trx_rseg_n_slots_debug; @@ -663,6 +674,8 @@ identifier is added to this 64-bit constant. */ | TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW) /* @} */ +#define TRX_DESCR_ARRAY_INITIAL_SIZE 1000 + #ifndef UNIV_HOTBACKUP /** Doublewrite control struct */ struct trx_doublewrite_struct{ @@ -690,16 +703,41 @@ struct trx_sys_struct{ trx_id_t max_trx_id; /*!< The smallest number not yet assigned as a transaction id or transaction number */ + char pad1[64]; /*!< Ensure max_trx_id does not share + cache line with other fields. */ + trx_id_t* descriptors; /*!< Array of trx descriptors */ + ulint descr_n_max; /*!< The current size of the descriptors + array. */ + char pad2[64]; /*!< Ensure static descriptor fields + do not share cache lines with + descr_n_used */ + ulint descr_n_used; /*!< Number of used elements in the + descriptors array. */ + char pad3[64]; /*!< Ensure descriptors do not share + cache line with other fields */ UT_LIST_BASE_NODE_T(trx_t) trx_list; /*!< List of active and committed in memory transactions, sorted on trx id, biggest first */ + char pad4[64]; /*!< Ensure list base nodes do not + share cache line with other fields */ UT_LIST_BASE_NODE_T(trx_t) mysql_trx_list; /*!< List of transactions created for MySQL */ + char pad5[64]; /*!< Ensure list base nodes do not + share cache line with other fields */ + UT_LIST_BASE_NODE_T(trx_t) trx_serial_list; + /*!< trx->no ordered List of + transactions in either TRX_PREPARED or + TRX_ACTIVE which have already been + assigned a serialization number */ + char pad6[64]; /*!< Ensure trx_serial_list does not + share cache line with other fields */ UT_LIST_BASE_NODE_T(trx_rseg_t) rseg_list; /*!< List of rollback segment objects */ + char pad7[64]; /*!< Ensure list base nodes do not + share cache line with other fields */ trx_rseg_t* latest_rseg; /*!< Latest rollback segment in the round-robin assignment of rollback segments to transactions */ diff --git a/storage/xtradb/include/trx0sys.ic b/storage/xtradb/include/trx0sys.ic index af05ab2f5ed..3af98cdf98b 100644 --- a/storage/xtradb/include/trx0sys.ic +++ b/storage/xtradb/include/trx0sys.ic @@ -367,28 +367,11 @@ trx_is_active( /*==========*/ trx_id_t trx_id) /*!< in: trx id of the transaction */ { - trx_t* trx; - ut_ad(mutex_own(&(kernel_mutex))); - if (trx_id < trx_list_get_min_trx_id()) { - - return(FALSE); - } - - if (UNIV_UNLIKELY(trx_id >= trx_sys->max_trx_id)) { - - /* There must be corruption: we return TRUE because this - function is only called by lock_clust_rec_some_has_impl() - and row_vers_impl_x_locked_off_kernel() and they have - diagnostic prints in this case */ - - return(TRUE); - } - - trx = trx_get_on_id(trx_id); - if (trx && (trx->conc_state == TRX_ACTIVE - || trx->conc_state == TRX_PREPARED)) { + if (trx_find_descriptor(trx_sys->descriptors, + trx_sys->descr_n_used, + trx_id)) { return(TRUE); } @@ -425,4 +408,27 @@ trx_sys_get_new_trx_id(void) return(id); } + +/*************************************************************//** +Find a slot for a given trx ID in a descriptors array. +@return: slot pointer */ +UNIV_INLINE +trx_id_t* +trx_find_descriptor( +/*================*/ + const trx_id_t* descriptors, /*!< in: descriptors array */ + ulint n_descr, /*!< in: array size */ + trx_id_t trx_id) /*!< in: trx pointer */ +{ + ut_ad(descriptors != trx_sys->descriptors || + mutex_own(&kernel_mutex)); + + if (UNIV_UNLIKELY(n_descr == 0)) { + + return(NULL); + } + + return((trx_id_t *) bsearch(&trx_id, descriptors, n_descr, + sizeof(trx_id_t), trx_descr_cmp)); +} #endif /* !UNIV_HOTBACKUP */ diff --git a/storage/xtradb/include/trx0trx.h b/storage/xtradb/include/trx0trx.h index 86f02f53b52..e0aad5e054a 100644 --- a/storage/xtradb/include/trx0trx.h +++ b/storage/xtradb/include/trx0trx.h @@ -447,6 +447,23 @@ trx_get_que_state_str( /*==================*/ const trx_t* trx); /*!< in: transaction */ +/*************************************************************//** +Callback function for trx_find_descriptor() to compare trx IDs. */ +UNIV_INTERN +int +trx_descr_cmp( +/*==========*/ + const void *a, /*!< in: pointer to first comparison argument */ + const void *b); /*!< in: pointer to second comparison argument */ + +/*************************************************************//** +Release a slot for a given trx in the global descriptors array. */ +UNIV_INTERN +void +trx_release_descriptor( +/*===================*/ + trx_t* trx); /*!< in: trx pointer */ + /* Signal to a transaction */ struct trx_sig_struct{ unsigned type:3; /*!< signal type */ @@ -477,10 +494,18 @@ struct trx_struct{ const char* op_info; /*!< English text describing the current operation, or an empty string */ - ulint conc_state; /*!< state of the trx from the point - of view of concurrency control: - TRX_ACTIVE, TRX_COMMITTED_IN_MEMORY, - ... */ + ulint state; /*!< state of the trx from the point of + view of concurrency control: TRX_ACTIVE, + TRX_COMMITTED_IN_MEMORY, ... This was + called 'conc_state' in the upstream and + has been renamed in Percona Server, + because changing it's value to/from + either TRX_ACTIVE or TRX_PREPARED + requires calling + trx_reserve_descriptor() / + trx_release_descriptor(). Different name + ensures we notice any new code changing + the state. */ /*------------------------------*/ /* MySQL has a transaction coordinator to coordinate two phase commit between multiple storage engines and the binary log. When @@ -494,6 +519,9 @@ struct trx_struct{ this is set to 1 then registered should also be set to 1. This is used in the XA code */ + unsigned is_in_trx_serial_list:1; + /* Set when transaction is in the + trx_serial_list */ /*------------------------------*/ ulint isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */ ulint check_foreigns; /* normally TRUE, but if the user @@ -627,6 +655,9 @@ struct trx_struct{ UT_LIST_NODE_T(trx_t) mysql_trx_list; /*!< list of transactions created for MySQL */ + UT_LIST_NODE_T(trx_t) + trx_serial_list;/*!< list node for + trx_sys->trx_serial_list */ /*------------------------------*/ ulint error_state; /*!< 0 if no error, otherwise error number; NOTE That ONLY the thread @@ -685,9 +716,6 @@ struct trx_struct{ UT_LIST_BASE_NODE_T(lock_t) trx_locks; /*!< locks reserved by the transaction */ /*------------------------------*/ - mem_heap_t* global_read_view_heap; - /* memory heap for the global read - view */ read_view_t* global_read_view; /* consistent read view associated to a transaction or NULL */ @@ -697,6 +725,7 @@ struct trx_struct{ associated to a transaction (i.e. same as global_read_view) or read view associated to a cursor */ + read_view_t* prebuilt_view; /* pre-built view array */ /*------------------------------*/ UT_LIST_BASE_NODE_T(trx_named_savept_t) trx_savepoints; /*!< savepoints set with SAVEPOINT ..., diff --git a/storage/xtradb/include/trx0trx.ic b/storage/xtradb/include/trx0trx.ic index 4a1d3bcde0b..1a1fc91eac5 100644 --- a/storage/xtradb/include/trx0trx.ic +++ b/storage/xtradb/include/trx0trx.ic @@ -31,9 +31,9 @@ trx_start_if_not_started( /*=====================*/ trx_t* trx) /*!< in: transaction */ { - ut_ad(trx->conc_state != TRX_COMMITTED_IN_MEMORY); + ut_ad(trx->state != TRX_COMMITTED_IN_MEMORY); - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { trx_start(trx, ULINT_UNDEFINED); } @@ -48,9 +48,9 @@ trx_start_if_not_started_low( /*=========================*/ trx_t* trx) /*!< in: transaction */ { - ut_ad(trx->conc_state != TRX_COMMITTED_IN_MEMORY); + ut_ad(trx->state != TRX_COMMITTED_IN_MEMORY); - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { trx_start_low(trx, ULINT_UNDEFINED); } diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index 60c5cc79852..0fefdbaeb9a 100644 --- a/storage/xtradb/include/univ.i +++ b/storage/xtradb/include/univ.i @@ -64,7 +64,7 @@ component, i.e. we show M.N.P as M.N */ (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR) #ifndef PERCONA_INNODB_VERSION -#define PERCONA_INNODB_VERSION 30.1 +#define PERCONA_INNODB_VERSION 30.2 #endif #define INNODB_VERSION_STR MYSQL_SERVER_VERSION "-" IB_TO_STR(PERCONA_INNODB_VERSION) diff --git a/storage/xtradb/lock/lock0lock.c b/storage/xtradb/lock/lock0lock.c index a38656200db..63478c98371 100644 --- a/storage/xtradb/lock/lock0lock.c +++ b/storage/xtradb/lock/lock0lock.c @@ -4925,7 +4925,7 @@ lock_print_info_all_transactions( trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list); while (trx) { - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { fputs("---", file); trx_print(file, trx, 600); } @@ -5093,9 +5093,9 @@ lock_table_queue_validate( lock = UT_LIST_GET_FIRST(table->locks); while (lock) { - ut_a(((lock->trx)->conc_state == TRX_ACTIVE) - || ((lock->trx)->conc_state == TRX_PREPARED) - || ((lock->trx)->conc_state == TRX_COMMITTED_IN_MEMORY)); + ut_a(((lock->trx)->state == TRX_ACTIVE) + || ((lock->trx)->state == TRX_PREPARED) + || ((lock->trx)->state == TRX_COMMITTED_IN_MEMORY)); if (!lock_get_wait(lock)) { @@ -5143,7 +5143,7 @@ lock_rec_queue_validate( lock = lock_rec_get_first(block, heap_no); while (lock) { - switch(lock->trx->conc_state) { + switch(lock->trx->state) { case TRX_ACTIVE: case TRX_PREPARED: case TRX_COMMITTED_IN_MEMORY: @@ -5230,9 +5230,9 @@ lock_rec_queue_validate( lock = lock_rec_get_first(block, heap_no); while (lock) { - ut_a(lock->trx->conc_state == TRX_ACTIVE - || lock->trx->conc_state == TRX_PREPARED - || lock->trx->conc_state == TRX_COMMITTED_IN_MEMORY); + ut_a(lock->trx->state == TRX_ACTIVE + || lock->trx->state == TRX_PREPARED + || lock->trx->state == TRX_COMMITTED_IN_MEMORY); ut_a(trx_in_trx_list(lock->trx)); if (index) { @@ -5311,9 +5311,9 @@ loop: } ut_a(trx_in_trx_list(lock->trx)); - ut_a(lock->trx->conc_state == TRX_ACTIVE - || lock->trx->conc_state == TRX_PREPARED - || lock->trx->conc_state == TRX_COMMITTED_IN_MEMORY); + ut_a(lock->trx->state == TRX_ACTIVE + || lock->trx->state == TRX_PREPARED + || lock->trx->state == TRX_COMMITTED_IN_MEMORY); # ifdef UNIV_SYNC_DEBUG /* Only validate the record queues when this thread is not diff --git a/storage/xtradb/log/log0log.c b/storage/xtradb/log/log0log.c index e7c7a165b9c..a5243d22e8d 100644 --- a/storage/xtradb/log/log0log.c +++ b/storage/xtradb/log/log0log.c @@ -265,13 +265,12 @@ log_check_tracking_margin( } /************************************************************//** -Opens the log for log_write_low. The log must be closed with log_close and -released with log_release. +Opens the log for log_write_low. The log must be closed with log_close. @return start lsn of the log record */ UNIV_INTERN ib_uint64_t -log_reserve_and_open( -/*=================*/ +log_open( +/*=====*/ ulint len) /*!< in: length of data to be catenated */ { log_t* log = log_sys; @@ -284,7 +283,6 @@ log_reserve_and_open( ut_a(len < log->buf_size / 2); loop: - mutex_enter(&(log->mutex)); ut_ad(!recv_no_log_write); /* Calculate an upper limit for the space the string may take in the @@ -305,6 +303,8 @@ loop: ut_ad(++count < 50); + mutex_enter(&(log->mutex)); + goto loop; } @@ -318,6 +318,8 @@ loop: os_thread_sleep(10000); + mutex_enter(&(log->mutex)); + goto loop; } @@ -338,6 +340,8 @@ loop: ut_ad(++count < 50); + mutex_enter(&(log->mutex)); + goto loop; } } @@ -494,9 +498,12 @@ log_close(void) if (tracked_lsn_age >= log->log_group_capacity) { - fprintf(stderr, " InnoDB: Error: the age of the " + fprintf(stderr, "InnoDB: Error: the age of the " "oldest untracked record exceeds the log " "group capacity!\n"); + fprintf(stderr, "InnoDB: Error: stopping the log " + "tracking thread at LSN %llu\n", tracked_lsn); + srv_track_changed_pages = FALSE; } } diff --git a/storage/xtradb/mtr/mtr0mtr.c b/storage/xtradb/mtr/mtr0mtr.c index 092bd702115..9eb7b18f301 100644 --- a/storage/xtradb/mtr/mtr0mtr.c +++ b/storage/xtradb/mtr/mtr0mtr.c @@ -38,6 +38,25 @@ Created 11/26/1995 Heikki Tuuri #ifndef UNIV_HOTBACKUP # include "log0recv.h" + +/***************************************************//** +Checks if a mini-transaction is dirtying a clean page. +@return TRUE if the mtr is dirtying a clean page. */ +UNIV_INTERN +ibool +mtr_block_dirtied( +/*==============*/ + const buf_block_t* block) /*!< in: block being x-fixed */ +{ + ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); + ut_ad(block->page.buf_fix_count > 0); + + /* It is OK to read oldest_modification because no + other thread can be performing a write of it and it + is only during write that the value is reset to 0. */ + return(block->page.oldest_modification == 0); +} + /*****************************************************************//** Releases the item in the slot given. */ static @@ -126,7 +145,7 @@ mtr_memo_slot_note_modification( buf_block_t* block = (buf_block_t*) slot->object; #ifdef UNIV_DEBUG - ut_ad(log_flush_order_mutex_own()); + ut_ad(!mtr->made_dirty || log_flush_order_mutex_own()); #endif /* UNIV_DEBUG */ buf_flush_note_modification(block, mtr); } @@ -202,12 +221,14 @@ mtr_log_reserve_and_write( Add pages to flush list and exit */ goto func_exit; } + } else { + mutex_enter(&log_sys->mutex); } data_size = dyn_array_get_data_size(mlog); /* Open the database log for log_write_low */ - mtr->start_lsn = log_reserve_and_open(data_size); + mtr->start_lsn = log_open(data_size); if (mtr->log_mode == MTR_LOG_ALL) { @@ -226,7 +247,15 @@ mtr_log_reserve_and_write( mtr->end_lsn = log_close(); func_exit: - log_flush_order_mutex_enter(); + + /* No need to acquire log_flush_order_mutex if this mtr has + not dirtied a clean page. log_flush_order_mutex is used to + ensure ordered insertions in the flush_list. We need to + insert in the flush_list iff the page in question was clean + before modifications. */ + if (mtr->made_dirty) { + log_flush_order_mutex_enter(); + } /* It is now safe to release the log mutex because the flush_order mutex will ensure that we are the first one @@ -237,7 +266,9 @@ func_exit: mtr_memo_note_modifications(mtr); } - log_flush_order_mutex_exit(); + if (mtr->made_dirty) { + log_flush_order_mutex_exit(); + } } #endif /* !UNIV_HOTBACKUP */ diff --git a/storage/xtradb/read/read0read.c b/storage/xtradb/read/read0read.c index f049dd21e8d..c04dae51ff5 100644 --- a/storage/xtradb/read/read0read.c +++ b/storage/xtradb/read/read0read.c @@ -145,14 +145,27 @@ read_view_t* read_view_create_low( /*=================*/ ulint n, /*!< in: number of cells in the trx_ids array */ - mem_heap_t* heap) /*!< in: memory heap from which allocated */ + read_view_t* view) /*!< in: pre-allocated view array or NULL if a + new one needs to be created */ { - read_view_t* view; + if (view == NULL) { + view = ut_malloc(sizeof(read_view_t)); + view->max_descr = 0; + view->descriptors = NULL; + } - view = mem_heap_alloc(heap, sizeof(read_view_t)); + if (UNIV_UNLIKELY(view->max_descr < n)) { - view->n_trx_ids = n; - view->trx_ids = mem_heap_alloc(heap, n * sizeof *view->trx_ids); + /* avoid frequent re-allocations by extending the array to the + desired size + 10% */ + + view->max_descr = n + n / 10; + view->descriptors = ut_realloc(view->descriptors, + view->max_descr * + sizeof(trx_id_t)); + } + + view->n_descr = n; return(view); } @@ -169,8 +182,8 @@ read_view_oldest_copy_or_open_new( /*==============================*/ trx_id_t cr_trx_id, /*!< in: trx_id of creating transaction, or 0 used in purge */ - mem_heap_t* heap) /*!< in: memory heap from which - allocated */ + read_view_t* view) /*!< in: pre-allocated view array or + NULL if a new one needs to be created */ { read_view_t* old_view; read_view_t* view_copy; @@ -185,10 +198,10 @@ read_view_oldest_copy_or_open_new( if (old_view == NULL) { - return(read_view_open_now(cr_trx_id, heap)); + return(read_view_open_now(cr_trx_id, view, TRUE)); } - n = old_view->n_trx_ids; + n = old_view->n_descr; if (old_view->creator_trx_id) { n++; @@ -196,7 +209,7 @@ read_view_oldest_copy_or_open_new( needs_insert = FALSE; } - view_copy = read_view_create_low(n, heap); + view_copy = read_view_create_low(n, view); /* Insert the id of the creator in the right place of the descending array of ids, if needs_insert is TRUE: */ @@ -204,7 +217,7 @@ read_view_oldest_copy_or_open_new( i = 0; while (i < n) { if (needs_insert - && (i >= old_view->n_trx_ids + && (i >= old_view->n_descr || old_view->creator_trx_id > read_view_get_nth_trx_id(old_view, i))) { @@ -251,16 +264,17 @@ read_view_open_now( /*===============*/ trx_id_t cr_trx_id, /*!< in: trx_id of creating transaction, or 0 used in purge */ - mem_heap_t* heap) /*!< in: memory heap from which - allocated */ + read_view_t* view, /*!< in: current read view or NULL if it + doesn't exist yet */ + ibool exclude_self) /*!< in: TRUE, if cr_trx_id should be + excluded from the resulting view */ { - read_view_t* view; - trx_t* trx; - ulint n; + trx_id_t* descr; + ulint i; ut_ad(mutex_own(&kernel_mutex)); - view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap); + view = read_view_create_low(trx_sys->descr_n_used, view); view->creator_trx_id = cr_trx_id; view->type = VIEW_NORMAL; @@ -271,40 +285,58 @@ read_view_open_now( view->low_limit_no = trx_sys->max_trx_id; view->low_limit_id = view->low_limit_no; - n = 0; - trx = UT_LIST_GET_FIRST(trx_sys->trx_list); + /* No active transaction should be visible */ - /* No active transaction should be visible, except cr_trx */ + descr = trx_find_descriptor(trx_sys->descriptors, + trx_sys->descr_n_used, + cr_trx_id); - while (trx) { - if (trx->id != cr_trx_id - && (trx->conc_state == TRX_ACTIVE - || trx->conc_state == TRX_PREPARED)) { + if (UNIV_LIKELY(exclude_self && descr != NULL)) { - read_view_set_nth_trx_id(view, n, trx->id); + ut_ad(trx_sys->descr_n_used > 0); + ut_ad(view->n_descr > 0); - n++; + view->n_descr--; - /* NOTE that a transaction whose trx number is < - trx_sys->max_trx_id can still be active, if it is - in the middle of its commit! Note that when a - transaction starts, we initialize trx->no to - IB_ULONGLONG_MAX. */ - - if (view->low_limit_no > trx->no) { - - view->low_limit_no = trx->no; - } - } - - trx = UT_LIST_GET_NEXT(trx_list, trx); + i = descr - trx_sys->descriptors; + } else { + i = trx_sys->descr_n_used; } - view->n_trx_ids = n; + if (UNIV_LIKELY(i > 0)) { - if (n > 0) { + /* Copy the [0; i-1] range */ + memcpy(view->descriptors, trx_sys->descriptors, + i * sizeof(trx_id_t)); + } + + if (UNIV_UNLIKELY(i + 1 < trx_sys->descr_n_used)) { + + /* Copy the [i+1; descr_n_used-1] range */ + memcpy(view->descriptors + i, + trx_sys->descriptors + i + 1, + (trx_sys->descr_n_used - i - 1) * + sizeof(trx_id_t)); + } + + /* NOTE that a transaction whose trx number is < trx_sys->max_trx_id can + still be active, if it is in the middle of its commit! Note that when a + transaction starts, we initialize trx->no to IB_ULONGLONG_MAX. */ + + if (UT_LIST_GET_LEN(trx_sys->trx_serial_list) > 0) { + + trx_id_t trx_no; + + trx_no = UT_LIST_GET_FIRST(trx_sys->trx_serial_list)->no; + + if (trx_no < view->low_limit_no) { + view->low_limit_no = trx_no; + } + } + + if (UNIV_LIKELY(view->n_descr > 0)) { /* The last active transaction has the smallest id: */ - view->up_limit_id = read_view_get_nth_trx_id(view, n - 1); + view->up_limit_id = view->descriptors[0]; } else { view->up_limit_id = view->low_limit_id; } @@ -328,6 +360,23 @@ read_view_close( UT_LIST_REMOVE(view_list, trx_sys->view_list, view); } +/*********************************************************************//** +Frees resource allocated by a read view. */ +UNIV_INTERN +void +read_view_free( +/*===========*/ + read_view_t* view) /*< in: read view */ +{ + ut_ad(mutex_own(&kernel_mutex)); + + if (view->descriptors != NULL) { + ut_free(view->descriptors); + } + + ut_free(view); +} + /*********************************************************************//** Closes a consistent read view for MySQL. This function is called at an SQL statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */ @@ -343,8 +392,6 @@ read_view_close_for_mysql( read_view_close(trx->global_read_view); - mem_heap_empty(trx->global_read_view_heap); - trx->read_view = NULL; trx->global_read_view = NULL; @@ -382,7 +429,7 @@ read_view_print( fprintf(file, "Read view individually stored trx ids:\n"); - n_ids = view->n_trx_ids; + n_ids = view->n_descr; for (i = 0; i < n_ids; i++) { fprintf(file, "Read view trx id " TRX_ID_FMT "\n", @@ -404,8 +451,6 @@ read_cursor_view_create_for_mysql( cursor_view_t* curview; read_view_t* view; mem_heap_t* heap; - trx_t* trx; - ulint n; ut_a(cr_trx); @@ -424,61 +469,14 @@ read_cursor_view_create_for_mysql( mutex_enter(&kernel_mutex); - curview->read_view = read_view_create_low( - UT_LIST_GET_LEN(trx_sys->trx_list), curview->heap); - - view = curview->read_view; - view->creator_trx_id = cr_trx->id; - view->type = VIEW_HIGH_GRANULARITY; - view->undo_no = cr_trx->undo_no; - - /* No future transactions should be visible in the view */ - - view->low_limit_no = trx_sys->max_trx_id; - view->low_limit_id = view->low_limit_no; - - n = 0; - trx = UT_LIST_GET_FIRST(trx_sys->trx_list); - - /* No active transaction should be visible */ - - while (trx) { - - if (trx->conc_state == TRX_ACTIVE - || trx->conc_state == TRX_PREPARED) { - - read_view_set_nth_trx_id(view, n, trx->id); - - n++; - - /* NOTE that a transaction whose trx number is < - trx_sys->max_trx_id can still be active, if it is - in the middle of its commit! Note that when a - transaction starts, we initialize trx->no to - IB_ULONGLONG_MAX. */ - - if (view->low_limit_no > trx->no) { - - view->low_limit_no = trx->no; - } - } - - trx = UT_LIST_GET_NEXT(trx_list, trx); - } - - view->n_trx_ids = n; - - if (n > 0) { - /* The last active transaction has the smallest id: */ - view->up_limit_id = read_view_get_nth_trx_id(view, n - 1); - } else { - view->up_limit_id = view->low_limit_id; - } - - UT_LIST_ADD_FIRST(view_list, trx_sys->view_list, view); + curview->read_view = read_view_open_now(cr_trx->id, NULL, FALSE); mutex_exit(&kernel_mutex); + view = curview->read_view; + view->type = VIEW_HIGH_GRANULARITY; + view->undo_no = cr_trx->undo_no; + return(curview); } @@ -503,6 +501,8 @@ read_cursor_view_close_for_mysql( mutex_enter(&kernel_mutex); read_view_close(curview->read_view); + read_view_free(curview->read_view); + trx->read_view = trx->global_read_view; mutex_exit(&kernel_mutex); diff --git a/storage/xtradb/row/row0ins.c b/storage/xtradb/row/row0ins.c index b459019a257..925446e4722 100644 --- a/storage/xtradb/row/row0ins.c +++ b/storage/xtradb/row/row0ins.c @@ -1364,11 +1364,11 @@ run_again: const rec_t* rec = btr_pcur_get_rec(&pcur); const buf_block_t* block = btr_pcur_get_block(&pcur); - if (srv_pass_corrupt_table && !block) { + SRV_CORRUPT_TABLE_CHECK(block, + { err = DB_CORRUPTION; - break; - } - ut_a(block); + goto exit_loop; + }); if (page_rec_is_infimum(rec)) { @@ -1499,6 +1499,7 @@ run_again: } } while (btr_pcur_move_to_next(&pcur, &mtr)); +exit_loop: if (check_ref) { row_ins_foreign_report_add_err( trx, foreign, btr_pcur_get_rec(&pcur), entry); diff --git a/storage/xtradb/row/row0merge.c b/storage/xtradb/row/row0merge.c index 0b6a6302854..40e7d99b839 100644 --- a/storage/xtradb/row/row0merge.c +++ b/storage/xtradb/row/row0merge.c @@ -1298,11 +1298,11 @@ row_merge_read_clustered_index( if (UNIV_LIKELY(has_next)) { rec = btr_pcur_get_rec(&pcur); - if (srv_pass_corrupt_table && !rec) { + SRV_CORRUPT_TABLE_CHECK(rec, + { err = DB_CORRUPTION; goto err_exit; - } - ut_a(rec); + }); offsets = rec_get_offsets(rec, clust_index, NULL, ULINT_UNDEFINED, &row_heap); diff --git a/storage/xtradb/row/row0sel.c b/storage/xtradb/row/row0sel.c index 858d50fd5a6..dec192585ce 100644 --- a/storage/xtradb/row/row0sel.c +++ b/storage/xtradb/row/row0sel.c @@ -3952,9 +3952,9 @@ release_search_latch_if_needed: trx->has_search_latch = FALSE; } - ut_ad(prebuilt->sql_stat_start || trx->conc_state == TRX_ACTIVE); - ut_ad(trx->conc_state == TRX_NOT_STARTED - || trx->conc_state == TRX_ACTIVE); + ut_ad(prebuilt->sql_stat_start || trx->state == TRX_ACTIVE); + ut_ad(trx->state == TRX_NOT_STARTED + || trx->state == TRX_ACTIVE); ut_ad(prebuilt->sql_stat_start || prebuilt->select_lock_type != LOCK_NONE || trx->read_view); @@ -4137,11 +4137,11 @@ rec_loop: rec = btr_pcur_get_rec(pcur); - if (srv_pass_corrupt_table && !rec) { + SRV_CORRUPT_TABLE_CHECK(rec, + { err = DB_CORRUPTION; goto lock_wait_or_error; - } - ut_a(rec); + }); ut_ad(!!page_rec_is_comp(rec) == comp); #ifdef UNIV_SEARCH_DEBUG @@ -4278,8 +4278,9 @@ wrong_offs: offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap); - if (UNIV_UNLIKELY(srv_force_recovery > 0) - || (srv_pass_corrupt_table == 2 && index->table->is_corrupt)) { + if (UNIV_UNLIKELY(srv_force_recovery > 0 + || (index->table->is_corrupt && + srv_pass_corrupt_table == 2))) { if (!rec_validate(rec, offsets) || !btr_index_rec_validate(rec, index, FALSE)) { fprintf(stderr, @@ -5092,8 +5093,10 @@ row_search_check_if_query_cache_permitted( if (trx->isolation_level >= TRX_ISO_REPEATABLE_READ && !trx->read_view) { - trx->read_view = read_view_open_now( - trx->id, trx->global_read_view_heap); + trx->read_view = + read_view_open_now(trx->id, + NULL, TRUE); + trx->global_read_view = trx->read_view; } } diff --git a/storage/xtradb/row/row0vers.c b/storage/xtradb/row/row0vers.c index 6d83dbaf8ee..3fd13b829a2 100644 --- a/storage/xtradb/row/row0vers.c +++ b/storage/xtradb/row/row0vers.c @@ -667,9 +667,9 @@ row_vers_build_for_semi_consistent_read( mutex_enter(&kernel_mutex); version_trx = trx_get_on_id(version_trx_id); - if (version_trx - && (version_trx->conc_state == TRX_COMMITTED_IN_MEMORY - || version_trx->conc_state == TRX_NOT_STARTED)) { + if (version_trx && + (version_trx->state == TRX_COMMITTED_IN_MEMORY + || version_trx->state == TRX_NOT_STARTED)) { version_trx = NULL; } diff --git a/storage/xtradb/srv/srv0srv.c b/storage/xtradb/srv/srv0srv.c index 1a3667f45e3..83332ea6775 100644 --- a/storage/xtradb/srv/srv0srv.c +++ b/storage/xtradb/srv/srv0srv.c @@ -445,8 +445,6 @@ UNIV_INTERN ulong srv_expand_import = 0; /* 0:disable 1:enable */ UNIV_INTERN ulong srv_pass_corrupt_table = 0; /* 0:disable 1:enable */ UNIV_INTERN ulint srv_dict_size_limit = 0; - -UNIV_INTERN ulint srv_lazy_drop_table = 0; /*-------------------------------------------*/ UNIV_INTERN ulong srv_n_spin_wait_rounds = 30; UNIV_INTERN ulong srv_n_free_tickets_to_enter = 500; @@ -3075,7 +3073,7 @@ rescan_idle: mutex_enter(&kernel_mutex); trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list); while (trx) { - if (trx->conc_state == TRX_ACTIVE + if (trx->state == TRX_ACTIVE && trx->mysql_thd && innobase_thd_is_idle(trx->mysql_thd)) { ib_int64_t start_time = innobase_thd_get_start_time(trx->mysql_thd); diff --git a/storage/xtradb/trx/trx0purge.c b/storage/xtradb/trx/trx0purge.c index b048dc66efe..1e119c6828b 100644 --- a/storage/xtradb/trx/trx0purge.c +++ b/storage/xtradb/trx/trx0purge.c @@ -263,8 +263,9 @@ trx_purge_sys_create( purge_sys->query = trx_purge_graph_build(); - purge_sys->view = read_view_oldest_copy_or_open_new(0, - purge_sys->heap); + purge_sys->prebuilt_view = + read_view_oldest_copy_or_open_new(0, NULL); + purge_sys->view = purge_sys->prebuilt_view; } /************************************************************************ @@ -279,7 +280,12 @@ trx_purge_sys_close(void) que_graph_free(purge_sys->query); ut_a(purge_sys->sess->trx->is_purge); - purge_sys->sess->trx->conc_state = TRX_NOT_STARTED; + purge_sys->sess->trx->state = TRX_NOT_STARTED; + + mutex_enter(&kernel_mutex); + trx_release_descriptor(purge_sys->sess->trx); + mutex_exit(&kernel_mutex); + sess_close(purge_sys->sess); purge_sys->sess = NULL; @@ -289,6 +295,8 @@ trx_purge_sys_close(void) mutex_enter(&kernel_mutex); read_view_close(purge_sys->view); + read_view_free(purge_sys->prebuilt_view); + purge_sys->prebuilt_view = NULL; purge_sys->view = NULL; mutex_exit(&kernel_mutex); @@ -1177,7 +1185,7 @@ trx_purge( } purge_sys->view = read_view_oldest_copy_or_open_new( - 0, purge_sys->heap); + 0, purge_sys->prebuilt_view); mutex_exit(&kernel_mutex); diff --git a/storage/xtradb/trx/trx0roll.c b/storage/xtradb/trx/trx0roll.c index 3db63469cbe..4f001a91669 100644 --- a/storage/xtradb/trx/trx0roll.c +++ b/storage/xtradb/trx/trx0roll.c @@ -135,7 +135,7 @@ trx_rollback_for_mysql( { int err; - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { return(DB_SUCCESS); } @@ -170,7 +170,7 @@ trx_rollback_last_sql_stat_for_mysql( { int err; - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { return(DB_SUCCESS); } @@ -278,7 +278,7 @@ trx_rollback_to_savepoint_for_mysql( return(DB_NO_SAVEPOINT); } - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { ut_print_timestamp(stderr); fputs(" InnoDB: Error: transaction has a savepoint ", stderr); ut_print_name(stderr, trx, FALSE, savep->name); @@ -575,7 +575,7 @@ loop: continue; } - switch (trx->conc_state) { + switch (trx->state) { case TRX_NOT_STARTED: case TRX_PREPARED: continue; diff --git a/storage/xtradb/trx/trx0sys.c b/storage/xtradb/trx/trx0sys.c index 59b7da4083d..975e0caed60 100644 --- a/storage/xtradb/trx/trx0sys.c +++ b/storage/xtradb/trx/trx0sys.c @@ -1406,6 +1406,12 @@ trx_sys_init_at_db_start(void) trx_sys = mem_zalloc(sizeof(*trx_sys)); + /* Allocate the trx descriptors array */ + trx_sys->descriptors = ut_malloc(sizeof(trx_id_t) * + TRX_DESCR_ARRAY_INITIAL_SIZE); + trx_sys->descr_n_max = TRX_DESCR_ARRAY_INITIAL_SIZE; + trx_sys->descr_n_used = 0; + sys_header = trx_sysf_get(&mtr); trx_rseg_list_and_array_init(sys_header, ib_bh, &mtr); @@ -1433,7 +1439,7 @@ trx_sys_init_at_db_start(void) for (;;) { - if (trx->conc_state != TRX_PREPARED) { + if (trx->state != TRX_PREPARED) { rows_to_undo += trx->undo_no; } @@ -2115,6 +2121,9 @@ trx_sys_close(void) ut_a(UT_LIST_GET_LEN(trx_sys->view_list) == 0); ut_a(UT_LIST_GET_LEN(trx_sys->mysql_trx_list) == 0); + ut_ad(trx_sys->descr_n_used == 0); + ut_free(trx_sys->descriptors); + mem_free(trx_sys); trx_sys = NULL; diff --git a/storage/xtradb/trx/trx0trx.c b/storage/xtradb/trx/trx0trx.c index f7924763e17..77ec043098a 100644 --- a/storage/xtradb/trx/trx0trx.c +++ b/storage/xtradb/trx/trx0trx.c @@ -85,6 +85,126 @@ trx_set_detailed_error_from_file( sizeof(trx->detailed_error)); } +/*************************************************************//** +Callback function for trx_find_descriptor() to compare trx IDs. */ +UNIV_INTERN +int +trx_descr_cmp( +/*==========*/ + const void *a, /*!< in: pointer to first comparison argument */ + const void *b) /*!< in: pointer to second comparison argument */ +{ + const trx_id_t* da = (const trx_id_t*) a; + const trx_id_t* db = (const trx_id_t*) b; + + if (*da < *db) { + return -1; + } else if (*da > *db) { + return 1; + } + + return 0; +} + +/*************************************************************//** +Reserve a slot for a given trx in the global descriptors array. */ +UNIV_INLINE +void +trx_reserve_descriptor( +/*===================*/ + const trx_t* trx) /*!< in: trx pointer */ +{ + ulint n_used; + ulint n_max; + trx_id_t* descr; + + ut_ad(mutex_own(&kernel_mutex)); + ut_ad(!trx_find_descriptor(trx_sys->descriptors, + trx_sys->descr_n_used, + trx->id)); + + n_used = trx_sys->descr_n_used + 1; + n_max = trx_sys->descr_n_max; + + if (UNIV_UNLIKELY(n_used > n_max)) { + + n_max = n_max * 2; + + trx_sys->descriptors = + ut_realloc(trx_sys->descriptors, + n_max * sizeof(trx_id_t)); + + trx_sys->descr_n_max = n_max; + } + + descr = trx_sys->descriptors + n_used - 1; + + if (UNIV_UNLIKELY(n_used > 1 && trx->id < descr[-1])) { + + /* Find the slot where it should be inserted. We could use a + binary search, but in reality linear search should be faster, + because the slot we are looking for is near the array end. */ + + trx_id_t* tdescr; + + for (tdescr = descr - 1; + tdescr >= trx_sys->descriptors && *tdescr > trx->id; + tdescr--) { + } + + tdescr++; + + ut_memmove(tdescr + 1, tdescr, (descr - tdescr) * + sizeof(trx_id_t)); + + descr = tdescr; + } + + *descr = trx->id; + + trx_sys->descr_n_used = n_used; +} + +/*************************************************************//** +Release a slot for a given trx in the global descriptors array. */ +UNIV_INTERN +void +trx_release_descriptor( +/*===================*/ + trx_t* trx) /*!< in: trx pointer */ +{ + ulint size; + trx_id_t* descr; + + ut_ad(mutex_own(&kernel_mutex)); + + if (UNIV_LIKELY(trx->is_in_trx_serial_list)) { + + UT_LIST_REMOVE(trx_serial_list, trx_sys->trx_serial_list, + trx); + trx->is_in_trx_serial_list = 0; + } + + descr = trx_find_descriptor(trx_sys->descriptors, + trx_sys->descr_n_used, + trx->id); + + if (UNIV_UNLIKELY(descr == NULL)) { + + return; + } + + size = (trx_sys->descriptors + trx_sys->descr_n_used - 1 - descr) * + sizeof(trx_id_t); + + if (UNIV_LIKELY(size > 0)) { + + ut_memmove(descr, descr + 1, size); + } + + trx_sys->descr_n_used--; +} + /****************************************************************//** Creates and initializes a transaction object. @return own: the transaction */ @@ -107,7 +227,7 @@ trx_create( trx->is_purge = 0; trx->is_recovered = 0; - trx->conc_state = TRX_NOT_STARTED; + trx->state = TRX_NOT_STARTED; trx->is_registered = 0; trx->active_commit_ordered = 0; @@ -118,6 +238,7 @@ trx_create( trx->id = 0; trx->no = IB_ULONGLONG_MAX; + trx->is_in_trx_serial_list = 0; trx->support_xa = TRUE; @@ -189,9 +310,9 @@ trx_create( trx->declared_to_be_inside_innodb = FALSE; trx->n_tickets_to_enter_innodb = 0; - trx->global_read_view_heap = mem_heap_create(256); trx->global_read_view = NULL; trx->read_view = NULL; + trx->prebuilt_view = NULL; trx->io_reads = 0; trx->io_read = 0; @@ -330,7 +451,7 @@ trx_free( trx->magic_n = 11112222; - ut_a(trx->conc_state == TRX_NOT_STARTED); + ut_a(trx->state == TRX_NOT_STARTED); mutex_free(&(trx->undo_mutex)); @@ -357,18 +478,18 @@ trx_free( ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0); - if (trx->global_read_view_heap) { - mem_heap_free(trx->global_read_view_heap); + if (trx->prebuilt_view != NULL) { + read_view_free(trx->prebuilt_view); } - trx->global_read_view = NULL; - ut_a(trx->read_view == NULL); ut_a(ib_vector_is_empty(trx->autoinc_locks)); /* We allocated a dedicated heap for the vector. */ ib_vector_free(trx->autoinc_locks); + trx_release_descriptor(trx); + mem_free(trx); } @@ -381,7 +502,7 @@ trx_free_prepared( trx_t* trx) /*!< in, own: trx object */ { ut_ad(mutex_own(&kernel_mutex)); - ut_a(trx->conc_state == TRX_PREPARED); + ut_a(trx->state == TRX_PREPARED); ut_a(trx->magic_n == TRX_MAGIC_N); /* Prepared transactions are sort of active; they allow @@ -414,15 +535,19 @@ trx_free_prepared( mem_heap_free(trx->lock_heap); } - if (trx->global_read_view_heap) { - mem_heap_free(trx->global_read_view_heap); - } - ut_a(ib_vector_is_empty(trx->autoinc_locks)); ib_vector_free(trx->autoinc_locks); + trx_release_descriptor(trx); + + if (trx->prebuilt_view != NULL) { + read_view_free(trx->prebuilt_view); + } + UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx); + ut_ad(trx_sys->descr_n_used <= UT_LIST_GET_LEN(trx_sys->trx_list)); + mem_free(trx); } @@ -531,6 +656,7 @@ trx_lists_init_at_db_start(void) ut_ad(mutex_own(&kernel_mutex)); UT_LIST_INIT(trx_sys->trx_list); + UT_LIST_INIT(trx_sys->trx_serial_list); /* Look from the rollback segments if there exist undo logs for transactions */ @@ -567,7 +693,7 @@ trx_lists_init_at_db_start(void) if (srv_force_recovery == 0) { - trx->conc_state = TRX_PREPARED; + trx->state = TRX_PREPARED; trx_n_prepared++; } else { fprintf(stderr, @@ -577,11 +703,12 @@ trx_lists_init_at_db_start(void) " rollback it" " anyway.\n"); - trx->conc_state = TRX_ACTIVE; + trx->state = TRX_ACTIVE; } + + trx_reserve_descriptor(trx); } else { - trx->conc_state - = TRX_COMMITTED_IN_MEMORY; + trx->state = TRX_COMMITTED_IN_MEMORY; } /* We give a dummy value for the trx no; @@ -593,12 +720,15 @@ trx_lists_init_at_db_start(void) trx->no = trx->id; } else { - trx->conc_state = TRX_ACTIVE; + trx->state = TRX_ACTIVE; /* A running transaction always has the number field inited to IB_ULONGLONG_MAX */ trx->no = IB_ULONGLONG_MAX; + + trx_reserve_descriptor(trx); + } if (undo->dict_operation) { @@ -643,7 +773,7 @@ trx_lists_init_at_db_start(void) if (srv_force_recovery == 0) { - trx->conc_state + trx->state = TRX_PREPARED; trx_n_prepared++; } else { @@ -654,11 +784,12 @@ trx_lists_init_at_db_start(void) " rollback it" " anyway.\n"); - trx->conc_state - = TRX_ACTIVE; + trx->state = TRX_ACTIVE; + trx_reserve_descriptor( + trx); } } else { - trx->conc_state + trx->state = TRX_COMMITTED_IN_MEMORY; } @@ -667,13 +798,14 @@ trx_lists_init_at_db_start(void) trx->no = trx->id; } else { - trx->conc_state = TRX_ACTIVE; - + trx->state = TRX_ACTIVE; /* A running transaction always has the number field inited to IB_ULONGLONG_MAX */ trx->no = IB_ULONGLONG_MAX; + + trx_reserve_descriptor(trx); } trx->rseg = rseg; @@ -744,13 +876,15 @@ trx_start_low( if (trx->is_purge) { trx->id = 0; - trx->conc_state = TRX_ACTIVE; + /* Don't reserve a descriptor, since this trx is not added to + trx_list. */ + trx->state = TRX_ACTIVE; trx->start_time = time(NULL); return(TRUE); } - ut_ad(trx->conc_state != TRX_ACTIVE); + ut_ad(trx->state != TRX_ACTIVE); ut_a(rseg_id == ULINT_UNDEFINED); @@ -770,7 +904,10 @@ trx_start_low( trx->rseg = rseg; - trx->conc_state = TRX_ACTIVE; + trx->state = TRX_ACTIVE; + + trx_reserve_descriptor(trx); + trx->start_time = time(NULL); UT_LIST_ADD_FIRST(trx_list, trx_sys->trx_list, trx); @@ -827,6 +964,14 @@ trx_serialisation_number_get( trx->no = trx_sys_get_new_trx_id(); + if (UNIV_LIKELY(trx->is_in_trx_serial_list == 0)) { + + UT_LIST_ADD_LAST(trx_serial_list, trx_sys->trx_serial_list, + trx); + + trx->is_in_trx_serial_list = 1; + } + /* If the rollack segment is not empty then the new trx_t::no can't be less than any trx_t::no already in the rollback segment. User threads only @@ -1016,10 +1161,10 @@ trx_commit_off_kernel( lsn = 0; } - ut_ad(trx->conc_state == TRX_ACTIVE || trx->conc_state == TRX_PREPARED); + ut_ad(trx->state == TRX_ACTIVE || trx->state == TRX_PREPARED); ut_ad(mutex_own(&kernel_mutex)); - if (UNIV_UNLIKELY(trx->conc_state == TRX_PREPARED)) { + if (UNIV_UNLIKELY(trx->state == TRX_PREPARED)) { ut_a(trx_n_prepared > 0); trx_n_prepared--; } @@ -1039,7 +1184,9 @@ trx_commit_off_kernel( committed. */ /*--------------------------------------*/ - trx->conc_state = TRX_COMMITTED_IN_MEMORY; + trx->state = TRX_COMMITTED_IN_MEMORY; + /* The following also removes trx from trx_serial_list */ + trx_release_descriptor(trx); /*--------------------------------------*/ /* If we release kernel_mutex below and we are still doing @@ -1060,7 +1207,6 @@ trx_commit_off_kernel( if (trx->global_read_view) { read_view_close(trx->global_read_view); - mem_heap_empty(trx->global_read_view_heap); trx->global_read_view = NULL; } @@ -1147,7 +1293,7 @@ trx_commit_off_kernel( /* Free all savepoints */ trx_roll_free_all_savepoints(trx); - trx->conc_state = TRX_NOT_STARTED; + trx->state = TRX_NOT_STARTED; trx->rseg = NULL; trx->undo_no = 0; trx->last_sql_stat_start.least_undo_no = 0; @@ -1163,6 +1309,8 @@ trx_commit_off_kernel( #endif UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx); + ut_ad(trx_sys->descr_n_used <= UT_LIST_GET_LEN(trx_sys->trx_list)); + trx->error_state = DB_SUCCESS; } @@ -1181,12 +1329,15 @@ trx_cleanup_at_db_startup( trx_undo_insert_cleanup(trx); } - trx->conc_state = TRX_NOT_STARTED; + trx->state = TRX_NOT_STARTED; + trx_release_descriptor(trx); trx->rseg = NULL; trx->undo_no = 0; trx->last_sql_stat_start.least_undo_no = 0; UT_LIST_REMOVE(trx_list, trx_sys->trx_list, trx); + + ut_ad(trx_sys->descr_n_used <= UT_LIST_GET_LEN(trx_sys->trx_list)); } /********************************************************************//** @@ -1200,7 +1351,7 @@ trx_assign_read_view( /*=================*/ trx_t* trx) /*!< in: active transaction */ { - ut_ad(trx->conc_state == TRX_ACTIVE); + ut_ad(trx->state == TRX_ACTIVE); if (trx->read_view) { return(trx->read_view); @@ -1208,11 +1359,9 @@ trx_assign_read_view( mutex_enter(&kernel_mutex); - if (!trx->read_view) { - trx->read_view = read_view_open_now( - trx->id, trx->global_read_view_heap); - trx->global_read_view = trx->read_view; - } + trx->read_view = read_view_open_now(trx->id, trx->prebuilt_view, TRUE); + trx->prebuilt_view = trx->read_view; + trx->global_read_view = trx->read_view; mutex_exit(&kernel_mutex); @@ -1577,7 +1726,7 @@ loop: return; } - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { trx_start_low(trx, ULINT_UNDEFINED); } @@ -1873,7 +2022,7 @@ trx_mark_sql_stat_end( { ut_a(trx); - if (trx->conc_state == TRX_NOT_STARTED) { + if (trx->state == TRX_NOT_STARTED) { trx->undo_no = 0; } @@ -1896,7 +2045,7 @@ trx_print( fprintf(f, "TRANSACTION " TRX_ID_FMT, (ullint) trx->id); - switch (trx->conc_state) { + switch (trx->state) { case TRX_NOT_STARTED: fputs(", not started", f); break; @@ -1912,7 +2061,7 @@ trx_print( fputs(", COMMITTED IN MEMORY", f); break; default: - fprintf(f, " state %lu", (ulong) trx->conc_state); + fprintf(f, " state %lu", (ulong) trx->state); } if (*trx->op_info) { @@ -2107,7 +2256,11 @@ trx_prepare_off_kernel( ut_ad(mutex_own(&kernel_mutex)); /*--------------------------------------*/ - trx->conc_state = TRX_PREPARED; + if (UNIV_UNLIKELY(trx->state != TRX_ACTIVE)) { + + trx_reserve_descriptor(trx); + } + trx->state = TRX_PREPARED; trx_n_prepared++; /*--------------------------------------*/ @@ -2221,7 +2374,7 @@ trx_recover_for_mysql( trx = UT_LIST_GET_FIRST(trx_sys->trx_list); while (trx) { - if (trx->conc_state == TRX_PREPARED) { + if (trx->state == TRX_PREPARED) { xid_list[count] = trx->xid; if (count == 0) { @@ -2294,7 +2447,7 @@ trx_get_trx_by_xid( the same */ if (trx->is_recovered - && trx->conc_state == TRX_PREPARED + && trx->state == TRX_PREPARED && xid->gtrid_length == trx->xid.gtrid_length && xid->bqual_length == trx->xid.bqual_length && memcmp(xid->data, trx->xid.data, diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index d28d576c661..88a7f8b84e8 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -318,13 +318,16 @@ void my_hash_sort_bin(CHARSET_INFO *cs __attribute__((unused)), #define INC_PTR(cs,A,B) (A)++ -int my_wildcmp_bin(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static +int my_wildcmp_bin_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ - + + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -383,8 +386,8 @@ int my_wildcmp_bin(CHARSET_INFO *cs, if (str++ == str_end) return(-1); { - int tmp=my_wildcmp_bin(cs,str,str_end,wildstr,wildend,escape,w_one, - w_many); + int tmp=my_wildcmp_bin_impl(cs,str,str_end,wildstr,wildend,escape,w_one, + w_many, recurse_level + 1); if (tmp <= 0) return(tmp); } @@ -395,6 +398,16 @@ int my_wildcmp_bin(CHARSET_INFO *cs, return(str != str_end ? 1 : 0); } +int my_wildcmp_bin(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_bin_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + static size_t my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)), uchar *dest, size_t dstlen, diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index 5879bdf7978..0c0332ea3da 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -251,13 +251,16 @@ int my_strcasecmp_mb(CHARSET_INFO * cs,const char *s, const char *t) #define likeconv(s,A) (uchar) (s)->sort_order[(uchar) (A)] -int my_wildcmp_mb(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static +int my_wildcmp_mb_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -346,8 +349,8 @@ int my_wildcmp_mb(CHARSET_INFO *cs, INC_PTR(cs,str, str_end); } { - int tmp=my_wildcmp_mb(cs,str,str_end,wildstr,wildend,escape,w_one, - w_many); + int tmp=my_wildcmp_mb_impl(cs,str,str_end,wildstr,wildend,escape,w_one, + w_many, recurse_level + 1); if (tmp <= 0) return (tmp); } @@ -358,6 +361,16 @@ int my_wildcmp_mb(CHARSET_INFO *cs, return (str != str_end ? 1 : 0); } +int my_wildcmp_mb(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_mb_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + size_t my_numchars_mb(CHARSET_INFO *cs __attribute__((unused)), const char *pos, const char *end) @@ -987,14 +1000,15 @@ pad_min_max: } -int -my_wildcmp_mb_bin(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static int my_wildcmp_mb_bin_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -1081,7 +1095,9 @@ my_wildcmp_mb_bin(CHARSET_INFO *cs, INC_PTR(cs,str, str_end); } { - int tmp=my_wildcmp_mb_bin(cs,str,str_end,wildstr,wildend,escape,w_one,w_many); + int tmp=my_wildcmp_mb_bin_impl(cs,str,str_end, + wildstr,wildend,escape, + w_one,w_many, recurse_level+1); if (tmp <= 0) return (tmp); } @@ -1092,6 +1108,17 @@ my_wildcmp_mb_bin(CHARSET_INFO *cs, return (str != str_end ? 1 : 0); } +int +my_wildcmp_mb_bin(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_mb_bin_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + /* Data was produced from EastAsianWidth.txt diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index e25c0783abf..3cd6805158e 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -847,13 +847,16 @@ cnv: #define INC_PTR(cs,A,B) (A)++ -int my_wildcmp_8bit(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +static +int my_wildcmp_8bit_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (*wildstr != w_many && *wildstr != w_one) @@ -913,8 +916,9 @@ int my_wildcmp_8bit(CHARSET_INFO *cs, str++; if (str++ == str_end) return(-1); { - int tmp=my_wildcmp_8bit(cs,str,str_end,wildstr,wildend,escape,w_one, - w_many); + int tmp=my_wildcmp_8bit_impl(cs,str,str_end, + wildstr,wildend,escape,w_one, + w_many, recurse_level+1); if (tmp <= 0) return(tmp); } @@ -925,6 +929,16 @@ int my_wildcmp_8bit(CHARSET_INFO *cs, return(str != str_end ? 1 : 0); } +int my_wildcmp_8bit(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_8bit_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + /* ** Calculate min_str and max_str that ranges a LIKE string. diff --git a/strings/ctype-uca.c b/strings/ctype-uca.c index e4a8d7a4067..020cfdfcbbe 100644 --- a/strings/ctype-uca.c +++ b/strings/ctype-uca.c @@ -7487,16 +7487,18 @@ static int my_uca_charcmp(CHARSET_INFO *cs, my_wc_t wc1, my_wc_t wc2) */ static -int my_wildcmp_uca(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many) +int my_wildcmp_uca_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, int recurse_level) { int result= -1; /* Not found, using wildcards */ my_wc_t s_wc, w_wc; int scan; my_charset_conv_mb_wc mb_wc= cs->cset->mb_wc; + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (1) @@ -7603,8 +7605,8 @@ int my_wildcmp_uca(CHARSET_INFO *cs, if (str == str_end) return -1; - result= my_wildcmp_uca(cs, str, str_end, wildstr, wildend, - escape, w_one, w_many); + result= my_wildcmp_uca_impl(cs, str, str_end, wildstr, wildend, + escape, w_one, w_many, recurse_level+1); if (result <= 0) return result; @@ -7616,6 +7618,16 @@ int my_wildcmp_uca(CHARSET_INFO *cs, return (str != str_end ? 1 : 0); } +int my_wildcmp_uca(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many) +{ + return my_wildcmp_uca_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, 1); +} + /* Collation language is implemented according to diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index b96ca0e5bbe..b17840bd54c 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -1920,11 +1920,12 @@ my_tosort_unicode(MY_UNICASE_INFO * const* uni_plane, my_wc_t *wc) ** 1 if matched with wildcard */ -int my_wildcmp_unicode(CHARSET_INFO *cs, - const char *str,const char *str_end, - const char *wildstr,const char *wildend, - int escape, int w_one, int w_many, - MY_UNICASE_INFO *const *weights) +static +int my_wildcmp_unicode_impl(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, + MY_UNICASE_INFO *const *weights, int recurse_level) { int result= -1; /* Not found, using wildcards */ my_wc_t s_wc, w_wc; @@ -1933,6 +1934,8 @@ int my_wildcmp_unicode(CHARSET_INFO *cs, const uchar *, const uchar *); mb_wc= cs->cset->mb_wc; + if (my_string_stack_guard && my_string_stack_guard(recurse_level)) + return 1; while (wildstr != wildend) { while (1) @@ -2054,9 +2057,9 @@ int my_wildcmp_unicode(CHARSET_INFO *cs, return -1; str+= scan; - result= my_wildcmp_unicode(cs, str, str_end, wildstr, wildend, - escape, w_one, w_many, - weights); + result= my_wildcmp_unicode_impl(cs, str, str_end, wildstr, wildend, + escape, w_one, w_many, + weights, recurse_level+1); if (result <= 0) return result; } @@ -2066,6 +2069,17 @@ int my_wildcmp_unicode(CHARSET_INFO *cs, } +int +my_wildcmp_unicode(CHARSET_INFO *cs, + const char *str,const char *str_end, + const char *wildstr,const char *wildend, + int escape, int w_one, int w_many, + MY_UNICASE_INFO *const *weights) +{ + return my_wildcmp_unicode_impl(cs, str, str_end, + wildstr, wildend, + escape, w_one, w_many, weights, 1); +} /* Store sorting weights using 2 bytes per character. diff --git a/strings/ctype.c b/strings/ctype.c index 6b6983ada60..23f18b6617b 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -38,6 +38,8 @@ */ +int (*my_string_stack_guard)(int)= NULL; + static char *mstr(char *str,const char *src,size_t l1,size_t l2) { l1= l1 +Packager: MySQL Release Engineering Vendor: %{mysql_vendor} -Provides: msqlormysql MySQL-server mysql +Provides: msqlormysql MySQL-server BuildRequires: %{distro_buildreq} # Regression tests may take a long time, override the default to skip them @@ -302,14 +302,25 @@ documentation and the manual for more information. Version: %{mysql_version} #Release: %{wsrep_version}.%{release} %endif -Summary: MySQL: a very fast and reliable SQL database server -Group: Applications/Databases -Requires: %{distro_requires} -Provides: msqlormysql MySQL MySQL-server -Conflicts: mysql mysql-server mysql-advanced mysql-server-advanced -Obsoletes: MySQL MySQL-server -Obsoletes: MySQL-server-classic MySQL-server-community MySQL-server-enterprise -Obsoletes: MySQL-server-advanced MySQL-server-advanced-gpl MySQL-server-enterprise-gpl +Summary: MySQL: a very fast and reliable SQL database server +Group: Applications/Databases +Requires: %{distro_requires} +%if %{defined susever} +Provides: msqlormysql MySQL MySQL-server +Conflicts: mysql mysql-server mysql-advanced mysql-server-advanced +Obsoletes: MySQL MySQL-server +Obsoletes: MySQL-server-classic MySQL-server-community MySQL-server-enterprise +Obsoletes: MySQL-server-advanced MySQL-server-advanced-gpl MySQL-server-enterprise-gpl +%else +Obsoletes: MySQL < %{version}-%{release} +Obsoletes: MySQL-server < %{version}-%{release} +Obsoletes: MySQL-server-advanced < %{version}-%{release} +Obsoletes: mysql mysql-server mysql-advanced mysql-server-advanced +Obsoletes: MySQL-server-classic MySQL-server-community MySQL-server-enterprise +Obsoletes: MySQL-server-advanced-gpl MySQL-server-enterprise-gpl +Provides: msqlormysql MySQL MySQL-server MySQL-server-advanced +Provides: mysql +%endif %description -n MySQL-server%{product_suffix} The MySQL(TM) software delivers a very fast, multi-threaded, multi-user, @@ -340,13 +351,23 @@ package "MySQL-client%{product_suffix}" as well! # ---------------------------------------------------------------------------- %package -n MySQL-client%{product_suffix} -Summary: MySQL - Client -Group: Applications/Databases -Provides: MySQL-client -Conflicts: mysql mysql-advanced -Obsoletes: MySQL-client -Obsoletes: MySQL-client-classic MySQL-client-community MySQL-client-enterprise -Obsoletes: MySQL-client-advanced MySQL-client-advanced-gpl MySQL-client-enterprise-gpl +Summary: MySQL - Client +Group: Applications/Databases +%if %{defined susever} +Provides: MySQL-client +Conflicts: mysql mysql-advanced +Obsoletes: MySQL-client +Obsoletes: MySQL-client-classic MySQL-client-community MySQL-client-enterprise +Obsoletes: MySQL-client-advanced MySQL-client-advanced-gpl MySQL-client-enterprise-gpl +%else +Obsoletes: mysql mysql-advanced +Obsoletes: MySQL-client < %{version}-%{release} +Obsoletes: MySQL-client-advanced < %{version}-%{release} +Obsoletes: MySQL-client-classic MySQL-client-community MySQL-client-enterprise +Obsoletes: MySQL-client-advanced-gpl MySQL-client-enterprise-gpl +Provides: MySQL-client MySQL-client-advanced +Provides: mysql +%endif %description -n MySQL-client%{product_suffix} This package contains the standard MySQL clients and administration tools. @@ -355,16 +376,28 @@ For a description of MySQL see the base MySQL RPM or http://www.mysql.com/ # ---------------------------------------------------------------------------- %package -n MySQL-test%{product_suffix} -Summary: MySQL - Test suite -Group: Applications/Databases -Requires: MySQL-client perl -Provides: MySQL-test -Conflicts: mysql-test mysql-test-advanced -Obsoletes: MySQL-test -Obsoletes: mysql-bench MySQL-bench -Obsoletes: MySQL-test-classic MySQL-test-community MySQL-test-enterprise -Obsoletes: MySQL-test-advanced MySQL-test-advanced-gpl MySQL-test-enterprise-gpl -AutoReqProv: no +Summary: MySQL - Test suite +Group: Applications/Databases +%if %{defined susever} +Requires: MySQL-client perl +Provides: MySQL-test +Conflicts: mysql-test mysql-test-advanced +Obsoletes: MySQL-test +Obsoletes: mysql-bench MySQL-bench +Obsoletes: MySQL-test-classic MySQL-test-community MySQL-test-enterprise +Obsoletes: MySQL-test-advanced MySQL-test-advanced-gpl MySQL-test-enterprise-gpl +AutoReqProv: no +%else +Requires: MySQL-client perl +Conflicts: mysql-test mysql-test-advanced +Obsoletes: mysql-bench MySQL-bench +Obsoletes: MySQL-test < %{version}-%{release} +Obsoletes: MySQL-test-advanced < %{version}-%{release} +Obsoletes: MySQL-test-classic MySQL-test-community MySQL-test-enterprise +Obsoletes: MySQL-test-advanced-gpl MySQL-test-enterprise-gpl +Provides: MySQL-test MySQL-test-advanced +AutoReqProv: no +%endif %description -n MySQL-test%{product_suffix} This package contains the MySQL regression test suite. @@ -373,13 +406,22 @@ For a description of MySQL see the base MySQL RPM or http://www.mysql.com/ # ---------------------------------------------------------------------------- %package -n MySQL-devel%{product_suffix} -Summary: MySQL - Development header files and libraries -Group: Applications/Databases -Provides: MySQL-devel -Conflicts: mysql-devel mysql-embedded-devel mysql-devel-advanced mysql-embedded-devel-advanced -Obsoletes: MySQL-devel -Obsoletes: MySQL-devel-classic MySQL-devel-community MySQL-devel-enterprise -Obsoletes: MySQL-devel-advanced MySQL-devel-advanced-gpl MySQL-devel-enterprise-gpl +Summary: MySQL - Development header files and libraries +Group: Applications/Databases +%if %{defined susever} +Provides: MySQL-devel +Conflicts: mysql-devel mysql-embedded-devel mysql-devel-advanced mysql-embedded-devel-advanced +Obsoletes: MySQL-devel +Obsoletes: MySQL-devel-classic MySQL-devel-community MySQL-devel-enterprise +Obsoletes: MySQL-devel-advanced MySQL-devel-advanced-gpl MySQL-devel-enterprise-gpl +%else +Conflicts: mysql-devel mysql-embedded-devel mysql-devel-advanced mysql-embedded-devel-advanced +Obsoletes: MySQL-devel < %{version}-%{release} +Obsoletes: MySQL-devel-advanced < %{version}-%{release} +Obsoletes: MySQL-devel-classic MySQL-devel-community MySQL-devel-enterprise +Obsoletes: MySQL-devel-advanced-gpl MySQL-devel-enterprise-gpl +Provides: MySQL-devel MySQL-devel-advanced +%endif %description -n MySQL-devel%{product_suffix} This package contains the development header files and libraries necessary @@ -389,14 +431,25 @@ For a description of MySQL see the base MySQL RPM or http://www.mysql.com/ # ---------------------------------------------------------------------------- %package -n MySQL-shared%{product_suffix} -Summary: MySQL - Shared libraries -Group: Applications/Databases -Provides: MySQL-shared -Obsoletes: MySQL-shared-standard MySQL-shared-pro -Obsoletes: MySQL-shared-pro-cert MySQL-shared-pro-gpl -Obsoletes: MySQL-shared-pro-gpl-cert MySQL-shared -Obsoletes: MySQL-shared-classic MySQL-shared-community MySQL-shared-enterprise -Obsoletes: MySQL-shared-advanced MySQL-shared-advanced-gpl MySQL-shared-enterprise-gpl +Summary: MySQL - Shared libraries +Group: Applications/Databases +%if %{defined susever} +Provides: MySQL-shared +Obsoletes: MySQL-shared-standard MySQL-shared-pro +Obsoletes: MySQL-shared-pro-cert MySQL-shared-pro-gpl +Obsoletes: MySQL-shared-pro-gpl-cert MySQL-shared +Obsoletes: MySQL-shared-classic MySQL-shared-community MySQL-shared-enterprise +Obsoletes: MySQL-shared-advanced MySQL-shared-advanced-gpl MySQL-shared-enterprise-gpl +%else +Obsoletes: MySQL-shared-standard MySQL-shared-pro +Obsoletes: MySQL-shared-pro-cert MySQL-shared-pro-gpl +Obsoletes: MySQL-shared < %{version}-%{release} +Obsoletes: MySQL-shared-advanced < %{version}-%{release} +Obsoletes: MySQL-shared-pro-gpl-cert +Obsoletes: MySQL-shared-classic MySQL-shared-community MySQL-shared-enterprise +Obsoletes: MySQL-shared-advanced-gpl MySQL-shared-enterprise-gpl +Provides: MySQL-shared MySQL-shared-advanced +%endif %description -n MySQL-shared%{product_suffix} This package contains the shared libraries (*.so*) which certain languages @@ -405,15 +458,26 @@ and applications need to dynamically load and use MySQL. # ---------------------------------------------------------------------------- %if %{undefined with_wsrep} %package -n MySQL-embedded%{product_suffix} -Summary: MySQL - Embedded library -Group: Applications/Databases -Requires: MySQL-devel -Provides: MySQL-embedded -Conflicts: mysql-embedded mysql-embedded-advanced -Obsoletes: MySQL-embedded -Obsoletes: MySQL-embedded-pro -Obsoletes: MySQL-embedded-classic MySQL-embedded-community MySQL-embedded-enterprise -Obsoletes: MySQL-embedded-advanced MySQL-embedded-advanced-gpl MySQL-embedded-enterprise-gpl +Summary: MySQL - Embedded library +Group: Applications/Databases +%if %{defined susever} +Requires: MySQL-devel +Provides: MySQL-embedded +Conflicts: mysql-embedded mysql-embedded-advanced +Obsoletes: MySQL-embedded +Obsoletes: MySQL-embedded-pro +Obsoletes: MySQL-embedded-classic MySQL-embedded-community MySQL-embedded-enterprise +Obsoletes: MySQL-embedded-advanced MySQL-embedded-advanced-gpl MySQL-embedded-enterprise-gpl +%else +Requires: MySQL-devel +Conflicts: mysql-embedded mysql-embedded-advanced +Obsoletes: MySQL-embedded-pro +Obsoletes: MySQL-embedded < %{version}-%{release} +Obsoletes: MySQL-embedded-advanced < %{version}-%{release} +Obsoletes: MySQL-embedded-classic MySQL-embedded-community MySQL-embedded-enterprise +Obsoletes: MySQL-embedded-advanced-gpl MySQL-embedded-enterprise-gpl +Provides: MySQL-embedded MySQL-embedded-advanced +%endif %description -n MySQL-embedded%{product_suffix} This package contains the MySQL server as an embedded library. @@ -758,13 +822,16 @@ if [ -d $mysql_datadir ] ; then echo "MySQL RPM upgrade to version $NEW_VERSION" > $STATUS_FILE echo "'pre' step running at `date`" >> $STATUS_FILE echo >> $STATUS_FILE - echo "ERR file(s):" >> $STATUS_FILE - ls -ltr $mysql_datadir/*.err >> $STATUS_FILE - echo >> $STATUS_FILE - echo "Latest 'Version' line in latest file:" >> $STATUS_FILE - grep '^Version' `ls -tr $mysql_datadir/*.err | tail -1` | \ + fcount=`ls -ltr $mysql_datadir/*.err 2>/dev/null | wc -l` + if [ $fcount -gt 0 ] ; then + echo "ERR file(s):" >> $STATUS_FILE + ls -ltr $mysql_datadir/*.err >> $STATUS_FILE + echo >> $STATUS_FILE + echo "Latest 'Version' line in latest file:" >> $STATUS_FILE + grep '^Version' `ls -tr $mysql_datadir/*.err | tail -1` | \ tail -1 >> $STATUS_FILE - echo >> $STATUS_FILE + echo >> $STATUS_FILE + fi if [ -n "$SERVER_TO_START" ] ; then # There is only one PID file, race possibility ignored diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index d926334bb7f..8519bd91d23 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -16903,13 +16903,14 @@ static void test_bug31418() */ #define LARGE_BUFFER_SIZE 2048 +#define OLD_USERNAME_CHAR_LENGTH 16 static void test_bug31669() { int rc; static char buff[LARGE_BUFFER_SIZE+1]; #ifndef EMBEDDED_LIBRARY - static char user[USERNAME_CHAR_LENGTH+1]; + static char user[OLD_USERNAME_CHAR_LENGTH+1]; static char db[NAME_CHAR_LEN+1]; static char query[LARGE_BUFFER_SIZE*2]; #endif @@ -16946,7 +16947,7 @@ static void test_bug31669() myquery(rc); memset(user, 'b', sizeof(user)); - user[USERNAME_CHAR_LENGTH]= 0; + user[OLD_USERNAME_CHAR_LENGTH]= 0; memset(buff, 'c', sizeof(buff)); buff[LARGE_BUFFER_SIZE]= 0; strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'%' IDENTIFIED BY " @@ -16965,11 +16966,11 @@ static void test_bug31669() rc= mysql_change_user(conn, user, buff, db); DIE_UNLESS(!rc); - user[USERNAME_CHAR_LENGTH-1]= 'a'; + user[OLD_USERNAME_CHAR_LENGTH-1]= 'a'; rc= mysql_change_user(conn, user, buff, db); DIE_UNLESS(rc); - user[USERNAME_CHAR_LENGTH-1]= 'b'; + user[OLD_USERNAME_CHAR_LENGTH-1]= 'b'; buff[LARGE_BUFFER_SIZE-1]= 'd'; rc= mysql_change_user(conn, user, buff, db); DIE_UNLESS(rc); @@ -17739,7 +17740,11 @@ static void test_bug43560(void) fprintf(stdout, "Skipping test_bug43560: server not DEBUG version\n"); DBUG_VOID_RETURN; } - + if (opt_unix_socket) + { + fprintf(stdout, "Skipping test_bug43560: connected via UNIX socket\n"); + DBUG_VOID_RETURN; + } /* Set up a separate connection for this test to avoid messing up the general MYSQL object used in other subtests. Use TCP protocol to avoid @@ -18850,6 +18855,109 @@ static void test_bug13001491() myquery(rc); } +static void test_mdev4326() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind; + char query[]= "SELECT * FROM mysql.user LIMIT ?"; + char str_data[]= "1"; + unsigned long length= 0; + int int_data= 1; + int rc, count; + my_bool is_null= 0; + my_bool error= 0; + myheader("test_mdev4326"); + + rc= mysql_change_user(mysql, opt_user, opt_password, "mysql"); + myquery(rc); + + rc= mysql_query(mysql, "SET GLOBAL general_log = 1"); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + check_stmt(stmt); + + /* Numeric parameter test */ + + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_execute(stmt, rc); + check_stmt(stmt); + verify_param_count(stmt, 1); + + memset((char *)&bind, 0, sizeof(bind)); + bind.buffer_type= MYSQL_TYPE_LONG; + bind.buffer= (char *)&int_data; + bind.is_null= &is_null; + bind.length= &length; + bind.error= &error; + + rc= mysql_stmt_bind_param(stmt, &bind); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 1); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 1); + int_data= 0; + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 0); + rc= mysql_stmt_close(stmt); + check_execute(stmt, rc); + + /* String parameter test */ + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_execute(stmt, rc); + check_stmt(stmt); + verify_param_count(stmt, 1); + + memset((char *)&bind, 0, sizeof(bind)); + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer= (char *)str_data; + length= bind.buffer_length= sizeof(str_data); + bind.is_null= &is_null; + bind.length= &length; + bind.error= &error; + + rc= mysql_stmt_bind_param(stmt, &bind); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 1); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 1); + str_data[0]= '0'; + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + count= 0; + while (!(rc= mysql_stmt_fetch(stmt))) + count++; + DIE_UNLESS(count == 0); + rc= mysql_stmt_close(stmt); + check_execute(stmt, rc); + + rc= mysql_change_user(mysql, opt_user, opt_password, current_db); + myquery(rc); +} static struct my_tests_st my_tests[]= { { "disable_query_logs", disable_query_logs }, @@ -19115,6 +19223,7 @@ static struct my_tests_st my_tests[]= { { "test_progress_reporting", test_progress_reporting }, { "test_bug11754979", test_bug11754979 }, { "test_bug13001491", test_bug13001491 }, + { "test_mdev4326", test_mdev4326 }, { 0, 0 } }; diff --git a/vio/viossl.c b/vio/viossl.c index 74ad97809e2..c6f6dbd49c9 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -383,6 +383,10 @@ static int ssl_do(struct st_VioSSLFd *ptr, Vio *vio, long timeout, yaSSL_transport_set_send_function(ssl, yassl_send); #endif +#if !defined(HAVE_YASSL) && defined(SSL_OP_NO_COMPRESSION) + SSL_set_options(ssl, SSL_OP_NO_COMPRESSION); +#endif + if ((r= ssl_handshake_loop(vio, ssl, func)) < 1) { DBUG_PRINT("error", ("SSL_connect/accept failure")); diff --git a/win/packaging/ca/CustomAction.cpp b/win/packaging/ca/CustomAction.cpp index 50b39adc0b1..67a17c2cc19 100644 --- a/win/packaging/ca/CustomAction.cpp +++ b/win/packaging/ca/CustomAction.cpp @@ -895,7 +895,7 @@ extern "C" UINT __stdcall CheckServiceUpgrades(MSIHANDLE hInstall) Only look for services that have mysqld.exe outside of the current installation directory. */ - if(strstr(props.mysqld_exe,installDir) == 0) + if(installDir[0] == 0 || strstr(props.mysqld_exe,installDir) == 0) { WcaLog(LOGMSG_STANDARD, "found service %S, major=%d, minor=%d", info[i].lpServiceName, props.version_major, props.version_minor); diff --git a/win/packaging/extra.wxs.in b/win/packaging/extra.wxs.in index ff1a529a2ee..da4ac6aa9ac 100644 --- a/win/packaging/extra.wxs.in +++ b/win/packaging/extra.wxs.in @@ -151,6 +151,9 @@ CreateOrUpgradeChoice = "Upgrade" CreateOrUpgradeChoice = "Create" + CreateOrUpgradeChoice = "Create" + CreateOrUpgradeChoice = "Create" + CreateOrUpgradeChoice = "Upgrade" 1 @@ -634,6 +637,7 @@ + @@ -689,7 +694,7 @@ @@ -823,7 +828,7 @@ - + - $C.bin.mysql_upgrade_wizard.exe = 3 AND NOT Installed + $C.bin.mysql_upgrade_wizard.exe = 3 AND NOT Installed AND NOT OLDERVERSIONBEINGUPGRADED - 3) AND NOT Installed]]> + 3) AND NOT Installed OR OLDERVERSIONBEINGUPGRADED]]> - 3) AND NOT Installed]]> + 3) AND NOT Installed OR OLDERVERSIONBEINGUPGRADED]]> diff --git a/win/packaging/heidisql.cmake b/win/packaging/heidisql.cmake index f826c9a6633..124f85bb87e 100644 --- a/win/packaging/heidisql.cmake +++ b/win/packaging/heidisql.cmake @@ -1,4 +1,4 @@ -SET(HEIDISQL_BASE_NAME "HeidiSQL_7.0_Portable") +SET(HEIDISQL_BASE_NAME "HeidiSQL_8.0_Portable") SET(HEIDISQL_ZIP "${HEIDISQL_BASE_NAME}.zip") SET(HEIDISQL_URL "http://heidisql.googlecode.com/files/${HEIDISQL_ZIP}") SET(HEIDISQL_DOWNLOAD_DIR ${THIRD_PARTY_DOWNLOAD_LOCATION}/${HEIDISQL_BASE_NAME})