From 0b116de7c58db3e483964d00e6a3803947bfaf4f Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Thu, 27 Jun 2013 15:18:48 +0400 Subject: [PATCH] MDEV-4438 - Spider storage engine --- .../dist/Debian/mariadb-server-10.0.files.in | 1 + .../dist/Ubuntu/mariadb-server-10.0.files.in | 1 + mysql-test/mysql-test-run.pl | 2 +- storage/spider/CMakeLists.txt | 45 + storage/spider/Makefile.am | 89 + storage/spider/configure.in | 95 + storage/spider/ha_spider.cc | 13545 ++++++++++++++++ storage/spider/ha_spider.h | 1014 ++ storage/spider/hs_client/allocator.hpp | 43 + storage/spider/hs_client/auto_addrinfo.hpp | 49 + storage/spider/hs_client/auto_file.hpp | 67 + .../spider/hs_client/auto_ptrcontainer.hpp | 70 + storage/spider/hs_client/config.cpp | 291 + storage/spider/hs_client/config.hpp | 81 + storage/spider/hs_client/escape.cpp | 127 + storage/spider/hs_client/escape.hpp | 64 + storage/spider/hs_client/fatal.cpp | 68 + storage/spider/hs_client/fatal.hpp | 33 + storage/spider/hs_client/hs_compat.h | 31 + storage/spider/hs_client/hstcpcli.cpp | 643 + storage/spider/hs_client/hstcpcli.hpp | 93 + storage/spider/hs_client/mutex.hpp | 48 + storage/spider/hs_client/socket.cpp | 310 + storage/spider/hs_client/socket.hpp | 62 + storage/spider/hs_client/string_buffer.hpp | 146 + storage/spider/hs_client/string_ref.hpp | 106 + storage/spider/hs_client/string_util.cpp | 206 + storage/spider/hs_client/string_util.hpp | 51 + storage/spider/hs_client/thread.hpp | 84 + storage/spider/hs_client/util.hpp | 25 + .../spider/bg/include/deinit_child2_1.inc | 0 .../spider/bg/include/deinit_child2_2.inc | 0 .../spider/bg/include/deinit_child2_3.inc | 0 .../spider/bg/include/deinit_child3_1.inc | 0 .../spider/bg/include/deinit_child3_2.inc | 0 .../spider/bg/include/deinit_child3_3.inc | 0 .../spider/bg/include/deinit_master_1.inc | 1 + .../spider/bg/include/deinit_slave1_1.inc | 0 .../spider/bg/include/ha_deinit_child2_1.inc | 0 .../spider/bg/include/ha_deinit_child2_2.inc | 0 .../spider/bg/include/ha_deinit_child2_3.inc | 0 .../spider/bg/include/ha_deinit_child3_1.inc | 1 + .../spider/bg/include/ha_deinit_child3_2.inc | 1 + .../spider/bg/include/ha_deinit_child3_3.inc | 1 + .../spider/bg/include/ha_deinit_master_1.inc | 0 .../spider/bg/include/ha_init_child2_1.inc | 8 + .../spider/bg/include/ha_init_child2_2.inc | 4 + .../spider/bg/include/ha_init_child2_3.inc | 4 + .../spider/bg/include/ha_init_child3_1.inc | 140 + .../spider/bg/include/ha_init_child3_2.inc | 140 + .../spider/bg/include/ha_init_child3_3.inc | 140 + .../spider/bg/include/ha_init_master_1.inc | 105 + .../spider/bg/include/hs_deinit_child2_1.inc | 0 .../spider/bg/include/hs_deinit_child2_2.inc | 0 .../spider/bg/include/hs_deinit_child2_3.inc | 0 .../spider/bg/include/hs_deinit_master_1.inc | 0 .../spider/bg/include/hs_init_child2_1.inc | 24 + .../spider/bg/include/hs_init_child2_2.inc | 12 + .../spider/bg/include/hs_init_child2_3.inc | 0 .../spider/bg/include/hs_init_master_1.inc | 12 + .../spider/bg/include/init_child2_1.inc | 175 + .../spider/bg/include/init_child2_2.inc | 80 + .../spider/bg/include/init_child2_3.inc | 11 + .../spider/bg/include/init_child3_1.inc | 0 .../spider/bg/include/init_child3_2.inc | 0 .../spider/bg/include/init_child3_3.inc | 0 .../spider/bg/include/init_master_1.inc | 194 + .../spider/bg/include/init_slave1_1.inc | 10 + storage/spider/mysql-test/spider/bg/my.cnf | 176 + .../mysql-test/spider/bg/r/basic_sql.result | 701 + .../spider/bg/r/direct_aggregate.result | 132 + .../spider/bg/r/direct_update.result | 226 + .../mysql-test/spider/bg/r/function.result | 149 + .../spider/mysql-test/spider/bg/r/ha.result | 431 + .../spider/bg/r/spider3_fixes.result | 371 + .../spider/bg/r/spider_fixes.result | 692 + .../mysql-test/spider/bg/r/vp_fixes.result | 80 + storage/spider/mysql-test/spider/bg/suite.opt | 1 + storage/spider/mysql-test/spider/bg/suite.pm | 9 + .../mysql-test/spider/bg/t/basic_sql.test | 3189 ++++ .../spider/bg/t/connect_child2_1.inc | 1 + .../spider/bg/t/connect_child2_2.inc | 1 + .../spider/bg/t/connect_child2_3.inc | 1 + .../spider/bg/t/connect_child3_1.inc | 1 + .../spider/bg/t/connect_child3_2.inc | 1 + .../spider/bg/t/connect_child3_3.inc | 1 + .../spider/bg/t/connect_master_1.inc | 1 + .../spider/bg/t/connect_slave1_1.inc | 1 + .../spider/bg/t/direct_aggregate.test | 316 + .../mysql-test/spider/bg/t/direct_update.test | 354 + .../mysql-test/spider/bg/t/function.test | 276 + storage/spider/mysql-test/spider/bg/t/ha.test | 1794 ++ .../mysql-test/spider/bg/t/ha_test_deinit.inc | 30 + .../mysql-test/spider/bg/t/ha_test_init.inc | 30 + .../mysql-test/spider/bg/t/have_engine.inc | 7 + .../mysql-test/spider/bg/t/have_func.inc | 5 + .../mysql-test/spider/bg/t/have_partition.inc | 7 + .../mysql-test/spider/bg/t/have_trigger.inc | 2 + .../mysql-test/spider/bg/t/hs_test_deinit.inc | 17 + .../mysql-test/spider/bg/t/hs_test_init.inc | 17 + .../spider/bg/t/slave_test_deinit.inc | 6 + .../spider/bg/t/slave_test_init.inc | 44 + .../mysql-test/spider/bg/t/spider3_fixes.test | 570 + .../mysql-test/spider/bg/t/spider_fixes.test | 1967 +++ .../mysql-test/spider/bg/t/test_deinit.inc | 37 + .../mysql-test/spider/bg/t/test_init.inc | 74 + .../mysql-test/spider/bg/t/vp_fixes.test | 358 + .../handler/include/deinit_child2_1.inc | 0 .../handler/include/deinit_child2_2.inc | 0 .../handler/include/deinit_child2_3.inc | 0 .../handler/include/deinit_child3_1.inc | 0 .../handler/include/deinit_child3_2.inc | 0 .../handler/include/deinit_child3_3.inc | 0 .../handler/include/deinit_master_1.inc | 1 + .../handler/include/deinit_slave1_1.inc | 0 .../handler/include/ha_deinit_child2_1.inc | 0 .../handler/include/ha_deinit_child2_2.inc | 0 .../handler/include/ha_deinit_child2_3.inc | 0 .../handler/include/ha_deinit_child3_1.inc | 1 + .../handler/include/ha_deinit_child3_2.inc | 1 + .../handler/include/ha_deinit_child3_3.inc | 1 + .../handler/include/ha_deinit_master_1.inc | 0 .../handler/include/ha_init_child2_1.inc | 8 + .../handler/include/ha_init_child2_2.inc | 4 + .../handler/include/ha_init_child2_3.inc | 4 + .../handler/include/ha_init_child3_1.inc | 140 + .../handler/include/ha_init_child3_2.inc | 140 + .../handler/include/ha_init_child3_3.inc | 140 + .../handler/include/ha_init_master_1.inc | 105 + .../handler/include/hs_deinit_child2_1.inc | 0 .../handler/include/hs_deinit_child2_2.inc | 0 .../handler/include/hs_deinit_child2_3.inc | 0 .../handler/include/hs_deinit_master_1.inc | 0 .../handler/include/hs_init_child2_1.inc | 24 + .../handler/include/hs_init_child2_2.inc | 12 + .../handler/include/hs_init_child2_3.inc | 0 .../handler/include/hs_init_master_1.inc | 12 + .../spider/handler/include/init_child2_1.inc | 176 + .../spider/handler/include/init_child2_2.inc | 80 + .../spider/handler/include/init_child2_3.inc | 11 + .../spider/handler/include/init_child3_1.inc | 0 .../spider/handler/include/init_child3_2.inc | 0 .../spider/handler/include/init_child3_3.inc | 0 .../spider/handler/include/init_master_1.inc | 186 + .../spider/handler/include/init_slave1_1.inc | 10 + .../spider/mysql-test/spider/handler/my.cnf | 176 + .../spider/handler/r/basic_sql.result | 693 + .../spider/handler/r/direct_aggregate.result | 132 + .../spider/handler/r/direct_update.result | 242 + .../spider/handler/r/function.result | 149 + .../mysql-test/spider/handler/r/ha.result | 431 + .../spider/handler/r/spider3_fixes.result | 403 + .../spider/handler/r/spider_fixes.result | 699 + .../spider/handler/r/vp_fixes.result | 80 + .../spider/handler/t/basic_sql.test | 3189 ++++ .../spider/handler/t/connect_child2_1.inc | 1 + .../spider/handler/t/connect_child2_2.inc | 1 + .../spider/handler/t/connect_child2_3.inc | 1 + .../spider/handler/t/connect_child3_1.inc | 1 + .../spider/handler/t/connect_child3_2.inc | 1 + .../spider/handler/t/connect_child3_3.inc | 1 + .../spider/handler/t/connect_master_1.inc | 1 + .../spider/handler/t/connect_slave1_1.inc | 1 + .../spider/handler/t/direct_aggregate.test | 316 + .../spider/handler/t/direct_update.test | 354 + .../mysql-test/spider/handler/t/function.test | 276 + .../mysql-test/spider/handler/t/ha.test | 1794 ++ .../spider/handler/t/ha_test_deinit.inc | 30 + .../spider/handler/t/ha_test_init.inc | 30 + .../spider/handler/t/have_engine.inc | 7 + .../mysql-test/spider/handler/t/have_func.inc | 5 + .../spider/handler/t/have_partition.inc | 7 + .../spider/handler/t/have_trigger.inc | 2 + .../spider/handler/t/hs_test_deinit.inc | 17 + .../spider/handler/t/hs_test_init.inc | 17 + .../spider/handler/t/slave_test_deinit.inc | 6 + .../spider/handler/t/slave_test_init.inc | 44 + .../spider/handler/t/spider3_fixes.test | 570 + .../spider/handler/t/spider_fixes.test | 1967 +++ .../spider/handler/t/test_deinit.inc | 37 + .../mysql-test/spider/handler/t/test_init.inc | 74 + .../mysql-test/spider/handler/t/vp_fixes.test | 358 + .../spider/include/deinit_child2_1.inc | 3 + .../spider/include/deinit_child2_2.inc | 3 + .../spider/include/deinit_child2_3.inc | 3 + .../spider/include/deinit_child3_1.inc | 3 + .../spider/include/deinit_child3_2.inc | 3 + .../spider/include/deinit_child3_3.inc | 3 + .../spider/include/deinit_engine.inc | 4 + .../spider/include/deinit_handlersocket.inc | 1 + .../spider/include/deinit_innodb_plugin.inc | 1 + .../spider/include/deinit_master_1.inc | 1 + .../spider/include/deinit_slave1_1.inc | 0 .../spider/include/deinit_spider.inc | 17 + .../spider/include/ha_deinit_child2_1.inc | 0 .../spider/include/ha_deinit_child2_2.inc | 0 .../spider/include/ha_deinit_child2_3.inc | 0 .../spider/include/ha_deinit_child3_1.inc | 1 + .../spider/include/ha_deinit_child3_2.inc | 1 + .../spider/include/ha_deinit_child3_3.inc | 1 + .../spider/include/ha_deinit_master_1.inc | 0 .../spider/include/ha_init_child2_1.inc | 8 + .../spider/include/ha_init_child2_2.inc | 4 + .../spider/include/ha_init_child2_3.inc | 4 + .../spider/include/ha_init_child3_1.inc | 140 + .../spider/include/ha_init_child3_2.inc | 140 + .../spider/include/ha_init_child3_3.inc | 140 + .../spider/include/ha_init_master_1.inc | 105 + .../spider/include/hs_deinit_child2_1.inc | 0 .../spider/include/hs_deinit_child2_2.inc | 0 .../spider/include/hs_deinit_child2_3.inc | 0 .../spider/include/hs_deinit_master_1.inc | 0 .../spider/include/hs_init_child2_1.inc | 24 + .../spider/include/hs_init_child2_2.inc | 12 + .../spider/include/hs_init_child2_3.inc | 0 .../spider/include/hs_init_master_1.inc | 12 + .../spider/include/init_child2_1.inc | 178 + .../spider/include/init_child2_2.inc | 83 + .../spider/include/init_child2_3.inc | 14 + .../spider/include/init_child3_1.inc | 3 + .../spider/include/init_child3_2.inc | 3 + .../spider/include/init_child3_3.inc | 3 + .../mysql-test/spider/include/init_engine.inc | 10 + .../spider/include/init_master_1.inc | 186 + .../spider/include/init_slave1_1.inc | 10 + .../mysql-test/spider/include/init_spider.inc | 339 + storage/spider/mysql-test/spider/my.cnf | 177 + .../spider/oracle/include/deinit_child2_1.inc | 0 .../spider/oracle/include/deinit_child2_2.inc | 0 .../spider/oracle/include/deinit_child2_3.inc | 0 .../spider/oracle/include/deinit_child3_1.inc | 3 + .../spider/oracle/include/deinit_child3_2.inc | 3 + .../spider/oracle/include/deinit_child3_3.inc | 3 + .../spider/oracle/include/deinit_master_1.inc | 1 + .../spider/oracle/include/deinit_slave1_1.inc | 0 .../oracle/include/ha_deinit_child2_1.inc | 0 .../oracle/include/ha_deinit_child2_2.inc | 0 .../oracle/include/ha_deinit_child2_3.inc | 0 .../oracle/include/ha_deinit_child3_1.inc | 1 + .../oracle/include/ha_deinit_child3_2.inc | 1 + .../oracle/include/ha_deinit_child3_3.inc | 1 + .../oracle/include/ha_deinit_master_1.inc | 0 .../oracle/include/ha_init_child2_1.inc | 8 + .../oracle/include/ha_init_child2_2.inc | 4 + .../oracle/include/ha_init_child2_3.inc | 4 + .../oracle/include/ha_init_child3_1.inc | 140 + .../oracle/include/ha_init_child3_2.inc | 140 + .../oracle/include/ha_init_child3_3.inc | 140 + .../oracle/include/ha_init_master_1.inc | 109 + .../oracle/include/hs_deinit_child2_1.inc | 0 .../oracle/include/hs_deinit_child2_2.inc | 0 .../oracle/include/hs_deinit_child2_3.inc | 0 .../oracle/include/hs_deinit_master_1.inc | 0 .../oracle/include/hs_init_child2_1.inc | 24 + .../oracle/include/hs_init_child2_2.inc | 12 + .../oracle/include/hs_init_child2_3.inc | 0 .../oracle/include/hs_init_master_1.inc | 12 + .../spider/oracle/include/init_child2_1.inc | 192 + .../spider/oracle/include/init_child2_2.inc | 94 + .../spider/oracle/include/init_child2_3.inc | 15 + .../spider/oracle/include/init_child3_1.inc | 3 + .../spider/oracle/include/init_child3_2.inc | 3 + .../spider/oracle/include/init_child3_3.inc | 3 + .../spider/oracle/include/init_master_1.inc | 149 + .../spider/oracle/include/init_slave1_1.inc | 10 + .../spider/oracle/include/init_spider.inc | 105 + .../spider/mysql-test/spider/oracle/my.cnf | 146 + .../spider/oracle/r/basic_sql.result | 701 + .../spider/oracle/r/direct_aggregate.result | 132 + .../spider/oracle/r/direct_update.result | 226 + .../spider/oracle/r/function.result | 149 + .../mysql-test/spider/oracle/r/ha.result | 431 + .../spider/oracle/r/spider3_fixes.result | 343 + .../spider/oracle/r/spider_fixes.result | 670 + .../spider/oracle/r/vp_fixes.result | 80 + .../mysql-test/spider/oracle/t/basic_sql.test | 3189 ++++ .../spider/oracle/t/connect_child2_1.inc | 1 + .../spider/oracle/t/connect_child2_2.inc | 1 + .../spider/oracle/t/connect_child2_3.inc | 1 + .../spider/oracle/t/connect_child3_1.inc | 1 + .../spider/oracle/t/connect_child3_2.inc | 1 + .../spider/oracle/t/connect_child3_3.inc | 1 + .../spider/oracle/t/connect_master_1.inc | 1 + .../spider/oracle/t/connect_slave1_1.inc | 1 + .../spider/oracle/t/direct_aggregate.test | 316 + .../spider/oracle/t/direct_update.test | 354 + .../mysql-test/spider/oracle/t/function.test | 276 + .../spider/mysql-test/spider/oracle/t/ha.test | 1794 ++ .../spider/oracle/t/ha_test_deinit.inc | 30 + .../spider/oracle/t/ha_test_init.inc | 30 + .../spider/oracle/t/have_engine.inc | 7 + .../mysql-test/spider/oracle/t/have_func.inc | 5 + .../spider/oracle/t/have_partition.inc | 7 + .../spider/oracle/t/have_trigger.inc | 2 + .../spider/oracle/t/hs_test_deinit.inc | 17 + .../spider/oracle/t/hs_test_init.inc | 17 + .../spider/oracle/t/slave_test_deinit.inc | 6 + .../spider/oracle/t/slave_test_init.inc | 44 + .../spider/oracle/t/spider3_fixes.test | 570 + .../spider/oracle/t/spider_fixes.test | 1967 +++ .../spider/oracle/t/test_deinit.inc | 37 + .../mysql-test/spider/oracle/t/test_init.inc | 74 + .../mysql-test/spider/oracle/t/vp_fixes.test | 358 + .../oracle2/include/deinit_child2_1.inc | 0 .../oracle2/include/deinit_child2_2.inc | 0 .../oracle2/include/deinit_child2_3.inc | 0 .../oracle2/include/deinit_child3_1.inc | 3 + .../oracle2/include/deinit_child3_2.inc | 3 + .../oracle2/include/deinit_child3_3.inc | 3 + .../oracle2/include/deinit_master_1.inc | 1 + .../oracle2/include/deinit_slave1_1.inc | 0 .../oracle2/include/ha_deinit_child2_1.inc | 0 .../oracle2/include/ha_deinit_child2_2.inc | 0 .../oracle2/include/ha_deinit_child2_3.inc | 0 .../oracle2/include/ha_deinit_child3_1.inc | 1 + .../oracle2/include/ha_deinit_child3_2.inc | 1 + .../oracle2/include/ha_deinit_child3_3.inc | 1 + .../oracle2/include/ha_deinit_master_1.inc | 0 .../oracle2/include/ha_init_child2_1.inc | 8 + .../oracle2/include/ha_init_child2_2.inc | 4 + .../oracle2/include/ha_init_child2_3.inc | 4 + .../oracle2/include/ha_init_child3_1.inc | 140 + .../oracle2/include/ha_init_child3_2.inc | 140 + .../oracle2/include/ha_init_child3_3.inc | 140 + .../oracle2/include/ha_init_master_1.inc | 109 + .../oracle2/include/hs_deinit_child2_1.inc | 0 .../oracle2/include/hs_deinit_child2_2.inc | 0 .../oracle2/include/hs_deinit_child2_3.inc | 0 .../oracle2/include/hs_deinit_master_1.inc | 0 .../oracle2/include/hs_init_child2_1.inc | 24 + .../oracle2/include/hs_init_child2_2.inc | 12 + .../oracle2/include/hs_init_child2_3.inc | 0 .../oracle2/include/hs_init_master_1.inc | 12 + .../spider/oracle2/include/init_child2_1.inc | 192 + .../spider/oracle2/include/init_child2_2.inc | 94 + .../spider/oracle2/include/init_child2_3.inc | 15 + .../spider/oracle2/include/init_child3_1.inc | 3 + .../spider/oracle2/include/init_child3_2.inc | 3 + .../spider/oracle2/include/init_child3_3.inc | 3 + .../spider/oracle2/include/init_master_1.inc | 150 + .../spider/oracle2/include/init_slave1_1.inc | 10 + .../spider/oracle2/include/init_spider.inc | 105 + .../spider/mysql-test/spider/oracle2/my.cnf | 146 + .../spider/oracle2/r/basic_sql.result | 701 + .../spider/oracle2/r/direct_aggregate.result | 132 + .../spider/oracle2/r/direct_update.result | 226 + .../spider/oracle2/r/function.result | 149 + .../mysql-test/spider/oracle2/r/ha.result | 431 + .../spider/oracle2/r/spider3_fixes.result | 375 + .../spider/oracle2/r/spider_fixes.result | 678 + .../spider/oracle2/r/vp_fixes.result | 80 + .../spider/oracle2/t/basic_sql.test | 3189 ++++ .../spider/oracle2/t/connect_child2_1.inc | 1 + .../spider/oracle2/t/connect_child2_2.inc | 1 + .../spider/oracle2/t/connect_child2_3.inc | 1 + .../spider/oracle2/t/connect_child3_1.inc | 1 + .../spider/oracle2/t/connect_child3_2.inc | 1 + .../spider/oracle2/t/connect_child3_3.inc | 1 + .../spider/oracle2/t/connect_master_1.inc | 1 + .../spider/oracle2/t/connect_slave1_1.inc | 1 + .../spider/oracle2/t/direct_aggregate.test | 316 + .../spider/oracle2/t/direct_update.test | 354 + .../mysql-test/spider/oracle2/t/function.test | 276 + .../mysql-test/spider/oracle2/t/ha.test | 1794 ++ .../spider/oracle2/t/ha_test_deinit.inc | 30 + .../spider/oracle2/t/ha_test_init.inc | 30 + .../spider/oracle2/t/have_engine.inc | 7 + .../mysql-test/spider/oracle2/t/have_func.inc | 5 + .../spider/oracle2/t/have_partition.inc | 7 + .../spider/oracle2/t/have_trigger.inc | 2 + .../spider/oracle2/t/hs_test_deinit.inc | 17 + .../spider/oracle2/t/hs_test_init.inc | 17 + .../spider/oracle2/t/slave_test_deinit.inc | 6 + .../spider/oracle2/t/slave_test_init.inc | 44 + .../spider/oracle2/t/spider3_fixes.test | 570 + .../spider/oracle2/t/spider_fixes.test | 1967 +++ .../spider/oracle2/t/test_deinit.inc | 37 + .../mysql-test/spider/oracle2/t/test_init.inc | 74 + .../mysql-test/spider/oracle2/t/vp_fixes.test | 358 + .../mysql-test/spider/r/basic_sql.result | 701 + .../spider/r/direct_aggregate.result | 132 + .../mysql-test/spider/r/direct_update.result | 226 + .../mysql-test/spider/r/function.result | 149 + storage/spider/mysql-test/spider/r/ha.result | 431 + .../mysql-test/spider/r/spider3_fixes.result | 371 + .../mysql-test/spider/r/spider_fixes.result | 692 + .../mysql-test/spider/r/vp_fixes.result | 80 + storage/spider/mysql-test/spider/suite.opt | 1 + storage/spider/mysql-test/spider/suite.pm | 9 + .../spider/mysql-test/spider/t/basic_sql.test | 3189 ++++ .../mysql-test/spider/t/connect_child2_1.inc | 1 + .../mysql-test/spider/t/connect_child2_2.inc | 1 + .../mysql-test/spider/t/connect_child2_3.inc | 1 + .../mysql-test/spider/t/connect_child3_1.inc | 1 + .../mysql-test/spider/t/connect_child3_2.inc | 1 + .../mysql-test/spider/t/connect_child3_3.inc | 1 + .../mysql-test/spider/t/connect_master_1.inc | 1 + .../mysql-test/spider/t/connect_slave1_1.inc | 1 + .../mysql-test/spider/t/direct_aggregate.test | 316 + .../mysql-test/spider/t/direct_update.test | 354 + .../spider/mysql-test/spider/t/function.test | 276 + storage/spider/mysql-test/spider/t/ha.test | 1794 ++ .../mysql-test/spider/t/ha_test_deinit.inc | 30 + .../mysql-test/spider/t/ha_test_init.inc | 30 + .../mysql-test/spider/t/have_engine.inc | 7 + .../spider/mysql-test/spider/t/have_func.inc | 5 + .../mysql-test/spider/t/have_partition.inc | 7 + .../mysql-test/spider/t/have_plugin.inc | 5 + .../mysql-test/spider/t/have_trigger.inc | 2 + .../mysql-test/spider/t/hs_test_deinit.inc | 17 + .../mysql-test/spider/t/hs_test_init.inc | 17 + .../mysql-test/spider/t/slave_test_deinit.inc | 6 + .../mysql-test/spider/t/slave_test_init.inc | 44 + .../mysql-test/spider/t/spider3_fixes.test | 570 + .../mysql-test/spider/t/spider_fixes.test | 1967 +++ .../mysql-test/spider/t/test_deinit.inc | 37 + .../spider/mysql-test/spider/t/test_init.inc | 74 + .../spider/mysql-test/spider/t/vp_fixes.test | 358 + storage/spider/plug.in | 6 + storage/spider/spd_conn.cc | 3988 +++++ storage/spider/spd_conn.h | 313 + storage/spider/spd_copy_tables.cc | 1343 ++ storage/spider/spd_copy_tables.h | 55 + storage/spider/spd_db_conn.cc | 9729 +++++++++++ storage/spider/spd_db_conn.h | 1022 ++ storage/spider/spd_db_handlersocket.cc | 5308 ++++++ storage/spider/spd_db_handlersocket.h | 893 + storage/spider/spd_db_include.h | 1579 ++ storage/spider/spd_db_mysql.cc | 10839 +++++++++++++ storage/spider/spd_db_mysql.h | 1295 ++ storage/spider/spd_db_oracle.cc | 11764 ++++++++++++++ storage/spider/spd_db_oracle.h | 1389 ++ storage/spider/spd_direct_sql.cc | 1877 +++ storage/spider/spd_direct_sql.h | 67 + storage/spider/spd_err.h | 119 + storage/spider/spd_i_s.cc | 148 + storage/spider/spd_include.h | 1123 ++ storage/spider/spd_malloc.cc | 1267 ++ storage/spider/spd_malloc.h | 79 + storage/spider/spd_param.cc | 2933 ++++ storage/spider/spd_param.h | 370 + storage/spider/spd_ping_table.cc | 1460 ++ storage/spider/spd_ping_table.h | 102 + storage/spider/spd_sys_table.cc | 2417 +++ storage/spider/spd_sys_table.h | 427 + storage/spider/spd_table.cc | 7837 +++++++++ storage/spider/spd_table.h | 412 + storage/spider/spd_trx.cc | 4049 +++++ storage/spider/spd_trx.h | 260 + storage/spider/spd_udf.cc | 154 + storage/spider/spd_udf.def | 20 + storage/spider/spd_udf.h | 79 + 452 files changed, 158438 insertions(+), 1 deletion(-) create mode 100644 storage/spider/CMakeLists.txt create mode 100644 storage/spider/Makefile.am create mode 100644 storage/spider/configure.in create mode 100644 storage/spider/ha_spider.cc create mode 100644 storage/spider/ha_spider.h create mode 100644 storage/spider/hs_client/allocator.hpp create mode 100644 storage/spider/hs_client/auto_addrinfo.hpp create mode 100644 storage/spider/hs_client/auto_file.hpp create mode 100644 storage/spider/hs_client/auto_ptrcontainer.hpp create mode 100644 storage/spider/hs_client/config.cpp create mode 100644 storage/spider/hs_client/config.hpp create mode 100644 storage/spider/hs_client/escape.cpp create mode 100644 storage/spider/hs_client/escape.hpp create mode 100644 storage/spider/hs_client/fatal.cpp create mode 100644 storage/spider/hs_client/fatal.hpp create mode 100644 storage/spider/hs_client/hs_compat.h create mode 100644 storage/spider/hs_client/hstcpcli.cpp create mode 100644 storage/spider/hs_client/hstcpcli.hpp create mode 100644 storage/spider/hs_client/mutex.hpp create mode 100644 storage/spider/hs_client/socket.cpp create mode 100644 storage/spider/hs_client/socket.hpp create mode 100644 storage/spider/hs_client/string_buffer.hpp create mode 100644 storage/spider/hs_client/string_ref.hpp create mode 100644 storage/spider/hs_client/string_util.cpp create mode 100644 storage/spider/hs_client/string_util.hpp create mode 100644 storage/spider/hs_client/thread.hpp create mode 100644 storage/spider/hs_client/util.hpp create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/deinit_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/ha_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/hs_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/include/init_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/my.cnf create mode 100644 storage/spider/mysql-test/spider/bg/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/bg/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/bg/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/bg/r/function.result create mode 100644 storage/spider/mysql-test/spider/bg/r/ha.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/bg/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/bg/suite.opt create mode 100644 storage/spider/mysql-test/spider/bg/suite.pm create mode 100644 storage/spider/mysql-test/spider/bg/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_master_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/connect_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/direct_aggregate.test create mode 100644 storage/spider/mysql-test/spider/bg/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/bg/t/function.test create mode 100644 storage/spider/mysql-test/spider/bg/t/ha.test create mode 100644 storage/spider/mysql-test/spider/bg/t/ha_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/ha_test_init.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/have_engine.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/have_func.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/have_partition.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/have_trigger.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/hs_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/hs_test_init.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/slave_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/slave_test_init.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/bg/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/bg/t/test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/test_init.inc create mode 100644 storage/spider/mysql-test/spider/bg/t/vp_fixes.test create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/deinit_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/ha_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/hs_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/include/init_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/my.cnf create mode 100644 storage/spider/mysql-test/spider/handler/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/handler/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/handler/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/handler/r/function.result create mode 100644 storage/spider/mysql-test/spider/handler/r/ha.result create mode 100644 storage/spider/mysql-test/spider/handler/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/handler/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/handler/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/handler/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_master_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/connect_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/direct_aggregate.test create mode 100644 storage/spider/mysql-test/spider/handler/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/handler/t/function.test create mode 100644 storage/spider/mysql-test/spider/handler/t/ha.test create mode 100644 storage/spider/mysql-test/spider/handler/t/ha_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/ha_test_init.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/have_engine.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/have_func.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/have_partition.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/have_trigger.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/hs_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/hs_test_init.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/slave_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/slave_test_init.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/handler/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/handler/t/test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/test_init.inc create mode 100644 storage/spider/mysql-test/spider/handler/t/vp_fixes.test create mode 100644 storage/spider/mysql-test/spider/include/deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_engine.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_handlersocket.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_innodb_plugin.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/include/deinit_spider.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/include/ha_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/hs_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/include/init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/include/init_engine.inc create mode 100644 storage/spider/mysql-test/spider/include/init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/include/init_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/include/init_spider.inc create mode 100644 storage/spider/mysql-test/spider/my.cnf create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/deinit_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/ha_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/hs_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/include/init_spider.inc create mode 100644 storage/spider/mysql-test/spider/oracle/my.cnf create mode 100644 storage/spider/mysql-test/spider/oracle/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/function.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/ha.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/connect_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/direct_aggregate.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/function.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/ha.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/ha_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/ha_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/have_engine.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/have_func.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/have_partition.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/have_trigger.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/hs_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/hs_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/slave_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/slave_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/oracle/t/test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle/t/vp_fixes.test create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/deinit_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/ha_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_deinit_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_deinit_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/hs_init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/include/init_spider.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/my.cnf create mode 100644 storage/spider/mysql-test/spider/oracle2/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/function.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/ha.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle2/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/oracle2/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_master_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/connect_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/direct_aggregate.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/function.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/ha.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/ha_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/ha_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/have_engine.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/have_func.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/have_partition.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/have_trigger.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/hs_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/hs_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/slave_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/slave_test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/oracle2/t/test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/test_init.inc create mode 100644 storage/spider/mysql-test/spider/oracle2/t/vp_fixes.test create mode 100644 storage/spider/mysql-test/spider/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/r/function.result create mode 100644 storage/spider/mysql-test/spider/r/ha.result create mode 100644 storage/spider/mysql-test/spider/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/suite.opt create mode 100644 storage/spider/mysql-test/spider/suite.pm create mode 100644 storage/spider/mysql-test/spider/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/t/connect_child2_1.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_child2_2.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_child2_3.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_child3_1.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_child3_2.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_child3_3.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_master_1.inc create mode 100644 storage/spider/mysql-test/spider/t/connect_slave1_1.inc create mode 100644 storage/spider/mysql-test/spider/t/direct_aggregate.test create mode 100644 storage/spider/mysql-test/spider/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/t/function.test create mode 100644 storage/spider/mysql-test/spider/t/ha.test create mode 100644 storage/spider/mysql-test/spider/t/ha_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/ha_test_init.inc create mode 100644 storage/spider/mysql-test/spider/t/have_engine.inc create mode 100644 storage/spider/mysql-test/spider/t/have_func.inc create mode 100644 storage/spider/mysql-test/spider/t/have_partition.inc create mode 100644 storage/spider/mysql-test/spider/t/have_plugin.inc create mode 100644 storage/spider/mysql-test/spider/t/have_trigger.inc create mode 100644 storage/spider/mysql-test/spider/t/hs_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/hs_test_init.inc create mode 100644 storage/spider/mysql-test/spider/t/slave_test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/slave_test_init.inc create mode 100644 storage/spider/mysql-test/spider/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/t/test_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/test_init.inc create mode 100644 storage/spider/mysql-test/spider/t/vp_fixes.test create mode 100644 storage/spider/plug.in create mode 100644 storage/spider/spd_conn.cc create mode 100644 storage/spider/spd_conn.h create mode 100644 storage/spider/spd_copy_tables.cc create mode 100644 storage/spider/spd_copy_tables.h create mode 100644 storage/spider/spd_db_conn.cc create mode 100644 storage/spider/spd_db_conn.h create mode 100644 storage/spider/spd_db_handlersocket.cc create mode 100644 storage/spider/spd_db_handlersocket.h create mode 100644 storage/spider/spd_db_include.h create mode 100644 storage/spider/spd_db_mysql.cc create mode 100644 storage/spider/spd_db_mysql.h create mode 100644 storage/spider/spd_db_oracle.cc create mode 100644 storage/spider/spd_db_oracle.h create mode 100644 storage/spider/spd_direct_sql.cc create mode 100644 storage/spider/spd_direct_sql.h create mode 100644 storage/spider/spd_err.h create mode 100644 storage/spider/spd_i_s.cc create mode 100644 storage/spider/spd_include.h create mode 100644 storage/spider/spd_malloc.cc create mode 100644 storage/spider/spd_malloc.h create mode 100644 storage/spider/spd_param.cc create mode 100644 storage/spider/spd_param.h create mode 100644 storage/spider/spd_ping_table.cc create mode 100644 storage/spider/spd_ping_table.h create mode 100644 storage/spider/spd_sys_table.cc create mode 100644 storage/spider/spd_sys_table.h create mode 100644 storage/spider/spd_table.cc create mode 100644 storage/spider/spd_table.h create mode 100644 storage/spider/spd_trx.cc create mode 100644 storage/spider/spd_trx.h create mode 100644 storage/spider/spd_udf.cc create mode 100644 storage/spider/spd_udf.def create mode 100644 storage/spider/spd_udf.h 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/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/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index ed84175edae..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(); 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..d17de6cd32e --- /dev/null +++ b/storage/spider/spd_db_mysql.cc @@ -0,0 +1,10839 @@ +/* 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 + int not_used_int; + 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]) + { + str_to_datetime(mysql_row[11], strlen(mysql_row[11]), &mysql_time, 0, + ¬_used_int); +#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]) + { + str_to_datetime(mysql_row[12], strlen(mysql_row[12]), &mysql_time, 0, + ¬_used_int); +#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]) + { + str_to_datetime(mysql_row[13], strlen(mysql_row[13]), &mysql_time, 0, + ¬_used_int); +#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]) + { + str_to_datetime(mysql_row[6], strlen(mysql_row[6]), &mysql_time, 0, + ¬_used_int); +#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]) + { + str_to_datetime(mysql_row[7], strlen(mysql_row[7]), &mysql_time, 0, + ¬_used_int); +#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]) + { + str_to_datetime(mysql_row[8], strlen(mysql_row[8]), &mysql_time, 0, + ¬_used_int); +#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 +);