From 06eaf7232e9a920468c0f8d74dcf2fe8b555501c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:24:36 +0200 Subject: Adding upstream version 1:10.11.6. Signed-off-by: Daniel Baumann --- storage/spider/CMakeLists.txt | 43 + storage/spider/ha_spider.cc | 12186 ++++++++++++++ storage/spider/ha_spider.h | 794 + .../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 + .../mysql-test/spider/bg/include/init_child2_1.inc | 175 + .../mysql-test/spider/bg/include/init_child2_2.inc | 80 + .../mysql-test/spider/bg/include/init_child2_3.inc | 11 + .../mysql-test/spider/bg/include/init_child3_1.inc | 0 .../mysql-test/spider/bg/include/init_child3_2.inc | 0 .../mysql-test/spider/bg/include/init_child3_3.inc | 0 .../mysql-test/spider/bg/include/init_master_1.inc | 194 + .../mysql-test/spider/bg/include/init_slave1_1.inc | 10 + storage/spider/mysql-test/spider/bg/my.cnf | 176 + .../spider/mysql-test/spider/bg/r/basic_sql.result | 738 + .../mysql-test/spider/bg/r/basic_sql_part.result | 141 + .../mysql-test/spider/bg/r/direct_aggregate.result | 100 + .../spider/bg/r/direct_aggregate_part.result | 121 + .../mysql-test/spider/bg/r/direct_update.result | 155 + .../spider/bg/r/direct_update_part.result | 145 + .../spider/mysql-test/spider/bg/r/function.result | 160 + storage/spider/mysql-test/spider/bg/r/ha.result | 286 + .../spider/mysql-test/spider/bg/r/ha_part.result | 311 + .../mysql-test/spider/bg/r/spider3_fixes.result | 224 + .../spider/bg/r/spider3_fixes_part.result | 222 + .../mysql-test/spider/bg/r/spider_fixes.result | 616 + .../spider/bg/r/spider_fixes_part.result | 237 + .../spider/mysql-test/spider/bg/r/vp_fixes.result | 93 + storage/spider/mysql-test/spider/bg/suite.opt | 1 + storage/spider/mysql-test/spider/bg/suite.pm | 11 + .../spider/mysql-test/spider/bg/t/basic_sql.test | 2701 ++++ .../mysql-test/spider/bg/t/basic_sql_part.test | 571 + .../mysql-test/spider/bg/t/connect_child2_1.inc | 1 + .../mysql-test/spider/bg/t/connect_child2_2.inc | 1 + .../mysql-test/spider/bg/t/connect_child2_3.inc | 1 + .../mysql-test/spider/bg/t/connect_child3_1.inc | 1 + .../mysql-test/spider/bg/t/connect_child3_2.inc | 1 + .../mysql-test/spider/bg/t/connect_child3_3.inc | 1 + .../mysql-test/spider/bg/t/connect_master_1.inc | 1 + .../mysql-test/spider/bg/t/connect_slave1_1.inc | 1 + .../mysql-test/spider/bg/t/direct_aggregate.test | 181 + .../spider/bg/t/direct_aggregate_part.test | 210 + .../mysql-test/spider/bg/t/direct_update.test | 198 + .../mysql-test/spider/bg/t/direct_update_part.test | 211 + .../spider/mysql-test/spider/bg/t/function.test | 253 + storage/spider/mysql-test/spider/bg/t/ha.test | 882 + storage/spider/mysql-test/spider/bg/t/ha_part.test | 1017 ++ .../mysql-test/spider/bg/t/ha_test_deinit.inc | 30 + .../spider/mysql-test/spider/bg/t/ha_test_init.inc | 30 + .../spider/mysql-test/spider/bg/t/have_engine.inc | 7 + .../spider/mysql-test/spider/bg/t/have_func.inc | 5 + .../mysql-test/spider/bg/t/have_partition.inc | 7 + .../spider/mysql-test/spider/bg/t/have_trigger.inc | 2 + .../mysql-test/spider/bg/t/hs_test_deinit.inc | 17 + .../spider/mysql-test/spider/bg/t/hs_test_init.inc | 17 + .../mysql-test/spider/bg/t/slave_test_deinit.inc | 6 + .../mysql-test/spider/bg/t/slave_test_init.inc | 44 + .../mysql-test/spider/bg/t/spider3_fixes.test | 294 + .../mysql-test/spider/bg/t/spider3_fixes_part.test | 347 + .../mysql-test/spider/bg/t/spider_fixes.test | 1427 ++ .../mysql-test/spider/bg/t/spider_fixes_part.test | 647 + .../spider/mysql-test/spider/bg/t/test_deinit.inc | 37 + .../spider/mysql-test/spider/bg/t/test_init.inc | 74 + .../spider/mysql-test/spider/bg/t/vp_fixes.test | 335 + .../spider/mysql-test/spider/bugfix/disabled.def | 3 + .../checksum_table_with_quick_mode_3_deinit.inc | 14 + .../checksum_table_with_quick_mode_3_init.inc | 29 + .../spider/bugfix/include/cp932_column_deinit.inc | 13 + .../spider/bugfix/include/cp932_column_init.inc | 29 + .../delete_with_float_column_default_deinit.inc | 4 + .../delete_with_float_column_default_init.inc | 32 + .../include/delete_with_float_column_deinit.inc | 13 + .../include/delete_with_float_column_init.inc | 24 + .../delete_with_float_column_mariadb_deinit.inc | 4 + .../delete_with_float_column_mariadb_init.inc | 14 + .../delete_with_float_column_mysql_deinit.inc | 4 + .../delete_with_float_column_mysql_init.inc | 16 + .../include/direct_sql_with_comma_pwd_deinit.inc | 9 + .../include/direct_sql_with_comma_pwd_init.inc | 11 + .../include/direct_sql_with_tmp_table_deinit.inc | 7 + .../include/direct_sql_with_tmp_table_init.inc | 9 + .../include/group_by_order_by_limit_deinit.inc | 14 + .../include/group_by_order_by_limit_init.inc | 54 + .../spider/bugfix/include/insert_select_deinit.inc | 16 + .../spider/bugfix/include/insert_select_init.inc | 43 + .../spider/bugfix/include/mdev_19866_deinit.inc | 14 + .../spider/bugfix/include/mdev_19866_init.inc | 52 + .../spider/bugfix/include/mdev_20100_deinit.inc | 11 + .../spider/bugfix/include/mdev_20100_init.inc | 46 + .../spider/bugfix/include/mdev_20502_deinit.inc | 11 + .../spider/bugfix/include/mdev_20502_init.inc | 25 + .../spider/bugfix/include/mdev_21884_deinit.inc | 14 + .../spider/bugfix/include/mdev_21884_init.inc | 57 + .../spider/bugfix/include/mdev_22246_deinit.inc | 14 + .../spider/bugfix/include/mdev_22246_init.inc | 48 + .../spider/bugfix/include/mdev_22265_deinit.inc | 7 + .../spider/bugfix/include/mdev_22265_init.inc | 7 + .../spider/bugfix/include/mdev_24020_deinit.inc | 11 + .../spider/bugfix/include/mdev_24020_init.inc | 43 + .../spider/bugfix/include/mdev_24517_deinit.inc | 11 + .../spider/bugfix/include/mdev_24517_init.inc | 43 + .../spider/bugfix/include/mdev_24523_deinit.inc | 9 + .../spider/bugfix/include/mdev_24523_init.inc | 31 + .../spider/bugfix/include/quick_mode_0_deinit.inc | 19 + .../spider/bugfix/include/quick_mode_0_init.inc | 51 + .../spider/bugfix/include/quick_mode_1_deinit.inc | 19 + .../spider/bugfix/include/quick_mode_1_init.inc | 51 + .../spider/bugfix/include/quick_mode_2_deinit.inc | 19 + .../spider/bugfix/include/quick_mode_2_init.inc | 51 + .../spider/bugfix/include/quick_mode_3_deinit.inc | 19 + .../spider/bugfix/include/quick_mode_3_init.inc | 51 + .../include/return_found_rows_insert_deinit.inc | 11 + .../include/return_found_rows_insert_init.inc | 27 + .../include/return_found_rows_update_deinit.inc | 11 + .../include/return_found_rows_update_init.inc | 26 + .../bugfix/include/same_server_link_deinit.inc | 11 + .../bugfix/include/same_server_link_init.inc | 15 + .../bugfix/include/select_by_null_deinit.inc | 11 + .../spider/bugfix/include/select_by_null_init.inc | 24 + .../include/select_with_backquote_deinit.inc | 11 + .../bugfix/include/select_with_backquote_init.inc | 25 + .../bugfix/include/self_reference_deinit.inc | 10 + .../spider/bugfix/include/self_reference_init.inc | 13 + ...lave_transaction_retry_errors_5digit_deinit.inc | 10 + .../slave_transaction_retry_errors_5digit_init.inc | 10 + .../bugfix/include/slave_trx_isolation_deinit.inc | 15 + .../bugfix/include/slave_trx_isolation_init.inc | 35 + .../bugfix/include/spider_table_sts_deinit.inc | 12 + .../bugfix/include/spider_table_sts_init.inc | 13 + .../spider/bugfix/include/sql_mode_deinit.inc | 13 + .../spider/bugfix/include/sql_mode_init.inc | 40 + .../bugfix/include/sql_mode_mariadb_deinit.inc | 1 + .../bugfix/include/sql_mode_mariadb_init.inc | 3 + .../bugfix/include/sql_mode_mysql_deinit.inc | 1 + .../spider/bugfix/include/sql_mode_mysql_init.inc | 3 + .../bugfix/include/strict_group_by_deinit.inc | 18 + .../spider/bugfix/include/strict_group_by_init.inc | 60 + .../spider/bugfix/include/wait_timeout_deinit.inc | 18 + .../spider/bugfix/include/wait_timeout_init.inc | 56 + .../bugfix/include/wrapper_mariadb_deinit.inc | 11 + .../spider/bugfix/include/wrapper_mariadb_init.inc | 24 + .../spider/bugfix/include/xa_cmd_deinit.inc | 11 + .../spider/bugfix/include/xa_cmd_init.inc | 24 + storage/spider/mysql-test/spider/bugfix/my.cnf | 2 + storage/spider/mysql-test/spider/bugfix/my_1_1.cnf | 44 + storage/spider/mysql-test/spider/bugfix/my_2_1.cnf | 56 + storage/spider/mysql-test/spider/bugfix/my_2_2.cnf | 38 + storage/spider/mysql-test/spider/bugfix/my_2_3.cnf | 8 + storage/spider/mysql-test/spider/bugfix/my_3_1.cnf | 11 + storage/spider/mysql-test/spider/bugfix/my_3_2.cnf | 9 + storage/spider/mysql-test/spider/bugfix/my_3_3.cnf | 9 + storage/spider/mysql-test/spider/bugfix/my_4_1.cnf | 9 + .../r/checksum_table_with_quick_mode_3.result | 100 + .../mysql-test/spider/bugfix/r/cp932_column.result | 84 + .../mysql-test/spider/bugfix/r/ddl_log.result | 12 + .../r/delete_with_float_column_default.result | 85 + .../r/delete_with_float_column_mariadb.result | 85 + .../bugfix/r/delete_with_float_column_mysql.result | 85 + .../bugfix/r/direct_sql_with_comma_pwd.result | 37 + .../bugfix/r/direct_sql_with_tmp_table.result | 33 + .../spider/bugfix/r/group_by_order_by_limit.result | 126 + .../spider/mysql-test/spider/bugfix/r/index.result | 57 + .../spider/bugfix/r/insert_select.result | 102 + .../mysql-test/spider/bugfix/r/mdev_19866.result | 111 + .../mysql-test/spider/bugfix/r/mdev_20100.result | 119 + .../mysql-test/spider/bugfix/r/mdev_20502.result | 85 + .../mysql-test/spider/bugfix/r/mdev_21884.result | 104 + .../mysql-test/spider/bugfix/r/mdev_22246.result | 79 + .../mysql-test/spider/bugfix/r/mdev_22265.result | 23 + .../mysql-test/spider/bugfix/r/mdev_22979.result | 5 + .../mysql-test/spider/bugfix/r/mdev_24020.result | 97 + .../mysql-test/spider/bugfix/r/mdev_24343.result | 75 + .../mysql-test/spider/bugfix/r/mdev_24517.result | 78 + .../mysql-test/spider/bugfix/r/mdev_24523.result | 58 + .../mysql-test/spider/bugfix/r/mdev_24760.result | 49 + .../mysql-test/spider/bugfix/r/mdev_25116.result | 42 + .../mysql-test/spider/bugfix/r/mdev_25684.result | 18 + .../mysql-test/spider/bugfix/r/mdev_26013.result | 42 + .../mysql-test/spider/bugfix/r/mdev_26151.result | 34 + .../mysql-test/spider/bugfix/r/mdev_26158.result | 27 + .../mysql-test/spider/bugfix/r/mdev_26247.result | 96 + .../mysql-test/spider/bugfix/r/mdev_26539.result | 36 + .../mysql-test/spider/bugfix/r/mdev_26541.result | 19 + .../mysql-test/spider/bugfix/r/mdev_26544.result | 23 + .../mysql-test/spider/bugfix/r/mdev_26582.result | 11 + .../mysql-test/spider/bugfix/r/mdev_27172.result | 83 + .../mysql-test/spider/bugfix/r/mdev_27184.result | 21 + .../mysql-test/spider/bugfix/r/mdev_27233.result | 11 + .../mysql-test/spider/bugfix/r/mdev_27239.result | 20 + .../mysql-test/spider/bugfix/r/mdev_27240.result | 16 + .../mysql-test/spider/bugfix/r/mdev_28218.result | 9 + .../spider/bugfix/r/mdev_28218_init_file.result | 5 + .../spider/bugfix/r/mdev_28218_mixed.result | 5 + .../mysql-test/spider/bugfix/r/mdev_28854.result | 32 + .../mysql-test/spider/bugfix/r/mdev_28856.result | 180 + .../mysql-test/spider/bugfix/r/mdev_28996.result | 34 + .../mysql-test/spider/bugfix/r/mdev_28998.result | 26 + .../mysql-test/spider/bugfix/r/mdev_29008.result | 38 + .../mysql-test/spider/bugfix/r/mdev_29011.result | 40 + .../mysql-test/spider/bugfix/r/mdev_29163.result | 26 + .../mysql-test/spider/bugfix/r/mdev_29352.result | 13 + .../mysql-test/spider/bugfix/r/mdev_29447.result | 33 + .../mysql-test/spider/bugfix/r/mdev_29484.result | 39 + .../mysql-test/spider/bugfix/r/mdev_29502.result | 68 + .../mysql-test/spider/bugfix/r/mdev_29562.result | 47 + .../mysql-test/spider/bugfix/r/mdev_29644.result | 41 + .../mysql-test/spider/bugfix/r/mdev_29653.result | 33 + .../mysql-test/spider/bugfix/r/mdev_29904.result | 4 + .../mysql-test/spider/bugfix/r/mdev_30191.result | 44 + .../mysql-test/spider/bugfix/r/mdev_30370.result | 8 + .../mysql-test/spider/bugfix/r/mdev_30392.result | 25 + .../mysql-test/spider/bugfix/r/mdev_30981.result | 12 + .../mysql-test/spider/bugfix/r/mdev_31117.result | 22 + .../mysql-test/spider/bugfix/r/mdev_31338.result | 16 + .../mysql-test/spider/bugfix/r/mdev_31524.result | 50 + .../mysql-test/spider/bugfix/r/mdev_31645.result | 28 + .../mysql-test/spider/bugfix/r/mdev_31996.result | 47 + .../mysql-test/spider/bugfix/r/mdev_32683.result | 16 + .../spider/bugfix/r/plugin_load_add_all.result | 7 + .../spider/bugfix/r/plugin_load_add_spider.result | 7 + .../mysql-test/spider/bugfix/r/quick_mode_0.result | 504 + .../mysql-test/spider/bugfix/r/quick_mode_1.result | 504 + .../mysql-test/spider/bugfix/r/quick_mode_2.result | 504 + .../mysql-test/spider/bugfix/r/quick_mode_3.result | 504 + .../bugfix/r/return_found_rows_insert.result | 179 + .../bugfix/r/return_found_rows_update.result | 99 + .../spider/bugfix/r/same_server_link.result | 42 + .../spider/bugfix/r/select_by_null.result | 90 + .../spider/bugfix/r/select_with_backquote.result | 75 + .../spider/bugfix/r/self_reference.result | 36 + .../spider/bugfix/r/self_reference_multi.result | 22 + .../r/slave_transaction_retry_errors_5digit.result | 22 + .../spider/bugfix/r/slave_trx_isolation.result | 99 + .../spider/bugfix/r/spider_table_sts.result | 38 + .../spider/bugfix/r/sql_mode_mariadb.result | 83 + .../spider/bugfix/r/sql_mode_mysql.result | 83 + .../spider/bugfix/r/strict_group_by.result | 133 + .../spider/bugfix/r/udf_mysql_func_early.result | 43 + .../bugfix/r/udf_mysql_func_early_init_file.result | 1 + .../mysql-test/spider/bugfix/r/wait_timeout.result | 130 + .../spider/bugfix/r/wrapper_mariadb.result | 78 + .../mysql-test/spider/bugfix/r/xa_cmd.result | 68 + storage/spider/mysql-test/spider/bugfix/suite.opt | 1 + storage/spider/mysql-test/spider/bugfix/suite.pm | 11 + .../bugfix/t/checksum_table_with_quick_mode_3.cnf | 3 + .../bugfix/t/checksum_table_with_quick_mode_3.test | 74 + .../mysql-test/spider/bugfix/t/cp932_column.cnf | 3 + .../mysql-test/spider/bugfix/t/cp932_column.test | 82 + .../spider/mysql-test/spider/bugfix/t/ddl_log.test | 17 + .../spider/bugfix/t/delete_with_float_column.inc | 102 + .../bugfix/t/delete_with_float_column_default.cnf | 4 + .../bugfix/t/delete_with_float_column_default.test | 5 + .../bugfix/t/delete_with_float_column_mariadb.cnf | 4 + .../bugfix/t/delete_with_float_column_mariadb.test | 5 + .../bugfix/t/delete_with_float_column_mysql.cnf | 4 + .../bugfix/t/delete_with_float_column_mysql.test | 5 + .../spider/bugfix/t/direct_sql_with_comma_pwd.cnf | 3 + .../spider/bugfix/t/direct_sql_with_comma_pwd.test | 37 + .../spider/bugfix/t/direct_sql_with_tmp_table.cnf | 3 + .../spider/bugfix/t/direct_sql_with_tmp_table.test | 37 + .../spider/bugfix/t/group_by_order_by_limit.cnf | 4 + .../spider/bugfix/t/group_by_order_by_limit.test | 104 + .../spider/mysql-test/spider/bugfix/t/index.test | 53 + .../mysql-test/spider/bugfix/t/insert_select.cnf | 3 + .../mysql-test/spider/bugfix/t/insert_select.test | 101 + .../mysql-test/spider/bugfix/t/mdev_19866.cnf | 4 + .../mysql-test/spider/bugfix/t/mdev_19866.test | 99 + .../mysql-test/spider/bugfix/t/mdev_20100.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_20100.test | 93 + .../mysql-test/spider/bugfix/t/mdev_20502.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_20502.test | 80 + .../mysql-test/spider/bugfix/t/mdev_21884.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_21884.test | 105 + .../mysql-test/spider/bugfix/t/mdev_22246.cnf | 4 + .../mysql-test/spider/bugfix/t/mdev_22246.test | 92 + .../mysql-test/spider/bugfix/t/mdev_22265.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_22265.test | 28 + .../mysql-test/spider/bugfix/t/mdev_22979.test | 18 + .../mysql-test/spider/bugfix/t/mdev_24020.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_24020.test | 90 + .../mysql-test/spider/bugfix/t/mdev_24343.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_24343.test | 84 + .../mysql-test/spider/bugfix/t/mdev_24517.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_24517.test | 80 + .../mysql-test/spider/bugfix/t/mdev_24523.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_24523.test | 66 + .../mysql-test/spider/bugfix/t/mdev_24760.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_24760.test | 49 + .../mysql-test/spider/bugfix/t/mdev_25116.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_25116.test | 44 + .../mysql-test/spider/bugfix/t/mdev_25684.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_25684.test | 19 + .../mysql-test/spider/bugfix/t/mdev_26013.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_26013.test | 51 + .../mysql-test/spider/bugfix/t/mdev_26151.test | 54 + .../mysql-test/spider/bugfix/t/mdev_26158.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_26158.test | 31 + .../mysql-test/spider/bugfix/t/mdev_26247.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_26247.test | 85 + .../mysql-test/spider/bugfix/t/mdev_26539.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_26539.test | 40 + .../mysql-test/spider/bugfix/t/mdev_26541.test | 23 + .../mysql-test/spider/bugfix/t/mdev_26544.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_26544.test | 32 + .../mysql-test/spider/bugfix/t/mdev_26582.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_26582.test | 27 + .../mysql-test/spider/bugfix/t/mdev_27172.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_27172.test | 94 + .../mysql-test/spider/bugfix/t/mdev_27184.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_27184.test | 31 + .../mysql-test/spider/bugfix/t/mdev_27233.opt | 1 + .../mysql-test/spider/bugfix/t/mdev_27233.sql | 3 + .../mysql-test/spider/bugfix/t/mdev_27233.test | 7 + .../mysql-test/spider/bugfix/t/mdev_27239.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_27239.test | 24 + .../mysql-test/spider/bugfix/t/mdev_27240.cnf | 2 + .../mysql-test/spider/bugfix/t/mdev_27240.test | 29 + .../mysql-test/spider/bugfix/t/mdev_28218.test | 10 + .../spider/bugfix/t/mdev_28218_init_file.opt | 1 + .../spider/bugfix/t/mdev_28218_init_file.sql | 2 + .../spider/bugfix/t/mdev_28218_init_file.test | 7 + .../spider/bugfix/t/mdev_28218_mixed.opt | 2 + .../spider/bugfix/t/mdev_28218_mixed.sql | 1 + .../spider/bugfix/t/mdev_28218_mixed.test | 8 + .../mysql-test/spider/bugfix/t/mdev_28854.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_28854.test | 36 + .../mysql-test/spider/bugfix/t/mdev_28856.test | 163 + .../mysql-test/spider/bugfix/t/mdev_28996.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_28996.test | 40 + .../mysql-test/spider/bugfix/t/mdev_28998.test | 39 + .../mysql-test/spider/bugfix/t/mdev_29008.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29008.test | 39 + .../mysql-test/spider/bugfix/t/mdev_29011.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29011.test | 40 + .../mysql-test/spider/bugfix/t/mdev_29163.test | 36 + .../mysql-test/spider/bugfix/t/mdev_29352.test | 11 + .../mysql-test/spider/bugfix/t/mdev_29447.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29447.test | 37 + .../mysql-test/spider/bugfix/t/mdev_29484.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29484.test | 47 + .../mysql-test/spider/bugfix/t/mdev_29502.test | 67 + .../mysql-test/spider/bugfix/t/mdev_29562.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29562.test | 54 + .../mysql-test/spider/bugfix/t/mdev_29644.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29644.test | 56 + .../mysql-test/spider/bugfix/t/mdev_29653.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_29653.test | 37 + .../mysql-test/spider/bugfix/t/mdev_29904.test | 6 + .../mysql-test/spider/bugfix/t/mdev_30191.cnf | 3 + .../mysql-test/spider/bugfix/t/mdev_30191.test | 51 + .../mysql-test/spider/bugfix/t/mdev_30370.test | 11 + .../mysql-test/spider/bugfix/t/mdev_30392.test | 32 + .../mysql-test/spider/bugfix/t/mdev_30981.test | 24 + .../mysql-test/spider/bugfix/t/mdev_31117.test | 31 + .../mysql-test/spider/bugfix/t/mdev_31338.test | 23 + .../mysql-test/spider/bugfix/t/mdev_31524.test | 73 + .../mysql-test/spider/bugfix/t/mdev_31645.test | 35 + .../mysql-test/spider/bugfix/t/mdev_31996.test | 50 + .../mysql-test/spider/bugfix/t/mdev_32683.test | 14 + .../spider/bugfix/t/plugin_load_add_all.opt | 1 + .../spider/bugfix/t/plugin_load_add_all.test | 7 + .../spider/bugfix/t/plugin_load_add_spider.opt | 1 + .../spider/bugfix/t/plugin_load_add_spider.test | 7 + .../mysql-test/spider/bugfix/t/quick_mode_0.cnf | 4 + .../mysql-test/spider/bugfix/t/quick_mode_0.test | 158 + .../mysql-test/spider/bugfix/t/quick_mode_1.cnf | 4 + .../mysql-test/spider/bugfix/t/quick_mode_1.test | 158 + .../mysql-test/spider/bugfix/t/quick_mode_2.cnf | 4 + .../mysql-test/spider/bugfix/t/quick_mode_2.test | 158 + .../mysql-test/spider/bugfix/t/quick_mode_3.cnf | 4 + .../mysql-test/spider/bugfix/t/quick_mode_3.test | 159 + .../spider/bugfix/t/return_found_rows_insert.cnf | 3 + .../spider/bugfix/t/return_found_rows_insert.test | 104 + .../spider/bugfix/t/return_found_rows_update.cnf | 3 + .../spider/bugfix/t/return_found_rows_update.test | 80 + .../spider/bugfix/t/same_server_link.cnf | 2 + .../spider/bugfix/t/same_server_link.test | 55 + .../mysql-test/spider/bugfix/t/select_by_null.cnf | 3 + .../mysql-test/spider/bugfix/t/select_by_null.test | 74 + .../spider/bugfix/t/select_with_backquote.cnf | 3 + .../spider/bugfix/t/select_with_backquote.test | 76 + .../mysql-test/spider/bugfix/t/self_reference.cnf | 2 + .../mysql-test/spider/bugfix/t/self_reference.test | 45 + .../spider/bugfix/t/self_reference_multi.test | 30 + .../t/slave_transaction_retry_errors_5digit.cnf | 6 + .../t/slave_transaction_retry_errors_5digit.test | 9 + .../spider/bugfix/t/slave_trx_isolation.cnf | 4 + .../spider/bugfix/t/slave_trx_isolation.test | 99 + .../spider/bugfix/t/spider_table_sts.cnf | 2 + .../spider/bugfix/t/spider_table_sts.test | 46 + .../spider/mysql-test/spider/bugfix/t/sql_mode.inc | 68 + .../spider/bugfix/t/sql_mode_mariadb.cnf | 3 + .../spider/bugfix/t/sql_mode_mariadb.test | 5 + .../mysql-test/spider/bugfix/t/sql_mode_mysql.cnf | 3 + .../mysql-test/spider/bugfix/t/sql_mode_mysql.test | 5 + .../mysql-test/spider/bugfix/t/strict_group_by.cnf | 4 + .../spider/bugfix/t/strict_group_by.test | 109 + .../spider/bugfix/t/udf_mysql_func_early.cnf | 3 + .../spider/bugfix/t/udf_mysql_func_early.opt | 1 + .../spider/bugfix/t/udf_mysql_func_early.test | 48 + .../bugfix/t/udf_mysql_func_early_init_file.cnf | 3 + .../bugfix/t/udf_mysql_func_early_init_file.opt | 1 + .../bugfix/t/udf_mysql_func_early_init_file.sql | 1 + .../bugfix/t/udf_mysql_func_early_init_file.test | 4 + .../mysql-test/spider/bugfix/t/wait_timeout.cnf | 4 + .../mysql-test/spider/bugfix/t/wait_timeout.test | 109 + .../mysql-test/spider/bugfix/t/wrapper_mariadb.cnf | 3 + .../spider/bugfix/t/wrapper_mariadb.test | 73 + .../spider/mysql-test/spider/bugfix/t/xa_cmd.cnf | 3 + .../spider/mysql-test/spider/bugfix/t/xa_cmd.test | 71 + .../include/checksum_table_parallel_deinit.inc | 16 + .../checksum_table_parallel_extended_deinit.inc | 1 + .../checksum_table_parallel_extended_init.inc | 2 + .../include/checksum_table_parallel_init.inc | 53 + .../checksum_table_parallel_no_opt_deinit.inc | 1 + .../checksum_table_parallel_no_opt_init.inc | 2 + .../checksum_table_parallel_quick_deinit.inc | 1 + .../include/checksum_table_parallel_quick_init.inc | 2 + .../slave_transaction_retry_errors_deinit.inc | 10 + .../slave_transaction_retry_errors_init.inc | 10 + storage/spider/mysql-test/spider/feature/my.cnf | 2 + .../spider/mysql-test/spider/feature/my_1_1.cnf | 44 + .../spider/mysql-test/spider/feature/my_2_1.cnf | 56 + .../spider/mysql-test/spider/feature/my_2_2.cnf | 38 + .../spider/mysql-test/spider/feature/my_2_3.cnf | 8 + .../spider/mysql-test/spider/feature/my_3_1.cnf | 11 + .../spider/mysql-test/spider/feature/my_3_2.cnf | 9 + .../spider/mysql-test/spider/feature/my_3_3.cnf | 9 + .../spider/mysql-test/spider/feature/my_4_1.cnf | 9 + .../r/checksum_table_parallel_extended.result | 130 + .../r/checksum_table_parallel_no_opt.result | 128 + .../feature/r/checksum_table_parallel_quick.result | 128 + .../feature/r/engine_defined_attributes.result | 236 + .../r/slave_transaction_retry_errors.result | 22 + storage/spider/mysql-test/spider/feature/suite.opt | 1 + storage/spider/mysql-test/spider/feature/suite.pm | 11 + .../spider/feature/t/checksum_table_parallel.inc | 109 + .../feature/t/checksum_table_parallel_extended.cnf | 4 + .../t/checksum_table_parallel_extended.test | 5 + .../feature/t/checksum_table_parallel_no_opt.cnf | 4 + .../feature/t/checksum_table_parallel_no_opt.test | 5 + .../feature/t/checksum_table_parallel_quick.cnf | 4 + .../feature/t/checksum_table_parallel_quick.test | 5 + .../spider/feature/t/engine_defined_attributes.cnf | 4 + .../feature/t/engine_defined_attributes.test | 227 + .../feature/t/slave_transaction_retry_errors.cnf | 4 + .../feature/t/slave_transaction_retry_errors.test | 9 + .../checksum_table_with_quick_mode_3_deinit.inc | 14 + .../checksum_table_with_quick_mode_3_init.inc | 33 + .../mysql-test/spider/include/clean_up_spider.inc | 15 + .../mysql-test/spider/include/deinit_child2_1.inc | 3 + .../mysql-test/spider/include/deinit_child2_2.inc | 3 + .../mysql-test/spider/include/deinit_child2_3.inc | 3 + .../mysql-test/spider/include/deinit_child3_1.inc | 3 + .../mysql-test/spider/include/deinit_child3_2.inc | 3 + .../mysql-test/spider/include/deinit_child3_3.inc | 3 + .../mysql-test/spider/include/deinit_engine.inc | 4 + .../spider/include/deinit_handlersocket.inc | 1 + .../spider/include/deinit_innodb_plugin.inc | 1 + .../mysql-test/spider/include/deinit_master_1.inc | 1 + .../mysql-test/spider/include/deinit_slave1_1.inc | 0 .../mysql-test/spider/include/deinit_spider.inc | 8 + .../spider/include/direct_join_deinit.inc | 9 + .../mysql-test/spider/include/direct_join_init.inc | 53 + .../spider/include/direct_join_using_deinit.inc | 9 + .../spider/include/direct_join_using_init.inc | 13 + .../spider/include/direct_left_join_deinit.inc | 9 + .../spider/include/direct_left_join_init.inc | 13 + .../include/direct_left_join_nullable_deinit.inc | 9 + .../include/direct_left_join_nullable_init.inc | 13 + .../direct_left_right_join_nullable_deinit.inc | 9 + .../direct_left_right_join_nullable_init.inc | 13 + ...direct_left_right_left_join_nullable_deinit.inc | 9 + .../direct_left_right_left_join_nullable_init.inc | 13 + .../spider/include/direct_right_join_deinit.inc | 9 + .../spider/include/direct_right_join_init.inc | 13 + .../include/direct_right_join_nullable_deinit.inc | 9 + .../include/direct_right_join_nullable_init.inc | 13 + .../direct_right_left_join_nullable_deinit.inc | 9 + .../direct_right_left_join_nullable_init.inc | 13 + ...irect_right_left_right_join_nullable_deinit.inc | 9 + .../direct_right_left_right_join_nullable_init.inc | 13 + .../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 .../mysql-test/spider/include/ha_init_child2_1.inc | 8 + .../mysql-test/spider/include/ha_init_child2_2.inc | 4 + .../mysql-test/spider/include/ha_init_child2_3.inc | 4 + .../mysql-test/spider/include/ha_init_child3_1.inc | 140 + .../mysql-test/spider/include/ha_init_child3_2.inc | 140 + .../mysql-test/spider/include/ha_init_child3_3.inc | 140 + .../mysql-test/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 .../mysql-test/spider/include/hs_init_child2_1.inc | 24 + .../mysql-test/spider/include/hs_init_child2_2.inc | 12 + .../mysql-test/spider/include/hs_init_child2_3.inc | 0 .../mysql-test/spider/include/hs_init_master_1.inc | 12 + .../mysql-test/spider/include/init_child2_1.inc | 192 + .../mysql-test/spider/include/init_child2_2.inc | 83 + .../mysql-test/spider/include/init_child2_3.inc | 14 + .../mysql-test/spider/include/init_child3_1.inc | 3 + .../mysql-test/spider/include/init_child3_2.inc | 3 + .../mysql-test/spider/include/init_child3_3.inc | 3 + .../mysql-test/spider/include/init_engine.inc | 10 + .../mysql-test/spider/include/init_master_1.inc | 195 + .../mysql-test/spider/include/init_slave1_1.inc | 10 + .../mysql-test/spider/include/init_spider.inc | 191 + .../spider/include/partition_cond_push_deinit.inc | 20 + .../spider/include/partition_cond_push_init.inc | 58 + .../spider/include/partition_fulltext_deinit.inc | 23 + .../spider/include/partition_fulltext_init.inc | 72 + ...n_join_pushdown_for_single_partition_deinit.inc | 30 + ...ion_join_pushdown_for_single_partition_init.inc | 105 + .../spider/include/partition_mrr_deinit.inc | 23 + .../spider/include/partition_mrr_init.inc | 92 + .../spider/include/quick_mode_0_deinit.inc | 21 + .../spider/include/quick_mode_0_init.inc | 55 + .../spider/include/quick_mode_1_deinit.inc | 21 + .../spider/include/quick_mode_1_init.inc | 55 + .../spider/include/quick_mode_2_deinit.inc | 21 + .../spider/include/quick_mode_2_init.inc | 55 + .../spider/include/quick_mode_3_deinit.inc | 21 + .../spider/include/quick_mode_3_init.inc | 55 + .../spider/include/slave_trx_isolation_deinit.inc | 17 + .../spider/include/slave_trx_isolation_init.inc | 39 + storage/spider/mysql-test/spider/my.cnf | 177 + .../mysql-test/spider/r/auto_increment.result | 186 + .../spider/mysql-test/spider/r/basic_sql.result | 748 + .../mysql-test/spider/r/basic_sql_part.result | 141 + .../r/checksum_table_with_quick_mode_3.result | 104 + .../mysql-test/spider/r/direct_aggregate.result | 120 + .../spider/r/direct_aggregate_part.result | 121 + .../spider/mysql-test/spider/r/direct_join.result | 197 + .../mysql-test/spider/r/direct_join_using.result | 108 + .../mysql-test/spider/r/direct_left_join.result | 108 + .../spider/r/direct_left_join_nullable.result | 113 + .../r/direct_left_right_join_nullable.result | 113 + .../r/direct_left_right_left_join_nullable.result | 112 + .../mysql-test/spider/r/direct_right_join.result | 108 + .../spider/r/direct_right_join_nullable.result | 113 + .../r/direct_right_left_join_nullable.result | 112 + .../r/direct_right_left_right_join_nullable.result | 113 + .../mysql-test/spider/r/direct_update.result | 155 + .../mysql-test/spider/r/direct_update_part.result | 145 + .../mysql-test/spider/r/error_row_number.result | 45 + storage/spider/mysql-test/spider/r/function.result | 160 + storage/spider/mysql-test/spider/r/ha.result | 286 + storage/spider/mysql-test/spider/r/ha_part.result | 320 + .../mysql-test/spider/r/partition_cond_push.result | 168 + .../mysql-test/spider/r/partition_fulltext.result | 126 + ...ition_join_pushdown_for_single_partition.result | 130 + .../mysql-test/spider/r/partition_mrr.result | 267 + .../mysql-test/spider/r/pushdown_not_like.result | 63 + .../spider/mysql-test/spider/r/quick_mode_0.result | 508 + .../spider/mysql-test/spider/r/quick_mode_1.result | 508 + .../spider/mysql-test/spider/r/quick_mode_2.result | 508 + .../spider/mysql-test/spider/r/quick_mode_3.result | 508 + .../mysql-test/spider/r/show_system_tables.result | 37 + .../mysql-test/spider/r/slave_trx_isolation.result | 105 + .../mysql-test/spider/r/spider3_fixes.result | 232 + .../mysql-test/spider/r/spider3_fixes_part.result | 222 + .../spider/mysql-test/spider/r/spider_fixes.result | 623 + .../mysql-test/spider/r/spider_fixes_part.result | 351 + .../spider/r/spider_wrapper_protocols.result | 22 + .../spider/mysql-test/spider/r/timestamp.result | 431 + .../spider/mysql-test/spider/r/udf_pushdown.result | 218 + .../spider/r/variable_deprecation.result | 221 + storage/spider/mysql-test/spider/r/vp_fixes.result | 93 + .../include/direct_join_by_pkey_key_deinit.inc | 12 + .../e1121/include/direct_join_by_pkey_key_init.inc | 36 + .../include/direct_join_by_pkey_pkey_deinit.inc | 12 + .../include/direct_join_by_pkey_pkey_init.inc | 36 + .../e1121/include/load_data_ddi0_deinit.inc | 3 + .../e1121/include/load_data_ddi0_init.inc | 4 + .../e1121/include/load_data_ddi1_deinit.inc | 3 + .../e1121/include/load_data_ddi1_init.inc | 4 + .../regression/e1121/include/load_data_deinit.inc | 11 + .../regression/e1121/include/load_data_init.inc | 25 + .../mysql-test/spider/regression/e1121/my.cnf | 3 + .../mysql-test/spider/regression/e1121/my_1_1.cnf | 44 + .../mysql-test/spider/regression/e1121/my_2_1.cnf | 56 + .../e1121/r/direct_join_by_pkey_key.result | 94 + .../e1121/r/direct_join_by_pkey_pkey.result | 94 + .../regression/e1121/r/load_data_ddi0.result | 75 + .../regression/e1121/r/load_data_ddi1.result | 75 + .../e1121/r/load_data_ignore_ddi0.result | 95 + .../e1121/r/load_data_ignore_ddi1.result | 75 + .../regression/e1121/r/load_data_local_ddi0.result | 84 + .../regression/e1121/r/load_data_local_ddi1.result | 75 + .../e1121/r/load_data_local_ignore_ddi0.result | 95 + .../e1121/r/load_data_local_ignore_ddi1.result | 75 + .../e1121/r/load_data_local_replace_ddi0.result | 104 + .../e1121/r/load_data_local_replace_ddi1.result | 75 + .../e1121/r/load_data_replace_ddi0.result | 104 + .../e1121/r/load_data_replace_ddi1.result | 75 + .../mysql-test/spider/regression/e1121/suite.opt | 1 + .../mysql-test/spider/regression/e1121/suite.pm | 11 + .../e1121/t/direct_join_by_pkey_key.test | 88 + .../e1121/t/direct_join_by_pkey_pkey.test | 88 + .../spider/regression/e1121/t/load_data.inc | 82 + .../spider/regression/e1121/t/load_data_ddi0.test | 8 + .../spider/regression/e1121/t/load_data_ddi1.test | 8 + .../regression/e1121/t/load_data_ignore_ddi0.test | 8 + .../regression/e1121/t/load_data_ignore_ddi1.test | 8 + .../regression/e1121/t/load_data_local_ddi0.test | 8 + .../regression/e1121/t/load_data_local_ddi1.test | 8 + .../e1121/t/load_data_local_ignore_ddi0.test | 8 + .../e1121/t/load_data_local_ignore_ddi1.test | 8 + .../e1121/t/load_data_local_replace_ddi0.test | 8 + .../e1121/t/load_data_local_replace_ddi1.test | 8 + .../regression/e1121/t/load_data_replace_ddi0.test | 8 + .../regression/e1121/t/load_data_replace_ddi1.test | 8 + .../include/group_by_order_by_limit_ok_deinit.inc | 14 + .../include/group_by_order_by_limit_ok_init.inc | 54 + .../e112122/include/load_data_part_ddi0_deinit.inc | 3 + .../e112122/include/load_data_part_ddi0_init.inc | 4 + .../e112122/include/load_data_part_ddi1_deinit.inc | 3 + .../e112122/include/load_data_part_ddi1_init.inc | 4 + .../e112122/include/load_data_part_deinit.inc | 14 + .../e112122/include/load_data_part_init.inc | 52 + .../mysql-test/spider/regression/e112122/my.cnf | 4 + .../spider/regression/e112122/my_1_1.cnf | 44 + .../spider/regression/e112122/my_2_1.cnf | 56 + .../spider/regression/e112122/my_2_2.cnf | 38 + .../e112122/r/group_by_order_by_limit_ok.result | 126 + .../e112122/r/load_data_part_ddi0.result | 95 + .../e112122/r/load_data_part_ddi1.result | 95 + .../e112122/r/load_data_part_ignore_ddi0.result | 114 + .../e112122/r/load_data_part_ignore_ddi1.result | 95 + .../e112122/r/load_data_part_local_ddi0.result | 103 + .../e112122/r/load_data_part_local_ddi1.result | 95 + .../r/load_data_part_local_ignore_ddi0.result | 114 + .../r/load_data_part_local_ignore_ddi1.result | 95 + .../r/load_data_part_local_replace_ddi0.result | 123 + .../r/load_data_part_local_replace_ddi1.result | 95 + .../e112122/r/load_data_part_replace_ddi0.result | 123 + .../e112122/r/load_data_part_replace_ddi1.result | 95 + .../mysql-test/spider/regression/e112122/suite.opt | 1 + .../mysql-test/spider/regression/e112122/suite.pm | 11 + .../e112122/t/group_by_order_by_limit_ok.test | 104 + .../spider/regression/e112122/t/load_data_part.inc | 106 + .../regression/e112122/t/load_data_part_ddi0.test | 8 + .../regression/e112122/t/load_data_part_ddi1.test | 8 + .../e112122/t/load_data_part_ignore_ddi0.test | 8 + .../e112122/t/load_data_part_ignore_ddi1.test | 8 + .../e112122/t/load_data_part_local_ddi0.test | 8 + .../e112122/t/load_data_part_local_ddi1.test | 8 + .../t/load_data_part_local_ignore_ddi0.test | 8 + .../t/load_data_part_local_ignore_ddi1.test | 8 + .../t/load_data_part_local_replace_ddi0.test | 8 + .../t/load_data_part_local_replace_ddi1.test | 8 + .../e112122/t/load_data_part_replace_ddi0.test | 8 + .../e112122/t/load_data_part_replace_ddi1.test | 8 + storage/spider/mysql-test/spider/suite.opt | 1 + storage/spider/mysql-test/spider/suite.pm | 11 + .../spider/mysql-test/spider/t/auto_increment.test | 187 + .../mysql-test/spider/t/auto_increment_deinit.inc | 13 + .../mysql-test/spider/t/auto_increment_init.inc | 38 + storage/spider/mysql-test/spider/t/basic_sql.test | 2714 ++++ .../spider/mysql-test/spider/t/basic_sql_part.test | 571 + .../spider/t/checksum_table_with_quick_mode_3.test | 128 + .../mysql-test/spider/t/connect_child2_1.inc | 2 + .../mysql-test/spider/t/connect_child2_2.inc | 2 + .../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 | 191 + .../mysql-test/spider/t/direct_aggregate_part.test | 211 + .../spider/mysql-test/spider/t/direct_join.test | 347 + .../mysql-test/spider/t/direct_join_using.test | 199 + .../mysql-test/spider/t/direct_left_join.test | 199 + .../spider/t/direct_left_join_nullable.test | 214 + .../spider/t/direct_left_right_join_nullable.test | 214 + .../t/direct_left_right_left_join_nullable.test | 214 + .../mysql-test/spider/t/direct_right_join.test | 199 + .../spider/t/direct_right_join_nullable.test | 214 + .../spider/t/direct_right_left_join_nullable.test | 214 + .../t/direct_right_left_right_join_nullable.test | 214 + .../spider/mysql-test/spider/t/direct_update.test | 198 + .../mysql-test/spider/t/direct_update_part.test | 211 + .../mysql-test/spider/t/error_row_number.test | 37 + storage/spider/mysql-test/spider/t/function.test | 253 + storage/spider/mysql-test/spider/t/ha.test | 882 + storage/spider/mysql-test/spider/t/ha_part.test | 1024 ++ .../spider/mysql-test/spider/t/ha_test_deinit.inc | 30 + .../spider/mysql-test/spider/t/ha_test_init.inc | 30 + storage/spider/mysql-test/spider/t/have_engine.inc | 7 + storage/spider/mysql-test/spider/t/have_func.inc | 5 + .../spider/mysql-test/spider/t/have_partition.inc | 7 + storage/spider/mysql-test/spider/t/have_plugin.inc | 5 + .../spider/mysql-test/spider/t/have_trigger.inc | 2 + .../spider/mysql-test/spider/t/hs_test_deinit.inc | 17 + .../spider/mysql-test/spider/t/hs_test_init.inc | 17 + .../mysql-test/spider/t/partition_cond_push.test | 221 + .../mysql-test/spider/t/partition_fulltext.test | 225 + ...rtition_join_pushdown_for_single_partition.test | 224 + .../spider/mysql-test/spider/t/partition_mrr.test | 239 + .../mysql-test/spider/t/pushdown_not_like.test | 139 + .../spider/mysql-test/spider/t/quick_mode_0.test | 300 + .../spider/mysql-test/spider/t/quick_mode_1.test | 300 + .../spider/mysql-test/spider/t/quick_mode_2.test | 300 + .../spider/mysql-test/spider/t/quick_mode_3.test | 300 + .../mysql-test/spider/t/show_system_tables.test | 26 + .../mysql-test/spider/t/slave_test_deinit.inc | 6 + .../spider/mysql-test/spider/t/slave_test_init.inc | 44 + .../mysql-test/spider/t/slave_trx_isolation.test | 151 + .../spider/mysql-test/spider/t/spider3_fixes.test | 304 + .../mysql-test/spider/t/spider3_fixes_part.test | 347 + .../spider/mysql-test/spider/t/spider_fixes.test | 1442 ++ .../mysql-test/spider/t/spider_fixes_part.test | 901 ++ .../spider/t/spider_wrapper_protocols.test | 16 + storage/spider/mysql-test/spider/t/test_deinit.inc | 39 + storage/spider/mysql-test/spider/t/test_init.inc | 74 + storage/spider/mysql-test/spider/t/timestamp.test | 542 + .../mysql-test/spider/t/timestamp_deinit.inc | 13 + .../spider/mysql-test/spider/t/timestamp_init.inc | 62 + .../spider/mysql-test/spider/t/udf_pushdown.inc | 50 + .../spider/mysql-test/spider/t/udf_pushdown.test | 141 + .../mysql-test/spider/t/variable_deprecation.test | 137 + storage/spider/mysql-test/spider/t/vp_fixes.test | 335 + storage/spider/spd_conn.cc | 4119 +++++ storage/spider/spd_conn.h | 404 + storage/spider/spd_copy_tables.cc | 1220 ++ storage/spider/spd_copy_tables.h | 53 + storage/spider/spd_db_conn.cc | 9856 +++++++++++ storage/spider/spd_db_conn.h | 1143 ++ storage/spider/spd_db_include.cc | 236 + storage/spider/spd_db_include.h | 1822 +++ storage/spider/spd_db_mysql.cc | 16182 +++++++++++++++++++ storage/spider/spd_db_mysql.h | 1683 ++ storage/spider/spd_direct_sql.cc | 1817 +++ storage/spider/spd_direct_sql.h | 65 + storage/spider/spd_environ.h | 29 + storage/spider/spd_err.h | 141 + storage/spider/spd_group_by_handler.cc | 2065 +++ storage/spider/spd_group_by_handler.h | 42 + storage/spider/spd_i_s.cc | 265 + storage/spider/spd_include.h | 1265 ++ storage/spider/spd_init_query.h | 744 + storage/spider/spd_malloc.cc | 1306 ++ storage/spider/spd_malloc.h | 80 + storage/spider/spd_param.cc | 2538 +++ storage/spider/spd_param.h | 370 + storage/spider/spd_ping_table.cc | 1825 +++ storage/spider/spd_ping_table.h | 119 + storage/spider/spd_sys_table.cc | 3776 +++++ storage/spider/spd_sys_table.h | 644 + storage/spider/spd_table.cc | 9384 +++++++++++ storage/spider/spd_table.h | 519 + storage/spider/spd_trx.cc | 3863 +++++ storage/spider/spd_trx.h | 268 + storage/spider/spd_udf.cc | 153 + storage/spider/spd_udf.def | 20 + storage/spider/spd_udf.h | 77 + storage/spider/spider.cnf | 7 + 793 files changed, 141662 insertions(+) create mode 100644 storage/spider/CMakeLists.txt create mode 100644 storage/spider/ha_spider.cc create mode 100644 storage/spider/ha_spider.h 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/basic_sql_part.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_aggregate_part.result create mode 100644 storage/spider/mysql-test/spider/bg/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/bg/r/direct_update_part.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/ha_part.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/bg/r/spider_fixes_part.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/basic_sql_part.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_aggregate_part.test create mode 100644 storage/spider/mysql-test/spider/bg/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/bg/t/direct_update_part.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_part.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/spider3_fixes_part.test create mode 100644 storage/spider/mysql-test/spider/bg/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/bg/t/spider_fixes_part.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/bugfix/disabled.def create mode 100644 storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/insert_select_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/insert_select_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_19866_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_19866_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_20100_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_20100_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_20502_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_20502_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_21884_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_21884_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22265_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_22265_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24020_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24020_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24517_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24517_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24523_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/mdev_24523_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/same_server_link_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/same_server_link_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/select_by_null_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/select_by_null_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/self_reference_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/self_reference_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/strict_group_by_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/strict_group_by_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/xa_cmd_deinit.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/include/xa_cmd_init.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/my.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_1_1.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_2_1.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_2_2.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_2_3.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_3_1.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_3_2.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_3_3.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/my_4_1.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/cp932_column.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/ddl_log.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_comma_pwd.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_tmp_table.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/index.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/insert_select.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_20100.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_20502.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_21884.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_22265.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_22979.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_24020.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_24343.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_24517.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_24523.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_25684.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26151.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26158.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26247.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26539.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26541.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26544.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27184.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27233.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27239.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27240.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28218.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28218_init_file.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28218_mixed.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28854.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28996.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28998.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29008.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29011.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29163.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29447.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29484.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29502.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29562.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29644.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29653.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_30191.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_30370.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_30392.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_30981.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_31117.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_31338.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_31524.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_31645.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_31996.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_32683.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_spider.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/quick_mode_0.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/quick_mode_1.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/quick_mode_2.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/quick_mode_3.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/return_found_rows_insert.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/return_found_rows_update.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/same_server_link.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/select_by_null.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/select_with_backquote.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/self_reference.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/self_reference_multi.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/spider_table_sts.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/sql_mode_mariadb.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/sql_mode_mysql.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/strict_group_by.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early.result create mode 120000 storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/wait_timeout.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/wrapper_mariadb.result create mode 100644 storage/spider/mysql-test/spider/bugfix/r/xa_cmd.result create mode 100644 storage/spider/mysql-test/spider/bugfix/suite.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/suite.pm create mode 100644 storage/spider/mysql-test/spider/bugfix/t/checksum_table_with_quick_mode_3.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/checksum_table_with_quick_mode_3.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/cp932_column.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/cp932_column.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/ddl_log.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_default.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_default.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_mariadb.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_mariadb.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_mysql.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/delete_with_float_column_mysql.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/direct_sql_with_comma_pwd.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/direct_sql_with_comma_pwd.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/direct_sql_with_tmp_table.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/direct_sql_with_tmp_table.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/index.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/insert_select.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/insert_select.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_20100.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_20100.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_20502.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_20502.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_21884.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_21884.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22265.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22265.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_22979.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24020.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24020.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24343.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24343.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24517.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24517.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24523.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24523.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25684.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_25684.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26151.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26158.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26158.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26247.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26247.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26539.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26539.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26541.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26544.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26544.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27172.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27172.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27184.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27184.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27233.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27233.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27239.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27239.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27240.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27240.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.sql create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.sql create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28854.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28854.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28996.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28996.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28998.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29008.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29008.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29011.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29011.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29163.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29447.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29447.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29484.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29484.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29562.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29562.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29644.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29644.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29653.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29653.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30191.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30191.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30370.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30392.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30981.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_31117.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_31338.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_31524.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_31645.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_31996.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_32683.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_spider.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_spider.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_0.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_0.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_1.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_1.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_2.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_2.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_3.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/quick_mode_3.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/return_found_rows_insert.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/return_found_rows_update.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/same_server_link.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/same_server_link.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/select_by_null.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/select_by_null.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/select_with_backquote.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/select_with_backquote.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/self_reference.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/self_reference.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/slave_transaction_retry_errors_5digit.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/slave_transaction_retry_errors_5digit.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/slave_trx_isolation.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/slave_trx_isolation.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/spider_table_sts.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/sql_mode.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/t/sql_mode_mariadb.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/sql_mode_mariadb.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/sql_mode_mysql.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/sql_mode_mysql.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/strict_group_by.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/strict_group_by.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early_init_file.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early_init_file.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early_init_file.sql create mode 100644 storage/spider/mysql-test/spider/bugfix/t/udf_mysql_func_early_init_file.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/wait_timeout.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/wait_timeout.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/wrapper_mariadb.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/wrapper_mariadb.test create mode 100644 storage/spider/mysql-test/spider/bugfix/t/xa_cmd.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/xa_cmd.test create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_deinit.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_deinit.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_extended_init.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_init.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_deinit.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_no_opt_init.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_deinit.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/checksum_table_parallel_quick_init.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/slave_transaction_retry_errors_deinit.inc create mode 100644 storage/spider/mysql-test/spider/feature/include/slave_transaction_retry_errors_init.inc create mode 100644 storage/spider/mysql-test/spider/feature/my.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_1_1.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_2_1.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_2_2.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_2_3.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_3_1.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_3_2.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_3_3.cnf create mode 100644 storage/spider/mysql-test/spider/feature/my_4_1.cnf create mode 100644 storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_extended.result create mode 100644 storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_no_opt.result create mode 100644 storage/spider/mysql-test/spider/feature/r/checksum_table_parallel_quick.result create mode 100644 storage/spider/mysql-test/spider/feature/r/engine_defined_attributes.result create mode 100644 storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result create mode 100644 storage/spider/mysql-test/spider/feature/suite.opt create mode 100644 storage/spider/mysql-test/spider/feature/suite.pm create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel.inc create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.cnf create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_extended.test create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.cnf create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_no_opt.test create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.cnf create mode 100644 storage/spider/mysql-test/spider/feature/t/checksum_table_parallel_quick.test create mode 100644 storage/spider/mysql-test/spider/feature/t/engine_defined_attributes.cnf create mode 100644 storage/spider/mysql-test/spider/feature/t/engine_defined_attributes.test create mode 100644 storage/spider/mysql-test/spider/feature/t/slave_transaction_retry_errors.cnf create mode 100644 storage/spider/mysql-test/spider/feature/t/slave_transaction_retry_errors.test create mode 100644 storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/checksum_table_with_quick_mode_3_init.inc create mode 100644 storage/spider/mysql-test/spider/include/clean_up_spider.inc 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/direct_join_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_join_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_join_using_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_join_using_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_join_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_join_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_join_nullable_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_right_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_right_join_nullable_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_right_left_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_left_right_left_join_nullable_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_join_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_join_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_join_nullable_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_left_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_left_join_nullable_init.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_left_right_join_nullable_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/direct_right_left_right_join_nullable_init.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/include/partition_cond_push_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_cond_push_init.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_fulltext_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_fulltext_init.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_join_pushdown_for_single_partition_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_join_pushdown_for_single_partition_init.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_mrr_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/partition_mrr_init.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_0_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_0_init.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_1_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_1_init.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_2_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_2_init.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_3_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/quick_mode_3_init.inc create mode 100644 storage/spider/mysql-test/spider/include/slave_trx_isolation_deinit.inc create mode 100644 storage/spider/mysql-test/spider/include/slave_trx_isolation_init.inc create mode 100644 storage/spider/mysql-test/spider/my.cnf create mode 100644 storage/spider/mysql-test/spider/r/auto_increment.result create mode 100644 storage/spider/mysql-test/spider/r/basic_sql.result create mode 100644 storage/spider/mysql-test/spider/r/basic_sql_part.result create mode 100644 storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result create mode 100644 storage/spider/mysql-test/spider/r/direct_aggregate.result create mode 100644 storage/spider/mysql-test/spider/r/direct_aggregate_part.result create mode 100644 storage/spider/mysql-test/spider/r/direct_join.result create mode 100644 storage/spider/mysql-test/spider/r/direct_join_using.result create mode 100644 storage/spider/mysql-test/spider/r/direct_left_join.result create mode 100644 storage/spider/mysql-test/spider/r/direct_left_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_left_right_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_left_right_left_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_right_join.result create mode 100644 storage/spider/mysql-test/spider/r/direct_right_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_right_left_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_right_left_right_join_nullable.result create mode 100644 storage/spider/mysql-test/spider/r/direct_update.result create mode 100644 storage/spider/mysql-test/spider/r/direct_update_part.result create mode 100644 storage/spider/mysql-test/spider/r/error_row_number.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/ha_part.result create mode 100644 storage/spider/mysql-test/spider/r/partition_cond_push.result create mode 100644 storage/spider/mysql-test/spider/r/partition_fulltext.result create mode 100644 storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result create mode 100644 storage/spider/mysql-test/spider/r/partition_mrr.result create mode 100644 storage/spider/mysql-test/spider/r/pushdown_not_like.result create mode 100644 storage/spider/mysql-test/spider/r/quick_mode_0.result create mode 100644 storage/spider/mysql-test/spider/r/quick_mode_1.result create mode 100644 storage/spider/mysql-test/spider/r/quick_mode_2.result create mode 100644 storage/spider/mysql-test/spider/r/quick_mode_3.result create mode 100644 storage/spider/mysql-test/spider/r/show_system_tables.result create mode 100644 storage/spider/mysql-test/spider/r/slave_trx_isolation.result create mode 100644 storage/spider/mysql-test/spider/r/spider3_fixes.result create mode 100644 storage/spider/mysql-test/spider/r/spider3_fixes_part.result create mode 100644 storage/spider/mysql-test/spider/r/spider_fixes.result create mode 100644 storage/spider/mysql-test/spider/r/spider_fixes_part.result create mode 100644 storage/spider/mysql-test/spider/r/spider_wrapper_protocols.result create mode 100644 storage/spider/mysql-test/spider/r/timestamp.result create mode 100644 storage/spider/mysql-test/spider/r/udf_pushdown.result create mode 100644 storage/spider/mysql-test/spider/r/variable_deprecation.result create mode 100644 storage/spider/mysql-test/spider/r/vp_fixes.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/include/load_data_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/my.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e1121/my_1_1.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e1121/my_2_1.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_key.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_pkey.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e1121/suite.opt create mode 100644 storage/spider/mysql-test/spider/regression/e1121/suite.pm create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_key.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_pkey.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data.inc create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_deinit.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_init.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/my.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi0.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi1.result create mode 100644 storage/spider/mysql-test/spider/regression/e112122/suite.opt create mode 100644 storage/spider/mysql-test/spider/regression/e112122/suite.pm create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part.inc create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi1.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi0.test create mode 100644 storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi1.test 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/auto_increment.test create mode 100644 storage/spider/mysql-test/spider/t/auto_increment_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/auto_increment_init.inc create mode 100644 storage/spider/mysql-test/spider/t/basic_sql.test create mode 100644 storage/spider/mysql-test/spider/t/basic_sql_part.test create mode 100644 storage/spider/mysql-test/spider/t/checksum_table_with_quick_mode_3.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_aggregate_part.test create mode 100644 storage/spider/mysql-test/spider/t/direct_join.test create mode 100644 storage/spider/mysql-test/spider/t/direct_join_using.test create mode 100644 storage/spider/mysql-test/spider/t/direct_left_join.test create mode 100644 storage/spider/mysql-test/spider/t/direct_left_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_left_right_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_left_right_left_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_right_join.test create mode 100644 storage/spider/mysql-test/spider/t/direct_right_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_right_left_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_right_left_right_join_nullable.test create mode 100644 storage/spider/mysql-test/spider/t/direct_update.test create mode 100644 storage/spider/mysql-test/spider/t/direct_update_part.test create mode 100644 storage/spider/mysql-test/spider/t/error_row_number.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_part.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/partition_cond_push.test create mode 100644 storage/spider/mysql-test/spider/t/partition_fulltext.test create mode 100644 storage/spider/mysql-test/spider/t/partition_join_pushdown_for_single_partition.test create mode 100644 storage/spider/mysql-test/spider/t/partition_mrr.test create mode 100644 storage/spider/mysql-test/spider/t/pushdown_not_like.test create mode 100644 storage/spider/mysql-test/spider/t/quick_mode_0.test create mode 100644 storage/spider/mysql-test/spider/t/quick_mode_1.test create mode 100644 storage/spider/mysql-test/spider/t/quick_mode_2.test create mode 100644 storage/spider/mysql-test/spider/t/quick_mode_3.test create mode 100644 storage/spider/mysql-test/spider/t/show_system_tables.test 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/slave_trx_isolation.test create mode 100644 storage/spider/mysql-test/spider/t/spider3_fixes.test create mode 100644 storage/spider/mysql-test/spider/t/spider3_fixes_part.test create mode 100644 storage/spider/mysql-test/spider/t/spider_fixes.test create mode 100644 storage/spider/mysql-test/spider/t/spider_fixes_part.test create mode 100644 storage/spider/mysql-test/spider/t/spider_wrapper_protocols.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/timestamp.test create mode 100644 storage/spider/mysql-test/spider/t/timestamp_deinit.inc create mode 100644 storage/spider/mysql-test/spider/t/timestamp_init.inc create mode 100644 storage/spider/mysql-test/spider/t/udf_pushdown.inc create mode 100644 storage/spider/mysql-test/spider/t/udf_pushdown.test create mode 100644 storage/spider/mysql-test/spider/t/variable_deprecation.test create mode 100644 storage/spider/mysql-test/spider/t/vp_fixes.test 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_include.cc 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_direct_sql.cc create mode 100644 storage/spider/spd_direct_sql.h create mode 100644 storage/spider/spd_environ.h create mode 100644 storage/spider/spd_err.h create mode 100644 storage/spider/spd_group_by_handler.cc create mode 100644 storage/spider/spd_group_by_handler.h create mode 100644 storage/spider/spd_i_s.cc create mode 100644 storage/spider/spd_include.h create mode 100644 storage/spider/spd_init_query.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 create mode 100644 storage/spider/spider.cnf (limited to 'storage/spider') diff --git a/storage/spider/CMakeLists.txt b/storage/spider/CMakeLists.txt new file mode 100644 index 00000000..bc1387db --- /dev/null +++ b/storage/spider/CMakeLists.txt @@ -0,0 +1,43 @@ +IF(HAVE_WVLA) + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-vla") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-vla") +ENDIF() + +IF(MSVC) + # Temporarily disable "conversion from size_t .." + IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") + ENDIF() +ENDIF() + +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_group_by_handler.cc spd_db_include.cc +) + +IF(PLUGIN_PARTITION MATCHES "^NO$") + MESSAGE(STATUS "Spider is skipped because partitioning is disabled") +ELSE() + IF(DEB) + SET(extra_options COMPONENT spider-engine) + ELSE() + SET(extra_options CONFIG spider.cnf) + ENDIF() + + MYSQL_ADD_PLUGIN(spider ${SPIDER_SOURCES} ${extra_options} + STORAGE_ENGINE MODULE_ONLY) + IF(NOT TARGET spider) + RETURN() + ENDIF() +ENDIF() + +IF(MSVC AND (TARGET spider)) + IF (CMAKE_BUILD_TYPE STREQUAL "Debug") + ADD_CUSTOM_COMMAND(TARGET spider + POST_BUILD + COMMAND if not exist ..\\..\\sql\\lib mkdir ..\\..\\sql\\lib\\plugin + COMMAND copy Debug\\ha_spider.dll ..\\..\\sql\\lib\\plugin\\ha_spider.dll) + ENDIF() +ENDIF() diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc new file mode 100644 index 00000000..312f94a8 --- /dev/null +++ b/storage/spider/ha_spider.cc @@ -0,0 +1,12186 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019-2023 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#ifdef USE_PRAGMA_IMPLEMENTATION +#pragma implementation +#endif + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "key.h" +#include "sql_select.h" +#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" + +#define SPIDER_CAN_BG_SEARCH (1LL << 37) +#define SPIDER_CAN_BG_INSERT (1LL << 38) +#define SPIDER_CAN_BG_UPDATE (1LL << 39) + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern HASH spider_open_tables; +extern pthread_mutex_t spider_lgtm_tblhnd_share_mutex; + +/* UTC time zone for timestamp columns */ +extern Time_zone *UTC; + +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; + conns = NULL; + need_mons = NULL; + blob_buff = NULL; + conn_keys = NULL; + spider_thread_id = 0; + trx_conn_adjustment = 0; + search_link_query_id = 0; + partition_handler = NULL; + multi_range_keys = NULL; + mrr_key_buff = NULL; + append_tblnm_alias = NULL; + use_index_merge = FALSE; + is_clone = 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; + error_mode = 0; + use_spatial_index = FALSE; + use_fields = FALSE; + dml_inited = FALSE; + use_pre_call = FALSE; + use_pre_action = FALSE; + do_direct_update = FALSE; + prev_index_rnd_init = SPD_NONE; + direct_aggregate_item_first = NULL; + result_link_idx = 0; + result_list.sqls = NULL; + result_list.insert_sqls = NULL; + result_list.update_sqls = NULL; + result_list.tmp_sqls = NULL; + result_list.tmp_tables_created = FALSE; + result_list.bgs_working = FALSE; + result_list.direct_order_limit = FALSE; + result_list.direct_limit_offset = FALSE; + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + result_list.tmp_pos_row_first = NULL; + result_list.direct_aggregate = FALSE; + result_list.snap_direct_aggregate = FALSE; + result_list.direct_distinct = FALSE; + result_list.casual_read = NULL; + result_list.use_both_key = FALSE; + result_list.in_cmp_ref = FALSE; + 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; + conns = NULL; + need_mons = NULL; + blob_buff = NULL; + conn_keys = NULL; + spider_thread_id = 0; + trx_conn_adjustment = 0; + search_link_query_id = 0; + partition_handler = NULL; + multi_range_keys = NULL; + mrr_key_buff = NULL; + append_tblnm_alias = NULL; + use_index_merge = FALSE; + is_clone = 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; + error_mode = 0; + use_spatial_index = FALSE; + use_fields = FALSE; + dml_inited = FALSE; + use_pre_call = FALSE; + use_pre_action = FALSE; + do_direct_update = FALSE; + prev_index_rnd_init = SPD_NONE; + direct_aggregate_item_first = NULL; + result_link_idx = 0; + result_list.sqls = NULL; + result_list.insert_sqls = NULL; + result_list.update_sqls = NULL; + result_list.tmp_sqls = NULL; + result_list.tmp_tables_created = FALSE; + result_list.bgs_working = FALSE; + result_list.direct_order_limit = FALSE; + result_list.direct_limit_offset = FALSE; + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + result_list.tmp_pos_row_first = NULL; + result_list.direct_aggregate = FALSE; + result_list.snap_direct_aggregate = FALSE; + result_list.direct_distinct = FALSE; + result_list.casual_read = NULL; + result_list.use_both_key = FALSE; + result_list.in_cmp_ref = FALSE; + 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)); + partition_handler = NULL; + if (wide_handler_owner) + { + spider_free(spider_current_trx, wide_handler, MYF(0)); + } + wide_handler = NULL; + 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); + use_index_merge = TRUE; + + 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; + ha_spider *spider, *owner; + bool wide_handler_alloc = FALSE; + SPIDER_WIDE_SHARE *wide_share; + uint part_num; + bool partition_handler_alloc = FALSE; + ha_spider **wide_handler_handlers = NULL; + ha_partition *clone_source; + DBUG_ENTER("ha_spider::open"); + DBUG_PRINT("info",("spider this=%p", this)); + + dup_key_idx = (uint) -1; + conn_kinds = SPIDER_CONN_KIND_MYSQL; + table->file->get_no_parts("", &part_num); + if (part_num) + { + wide_handler_handlers = + (ha_spider **) ((ha_partition *) table->file)->get_child_handlers(); + spider = wide_handler_handlers[0]; + owner = wide_handler_handlers[part_num - 1]; + clone_source = ((ha_partition *) table->file)->get_clone_source(); + if (clone_source) + { + is_clone = TRUE; + } + } else { + spider = this; + owner = this; + clone_source = NULL; + } + if (!spider->wide_handler) + { + uchar *searched_bitmap; + uchar *ft_discard_bitmap; + uchar *position_bitmap; + uchar *idx_read_bitmap; + uchar *idx_write_bitmap; + uchar *rnd_read_bitmap; + uchar *rnd_write_bitmap; + if (!(wide_handler = (SPIDER_WIDE_HANDLER *) + spider_bulk_malloc(spider_current_trx, 16, MYF(MY_WME | MY_ZEROFILL), + &wide_handler, sizeof(SPIDER_WIDE_HANDLER), + &searched_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &ft_discard_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &position_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &idx_read_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &idx_write_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &rnd_read_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &rnd_write_bitmap, + (uint) sizeof(uchar) * no_bytes_in_map(table->read_set), + &partition_handler, + (uint) sizeof(SPIDER_PARTITION_HANDLER), + NullS) + ) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error_wide_handler_alloc; + } + spider->wide_handler = wide_handler; + owner->wide_handler = wide_handler; + wide_handler->searched_bitmap = searched_bitmap; + wide_handler->ft_discard_bitmap = ft_discard_bitmap; + wide_handler->position_bitmap = position_bitmap; + wide_handler->idx_read_bitmap = idx_read_bitmap; + wide_handler->idx_write_bitmap = idx_write_bitmap; + wide_handler->rnd_read_bitmap = rnd_read_bitmap; + wide_handler->rnd_write_bitmap = rnd_write_bitmap; + wide_handler->partition_handler = partition_handler; + wide_handler->owner = owner; + if (table_share->tmp_table == NO_TMP_TABLE) + wide_handler->top_share = table->s; + owner->wide_handler_owner = TRUE; + memset(wide_handler->ft_discard_bitmap, 0xFF, + no_bytes_in_map(table->read_set)); + memset(wide_handler->searched_bitmap, 0, + no_bytes_in_map(table->read_set)); + wide_handler_alloc = TRUE; + + if (!share && !spider_get_share(name, table, thd, this, &error_num)) + goto error_get_share; + + wide_share = share->wide_share; + + DBUG_PRINT("info",("spider create partition_handler")); + DBUG_PRINT("info",("spider table=%p", table)); + partition_handler->table = table; + partition_handler->no_parts = part_num; + partition_handler->owner = owner; + partition_handler->parallel_search_query_id = 0; + spider->partition_handler = partition_handler; + owner->partition_handler = partition_handler; + partition_handler->handlers = wide_handler_handlers; + partition_handler_alloc = TRUE; + } else { + wide_handler = spider->wide_handler; + partition_handler = wide_handler->partition_handler; + + if (!share && !spider_get_share(name, table, thd, this, &error_num)) + goto error_get_share; + + wide_share= share->wide_share; + } + if (wide_handler_alloc) + { + thr_lock_data_init(&wide_share->lock, &wide_handler->lock, NULL); + } + + 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()); + } + } + + if (is_clone) + { + if (part_num) + { + for (roop_count = 0; roop_count < (int) part_num; roop_count++) + { + if (partition_handler->handlers[roop_count]->share == share) + { + pt_clone_source_handler = + partition_handler->handlers[roop_count]; + break; + } + } + } + + wide_handler->external_lock_type = + pt_clone_source_handler->wide_handler->external_lock_type; + + if (wide_handler_alloc) + { + wide_handler->lock_mode = + pt_clone_source_handler->wide_handler->lock_mode; + if (!partition_handler->clone_bitmap_init) + { + pt_clone_source_handler->set_select_column_mode(); + partition_handler->clone_bitmap_init = TRUE; + } + set_clone_searched_bitmap(); + wide_handler->position_bitmap_init = FALSE; + wide_handler->sql_command = + pt_clone_source_handler->wide_handler->sql_command; + } + } else + wide_handler->semi_table_lock = + spider_param_semi_table_lock(thd, share->semi_table_lock); + + 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: + if (partition_handler_alloc) + { + wide_share = share->wide_share; + spider->partition_handler = NULL; + owner->partition_handler = NULL; + } + partition_handler = NULL; + spider_free_share(share); + share = NULL; + if (conn_keys) + { + spider_free(spider_current_trx, conn_keys, MYF(0)); + conn_keys = NULL; + } +error_get_share: + if (wide_handler_alloc) + { + spider_free(spider_current_trx, wide_handler, MYF(0)); + if (wide_handler_handlers) + { + wide_handler_handlers[0]->wide_handler = NULL; + } + spider->wide_handler = NULL; + owner->wide_handler = NULL; + owner->wide_handler_owner = FALSE; + } + wide_handler = NULL; +error_wide_handler_alloc: + DBUG_RETURN(error_num); +} + +int ha_spider::close() +{ + int error_num= 0, roop_count; + THD *thd = ha_thd(); + backup_error_status(); + DBUG_ENTER("ha_spider::close"); + DBUG_PRINT("info",("spider this=%p", this)); + + 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; + } + if (mrr_key_buff) + { + delete [] mrr_key_buff; + mrr_key_buff = NULL; + } + while (direct_aggregate_item_first) + { + direct_aggregate_item_current = direct_aggregate_item_first->next; + if (direct_aggregate_item_first->item) + { + delete direct_aggregate_item_first->item; + } + spider_free(spider_current_trx, direct_aggregate_item_first, MYF(0)); + direct_aggregate_item_first = direct_aggregate_item_current; + } + 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_get_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; + } + partition_handler = NULL; + if (wide_handler_owner) + { + spider_free(spider_current_trx, wide_handler, MYF(0)); + wide_handler_owner = FALSE; + } + wide_handler = 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; + } + + spider_free_share(share); + is_clone = FALSE; + pt_clone_source_handler = NULL; + share = NULL; + conns = NULL; + + DBUG_RETURN(error_num); +} + +int ha_spider::check_access_kind_for_connection( + THD *thd, + bool write_request +) { + int error_num, roop_count; + DBUG_ENTER("ha_spider::check_access_kind_for_connection"); + DBUG_PRINT("info",("spider this=%p", this)); + conn_kinds = 0; + switch (wide_handler->sql_command) + { + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + default: + conn_kinds |= SPIDER_CONN_KIND_MYSQL; + for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) + { + conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; + } + break; + } + if ((error_num = spider_check_trx_and_get_conn(thd, this, TRUE))) + { + DBUG_RETURN(error_num); + } + DBUG_PRINT("info",("spider wide_handler->semi_trx_isolation_chk = %s", + wide_handler->semi_trx_isolation_chk ? "TRUE" : "FALSE")); + if (wide_handler->semi_trx_isolation_chk) + { + SPIDER_SET_CONNS_PARAM(semi_trx_isolation_chk, TRUE, conns, + share->link_statuses, conn_link_idx, (int) share->link_count, + SPIDER_LINK_STATUS_RECOVERY); + } + DBUG_PRINT("info",("spider wide_handler->semi_trx_chk = %s", + wide_handler->semi_trx_chk ? "TRUE" : "FALSE")); + if (wide_handler->semi_trx_chk) + { + SPIDER_SET_CONNS_PARAM(semi_trx_chk, TRUE, conns, share->link_statuses, + conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY); + } else { + SPIDER_SET_CONNS_PARAM(semi_trx_chk, FALSE, conns, share->link_statuses, + conn_link_idx, (int) share->link_count, SPIDER_LINK_STATUS_RECOVERY); + } + DBUG_RETURN(0); +} + +void ha_spider::check_access_kind( + THD *thd +) { + DBUG_ENTER("ha_spider::check_access_kind"); + DBUG_PRINT("info",("spider this=%p", this)); + wide_handler->sql_command = thd_sql_command(thd); + DBUG_PRINT("info",("spider sql_command=%u", wide_handler->sql_command)); + DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id)); + wide_handler->update_request = FALSE; + DBUG_VOID_RETURN; +} + + +THR_LOCK_DATA **ha_spider::store_lock( + THD *thd, + THR_LOCK_DATA **to, + enum thr_lock_type lock_type +) { + DBUG_ENTER("ha_spider::store_lock"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + wide_handler->stage == SPD_HND_STAGE_STORE_LOCK && + wide_handler->stage_executor != this) + { + DBUG_RETURN(to); + } + wide_handler->stage = SPD_HND_STAGE_STORE_LOCK; + wide_handler->stage_executor = this; + wide_handler->lock_table_type = 0; + if (lock_type == TL_IGNORE) + { + *to++ = &wide_handler->lock; + DBUG_RETURN(to); + } + check_access_kind(thd); + DBUG_PRINT("info",("spider sql_command=%u", wide_handler->sql_command)); + DBUG_PRINT("info",("spider lock_type=%d", lock_type)); + DBUG_PRINT("info",("spider thd->query_id=%lld", thd->query_id)); + + wide_handler->lock_type = lock_type; + if ( + wide_handler->sql_command != SQLCOM_DROP_TABLE && + wide_handler->sql_command != SQLCOM_ALTER_TABLE + ) { + wide_handler->semi_trx_chk = FALSE; + } + switch (wide_handler->sql_command) + { + case SQLCOM_SELECT: + case SQLCOM_HA_READ: + if (lock_type == TL_READ_WITH_SHARED_LOCKS) + wide_handler->lock_mode = 1; + else if (lock_type <= TL_READ_NO_INSERT) + { + wide_handler->lock_mode = 0; + wide_handler->semi_trx_isolation_chk = TRUE; + } else + wide_handler->lock_mode = -1; + wide_handler->semi_trx_chk = TRUE; + break; + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + 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: + if (lock_type >= TL_READ && lock_type <= TL_READ_NO_INSERT) + { + wide_handler->lock_mode = -2; + wide_handler->semi_trx_isolation_chk = TRUE; + } else + wide_handler->lock_mode = -1; + wide_handler->semi_trx_chk = TRUE; + break; + default: + wide_handler->lock_mode = -1; + } + switch (lock_type) + { + case TL_READ_HIGH_PRIORITY: + wide_handler->high_priority = TRUE; + break; + case TL_WRITE_LOW_PRIORITY: + wide_handler->low_priority = TRUE; + break; + default: + break; + } + + if (wide_handler->lock_type != TL_IGNORE && + wide_handler->lock.type == TL_UNLOCK) + { + if ( + wide_handler->sql_command == SQLCOM_DROP_TABLE || + wide_handler->sql_command == SQLCOM_ALTER_TABLE || + wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS + ) { + 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 ( + wide_handler->sql_command == SQLCOM_LOCK_TABLES || + (spider_param_lock_exchange(thd) == 1 && wide_handler->semi_table_lock)) + { + DBUG_PRINT("info",("spider lock exchange route")); + DBUG_PRINT("info",("spider lock_type=%u", wide_handler->lock_type)); + if ( + ( + wide_handler->lock_type == TL_READ || + wide_handler->lock_type == TL_READ_NO_INSERT || + wide_handler->lock_type == TL_WRITE_LOW_PRIORITY || + wide_handler->lock_type == TL_WRITE + ) && + !spider_param_local_lock_table(thd) + ) { + wide_handler->lock_table_type = 1; + if (partition_handler && partition_handler->handlers) + { + uint roop_count; + for (roop_count = 0; roop_count < partition_handler->no_parts; + ++roop_count) + { + if (unlikely((store_error_num = + partition_handler->handlers[roop_count]-> + append_lock_tables_list()))) + { + break; + } + } + } else { + store_error_num = append_lock_tables_list(); + } + } + } else { + DBUG_PRINT("info",("spider default lock route")); + DBUG_PRINT("info",("spider lock_type=%u", wide_handler->lock_type)); + if ( + wide_handler->lock_type == TL_READ || + wide_handler->lock_type == TL_READ_NO_INSERT || + wide_handler->lock_type == TL_WRITE_LOW_PRIORITY || + wide_handler->lock_type == TL_WRITE + ) { + if ( + !spider_param_local_lock_table(thd) && + spider_param_semi_table_lock(thd, wide_handler->semi_table_lock) + ) { + wide_handler->lock_table_type = 2; + if (partition_handler && partition_handler->handlers) + { + uint roop_count; + for (roop_count = 0; + roop_count < partition_handler->no_parts; + ++roop_count) + { + if (unlikely((store_error_num = + partition_handler->handlers[roop_count]-> + append_lock_tables_list()))) + { + break; + } + } + } else { + store_error_num = append_lock_tables_list(); + } + } + } + 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; + } + wide_handler->lock.type = lock_type; + } + *to++ = &wide_handler->lock; + DBUG_RETURN(to); +} + +int ha_spider::external_lock( + THD *thd, + int lock_type +) { + int error_num = 0; + SPIDER_TRX *trx; + backup_error_status(); + + DBUG_ENTER("ha_spider::external_lock"); + + /* Beginning of wide_handler setup */ + if (wide_handler->stage == SPD_HND_STAGE_EXTERNAL_LOCK) + { + /* Only the stage executor deals with table locks. */ + if (wide_handler->stage_executor != this) + { + DBUG_RETURN(0); + } + } + else + { + /* Update the stage executor when the stage changes. */ + wide_handler->stage= SPD_HND_STAGE_EXTERNAL_LOCK; + wide_handler->stage_executor= this; + } + + info_auto_called = FALSE; + wide_handler->external_lock_type= lock_type; + wide_handler->sql_command = thd_sql_command(thd); + + trx= spider_get_trx(thd, TRUE, &error_num); + if (error_num) + { + DBUG_RETURN(error_num); + } + wide_handler->trx= trx; + /* End of wide_handler setup */ + + if (store_error_num) + { + DBUG_RETURN(store_error_num); + } + + /* We treat BEGIN as if UNLOCK TABLE. */ + if (wide_handler->sql_command == SQLCOM_BEGIN) + { + wide_handler->sql_command = SQLCOM_UNLOCK_TABLES; + } + const uint sql_command= wide_handler->sql_command; + + DBUG_ASSERT(sql_command != SQLCOM_RENAME_TABLE && + sql_command != SQLCOM_DROP_DB); + + if (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 (lock_type == F_UNLCK) + { + if (sql_command != SQLCOM_UNLOCK_TABLES) + { + DBUG_RETURN(0); /* Unlock remote tables only by UNLOCK TABLES. */ + } + if (!trx->locked_connections) + { + DBUG_RETURN(0); /* No remote table actually locked by Spider */ + } + } + else + { + if (unlikely((error_num= spider_internal_start_trx(this)))) + { + DBUG_RETURN(error_num); + } + if (sql_command != SQLCOM_SELECT && sql_command != SQLCOM_HA_READ) + { + trx->updated_in_this_trx= TRUE; + } + if (!wide_handler->lock_table_type) + { + DBUG_RETURN(0); /* No need to actually lock remote tables. */ + } + } + + if (!partition_handler || !partition_handler->handlers) + { + DBUG_RETURN(lock_tables()); /* Non-partitioned table */ + } + + for (uint i= 0; i < partition_handler->no_parts; ++i) + { + if (unlikely((error_num= partition_handler->handlers[i]->lock_tables()))) + { + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int ha_spider::start_stmt( + THD *thd, + thr_lock_type lock_type +) { + DBUG_ENTER("ha_spider::start_stmt"); + if ( + wide_handler->stage == SPD_HND_STAGE_START_STMT && + wide_handler->stage_executor != this) + { + DBUG_RETURN(0); + } + wide_handler->stage = SPD_HND_STAGE_START_STMT; + wide_handler->stage_executor = this; + 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)); + direct_aggregate_item_current = direct_aggregate_item_first; + while (direct_aggregate_item_current) + { + if (direct_aggregate_item_current->item) + { + delete direct_aggregate_item_current->item; + direct_aggregate_item_current->item = NULL; + if (direct_aggregate_item_current->init_mem_root) + { + free_root(&direct_aggregate_item_current->mem_root, MYF(0)); + direct_aggregate_item_current->init_mem_root = FALSE; + } + } + direct_aggregate_item_current = direct_aggregate_item_current->next; + } + result_list.direct_aggregate = FALSE; + result_list.snap_direct_aggregate = FALSE; + result_list.direct_distinct = FALSE; + store_error_num = 0; + if (wide_handler) + { + wide_handler->sql_command = SQLCOM_END; + wide_handler->between_flg = FALSE; + wide_handler->idx_bitmap_is_set = FALSE; + wide_handler->rnd_bitmap_is_set = FALSE; + wide_handler->quick_mode = FALSE; + wide_handler->keyread = FALSE; + wide_handler->ignore_dup_key = FALSE; + wide_handler->write_can_replace = FALSE; + wide_handler->insert_with_update = FALSE; + wide_handler->low_priority = FALSE; + wide_handler->high_priority = FALSE; + wide_handler->lock_table_type = 0; + wide_handler->semi_trx_isolation_chk = FALSE; + wide_handler->semi_trx_chk = FALSE; + if (!is_clone) + { + memset(wide_handler->ft_discard_bitmap, 0xFF, + no_bytes_in_map(table->read_set)); + memset(wide_handler->searched_bitmap, 0, + no_bytes_in_map(table->read_set)); + } + while (wide_handler->condition) + { + tmp_cond = wide_handler->condition->next; + spider_free(spider_current_trx, wide_handler->condition, MYF(0)); + wide_handler->condition = tmp_cond; + } + wide_handler->cond_check = FALSE; + wide_handler->direct_update_fields = NULL; +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + wide_handler->info_limit = 9223372036854775807LL; +#endif + wide_handler->stage = SPD_HND_STAGE_NONE; + wide_handler->stage_executor = NULL; + } + 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 = wide_handler->trx; + wide_handler->trx = tmp_trx; + if ((error_num2 = spider_db_free_result(this, FALSE))) + error_num = error_num2; + wide_handler->trx = trx_bak; + memset(need_mons, 0, sizeof(int) * share->link_count); + memset(result_list.casual_read, 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); + + 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; + } + } + } + dml_inited = FALSE; + use_pre_call = FALSE; + use_pre_action = FALSE; + pre_bitmap_checked = FALSE; + bulk_insert = FALSE; + partition_handler->clone_bitmap_init = FALSE; + result_list.tmp_table_join = FALSE; + result_list.use_union = FALSE; + result_list.use_both_key = FALSE; + pt_clone_last_searcher = NULL; + conn_kinds = SPIDER_CONN_KIND_MYSQL; + use_index_merge = FALSE; + init_rnd_handler = FALSE; + 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; + } + multi_range_num = 0; + ft_handler = NULL; + ft_current = NULL; + ft_count = 0; + ft_init_without_index_init = FALSE; + do_direct_update = FALSE; + prev_index_rnd_init = SPD_NONE; + result_list.direct_order_limit = FALSE; + result_list.direct_limit_offset = FALSE; + result_list.set_split_read = FALSE; + result_list.insert_dup_update_pushdown = FALSE; + use_spatial_index = FALSE; + use_fields = FALSE; + error_mode = 0; + 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)); + if ( + wide_handler->stage == SPD_HND_STAGE_EXTRA && + wide_handler->stage_executor != this) + { + DBUG_RETURN(0); + } + wide_handler->stage = SPD_HND_STAGE_EXTRA; + wide_handler->stage_executor = this; + switch (operation) + { + case HA_EXTRA_QUICK: + wide_handler->quick_mode = TRUE; + break; + case HA_EXTRA_KEYREAD: + if (!is_clone) + { + wide_handler->keyread = TRUE; + if (wide_handler->update_request) + { + if (check_partitioned()) + wide_handler->keyread = FALSE; + } + } + break; + case HA_EXTRA_NO_KEYREAD: + wide_handler->keyread = FALSE; + break; + case HA_EXTRA_IGNORE_DUP_KEY: + wide_handler->ignore_dup_key = TRUE; + break; + case HA_EXTRA_NO_IGNORE_DUP_KEY: + wide_handler->ignore_dup_key = FALSE; + break; + case HA_EXTRA_WRITE_CAN_REPLACE: + wide_handler->write_can_replace = TRUE; + break; + case HA_EXTRA_WRITE_CANNOT_REPLACE: + wide_handler->write_can_replace = FALSE; + break; + case HA_EXTRA_INSERT_WITH_UPDATE: + wide_handler->insert_with_update = TRUE; + break; + case HA_EXTRA_ATTACH_CHILDREN: + DBUG_PRINT("info",("spider HA_EXTRA_ATTACH_CHILDREN")); + if (!(wide_handler->trx = spider_get_trx(ha_thd(), TRUE, &error_num))) + DBUG_RETURN(error_num); + break; + case HA_EXTRA_ADD_CHILDREN_LIST: + DBUG_PRINT("info",("spider HA_EXTRA_ADD_CHILDREN_LIST")); + if (!(wide_handler->trx = spider_get_trx(ha_thd(), TRUE, &error_num))) + DBUG_RETURN(error_num); + break; +#if defined(HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN) || defined(HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF) +#ifdef HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN + case HA_EXTRA_STARTING_ORDERED_INDEX_SCAN: +#endif +#ifdef HA_EXTRA_HAS_HA_EXTRA_USE_CMP_REF + case HA_EXTRA_USE_CMP_REF: +#endif + DBUG_PRINT("info",("spider HA_EXTRA_STARTING_ORDERED_INDEX_SCAN")); + if (table_share->primary_key != MAX_KEY) + { + DBUG_PRINT("info",("spider need primary key columns")); + KEY *key_info = &table->key_info[table->s->primary_key]; + KEY_PART_INFO *key_part; + uint part_num; + for ( + key_part = key_info->key_part, part_num = 0; + part_num < spider_user_defined_key_parts(key_info); + key_part++, part_num++ + ) { + spider_set_bit(wide_handler->searched_bitmap, + key_part->field->field_index); + } + } else { + DBUG_PRINT("info",("spider need all columns")); + Field **field; + for ( + field = table->field; + *field; + field++ + ) { + spider_set_bit(wide_handler->searched_bitmap, (*field)->field_index); + } + } + 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)); + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + DBUG_RETURN(error_num); + } + } + 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 (pre_bitmap_checked) + pre_bitmap_checked = FALSE; + else { + if (wide_handler->external_lock_type == F_WRLCK) + { + pk_update = FALSE; +/* + check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT); +*/ + if ( + wide_handler->update_request && + share->have_recovery_link && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(wide_handler->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))) + DBUG_RETURN(error_num); + result_list.check_direct_order_limit = FALSE; + prev_index_rnd_init = SPD_INDEX; + DBUG_RETURN(0); +} + + +int ha_spider::index_end() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::index_end"); + DBUG_PRINT("info",("spider this=%p", this)); + 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)); +*/ + if ((error_num = drop_tmp_tables())) + DBUG_RETURN(check_error_mode(error_num)); + result_list.use_union = FALSE; + DBUG_RETURN(0); +} + + +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 (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + if ( + find_flag >= HA_READ_MBR_CONTAIN && + find_flag <= HA_READ_MBR_EQUAL + ) + use_spatial_index = TRUE; + + 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))) + DBUG_RETURN(error_num); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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]; + check_distinct_key_query(); + 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 (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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + 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 +) { + DBUG_ENTER("ha_spider::pre_index_read_map"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + index_read_map_internal(NULL, key, keypart_map, find_flag); + 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)); + 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 (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + 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 ( + result_list.current + && + (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))) + DBUG_RETURN(error_num); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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]; + check_distinct_key_query(); + 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 (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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + 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 (wide_handler->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(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 (wide_handler->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_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 (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + 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 ((error_num = spider_db_free_result(this, FALSE))) + DBUG_RETURN(error_num); + if ((error_num= reset_sql_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + + check_direct_order_limit(); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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; + check_distinct_key_query(); + 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 (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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + } + + 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 (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + 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 ((error_num = spider_db_free_result(this, FALSE))) + DBUG_RETURN(error_num); + if ((error_num= reset_sql_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + + check_direct_order_limit(); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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; + check_distinct_key_query(); + 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 (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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + } + + 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 (wide_handler->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(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 (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + 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 (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))) + DBUG_RETURN(error_num); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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]; + check_distinct_key_query(); + result_list.limit_num = + result_list.internal_limit >= result_list.split_read ? + result_list.split_read : result_list.internal_limit; + DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num)); + if ( + (error_num = spider_db_append_key_where( + start_key, eq_range ? NULL : end_key, this)) + ) + 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( + 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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + 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; + if ((error_num = read_range_next())) + DBUG_RETURN(error_num); + DBUG_RETURN(0); + } + if ((error_num = read_range_first_internal(table->record[0], start_key, + end_key, eq_range, sorted))) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +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 (wide_handler->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); +} + +void ha_spider::reset_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::reset_no_where_cond"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond = + FALSE; + } + DBUG_VOID_RETURN; +} + +bool ha_spider::check_no_where_cond() +{ + uint roop_count; + DBUG_ENTER("ha_spider::check_no_where_cond"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + if (dbton_handler[share->use_sql_dbton_ids[roop_count]]->no_where_cond) + { + DBUG_RETURN(TRUE); + } + } + DBUG_RETURN(FALSE); +} + +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 +) +{ + DBUG_ENTER("ha_spider::multi_range_read_info_const"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!pre_bitmap_checked) + { + if (wide_handler->external_lock_type == F_WRLCK) + { + pk_update = FALSE; + if ( + wide_handler->update_request && + share->have_recovery_link && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(wide_handler->searched_bitmap, 0xFF, + no_bytes_in_map(table->read_set)); + } + } + + if (!is_clone) + set_select_column_mode(); + + pre_bitmap_checked = TRUE; + } +/* + multi_range_num = n_ranges; + mrr_have_range = FALSE; +*/ + 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); +} + +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 +) +{ + DBUG_ENTER("ha_spider::multi_range_read_info"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!pre_bitmap_checked) + { + if (wide_handler->external_lock_type == F_WRLCK) + { + pk_update = FALSE; + if ( + wide_handler->update_request && + share->have_recovery_link && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(wide_handler->searched_bitmap, 0xFF, + no_bytes_in_map(table->read_set)); + } + } + + if (!is_clone) + set_select_column_mode(); + + pre_bitmap_checked = TRUE; + } +/* + multi_range_num = n_ranges; + mrr_have_range = FALSE; +*/ + 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(wide_handler->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; + mrr_have_range = FALSE; + reset_no_where_cond(); + DBUG_RETURN( + handler::multi_range_read_init( + seq, + seq_init_param, + n_ranges, + mode, + buf + ) + ); +} + +int ha_spider::multi_range_read_next_first( + range_id_t *range_info +) +{ + int error_num, roop_count; + SPIDER_CONN *conn; + int range_res; + backup_error_status(); + DBUG_ENTER("ha_spider::multi_range_read_next_first"); + DBUG_PRINT("info",("spider this=%p", this)); + if (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + do_direct_update = FALSE; + 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 = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + 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))) + DBUG_RETURN(error_num); + result_list.desc_flg = FALSE; + result_list.sorted = mrr_is_output_sorted; + result_list.key_info = &table->key_info[active_index]; + if (multi_range_num == 1 || result_list.multi_split_read <= 1) + { + if (wide_handler->keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + mrr_with_cnt = 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); + error_num = HA_ERR_END_OF_FILE; + while (!(range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range))) + { + DBUG_PRINT("info",("spider range_res1=%d", range_res)); + 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; + DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num)); + if ( + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) + ) + 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( + 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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } + if (!error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } + } + if (!error_num) + { + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + if (error_num) + break; + } + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + } else { + if (!range_info) + DBUG_RETURN(0); + if (!(error_num = spider_db_fetch(table->record[0], this, table))) + { + *range_info = (char *) mrr_cur_range.ptr; + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + if (result_list.current == result_list.first) + result_list.current = NULL; + else + result_list.current = result_list.current->prev; + } + } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } + set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + } + DBUG_PRINT("info",("spider range_res2=%d", range_res)); + if (error_num) + DBUG_RETURN(check_error_mode_eof(error_num)); + } else { + bool tmp_high_priority = wide_handler->high_priority; + bool have_multi_range; + const uchar *first_mrr_start_key; + const uchar *first_mrr_end_key; + uint first_mrr_start_key_length; + uint first_mrr_end_key_length; + have_second_range = FALSE; + if (wide_handler->keyread) + result_list.keyread = TRUE; + else + result_list.keyread = FALSE; + mrr_with_cnt = TRUE; + multi_range_cnt = 0; + multi_range_hit_point = 0; + 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 (!(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))) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_PRINT("info",("spider alloc multi_range_keys=%p", multi_range_keys)); + if (!mrr_key_buff) + { + if (!(mrr_key_buff = new spider_string[2])) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + for (roop_count = 0; roop_count < 2; roop_count++) + mrr_key_buff[roop_count].init_calc_mem(235); + } + error_num = 0; + 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)); + mrr_key_buff[0].length(0); + first_mrr_start_key = mrr_cur_range.start_key.key; + first_mrr_start_key_length = mrr_cur_range.start_key.length; + if (first_mrr_start_key_length) + { + if (mrr_key_buff[0].reserve(first_mrr_start_key_length)) + DBUG_RETURN(HA_ERR_END_OF_FILE); + mrr_key_buff[0].q_append((const char *) first_mrr_start_key, + first_mrr_start_key_length); + mrr_cur_range.start_key.key = (const uchar *) mrr_key_buff[0].ptr(); + } + mrr_key_buff[1].length(0); + first_mrr_end_key = mrr_cur_range.end_key.key; + first_mrr_end_key_length = mrr_cur_range.end_key.length; + if (first_mrr_end_key_length) + { + if (mrr_key_buff[1].reserve(first_mrr_end_key_length)) + DBUG_RETURN(HA_ERR_END_OF_FILE); + mrr_key_buff[1].q_append((const char *) first_mrr_end_key, + first_mrr_end_key_length); + mrr_cur_range.end_key.key = (const uchar *) mrr_key_buff[1].ptr(); + } + result_list.tmp_table_join = FALSE; + memset(result_list.tmp_table_join_first, 0, share->link_bitmap_size); + do + { + if ((range_res = mrr_funcs.next(mrr_iter, &mrr_second_range))) + { + have_second_range = FALSE; + have_multi_range = FALSE; + } else { + have_second_range = TRUE; + have_multi_range = TRUE; + } + DBUG_PRINT("info",("spider range_res5=%d", range_res)); + result_list.tmp_reuse_sql = FALSE; + if (bka_mode && + have_multi_range && + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) + ) { + if ( + result_list.tmp_table_join && + result_list.tmp_table_join_key_part_map == + mrr_cur_range.start_key.keypart_map + ) { + /* reuse tmp_sql */ + result_list.tmp_reuse_sql = TRUE; + } else { + /* create tmp_sql */ + result_list.tmp_table_join = TRUE; + result_list.tmp_table_join_key_part_map = + mrr_cur_range.start_key.keypart_map; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + } + memset(result_list.tmp_table_join_first, 0xFF, + share->link_bitmap_size); + } else { + result_list.tmp_table_join = 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 (bka_mode == 2) + { + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_union_table_and_sql_for_bka( + &mrr_cur_range.start_key + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_union_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + } else { + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_tmp_table_and_sql_for_bka( + &mrr_cur_range.start_key + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_tmp_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + } + + do + { + if ( + !SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + mrr_cur_range.start_key.keypart_map + ) { + result_list.tmp_table_join_break_after_get_next = TRUE; + break; + } + + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; + if (bka_mode == 2) + { + if ((error_num = spider_db_append_select(this))) + DBUG_RETURN(error_num); + if (multi_range_cnt == 0) + { + if ((error_num = append_multi_range_cnt_with_name_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt))) + DBUG_RETURN(error_num); + if ((error_num = append_key_column_values_with_name_sql_part( + &mrr_cur_range.start_key, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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 = append_key_column_values_sql_part( + &mrr_cur_range.start_key, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_union_table_connector_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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( + &mrr_cur_range.start_key, + 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; + 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)); + } + } + while (!range_res); + if (bka_mode == 2) + { + if ((error_num = append_union_table_terminator_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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.split_read = result_list.internal_limit; + if ( + (error_num = init_union_table_name_pos_sql()) || + (error_num = append_union_all_start_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + + do + { + DBUG_PRINT("info",("spider range_res7=%d", range_res)); + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; + 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)) || + (error_num = set_union_table_name_pos_sql()) + ) + DBUG_RETURN(error_num); + wide_handler->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); + DBUG_PRINT("info",("spider internal_offset=%lld", + result_list.internal_offset)); + DBUG_PRINT("info",("spider limit_num=%lld", result_list.limit_num)); + if ( + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) + ) + 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; + 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)); + } + if (check_no_where_cond()) + { + range_res = 1; + break; + } + } + while (!range_res); + wide_handler->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; + + bool direct_aggregate_backup = result_list.direct_aggregate; + result_list.direct_aggregate = FALSE; + 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); + } + result_list.direct_aggregate = direct_aggregate_backup; + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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)); + conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + if ( + result_list.tmp_table_join && bka_mode != 2 && + 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, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_TMP_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + spider_db_discard_multiple_result(this, roop_count, conn); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + 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) + { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res9=%d", range_res)); + } + if ( + range_res + ) { + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + 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 (!range_info) + DBUG_RETURN(0); + if (!(error_num = spider_db_fetch(table->record[0], this, table))) + { + *range_info = multi_range_keys[multi_range_hit_point]; + 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) + { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res10=%d", range_res)); + } + if ( + range_res + ) { + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + 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); + } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } + multi_range_cnt = 0; + if ((error_num= reset_sql_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } while (!error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::pre_multi_range_read_next( + bool use_parallel +) { + DBUG_ENTER("ha_spider::pre_multi_range_read_next"); + DBUG_PRINT("info",("spider this=%p", this)); + check_pre_call(use_parallel); + if (use_pre_call) + { + store_error_num = + multi_range_read_next_first(NULL); + DBUG_RETURN(store_error_num); + } + DBUG_RETURN(0); +} + +int ha_spider::multi_range_read_next( + range_id_t *range_info +) +{ + int error_num; + DBUG_ENTER("ha_spider::multi_range_read_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; + mrr_have_range = TRUE; + DBUG_RETURN(multi_range_read_next_next(range_info)); + } + 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); +} + +int ha_spider::multi_range_read_next_next( + range_id_t *range_info +) +{ + int error_num, roop_count; + SPIDER_CONN *conn; + int range_res; + backup_error_status(); + DBUG_ENTER("ha_spider::multi_range_read_next_next"); + DBUG_PRINT("info",("spider this=%p", this)); + if (wide_handler->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 (multi_range_num == 1 || result_list.multi_split_read <= 1) + { + if (!(error_num = spider_db_seek_next(table->record[0], this, + search_link_idx, table))) + { + *range_info = (char *) mrr_cur_range.ptr; + DBUG_RETURN(0); + } + + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res1=%d", range_res)); + 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 || + range_res + ) + DBUG_RETURN(error_num); + spider_db_free_one_result_for_start_next(this); + spider_first_split_read_param(this); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + 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; + do + { + DBUG_PRINT("info",("spider range_res2=%d", range_res)); + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } + set_where_to_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); + 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 ( + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) + ) + 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( + 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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } + if (!error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + } + } + if (!error_num) + { + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + if (error_num) + break; + } + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + result_list.current = result_list.current->prev; + } + } else + DBUG_RETURN(error_num); + } else { + if (!(error_num = spider_db_fetch(table->record[0], this, table))) + { + *range_info = (char *) mrr_cur_range.ptr; + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + result_list.current = result_list.current->prev; + } + } else + DBUG_RETURN(error_num); + } + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res3=%d", range_res)); + } + while (!range_res); + 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))) + { + *range_info = multi_range_keys[multi_range_hit_point]; + DBUG_RETURN(0); + } + + const uchar *first_mrr_start_key; + const uchar *first_mrr_end_key; + uint first_mrr_start_key_length; + uint first_mrr_end_key_length; + if (!result_list.tmp_table_join_break_after_get_next) + { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res4=%d", range_res)); + if (!range_res) + { + mrr_key_buff[0].length(0); + first_mrr_start_key = mrr_cur_range.start_key.key; + first_mrr_start_key_length = mrr_cur_range.start_key.length; + if (first_mrr_start_key_length) + { + if (mrr_key_buff[0].reserve(first_mrr_start_key_length)) + DBUG_RETURN(HA_ERR_END_OF_FILE); + mrr_key_buff[0].q_append((const char *) first_mrr_start_key, + first_mrr_start_key_length); + mrr_cur_range.start_key.key = (const uchar *) mrr_key_buff[0].ptr(); + } + mrr_key_buff[1].length(0); + first_mrr_end_key = mrr_cur_range.end_key.key; + first_mrr_end_key_length = mrr_cur_range.end_key.length; + if (first_mrr_end_key_length) + { + if (mrr_key_buff[1].reserve(first_mrr_end_key_length)) + DBUG_RETURN(HA_ERR_END_OF_FILE); + mrr_key_buff[1].q_append((const char *) first_mrr_end_key, + first_mrr_end_key_length); + mrr_cur_range.end_key.key = (const uchar *) mrr_key_buff[1].ptr(); + } + } + } else { + result_list.tmp_table_join_break_after_get_next = FALSE; + range_res = 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 || + range_res + ) + DBUG_RETURN(error_num); + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } + spider_db_free_one_result_for_start_next(this); + spider_first_split_read_param(this); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + 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))) + DBUG_RETURN(error_num); + + bool tmp_high_priority = wide_handler->high_priority; + bool have_multi_range; + multi_range_cnt = 0; + error_num = 0; + do + { + if ( + !have_second_range && + (range_res = mrr_funcs.next(mrr_iter, &mrr_second_range)) + ) + { + have_second_range = FALSE; + have_multi_range = FALSE; + } else { + have_second_range = TRUE; + have_multi_range = TRUE; + } + DBUG_PRINT("info",("spider range_res5=%d", range_res)); + result_list.tmp_reuse_sql = FALSE; + if (bka_mode && + have_multi_range && + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) + ) { + if ( + result_list.tmp_table_join && + result_list.tmp_table_join_key_part_map == + mrr_cur_range.start_key.keypart_map + ) { + /* reuse tmp_sql */ + result_list.tmp_reuse_sql = TRUE; + } else { + /* create tmp_sql */ + result_list.tmp_table_join = TRUE; + result_list.tmp_table_join_key_part_map = + mrr_cur_range.start_key.keypart_map; + if ((error_num = reset_sql_sql( + SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL))) + DBUG_RETURN(error_num); + } + memset(result_list.tmp_table_join_first, 0xFF, + share->link_bitmap_size); + } else { + result_list.tmp_table_join = 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 (bka_mode == 2) + { + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_union_table_and_sql_for_bka( + &mrr_cur_range.start_key + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_union_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + } else { + if (!result_list.tmp_reuse_sql) + { + if ((error_num = append_tmp_table_and_sql_for_bka( + &mrr_cur_range.start_key + ))) { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = reuse_tmp_table_and_sql_for_bka())) + { + DBUG_RETURN(error_num); + } + } + } + + do + { + if ( + !SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) || + result_list.tmp_table_join_key_part_map != + mrr_cur_range.start_key.keypart_map + ) { + result_list.tmp_table_join_break_after_get_next = TRUE; + break; + } + + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; + if (bka_mode == 2) + { + if ((error_num = spider_db_append_select(this))) + DBUG_RETURN(error_num); + if (multi_range_cnt == 0) + { + if ((error_num = append_multi_range_cnt_with_name_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, multi_range_cnt))) + DBUG_RETURN(error_num); + if ((error_num = append_key_column_values_with_name_sql_part( + &mrr_cur_range.start_key, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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 = append_key_column_values_sql_part( + &mrr_cur_range.start_key, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } + if ((error_num = append_union_table_connector_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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( + &mrr_cur_range.start_key, + 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; + 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)); + } + } + while (!range_res); + if (bka_mode == 2) + { + if ((error_num = append_union_table_terminator_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + 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 = init_union_table_name_pos_sql()) || + (error_num = + append_union_all_start_sql_part(SPIDER_SQL_TYPE_SELECT_SQL)) + ) + DBUG_RETURN(error_num); + do + { + multi_range_keys[multi_range_cnt] = mrr_cur_range.ptr; + 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)) || + (error_num = set_union_table_name_pos_sql()) + ) + DBUG_RETURN(error_num); + wide_handler->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 ( + (error_num = spider_db_append_key_where( + &mrr_cur_range.start_key, + SPIDER_TEST(mrr_cur_range.range_flag & EQ_RANGE) ? + NULL : &mrr_cur_range.end_key, this)) + ) + 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; + 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)); + } + } + while (!range_res); + wide_handler->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; + + bool direct_aggregate_backup = result_list.direct_aggregate; + result_list.direct_aggregate = FALSE; + 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); + } + result_list.direct_aggregate = direct_aggregate_backup; + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + } else { + ulong sql_type; + conn= conns[roop_count]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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)); + conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + if ( + result_list.tmp_table_join && bka_mode != 2 && + 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, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_TMP_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + spider_db_discard_multiple_result(this, roop_count, conn); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + break; + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + 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) + { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res8=%d", range_res)); + } + if ( + range_res + ) { + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + 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))) + { + *range_info = multi_range_keys[multi_range_hit_point]; + 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) + { + range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); + DBUG_PRINT("info",("spider range_res9=%d", range_res)); + } + if ( + range_res + ) { + 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; + spider_db_free_one_result(&result_list, + (SPIDER_RESULT *) result_list.current); + 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); + } + if (check_no_where_cond()) + { + DBUG_RETURN(check_error_mode_eof(0)); + } + multi_range_cnt = 0; + if ((error_num= reset_sql_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } 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)); + DBUG_PRINT("info",("spider scan=%s", scan ? "TRUE" : "FALSE")); + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + DBUG_RETURN(error_num); + } + } + pushed_pos = NULL; +/* + if (wide_handler->external_lock_type == F_WRLCK) + check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT); +*/ + rnd_scan_and_first = scan; + if ( + scan && + wide_handler->sql_command != SQLCOM_ALTER_TABLE + ) { + spider_set_result_list_param(this); + pk_update = FALSE; + if ( + result_list.current && + !result_list.low_mem_read && + prev_index_rnd_init == SPD_RND + ) { + 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) + ) { + if (conns[roop_count] && result_list.bgs_working) + spider_bg_conn_break(conns[roop_count], this); + if (quick_targets[roop_count]) + { + spider_db_free_one_quick_result( + (SPIDER_RESULT *) result_list.current); + 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; + result_list.bgs_phase = 0; + } + + mrr_with_cnt = FALSE; + use_spatial_index = FALSE; + + if ( + wide_handler->update_request && + share->have_recovery_link && + wide_handler->external_lock_type == F_WRLCK && + (pk_update = spider_check_pk_update(table)) + ) { + bitmap_set_all(table->read_set); + if (is_clone) + memset(wide_handler->searched_bitmap, 0xFF, + no_bytes_in_map(table->read_set)); + } + + set_select_column_mode(); + result_list.keyread = FALSE; + + init_rnd_handler = FALSE; + if ((error_num= reset_sql_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + result_list.check_direct_order_limit = FALSE; + } + } + prev_index_rnd_init = SPD_RND; + DBUG_RETURN(0); +} + + +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); +} + + +int ha_spider::rnd_next_internal( + uchar *buf +) { + int error_num; + ha_spider *direct_limit_offset_spider = + (ha_spider *) partition_handler->owner; + backup_error_status(); + DBUG_ENTER("ha_spider::rnd_next_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (wide_handler->trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + /* do not copy table data at alter table */ + if (wide_handler->sql_command == SQLCOM_ALTER_TABLE) + DBUG_RETURN(HA_ERR_END_OF_FILE); + do_direct_update = FALSE; + + if (rnd_scan_and_first) + { + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_direct_order_limit(); + check_select_column(TRUE); + + if (this->result_list.direct_limit_offset) + { + if (direct_limit_offset_spider->direct_select_limit == 0) + { // mean has got all result + DBUG_RETURN(check_error_mode_eof(HA_ERR_END_OF_FILE)); + } + if ( + partition_handler->handlers && + direct_limit_offset_spider->direct_current_offset > 0 + ) { + longlong table_count = this->records(); + DBUG_PRINT("info",("spider table_count=%lld", table_count)); + if (table_count <= direct_limit_offset_spider->direct_current_offset) + { + // skip this spider(partition) + direct_limit_offset_spider->direct_current_offset -= table_count; + DBUG_PRINT("info",("spider direct_current_offset=%lld", + direct_limit_offset_spider->direct_current_offset)); + DBUG_RETURN(check_error_mode_eof(HA_ERR_END_OF_FILE)); + } + } + + // make the offset/limit statement + DBUG_PRINT("info",("spider direct_current_offset=%lld", + direct_limit_offset_spider->direct_current_offset)); + result_list.internal_offset = direct_limit_offset_spider->direct_current_offset; + DBUG_PRINT("info",("spider direct_select_limit=%lld", + direct_limit_offset_spider->direct_select_limit)); + result_list.internal_limit = direct_limit_offset_spider->direct_select_limit; + result_list.split_read = direct_limit_offset_spider->direct_select_limit; + + // start with this spider(partition) + direct_limit_offset_spider->direct_current_offset = 0; + } + + 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) + { + 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 (result_list.direct_aggregate) + { + if ((error_num = + append_group_by_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 ((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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + SPIDER_CONN *conn = conns[roop_count]; + ulong sql_type; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + rnd_scan_and_first = FALSE; + + if (this->result_list.direct_limit_offset) + { + 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); + } + } + + if ( + result_list.direct_limit_offset && + direct_limit_offset_spider->direct_select_offset > 0 + ) { + // limit-- for each got row + direct_limit_offset_spider->direct_select_offset--; + DBUG_RETURN(0); + } + + 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 { + if (is_clone) + { + DBUG_PRINT("info",("spider set pt_clone_last_searcher (NULL) to %p", + pt_clone_source_handler)); + pt_clone_source_handler->pt_clone_last_searcher = NULL; + } + 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 (!wide_handler->position_bitmap_init) + { + if (select_column_mode) + { + spider_db_handler *dbton_hdl = + dbton_handler[result_list.current->dbton_id]; + dbton_hdl->copy_minimum_select_bitmap(wide_handler->position_bitmap); + } + wide_handler->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)); +#ifndef DBUG_OFF + for (uint roop_count = 0; roop_count < ((table->s->fields + 7) / 8); + roop_count++) + { + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + DBUG_PRINT("info",("spider read_set=%d", + ((uchar *) table->read_set->bitmap)[roop_count])); + } +#endif + if (wide_handler->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)); + result_list.in_cmp_ref = TRUE; + 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((uint) ptr_diff))) + { + DBUG_PRINT("info",("spider different at %s", + SPIDER_field_name_str(*field))); + break; + } + } + } + result_list.in_cmp_ref = FALSE; + 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 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; + + DBUG_RETURN(0); +} + +void ha_spider::ft_end() +{ + DBUG_ENTER("ha_spider::ft_end"); + DBUG_PRINT("info",("spider this=%p", this)); + 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; + handler::ft_end(); + 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())); + if (inx == NO_SUCH_KEY) + { + my_error(ER_FT_MATCHING_KEY_NOT_FOUND, MYF(0)); + DBUG_RETURN(NULL); + } + + tmp_ft_info = ft_current; + if (ft_current) + ft_current = ft_current->next; + else { + ft_current = ft_first; + set_ft_discard_bitmap(); + } + + 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)))) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + 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 (wide_handler->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(); + if ((error_num = spider_set_conn_bg_param(this))) + DBUG_RETURN(error_num); + check_select_column(FALSE); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list.finish_flg = FALSE; + result_list.record_num = 0; + if (wide_handler->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))) + 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 (result_list.direct_aggregate) + { + if ((error_num = + append_group_by_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); + } + } + + 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) + ) { + if (result_list.bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read( + wide_handler->trx->thd, this, + roop_count))) + DBUG_RETURN(error_num); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + } else { + 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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL, roop_count))) + { + 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_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_SELECT_SQL, + conn, + result_list.quick_mode, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode_eof(error_num)); + } + connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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); + } + } + } + } + + 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); + int sts_sync = spider_param_sts_sync(thd, share->sts_sync); + int sts_bg_mode = spider_param_sts_bg_mode(thd, share->sts_bg_mode); + 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)); +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT + auto_inc_temporary = FALSE; +#endif + wide_handler->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->lgtm_tblhnd_share->auto_increment_value) + stats.auto_increment_value = + share->lgtm_tblhnd_share->auto_increment_value; + else { + stats.auto_increment_value = 1; +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT + auto_inc_temporary = TRUE; +#endif + } + } + if ( + wide_handler->sql_command == SQLCOM_DROP_TABLE || + wide_handler->sql_command == SQLCOM_ALTER_TABLE + ) + 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); + info_auto_called = TRUE; + } + 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(wide_handler->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 (wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS) + { + if (thd->is_error()) + { + DBUG_PRINT("info", ("spider clear_error")); + thd->clear_error(); + } + DBUG_RETURN(0); + } + 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; + if (tmp_auto_increment_mode == 1) + sts_sync = 0; + } + } + if (flag & HA_STATUS_AUTO) + { + if ( + share->wide_share && + tmp_auto_increment_mode == 1 && + !share->lgtm_tblhnd_share->auto_increment_init + ) { + sts_interval = 0; + sts_sync = 0; + } + } + if (difftime(tmp_time, share->sts_get_time) >= sts_interval) + { + if ( + sts_interval == 0 || + !pthread_mutex_trylock(&share->sts_mutex) + ) { + if (sts_interval == 0 || sts_bg_mode == 0) + { + 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))) + { + pthread_mutex_unlock(&share->sts_mutex); + if (!share->sts_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(wide_handler->trx, + share, TRUE)) + ) { + spider_init_error_table->init_error = error_num; + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) + strmov(spider_init_error_table->init_error_msg, + spider_stmt_da_message(thd)); + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + } + if (wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS) + { + if (thd->is_error()) + { + DBUG_PRINT("info", ("spider clear_error")); + thd->clear_error(); + } + DBUG_RETURN(0); + } + DBUG_RETURN(check_error_mode(error_num)); + } + if ((error_num = spider_get_sts(share, search_link_idx, tmp_time, + this, sts_interval, sts_mode, + sts_sync, + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + search_link_idx, + (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], + share->monitoring_flag[search_link_idx], + TRUE + ); + } + if (!share->sts_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(wide_handler->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())) + strmov(spider_init_error_table->init_error_msg, + spider_stmt_da_message(thd)); + spider_init_error_table->init_error_time = + (time_t) time((time_t*) 0); + } + share->init_error = TRUE; + share->init = TRUE; + } + if (wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS) + { + if (thd->is_error()) + { + DBUG_PRINT("info", ("spider clear_error")); + thd->clear_error(); + } + DBUG_RETURN(0); + } + DBUG_RETURN(check_error_mode(error_num)); + } + } + } else if (sts_bg_mode == 1) { + /* 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; + share->bg_sts_sync = sts_sync; + if (!share->bg_sts_init) + { + if ((error_num = spider_create_sts_thread(share))) + { + pthread_mutex_unlock(&share->sts_mutex); + if (wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS) + { + if (thd->is_error()) + { + DBUG_PRINT("info", ("spider clear_error")); + thd->clear_error(); + } + DBUG_RETURN(0); + } + DBUG_RETURN(error_num); + } + } else + pthread_cond_signal(&share->bg_sts_cond); + } + } else { + share->bg_sts_try_time = tmp_time; + share->bg_sts_interval = sts_interval; + share->bg_sts_mode = sts_mode; + share->bg_sts_sync = sts_sync; + spider_table_add_share_to_sts_thread(share); + } + pthread_mutex_unlock(&share->sts_mutex); + } + } + if (flag & HA_STATUS_CONST) + { + if ((error_num = check_crd())) + { + if (wide_handler->sql_command == SQLCOM_SHOW_CREATE || + wide_handler->sql_command == SQLCOM_SHOW_FIELDS) + { + if (thd->is_error()) + { + DBUG_PRINT("info", ("spider clear_error")); + thd->clear_error(); + } + DBUG_RETURN(0); + } + DBUG_RETURN(error_num); + } + spider_db_set_cardinarity(this, table); + } + + if (flag & HA_STATUS_TIME) + stats.update_time = (ulong) share->stat.update_time; + if (flag & (HA_STATUS_CONST | HA_STATUS_VARIABLE)) + { + stats.max_data_file_length = share->stat.max_data_file_length; + stats.create_time = share->stat.create_time; + stats.block_size = spider_param_block_size(thd); + } + if (flag & HA_STATUS_VARIABLE) + { + stats.data_file_length = share->stat.data_file_length; + stats.index_file_length = share->stat.index_file_length; + stats.records = share->stat.records; + stats.mean_rec_length = share->stat.mean_rec_length; + stats.check_time = share->stat.check_time; + if (stats.records <= 1 /* && (flag & HA_STATUS_NO_LOCK) */ ) + stats.records = 2; + stats.checksum = share->stat.checksum; + stats.checksum_null = share->stat.checksum_null; + } + if (flag & HA_STATUS_AUTO) + { +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT + auto_inc_temporary = FALSE; +#endif + if (share->wide_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->lgtm_tblhnd_share->auto_increment_value = first_value; + share->lgtm_tblhnd_share->auto_increment_lclval = first_value; + share->lgtm_tblhnd_share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + stats.auto_increment_value = first_value; + } else if (tmp_auto_increment_mode == 1 && + !share->lgtm_tblhnd_share->auto_increment_init) + { + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + share->lgtm_tblhnd_share->auto_increment_lclval = + share->lgtm_tblhnd_share->auto_increment_value; + share->lgtm_tblhnd_share->auto_increment_init = TRUE; + stats.auto_increment_value = + share->lgtm_tblhnd_share->auto_increment_value; + } else { + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + stats.auto_increment_value = + share->lgtm_tblhnd_share->auto_increment_value; + } + } else { + stats.auto_increment_value = + share->lgtm_tblhnd_share->auto_increment_value; + } + } + } + if (flag & HA_STATUS_ERRKEY) + errkey = dup_key_idx; + DBUG_RETURN(0); +} + +ha_rows ha_spider::records_in_range( + uint inx, + const key_range *start_key, + const key_range *end_key, + page_range *pages) +{ + 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); + int crd_sync = spider_param_crd_sync(thd, share->crd_sync); + int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode); + 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)); + DBUG_PRINT("info",("spider inx=%u", inx)); + 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(wide_handler->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); + /* This assertion simply demonstrates that the + static_key_cardinality field is unused. It will be deprecated + (MDEV-28861) and removed (MDEV-31146). */ + DBUG_ASSERT(share->static_key_cardinality[inx] == -1); + if (crd_mode == 1 || crd_mode == 2) + { + DBUG_PRINT("info", ("spider static_key_cardinality[%u]=%lld", inx, + share->static_key_cardinality[inx])); + DBUG_PRINT("info", + ("spider difftime=%f", difftime(tmp_time, share->crd_get_time))); + DBUG_PRINT("info", + ("spider crd_interval=%f", crd_interval)); + if ( + share->static_key_cardinality[inx] == -1 && + difftime(tmp_time, share->crd_get_time) >= crd_interval + ) { + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + if (check_error_mode(error_num)) + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + } + if ( + crd_interval == 0 || + !pthread_mutex_trylock(&share->crd_mutex) + ) { + if (crd_interval == 0 || crd_bg_mode == 0) + { + 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, + crd_sync, + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + search_link_idx, + (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], + share->monitoring_flag[search_link_idx], + TRUE + ); + } + if (!share->crd_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(wide_handler->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())) + strmov(spider_init_error_table->init_error_msg, + spider_stmt_da_message(thd)); + 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); + } + } + } else if (crd_bg_mode == 1) { + /* 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; + share->bg_crd_sync = crd_sync; + 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); + } + } else { + share->bg_crd_try_time = tmp_time; + share->bg_crd_interval = crd_interval; + share->bg_crd_mode = crd_mode; + share->bg_crd_sync = crd_sync; + spider_table_add_share_to_crd_thread(share); + } + pthread_mutex_unlock(&share->crd_mutex); + } + } + + KEY *key_info = &table->key_info[inx]; + key_part_map full_key_part_map = + make_prev_keypart_map(spider_user_defined_key_parts(key_info)); + 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 = NULL; + double rows = (double) share->stat.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; + + if (share->static_key_cardinality[inx] == -1) + { + for ( + key_part = key_info->key_part; + tgt_key_part_map > 1; + tgt_key_part_map >>= 1, + key_part++ + ) { + field = key_part->field; + DBUG_PRINT("info", + ("spider field_index=%u", + field->field_index)); + DBUG_PRINT("info", + ("spider cardinality=%lld", share->cardinality[field->field_index])); + if (share->cardinality[field->field_index] == -1) + { + DBUG_PRINT("info", + ("spider uninitialized column cardinality")); + DBUG_RETURN(HA_POS_ERROR); + } + 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; + DBUG_PRINT("info", + ("spider field_index=%u", + field->field_index)); + DBUG_PRINT("info", + ("spider cardinality=%lld", share->cardinality[field->field_index])); + if (share->cardinality[field->field_index] == -1) + { + DBUG_PRINT("info", + ("spider uninitialized column cardinality")); + DBUG_RETURN(HA_POS_ERROR); + } + } + if ( + start_key_part_map >= end_key_part_map && + start_key->flag == HA_READ_KEY_EXACT + ) { + if (share->static_key_cardinality[inx] == -1) + { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight) >= 1) + rows = rows / rate; + } else { + rate = ((double) share->static_key_cardinality[inx]); + rows = rows / rate; + } + } else if (start_key_part_map == end_key_part_map) + { + if (share->static_key_cardinality[inx] == -1) + { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight / 4) >= 1) + rows = rows / rate; + } else { + if ((rate = + ((double) share->static_key_cardinality[inx]) / 4) >= 1) + rows = rows / rate; + } + } else { + if (share->static_key_cardinality[inx] == -1) + { + if ((rate = + ((double) share->cardinality[field->field_index]) / weight / 16) >= 1) + rows = rows / rate; + } else { + if ((rate = + ((double) share->static_key_cardinality[inx]) / 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) + { + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + if (check_error_mode(error_num)) + my_errno = error_num; + DBUG_RETURN(HA_POS_ERROR); + } + } + 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); + int crd_sync = spider_param_crd_sync(thd, share->crd_sync); + int crd_bg_mode = spider_param_crd_bg_mode(thd, share->crd_bg_mode); + 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(wide_handler->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; + if ((error_num = spider_check_trx_and_get_conn(ha_thd(), this, FALSE))) + { + DBUG_RETURN(check_error_mode(error_num)); + } + 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) + ) { + if (crd_interval == 0 || crd_bg_mode == 0) + { + 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, + crd_sync, + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + search_link_idx, + (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], + share->monitoring_flag[search_link_idx], + TRUE + ); + } + if (!share->crd_init) + { + if ( + spider_init_error_table || + (spider_init_error_table = + spider_get_init_error_table(wide_handler->trx, share, TRUE)) + ) { + spider_init_error_table->init_error = error_num; + if ((spider_init_error_table->init_error_with_message = + thd->is_error())) + strmov(spider_init_error_table->init_error_msg, + spider_stmt_da_message(thd)); + 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)); + } + } + } else if (crd_bg_mode == 1) { + /* 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; + share->bg_crd_sync = crd_sync; + 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); + } + } else { + share->bg_crd_try_time = tmp_time; + share->bg_crd_interval = crd_interval; + share->bg_crd_mode = crd_mode; + share->bg_crd_sync = crd_sync; + spider_table_add_share_to_crd_thread(share); + } + pthread_mutex_unlock(&share->crd_mutex); + } + } + DBUG_RETURN(0); +} + +int ha_spider::pre_records() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::pre_records"); + DBUG_PRINT("info",("spider this=%p", this)); + if (wide_handler->sql_command == SQLCOM_ALTER_TABLE) + { + DBUG_RETURN(0); + } + if (!(share->additional_table_flags & HA_HAS_RECORDS)) + { + DBUG_RETURN(0); + } + THD *thd = wide_handler->trx->thd; + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this, + search_link_idx, TRUE))) + { + DBUG_RETURN(check_error_mode(error_num)); + } + use_pre_action = TRUE; + 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 (wide_handler->sql_command == SQLCOM_ALTER_TABLE) + { + use_pre_action = FALSE; + DBUG_RETURN(0); + } + if (!(share->additional_table_flags & HA_HAS_RECORDS) && !this->result_list.direct_limit_offset) + { + DBUG_RETURN(handler::records()); + } + if (!use_pre_action && !this->result_list.direct_limit_offset) + { + THD *thd = wide_handler->trx->thd; + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + } + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_RECORDS, this, + search_link_idx, FALSE))) + { + use_pre_action = FALSE; + check_error_mode(error_num); + DBUG_RETURN(HA_POS_ERROR); + } + use_pre_action = FALSE; + share->stat.records = table_rows; + DBUG_RETURN(table_rows); +} + +int ha_spider::pre_calculate_checksum() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::pre_calculate_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + THD *thd = wide_handler->trx->thd; + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + DBUG_RETURN(error_num); + } + } + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + action_flags = T_EXTEND; + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this, + search_link_idx, TRUE))) + { + DBUG_RETURN(check_error_mode(error_num)); + } + use_pre_action = TRUE; + DBUG_RETURN(0); +} + +int ha_spider::calculate_checksum() +{ + int error_num; + backup_error_status(); + DBUG_ENTER("ha_spider::calculate_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + DBUG_RETURN(error_num); + } + } + if (!use_pre_action && !this->result_list.direct_limit_offset) + { + THD *thd = wide_handler->trx->thd; + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + ) { + result_list.casual_read[search_link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + } + action_flags = T_EXTEND; + if ((error_num = spider_db_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, this, + search_link_idx, FALSE))) + { + use_pre_action = FALSE; + DBUG_RETURN(check_error_mode(error_num)); + } + use_pre_action = FALSE; + if (checksum_null) + { + share->stat.checksum_null = TRUE; + share->stat.checksum = 0; + stats.checksum_null = TRUE; + stats.checksum = 0; + } else { + share->stat.checksum_null = FALSE; + share->stat.checksum = (ha_checksum) checksum_val; + stats.checksum_null = FALSE; + stats.checksum = (ha_checksum) checksum_val; + } + DBUG_RETURN(0); +} + +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_BIT_FIELD | + HA_NO_COPY_ON_ALTER | + HA_BINLOG_ROW_CAPABLE | + HA_BINLOG_STMT_CAPABLE | + HA_PARTIAL_COLUMN_READ | +#ifdef HA_SLOW_CMP_REF + HA_SLOW_CMP_REF | +#endif +#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON + HA_CAN_TABLE_CONDITION_PUSHDOWN | +#endif + SPIDER_CAN_BG_SEARCH | + SPIDER_CAN_BG_INSERT | + SPIDER_CAN_BG_UPDATE | +#ifdef HA_CAN_DIRECT_UPDATE_AND_DELETE + HA_CAN_DIRECT_UPDATE_AND_DELETE | +#endif +#ifdef HA_CAN_FORCE_BULK_UPDATE + (share && share->force_bulk_update ? HA_CAN_FORCE_BULK_UPDATE : 0) | +#endif +#ifdef HA_CAN_FORCE_BULK_DELETE + (share && share->force_bulk_delete ? HA_CAN_FORCE_BULK_DELETE : 0) | +#endif + (share ? share->additional_table_flags : 0) + ; + DBUG_RETURN(flags); +} + +ulong ha_spider::table_flags_for_partition() +{ + DBUG_ENTER("ha_spider::table_flags_for_partition"); + DBUG_PRINT("info",("spider this=%p", this)); + ulong flags = +#ifdef HA_PT_CALL_AT_ONCE_STORE_LOCK + HA_PT_CALL_AT_ONCE_STORE_LOCK | +#endif +#ifdef HA_PT_CALL_AT_ONCE_EXTERNAL_LOCK + HA_PT_CALL_AT_ONCE_EXTERNAL_LOCK | +#endif +#ifdef HA_PT_CALL_AT_ONCE_START_STMT + HA_PT_CALL_AT_ONCE_START_STMT | +#endif +#ifdef HA_PT_CALL_AT_ONCE_EXTRA + HA_PT_CALL_AT_ONCE_EXTRA | +#endif +#ifdef HA_PT_CALL_AT_ONCE_COND_PUSH + HA_PT_CALL_AT_ONCE_COND_PUSH | +#endif +#ifdef HA_PT_CALL_AT_ONCE_INFO_PUSH + HA_PT_CALL_AT_ONCE_INFO_PUSH | +#endif +#ifdef HA_PT_CALL_AT_ONCE_TOP_TABLE + HA_PT_CALL_AT_ONCE_TOP_TABLE | +#endif + 0; + DBUG_RETURN(flags); +} + +const char *ha_spider::index_type( + uint key_number +) { + KEY *key_info = &table->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); +} + +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", ( + !share->lgtm_tblhnd_share->auto_increment_init || + ( + !spider_param_auto_increment_mode(thd, share->auto_increment_mode) && + !info_auto_called + ) + ) ? "TRUE" : "FALSE")); + DBUG_RETURN(( + !share->lgtm_tblhnd_share->auto_increment_init || + ( + !spider_param_auto_increment_mode(thd, share->auto_increment_mode) && + !info_auto_called + ) + )); +} + +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT +bool ha_spider::can_use_for_auto_inc_init() +{ + DBUG_ENTER("ha_spider::can_use_for_auto_inc_init"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider return=%s", ( + !auto_inc_temporary + ) ? "TRUE" : "FALSE")); + DBUG_RETURN(( + !auto_inc_temporary + )); +} +#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() && + wide_handler->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")); + } +*/ + DBUG_PRINT("info",("spider auto_increment_mode=%d", + auto_increment_mode)); + DBUG_PRINT("info",("spider next_number_field=%lld", + table->next_number_field->val_int())); + 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->lgtm_tblhnd_share->auto_increment_mutex); + next_insert_id = share->lgtm_tblhnd_share->auto_increment_value; + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + } + if ((error_num = handler::update_auto_increment())) + { + if (lock_here) + pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex); + DBUG_RETURN(check_error_mode(error_num)); + } + if (lock_here) + { + if (insert_id_for_cur_row) + { + share->lgtm_tblhnd_share->auto_increment_lclval = + insert_id_for_cur_row + 1; + share->lgtm_tblhnd_share->auto_increment_value = next_insert_id; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + } + pthread_mutex_unlock(&share->lgtm_tblhnd_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); + bool rev= table->key_info[table->s->next_number_index]. + key_part[table->s->next_number_keypart].key_part_flag & + HA_REVERSE_SORT; + 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 if (rev) + error_num = index_first(table->record[1]); + 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->lgtm_tblhnd_share->auto_increment_mutex); + DBUG_PRINT("info",("spider before auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + *first_value = share->lgtm_tblhnd_share->auto_increment_lclval; + share->lgtm_tblhnd_share->auto_increment_lclval += + nb_desired_values * increment; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + if (auto_increment_mode != 1) + pthread_mutex_unlock(&share->lgtm_tblhnd_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->lgtm_tblhnd_share->auto_increment_mutex); + share->lgtm_tblhnd_share->auto_increment_lclval = value; + share->lgtm_tblhnd_share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + pthread_mutex_unlock(&share->lgtm_tblhnd_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, + uint flags +) +{ + 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; + bzero(©_info, sizeof(copy_info)); + 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, ©_info, TRUE))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +int ha_spider::write_row( + const 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); + } + if (!dml_inited) + { + if (unlikely((error_num = dml_init()))) + { + DBUG_RETURN(error_num); + } + } +#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT + ha_statistic_increment(&SSV::ha_write_count); +#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 *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 *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->lgtm_tblhnd_share->auto_increment_init) + { + pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex); + if (!share->lgtm_tblhnd_share->auto_increment_init) + { + info(HA_STATUS_AUTO); + share->lgtm_tblhnd_share->auto_increment_lclval = + stats.auto_increment_value; + share->lgtm_tblhnd_share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + } + pthread_mutex_unlock(&share->lgtm_tblhnd_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(wide_handler->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 = + (wide_handler->insert_with_update && + !result_list.insert_dup_update_pushdown) || + (!direct_dup_insert && wide_handler->ignore_dup_key) ? + 0 : spider_param_bulk_size(wide_handler->trx->thd, share->bulk_size); + else + bulk_size = 0; + } + if ((error_num = spider_db_bulk_insert(this, table, ©_info, FALSE))) + DBUG_RETURN(check_error_mode(error_num)); + + DBUG_RETURN(0); +} + + +void ha_spider::direct_update_init( + THD *thd, + bool hs_request +) { + DBUG_ENTER("ha_spider::direct_update_init"); + DBUG_PRINT("info",("spider this=%p", this)); + do_direct_update = TRUE; + DBUG_VOID_RETURN; +} + +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( + ha_rows *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); +} + +int 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)) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +#ifdef SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA +int ha_spider::bulk_update_row( + const uchar *old_data, + const uchar *new_data, + ha_rows *dup_key_found +) +#else +int ha_spider::bulk_update_row( + const uchar *old_data, + uchar *new_data, + ha_rows *dup_key_found +) +#endif +{ + 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)); +} + +#ifdef SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA +int ha_spider::update_row( + const uchar *old_data, + const uchar *new_data +) +#else +int ha_spider::update_row( + const uchar *old_data, + uchar *new_data +) +#endif +{ + 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); + } +#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT + ha_statistic_increment(&SSV::ha_update_count); +#endif + do_direct_update = FALSE; + 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->lgtm_tblhnd_share->auto_increment_mutex); + if (!share->lgtm_tblhnd_share->auto_increment_init) + { + info(HA_STATUS_AUTO); + share->lgtm_tblhnd_share->auto_increment_lclval = + stats.auto_increment_value; + share->lgtm_tblhnd_share->auto_increment_init = TRUE; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->lgtm_tblhnd_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->lgtm_tblhnd_share->auto_increment_lclval) + { + share->lgtm_tblhnd_share->auto_increment_lclval = tmp_auto_increment + 1; + share->lgtm_tblhnd_share->auto_increment_value = tmp_auto_increment + 1; + DBUG_PRINT("info",("spider after auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + } + pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + +bool ha_spider::check_direct_update_sql_part( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::check_direct_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 && + dbton_hdl->check_direct_update(select_lex, select_limit, offset_limit) + ) { + DBUG_RETURN(TRUE); + } + } + DBUG_RETURN(FALSE); +} + +/** + Perform initialization for a direct update request. + + @param update fields Pointer to the list of fields to update. + + @return >0 Error. + 0 Success. +*/ + +int ha_spider::direct_update_rows_init( + List *update_fields +) +{ + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + List_iterator it(*wide_handler->direct_update_fields); + Item *item; + Field *field; + THD *thd = wide_handler->trx->thd; + DBUG_ENTER("ha_spider::direct_update_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (thd->variables.time_zone != UTC) + { + while ((item = it++)) + { + if (item->type() == Item::FIELD_ITEM) + { + field = ((Item_field *)item)->field; + + if (field->type() == FIELD_TYPE_TIMESTAMP && + field->flags & UNIQUE_KEY_FLAG) + { + /* + Spider cannot perform direct update on unique timestamp fields. + To avoid false duplicate key errors, the table needs to be + updated one row at a time. + */ + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + } + } + if (!dml_inited) + { + if (unlikely(dml_init())) + { + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + direct_update_init( + thd, + FALSE + ); + if (!wide_handler->condition) + wide_handler->cond_check = FALSE; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + if (wide_handler->direct_update_fields) + { + if ( +#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + !select_lex || + select_lex->table_list.elements != 1 || + check_update_columns_sql_part() || + check_direct_update_sql_part(select_lex, select_limit, offset_limit) || + spider_db_append_condition(this, NULL, 0, TRUE) + ) { + DBUG_PRINT("info",("spider FALSE by condition")); + do_direct_update = FALSE; + 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")); + do_direct_update = FALSE; + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + result_list.direct_order_limit = TRUE; + } + wide_handler->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 sql_command=%u", wide_handler->sql_command)); + DBUG_PRINT("info",("spider do_direct_update=%s", + do_direct_update ? "TRUE" : "FALSE")); + if ( + !offset_limit && + do_direct_update + ) { + wide_handler->trx->direct_update_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); + } + DBUG_PRINT("info",("spider FALSE by default")); + do_direct_update = FALSE; + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + + +int ha_spider::direct_update_rows( + ha_rows *update_rows, + ha_rows *found_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); + } + if ((error_num= + spider_db_direct_update(this, table, update_rows, found_rows))) + DBUG_RETURN(check_error_mode(error_num)); + + DBUG_RETURN(0); +} + + +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); + } +#ifndef SPIDER_WITHOUT_HA_STATISTIC_INCREMENT + ha_statistic_increment(&SSV::ha_delete_count); +#endif + do_direct_update = FALSE; + if ((error_num = spider_db_delete(this, table, buf))) + DBUG_RETURN(check_error_mode(error_num)); + DBUG_RETURN(0); +} + +bool ha_spider::check_direct_delete_sql_part( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::check_direct_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 && + dbton_hdl->check_direct_delete(select_lex, select_limit, offset_limit) + ) { + DBUG_RETURN(TRUE); + } + } + DBUG_RETURN(FALSE); +} + +int ha_spider::direct_delete_rows_init() +{ + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + THD *thd = wide_handler->trx->thd; + DBUG_ENTER("ha_spider::direct_delete_rows_init"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!dml_inited) + { + if (unlikely(dml_init())) + { + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + direct_update_init( + thd, + FALSE + ); + if (!wide_handler->condition) + wide_handler->cond_check = FALSE; + spider_get_select_limit(this, &select_lex, &select_limit, &offset_limit); + if ( +#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + !select_lex || + select_lex->table_list.elements != 1 || + check_direct_delete_sql_part(select_lex, select_limit, offset_limit) || + spider_db_append_condition(this, NULL, 0, TRUE) + ) { + DBUG_PRINT("info",("spider FALSE by condition")); + do_direct_update = FALSE; + 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")); + do_direct_update = FALSE; + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + } + } + result_list.direct_order_limit = TRUE; + } + wide_handler->trx->direct_delete_count++; + DBUG_PRINT("info",("spider OK")); + DBUG_RETURN(0); +} + + +int ha_spider::direct_delete_rows( + ha_rows *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); + } + if ((error_num= spider_db_direct_delete(this, table, delete_rows))) + DBUG_RETURN(check_error_mode(error_num)); + + DBUG_RETURN(0); +} + + +int ha_spider::delete_all_rows() +{ + THD *thd = ha_thd(); + DBUG_ENTER("ha_spider::delete_all_rows"); + if (spider_param_delete_all_rows_type(thd, share->delete_all_rows_type)) + DBUG_RETURN(HA_ERR_WRONG_COMMAND); + DBUG_RETURN(truncate()); +} + +int ha_spider::truncate() +{ + int error_num; + 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); + } + wide_handler->sql_command = SQLCOM_TRUNCATE; + if ((error_num = spider_check_trx_and_get_conn(thd, this, FALSE))) + { + DBUG_RETURN(error_num); + } + do_direct_update = FALSE; + if ((error_num = spider_db_delete_all_rows(this))) + DBUG_RETURN(check_error_mode(error_num)); + if (wide_handler->sql_command == SQLCOM_TRUNCATE && + table->found_next_number_field) + { + DBUG_PRINT("info",("spider reset auto increment")); + pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex); + share->lgtm_tblhnd_share->auto_increment_lclval = 1; + share->lgtm_tblhnd_share->auto_increment_init = FALSE; + share->lgtm_tblhnd_share->auto_increment_value = 1; + DBUG_PRINT("info",("spider init auto_increment_lclval=%llu", + share->lgtm_tblhnd_share->auto_increment_lclval)); + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex); + } + DBUG_RETURN(0); +} + + +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->stat.records * share->stat.mean_rec_length + 2)); + DBUG_RETURN(share->scan_rate * share->stat.records * + share->stat.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 (wide_handler->keyread) + { + DBUG_PRINT("info",("spider read_time(keyread) = %.6f", + share->read_rate * table->key_info[index].key_length * + rows / 2 + 2)); + DBUG_RETURN(share->read_rate * table->key_info[index].key_length * + rows / 2 + 2); + } else { + DBUG_PRINT("info",("spider read_time = %.6f", + share->read_rate * share->stat.mean_rec_length * rows + 2)); + DBUG_RETURN(share->read_rate * share->stat.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); +} + +void ha_spider::print_error( + int error, + myf errflag +) { + DBUG_ENTER("ha_spider::print_error"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!current_thd->is_error()) + { + switch (error) + { + case ER_SPIDER_CON_COUNT_ERROR: + my_message(error, ER_SPIDER_CON_COUNT_ERROR_STR, MYF(0)); + break; + default: + handler::print_error(error, errflag); + break; + } + } + DBUG_VOID_RETURN; +} + +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, dummy; + SPIDER_SHARE tmp_share; + THD *thd = ha_thd(); + uint sql_command = thd_sql_command(thd), roop_count; + SPIDER_TRX *trx; + TABLE *table_tables = NULL; + SPIDER_Open_tables_backup open_tables_backup; + 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 (!is_supported_parser_charset(info->default_table_charset)) + { + String charset_option; + charset_option.append(STRING_WITH_LEN("CHARSET ")); + charset_option.append(info->default_table_charset->cs_name); + my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), "SPIDER", + charset_option.c_ptr()); + error_num= ER_ILLEGAL_HA_CREATE_OPTION; + goto error_charset; + } + 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((void*)&tmp_share, 0, sizeof(SPIDER_SHARE)); + tmp_share.table_name = (char*) name; + tmp_share.table_name_length = strlen(name); + tmp_share.table_name_hash_value = my_calc_hash(&trx->trx_alter_table_hash, + (uchar*) tmp_share.table_name, tmp_share.table_name_length); + tmp_share.lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share( + name, tmp_share.table_name_length, tmp_share.table_name_hash_value, + FALSE, TRUE, &error_num); + if (!tmp_share.lgtm_tblhnd_share) + { + goto error; + } + if (form->s->keys > 0) + { + if (!(tmp_share.static_key_cardinality = (longlong *) + spider_bulk_malloc(spider_current_trx, 246, MYF(MY_WME), + &tmp_share.static_key_cardinality, + (uint) (sizeof(*tmp_share.static_key_cardinality) * form->s->keys), + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + goto error; + } + if (!(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, + form->part_info, + 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 ( + thd->lex->create_info.or_replace() && + (error_num = spider_delete_tables( + table_tables, tmp_share.table_name, &dummy)) + ) { + 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; + } + 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))) + { + 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: %llu alter_info.partition_flags: %lu", + thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags)); + if ((thd->lex->alter_info.partition_flags & + ( + SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP | + SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE | + SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD + ) + ) && + 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; + } + } + + if ( + ( + (info->used_fields & HA_CREATE_USED_AUTO) || + sql_command == SQLCOM_ALTER_TABLE || + sql_command == SQLCOM_CREATE_INDEX || + sql_command == SQLCOM_RENAME_TABLE + ) && + info->auto_increment_value > 0 + ) { + pthread_mutex_lock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex); + tmp_share.lgtm_tblhnd_share->auto_increment_value = + info->auto_increment_value; + DBUG_PRINT("info",("spider auto_increment_value=%llu", + tmp_share.lgtm_tblhnd_share->auto_increment_value)); + pthread_mutex_unlock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex); + } + + if (tmp_share.static_key_cardinality) + spider_free(spider_current_trx, tmp_share.static_key_cardinality, MYF(0)); + 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); + if (tmp_share.lgtm_tblhnd_share) + spider_free_lgtm_tblhnd_share_alloc(tmp_share.lgtm_tblhnd_share, FALSE); + if (tmp_share.static_key_cardinality) + spider_free(spider_current_trx, tmp_share.static_key_cardinality, MYF(0)); + spider_free_share_alloc(&tmp_share); +error_alter_before_unlock: +error_get_trx: +error_charset: + 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 (wide_handler && wide_handler->sql_command == SQLCOM_ALTER_TABLE) + { + SPIDER_TRX *trx = wide_handler->trx; + THD *thd = trx->thd; + 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_VOID_RETURN; + } + } + } + + 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)); + if ( + !(create_info->used_fields & HA_CREATE_USED_AUTO) + ) { + info(HA_STATUS_AUTO); + create_info->auto_increment_value = stats.auto_increment_value; + } + 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), + to_len = strlen(to), tmp_error_num; + my_hash_value_type from_hash_value = my_calc_hash(&spider_open_tables, + (uchar*) from, from_len); + my_hash_value_type to_hash_value = my_calc_hash(&spider_open_tables, + (uchar*) to, to_len); + 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; + SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share; + SPIDER_Open_tables_backup open_tables_backup; + 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++) + { + if ((error_num = + spider_release_ping_table_mon_list(from, from_len, roop_count))) + { + goto error; + } + } + } else if (sql_command == SQLCOM_ALTER_TABLE) + { + 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) + { + DBUG_PRINT("info",("spider copy %d", roop_count)); + alter_table_from->tmp_link_statuses[roop_count] = + alter_table_to->tmp_link_statuses[roop_count]; + } + DBUG_PRINT("info",("spider link_status_from[%d]=%ld", roop_count, + alter_table_from->tmp_link_statuses[roop_count])); + DBUG_PRINT("info",("spider link_status_to[%d]=%ld", roop_count, + alter_table_to->tmp_link_statuses[roop_count])); + } + } + + DBUG_PRINT("info", + ("spider alter_info.flags: %llu alter_info.partition_flags: %lu", + thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags)); + if ( + (thd->lex->alter_info.partition_flags & + ( + SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP | + SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE | + SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD + ) + ) + ) + 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++) + { + if ((error_num = + spider_release_ping_table_mon_list(from, from_len, roop_count))) + { + goto error; + } + } + for (roop_count = 0; roop_count < old_link_count; roop_count++) + { + if ((error_num = + spider_release_ping_table_mon_list(to, to_len, roop_count))) + { + goto error; + } + } + } +/* + spider_free_trx_alter_table_alloc(trx, alter_table_from); +*/ + } + + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + from_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share( + from, from_len, from_hash_value, TRUE, FALSE, &error_num); + if (from_lgtm_tblhnd_share) + { + to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share( + to, to_len, to_hash_value, TRUE, TRUE, &error_num); + if (!to_lgtm_tblhnd_share) + { + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + goto error; + } + DBUG_PRINT("info", + ("spider auto_increment_init=%s", + from_lgtm_tblhnd_share->auto_increment_init ? "TRUE" : "FALSE")); + to_lgtm_tblhnd_share->auto_increment_init = + from_lgtm_tblhnd_share->auto_increment_init; + to_lgtm_tblhnd_share->auto_increment_lclval = + from_lgtm_tblhnd_share->auto_increment_lclval; + to_lgtm_tblhnd_share->auto_increment_value = + from_lgtm_tblhnd_share->auto_increment_value; + spider_free_lgtm_tblhnd_share_alloc(from_lgtm_tblhnd_share, TRUE); + } + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + 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); + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share( + to, to_len, to_hash_value, TRUE, FALSE, &tmp_error_num); + if (to_lgtm_tblhnd_share) + spider_free_lgtm_tblhnd_share_alloc(to_lgtm_tblhnd_share, TRUE); + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + 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; + SPIDER_Open_tables_backup open_tables_backup; + 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) + { + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; + int roop_count, old_link_count = 0, name_len = strlen(name); + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) name, name_len); + if ( + sql_command == SQLCOM_ALTER_TABLE && + (alter_table = + (SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value( + &trx->trx_alter_table_hash, + hash_value, (uchar*) name, name_len)) && + alter_table->now_create + ) + DBUG_RETURN(0); + + DBUG_PRINT("info", + ("spider alter_info.flags: %llu alter_info.partition_flags: %lu", + thd->lex->alter_info.flags, thd->lex->alter_info.partition_flags)); + if ( + sql_command == SQLCOM_ALTER_TABLE && + (thd->lex->alter_info.partition_flags & + ( + SPIDER_ALTER_PARTITION_ADD | SPIDER_ALTER_PARTITION_DROP | + SPIDER_ALTER_PARTITION_COALESCE | SPIDER_ALTER_PARTITION_REORGANIZE | + SPIDER_ALTER_PARTITION_TABLE_REORG | SPIDER_ALTER_PARTITION_REBUILD + ) + ) + ) + need_lock = TRUE; + + if ((error_num = spider_sys_delete_table_sts( + current_thd, name, name_len, need_lock))) + goto error; + if ((error_num = spider_sys_delete_table_crd( + current_thd, name, name_len, need_lock))) + goto error; + 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++) + { + if ((error_num = + spider_release_ping_table_mon_list(name, name_len, roop_count))) + goto error; + } + + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share( + name, name_len, hash_value, TRUE, FALSE, &error_num); + if (lgtm_tblhnd_share) + spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE); + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + } + + 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); +} + +#ifdef SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR +bool ha_spider::auto_repair(int error) const +#else +bool ha_spider::auto_repair() const +#endif +{ + 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::field_exchange( + Field *field +) { + DBUG_ENTER("ha_spider::field_exchange"); + DBUG_PRINT("info",("spider in field=%p", field)); + DBUG_PRINT("info",("spider in field->table=%p", field->table)); + DBUG_PRINT("info",("spider table=%p", table)); + if (field->table != table) + DBUG_RETURN(NULL); + 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"); + if ( + wide_handler->stage == SPD_HND_STAGE_COND_PUSH && + wide_handler->stage_executor != this) + { + DBUG_RETURN(NULL); + } + wide_handler->stage = SPD_HND_STAGE_COND_PUSH; + wide_handler->stage_executor = this; + wide_handler->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 = wide_handler->condition; + wide_handler->condition = tmp_cond; + } + DBUG_RETURN(NULL); +} + +void ha_spider::cond_pop() +{ + DBUG_ENTER("ha_spider::cond_pop"); + if ( + wide_handler->stage == SPD_HND_STAGE_COND_POP && + wide_handler->stage_executor != this) + { + DBUG_VOID_RETURN; + } + wide_handler->stage = SPD_HND_STAGE_COND_POP; + wide_handler->stage_executor = this; + if (wide_handler->condition) + { + SPIDER_CONDITION *tmp_cond = wide_handler->condition->next; + spider_free(spider_current_trx, wide_handler->condition, MYF(0)); + wide_handler->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)); + if ( + wide_handler->stage == SPD_HND_STAGE_INFO_PUSH && + wide_handler->stage_executor != this) + { + DBUG_RETURN(0); + } + wide_handler->stage = SPD_HND_STAGE_INFO_PUSH; + wide_handler->stage_executor = this; + + switch (info_type) + { +#ifdef INFO_KIND_UPDATE_FIELDS + case INFO_KIND_UPDATE_FIELDS: + DBUG_PRINT("info",("spider INFO_KIND_UPDATE_FIELDS")); + wide_handler->direct_update_fields = (List *) info; + wide_handler->update_request = TRUE; + if (wide_handler->keyread && check_partitioned()) + wide_handler->keyread = FALSE; + break; +#endif +#ifdef INFO_KIND_UPDATE_VALUES + case INFO_KIND_UPDATE_VALUES: + DBUG_PRINT("info",("spider INFO_KIND_UPDATE_VALUES")); + wide_handler->direct_update_values = (List *) info; + break; +#endif +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + case INFO_KIND_FORCE_LIMIT_BEGIN: + DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_BEGIN")); + wide_handler->info_limit = *((longlong *) info); + break; + case INFO_KIND_FORCE_LIMIT_END: + DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_END")); + wide_handler->info_limit = 9223372036854775807LL; + break; +#endif + default: + break; + } + DBUG_RETURN(error_num); +} + +void ha_spider::return_record_by_parent() +{ + DBUG_ENTER("ha_spider::return_record_by_parent"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_db_refetch_for_item_sum_funcs(this); + DBUG_VOID_RETURN; +} + +TABLE *ha_spider::get_table() +{ + DBUG_ENTER("ha_spider::get_table"); + DBUG_RETURN(table); +} + +void ha_spider::set_ft_discard_bitmap() +{ + DBUG_ENTER("ha_spider::set_ft_discard_bitmap"); + TABLE_LIST *table_list = spider_get_parent_table_list(this); + if (table_list) + { + st_select_lex *select_lex = table_list->select_lex; + if (select_lex && select_lex->ftfunc_list) + { + uint roop_count; + Field *field; + Item *item, *item_next; + Item_func_match *item_func_match; + Item_field *item_field; + { + List_iterator_fast fmi(*select_lex->ftfunc_list); + while ((item_func_match = fmi++)) + { + DBUG_PRINT("info",("spider item_func_match=%p", item_func_match)); + uint item_count = item_func_match->argument_count(); + Item **item_list = item_func_match->arguments(); + for (roop_count = 1; roop_count < item_count; roop_count++) + { + item_field = (Item_field *) item_list[roop_count]; + DBUG_PRINT("info",("spider item_field=%p", item_field)); + field = item_field->field; + DBUG_PRINT("info",("spider field=%p", field)); + if (!field || !(field = field_exchange(field))) + continue; + DBUG_PRINT("info",("spider clear_bit=%u", field->field_index)); + spider_clear_bit(wide_handler->ft_discard_bitmap, + field->field_index); + } + } + } + THD *thd = ha_thd(); + Statement *stmt = thd->stmt_map.find(thd->id); + if (stmt && stmt->free_list) + { + DBUG_PRINT("info",("spider item from stmt")); + item_next = stmt->free_list; + } else { + DBUG_PRINT("info",("spider item from thd")); + item_next = thd->free_list; + } + while ((item = item_next)) + { + DBUG_PRINT("info",("spider item=%p", item)); + DBUG_PRINT("info",("spider itemtype=%u", item->type())); + item_next = item->next; + if (item->type() != Item::FIELD_ITEM) + continue; + field = ((Item_field *) item)->field; + DBUG_PRINT("info",("spider field=%p", field)); + if (!field || !(field = field_exchange(field))) + continue; + DBUG_PRINT("info",("spider field_index=%u", field->field_index)); + if (!spider_bit_is_set(wide_handler->ft_discard_bitmap, + field->field_index)) + { + bool match_flag = FALSE; + List_iterator_fast fmi(*select_lex->ftfunc_list); + while ((item_func_match = fmi++)) + { + DBUG_PRINT("info",("spider item_func_match=%p", item_func_match)); + uint item_count = item_func_match->argument_count(); + Item **item_list = item_func_match->arguments(); + for (roop_count = 1; roop_count < item_count; roop_count++) + { + DBUG_PRINT("info",("spider item_list[%u]=%p", roop_count, + item_list[roop_count])); + if (item == item_list[roop_count]) + { + DBUG_PRINT("info",("spider matched")); + match_flag = TRUE; + break; + } + } + if (match_flag) + break; + } + if (!match_flag) + { + DBUG_PRINT("info",("spider set_bit=%u", field->field_index)); + spider_set_bit(wide_handler->ft_discard_bitmap, + field->field_index); + } + } + } + } + } + DBUG_VOID_RETURN; +} + +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++) + { + wide_handler->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", + wide_handler->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 (wide_handler->sql_command == SQLCOM_UPDATE || + wide_handler->sql_command == SQLCOM_UPDATE_MULTI) + { + DBUG_PRINT("info",("spider update option start")); + Item *item; + st_select_lex *select_lex = spider_get_select_lex(this); + List_iterator_fast fi(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(wide_handler->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"); + DBUG_PRINT("info",("spider searched_bitmap=%p", + wide_handler->searched_bitmap)); +#ifndef DBUG_OFF + int roop_count; + for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + DBUG_PRINT("info", ("spider before searched_bitmap is %x", + ((uchar *) wide_handler->searched_bitmap)[roop_count])); +#endif + memcpy(wide_handler->searched_bitmap, + pt_clone_source_handler->wide_handler->searched_bitmap, + (table_share->fields + 7) / 8); +#ifndef DBUG_OFF + for (roop_count = 0; roop_count < (int) ((table_share->fields + 7) / 8); + roop_count++) + DBUG_PRINT("info", ("spider after searched_bitmap is %x", + ((uchar *) wide_handler->searched_bitmap)[roop_count])); +#endif + memcpy(wide_handler->ft_discard_bitmap, + pt_clone_source_handler->wide_handler->ft_discard_bitmap, + (table_share->fields + 7) / 8); + DBUG_VOID_RETURN; +} + +void ha_spider::set_searched_bitmap_from_item_list() +{ + DBUG_ENTER("ha_spider::set_searched_bitmap_from_item_list"); + Field *field; + Item *item, *item_next; + THD *thd = ha_thd(); + Statement *stmt = thd->stmt_map.find(thd->id); + if (stmt && stmt->free_list) + { + DBUG_PRINT("info",("spider item from stmt")); + item_next = stmt->free_list; + } else { + DBUG_PRINT("info",("spider item from thd")); + item_next = thd->free_list; + } + while ((item = item_next)) + { + DBUG_PRINT("info",("spider item=%p", item)); + DBUG_PRINT("info",("spider itemtype=%u", item->type())); + item_next = item->next; + if (item->type() != Item::FIELD_ITEM) + continue; + field = ((Item_field *) item)->field; + DBUG_PRINT("info",("spider field=%p", field)); + if (!field || !(field = field_exchange(field))) + continue; + DBUG_PRINT("info",("spider field_index=%u", field->field_index)); + spider_set_bit(wide_handler->searched_bitmap, field->field_index); + } + 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 = wide_handler->trx->thd; + DBUG_ENTER("ha_spider::set_select_column_mode"); + wide_handler->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) + { + DBUG_PRINT("info",("spider searched_bitmap=%p", + wide_handler->searched_bitmap)); + set_searched_bitmap(); + set_searched_bitmap_from_item_list(); + if (wide_handler->external_lock_type == F_WRLCK && + wide_handler->sql_command != SQLCOM_SELECT) + { + uint part_num = 0; + if (wide_handler->update_request) + part_num = check_partitioned(); + if ( + part_num || + table_share->primary_key == MAX_KEY + ) { + /* need all columns */ + for (roop_count = 0; roop_count < (int) table_share->fields; + roop_count++) + spider_set_bit(wide_handler->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) spider_user_defined_key_parts(key_info); + roop_count++) + { + field = key_part[roop_count].field; + spider_set_bit(wide_handler->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", + wide_handler->searched_bitmap[roop_count])); +#endif + } + } + DBUG_VOID_RETURN; +} + +void ha_spider::check_select_column(bool rnd) +{ + THD *thd = wide_handler->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) + { + if (!rnd) + { + if (wide_handler->between_flg) + { + memcpy(wide_handler->idx_read_bitmap, + table->read_set->bitmap, (table_share->fields + 7) / 8); + memcpy(wide_handler->idx_write_bitmap, + table->write_set->bitmap, (table_share->fields + 7) / 8); + wide_handler->between_flg = FALSE; + wide_handler->idx_bitmap_is_set = TRUE; + DBUG_PRINT("info",("spider set idx_bitmap")); + } else if (wide_handler->idx_bitmap_is_set) + { + memcpy(table->read_set->bitmap, + wide_handler->idx_read_bitmap, + (table_share->fields + 7) / 8); + memcpy(table->write_set->bitmap, + wide_handler->idx_write_bitmap, + (table_share->fields + 7) / 8); + DBUG_PRINT("info",("spider copy idx_bitmap")); + } + } else { + if ( + !wide_handler->rnd_bitmap_is_set && + ( + wide_handler->between_flg || + wide_handler->idx_bitmap_is_set + ) + ) { + memcpy(wide_handler->rnd_read_bitmap, + table->read_set->bitmap, (table_share->fields + 7) / 8); + memcpy(wide_handler->rnd_write_bitmap, + table->write_set->bitmap, (table_share->fields + 7) / 8); + wide_handler->between_flg = FALSE; + wide_handler->rnd_bitmap_is_set = TRUE; + DBUG_PRINT("info",("spider set rnd_bitmap")); + } else if (wide_handler->rnd_bitmap_is_set) + { + memcpy(table->read_set->bitmap, + wide_handler->rnd_read_bitmap, + (table_share->fields + 7) / 8); + memcpy(table->write_set->bitmap, + wide_handler->rnd_write_bitmap, + (table_share->fields + 7) / 8); + DBUG_PRINT("info",("spider copy rnd_bitmap")); + } + } + } + DBUG_VOID_RETURN; +} + +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); + + if (!support_bulk_update_sql()) + { + result_list.bulk_update_mode = 0; + DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 1", + result_list.bulk_update_mode)); +/* + } else if ( + split_read != 9223372036854775807LL + ) { + result_list.bulk_update_mode = 2; + DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 2", + result_list.bulk_update_mode)); +*/ + } else { + if (result_list.bulk_update_start == SPD_BU_NOT_START) + { + result_list.bulk_update_mode = bulk_update_mode; + DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 3", + result_list.bulk_update_mode)); + } else { + result_list.bulk_update_mode = 1; + DBUG_PRINT("info",("spider result_list.bulk_update_mode=%d 4", + result_list.bulk_update_mode)); + } + } + 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; + ha_rows 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() +{ + 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; + } else + result_list.direct_order_limit = FALSE; + + spider_set_direct_limit_offset(this); + result_list.check_direct_order_limit = TRUE; + } + DBUG_VOID_RETURN; +} + +/******************************************************************** + * Check whether the current query is a SELECT DISTINCT using an + * index in a non-partitioned Spider configuration, with a + * projection list that consists solely of the first key prefix + * column. + * + * For a SELECT DISTINCT query using an index in a non-partitioned + * Spider configuration, with a projection list that consists + * solely of the first key prefix, set the internal row retrieval + * limit to avoid visiting each row multiple times. + ********************************************************************/ +void ha_spider::check_distinct_key_query() +{ + DBUG_ENTER( "ha_spider::check_distinct_key_query" ); + + if ( result_list.direct_distinct && !partition_handler->handlers && + result_list.keyread && result_list.check_direct_order_limit ) + { + // SELECT DISTINCT query using an index in a non-partitioned configuration + KEY_PART_INFO* key_part = result_list.key_info->key_part; + Field* key_field = key_part->field; + + if ( is_sole_projection_field( key_field->field_index ) ) + { + // Projection list consists solely of the first key prefix column + + // Set the internal row retrieval limit to avoid visiting each row + // multiple times. This fixes a Spider performance bug that + // caused each row to be visited multiple times. + result_list.internal_limit = 1; + } + } + + DBUG_VOID_RETURN; +} + +/******************************************************************** + * Determine whether the current query's projection list + * consists solely of the specified column. + * + * Params IN - field_index: + * Field index of the column of interest within + * its table. + * + * Returns TRUE - if the query's projection list consists + * solely of the specified column. + * FALSE - otherwise. + ********************************************************************/ +bool ha_spider::is_sole_projection_field( + uint16 field_index +) { + // NOTE: It is assumed that spider_db_append_select_columns() has already been called + // to build the bitmap of projection fields + bool is_ha_sole_projection_field; + uint loop_index, dbton_id; + spider_db_handler* dbton_hdl; + DBUG_ENTER( "ha_spider::is_sole_projection_field" ); + + for ( loop_index = 0; loop_index < share->use_sql_dbton_count; loop_index++ ) + { + dbton_id = share->use_sql_dbton_ids[ loop_index ]; + dbton_hdl = dbton_handler[ dbton_id ]; + + if ( dbton_hdl->first_link_idx >= 0 ) + { + is_ha_sole_projection_field = dbton_hdl->is_sole_projection_field( field_index ); + if ( !is_ha_sole_projection_field ) + { + DBUG_RETURN( FALSE ); + } + } + } + + DBUG_RETURN( TRUE ); +} + +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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL, roop_count))) + { + 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; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + error_num = tmp_error_num; + } + if (!tmp_error_num) + { + spider_conn_set_timeout_from_share(conn, roop_count, + wide_handler->trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL, + conn, + -1, + &need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + error_num = tmp_error_num; + } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +void ha_spider::set_error_mode() +{ + THD *thd = ha_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_BINLOG_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: + 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 +) { + THD* thd = ha_thd(); + LEX *lex = thd->lex; + st_select_lex *select_lex = spider_get_select_lex(this); + int skip_parallel_search = + spider_param_skip_parallel_search(thd, share->skip_parallel_search); + DBUG_ENTER("ha_spider::check_pre_call"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + ( + (skip_parallel_search & 1) && + lex->sql_command != SQLCOM_SELECT // such like insert .. select .. + ) || + ( + (skip_parallel_search & 2) && + lex->sql_cache == LEX::SQL_NO_CACHE // for mysqldump + ) + ) { + use_pre_call = FALSE; + DBUG_VOID_RETURN; + } + if ( + use_parallel && + thd->query_id != partition_handler->parallel_search_query_id + ) { + partition_handler->parallel_search_query_id = thd->query_id; + ++wide_handler->trx->parallel_search_count; + } + use_pre_call = use_parallel; + if (!use_pre_call) + { + longlong select_limit; + longlong offset_limit; + spider_get_select_limit_from_select_lex( + select_lex, &select_limit, &offset_limit); + if ( + select_lex && + (!select_lex->limit_params.explicit_limit || !select_limit) + ) { + use_pre_call = TRUE; + } + } + DBUG_VOID_RETURN; +} + +void ha_spider::check_insert_dup_update_pushdown() +{ + THD *thd = wide_handler->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; + } + wide_handler->direct_update_fields = &thd->lex->update_list; + wide_handler->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; +} + + +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; + dbton_hdl->strict_group_by = dbton_hdl2->strict_group_by; + } + 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; + dbton_hdl->strict_group_by = FALSE; + } + 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 (share->strict_group_bys[all_link_idx]) + { + dbton_hdl->strict_group_by = TRUE; + } + } + } + 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; + } + } + } + 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); +} + +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_union_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_union_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_union_table_and_sql_for_bka(start_key)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::reuse_union_table_and_sql_for_bka() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::reuse_union_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_union_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); +} + +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); +} + +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); +} + +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); +} + +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_union_table_connector_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_union_table_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_union_table_connector_part(sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_union_table_terminator_sql_part( + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_union_table_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_union_table_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_column_values_with_name_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_with_name_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_with_name_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); +} + +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_sum_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_sum_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_sum_select_part(sql_type, + alias, alias_length)) + ) { + 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_group_by_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_group_by_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_group_by_part( + alias, alias_length, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +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"); + if (result_list.direct_aggregate) + { + st_select_lex *select_lex = spider_get_select_lex(this); + ORDER *group = (ORDER *) select_lex->group_list.first; + if (!group && *(select_lex->join->sum_funcs)) + { + DBUG_PRINT("info",("spider skip order by")); + DBUG_RETURN(0); + } + } + 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"); + if (result_list.direct_aggregate) + { + st_select_lex *select_lex = spider_get_select_lex(this); + ORDER *group = (ORDER *) select_lex->group_list.first; + if (!group && *(select_lex->join->sum_funcs)) + { + DBUG_PRINT("info",("spider skip order by")); + DBUG_RETURN(0); + } + } + 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); +} + +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); +} + +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"); + 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); + } + } + 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_multi_range_cnt_with_name_sql_part( + ulong sql_type, + uint multi_range_cnt +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_multi_range_cnt_with_name_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_with_name_part( + sql_type, multi_range_cnt)) + ) { + 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 ( + !(error_num = tmp_table[roop_count]->file->ha_rnd_next( + tmp_table[roop_count]->record[0])) + ) { + 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) + ) { +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor + LEX_CSTRING field_name = {STRING_WITH_LEN("a")}; + if ( + !tmp_table[roop_count] && + !(tmp_table[roop_count] = spider_mk_sys_tmp_table( + wide_handler->trx->thd, table, + &result_list.upd_tmp_tbl_prms[roop_count], + &field_name, result_list.update_sqls[roop_count].charset())) + ) +#else + if ( + !tmp_table[roop_count] && + !(tmp_table[roop_count] = spider_mk_sys_tmp_table( + wide_handler->trx->thd, table, + &result_list.upd_tmp_tbl_prms[roop_count], "a", + result_list.update_sqls[roop_count].charset())) + ) +#endif + { + 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(wide_handler->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(wide_handler->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, NULL, this, str, + alias, alias_length, dbton_id, FALSE, NULL)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::init_union_table_name_pos_sql() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::init_union_table_name_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 && + (error_num = dbton_hdl->init_union_table_name_pos()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::set_union_table_name_pos_sql() +{ + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::set_union_table_name_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 && + (error_num = dbton_hdl->set_union_table_name_pos()) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int ha_spider::append_lock_tables_list() +{ + int error_num, roop_count; + DBUG_ENTER("ha_spider::append_lock_tables_list"); + DBUG_PRINT("info",("spider lock_table_type=%u", + wide_handler->lock_table_type)); + + if ((error_num = spider_check_trx_and_get_conn(wide_handler->trx->thd, this, + FALSE))) + { + DBUG_RETURN(error_num); + } + + if (wide_handler->lock_table_type == 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) + ) { + 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))) + { + DBUG_RETURN(error_num); + } + if (appended) + { + conn->table_lock = 2; + } + } + } else if (wide_handler->lock_table_type == 2) + { + 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(wide_handler->trx->thd, + share->semi_table_lock) + ) { + 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))) + { + DBUG_RETURN(error_num); + } + if (appended) + { + conn->table_lock = 3; + } + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::lock_tables() +{ + int error_num, roop_count; + DBUG_ENTER("ha_spider::lock_tables"); + DBUG_PRINT("info",("spider lock_table_type=%u", + wide_handler->lock_table_type)); + + 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 (wide_handler->sql_command != SQLCOM_UNLOCK_TABLES) + { + DBUG_PRINT("info",("spider conns[%d]->join_trx=%u", + roop_count, conns[roop_count]->join_trx)); + if ( + (!conns[roop_count]->join_trx && + (error_num = spider_internal_start_trx_for_connection(this, + conns[roop_count], + roop_count))) + ) { + if ( + share->monitoring_kind[roop_count] && + need_mons[roop_count] + ) { + error_num = spider_ping_table_mon_from_table( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + reset_first_link_idx(); + } + 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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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 (wide_handler->sql_command == SQLCOM_UNLOCK_TABLES || + spider_param_internal_unlock(wide_handler->trx->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( + wide_handler->trx, + wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + } + } + } + DBUG_RETURN(0); +} + +int ha_spider::dml_init() +{ + int error_num, roop_count; + SPIDER_TRX *trx = wide_handler->trx; + THD *thd = trx->thd; + bool sync_trx_isolation = spider_param_sync_trx_isolation(thd); + DBUG_ENTER("ha_spider::dml_init"); + if (wide_handler->lock_mode == -2) + { + wide_handler->lock_mode = spider_param_selupd_lock_mode(thd, + share->selupd_lock_mode); + } + if ((error_num = check_access_kind_for_connection(thd, + (wide_handler->lock_type >= TL_WRITE_ALLOW_WRITE)))) + { + DBUG_RETURN(error_num); + } + 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); + } + if (wide_handler->sql_command == SQLCOM_TRUNCATE) + 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 < (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) + ) { + DBUG_PRINT("info",("spider conns[%d]->join_trx=%u", + roop_count, conns[roop_count]->join_trx)); + if ( + (!conns[roop_count]->join_trx && + (error_num = spider_internal_start_trx_for_connection(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, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + 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 + ) { + spider_conn_queue_semi_trx_isolation(conns[roop_count], + spider_param_semi_trx_isolation(trx->thd)); + } 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, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(check_error_mode(error_num)); + } + } + conns[roop_count]->semi_trx_isolation = -1; + } + } + if (wide_handler->insert_with_update) + { + check_insert_dup_update_pushdown(); + } + dml_inited = TRUE; + DBUG_RETURN(0); +} + diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h new file mode 100644 index 00000000..4dffdf78 --- /dev/null +++ b/storage/spider/ha_spider.h @@ -0,0 +1,794 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019-2022 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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 final : public handler +{ +public: + SPIDER_SHARE *share; + ulonglong spider_thread_id; + ulonglong trx_conn_adjustment; + uint mem_calc_id; + const char *mem_calc_func_name; + const char *mem_calc_file_name; + ulong mem_calc_line_no; + ulonglong *connection_ids; + uint conn_kinds; + uint *conn_kind; + char *conn_keys_first_ptr; + char **conn_keys; + SPIDER_CONN **conns; + /* 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_string *blob_buff; + SPIDER_POSITION *pushed_pos; + SPIDER_POSITION pushed_pos_buf; + SPIDER_PARTITION_HANDLER *partition_handler; + bool wide_handler_owner = FALSE; + SPIDER_WIDE_HANDLER *wide_handler = NULL; + + bool is_clone; + ha_spider *pt_clone_source_handler; + ha_spider *pt_clone_last_searcher; + bool use_index_merge; + + bool init_index_handler; + bool init_rnd_handler; + + bool da_status; + bool use_spatial_index; + + uint idx_for_direct_join; + bool use_fields; + spider_fields *fields; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_LINK_IDX_CHAIN *result_link_idx_chain; + + /* for mrr */ + bool mrr_with_cnt; + uint multi_range_cnt; + uint multi_range_hit_point; + int multi_range_num; + bool have_second_range; + KEY_MULTI_RANGE mrr_second_range; + spider_string *mrr_key_buff; + range_id_t *multi_range_keys; + + char *append_tblnm_alias; + uint append_tblnm_alias_length; + + ha_spider *next; + + bool dml_inited; + bool rnd_scan_and_first; + bool use_pre_call; + bool use_pre_action; + bool pre_bitmap_checked; + bool bulk_insert; + bool info_auto_called; +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT + bool auto_inc_temporary; +#endif + int bulk_size; + int direct_dup_insert; + int store_error_num; + uint dup_key_idx; + int select_column_mode; + bool pk_update; + bool force_auto_increment; + int bka_mode; + int error_mode; + ulonglong store_last_insert_id; + + ulonglong *db_request_id; + uchar *db_request_phase; + bool do_direct_update; + uint direct_update_kinds; + spider_index_rnd_init prev_index_rnd_init; + SPIDER_ITEM_HLD *direct_aggregate_item_first; + SPIDER_ITEM_HLD *direct_aggregate_item_current; + ha_rows table_rows; + ha_checksum checksum_val; + bool checksum_null; + uint action_flags; + + /* 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; + + /* for direct limit offset */ + longlong direct_select_offset; + longlong direct_current_offset; + longlong direct_select_limit; + + 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_for_connection( + THD *thd, + bool write_request + ); + void check_access_kind( + THD *thd + ); + 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 start_stmt( + THD *thd, + thr_lock_type lock_type + ); + int reset(); + int extra( + enum ha_extra_function operation + ); + int index_init( + uint idx, + bool sorted + ); + int index_end(); + 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(); + void reset_no_where_cond(); + bool check_no_where_cond(); + 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 + ); + int multi_range_read_init( + RANGE_SEQ_IF *seq, + void *seq_init_param, + uint n_ranges, + uint mode, + HANDLER_BUFFER *buf + ); + 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 + ); + int rnd_init( + bool scan + ); + int rnd_end(); + 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 + ); + int pre_multi_range_read_next( + bool use_parallel + ); + 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, + const key_range *start_key, + const key_range *end_key, + page_range *pages + ); + int check_crd(); + int pre_records(); + ha_rows records(); + int pre_calculate_checksum(); + int calculate_checksum(); + const char *table_type() const; + ulonglong table_flags() const; + ulong table_flags_for_partition(); + 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(); + bool need_info_for_auto_inc(); +#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT + bool can_use_for_auto_inc_init(); +#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, + uint flags + ); + int end_bulk_insert(); + int write_row( + const uchar *buf + ); + void direct_update_init( + THD *thd, + bool hs_request + ); + bool start_bulk_update(); + int exec_bulk_update( + ha_rows *dup_key_found + ); + int end_bulk_update(); +#ifdef SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA + int bulk_update_row( + const uchar *old_data, + const uchar *new_data, + ha_rows *dup_key_found + ); + int update_row( + const uchar *old_data, + const uchar *new_data + ); +#else + int bulk_update_row( + const uchar *old_data, + uchar *new_data, + ha_rows *dup_key_found + ); + int update_row( + const uchar *old_data, + uchar *new_data + ); +#endif + bool check_direct_update_sql_part( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); + int direct_update_rows_init( + List *update_fields + ); + int direct_update_rows( + ha_rows *update_rows, + ha_rows *found_row + ); + bool start_bulk_delete(); + int end_bulk_delete(); + int delete_row( + const uchar *buf + ); + bool check_direct_delete_sql_part( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); + int direct_delete_rows_init(); + int direct_delete_rows( + ha_rows *delete_rows + ); + int delete_all_rows(); + int truncate(); + double scan_time(); + double read_time( + uint index, + uint ranges, + ha_rows rows + ); + const key_map *keys_to_use_for_scanning(); + ha_rows estimate_rows_upper_bound(); + void print_error( + int error, + myf errflag + ); + 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; +#ifdef SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR + bool auto_repair(int error) const; +#else + bool auto_repair() const; +#endif + 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 *field_exchange( + Field *field + ); + const COND *cond_push( + const COND* cond + ); + void cond_pop(); + int info_push( + uint info_type, + void *info + ); + void return_record_by_parent(); + TABLE *get_table(); + void set_ft_discard_bitmap(); + void set_searched_bitmap(); + void set_clone_searched_bitmap(); + void set_searched_bitmap_from_item_list(); + void set_select_column_mode(); + void check_select_column(bool rnd); + 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(); + void check_distinct_key_query(); + bool is_sole_projection_field( + uint16 field_index + ); + int drop_tmp_tables(); + 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 + ); + int ft_read_internal(uchar *buf); + int rnd_next_internal(uchar *buf); + void check_pre_call( + bool use_parallel + ); + void check_insert_dup_update_pushdown(); + 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 + ); + int append_tmp_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_tmp_table_and_sql_for_bka(); + int append_union_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_union_table_and_sql_for_bka(); + int append_insert_sql_part(); + int append_update_sql_part(); + int append_update_set_sql_part(); + int append_direct_update_set_sql_part(); + 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(); + 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_union_table_connector_sql_part( + ulong sql_type + ); + int append_union_table_terminator_sql_part( + ulong sql_type + ); + int append_key_column_values_sql_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_column_values_with_name_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 + ); + 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_sum_select_sql_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + 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_group_by_sql_part( + const char *alias, + uint alias_length, + 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 + ); + 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 + ); + 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_multi_range_cnt_with_name_sql_part( + ulong sql_type, + uint multi_range_cnt + ); + 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 + ); + int init_union_table_name_pos_sql(); + int set_union_table_name_pos_sql(); + int append_lock_tables_list(); + int lock_tables(); + int dml_init(); +}; 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..c19e376d --- /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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..c19e376d --- /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 00000000..c19e376d --- /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 00000000..c19e376d --- /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 00000000..e69de29b 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 00000000..26848294 --- /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 00000000..205eaa6f --- /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 00000000..55cb8583 --- /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 00000000..3ac4f97b --- /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 00000000..cf47099f --- /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 00000000..094d26b6 --- /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 00000000..78797d80 --- /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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..ee006858 --- /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 00000000..1c5a02d5 --- /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 00000000..e69de29b 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 00000000..a43e9956 --- /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 00000000..611ce601 --- /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 00000000..9f0b5e2f --- /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 00000000..05dbb1c3 --- /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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..e69de29b 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 00000000..d6e302a6 --- /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 00000000..73c3c6b9 --- /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 00000000..246099c6 --- /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 set 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 00000000..94a09fc3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/basic_sql.result @@ -0,0 +1,738 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table select test +connection master_1; +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 +connection master_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-01-01 00:00:00 +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 +connection master_1; +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' +connection master_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-01-01 00:00:00 +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 +connection master_1; +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 +connection master_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 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 +connection master_1; +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 +connection master_1; +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 +connection master_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 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 +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; +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 +connection master_1; +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 +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; +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 +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; +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 +connection master_1; +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 +connection master_1; +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 +connection master_1; +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 +connection master_1; +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 +connection master_1; +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 +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; +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 +connection master_1; +SELECT found_rows(); +found_rows() +5 + +select high_priority +connection master_1; +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 +connection master_1; +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 +connection master_1; +SELECT count(*) FROM ta_l ORDER BY a; +count(*) +5 + +select table join not use index +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; +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 +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; +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 +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; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +insert +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +connection master_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 + +insert select +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +connection master_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 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 +connection master_1; +TRUNCATE TABLE ta_l; +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'); +connection master_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 e 2008-01-01 23:59:59 + +insert low_priority +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +connection master_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 + +insert high_priority +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +connection master_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 + +insert ignore +connection master_1; +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' +connection master_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 + +insert update (insert) +connection master_1; +TRUNCATE TABLE ta_l; +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'; +connection master_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 + +insert update (update) +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'; +connection master_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 f 2005-08-08 11:11:11 + +replace +connection master_1; +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +connection master_1; +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +connection master_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 f 2008-02-02 02:02:02 + +replace select +connection master_1; +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +connection master_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 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 +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'); +connection master_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 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 +connection master_1; +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +connection master_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 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'); +connection master_1; +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +connection master_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 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +connection master_1; +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +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); +connection master_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 +connection master_1; +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +connection master_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 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +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; +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +connection master_1; +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +connection master_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 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +connection master_1; +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +connection master_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 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +connection master_1; +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +connection master_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 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +connection master_1; +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +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'); +connection master_1; +DELETE FROM ta_l WHERE a = 2; +connection master_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 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 +connection master_1; +DELETE FROM ta_l; +connection master_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') + +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'); +connection master_1; +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +connection master_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') +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'); +connection master_1; +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +connection master_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'); +connection master_1; +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +connection master_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') +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'); +connection master_1; +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE IGNORE FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE QUICK FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE FROM ta_l WHERE b = 'e'; +connection master_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') +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'); +connection master_1; +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +connection master_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') +10 j 2008-01-01 23:59:59 + +truncate +connection master_1; +TRUNCATE TABLE ta_l; +connection master_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') + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/basic_sql_part.result b/storage/spider/mysql-test/spider/bg/r/basic_sql_part.result new file mode 100644 index 00000000..0f402940 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/basic_sql_part.result @@ -0,0 +1,141 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection master_1; +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 with partition and select test +connection master_1; +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +connection master_1; +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 + +select partition using pushdown +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; +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 +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; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +update partition pushdown +connection master_1; +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +connection master_1; +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 +connection master_1; +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +connection master_1; +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 partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +connection master_1; +DELETE FROM ta_l2 WHERE b = 'g'; +connection master_1; +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; +connection master_1; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +connection master_1; +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 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..9a8660ba --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_aggregate.result @@ -0,0 +1,100 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table select test +connection master_1; +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 +connection master_1; +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 0 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_part.result b/storage/spider/mysql-test/spider/bg/r/direct_aggregate_part.result new file mode 100644 index 00000000..9d65fcc2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_aggregate_part.result @@ -0,0 +1,121 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +with partition test +connection master_1; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 4 +SELECT SUM(a) FROM ta_l2; +SUM(a) +15 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SET spider_direct_aggregate=0; +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SELECT SUM(a) FROM ta_l2; +SUM(a) +15 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +set spider_direct_aggregate=@old_spider_direct_aggregate; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..0e536d48 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_update.result @@ -0,0 +1,155 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table select test +connection master_1; +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 +connection master_1; +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 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_part.result b/storage/spider/mysql-test/spider/bg/r/direct_update_part.result new file mode 100644 index 00000000..7069cd72 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/direct_update_part.result @@ -0,0 +1,145 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +with partition test +connection master_1; +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 0 +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 2 +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 3 +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 5 +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 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 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 1 +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 3 +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 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 +4 d 2003-12-01 05:01:03 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..c088a8a9 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/function.result @@ -0,0 +1,160 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +in() +connection master_1; +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; +connection master_1; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +connection master_1; +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); +connection master_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 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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..3c37c2d5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/ha.result @@ -0,0 +1,286 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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-01-01 00:00:00 +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 +connection master_1; +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 +connection master_1; +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; +connection master_1; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +active standby test +create table test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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-01-01 00:00:00 +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 +connection master_1; +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_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_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 +connection master_1; +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"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; +connection master_1; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +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; +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; +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/ha_part.result b/storage/spider/mysql-test/spider/bg/r/ha_part.result new file mode 100644 index 00000000..39fa2655 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/ha_part.result @@ -0,0 +1,311 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table with partition test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_1; +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 +connection master_1; +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_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_l2#P#pt2 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_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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; + +create table with partition test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_1; +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 +connection master_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_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_l2#P#pt2 1 +auto_test_local ta_l2#P#pt2 0 +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_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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +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; +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; +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 00000000..aa734573 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result @@ -0,0 +1,224 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +3.1 +auto_increment +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +connection master_1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/spider3_fixes_part.result b/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result new file mode 100644 index 00000000..b793346d --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result @@ -0,0 +1,222 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +auto_increment with partition +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +connection master_1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..51045e0b --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider_fixes.result @@ -0,0 +1,616 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table and insert +connection master_1; +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 "<" +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; +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 "<=" +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; +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 +connection master_1; +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +connection master_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; +connection master_1; +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; +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +5 c 2001-12-31 23:59:59 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +2 b 2000-01-01 00:00:00 +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'; +a b c +2 b 2000-01-01 00:00:00 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +connection master_1; +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;; +connection master_1; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +connection master_1; +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 +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); +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 + +2.23 +index merge +connection master_1; +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; +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; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +connection master_1; +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 +1 2 3 +2 3 4 +3 4 5 +4 5 6 +5 6 7 +6 7 8 +7 8 9 +8 9 10 +9 10 11 +10 11 12 +11 12 13 +12 13 14 +13 14 15 +14 15 16 +15 16 17 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (18, 2, 3); +connection master_1; +UPDATE ta_l_int SET c = 4 WHERE b = 2; +connection master_1; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +1 2 4 +2 3 4 +3 4 5 +4 5 6 +5 6 7 +6 7 8 +7 8 9 +8 9 10 +9 10 11 +10 11 12 +11 12 13 +12 13 14 +13 14 15 +14 15 16 +15 16 17 +16 17 18 +17 2 4 +18 2 4 + +2.25 +direct order limit +connection master_1; +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 +3 4 5 +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 3 + +2.26 +lock tables +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 +connection master_1; + +read only +connection master_1; +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 +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +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 = 777; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 777; +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 +connection master_1; +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 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 +connection master_1; +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; +connection master_1; +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 +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; +connection master_1; +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_part.result b/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result new file mode 100644 index 00000000..faf0b6ef --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result @@ -0,0 +1,237 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection master_1; +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'); + +2.17 +partition with sort +connection master_1; +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 +connection master_1; +DROP TABLE IF EXISTS ta_l2; +connection master_1; +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 with partition +connection master_1; +DROP TABLE IF EXISTS ta_l_int; +connection master_1; +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; +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; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.26 +auto_increment with partition +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 +connection master_1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..cc0e4105 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/r/vp_fixes.result @@ -0,0 +1,93 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table and insert +connection master_1; +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 +connection master_1; +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 +connection master_1; +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +connection master_1; +DROP TABLE IF EXISTS ta_l_int; +connection master_1; +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 +connection master_1; +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..672a3b37 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/suite.opt @@ -0,0 +1 @@ +--loose-innodb --loose-skip-performance-schema 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 00000000..171fa6c4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/suite.pm @@ -0,0 +1,11 @@ +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; + +sub is_default { 1 } + +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 00000000..f680cd43 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/basic_sql.test @@ -0,0 +1,2701 @@ +# This test tests by executing basic SQL +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT found_rows(); +--enable_ps2_protocol + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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/basic_sql_part.test b/storage/spider/mysql-test/spider/bg/t/basic_sql_part.test new file mode 100644 index 00000000..1bb18358 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/basic_sql_part.test @@ -0,0 +1,571 @@ +# This test tests by executing basic SQL +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +--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, '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'); + +--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 command_type != 'Execute' AND argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 00000000..cd9b0c9c --- /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 00000000..e145f66b --- /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 00000000..d356348d --- /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 00000000..03e5c188 --- /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 00000000..d62a7ada --- /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 00000000..fb49f5bf --- /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 00000000..0c129ce5 --- /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 00000000..45a82274 --- /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 00000000..4b330692 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_aggregate.test @@ -0,0 +1,181 @@ +--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 + +--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 +--disable_ps2_protocol +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; +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + 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_aggregate_part.test b/storage/spider/mysql-test/spider/bg/t/direct_aggregate_part.test new file mode 100644 index 00000000..af35adb0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_aggregate_part.test @@ -0,0 +1,210 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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 + --disable_ps2_protocol + set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; + set spider_direct_aggregate=1; + + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT SUM(a) 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; + --enable_ps2_protocol + + SET spider_direct_aggregate=0; + SELECT COUNT(*) FROM ta_l2; + SELECT SUM(a) FROM ta_l2; + SELECT MAX(a) FROM ta_l2; + SELECT MIN(a) FROM ta_l2; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + + set spider_direct_aggregate=@old_spider_direct_aggregate; + 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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 00000000..94f27e28 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_update.test @@ -0,0 +1,198 @@ +--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 + +--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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + 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_part.test b/storage/spider/mysql-test/spider/bg/t/direct_update_part.test new file mode 100644 index 00000000..e8f18825 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/direct_update_part.test @@ -0,0 +1,211 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 00000000..2472e774 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/function.test @@ -0,0 +1,253 @@ +# This test tests for using functions +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 00000000..1924b908 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/ha.test @@ -0,0 +1,882 @@ +# This test tests for ha features +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 + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +eval $MASTER_1_CHANGE_HA_MON; +--enable_ps2_protocol + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +eval $MASTER_1_CHANGE_HA_MON; +--enable_ps2_protocol + +--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_part.test b/storage/spider/mysql-test/spider/bg/t/ha_part.test new file mode 100644 index 00000000..33fe9850 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/ha_part.test @@ -0,0 +1,1017 @@ +# This test tests for ha features +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 + } + } +} + +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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 00000000..53d0409d --- /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 00000000..70576ab1 --- /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 00000000..64bef749 --- /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 00000000..e0823e73 --- /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 00000000..b6e69947 --- /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 00000000..32de484b --- /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 00000000..7ec2e981 --- /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 00000000..831bf479 --- /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 00000000..e9d99b7a --- /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 00000000..739d8897 --- /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 00000000..64d3b657 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider3_fixes.test @@ -0,0 +1,294 @@ +# This test tests for Spider 3.0's bug fixes +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 + +--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; +--disable_ps_protocol +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +--enable_ps_protocol +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 command_type != 'Execute' AND 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 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/spider3_fixes_part.test b/storage/spider/mysql-test/spider/bg/t/spider3_fixes_part.test new file mode 100644 index 00000000..bcd85f42 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider3_fixes_part.test @@ -0,0 +1,347 @@ +# This test tests for Spider 3.0's bug fixes +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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; + --disable_ps_protocol + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + --enable_ps_protocol + 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 00000000..061dbac2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider_fixes.test @@ -0,0 +1,1427 @@ +# This test tests for Spider's bug fixes +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 + +--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 +--disable_ps2_protocol +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.23 +--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 command_type != 'Execute' AND 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 (18, 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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; +--disable_ps2_protocol +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +--enable_ps2_protocol +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; +--disable_ps_protocol +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +--enable_ps_protocol +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 command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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/spider_fixes_part.test b/storage/spider/mysql-test/spider/bg/t/spider_fixes_part.test new file mode 100644 index 00000000..e6c4456e --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/spider_fixes_part.test @@ -0,0 +1,647 @@ +# This test tests for Spider's bug fixes +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +--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'); + +--echo +--echo 2.17 +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo 2.26 +--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; + --disable_ps_protocol + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + --enable_ps_protocol + 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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/test_deinit.inc b/storage/spider/mysql-test/spider/bg/t/test_deinit.inc new file mode 100644 index 00000000..989bde26 --- /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 00000000..f2cd6c02 --- /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 00000000..2c3e1523 --- /dev/null +++ b/storage/spider/mysql-test/spider/bg/t/vp_fixes.test @@ -0,0 +1,335 @@ +# This test tests for VP's bug fixes +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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/bugfix/disabled.def b/storage/spider/mysql-test/spider/bugfix/disabled.def new file mode 100644 index 00000000..3fd0a2d4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/disabled.def @@ -0,0 +1,3 @@ +wait_timeout : MDEV-26045 +mdev_29904 : MDEV-31101 +mdev_27239: MDEV-32046 diff --git a/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_deinit.inc new file mode 100644 index 00000000..47f6df94 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc new file mode 100644 index 00000000..a5dc920e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/checksum_table_with_quick_mode_3_init.inc @@ -0,0 +1,29 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%checksum %'; +--connection master_1 +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; diff --git a/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc new file mode 100644 index 00000000..930cde88 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_deinit.inc @@ -0,0 +1,13 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc new file mode 100644 index 00000000..5ef1c301 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/cp932_column_init.inc @@ -0,0 +1,29 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + txt_utf8 char(8) NOT NULL, + txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE DEFAULT CHARACTER SET utf8; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, txt_utf8, txt_cp932 FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND (argument LIKE '%insert %' OR argument LIKE '%update %'); +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_deinit.inc new file mode 100644 index 00000000..4fd217a5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_deinit.inc @@ -0,0 +1,4 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--source delete_with_float_column_deinit.inc diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_init.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_init.inc new file mode 100644 index 00000000..872dd9c0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_default_init.inc @@ -0,0 +1,32 @@ +--source delete_with_float_column_init.inc +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +if ($VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", + host "localhost", + database "auto_test_remote", + user "root", + password "", + port "$CHILD2_1_MYPORT"'; +} +if (!$VERSION_COMPILE_OS_WIN) +{ + let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", + host "localhost", + database "auto_test_remote", + user "root", + password "", + socket "$CHILD2_1_MYSOCK"'; +} +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + f float DEFAULT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_deinit.inc new file mode 100644 index 00000000..4ea789fe --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_deinit.inc @@ -0,0 +1,13 @@ +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--connection master_1 +set session binlog_format= @old_binlog_format; +--connection slave1_1 +--disable_warnings +--disable_query_log +--disable_result_log +--source ../include/deinit_spider.inc +--source ../t/slave_test_deinit.inc +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_init.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_init.inc new file mode 100644 index 00000000..b08c9fb1 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_init.inc @@ -0,0 +1,24 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--source ../t/slave_test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, f FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; +--connection slave1_1 +--disable_warnings +--disable_query_log +--disable_result_log +--source ../include/init_spider.inc +--enable_result_log +--enable_query_log +--enable_warnings +--connection master_1 +set @old_binlog_format= @@binlog_format; +set session binlog_format= 'ROW'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_deinit.inc new file mode 100644 index 00000000..4fd217a5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_deinit.inc @@ -0,0 +1,4 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--source delete_with_float_column_deinit.inc diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_init.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_init.inc new file mode 100644 index 00000000..9d396149 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mariadb_init.inc @@ -0,0 +1,14 @@ +--source delete_with_float_column_init.inc +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1", wrapper "mariadb"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + f float DEFAULT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_deinit.inc new file mode 100644 index 00000000..4fd217a5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_deinit.inc @@ -0,0 +1,4 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--source delete_with_float_column_deinit.inc diff --git a/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_init.inc b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_init.inc new file mode 100644 index 00000000..d98f3c12 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/delete_with_float_column_mysql_init.inc @@ -0,0 +1,16 @@ +--source delete_with_float_column_init.inc +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1", wrapper "mysql"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a $STR_SEMICOLON + DROP FUNCTION to_float; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + f float DEFAULT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE FUNCTION to_float(a decimal(20,6)) RETURNS float RETURN cast(a as double); diff --git a/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_deinit.inc new file mode 100644 index 00000000..27682e43 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_deinit.inc @@ -0,0 +1,9 @@ +--connection child2_1 +DROP USER tu@'%'; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_init.inc b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_init.inc new file mode 100644 index 00000000..c87af2d0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_comma_pwd_init.inc @@ -0,0 +1,11 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +let $DIRECT_SQL_COMMAND= + SELECT spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test", password "pass,1234", user "tu"'); +--connection child2_1 +GRANT ALL ON *.* TO tu@'%' IDENTIFIED BY 'pass,1234'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_deinit.inc new file mode 100644 index 00000000..ecb5622a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_deinit.inc @@ -0,0 +1,7 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_init.inc b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_init.inc new file mode 100644 index 00000000..7b58bd3e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/direct_sql_with_tmp_table_init.inc @@ -0,0 +1,9 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +let $DIRECT_SQL_COMMAND= + SELECT spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test"'); diff --git a/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc new file mode 100644 index 00000000..9d255152 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc new file mode 100644 index 00000000..b11ac98d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc @@ -0,0 +1,54 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/insert_select_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/insert_select_deinit.inc new file mode 100644 index 00000000..b8b2f200 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/insert_select_deinit.inc @@ -0,0 +1,16 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_1_2= $MASTER_1_COMMENT_2_1_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_DROP_TABLES2= $CHILD2_1_DROP_TABLES2_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES2= $CHILD2_1_CREATE_TABLES2_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/insert_select_init.inc b/storage/spider/mysql-test/spider/bugfix/include/insert_select_init.inc new file mode 100644 index 00000000..972fdb7e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/insert_select_init.inc @@ -0,0 +1,43 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_1_2_BACKUP= $MASTER_1_COMMENT_2_1_2 +let $MASTER_1_COMMENT_2_1_2= + COMMENT='table "tbl_b", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_DROP_TABLES2_BACKUP= $CHILD2_1_DROP_TABLES2 +let $CHILD2_1_DROP_TABLES2= + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt,tm) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_CREATE_TABLES2_BACKUP= $CHILD2_1_CREATE_TABLES2 +let $CHILD2_1_CREATE_TABLES2= + CREATE TABLE tbl_b ( + pkey int NOT NULL, + dt datetime NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (dt) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, dt FROM tbl_b ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_deinit.inc new file mode 100644 index 00000000..9d255152 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_init.inc new file mode 100644 index 00000000..379cb0fb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_19866_init.inc @@ -0,0 +1,52 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + val char(1) NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, val FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + val char(1) NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, val FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_deinit.inc new file mode 100644 index 00000000..1880a1c7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_init.inc new file mode 100644 index 00000000..ca71d739 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_20100_init.inc @@ -0,0 +1,46 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1 +let $MASTER_1_COMMENT_P_2_1= + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', + PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', + PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r2 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r3 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r4; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r3 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r4 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT a, b, c FROM ta_r2 ORDER BY a $STR_SEMICOLON + SELECT a, b, c FROM ta_r3 ORDER BY a $STR_SEMICOLON + SELECT a, b, c FROM ta_r4 ORDER BY a; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_init.inc new file mode 100644 index 00000000..924d3b72 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_20502_init.inc @@ -0,0 +1,25 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + val int(10) unsigned DEFAULT NULL, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT id, val FROM tbl_a ORDER BY id; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_deinit.inc new file mode 100644 index 00000000..74efe3a2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_bgs_mode= @old_spider_bgs_mode; +set session spider_quick_mode= @old_spider_quick_mode; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_init.inc new file mode 100644 index 00000000..68a496a7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_21884_init.inc @@ -0,0 +1,57 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1 +let $MASTER_1_COMMENT_P_2_1= + COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( + PARTITION pt1 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r2", + priority "1000"', + PARTITION pt2 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", priority "1000001"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r2 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r3; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + txt char(8) NOT NULL, + PRIMARY KEY (pkey, txt) + ) $CHILD2_1_ENGINE DEFAULT CHARACTER SET utf8; +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r2 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a,b) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r3 ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a,b) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, txt FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_TABLES= + SELECT a, b, c FROM ta_r2 ORDER BY a $STR_SEMICOLON + SELECT a, b, c FROM ta_r3 ORDER BY a; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 2; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc new file mode 100644 index 00000000..9d255152 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc new file mode 100644 index 00000000..48226ba2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22246_init.inc @@ -0,0 +1,48 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY HASH(id) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT * FROM tbl_a ORDER BY id; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_deinit.inc new file mode 100644 index 00000000..ecb5622a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_deinit.inc @@ -0,0 +1,7 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_init.inc new file mode 100644 index 00000000..6cf6b0c1 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_22265_init.inc @@ -0,0 +1,7 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_deinit.inc new file mode 100644 index 00000000..1880a1c7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_init.inc new file mode 100644 index 00000000..63fd70a4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24020_init.inc @@ -0,0 +1,43 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1 +let $MASTER_1_COMMENT_P_2_1= + PARTITION BY LIST(a % 3) ( + PARTITION pt1 VALUES IN (0) COMMENT='srv "s_2_1", table "ta_r2"', + PARTITION pt2 VALUES IN (1) COMMENT='srv "s_2_1", table "ta_r3"', + PARTITION pt3 VALUES IN (2) COMMENT='srv "s_2_1", table "ta_r4"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r2 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r3 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r4; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r2 ( + a INT, + b VARCHAR(30), + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r3 ( + a INT, + b VARCHAR(30), + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r4 ( + a INT, + b VARCHAR(30), + PRIMARY KEY(a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT a, b FROM ta_r2 ORDER BY a $STR_SEMICOLON + SELECT a, b FROM ta_r3 ORDER BY a $STR_SEMICOLON + SELECT a, b FROM ta_r4 ORDER BY a; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_deinit.inc new file mode 100644 index 00000000..1880a1c7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_init.inc new file mode 100644 index 00000000..b5b77a53 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24517_init.inc @@ -0,0 +1,43 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1 +let $MASTER_1_COMMENT_P_2_1= + PARTITION BY RANGE(i) ( + PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', + PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', + PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS ta_r2 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r3 $STR_SEMICOLON + DROP TABLE IF EXISTS ta_r4; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r2 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r3 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r4 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT i, j FROM ta_r2 ORDER BY i $STR_SEMICOLON + SELECT i, j FROM ta_r3 ORDER BY i $STR_SEMICOLON + SELECT i, j FROM ta_r4 ORDER BY i; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_deinit.inc new file mode 100644 index 00000000..e8d30523 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_deinit.inc @@ -0,0 +1,9 @@ +--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_init.inc b/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_init.inc new file mode 100644 index 00000000..989faa54 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/mdev_24523_init.inc @@ -0,0 +1,31 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1 +let $MASTER_1_COMMENT_P_2_1= + PARTITION BY RANGE(i) ( + PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', + PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', + PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ); +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE ta_r2 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r3 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE ta_r4 ( + i INT, + j JSON, + PRIMARY KEY(i) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_deinit.inc new file mode 100644 index 00000000..42124a79 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_deinit.inc @@ -0,0 +1,19 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_2= $MASTER_1_COMMENT_2_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_init.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_init.inc new file mode 100644 index 00000000..2ff26472 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_0_init.inc @@ -0,0 +1,51 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_2_BACKUP= $MASTER_1_COMMENT_2_2 +let $MASTER_1_COMMENT_2_2= + COMMENT='table "tbl_b", srv "s_2_2"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_b ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 0; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; +let $MASTER_1_SET_QUICK_PAGE_BYTE_6= + set session spider_quick_page_byte= 6; +let $MASTER_1_SET_QUICK_PAGE_BYTE_0= + set session spider_quick_page_byte= 0; diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_deinit.inc new file mode 100644 index 00000000..42124a79 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_deinit.inc @@ -0,0 +1,19 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_2= $MASTER_1_COMMENT_2_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_init.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_init.inc new file mode 100644 index 00000000..2120fdaa --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_1_init.inc @@ -0,0 +1,51 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_2_BACKUP= $MASTER_1_COMMENT_2_2 +let $MASTER_1_COMMENT_2_2= + COMMENT='table "tbl_b", srv "s_2_2"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_b ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 1; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; +let $MASTER_1_SET_QUICK_PAGE_BYTE_6= + set session spider_quick_page_byte= 6; +let $MASTER_1_SET_QUICK_PAGE_BYTE_0= + set session spider_quick_page_byte= 0; diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_deinit.inc new file mode 100644 index 00000000..42124a79 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_deinit.inc @@ -0,0 +1,19 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_2= $MASTER_1_COMMENT_2_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_init.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_init.inc new file mode 100644 index 00000000..0f0644c8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_2_init.inc @@ -0,0 +1,51 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_2_BACKUP= $MASTER_1_COMMENT_2_2 +let $MASTER_1_COMMENT_2_2= + COMMENT='table "tbl_b", srv "s_2_2"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_b ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 2; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; +let $MASTER_1_SET_QUICK_PAGE_BYTE_6= + set session spider_quick_page_byte= 6; +let $MASTER_1_SET_QUICK_PAGE_BYTE_0= + set session spider_quick_page_byte= 0; diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_deinit.inc new file mode 100644 index 00000000..42124a79 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_deinit.inc @@ -0,0 +1,19 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_2= $MASTER_1_COMMENT_2_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection master_1 +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_init.inc b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_init.inc new file mode 100644 index 00000000..9556d2e4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/quick_mode_3_init.inc @@ -0,0 +1,51 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_2_BACKUP= $MASTER_1_COMMENT_2_2 +let $MASTER_1_COMMENT_2_2= + COMMENT='table "tbl_b", srv "s_2_2"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_b ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; +let $MASTER_1_SET_QUICK_PAGE_BYTE_6= + set session spider_quick_page_byte= 6; +let $MASTER_1_SET_QUICK_PAGE_BYTE_0= + set session spider_quick_page_byte= 0; diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc new file mode 100644 index 00000000..e383327b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_insert_init.inc @@ -0,0 +1,27 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + PRIMARY KEY (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND (argument LIKE '%insert %' OR argument LIKE '%replace %'); +--let $MASTER_1_SET_COMMAND=set session spider_direct_dup_insert=1 $STR_SEMICOLON diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc new file mode 100644 index 00000000..e0c25939 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/return_found_rows_update_init.inc @@ -0,0 +1,26 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT skey, dt, tm FROM tbl_a ORDER BY skey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/same_server_link_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/same_server_link_deinit.inc new file mode 100644 index 00000000..a4e8a10d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/same_server_link_deinit.inc @@ -0,0 +1,11 @@ +--connection master_1 +set global spider_same_server_link= @old_global_spider_same_server_link; +set session spider_same_server_link= @old_session_spider_same_server_link; +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/same_server_link_init.inc b/storage/spider/mysql-test/spider/bugfix/include/same_server_link_init.inc new file mode 100644 index 00000000..2c8150c9 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/same_server_link_init.inc @@ -0,0 +1,15 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_b", host "127.0.0.1", port "$MASTER_1_MYPORT", user "root"'; +--connection master_1 +set @old_global_spider_same_server_link= @@global.spider_same_server_link; +set @old_session_spider_same_server_link= @@session.spider_same_server_link; +set global spider_same_server_link= 0; +set session spider_same_server_link= 0; diff --git a/storage/spider/mysql-test/spider/bugfix/include/select_by_null_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/select_by_null_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/select_by_null_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/select_by_null_init.inc b/storage/spider/mysql-test/spider/bugfix/include/select_by_null_init.inc new file mode 100644 index 00000000..3a5f91de --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/select_by_null_init.inc @@ -0,0 +1,24 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_init.inc b/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_init.inc new file mode 100644 index 00000000..41c4fd3a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/select_with_backquote_init.inc @@ -0,0 +1,25 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + txt_utf8 char(8) NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE DEFAULT CHARACTER SET utf8; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, txt_utf8 FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/self_reference_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/self_reference_deinit.inc new file mode 100644 index 00000000..34376d50 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/self_reference_deinit.inc @@ -0,0 +1,10 @@ +--connection master_1 +set spider_same_server_link= @old_spider_same_server_link; +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/self_reference_init.inc b/storage/spider/mysql-test/spider/bugfix/include/self_reference_init.inc new file mode 100644 index 00000000..b7e2c4d0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/self_reference_init.inc @@ -0,0 +1,13 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", host "127.0.0.1", port "$MASTER_1_MYPORT", user "root"'; +--connection master_1 +set @old_spider_same_server_link= @@spider_same_server_link; +set spider_same_server_link= ON; diff --git a/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_deinit.inc new file mode 100644 index 00000000..5ac67cdf --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_deinit.inc @@ -0,0 +1,10 @@ +--connection slave1_1 +--disable_warnings +--disable_query_log +--disable_result_log +--source ../include/deinit_spider.inc +--source ../t/slave_test_deinit.inc +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_init.inc b/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_init.inc new file mode 100644 index 00000000..052d6ebb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/slave_transaction_retry_errors_5digit_init.inc @@ -0,0 +1,10 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--source ../t/slave_test_init.inc +--connection slave1_1 +--source ../include/init_spider.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_deinit.inc new file mode 100644 index 00000000..7c20b2bc --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_deinit.inc @@ -0,0 +1,15 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--connection slave1_1 +set global spider_slave_trx_isolation= @old_spider_slave_trx_isolation; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../include/deinit_spider.inc +--source ../t/slave_test_deinit.inc +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_init.inc b/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_init.inc new file mode 100644 index 00000000..bfdb0831 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/slave_trx_isolation_init.inc @@ -0,0 +1,35 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--source ../t/slave_test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%set %'; +--connection slave1_1 +--disable_warnings +--disable_query_log +--disable_result_log +--source ../include/init_spider.inc +--enable_result_log +--enable_query_log +--enable_warnings +set @old_spider_slave_trx_isolation= @@spider_slave_trx_isolation; +set global spider_slave_trx_isolation= 1; diff --git a/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc new file mode 100644 index 00000000..01645e85 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_deinit.inc @@ -0,0 +1,12 @@ +--connection master_1 +alter table mysql.spider_table_sts add column checksum bigint unsigned default null after update_time; +DROP DATABASE IF EXISTS auto_test_local; + +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc new file mode 100644 index 00000000..1e438812 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/spider_table_sts_init.inc @@ -0,0 +1,13 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", host "127.0.0.1", port "$MASTER_1_MYPORT", user "root"'; +--connection master_1 +alter table mysql.spider_table_sts drop column checksum; +insert into mysql.spider_table_sts values ('auto_test_local', 'tbl_a', 0, 0, 0, 0, 0, '2019-01-01 00:00:00', '2019-01-01 00:00:00', '2019-01-01 00:00:00'); diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_deinit.inc new file mode 100644 index 00000000..07f4d39a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_deinit.inc @@ -0,0 +1,13 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--connection master_1 +set session sql_mode= @old_sql_mode; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_init.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_init.inc new file mode 100644 index 00000000..09ab2934 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_init.inc @@ -0,0 +1,40 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $SQL_MODES= real_as_float,pipes_as_concat,ansi_quotes,ignore_space,ignore_bad_table_options,only_full_group_by,no_unsigned_subtraction,no_dir_in_create,postgresql,oracle,mssql,db2,maxdb,no_key_options,no_table_options,no_field_options,mysql323,mysql40,ansi,no_auto_value_on_zero,no_backslash_escapes,strict_trans_tables,strict_all_tables,no_zero_in_date,no_zero_date,allow_invalid_dates,error_for_division_by_zero,traditional,no_auto_create_user,high_not_precedence,no_engine_substitution,pad_char_to_full_length +if (`SELECT IF(STRCMP('$SERVER_NAME', 'MariaDB') = 0, 1, 0)`) +{ + if (`SELECT IF($SERVER_MAJOR_VERSION = 10, 1, 0)`) + { + if (`SELECT IF($SERVER_MINOR_VERSION >= 3, 1, 0)`) + { + --let $SQL_MODES= $SQL_MODES,empty_string_is_null,simultaneous_assignment + } + if (`SELECT IF($SERVER_MINOR_VERSION >= 4, 1, 0)`) + { + --let $SQL_MODES= $SQL_MODES,time_round_fractional + } + } +} +--connection master_1 +set @old_sql_mode= @@sql_mode; +eval set session sql_mode= '$SQL_MODES'; +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%sql_mode%'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_deinit.inc new file mode 100644 index 00000000..0dbff811 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_deinit.inc @@ -0,0 +1 @@ +--source sql_mode_deinit.inc diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_init.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_init.inc new file mode 100644 index 00000000..8e03b94b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mariadb_init.inc @@ -0,0 +1,3 @@ +--source sql_mode_init.inc +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1", wrapper "mariadb"'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_deinit.inc new file mode 100644 index 00000000..0dbff811 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_deinit.inc @@ -0,0 +1 @@ +--source sql_mode_deinit.inc diff --git a/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_init.inc b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_init.inc new file mode 100644 index 00000000..2cdd56bc --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/sql_mode_mysql_init.inc @@ -0,0 +1,3 @@ +--source sql_mode_init.inc +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1", wrapper "mysql"'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_deinit.inc new file mode 100644 index 00000000..2b0f9cbb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_deinit.inc @@ -0,0 +1,18 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection child2_1 +set global sql_mode= @old_sql_mode; +--connection master_1 +set session spider_sync_sql_mode= @old_spider_sync_sql_mode; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_init.inc b/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_init.inc new file mode 100644 index 00000000..e4614c87 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/strict_group_by_init.inc @@ -0,0 +1,60 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source strict_group_by_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--connection master_1 +set @old_spider_sync_sql_mode= @@spider_sync_sql_mode; +set session spider_sync_sql_mode= FALSE; +--connection child2_1 +set @old_sql_mode= @@sql_mode; +set global sql_mode= 'ONLY_FULL_GROUP_BY'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc new file mode 100644 index 00000000..e66247c8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_deinit.inc @@ -0,0 +1,18 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--connection child2_1 +set global wait_timeout= @old_wait_timeout; +--connection child2_2 +set global wait_timeout= @old_wait_timeout; +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc new file mode 100644 index 00000000..b98f7216 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wait_timeout_init.inc @@ -0,0 +1,56 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source wait_timeout_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; +--connection child2_1 +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; +--connection child2_2 +set @old_wait_timeout= @@wait_timeout; +set global wait_timeout= 1; diff --git a/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_init.inc b/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_init.inc new file mode 100644 index 00000000..80c5440f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/wrapper_mariadb_init.inc @@ -0,0 +1,24 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1", wrapper "mariadb"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_deinit.inc new file mode 100644 index 00000000..76b7582a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_init.inc b/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_init.inc new file mode 100644 index 00000000..025ed835 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/xa_cmd_init.inc @@ -0,0 +1,24 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; diff --git a/storage/spider/mysql-test/spider/bugfix/my.cnf b/storage/spider/mysql-test/spider/bugfix/my.cnf new file mode 100644 index 00000000..b7f76a63 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/my_1_1.cnf b/storage/spider/mysql-test/spider/bugfix/my_1_1.cnf new file mode 100644 index 00000000..5f17295d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_1_1.cnf @@ -0,0 +1,44 @@ +[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 + +[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 + +STR_SEMICOLON= ; + +#The followings are set 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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_2_1.cnf b/storage/spider/mysql-test/spider/bugfix/my_2_1.cnf new file mode 100644 index 00000000..24161645 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_2_1.cnf @@ -0,0 +1,56 @@ +[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 + +[ENV] +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_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_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 + +#The followings are set in include/init_xxx.inc files +# 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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_2_2.cnf b/storage/spider/mysql-test/spider/bugfix/my_2_2.cnf new file mode 100644 index 00000000..2d3c2a89 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_2_2.cnf @@ -0,0 +1,38 @@ +[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 + +[ENV] +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_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_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 + +#The followings are set in include/init_xxx.inc files +# CHILD2_2_DROP_TABLES +# CHILD2_2_CREATE_TABLES +# CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/bugfix/my_2_3.cnf b/storage/spider/mysql-test/spider/bugfix/my_2_3.cnf new file mode 100644 index 00000000..024da651 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_2_3.cnf @@ -0,0 +1,8 @@ +[mysqld.2.3] + +[ENV] +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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_3_1.cnf b/storage/spider/mysql-test/spider/bugfix/my_3_1.cnf new file mode 100644 index 00000000..fad21607 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_3_1.cnf @@ -0,0 +1,11 @@ +[mysqld.3.1] +loose_partition= 1 + +[ENV] +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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_3_2.cnf b/storage/spider/mysql-test/spider/bugfix/my_3_2.cnf new file mode 100644 index 00000000..6f027b6f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_3_2.cnf @@ -0,0 +1,9 @@ +[mysqld.3.2] +loose_partition= 1 + +[ENV] +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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_3_3.cnf b/storage/spider/mysql-test/spider/bugfix/my_3_3.cnf new file mode 100644 index 00000000..fbb33694 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_3_3.cnf @@ -0,0 +1,9 @@ +[mysqld.3.3] +loose_partition= 1 + +[ENV] +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 diff --git a/storage/spider/mysql-test/spider/bugfix/my_4_1.cnf b/storage/spider/mysql-test/spider/bugfix/my_4_1.cnf new file mode 100644 index 00000000..d1812a48 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/my_4_1.cnf @@ -0,0 +1,9 @@ +[mysqld.4.1] +loose_partition= 1 + +[ENV] +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 diff --git a/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result b/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result new file mode 100644 index 00000000..033e1593 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/checksum_table_with_quick_mode_3.result @@ -0,0 +1,100 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; + +this test is for MDEV-16279 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +FLUSH TABLES; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +CHECKSUM TABLE tbl_a EXTENDED; +Table Checksum +auto_test_local.tbl_a 1061386331 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%checksum %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result b/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result new file mode 100644 index 00000000..c0566840 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/cp932_column.result @@ -0,0 +1,84 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18992 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +txt_utf8 char(8) NOT NULL, +txt_cp932 char(8) NOT NULL COLLATE cp932_japanese_ci, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE DEFAULT CHARACTER SET utf8 MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'',''),(1,'',''),(2,'',''),(3,'',''),(4,'',''),(5,'',''),(6,'',''),(7,'',''),(8,'',''),(9,'',''); +FLUSH TABLES; + +test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SET NAMES cp932; +INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (10,'','’†‘'); +INSERT INTO tbl_a (pkey,txt_utf8,txt_cp932) VALUES (0,'','') ON DUPLICATE KEY UPDATE txt_cp932 = '’†‘'; +UPDATE tbl_a SET txt_cp932 = '’†‘' WHERE pkey = 2; +SET NAMES utf8; +connection child2_1; +SET NAMES cp932; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND (argument LIKE '%insert %' OR argument LIKE '%update %'); +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`,`txt_utf8`,`txt_cp932`)values(10,'',_cp932'\\x92\\x86\\x8D\\x91') +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`txt_utf8`,`txt_cp932`)values(0,'',_cp932'') on duplicate key update `txt_cp932` = _cp932'\x92\x86\x8D\x91' +update `auto_test_remote`.`tbl_a` set `txt_cp932` = _cp932'\x92\x86\x8D\x91' where (`pkey` = 2) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND (argument LIKE '%insert %' OR argument LIKE '%update %') +SELECT pkey, txt_utf8, txt_cp932 FROM tbl_a ORDER BY pkey; +pkey txt_utf8 txt_cp932 +0 ’†‘ +1 +2 ’†‘ +3 +4 +5 +6 +7 +8 +9 +10 ’†‘ +SET NAMES utf8; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/ddl_log.result b/storage/spider/mysql-test/spider/bugfix/r/ddl_log.result new file mode 100644 index 00000000..2abbcc6b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/ddl_log.result @@ -0,0 +1,12 @@ +# restart: --plugin-load-add=ha_spider +# +# MDEV-32532 Assertion failure in ddl_log_increment_phase_no_lock upon +# partition operations with spider plugin loaded +# +CREATE TABLE t1 (a INT) PARTITION BY HASH (a) PARTITIONS 2; +ALTER TABLE t1 REBUILD PARTITION p0; +drop table t1; +# +# End of 10.10 +# +uninstall plugin spider; diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result new file mode 100644 index 00000000..cb1b190f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result @@ -0,0 +1,85 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +for slave1_1 +connection slave1_1; +connection master_1; +set @old_binlog_format= @@binlog_format; +set session binlog_format= 'ROW'; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SET SESSION sql_log_bin= 1; +connection slave1_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +connection master_1; +INSERT INTO tbl_a (pkey, f) VALUES (0,NULL); +INSERT INTO tbl_a (pkey, f) VALUES (1,0.671437); +DELETE FROM tbl_a WHERE pkey = 0; +DELETE FROM tbl_a WHERE pkey = 1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; +argument +delete from `auto_test_remote`.`tbl_a` where `pkey` = 0 and `f` is null limit 1 +delete from `auto_test_remote`.`tbl_a` where `pkey` = 1 and `f` = cast(0.671437 as float) limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %' +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f +connection slave1_1; +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session binlog_format= @old_binlog_format; +connection slave1_1; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result new file mode 100644 index 00000000..cb1b190f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result @@ -0,0 +1,85 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +for slave1_1 +connection slave1_1; +connection master_1; +set @old_binlog_format= @@binlog_format; +set session binlog_format= 'ROW'; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SET SESSION sql_log_bin= 1; +connection slave1_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +connection master_1; +INSERT INTO tbl_a (pkey, f) VALUES (0,NULL); +INSERT INTO tbl_a (pkey, f) VALUES (1,0.671437); +DELETE FROM tbl_a WHERE pkey = 0; +DELETE FROM tbl_a WHERE pkey = 1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; +argument +delete from `auto_test_remote`.`tbl_a` where `pkey` = 0 and `f` is null limit 1 +delete from `auto_test_remote`.`tbl_a` where `pkey` = 1 and `f` = cast(0.671437 as float) limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %' +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f +connection slave1_1; +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session binlog_format= @old_binlog_format; +connection slave1_1; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result new file mode 100644 index 00000000..11310212 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result @@ -0,0 +1,85 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +for slave1_1 +connection slave1_1; +connection master_1; +set @old_binlog_format= @@binlog_format; +set session binlog_format= 'ROW'; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SET SESSION sql_log_bin= 1; +connection slave1_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +f float DEFAULT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +connection master_1; +INSERT INTO tbl_a (pkey, f) VALUES (0,NULL); +INSERT INTO tbl_a (pkey, f) VALUES (1,0.671437); +DELETE FROM tbl_a WHERE pkey = 0; +DELETE FROM tbl_a WHERE pkey = 1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; +argument +delete from `auto_test_remote`.`tbl_a` where `pkey` = 0 and `f` is null limit 1 +delete from `auto_test_remote`.`tbl_a` where `pkey` = 1 and `f` = /* create function to_float(a decimal(20,6)) returns float return a */ to_float(0.671437) limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %' +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f +connection slave1_1; +SELECT pkey, f FROM tbl_a ORDER BY pkey; +pkey f + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session binlog_format= @old_binlog_format; +connection slave1_1; +for slave1_1 +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_comma_pwd.result b/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_comma_pwd.result new file mode 100644 index 00000000..b485d645 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_comma_pwd.result @@ -0,0 +1,37 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +GRANT ALL ON *.* TO tu@'%' IDENTIFIED BY 'pass,1234'; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TEMPORARY TABLE tmp_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 +SELECT spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test", password "pass,1234", user "tu"'); +spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test", password "pass,1234", user "tu"') +1 +SELECT pkey FROM tmp_a; +pkey +22 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP USER tu@'%'; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_tmp_table.result b/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_tmp_table.result new file mode 100644 index 00000000..65beb8a4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/direct_sql_with_tmp_table.result @@ -0,0 +1,33 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TEMPORARY TABLE tmp_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 +SELECT spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test"'); +spider_direct_sql('SELECT 22', 'tmp_a', 'srv "s_2_1", database "test"') +1 +SELECT pkey FROM tmp_a; +pkey +22 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result b/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result new file mode 100644 index 00000000..e9054a17 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result @@ -0,0 +1,126 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-16520 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +skey int NOT NULL, +PRIMARY KEY (pkey), +KEY idx1 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,skey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_a (pkey,skey) VALUES (10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19); +INSERT INTO tbl_a (pkey,skey) VALUES (20,5),(21,6),(22,7),(23,8),(24,9),(25,10),(26,11),(27,12),(28,13),(29,14); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; +skey cnt +14 2 +13 2 +12 2 +11 2 +10 2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 60 +set spider_direct_aggregate=@old_spider_direct_aggregate; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote`.`tbl_a` group by `skey` order by `skey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +1 1 +3 3 +5 5 +7 7 +9 9 +11 11 +13 13 +15 15 +17 17 +19 19 +21 6 +23 8 +25 10 +27 12 +29 14 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote2`.`tbl_a` group by `skey` order by `skey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +0 0 +2 2 +4 4 +6 6 +8 8 +10 10 +12 12 +14 14 +16 16 +18 18 +20 5 +22 7 +24 9 +26 11 +28 13 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/index.result b/storage/spider/mysql-test/spider/bugfix/r/index.result new file mode 100644 index 00000000..801fec2e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/index.result @@ -0,0 +1,57 @@ +for master_1 +for child2 +for child3 +create database auto_test_local; +set spider_same_server_link= on; +# +# MDEV-27590 Auto-increment on Spider tables with DESC PK does not work properly +# +select @@spider_auto_increment_mode; +@@spider_auto_increment_mode +0 +create or replace table auto_test_local.t (id int primary key) engine=InnoDB; +create or replace table t_sp1 (id int auto_increment, primary key(id desc)) +engine=Spider COMMENT='wrapper "mysql", srv "s_1", table "t"'; +insert into t_sp1 () values (),(),(); +insert into t_sp1 () values (),(),(); +select * from t_sp1; +id +1 +2 +3 +4 +5 +6 +drop table t_sp1, auto_test_local.t; +# +# MDEV-27581 Wrong result with DESC key on partitioned Spider table +# +create table auto_test_local.t1 (a int primary key); +create table auto_test_local.t2 (a int primary key); +create table t (a int, primary key (a desc)) engine=spider +engine=spider comment='wrapper "mysql", srv "s_1"' +partition by range (a) +(partition p1 values less than (4) comment "table 't1'", +partition p2 values less than (maxvalue) comment "table 't2'"); +insert into t values (1),(2),(10),(11); +select * from t where a > 1 order by a; +a +2 +10 +11 +drop table t, auto_test_local.t1, auto_test_local.t2; +# +# MDEV-27617 HANDLER KEY > (x) does not work with DESC keys, Spider is affected and returns wrong results +# +create table auto_test_local.t (a int, b char(1), primary key(a desc)); +insert into auto_test_local.t VALUES (1,'f'),(2,'g'),(3,'j'), (4,'i'),(5,'h'); +create table ts (a int, b char(1), primary key(a desc)) +engine=spider comment='wrapper "mysql", srv "s_1", table "t"'; +select a, b from ts where a > 0 and b = 'g' order by a; +a b +2 g +drop table ts, auto_test_local.t; +drop database auto_test_local; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/insert_select.result b/storage/spider/mysql-test/spider/bugfix/r/insert_select.result new file mode 100644 index 00000000..670777d9 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/insert_select.result @@ -0,0 +1,102 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-16399 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES2 +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +skey int NOT NULL, +dt date NOT NULL, +tm time NOT NULL, +KEY idx1 (skey,dt,tm) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +dt datetime NOT NULL, +PRIMARY KEY (pkey), +KEY idx1 (dt) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2 +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(1, '2013-02-01', '13:00:00'),(2, '2013-03-01', '13:00:00'),(3, '2013-04-01', '13:00:00'),(4, '2013-05-01', '13:00:00'),(5, '2013-06-01', '13:00:00'),(6, '2013-07-01', '13:00:00'),(7, '2013-08-01', '13:00:00'),(8, '2013-09-01', '13:00:00'),(9, '2013-10-01', '13:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-11-01', '11:00:00'),(1, '2012-12-01', '11:00:00'),(2, '2012-11-30', '11:00:00'),(3, '2012-11-29', '11:00:00'),(4, '2012-11-28', '11:00:00'),(5, '2012-11-27', '11:00:00'),(6, '2012-11-26', '11:00:00'),(7, '2012-11-25', '11:00:00'),(8, '2012-11-24', '11:00:00'),(9, '2012-11-23', '11:00:00'); +FLUSH TABLES; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 4 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 3 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 2 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 1 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 0 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 9 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 8 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 7 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 6 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 5 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 4) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 3) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 2) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 1) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 0) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 9) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 8) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 7) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 6) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +select t0.`skey` `skey`,cast((concat(t0.`dt` , _latin1' ' , t0.`tm`)) as datetime) `CAST(CONCAT(dt, ' ', tm) AS datetime)` from `auto_test_remote`.`tbl_a` t0 where ((t0.`skey` = 5) and (t0.`dt` > _latin1'2012-11-21')) lock in share mode +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, dt FROM tbl_b ORDER BY pkey; +pkey dt +0 2013-01-01 13:00:00 +1 2012-12-01 11:00:00 +2 2012-11-30 11:00:00 +3 2012-11-29 11:00:00 +4 2012-11-28 11:00:00 +5 2012-11-27 11:00:00 +6 2012-11-26 11:00:00 +7 2012-11-25 11:00:00 +8 2012-11-24 11:00:00 +9 2012-11-23 11:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result new file mode 100644 index 00000000..dbf0f54c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result @@ -0,0 +1,111 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-19866 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val char(1) NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (1,'1'),(2,'2'),(3,'3'),(4,'4'); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_a; +pkey val +1 1 +3 3 +2 2 +4 4 +SELECT * FROM tbl_a WHERE pkey = 1; +pkey val +1 1 +SELECT * FROM tbl_a; +pkey val +1 1 +3 3 +2 2 +4 4 +SELECT * FROM tbl_a WHERE pkey = 2; +pkey val +2 2 +SELECT * FROM tbl_a; +pkey val +1 1 +3 3 +2 2 +4 4 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey`,`val` from `auto_test_remote`.`tbl_a` +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 +select `pkey`,`val` from `auto_test_remote`.`tbl_a` +select `pkey`,`val` from `auto_test_remote`.`tbl_a` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +2 2 +4 4 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_20100.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_20100.result new file mode 100644 index 00000000..52876c34 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_20100.result @@ -0,0 +1,119 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-20100 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) ENGINE=Spider PARTITION BY RANGE(a) ( +PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', +PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', +PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ) +INSERT INTO tbl_a (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'); + +test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a, b, c FROM tbl_a PARTITION (pt2) WHERE b = 'c'; +a b c +5 c 2001-12-31 23:59:59 +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt2); +a b c +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +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, c FROM tbl_a PARTITION (pt3) WHERE b = 'c'; +a b c +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt2); +a b c +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +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, c FROM tbl_a PARTITION (pt1) WHERE b = 'c'; +a b c +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt3); +a b c +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +SELECT a, b, c FROM tbl_a PARTITION (pt1) WHERE b = 'c'; +a b c +SELECT a, b, c FROM tbl_a PARTITION (pt2,pt3); +a b c +5 c 2001-12-31 23:59:59 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r3` t0 where (t0.`b` = 'c') +select `a`,`b`,`c` from `auto_test_remote`.`ta_r2` +select `a`,`b`,`c` from `auto_test_remote`.`ta_r3` +select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r4` t0 where (t0.`b` = 'c') +select `a`,`b`,`c` from `auto_test_remote`.`ta_r2` +select `a`,`b`,`c` from `auto_test_remote`.`ta_r3` +select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r2` t0 where (t0.`b` = 'c') +select `a`,`b`,`c` from `auto_test_remote`.`ta_r2` +select `a`,`b`,`c` from `auto_test_remote`.`ta_r4` +select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r2` t0 where (t0.`b` = 'c') +select `a`,`b`,`c` from `auto_test_remote`.`ta_r3` +select `a`,`b`,`c` from `auto_test_remote`.`ta_r4` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, c FROM ta_r2 ORDER BY a ; +SELECT a, b, c FROM ta_r3 ORDER BY a ; +SELECT a, b, c FROM ta_r4 ORDER BY a; +a b c +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +4 d 2003-11-30 05:01:03 +a b c +5 c 2001-12-31 23:59:59 +a b c + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_20502.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_20502.result new file mode 100644 index 00000000..ee06e449 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_20502.result @@ -0,0 +1,85 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-20502 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +id int(10) unsigned NOT NULL AUTO_INCREMENT, +val int(10) unsigned DEFAULT NULL, +PRIMARY KEY(id) +) ENGINE=Spider COMMENT='table "tbl_a", srv "s_2_1"' +INSERT INTO tbl_a (val) VALUES (1); + +test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT id, 0 AS const, val FROM tbl_a; +id const val +1 0 1 +SELECT 1+2, id, 0 AS const, val, val+10, (SELECT tbl_a.val+1 FROM tbl_a) AS sq +FROM tbl_a; +1+2 id const val val+10 sq +3 1 0 1 11 2 +INSERT INTO tbl_a (val) VALUES (2), (1); +SELECT val+10, 0 AS const, val, (SELECT tbl_a.val+1 FROM tbl_a LIMIT 1) AS sq +FROM tbl_a GROUP BY val; +val+10 const val sq +11 0 1 2 +12 0 2 2 +SELECT MAX(id) AS m, 0 AS const, val, (SELECT tbl_a.val+1 FROM tbl_a LIMIT 1) AS sq +FROM tbl_a GROUP BY val; +m const val sq +3 0 1 2 +2 0 2 2 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`id` `id`,t0.`val` `val` from `auto_test_remote`.`tbl_a` t0 +select t0.`id` `id`,t0.`val` `val`,(t0.`val` + 10) `val+10` from `auto_test_remote`.`tbl_a` t0 +select (t0.`val` + 1) `tbl_a.val+1` from `auto_test_remote`.`tbl_a` t0 +select `id`,`val` from `auto_test_remote`.`tbl_a` order by `id` desc limit 1 for update +select (t0.`val` + 10) `val+10`,t0.`val` `val` from `auto_test_remote`.`tbl_a` t0 group by t0.`val` order by t0.`val` +select (t0.`val` + 1) `tbl_a.val+1` from `auto_test_remote`.`tbl_a` t0 limit 1 +select max(t0.`id`) `m`,t0.`val` `val` from `auto_test_remote`.`tbl_a` t0 group by t0.`val` order by t0.`val` +select (t0.`val` + 1) `tbl_a.val+1` from `auto_test_remote`.`tbl_a` t0 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT id, val FROM tbl_a ORDER BY id; +id val +1 1 +2 2 +3 1 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_21884.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_21884.result new file mode 100644 index 00000000..7a9c58e6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_21884.result @@ -0,0 +1,104 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode= 2; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; + +this test is for MDEV-21884 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a,b) +) ENGINE=Spider COMMENT='table "ta_r3"' + PARTITION BY RANGE(a) ( +PARTITION pt1 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r2", + priority "1000"', +PARTITION pt2 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", priority "1000001"' + ) +CREATE TABLE tb_l ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE2 MASTER_1_CHARSET2 +INSERT INTO tbl_a (a, b, c) VALUES +(11, 'a', '2008-08-01 10:21:39'), +(11, 'b', '2000-01-01 00:00:00'), +(12, 'e', '2007-06-04 20:03:11'), +(12, 'd', '2003-11-30 05:01:03'), +(13, 'c', '2001-12-31 23:59:59'); +INSERT INTO tb_l (a, b, c) VALUES +(11, 'a', '2008-08-01 10:21:39'), +(12, 'b', '2000-01-01 00:00:00'), +(13, 'e', '2007-06-04 20:03:11'), +(14, 'd', '2003-11-30 05:01:03'), +(15, 'c', '2001-12-31 23:59:59'); + +test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT STRAIGHT_JOIN b.a, b.b FROM tb_l a, tbl_a b WHERE a.a = b.a; +a b +11 a +11 b +12 d +12 e +13 c +connection child2_1; +SET NAMES utf8; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `a`,`b` from `auto_test_remote`.`ta_r2` order by `a`,`b` +select `a`,`b` from `auto_test_remote`.`ta_r3` order by `a`,`b` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, c FROM ta_r2 ORDER BY a ; +SELECT a, b, c FROM ta_r3 ORDER BY a; +a b c +a b c +11 a 2008-08-01 10:21:39 +11 b 2000-01-01 00:00:00 +12 d 2003-11-30 05:01:03 +12 e 2007-06-04 20:03:11 +13 c 2001-12-31 23:59:59 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_bgs_mode= @old_spider_bgs_mode; +set session spider_quick_mode= @old_spider_quick_mode; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result new file mode 100644 index 00000000..0254d8bf --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_22246.result @@ -0,0 +1,79 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-22246 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +id bigint NOT NULL, +node text, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_a; +id node +2 DB-G1 +1 DB-G0 +SELECT * FROM tbl_a WHERE id <0 || id >0; +id node +1 DB-G0 +2 DB-G1 +connection child2_1; +SELECT * FROM tbl_a ORDER BY id; +id node +2 DB-G1 +connection child2_2; +SELECT * FROM tbl_a ORDER BY id; +id node +1 DB-G0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_22265.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_22265.result new file mode 100644 index 00000000..0331943a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_22265.result @@ -0,0 +1,23 @@ +for master_1 +for child2 +for child3 + +this test is for MDEV-22265 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; + +create table +connection master_1; +create table t2345678911234567892123456789312345678941234567895123(id int) ENGINE=SPIDER DEFAULT CHARSET=latin1 COMMENT='host "h114", user "spider", password "spider", port "3306", database "test32738"'; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +for master_1 +for child2 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_22979.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_22979.result new file mode 100644 index 00000000..b3049af3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_22979.result @@ -0,0 +1,5 @@ +MDEV-22979 "mysqld --bootstrap" / mysql_install_db hangs when Spider is installed +# Kill the server +# restart +Warnings: +Note 1305 SONAME ha_spider.so does not exist diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_24020.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_24020.result new file mode 100644 index 00000000..164c68fb --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_24020.result @@ -0,0 +1,97 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-24020 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +connection master_1; +CREATE TABLE tbl_a ( +a INT, +b VARCHAR(30), +PRIMARY KEY(a) +) ENGINE=Spider PARTITION BY LIST(a % 3) ( +PARTITION pt1 VALUES IN (0) COMMENT='srv "s_2_1", table "ta_r2"', +PARTITION pt2 VALUES IN (1) COMMENT='srv "s_2_1", table "ta_r3"', +PARTITION pt3 VALUES IN (2) COMMENT='srv "s_2_1", table "ta_r4"' + ) +INSERT INTO tbl_a VALUES(10000, " abcd "); +INSERT INTO tbl_a VALUES(10001, " abcd "); +INSERT INTO tbl_a VALUES(10002, " abcd "); +INSERT INTO tbl_a VALUES(10003, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10004, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10005, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10006, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10007, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10008, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10009, "[[[**abcd****]]"); + +test 1 +connection master_1; +UPDATE tbl_a SET b = trim(b) WHERE a = 10000; +SELECT * FROM tbl_a WHERE a = 10000; +a b +10000 abcd +UPDATE tbl_a SET b = ltrim(b) WHERE a = 10001; +SELECT * FROM tbl_a WHERE a = 10001; +a b +10001 abcd +UPDATE tbl_a SET b = rtrim(b) WHERE a = 10002; +SELECT * FROM tbl_a WHERE a = 10002; +a b +10002 abcd +UPDATE tbl_a SET b = trim(BOTH '[' FROM b) WHERE a = 10003; +SELECT * FROM tbl_a WHERE a = 10003; +a b +10003 abcd] +UPDATE tbl_a SET b = trim(LEADING '[' FROM b) WHERE a = 10004; +SELECT * FROM tbl_a WHERE a = 10004; +a b +10004 abcd][[ +UPDATE tbl_a SET b = trim(TRAILING '[' FROM b) WHERE a = 10005; +SELECT * FROM tbl_a WHERE a = 10005; +a b +10005 [[[abcd] +UPDATE tbl_a SET b = trim(LEADING '[' FROM trim(TRAILING ']' FROM b)) WHERE a = 10006; +SELECT * FROM tbl_a WHERE a = 10006; +a b +10006 abcd +UPDATE tbl_a SET b = trim(TRAILING '[' FROM trim(LEADING ']' FROM b)) WHERE a = 10007; +SELECT * FROM tbl_a WHERE a = 10007; +a b +10007 [[[abcd]] +UPDATE tbl_a SET b = trim(TRAILING ']' FROM trim(LEADING '[' FROM b)) WHERE a = 10008; +SELECT * FROM tbl_a WHERE a = 10008; +a b +10008 abcd +UPDATE tbl_a SET b = trim(BOTH '*' FROM trim(TRAILING ']' FROM trim(LEADING '[' FROM b))) WHERE a = 10009; +SELECT * FROM tbl_a WHERE a = 10009; +a b +10009 abcd + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_24343.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_24343.result new file mode 100644 index 00000000..1d154daa --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_24343.result @@ -0,0 +1,75 @@ +# +# MDEV-24343 Spider Left join failed Unknown column 't0.ID' in 'on clause' +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`first_name` varchar(255) DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO `tbl_a` VALUES (1,'RICHARD'), (2,'STEPHANE'), (3,'ALAIN'); +CREATE TABLE `tbl_b` ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`last_name` varchar(255) DEFAULT NULL, +PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO `tbl_b` VALUES (1,'DEMONGEOT'),(2,'VAROQUI'); +CREATE TABLE `tbl_c` ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`surname` varchar(255) DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO `tbl_c` VALUES (1,'CON'),(2,'MOYEN'),(3,'MOYEN2'); +SELECT * from tbl_b JOIN tbl_c ON tbl_b.id = tbl_c.id LEFT OUTER JOIN tbl_a ON tbl_a.id = tbl_b.id; +id last_name id surname id first_name +1 DEMONGEOT 1 CON 1 RICHARD +2 VAROQUI 2 MOYEN 2 STEPHANE +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`first_name` varchar(255) DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' +PARTITION BY LIST COLUMNS(`id`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); +CREATE TABLE `tbl_b` ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`last_name` varchar(255) DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_b"' +PARTITION BY LIST COLUMNS(`id`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); +CREATE TABLE `tbl_c` ( +`id` int(10) unsigned NOT NULL AUTO_INCREMENT, +`surname` varchar(255) DEFAULT NULL, +PRIMARY KEY (`id`) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_c"' +PARTITION BY LIST COLUMNS(`id`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); +SELECT * from tbl_b JOIN tbl_c ON tbl_b.id = tbl_c.id LEFT OUTER JOIN tbl_a ON tbl_a.id = tbl_b.id; +id last_name id surname id first_name +1 DEMONGEOT 1 CON 1 RICHARD +2 VAROQUI 2 MOYEN 2 STEPHANE +connection master_1; +DROP DATABASE auto_test_local; +connection child2_1; +DROP DATABASE auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_24517.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_24517.result new file mode 100644 index 00000000..f084c967 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_24517.result @@ -0,0 +1,78 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-24517 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +i INT, +j JSON, +PRIMARY KEY(i) +) ENGINE=Spider PARTITION BY RANGE(i) ( +PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', +PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', +PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ) +INSERT INTO tbl_a (i, j) VALUES +(1, '{"ID": "3", "Name": "Barney", "Age": 18}'), +(2, '{"ID": "4", "Name": "Betty", "Age": 19}'), +(3, '{"ID": "2", "Name": "Wilma", "Age": 20}'), +(4, '[10, 20, [30, 40]]'); + +test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Age')=19; +i j +2 {"ID": "4", "Name": "Betty", "Age": 19} +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Name')="Betty"; +i j +2 {"ID": "4", "Name": "Betty", "Age": 19} +SELECT i, JSON_EXTRACT(j, "$.ID") +FROM tbl_a +WHERE JSON_EXTRACT(j, "$.ID") > 1 AND i < 4 +ORDER BY JSON_EXTRACT(j, "$.Name"); +i JSON_EXTRACT(j, "$.ID") +1 "3" +2 "4" +3 "2" +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[1]') = 20; +i j +4 [10, 20, [30, 40]] +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[2][0]') = 30; +i j +4 [10, 20, [30, 40]] + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_24523.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_24523.result new file mode 100644 index 00000000..0b3d6c31 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_24523.result @@ -0,0 +1,58 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-24523 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +connection master_1; +CREATE TABLE tbl_a ( +i INT, +j JSON, +PRIMARY KEY(i) +) ENGINE=Spider PARTITION BY RANGE(i) ( +PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"', +PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"', +PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"' + ) +INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}'); + +test 1 +connection master_1; +UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]'); +SELECT * FROM tbl_a; +i j +1 {"a": 10, "b": [2, 3]} +TRUNCATE TABLE tbl_a; +INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}'); +UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]'); +SELECT * FROM tbl_a; +i j +1 {"a": 10, "b": "[1, 2]"} + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result new file mode 100644 index 00000000..08481cd1 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_24760.result @@ -0,0 +1,49 @@ +# +# MDEV-24760 SELECT..CASE statement syntax error at Spider Engine table +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +DROP TABLE IF EXISTS tbl_a; +Warnings: +Note 1051 Unknown table 'auto_test_remote.tbl_a' +CREATE TABLE tbl_a ( +id int NOT NULL AUTO_INCREMENT, +name varchar(255) DEFAULT NULL, +PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO tbl_a (name) VALUES ('Alice'), ('Bob'); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +id int NOT NULL AUTO_INCREMENT, +name varchar(255) DEFAULT NULL, +PRIMARY KEY (id) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' +PARTITION BY HASH(id) ( +PARTITION pt1 COMMENT='srv "s_2_1"' +); +SELECT id, CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END FROM tbl_a; +id CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END +1 A +2 B +SELECT id, CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END FROM tbl_a; +id CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END +1 A +2 B +DROP DATABASE auto_test_local; +connection child2_1; +DROP DATABASE auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result new file mode 100644 index 00000000..09efba25 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_25116.result @@ -0,0 +1,42 @@ +# +# MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (id INT); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +id INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +connection master_1; +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a; +IF(COUNT(id > 0),'Y','N') +N +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 1 +set spider_direct_aggregate=@old_spider_direct_aggregate; +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_25684.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_25684.result new file mode 100644 index 00000000..8d4bea79 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_25684.result @@ -0,0 +1,18 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +MDEV-25684 Crash in THD::find_temporary_table while calling spider_direct_sql UDF without temporary table created + +connection master_1; +SELECT SPIDER_DIRECT_SQL('SELECT * FROM s', 'non_existing_temporary_table', 'srv "s_2_1"'); +ERROR HY000: Temporary table 'test.non_existing_temporary_table' is not found +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result new file mode 100644 index 00000000..3af1f7df --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result @@ -0,0 +1,42 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +MDEV-26013 distinct not work properly in some cases for spider tables + +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +`a`int, +`b`int, +PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +insert into `tbl_a` VALUES (1,999), (2,999); +connection master_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +`a`int, +`b`int, +PRIMARY KEY (`a`) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS(`a`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); +connection master_1; +SELECT distinct b FROM tbl_a WHERE b=999; +b +999 +connection master_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26151.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26151.result new file mode 100644 index 00000000..b0a430e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26151.result @@ -0,0 +1,34 @@ + +MDEV-26151 MDEV-31787 + +for master_1 +for child2 +for child3 +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode=1; +CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +create table td (a int, PRIMARY KEY (a)); +create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_26151",TABLE "td", casual_read "3"'; +insert into td values (11), (42); +select max(a) from ts; +max(a) +42 +drop table td, ts; +create table td (a int, PRIMARY KEY (a)); +create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv_mdev_26151",TABLE "td", casual_read "1"'; +insert into td values (11), (42); +select max(a) from ts; +max(a) +42 +select min(a) from ts; +min(a) +11 +drop table td, ts; +drop server srv_mdev_26151; +set session spider_bgs_mode=@old_spider_bgs_mode; +for master_1 +for child2 +for child3 + +end of test + diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26158.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26158.result new file mode 100644 index 00000000..2870dab2 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26158.result @@ -0,0 +1,27 @@ +# +# MDEV-26158 SIGSEGV in spider_free_mem from ha_spider::open on INSERT +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE t ( +c INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' +PARTITION BY LIST COLUMNS(`c`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); +INSERT INTO t SELECT * FROM t; +ERROR 42000: Unknown database 'auto_test_remote' +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26247.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26247.result new file mode 100644 index 00000000..723a81a9 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26247.result @@ -0,0 +1,96 @@ +# +# MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064 +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE t1 ( +a11 int, +primary key (a11) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE t2 ( +a21 int, +a22 int, +primary key (a21, a22) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE t3 ( +a31 int, +a32 int, +primary key (a31, a32) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t2 VALUES (1, 11), (2, 22), (3, 33); +INSERT INTO t3 VALUES (1, 111), (2, 222), (3, 333); +connection master_1; +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE t1 ( +a11 int, +primary key (a11) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t1"'; +CREATE TABLE t2 ( +a21 int, +a22 int, +primary key (a21, a22) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t2"'; +CREATE TABLE t3 ( +a31 int, +a32 int, +primary key (a31, a32) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t3"'; +SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 WHERE a11 IN (1); +a22 +11 +SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 WHERE a11 IN (1); +a22 +NULL +SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1); +a22 +11 +SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1,2); +a22 +11 +22 +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1); +a22 a32 +11 111 +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 RIGHT JOIN t3 on a21 = a31 - a31 WHERE a11 IN (1); +a22 a32 +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1,2); +a22 a32 +11 111 +22 222 +SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 WHERE a11 IN (1); +a22 +11 +SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 - a21 WHERE a11 IN (1); +a22 +SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1); +a22 +11 +SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1,2); +a22 +11 +22 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +# +# end of test mdev_26247 +# diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26539.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26539.result new file mode 100644 index 00000000..4e195fdd --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26539.result @@ -0,0 +1,36 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +# +# MDEV-26539 SIGSEGV in spider_check_and_set_trx_isolation and I_P_List_iterator from THD::drop_temporary_table (10.5.3 opt only) on ALTER +# +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +c INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +c INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS (c) ( +PARTITION pt1 DEFAULT COMMENT = 'srv "s_2_1"' +); +INSERT INTO tbl_a VALUES (1); +ALTER TABLE tbl_a CHECK PARTITION ALL; +Table Op Msg_type Msg_text +auto_test_local.tbl_a check status OK +DROP DATABASE auto_test_local; +connection child2_1; +DROP DATABASE auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26541.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26541.result new file mode 100644 index 00000000..72921d2e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26541.result @@ -0,0 +1,19 @@ +# +# MDEV-26541 Undefined symbol: _ZTI12ha_partition when attempting to use ha_spider.so in UBSAN builds +# +INSTALL SONAME 'ha_spider.so'; +DROP FUNCTION spider_flush_table_mon_cache; +DROP FUNCTION spider_copy_tables; +DROP FUNCTION spider_ping_table; +DROP FUNCTION spider_bg_direct_sql; +DROP FUNCTION spider_direct_sql; +UNINSTALL SONAME IF EXISTS "ha_spider"; +DROP TABLE IF EXISTS mysql.spider_xa; +DROP TABLE IF EXISTS mysql.spider_xa_member; +DROP TABLE IF EXISTS mysql.spider_xa_failed_log; +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 TABLE IF EXISTS mysql.spider_table_position_for_recovery; +DROP TABLE IF EXISTS mysql.spider_table_sts; +DROP TABLE IF EXISTS mysql.spider_table_crd; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26544.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26544.result new file mode 100644 index 00000000..b3d5facc --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26544.result @@ -0,0 +1,23 @@ +# +# MDEV-26544 Assertion `part_share->auto_inc_initialized' failed in ha_partition::get_auto_increment on INSERT +# +for master_1 +for child2 +for child3 +connection master_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE `tbl_a` ( +`a` INT AUTO_INCREMENT, KEY(`a`) +) ENGINE=Spider DEFAULT CHARSET=utf8 +PARTITION BY LIST COLUMNS (`a`) ( +PARTITION `pt1` DEFAULT +); +INSERT INTO tbl_a (a) VALUES (0); +ERROR HY000: Unable to connect to foreign data source: localhost +INSERT INTO tbl_a () VALUES (); +ERROR HY000: Unable to connect to foreign data source: localhost +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result new file mode 100644 index 00000000..f393867f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result @@ -0,0 +1,11 @@ +# +# MDEV-26582 SIGSEGV in spider_db_bulk_insert and spider_db_connect and spider_db_before_query, and hang in "End of update loop" / "Reset for next command" query states +# +CREATE DATABASE IF NOT EXISTS auto_test_local; +USE auto_test_local; +CREATE TABLE t (i CHAR) ENGINE=SPIDER; +INSERT INTO t VALUES (0); +Got one of the listed errors +INSERT t SELECT 1 ON DUPLICATE KEY UPDATE c=1; +ERROR 42S22: Unknown column 'c' in 'field list' +DROP DATABASE IF EXISTS auto_test_local; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result new file mode 100644 index 00000000..531e48b8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result @@ -0,0 +1,83 @@ +# +# MDEV-27172 Prefix indices on Spider tables may lead to wrong query results +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +SET @general_log_backup = @@global.general_log; +SET @log_output_backup = @@global.log_output; +SET @@global.general_log = 1; +SET @@global.log_output = "TABLE"; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +id int NOT NULL, +greeting VARCHAR(255), +KEY(greeting) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE tbl_b ( +id int NOT NULL, +greeting VARCHAR(255), +KEY k (greeting(5)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE tbl_c ( +id int NOT NULL, +greeting TEXT, +KEY k (greeting(5)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +id int NOT NULL, +greeting VARCHAR(255), +KEY k (greeting) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +INSERT INTO tbl_a VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_a WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; +id greeting +2 Aloha! +CREATE TABLE tbl_b ( +id int NOT NULL, +greeting VARCHAR(255), +KEY k (greeting(5)) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_b", srv "s_2_1"'; +INSERT INTO tbl_b VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_b WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; +id greeting +2 Aloha! +CREATE TABLE tbl_c ( +id int NOT NULL, +greeting TEXT, +KEY k (greeting(5)) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_c", srv "s_2_1"'; +INSERT INTO tbl_c VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_c WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; +id greeting +2 Aloha! +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE 'select `id`,`greeting` from %'; +argument +select `id`,`greeting` from `auto_test_remote`.`tbl_a` where `greeting` = 'Aloha!' and ((`greeting` = 'Aloha!')) +select `id`,`greeting` from `auto_test_remote`.`tbl_b` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) +select `id`,`greeting` from `auto_test_remote`.`tbl_c` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!')) +connection child2_1; +SET @@global.general_log = @general_log_backup; +SET @@global.log_output = @log_output_backup; +DROP DATABASE auto_test_remote; +connection master_1; +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27184.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27184.result new file mode 100644 index 00000000..bcd65772 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27184.result @@ -0,0 +1,21 @@ +# +# MDEV-27184 Assertion `(old_top == initial_top (av) && old_size == 0) || +# ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && +# ((unsigned long) old_end & (pagesize - 1)) == 0)' failed, +# Assertion `str.alloced_length() >= str.length() + data_len' failed +# +for master_1 +for child2 +for child3 +connection master_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (a FLOAT) ENGINE=SPIDER; +INSERT INTO tbl_a VALUES +(0xF5A7),(0xF5A8),(0xF5A9),(0xF5AA),(0xF5AB),(0xF5AC),(0xF5AD),(0xF5AE), +(0xF5A7),(0xF5A8),(0xF5A9),(0xF5AA),(0xF5AB),(0xF5AC),(0xF5AD),(0xF5AE); +Got one of the listed errors +DROP DATABASE auto_test_remote; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27233.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27233.result new file mode 100644 index 00000000..17f3316b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27233.result @@ -0,0 +1,11 @@ +# +# MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table +# +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `c` int(11) DEFAULT NULL +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +Warnings: +Error 1429 Unable to connect to foreign data source: localhost +Error 1429 Unable to connect to foreign data source: localhost diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27239.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27239.result new file mode 100644 index 00000000..de135972 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27239.result @@ -0,0 +1,20 @@ +# +# MDEV-27239 Spider: Assertion `thd->transaction->stmt.ha_list == __null || trans == &thd->transaction->stmt' failed in ha_commit_trans on BEGIN WORK after FTWRL +# +for master_1 +for child2 +for child3 +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a (a INT) ENGINE=SPIDER; +FLUSH TABLE tbl_a WITH READ LOCK; +Warnings: +Error 1429 Unable to connect to foreign data source: localhost +Error 1429 Unable to connect to foreign data source: localhost +Error 1429 Unable to connect to foreign data source: localhost +Error 1429 Unable to connect to foreign data source: localhost +BEGIN; +DROP DATABASE auto_test_local; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27240.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27240.result new file mode 100644 index 00000000..407e916f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27240.result @@ -0,0 +1,16 @@ +for master_1 +for child2 +for child3 +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a (a INT KEY) ENGINE=SPIDER; +SELECT a.z FROM tbl_a AS a,tbl_a b WHERE a.z=b.z; +ERROR 42S22: Unknown column 'a.z' in 'field list' +ALTER TABLE tbl_a CHANGE c c INT; +ERROR 42S22: Unknown column 'c' in 'tbl_a' +LOCK TABLE tbl_a READ; +Got one of the listed errors +DROP DATABASE auto_test_local; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28218.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218.result new file mode 100644 index 00000000..394d3b27 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218.result @@ -0,0 +1,9 @@ +# +# MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +# +INSTALL SONAME 'ha_spider.so'; +DROP TABLE IF EXISTS mysql.spider_tables; +show create table mysql.spider_tables; +ERROR 42S02: Table 'mysql.spider_tables' doesn't exist +Warnings: +Note 1051 Unknown table 'mysql.spider_tables' diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_init_file.result new file mode 100644 index 00000000..05c396ac --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_init_file.result @@ -0,0 +1,5 @@ +# +# MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +# +show create table mysql.spider_tables; +ERROR 42S02: Table 'mysql.spider_tables' doesn't exist diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_mixed.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_mixed.result new file mode 100644 index 00000000..05c396ac --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28218_mixed.result @@ -0,0 +1,5 @@ +# +# MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +# +show create table mysql.spider_tables; +ERROR 42S02: Table 'mysql.spider_tables' doesn't exist diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28854.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28854.result new file mode 100644 index 00000000..e5cee8d4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28854.result @@ -0,0 +1,32 @@ +# +# MDEV-28854 Spider: Disallow INSERT DELAYED on Spider table +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (id INT); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +id INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +connection master_1; +INSERT DELAYED INTO tbl_a VALUES (1); +ERROR HY000: DELAYED option not supported for table 'tbl_a' +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result new file mode 100644 index 00000000..fae3cc6b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result @@ -0,0 +1,180 @@ +# +# MDEV-28856 Spider: Implement more engine-defined options +# +for master_1 +for child2 +for child3 +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +# testing monitoring_* +INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server) VALUES +('test', 't1', '0', 1, 'srv'); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"'; +/* 1 */ insert into t1 values (42); +ERROR HY000: Table 'test.t2' get a problem +/* 2 */ insert into t1 values (42); +ERROR HY000: All links of 'test.t1' are failed +create table t2 (c int); +/* 3 */ insert into t1 values (42); +ERROR HY000: All links of 'test.t1' are failed +drop table t1, t2; +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2", + monitoring_bg_interval "500000"'; +/* 4 */ insert into t1 values (42); +ERROR 42S02: Table 'test.t2' doesn't exist +drop table t1; +# testing query_cache_sync +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"'; +create table t2 (c int); +/* 5 */ insert into t1 values (42); +select sql_cache * from t1; +c +42 +select sql_no_cache * from t1; +c +42 +drop table t1, t2; +# testing tgt_pk_names +create table t2 (c int); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 6 */ insert ignore into t1 values (42), (42); +select * from t1; +c +42 +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 7 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 8 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'PRIMARY' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, unique key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9.1 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'PRIMARY' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, unique key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"'; +/* 10 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'c' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 11 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, d int, unique key (c), unique key (d)); +create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 12 */ insert ignore into t1 values (42, 43), (43, 43); +Warnings: +Warning 1062 Duplicate entry '43' for key 'd' +select * from t1; +c d +42 43 +drop table t1, t2; +# Testing index hint +create table t2 (c int, d int, primary key (c), key (d)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + KEY `d` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + KEY `d` (`d`) +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"' +/* 13 */ insert into t1 values (42, 23), (37, 93); +select max(d) from t1; +max(d) +93 +drop table t1, t2; +create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + `e` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + UNIQUE KEY `e` (`e`), + KEY `d` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + `e` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + UNIQUE KEY `e` (`e`), + KEY `d` (`d`) +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"' +/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47); +select max(d) from t1; +max(d) +93 +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 +# +# end of test mdev_28856 +# diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28996.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28996.result new file mode 100644 index 00000000..f805e7ef --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28996.result @@ -0,0 +1,34 @@ +# +# MDEV-28996 ASAN errors in String::q_append / spider_string::q_append / spider_db_mbase_util::open_item_func +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a CHAR(8) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO tbl_a VALUES ('foo'),('bar'); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a CHAR(8) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT MAX(BINARY a) FROM tbl_a; +MAX(BINARY a) +foo +DROP DATABASE auto_test_local; +connection child2_1; +DROP DATABASE auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28998.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28998.result new file mode 100644 index 00000000..d664b090 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28998.result @@ -0,0 +1,26 @@ +# +# MDEV-28998 ASAN errors in spider_fields::free_conn_holder or spider_create_group_by_handler +# +for master_1 +for child2 +for child3 +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; +CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t1_SPIDER (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'"; +CREATE TABLE t2 AS SELECT a FROM t1_SPIDER; +SELECT * FROM t2; +a +1 +2 +DROP TABLE t2, t1_SPIDER, t1; +drop server s; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; +for master_1 +for child2 +for child3 +# +# end of test mdev_28998 +# diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29008.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29008.result new file mode 100644 index 00000000..66e33f42 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29008.result @@ -0,0 +1,38 @@ +# +# MDEV-29008 Server crash or assertion `field' failed in spider_db_open_item_ident / group by handler +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT, +b INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO tbl_a VALUES (1,2),(3,4); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT, +b INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT MIN(t2.a) AS f1, t1.b AS f2 FROM tbl_a AS t1 JOIN tbl_a AS t2 GROUP BY f2 ORDER BY f1, f2; +f1 f2 +1 2 +1 4 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29011.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29011.result new file mode 100644 index 00000000..04f9651b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29011.result @@ -0,0 +1,40 @@ +# +# MDEV-29011 Server crash in spider_db_open_item_cond with XOR operator +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT, +b INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO tbl_a VALUES (0, 0), (0, 1), (1, 0), (1, 1); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT, +b INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT a XOR b AS f FROM tbl_a; +f +0 +1 +1 +0 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29163.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29163.result new file mode 100644 index 00000000..96d8a729 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29163.result @@ -0,0 +1,26 @@ +# +# MDEV-29163 Server crash with SIGSEGV or dynamic-stack-buffer-overflow in spider_db_mbase_util::append_table +# +for master_1 +for child2 +for child3 +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; +CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT); +CREATE TABLE t3 (c INT, PRIMARY KEY(c)); +CREATE TABLE t1_spider (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'"; +CREATE TABLE t2_spider (b INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't2'"; +CREATE TABLE t3_spider (c INT, PRIMARY KEY(c)) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't3'"; +SELECT t1_spider.* FROM t1_spider LEFT JOIN t2_spider LEFT JOIN t3_spider ON b = c ON a = b; +a +DROP TABLE t1_spider, t2_spider, t3_spider, t1, t2, t3; +drop server s; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; +for master_1 +for child2 +for child3 +# +# end of test mdev_29163 +# diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result new file mode 100644 index 00000000..975d3834 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result @@ -0,0 +1,13 @@ +CREATE TABLE t (c INT); +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `c` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FLUSH TABLES WITH READ LOCK; +CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; +ERROR HY000: Can't execute the query because you have a conflicting read lock +SELECT * FROM t; +c +# restart +DROP TABLE t; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29447.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29447.result new file mode 100644 index 00000000..358e131f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29447.result @@ -0,0 +1,33 @@ +# +# MDEV-29447 SIGSEGV in spider_db_open_item_field and SIGSEGV spider_db_print_item_type, on SELECT +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT TRIM(LEADING 'c' FROM a) FROM tbl_a; +TRIM(LEADING 'c' FROM a) +connection child2_1; +DROP DATABASE auto_test_remote; +connection master_1; +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29484.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29484.result new file mode 100644 index 00000000..cc950ac0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29484.result @@ -0,0 +1,39 @@ +# +# MDEV-29484 Assertion `!trx_free || !trx->locked_connections' failed in spider_free_trx_conn on LOCK TABLES +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +CREATE TABLE tbl_b ( +a INT +) ENGINE=Spider DEFAULT CHARSET=utf8; +LOCK TABLES tbl_a WRITE; +LOCK TABLES tbl_b READ, tbl_a READ; +ERROR HY000: Unable to connect to foreign data source: localhost +disconnect master_1; +connect master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK; +connection child2_1; +DROP DATABASE auto_test_remote; +connection master_1; +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29502.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29502.result new file mode 100644 index 00000000..54c5e9a6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29502.result @@ -0,0 +1,68 @@ +# +# MDEV-29502 ASAN: heap-buffer-overflow & stack-buffer-overflow in spider_db_mbase_row::append_to_str | SIGSEGV's in __memmove_avx_unaligned_erms from memcpy in Binary_string::q_append, in Static_binary_string::q_append and my_strntoull10rnd_8bit | Unknown error 12801 +# +for master_1 +for child2 +for child3 +CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +CREATE TABLE t (a INT); +INSERT INTO t VALUES (23),(48); +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +CREATE TABLE t1 (a INT KEY) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "srv_mdev_29502",TABLE "t"'; +SELECT MAX(a) FROM t1; +MAX(a) +48 +SELECT SUM(a) FROM t1; +SUM(a) +71 +SELECT COUNT(a) FROM t1; +COUNT(a) +2 +SELECT MAX(a), SUM(a) FROM t1; +MAX(a) SUM(a) +48 71 +SELECT COUNT(a), MAX(a), SUM(a) FROM t1; +COUNT(a) MAX(a) SUM(a) +2 48 71 +SELECT MAX(a), COUNT(a), SUM(a) FROM t1; +MAX(a) COUNT(a) SUM(a) +48 2 71 +SELECT MAX(a), MAX(COALESCE(a)) FROM t1; +MAX(a) MAX(COALESCE(a)) +48 48 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +DROP TABLE t, t1; +CREATE TABLE t (a INT, b INT); +INSERT INTO t VALUES (23, -1),(48, 97); +CREATE TABLE t1 (a INT, b INT) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "srv_mdev_29502",TABLE "t"'; +SELECT MAX(a + b), SUM(a - b) FROM t1; +MAX(a + b) SUM(a - b) +145 -25 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +DROP TABLE t, t1; +CREATE TABLE t (a INT); +INSERT INTO t VALUES (23),(97),(42); +CREATE TABLE t1 (a INT) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "srv_mdev_29502",TABLE "t"'; +SELECT IF(COUNT(a > 0),'Y','N'), MAX(a) FROM t1; +IF(COUNT(a > 0),'Y','N') MAX(a) +Y 97 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 2 +SELECT MAX(a), IF(COUNT(a > 0),'Y','N') FROM t1; +MAX(a) IF(COUNT(a > 0),'Y','N') +97 Y +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 4 +DROP TABLE t, t1; +set spider_direct_aggregate=@old_spider_direct_aggregate; +DROP SERVER srv_mdev_29502; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29562.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29562.result new file mode 100644 index 00000000..561ce18a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29562.result @@ -0,0 +1,47 @@ +# +# MDEV-29562 Spider table with charset utf32/utf16/ucs2 tries to set client charset to unsupported value +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider CHARSET utf32 COMMENT='table "tbl_a", srv "s_2_1"'; +ERROR HY000: Table storage engine 'SPIDER' does not support the create option 'CHARSET utf32' +ALTER DATABASE auto_test_local CHARSET="ucs2"; +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider COMMENT='table "tbl_a", srv "s_2_1"'; +ERROR HY000: Table storage engine 'SPIDER' does not support the create option 'CHARSET ucs2' +CREATE TABLE tbl_a ( +a INT +) ENGINE=Spider CHARSET utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT * FROM tbl_a; +a +ALTER TABLE tbl_a CONVERT TO CHARACTER SET utf16; +ERROR HY000: Table storage engine 'SPIDER' does not support the create option 'CHARSET utf16' +ALTER TABLE tbl_a CONVERT TO CHARACTER SET utf16le; +ERROR HY000: Table storage engine 'SPIDER' does not support the create option 'CHARSET utf16le' +ALTER TABLE tbl_a CONVERT TO CHARACTER SET latin1; +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29644.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29644.result new file mode 100644 index 00000000..b52cecc5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29644.result @@ -0,0 +1,41 @@ +# +# MDEV-29644 a potential bug of null pointer dereference in spider_db_mbase::print_warnings() +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a ( +a CHAR(5) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +SET GLOBAL sql_mode=''; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +a CHAR(255) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SET sql_mode=''; +INSERT INTO tbl_a VALUES ("this will be truncated"); +NOT FOUND /\[WARN SPIDER RESULT\].* Warning 1265 Data truncated for column 'a' at row 1.*/ in mysqld.1.1.err +SET GLOBAL spider_log_result_errors=4; +INSERT INTO tbl_a VALUES ("this will be truncated"); +FOUND 1 /\[WARN SPIDER RESULT\].* Warning 1265 Data truncated for column 'a' at row 1.*/ in mysqld.1.1.err +connection master_1; +SET GLOBAL spider_log_result_errors=DEFAULT; +SET sql_mode=DEFAULT; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +SET GLOBAL sql_mode=DEFAULT; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29653.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29653.result new file mode 100644 index 00000000..abbcfcb7 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29653.result @@ -0,0 +1,33 @@ +# +# MDEV-29653 Assertion `0' failed in Item_cache_row::illegal_method_call on SELECT from Spider table +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE t ( +c INT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE ts ( +c INT +) ENGINE=Spider COMMENT='table "t", srv "s_2_1"'; +SELECT 1 FROM ts WHERE ROW(c, c) NOT IN ((0,0),(1,1)); +1 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result new file mode 100644 index 00000000..c89309a5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29904.result @@ -0,0 +1,4 @@ +# +# MDEV-29904 SPIDER plugin initialization fails upon startup +# +# restart: --plugin-load-add=ha_spider diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_30191.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_30191.result new file mode 100644 index 00000000..941f210c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_30191.result @@ -0,0 +1,44 @@ +# +# MDEV-30191 SIGSEGV & heap-use-after-free in spider_db_print_item_type, SIGABRT in __cxa_pure_virtual/spider_db_print_item_type, Got error 128 "Out of memory in engine", 56/112 memory not freed, and Assertion `fixed()' failed in Item_sp_variable::val_str on SP call +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (c INT); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +CREATE TABLE tbl_a ( +c INT +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +CREATE TABLE tbl_b (c INT); +CREATE PROCEDURE sp() BEGIN +DECLARE v1 DATE; +WHILE EXISTS (SELECT 1 FROM tbl_a WHERE c>v1 AND c<=v1) DO +SELECT 1; +END WHILE; +WHILE EXISTS (SELECT 1 +FROM tbl_a +WHERE c 1 order by a; +drop table t, auto_test_local.t1, auto_test_local.t2; + +--echo # +--echo # MDEV-27617 HANDLER KEY > (x) does not work with DESC keys, Spider is affected and returns wrong results +--echo # + +create table auto_test_local.t (a int, b char(1), primary key(a desc)); +insert into auto_test_local.t VALUES (1,'f'),(2,'g'),(3,'j'), (4,'i'),(5,'h'); +create table ts (a int, b char(1), primary key(a desc)) +engine=spider comment='wrapper "mysql", srv "s_1", table "t"'; +select a, b from ts where a > 0 and b = 'g' order by a; +drop table ts, auto_test_local.t; + +drop database auto_test_local; +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/insert_select.cnf b/storage/spider/mysql-test/spider/bugfix/t/insert_select.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/insert_select.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/insert_select.test b/storage/spider/mysql-test/spider/bugfix/t/insert_select.test new file mode 100644 index 00000000..c2ac615e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/insert_select.test @@ -0,0 +1,101 @@ +--source ../include/insert_select_init.inc +--echo +--echo this test is for MDEV-16399 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +echo CHILD2_1_CREATE_TABLES2; +eval $CHILD2_1_CREATE_TABLES2; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt,tm) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + skey int NOT NULL, + dt date NOT NULL, + tm time NOT NULL, + KEY idx1 (skey,dt,tm) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + dt datetime NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (dt) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + dt datetime NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (dt) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1_2; +--enable_query_log +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(1, '2013-02-01', '13:00:00'),(2, '2013-03-01', '13:00:00'),(3, '2013-04-01', '13:00:00'),(4, '2013-05-01', '13:00:00'),(5, '2013-06-01', '13:00:00'),(6, '2013-07-01', '13:00:00'),(7, '2013-08-01', '13:00:00'),(8, '2013-09-01', '13:00:00'),(9, '2013-10-01', '13:00:00'); +INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-11-01', '11:00:00'),(1, '2012-12-01', '11:00:00'),(2, '2012-11-30', '11:00:00'),(3, '2012-11-29', '11:00:00'),(4, '2012-11-28', '11:00:00'),(5, '2012-11-27', '11:00:00'),(6, '2012-11-26', '11:00:00'),(7, '2012-11-25', '11:00:00'),(8, '2012-11-24', '11:00:00'),(9, '2012-11-23', '11:00:00'); +FLUSH TABLES; + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 4 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 3 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 2 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 1 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 0 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 9 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 8 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 7 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 6 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); +INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 5 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY)); + +--connection child2_1 +--disable_ps2_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +--enable_ps2_protocol +eval $CHILD2_1_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/insert_select_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf new file mode 100644 index 00000000..e0ffb99c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test new file mode 100644 index 00000000..0b8ce69c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test @@ -0,0 +1,99 @@ +--source ../include/mdev_19866_init.inc +--echo +--echo this test is for MDEV-19866 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + val char(1) NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + val char(1) NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey,val) VALUES (1,'1'),(2,'2'),(3,'3'),(4,'4'); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_ps2_protocol +SELECT * FROM tbl_a; +SELECT * FROM tbl_a WHERE pkey = 1; +SELECT * FROM tbl_a; +SELECT * FROM tbl_a WHERE pkey = 2; +SELECT * FROM tbl_a; + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; +eval $CHILD2_2_SELECT_TABLES; +--enable_ps2_protocol + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_19866_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.test new file mode 100644 index 00000000..3d1ccf3c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_20100.test @@ -0,0 +1,93 @@ +--source ../include/mdev_20100_init.inc +--echo +--echo this test is for MDEV-20100 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +--disable_ps_protocol +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +eval CREATE TABLE tbl_a ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +--enable_query_log +INSERT INTO tbl_a (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 test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_ps2_protocol +SELECT a, b, c FROM tbl_a PARTITION (pt2) WHERE b = 'c'; +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt2); +SELECT a, b, c FROM tbl_a PARTITION (pt3) WHERE b = 'c'; +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt2); +SELECT a, b, c FROM tbl_a PARTITION (pt1) WHERE b = 'c'; +SELECT a, b, c FROM tbl_a PARTITION (pt1,pt3); +SELECT a, b, c FROM tbl_a PARTITION (pt1) WHERE b = 'c'; +SELECT a, b, c FROM tbl_a PARTITION (pt2,pt3); +--enable_ps2_protocol + +--connection child2_1 +--disable_ps2_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +--enable_ps2_protocol +--disable_ps_protocol +eval $CHILD2_1_SELECT_TABLES; +--enable_ps_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_20100_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.test new file mode 100644 index 00000000..1cd1c689 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_20502.test @@ -0,0 +1,80 @@ +--source ../include/mdev_20502_init.inc +--echo +--echo this test is for MDEV-20502 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + val int(10) unsigned DEFAULT NULL, + PRIMARY KEY(id) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + val int(10) unsigned DEFAULT NULL, + PRIMARY KEY(id) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (val) VALUES (1); + +--echo +--echo test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--disable_ps2_protocol +--connection master_1 +SELECT id, 0 AS const, val FROM tbl_a; +SELECT 1+2, id, 0 AS const, val, val+10, (SELECT tbl_a.val+1 FROM tbl_a) AS sq +FROM tbl_a; +INSERT INTO tbl_a (val) VALUES (2), (1); +SELECT val+10, 0 AS const, val, (SELECT tbl_a.val+1 FROM tbl_a LIMIT 1) AS sq +FROM tbl_a GROUP BY val; +SELECT MAX(id) AS m, 0 AS const, val, (SELECT tbl_a.val+1 FROM tbl_a LIMIT 1) AS sq +FROM tbl_a GROUP BY val; + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; +--enable_ps2_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_20502_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.test new file mode 100644 index 00000000..c1a9aaa4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_21884.test @@ -0,0 +1,105 @@ +--source ../include/mdev_21884_init.inc +--echo +--echo this test is for MDEV-21884 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +--disable_ps_protocol +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a,b) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +eval CREATE TABLE tbl_a ( + a INT, + b CHAR(1), + c DATETIME, + PRIMARY KEY(a,b) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +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 tbl_a (a, b, c) VALUES + (11, 'a', '2008-08-01 10:21:39'), + (11, 'b', '2000-01-01 00:00:00'), + (12, 'e', '2007-06-04 20:03:11'), + (12, 'd', '2003-11-30 05:01:03'), + (13, 'c', '2001-12-31 23:59:59'); +INSERT INTO tb_l (a, b, c) VALUES + (11, 'a', '2008-08-01 10:21:39'), + (12, 'b', '2000-01-01 00:00:00'), + (13, 'e', '2007-06-04 20:03:11'), + (14, 'd', '2003-11-30 05:01:03'), + (15, 'c', '2001-12-31 23:59:59'); + +--echo +--echo test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_ps2_protocol +SELECT STRAIGHT_JOIN b.a, b.b FROM tb_l a, tbl_a b WHERE a.a = b.a; +--enable_ps2_protocol + +--connection child2_1 +SET NAMES utf8; +--disable_ps2_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +--enable_ps2_protocol +--disable_ps_protocol +eval $CHILD2_1_SELECT_TABLES; +--enable_ps_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_21884_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf new file mode 100644 index 00000000..e0ffb99c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test new file mode 100644 index 00000000..9e58bc1a --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22246.test @@ -0,0 +1,92 @@ +--source ../include/mdev_22246_init.inc +--echo +--echo this test is for MDEV-22246 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + id bigint NOT NULL, + node text, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (id,node) VALUES (1,'DB-G0'),(2,'DB-G1'); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT * FROM tbl_a; +SELECT * FROM tbl_a WHERE id <0 || id >0; + +--connection child2_1 +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_22246_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.test new file mode 100644 index 00000000..0dcb1031 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22265.test @@ -0,0 +1,28 @@ +--source ../include/mdev_22265_init.inc +--echo +--echo this test is for MDEV-22265 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +--enable_warnings + +--echo +--echo create table +--connection master_1 +create table t2345678911234567892123456789312345678941234567895123(id int) ENGINE=SPIDER DEFAULT CHARSET=latin1 COMMENT='host "h114", user "spider", password "spider", port "3306", database "test32738"'; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--enable_warnings +--source ../include/mdev_22265_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_22979.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_22979.test new file mode 100644 index 00000000..7f42bd73 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_22979.test @@ -0,0 +1,18 @@ +--echo MDEV-22979 "mysqld --bootstrap" / mysql_install_db hangs when Spider is installed + +# This test is not the most faithful, as it does not have any +# dependency problems on the existence of the `mysql` database. To +# test MDEV-22979 faithfully, a mysql_install_db invocation with +# --plugin-load-add=ha_spider should be run. We cannot run it in mtr +# because we do not have access to --srcdir. + +let $MYSQLD_DATADIR= `select @@datadir`; +let $PLUGIN_DIR=`select @@plugin_dir`; +--source include/kill_mysqld.inc +--write_file $MYSQLTEST_VARDIR/tmp/mdev_22979.sql +drop table if exists foo.bar; +EOF +--exec $MYSQLD_CMD --datadir=$MYSQLD_DATADIR --bootstrap --plugin-dir=$PLUGIN_DIR --plugin-load-add=ha_spider < $MYSQLTEST_VARDIR/tmp/mdev_22979.sql +--source include/start_mysqld.inc +--disable_query_log +--source ../../include/clean_up_spider.inc diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.test new file mode 100644 index 00000000..ac06d860 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24020.test @@ -0,0 +1,90 @@ +--source ../include/mdev_24020_init.inc +--echo +--echo this test is for MDEV-24020 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +--disable_ps_protocol +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT, + b VARCHAR(30), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +eval CREATE TABLE tbl_a ( + a INT, + b VARCHAR(30), + PRIMARY KEY(a) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +--enable_query_log +INSERT INTO tbl_a VALUES(10000, " abcd "); +INSERT INTO tbl_a VALUES(10001, " abcd "); +INSERT INTO tbl_a VALUES(10002, " abcd "); +INSERT INTO tbl_a VALUES(10003, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10004, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10005, "[[[abcd][["); +INSERT INTO tbl_a VALUES(10006, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10007, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10008, "[[[abcd]]"); +INSERT INTO tbl_a VALUES(10009, "[[[**abcd****]]"); + +--echo +--echo test 1 + +--connection master_1 +UPDATE tbl_a SET b = trim(b) WHERE a = 10000; +SELECT * FROM tbl_a WHERE a = 10000; +UPDATE tbl_a SET b = ltrim(b) WHERE a = 10001; +SELECT * FROM tbl_a WHERE a = 10001; +UPDATE tbl_a SET b = rtrim(b) WHERE a = 10002; +SELECT * FROM tbl_a WHERE a = 10002; +UPDATE tbl_a SET b = trim(BOTH '[' FROM b) WHERE a = 10003; +SELECT * FROM tbl_a WHERE a = 10003; +UPDATE tbl_a SET b = trim(LEADING '[' FROM b) WHERE a = 10004; +SELECT * FROM tbl_a WHERE a = 10004; +UPDATE tbl_a SET b = trim(TRAILING '[' FROM b) WHERE a = 10005; +SELECT * FROM tbl_a WHERE a = 10005; +UPDATE tbl_a SET b = trim(LEADING '[' FROM trim(TRAILING ']' FROM b)) WHERE a = 10006; +SELECT * FROM tbl_a WHERE a = 10006; +UPDATE tbl_a SET b = trim(TRAILING '[' FROM trim(LEADING ']' FROM b)) WHERE a = 10007; +SELECT * FROM tbl_a WHERE a = 10007; +UPDATE tbl_a SET b = trim(TRAILING ']' FROM trim(LEADING '[' FROM b)) WHERE a = 10008; +SELECT * FROM tbl_a WHERE a = 10008; +UPDATE tbl_a SET b = trim(BOTH '*' FROM trim(TRAILING ']' FROM trim(LEADING '[' FROM b))) WHERE a = 10009; +SELECT * FROM tbl_a WHERE a = 10009; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--enable_warnings +--source ../include/mdev_24020_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.test new file mode 100644 index 00000000..5756cbac --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24343.test @@ -0,0 +1,84 @@ +--echo # +--echo # MDEV-24343 Spider Left join failed Unknown column 't0.ID' in 'on clause' +--echo # + +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE tbl_a ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `first_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO `tbl_a` VALUES (1,'RICHARD'), (2,'STEPHANE'), (3,'ALAIN'); + +eval CREATE TABLE `tbl_b` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`ID`) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO `tbl_b` VALUES (1,'DEMONGEOT'),(2,'VAROQUI'); + +eval CREATE TABLE `tbl_c` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `surname` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO `tbl_c` VALUES (1,'CON'),(2,'MOYEN'),(3,'MOYEN2'); + +SELECT * from tbl_b JOIN tbl_c ON tbl_b.id = tbl_c.id LEFT OUTER JOIN tbl_a ON tbl_a.id = tbl_b.id; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `first_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' +PARTITION BY LIST COLUMNS(`id`) ( + PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); + +eval CREATE TABLE `tbl_b` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_b"' +PARTITION BY LIST COLUMNS(`id`) ( + PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); + +eval CREATE TABLE `tbl_c` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `surname` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_c"' +PARTITION BY LIST COLUMNS(`id`) ( + PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); + +SELECT * from tbl_b JOIN tbl_c ON tbl_b.id = tbl_c.id LEFT OUTER JOIN tbl_a ON tbl_a.id = tbl_b.id; + +--connection master_1 +DROP DATABASE auto_test_local; + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.test new file mode 100644 index 00000000..21b9dda4 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24517.test @@ -0,0 +1,80 @@ +--source ../include/mdev_24517_init.inc +--echo +--echo this test is for MDEV-24517 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +--disable_ps_protocol +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + i INT, + j JSON, + PRIMARY KEY(i) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +eval CREATE TABLE tbl_a ( + i INT, + j JSON, + PRIMARY KEY(i) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +--enable_query_log +INSERT INTO tbl_a (i, j) VALUES + (1, '{"ID": "3", "Name": "Barney", "Age": 18}'), + (2, '{"ID": "4", "Name": "Betty", "Age": 19}'), + (3, '{"ID": "2", "Name": "Wilma", "Age": 20}'), + (4, '[10, 20, [30, 40]]'); + +--echo +--echo test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Age')=19; +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Name')="Betty"; +SELECT i, JSON_EXTRACT(j, "$.ID") + FROM tbl_a + WHERE JSON_EXTRACT(j, "$.ID") > 1 AND i < 4 + ORDER BY JSON_EXTRACT(j, "$.Name"); +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[1]') = 20; +SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[2][0]') = 30; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/mdev_24517_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.test new file mode 100644 index 00000000..00c0c873 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24523.test @@ -0,0 +1,66 @@ +--source ../include/mdev_24523_init.inc +--echo +--echo this test is for MDEV-24523 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +--disable_ps_protocol +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + i INT, + j JSON, + PRIMARY KEY(i) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +eval CREATE TABLE tbl_a ( + i INT, + j JSON, + PRIMARY KEY(i) +) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1; +--enable_query_log +INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}'); + +--echo +--echo test 1 + +--connection master_1 +UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]'); +SELECT * FROM tbl_a; +TRUNCATE TABLE tbl_a; +INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}'); +UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]'); +SELECT * FROM tbl_a; +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--enable_warnings +--source ../include/mdev_24523_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test new file mode 100644 index 00000000..149b057d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_24760.test @@ -0,0 +1,49 @@ +--echo # +--echo # MDEV-24760 SELECT..CASE statement syntax error at Spider Engine table +--echo # + +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_query_log +--enable_result_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +DROP TABLE IF EXISTS tbl_a; +eval CREATE TABLE tbl_a ( + id int NOT NULL AUTO_INCREMENT, + name varchar(255) DEFAULT NULL, + PRIMARY KEY (id) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO tbl_a (name) VALUES ('Alice'), ('Bob'); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + id int NOT NULL AUTO_INCREMENT, + name varchar(255) DEFAULT NULL, + PRIMARY KEY (id) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' +PARTITION BY HASH(id) ( + PARTITION pt1 COMMENT='srv "s_2_1"' +); + +SELECT id, CASE WHEN name='Alice' THEN "A" WHEN name='Bob' THEN "B" END FROM tbl_a; +SELECT id, CASE name WHEN 'Alice' THEN "A" WHEN 'Bob' THEN "B" END FROM tbl_a; + +DROP DATABASE auto_test_local; + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test new file mode 100644 index 00000000..7ef23538 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25116.test @@ -0,0 +1,44 @@ +--echo # +--echo # MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +CREATE TABLE tbl_a (id INT); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + id INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +--connection master_1 +--disable_ps2_protocol +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +set spider_direct_aggregate=@old_spider_direct_aggregate; +--enable_ps2_protocol + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.test new file mode 100644 index 00000000..243031e5 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_25684.test @@ -0,0 +1,19 @@ +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--echo +--echo MDEV-25684 Crash in THD::find_temporary_table while calling spider_direct_sql UDF without temporary table created +--echo + +--connection master_1 +--error 12703 +SELECT SPIDER_DIRECT_SQL('SELECT * FROM s', 'non_existing_temporary_table', 'srv "s_2_1"'); + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test new file mode 100644 index 00000000..e31041c3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test @@ -0,0 +1,51 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings + +--echo +--echo MDEV-26013 distinct not work properly in some cases for spider tables +--echo + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE tbl_a ( + `a`int, + `b`int, + PRIMARY KEY (`a`) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +insert into `tbl_a` VALUES (1,999), (2,999); + +--connection master_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE tbl_a ( + `a`int, + `b`int, + PRIMARY KEY (`a`) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS(`a`) ( + PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); + +--connection master_1 +SELECT distinct b FROM tbl_a WHERE b=999; + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_remote; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26151.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26151.test new file mode 100644 index 00000000..f9e157d3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26151.test @@ -0,0 +1,54 @@ +--echo +--echo MDEV-26151 MDEV-31787 +--echo + +# This test exercises the code path where a nonzero casual_read takes +# effect. + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--let $srv=srv_mdev_26151 +set @old_spider_bgs_mode= @@spider_bgs_mode; +set session spider_bgs_mode=1; +evalp CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +# casual_read != 0 && casual_read != 1 +create table td (a int, PRIMARY KEY (a)); + +eval create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "td", casual_read "3"'; + +insert into td values (11), (42); + +select max(a) from ts; + +drop table td, ts; + +create table td (a int, PRIMARY KEY (a)); + +# casual_read = 1 +eval create table ts (a int, PRIMARY KEY (a)) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "td", casual_read "1"'; + +insert into td values (11), (42); + +select max(a) from ts; + +select min(a) from ts; + +drop table td, ts; + +eval drop server $srv; +set session spider_bgs_mode=@old_spider_bgs_mode; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log + +--echo +--echo end of test +--echo diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.test new file mode 100644 index 00000000..0484d2b6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26158.test @@ -0,0 +1,31 @@ +--echo # +--echo # MDEV-26158 SIGSEGV in spider_free_mem from ha_spider::open on INSERT +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE t ( + c INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' +PARTITION BY LIST COLUMNS(`c`) ( + PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' +); + +--error ER_BAD_DB_ERROR +INSERT INTO t SELECT * FROM t; + +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.test new file mode 100644 index 00000000..8d27c6e0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26247.test @@ -0,0 +1,85 @@ +--echo # +--echo # MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064 +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE t1 ( + a11 int, + primary key (a11) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +eval CREATE TABLE t2 ( + a21 int, + a22 int, + primary key (a21, a22) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +eval CREATE TABLE t3 ( + a31 int, + a32 int, + primary key (a31, a32) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO t1 VALUES (1), (2), (3); +INSERT INTO t2 VALUES (1, 11), (2, 22), (3, 33); +INSERT INTO t3 VALUES (1, 111), (2, 222), (3, 333); + +--connection master_1 +#FIXME: this is a workaround. +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; + +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE t1 ( + a11 int, + primary key (a11) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t1"'; + +eval CREATE TABLE t2 ( + a21 int, + a22 int, + primary key (a21, a22) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t2"'; + +eval CREATE TABLE t3 ( + a31 int, + a32 int, + primary key (a31, a32) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t3"'; + +SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 WHERE a11 IN (1); +SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 WHERE a11 IN (1); +SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1); +SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1,2); +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1); +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 RIGHT JOIN t3 on a21 = a31 - a31 WHERE a11 IN (1); +SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1,2); +SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 WHERE a11 IN (1); +SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 - a21 WHERE a11 IN (1); +SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1); +SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1,2); + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log +--echo # +--echo # end of test mdev_26247 +--echo # diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.test new file mode 100644 index 00000000..f2561f8c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26539.test @@ -0,0 +1,40 @@ +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--echo # +--echo # MDEV-26539 SIGSEGV in spider_check_and_set_trx_isolation and I_P_List_iterator from THD::drop_temporary_table (10.5.3 opt only) on ALTER +--echo # + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + c INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + c INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS (c) ( + PARTITION pt1 DEFAULT COMMENT = 'srv "s_2_1"' +); + +INSERT INTO tbl_a VALUES (1); +ALTER TABLE tbl_a CHECK PARTITION ALL; + +DROP DATABASE auto_test_local; + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26541.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26541.test new file mode 100644 index 00000000..bf6cb255 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26541.test @@ -0,0 +1,23 @@ +--echo # +--echo # MDEV-26541 Undefined symbol: _ZTI12ha_partition when attempting to use ha_spider.so in UBSAN builds +--echo # + +if (`select not(count(*)) from information_schema.system_variables where variable_name='have_sanitizer' and global_value like "%UBSAN%"`) +{ +--skip test needs to be run with UBSAN +} + +# init spider + +INSTALL SONAME 'ha_spider.so'; + +let $PLUGIN_NAME= spider_flush_table_mon_cache; +let $PLUGIN_EXIST= + `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`; +while (!$PLUGIN_EXIST) +{ + let $PLUGIN_EXIST= + `SELECT COUNT(*) FROM mysql.func WHERE name = '$PLUGIN_NAME'`; +} + +--source ../../include/clean_up_spider.inc diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.test new file mode 100644 index 00000000..ac2b6898 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26544.test @@ -0,0 +1,32 @@ +--echo # +--echo # MDEV-26544 Assertion `part_share->auto_inc_initialized' failed in ha_partition::get_auto_increment on INSERT +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection master_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE `tbl_a` ( + `a` INT AUTO_INCREMENT, KEY(`a`) +) $MASTER_1_ENGINE $MASTER_1_CHARSET +PARTITION BY LIST COLUMNS (`a`) ( + PARTITION `pt1` DEFAULT +); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT INTO tbl_a (a) VALUES (0); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT INTO tbl_a () VALUES (); + +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test new file mode 100644 index 00000000..b131b093 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test @@ -0,0 +1,27 @@ +--echo # +--echo # MDEV-26582 SIGSEGV in spider_db_bulk_insert and spider_db_connect and spider_db_before_query, and hang in "End of update loop" / "Reset for next command" query states +--echo # + +# NOTE: The bug does not reproduce if we import ../../t/test_init.inc instead. +--disable_query_log +--disable_result_log +--source ../../include/init_spider.inc +--enable_result_log +--enable_query_log + +CREATE DATABASE IF NOT EXISTS auto_test_local; +USE auto_test_local; + +CREATE TABLE t (i CHAR) ENGINE=SPIDER; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE,ER_NET_READ_ERROR +INSERT INTO t VALUES (0); +--error ER_BAD_FIELD_ERROR +INSERT t SELECT 1 ON DUPLICATE KEY UPDATE c=1; + +DROP DATABASE IF EXISTS auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../include/deinit_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.test new file mode 100644 index 00000000..d6e2ff2c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27172.test @@ -0,0 +1,94 @@ +--echo # +--echo # MDEV-27172 Prefix indices on Spider tables may lead to wrong query results +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +SET @general_log_backup = @@global.general_log; +SET @log_output_backup = @@global.log_output; +SET @@global.general_log = 1; +SET @@global.log_output = "TABLE"; + +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE tbl_a ( + id int NOT NULL, + greeting VARCHAR(255), + KEY(greeting) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +eval CREATE TABLE tbl_b ( + id int NOT NULL, + greeting VARCHAR(255), + KEY k (greeting(5)) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +eval CREATE TABLE tbl_c ( + id int NOT NULL, + greeting TEXT, + KEY k (greeting(5)) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +# = (equality) +eval CREATE TABLE tbl_a ( + id int NOT NULL, + greeting VARCHAR(255), + KEY k (greeting) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +--disable_ps2_protocol +INSERT INTO tbl_a VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_a WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; # hack to disable GBH + +# LIKE +eval CREATE TABLE tbl_b ( + id int NOT NULL, + greeting VARCHAR(255), + KEY k (greeting(5)) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_b", srv "s_2_1"'; + +INSERT INTO tbl_b VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_b WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; # hack to disable GBH + +# LIKE +eval CREATE TABLE tbl_c ( + id int NOT NULL, + greeting TEXT, + KEY k (greeting(5)) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_c", srv "s_2_1"'; + +INSERT INTO tbl_c VALUES (1, "Hi!"),(2, "Aloha!"),(3, "Aloha!!!"); +SELECT * FROM tbl_c WHERE greeting = "Aloha!" + AND CASE greeting WHEN "Aloha!" THEN "one" ELSE 'more' END = "one"; # hack to disable GBH + +--connection child2_1 +SELECT argument FROM mysql.general_log WHERE argument LIKE 'select `id`,`greeting` from %'; +--enable_ps2_protocol + +--connection child2_1 +SET @@global.general_log = @general_log_backup; +SET @@global.log_output = @log_output_backup; +DROP DATABASE auto_test_remote; + +--connection master_1 +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.test new file mode 100644 index 00000000..c7d64d2b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27184.test @@ -0,0 +1,31 @@ +--echo # +--echo # MDEV-27184 Assertion `(old_top == initial_top (av) && old_size == 0) || +--echo # ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && +--echo # ((unsigned long) old_end & (pagesize - 1)) == 0)' failed, +--echo # Assertion `str.alloced_length() >= str.length() + data_len' failed +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection master_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +CREATE TABLE tbl_a (a FLOAT) ENGINE=SPIDER; + +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE,ER_NET_READ_ERROR +INSERT INTO tbl_a VALUES + (0xF5A7),(0xF5A8),(0xF5A9),(0xF5AA),(0xF5AB),(0xF5AC),(0xF5AD),(0xF5AE), + (0xF5A7),(0xF5A8),(0xF5A9),(0xF5AA),(0xF5AB),(0xF5AC),(0xF5AD),(0xF5AE); + +DROP DATABASE auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.opt new file mode 100644 index 00000000..b0466071 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.opt @@ -0,0 +1 @@ +--init-file=$MTR_SUITE_DIR/t/mdev_27233.sql diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql new file mode 100644 index 00000000..2be9ec1f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql @@ -0,0 +1,3 @@ +INSTALL SONAME 'ha_spider.so'; +USE test; +CREATE TABLE t (c INT) ENGINE=SPIDER; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.test new file mode 100644 index 00000000..88e70f4b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27233.test @@ -0,0 +1,7 @@ +--echo # +--echo # MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table +--echo # +# ps protocol eats warnings +--disable_ps_protocol +show create table t; +--enable_ps_protocol diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.test new file mode 100644 index 00000000..3cf4bebd --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27239.test @@ -0,0 +1,24 @@ +--echo # +--echo # MDEV-27239 Spider: Assertion `thd->transaction->stmt.ha_list == __null || trans == &thd->transaction->stmt' failed in ha_commit_trans on BEGIN WORK after FTWRL +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +CREATE DATABASE auto_test_local; +USE auto_test_local; + +CREATE TABLE tbl_a (a INT) ENGINE=SPIDER; +FLUSH TABLE tbl_a WITH READ LOCK; +BEGIN; + +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.cnf new file mode 100644 index 00000000..b0853e32 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.test new file mode 100644 index 00000000..c9cc9f6e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27240.test @@ -0,0 +1,29 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings + +CREATE DATABASE auto_test_local; +USE auto_test_local; + +CREATE TABLE tbl_a (a INT KEY) ENGINE=SPIDER; +--error ER_BAD_FIELD_ERROR +SELECT a.z FROM tbl_a AS a,tbl_a b WHERE a.z=b.z; +--error ER_BAD_FIELD_ERROR +ALTER TABLE tbl_a CHANGE c c INT; +# FIXME: MDEV-32046 +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE,ER_NET_READ_ERROR +LOCK TABLE tbl_a READ; + +DROP DATABASE auto_test_local; + +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218.test new file mode 100644 index 00000000..91fdf168 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218.test @@ -0,0 +1,10 @@ +--echo # +--echo # MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +--echo # +INSTALL SONAME 'ha_spider.so'; +DROP TABLE IF EXISTS mysql.spider_tables; +--error ER_NO_SUCH_TABLE +show create table mysql.spider_tables; + +--disable_query_log +--source ../../include/clean_up_spider.inc diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.opt new file mode 100644 index 00000000..556df9cd --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.opt @@ -0,0 +1 @@ +--init-file=$MTR_SUITE_DIR/t/mdev_28218_init_file.sql diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.sql b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.sql new file mode 100644 index 00000000..ef3e1e91 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.sql @@ -0,0 +1,2 @@ +INSTALL PLUGIN spider SONAME 'ha_spider.so'; +DROP TABLE IF EXISTS mysql.spider_tables; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.test new file mode 100644 index 00000000..9152df4f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_init_file.test @@ -0,0 +1,7 @@ +--echo # +--echo # MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +--echo # +# This is a variant of the testcase in MDEV-28218, where we put the +# queries are in an init file +--error ER_NO_SUCH_TABLE +show create table mysql.spider_tables; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.opt new file mode 100644 index 00000000..5561f625 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.opt @@ -0,0 +1,2 @@ +--plugin-load-add=ha_spider +--init-file=$MTR_SUITE_DIR/t/mdev_28218_mixed.sql diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.sql b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.sql new file mode 100644 index 00000000..e408ae0c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS mysql.spider_tables; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.test new file mode 100644 index 00000000..184a5399 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28218_mixed.test @@ -0,0 +1,8 @@ +--echo # +--echo # MDEV-28218 Spider: thread hang/deadlock as result of INSTALL PLUGIN and DROP TABLE +--echo # +# this is a variant of the testcase in MDEV-28218, where we load +# spider early with --plugin_load_add, and execute the drop table +# query in an init file +--error ER_NO_SUCH_TABLE +show create table mysql.spider_tables; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.test new file mode 100644 index 00000000..47f4e57d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28854.test @@ -0,0 +1,36 @@ +--echo # +--echo # MDEV-28854 Spider: Disallow INSERT DELAYED on Spider table +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (id INT); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE tbl_a ( + id INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +--connection master_1 +--error ER_DELAYED_NOT_SUPPORTED +INSERT DELAYED INTO tbl_a VALUES (1); + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test new file mode 100644 index 00000000..4f23168e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test @@ -0,0 +1,163 @@ +--echo # +--echo # MDEV-28856 Spider: Implement more engine-defined options +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +# This test covers some table params under consideration for inclusion +# in the engine-defined options to be implemented in MDEV-28856. +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +--echo # testing monitoring_* +INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server) VALUES +('test', 't1', '0', 1, 'srv'); + +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"'; + +--error 12511 +/* 1 */ insert into t1 values (42); +--error 12514 +/* 2 */ insert into t1 values (42); +create table t2 (c int); +# Even though the table is available now, we still get "all links +# failed" error +--error 12514 +/* 3 */ insert into t1 values (42); +drop table t1, t2; + +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2", + monitoring_bg_interval "500000"'; + +# The monitoring thread was killed before it could ping the remote +# table, so the error is not 12511 or 12514 +--error ER_NO_SUCH_TABLE +/* 4 */ insert into t1 values (42); +drop table t1; + +--echo # testing query_cache_sync +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"'; +create table t2 (c int); +/* 5 */ insert into t1 values (42); +select sql_cache * from t1; +select sql_no_cache * from t1; + +drop table t1, t2; + +--echo # testing tgt_pk_names +# can insert duplicates... +create table t2 (c int); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 6 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# pk_names not used because no key declared in t1, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 7 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# pk_name is the default "PRIMARY", 1062 +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 8 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name c does not match PRIMARY, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# local primary key name c matches remote unique key name c, 1062 but +# warning says PRIMARY instead of c, because key->name is PRIMARY +# instead of c +create table t2 (c int, unique key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9.1 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name f does not match t2 key name, but it is not used any way +# because there's no primary key, 1062 +create table t2 (c int, unique key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"'; +/* 10 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name blah does not match t2 error key name PRIMARY, and the +# non-primary key-route does not return PRIMARY, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 11 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name blah does not match t2 key name, but still 1062, because we +# go through the non-primary key route +create table t2 (c int, d int, unique key (c), unique key (d)); +create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 12 */ insert ignore into t1 values (42, 43), (43, 43); +select * from t1; + +drop table t1, t2; + +--echo # Testing index hint +create table t2 (c int, d int, primary key (c), key (d)); +show create table t2; +create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"'; +show create table t1; +/* 13 */ insert into t1 values (42, 23), (37, 93); +select max(d) from t1; + +drop table t1, t2; + +# multiple indices +create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e)); +show create table t2; +create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"'; +show create table t1; +/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47); +select max(d) from t1; + +drop table t1, t2; + +drop server srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test mdev_28856 +--echo # diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.test new file mode 100644 index 00000000..8097fe7e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28996.test @@ -0,0 +1,40 @@ +--echo # +--echo # MDEV-28996 ASAN errors in String::q_append / spider_string::q_append / spider_db_mbase_util::open_item_func +--echo # + +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_query_log +--enable_result_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +eval CREATE TABLE tbl_a ( + a CHAR(8) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO tbl_a VALUES ('foo'),('bar'); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + a CHAR(8) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +SELECT MAX(BINARY a) FROM tbl_a; + +DROP DATABASE auto_test_local; + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28998.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28998.test new file mode 100644 index 00000000..d67011ca --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28998.test @@ -0,0 +1,39 @@ +--echo # +--echo # MDEV-28998 ASAN errors in spider_fields::free_conn_holder or spider_create_group_by_handler +--echo # + +if (`select not(count(*)) from information_schema.system_variables where variable_name='have_sanitizer' and global_value like "%ASAN%"`) +{ +--skip test needs to be run with ASAN +} + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +# FIXME: this is a workaround. +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; +evalp CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t1_SPIDER (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'"; + +CREATE TABLE t2 AS SELECT a FROM t1_SPIDER; +SELECT * FROM t2; + +# Cleanup +DROP TABLE t2, t1_SPIDER, t1; +drop server s; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test mdev_28998 +--echo # diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.test new file mode 100644 index 00000000..28d9a924 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29008.test @@ -0,0 +1,39 @@ +--echo # +--echo # MDEV-29008 Server crash or assertion `field' failed in spider_db_open_item_ident / group by handler +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a INT, + b INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +INSERT INTO tbl_a VALUES (1,2),(3,4); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE tbl_a ( + a INT, + b INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +SELECT MIN(t2.a) AS f1, t1.b AS f2 FROM tbl_a AS t1 JOIN tbl_a AS t2 GROUP BY f2 ORDER BY f1, f2; + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.test new file mode 100644 index 00000000..6aaf9305 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29011.test @@ -0,0 +1,40 @@ +--echo # +--echo # MDEV-29011 Server crash in spider_db_open_item_cond with XOR operator +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a INT, + b INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +INSERT INTO tbl_a VALUES (0, 0), (0, 1), (1, 0), (1, 1); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE tbl_a ( + a INT, + b INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +SELECT a XOR b AS f FROM tbl_a; + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29163.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29163.test new file mode 100644 index 00000000..0bfcc46f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29163.test @@ -0,0 +1,36 @@ +--echo # +--echo # MDEV-29163 Server crash with SIGSEGV or dynamic-stack-buffer-overflow in spider_db_mbase_util::append_table +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +#FIXME: this is a workaround. +set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler; +set spider_disable_group_by_handler=1; +evalp CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT); +CREATE TABLE t3 (c INT, PRIMARY KEY(c)); + +CREATE TABLE t1_spider (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'"; +CREATE TABLE t2_spider (b INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't2'"; +CREATE TABLE t3_spider (c INT, PRIMARY KEY(c)) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't3'"; + +SELECT t1_spider.* FROM t1_spider LEFT JOIN t2_spider LEFT JOIN t3_spider ON b = c ON a = b; + +# Cleanup +DROP TABLE t1_spider, t2_spider, t3_spider, t1, t2, t3; +drop server s; +set spider_disable_group_by_handler=@old_spider_disable_group_by_handler; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test mdev_29163 +--echo # diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test new file mode 100644 index 00000000..626364ef --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test @@ -0,0 +1,11 @@ +CREATE TABLE t (c INT); +SHOW CREATE TABLE t; +FLUSH TABLES WITH READ LOCK; + +--error ER_CANT_UPDATE_WITH_READLOCK +CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; +SELECT * FROM t; + +--source include/restart_mysqld.inc + +DROP TABLE t; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.test new file mode 100644 index 00000000..60250be6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29447.test @@ -0,0 +1,37 @@ +--echo # +--echo # MDEV-29447 SIGSEGV in spider_db_open_item_field and SIGSEGV spider_db_print_item_type, on SELECT +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE tbl_a ( + a INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +SELECT TRIM(LEADING 'c' FROM a) FROM tbl_a; + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--connection master_1 +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.test new file mode 100644 index 00000000..b6fe3b54 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29484.test @@ -0,0 +1,47 @@ +--echo # +--echo # MDEV-29484 Assertion `!trx_free || !trx->locked_connections' failed in spider_free_trx_conn on LOCK TABLES +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + a INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +eval CREATE TABLE tbl_b ( + a INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET; + +LOCK TABLES tbl_a WRITE; +--error 1429 +LOCK TABLES tbl_b READ, tbl_a READ; + +--disconnect master_1 # crash +--source ../../t/connect_master_1.inc + +--connection child2_1 +DROP DATABASE auto_test_remote; + +--connection master_1 +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test new file mode 100644 index 00000000..88591f80 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test @@ -0,0 +1,67 @@ +--echo # +--echo # MDEV-29502 ASAN: heap-buffer-overflow & stack-buffer-overflow in spider_db_mbase_row::append_to_str | SIGSEGV's in __memmove_avx_unaligned_erms from memcpy in Binary_string::q_append, in Static_binary_string::q_append and my_strntoull10rnd_8bit | Unknown error 12801 +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--let $srv=srv_mdev_29502 +evalp CREATE SERVER $srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +CREATE TABLE t (a INT); +INSERT INTO t VALUES (23),(48); + +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; + +eval CREATE TABLE t1 (a INT KEY) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "$srv",TABLE "t"'; + +SELECT MAX(a) FROM t1; +SELECT SUM(a) FROM t1; +SELECT COUNT(a) FROM t1; +SELECT MAX(a), SUM(a) FROM t1; +SELECT COUNT(a), MAX(a), SUM(a) FROM t1; +SELECT MAX(a), COUNT(a), SUM(a) FROM t1; +SELECT MAX(a), MAX(COALESCE(a)) FROM t1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; + +DROP TABLE t, t1; + +CREATE TABLE t (a INT, b INT); +INSERT INTO t VALUES (23, -1),(48, 97); + +eval CREATE TABLE t1 (a INT, b INT) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "$srv",TABLE "t"'; + +SELECT MAX(a + b), SUM(a - b) FROM t1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; + +DROP TABLE t, t1; + +# An example where GBH is not created (MDEV-25116), and direct +# aggregate is used to speed up the query. +CREATE TABLE t (a INT); +INSERT INTO t VALUES (23),(97),(42); + +eval CREATE TABLE t1 (a INT) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "$srv",TABLE "t"'; + +--disable_ps2_protocol +SELECT IF(COUNT(a > 0),'Y','N'), MAX(a) FROM t1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +SELECT MAX(a), IF(COUNT(a > 0),'Y','N') FROM t1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +--enable_ps2_protocol + +DROP TABLE t, t1; + +set spider_direct_aggregate=@old_spider_direct_aggregate; + +eval DROP SERVER $srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.test new file mode 100644 index 00000000..5ddb2cef --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29562.test @@ -0,0 +1,54 @@ +--echo # +--echo # MDEV-29562 Spider table with charset utf32/utf16/ucs2 tries to set client charset to unsupported value +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +--error ER_ILLEGAL_HA_CREATE_OPTION +eval CREATE TABLE tbl_a ( + a INT +) $MASTER_1_ENGINE CHARSET utf32 COMMENT='table "tbl_a", srv "s_2_1"'; + +ALTER DATABASE auto_test_local CHARSET="ucs2"; +--error ER_ILLEGAL_HA_CREATE_OPTION +eval CREATE TABLE tbl_a ( + a INT +) $MASTER_1_ENGINE COMMENT='table "tbl_a", srv "s_2_1"'; + +eval CREATE TABLE tbl_a ( + a INT +) $MASTER_1_ENGINE CHARSET utf8 COMMENT='table "tbl_a", srv "s_2_1"'; +SELECT * FROM tbl_a; + +--error ER_ILLEGAL_HA_CREATE_OPTION +ALTER TABLE tbl_a CONVERT TO CHARACTER SET utf16; +--error ER_ILLEGAL_HA_CREATE_OPTION +ALTER TABLE tbl_a CONVERT TO CHARACTER SET utf16le; + +ALTER TABLE tbl_a CONVERT TO CHARACTER SET latin1; + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.test new file mode 100644 index 00000000..3a8fbb25 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29644.test @@ -0,0 +1,56 @@ +--echo # +--echo # MDEV-29644 a potential bug of null pointer dereference in spider_db_mbase::print_warnings() +--echo # + +# The test case below does not cause the potential null pointer dereference. +# It is just for checking spider_db_mbase::fetch_and_print_warnings() works. + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE tbl_a ( + a CHAR(5) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +SET GLOBAL sql_mode=''; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE tbl_a ( + a CHAR(255) +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; + +SET sql_mode=''; + +let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.1.err; +let SEARCH_PATTERN= \[WARN SPIDER RESULT\].* Warning 1265 Data truncated for column 'a' at row 1.*; + +INSERT INTO tbl_a VALUES ("this will be truncated"); +--source include/search_pattern_in_file.inc # should not find + +SET GLOBAL spider_log_result_errors=4; + +INSERT INTO tbl_a VALUES ("this will be truncated"); +--source include/search_pattern_in_file.inc # should find + +--connection master_1 +SET GLOBAL spider_log_result_errors=DEFAULT; +SET sql_mode=DEFAULT; +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +SET GLOBAL sql_mode=DEFAULT; +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.test new file mode 100644 index 00000000..6accaed3 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29653.test @@ -0,0 +1,37 @@ +--echo # +--echo # MDEV-29653 Assertion `0' failed in Item_cache_row::illegal_method_call on SELECT from Spider table +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +eval CREATE TABLE t ( + c INT +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +eval CREATE TABLE ts ( + c INT +) $MASTER_1_ENGINE COMMENT='table "t", srv "s_2_1"'; + +SELECT 1 FROM ts WHERE ROW(c, c) NOT IN ((0,0),(1,1)); + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; + +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_query_log +--enable_result_log diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test new file mode 100644 index 00000000..d3dcb363 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29904.test @@ -0,0 +1,6 @@ +--echo # +--echo # MDEV-29904 SPIDER plugin initialization fails upon startup +--echo # + +--let $restart_parameters=--plugin-load-add=ha_spider +--source include/restart_mysqld.inc diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.cnf new file mode 100644 index 00000000..05dfd8a0 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.test new file mode 100644 index 00000000..8d19a351 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_30191.test @@ -0,0 +1,51 @@ +--echo # +--echo # MDEV-30191 SIGSEGV & heap-use-after-free in spider_db_print_item_type, SIGABRT in __cxa_pure_virtual/spider_db_print_item_type, Got error 128 "Out of memory in engine", 56/112 memory not freed, and Assertion `fixed()' failed in Item_sp_variable::val_str on SP call +--echo # + +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE tbl_a (c INT); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +eval CREATE TABLE tbl_a ( + c INT +) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"'; +CREATE TABLE tbl_b (c INT); + +--delimiter $$ +CREATE PROCEDURE sp() BEGIN + DECLARE v1 DATE; + WHILE EXISTS (SELECT 1 FROM tbl_a WHERE c>v1 AND c<=v1) DO + SELECT 1; + END WHILE; + WHILE EXISTS (SELECT 1 + FROM tbl_a + WHERE c 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 +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +connection master_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 + +insert select +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +connection master_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 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 +connection master_1; +TRUNCATE TABLE ta_l; +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'); +connection master_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 e 2008-01-01 23:59:59 + +insert low_priority +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT LOW_PRIORITY INTO ta_l (a, b, c) values (2, 'e', '2008-01-01 23:59:59'); +connection master_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 + +insert high_priority +connection master_1; +TRUNCATE TABLE ta_l; +connection master_1; +INSERT HIGH_PRIORITY INTO ta_l (a, b, c) VALUES (2, 'e', +'2008-01-01 23:59:59'); +connection master_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 + +insert ignore +connection master_1; +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' +connection master_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 + +insert update (insert) +connection master_1; +TRUNCATE TABLE ta_l; +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'; +connection master_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 + +insert update (update) +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'; +connection master_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 f 2005-08-08 11:11:11 + +replace +connection master_1; +TRUNCATE TABLE ta_l; +INSERT INTO ta_l (a, b, c) VALUES (2, 'e', '2008-01-01 23:59:59'); +connection master_1; +REPLACE INTO ta_l (a, b, c) VALUES (2, 'f', '2008-02-02 02:02:02'); +connection master_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 f 2008-02-02 02:02:02 + +replace select +connection master_1; +REPLACE INTO ta_l (a, b, c) SELECT a, b, c FROM tb_l; +connection master_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 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 +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'); +connection master_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 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 +connection master_1; +REPLACE LOW_PRIORITY INTO ta_l (a, b, c) VALUES (3, 'g', +'2009-03-03 03:03:03'); +connection master_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 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'); +connection master_1; +UPDATE ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +connection master_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 e 2008-01-01 23:59:59 +2 f 2008-02-02 02:02:02 + +update select +connection master_1; +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a IN (SELECT a FROM +tb_l); +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update select a +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); +connection master_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 +connection master_1; +UPDATE ta_l a, tb_l b SET a.b = b.b, a.c = b.c WHERE a.a = b.a; +connection master_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 f 2008-07-01 10:21:39 +2 g 2000-02-01 00:00:00 + +update join a +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; +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +update low_priority +connection master_1; +UPDATE LOW_PRIORITY ta_l SET b = 'f', c = '2008-02-02 02:02:02' WHERE a = 2; +connection master_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 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update ignore +connection master_1; +UPDATE IGNORE ta_l SET a = 1, b = 'g', c = '2009-03-03 03:03:03' WHERE a = 2; +connection master_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 g 2009-03-03 03:03:03 +2 f 2008-02-02 02:02:02 + +update pushdown +connection master_1; +update ta_l set b = 'j', c = '2009-03-03 03:03:03' where b = 'f'; +connection master_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 g 2009-03-03 03:03:03 +2 j 2009-03-03 03:03:03 + +update index pushdown +connection master_1; +UPDATE ta_l SET b = 'g', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'j'; +connection master_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 g 2009-03-03 03:03:03 +2 g 2009-03-03 03:03:03 + +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'); +connection master_1; +DELETE FROM ta_l WHERE a = 2; +connection master_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 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 +connection master_1; +DELETE FROM ta_l; +connection master_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') + +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'); +connection master_1; +DELETE FROM ta_l WHERE a IN (SELECT a FROM tb_l); +connection master_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') +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'); +connection master_1; +DELETE FROM ta_l WHERE a = (SELECT a FROM tb_l ORDER BY a LIMIT 1); +connection master_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'); +connection master_1; +DELETE a FROM ta_l a, (SELECT a FROM tb_l ORDER BY a) b WHERE a.a = b.a; +connection master_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') +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'); +connection master_1; +DELETE LOW_PRIORITY FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE IGNORE FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE QUICK FROM ta_l WHERE a = 2; +connection master_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 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'); +connection master_1; +DELETE FROM ta_l WHERE b = 'e'; +connection master_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') +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'); +connection master_1; +DELETE FROM ta_l WHERE a > 0 AND b = 'e'; +connection master_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') +10 j 2008-01-01 23:59:59 + +truncate +connection master_1; +TRUNCATE TABLE ta_l; +connection master_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') +connection master_1; +create table t2345678911234567892123456789312345678941234567895123234234(id int) ENGINE=SPIDER +COMMENT='host "192.168.21.1", user "spider", password "password", database "test32738123123123"'; +drop table t2345678911234567892123456789312345678941234567895123234234; +# +# MDEV-26139 Spider crashes with segmentation fault (signal 11) on CREATE TABLE when COMMENT does not contain embedded double quotes +# +create table mdev_26139 (id int) ENGINE=SPIDER +COMMENT="host '192.168.21.1', user 'spider', password 'password', database 'test'"; +drop table mdev_26139; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/basic_sql_part.result b/storage/spider/mysql-test/spider/r/basic_sql_part.result new file mode 100644 index 00000000..0f402940 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/basic_sql_part.result @@ -0,0 +1,141 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection master_1; +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 with partition and select test +connection master_1; +CREATE TABLE ta_l2 ( +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT_P_2_1 +SELECT a, b, c FROM tb_l +connection master_1; +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 + +select partition using pushdown +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; +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 +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; +a b date_format(a.c, '%Y-%m-%d %H:%i:%s') +2 g 2000-02-01 00:00:00 + +update partition pushdown +connection master_1; +UPDATE ta_l2 SET b = 'e', c = '2009-03-03 03:03:03' WHERE b = 'j'; +connection master_1; +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 +connection master_1; +UPDATE ta_l2 SET b = 'j', c = '2009-03-03 03:03:03' WHERE a > 0 AND b = 'e'; +connection master_1; +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 partition pushdown +TRUNCATE TABLE ta_l2; +INSERT INTO ta_l2 SELECT a, b, c FROM tb_l; +connection master_1; +DELETE FROM ta_l2 WHERE b = 'g'; +connection master_1; +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; +connection master_1; +DELETE FROM ta_l2 WHERE a > 0 AND b = 'g'; +connection master_1; +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 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/checksum_table_with_quick_mode_3.result b/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result new file mode 100644 index 00000000..ff6b968c --- /dev/null +++ b/storage/spider/mysql-test/spider/r/checksum_table_with_quick_mode_3.result @@ -0,0 +1,104 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +FLUSH TABLES; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +CHECKSUM TABLE tbl_a EXTENDED; +Table Checksum +auto_test_local.tbl_a 1061386331 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%checksum %'; +argument +checksum table `auto_test_remote`.`tbl_a` extended +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%checksum %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +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 00000000..2455fe18 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_aggregate.result @@ -0,0 +1,120 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table select test +connection master_1; +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 +connection master_1; +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 0 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT MIN(a) FROM ta_l WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SET spider_direct_aggregate=0; +SELECT COUNT(*) FROM ta_l; +COUNT(*) +5 +SELECT MAX(a) FROM ta_l; +MAX(a) +5 +SELECT MIN(a) FROM ta_l; +MIN(a) +1 +SELECT MAX(a) FROM ta_l WHERE a < 5; +MAX(a) +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 0 +SET spider_direct_aggregate=1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_part.result b/storage/spider/mysql-test/spider/r/direct_aggregate_part.result new file mode 100644 index 00000000..9d65fcc2 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_aggregate_part.result @@ -0,0 +1,121 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +with partition test +connection master_1; +CREATE TABLE ta_l2 ( +a INT, +b CHAR(1), +c DATETIME, +PRIMARY KEY(a) +) MASTER_1_ENGINE MASTER_1_COMMENT2_P_2_1 +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 4 +SELECT SUM(a) FROM ta_l2; +SUM(a) +15 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +SET spider_direct_aggregate=0; +SELECT COUNT(*) FROM ta_l2; +COUNT(*) +5 +SELECT SUM(a) FROM ta_l2; +SUM(a) +15 +SELECT MAX(a) FROM ta_l2; +MAX(a) +5 +SELECT MIN(a) FROM ta_l2; +MIN(a) +1 +SELECT MAX(a) FROM ta_l2 WHERE a < 5; +MAX(a) +4 +SELECT MIN(a) FROM ta_l2 WHERE a > 1; +MIN(a) +2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 8 +set spider_direct_aggregate=@old_spider_direct_aggregate; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_join.result b/storage/spider/mysql-test/spider/r/direct_join.result new file mode 100644 index 00000000..398985ac --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_join.result @@ -0,0 +1,197 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES5 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES5 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c FROM tbl_a a, tbl_b b, tbl_c c WHERE a.a = b.a and a.a = c.a ORDER BY a.b DESC LIMIT 1,2; +a b c +4 40 400 +3 30 300 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc limit 1,2 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 +3 c 2000-01-03 00:00:00 +4 d 2000-01-04 00:00:00 +5 e 2000-01-05 00:00:00 + +Test JOIN on a constant table. +Spider should NOT push down the join because the tbl_person table +is optimized as a constant table. +connection child2_1; +CHILD2_1_DROP_CONST_TABLE_JOIN +CHILD2_1_DROP_CONST_TABLE2_JOIN +CHILD2_1_CREATE_CONST_TABLE_JOIN +CHILD2_1_CREATE_CONST_TABLE2_JOIN +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_person; +DROP TABLE IF EXISTS tbl_ncd_cm_person; +CREATE TABLE tbl_person ( +id VARCHAR(50) NOT NULL, +hr_status VARCHAR(50) NULL DEFAULT NULL, +region_code VARCHAR(50) NULL DEFAULT NULL, +region INT(11) NOT NULL, +PRIMARY KEY (id, region) USING BTREE +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_CONST_TABLE_JOIN +MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN MASTER_1_PART_CONST_TABLE_JOIN +SHOW CREATE TABLE tbl_person +Table Create Table +tbl_person CREATE TABLE `tbl_person` ( + `id` varchar(50) NOT NULL, + `hr_status` varchar(50) DEFAULT NULL, + `region_code` varchar(50) DEFAULT NULL, + `region` int(11) NOT NULL, + PRIMARY KEY (`id`,`region`) USING BTREE +) ENGINE=SPIDER DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=DYNAMIC COMMENT='table "tbl_ncd_cm_person"' + PARTITION BY LIST COLUMNS(`region`) +(PARTITION `pt1` VALUES IN (510411) COMMENT = 'tbl "tbl_person", srv "s_2_1"' ENGINE = SPIDER) +CREATE TABLE tbl_ncd_cm_person ( +id VARCHAR(50) NOT NULL, +person_id VARCHAR(50) NULL DEFAULT '', +diseaseKind_id VARCHAR(50) NULL DEFAULT NULL, +region INT(11) NOT NULL, +PRIMARY KEY (id, region) USING BTREE +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_CONST_TABLE2_JOIN +MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN MASTER_1_PART_CONST_TABLE2_JOIN +SHOW CREATE TABLE tbl_ncd_cm_person +Table Create Table +tbl_ncd_cm_person CREATE TABLE `tbl_ncd_cm_person` ( + `id` varchar(50) NOT NULL, + `person_id` varchar(50) DEFAULT '', + `diseaseKind_id` varchar(50) DEFAULT NULL, + `region` int(11) NOT NULL, + PRIMARY KEY (`id`,`region`) USING BTREE +) ENGINE=SPIDER DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=DYNAMIC + PARTITION BY LIST COLUMNS(`region`) +(PARTITION `pt1` VALUES IN (510411) COMMENT = 'tbl "tbl_ncd_cm_person", srv "s_2_1"' ENGINE = SPIDER) +INSERT INTO tbl_person VALUES ('24FC3F0A5119432BAE13DD65AABAA39C', +'1', '123-51041110620301-321', 510411); +INSERT INTO tbl_person VALUES ('123456789012345678901234567890AB', +'1', '123-51041110620301-321', 510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789', +'24FC3F0A5119432BAE13DD65AABAA39C', +'52A0328740914BCE86ED10A4D2521816', +510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789AB', +'123456789012345678901234567890AB', +'52A0328740914BCE86ED10A4D2521816', +510411); +DELETE FROM tbl_ncd_cm_person; +INSERT INTO tbl_ncd_cm_person VALUES ('123456789', +'24FC3F0A5119432BAE13DD65AABAA39C', +'52A0328740914BCE86ED10A4D2521816', +510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789AB', +'123456789012345678901234567890AB', +'52A0328740914BCE86ED10A4D2521816', +510411); +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT count(0) FROM tbl_person tp INNER JOIN tbl_ncd_cm_person tncp ON tp.id = tncp.person_id WHERE 1 = 1 AND tp.hr_status != "99" AND tp.hr_status != "2" AND tp.region_code LIKE CONCAT(CONCAT('%', '51041110620301', '%')) AND tp.id = '24FC3F0A5119432BAE13DD65AABAA39C' AND tncp.diseaseKind_id = '52A0328740914BCE86ED10A4D2521816' AND tp.region = 510411; +count(0) +1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `id`,`hr_status`,`region_code`,`region` from `auto_test_remote`.`tbl_person` where `id` = '24FC3F0A5119432BAE13DD65AABAA39C' and `region` = 510411 +select count(0) `count(0)` from `auto_test_remote`.`tbl_ncd_cm_person` t0 where ((t0.`person_id` = '24FC3F0A5119432BAE13DD65AABAA39C') and (t0.`diseaseKind_id` = '52A0328740914BCE86ED10A4D2521816')) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT * FROM tbl_person; +id hr_status region_code region +123456789012345678901234567890AB 1 123-51041110620301-321 510411 +24FC3F0A5119432BAE13DD65AABAA39C 1 123-51041110620301-321 510411 +SELECT * FROM tbl_ncd_cm_person; +id person_id diseaseKind_id region +123456789 24FC3F0A5119432BAE13DD65AABAA39C 52A0328740914BCE86ED10A4D2521816 510411 +123456789AB 123456789012345678901234567890AB 52A0328740914BCE86ED10A4D2521816 510411 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_join_using.result b/storage/spider/mysql-test/spider/r/direct_join_using.result new file mode 100644 index 00000000..facfabfe --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_join_using.result @@ -0,0 +1,108 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES5 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES5 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c FROM tbl_a a join tbl_b b using(a) join tbl_c c using(a) ORDER BY a.b DESC; +a b c +5 50 500 +4 40 400 +3 30 300 +2 20 200 +1 10 100 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 +3 c 2000-01-03 00:00:00 +4 d 2000-01-04 00:00:00 +5 e 2000-01-05 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_left_join.result b/storage/spider/mysql-test/spider/r/direct_left_join.result new file mode 100644 index 00000000..1af1a661 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_left_join.result @@ -0,0 +1,108 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES5 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES5 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c FROM tbl_a a left join tbl_b b on a.a = b.a left join tbl_c c on a.a = c.a ORDER BY a.b DESC; +a b c +5 50 500 +4 40 400 +3 30 300 +2 20 200 +1 10 100 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 left join `auto_test_remote`.`ta_r_3` t1 on (t1.`a` = t0.`a`) left join `auto_test_remote`.`ta_r_int` t2 on (t2.`a` = t0.`a`) where 1 order by t0.`b` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 +3 c 2000-01-03 00:00:00 +4 d 2000-01-04 00:00:00 +5 e 2000-01-05 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_left_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_left_join_nullable.result new file mode 100644 index 00000000..4adfb1bd --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_left_join_nullable.result @@ -0,0 +1,113 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_d a left join tbl_c b on a.a = b.a left join tbl_b c on b.c = c.c left join tbl_a d on c.b = d.b ORDER BY a.a DESC; +a b c a +5 NULL NULL NULL +4 NULL NULL NULL +3 c 2000-01-03 00:00:00 NULL +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t0 left join `auto_test_remote`.`ta_r_auto_inc` t1 on (t1.`a` = t0.`a`) left join `auto_test_remote`.`ta_r_3` t2 on (t2.`c` = t1.`c`) left join `auto_test_remote`.`ta_r` t3 on (t3.`b` = t2.`b`) where 1 order by t0.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_left_right_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_left_right_join_nullable.result new file mode 100644 index 00000000..a6bd3a7c --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_left_right_join_nullable.result @@ -0,0 +1,113 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_a a left join tbl_b b on a.a = b.a left join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; +a b c a +NULL NULL NULL 5 +NULL NULL NULL 4 +NULL NULL NULL 3 +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_auto_inc` t2 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null)) where 1 order by t3.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_left_right_left_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_left_right_left_join_nullable.result new file mode 100644 index 00000000..8fab6d24 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_left_right_left_join_nullable.result @@ -0,0 +1,112 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_a a left join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c left join tbl_d d on c.b = d.b ORDER BY d.a DESC; +a b c a +NULL d 2000-01-04 00:00:00 4 +NULL c 2000-01-03 00:00:00 3 +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join (`auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t1.`c` = t2.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null)) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_right_join.result b/storage/spider/mysql-test/spider/r/direct_right_join.result new file mode 100644 index 00000000..d7780b94 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_right_join.result @@ -0,0 +1,108 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES5 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES5 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +PRIMARY KEY(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on a.a = c.a ORDER BY a.b DESC; +a b c +5 50 500 +4 40 400 +3 30 300 +2 20 200 +1 10 100 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r_int` t2 left join (`auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1) on ((t0.`a` = t2.`a`) and (t1.`a` = t2.`a`)) where 1 order by t0.`b` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 +3 c 2000-01-03 00:00:00 +4 d 2000-01-04 00:00:00 +5 e 2000-01-05 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_right_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_right_join_nullable.result new file mode 100644 index 00000000..5101ea50 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_right_join_nullable.result @@ -0,0 +1,113 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; +a b c a +NULL NULL NULL 5 +NULL d 2000-01-04 00:00:00 4 +NULL c 2000-01-03 00:00:00 3 +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join `auto_test_remote`.`ta_r_auto_inc` t2 on (t2.`b` = t3.`b`) left join `auto_test_remote`.`ta_r_3` t1 on (t1.`c` = t2.`c`) left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null)) where 1 order by t3.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_right_left_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_right_left_join_nullable.result new file mode 100644 index 00000000..c90fe3ab --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_right_left_join_nullable.result @@ -0,0 +1,112 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c left join tbl_d d on c.b = d.b ORDER BY d.a DESC; +a b c a +NULL d 2000-01-04 00:00:00 4 +NULL c 2000-01-03 00:00:00 3 +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join `auto_test_remote`.`ta_r_3` t1 on (t1.`c` = t2.`c`) left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null)) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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_right_left_right_join_nullable.result b/storage/spider/mysql-test/spider/r/direct_right_left_right_join_nullable.result new file mode 100644 index 00000000..f6c808be --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_right_left_right_join_nullable.result @@ -0,0 +1,113 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES6 +CHILD2_1_DROP_TABLES4 +CHILD2_1_DROP_TABLES3 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES6 +CHILD2_1_CREATE_TABLES4 +CHILD2_1_CREATE_TABLES3 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1 +CREATE TABLE tbl_c ( +a INT AUTO_INCREMENT, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10', +KEY idx0(a), +KEY idx1(b), +KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1 +CREATE TABLE tbl_d ( +a INT DEFAULT 10, +b CHAR(1) DEFAULT 'c', +c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1 +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a left join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; +a b c a +NULL NULL NULL 5 +NULL NULL NULL 4 +NULL c 2000-01-03 00:00:00 3 +2 b 2000-01-02 00:00:00 2 +1 a 2000-01-01 00:00:00 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_auto_inc` t2 join `auto_test_remote`.`ta_r_3` t1 left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null))) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`)) where 1 order by t3.`a` desc +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a; +a b date_format(c, '%Y-%m-%d %H:%i:%s') +1 a 2000-01-01 00:00:00 +2 b 2000-01-02 00:00:00 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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 00000000..0e536d48 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_update.result @@ -0,0 +1,155 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table select test +connection master_1; +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 +connection master_1; +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 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_part.result b/storage/spider/mysql-test/spider/r/direct_update_part.result new file mode 100644 index 00000000..7069cd72 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/direct_update_part.result @@ -0,0 +1,145 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +with partition test +connection master_1; +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 0 +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 2 +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 3 +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 5 +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 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 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 1 +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 3 +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 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 +4 d 2003-12-01 05:01:03 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/error_row_number.result b/storage/spider/mysql-test/spider/r/error_row_number.result new file mode 100644 index 00000000..cc2b5487 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/error_row_number.result @@ -0,0 +1,45 @@ +# +# MDEV-26693 ROW_NUMBER is wrong upon INSERT or UPDATE on Spider table +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection child2_1; +create database auto_test_remote; +use auto_test_remote; +create table ta_r (id int primary key); +connection master_1; +create table spd (id int primary key) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +insert into spd values (1),(2),(1); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +get diagnostics condition 1 @n = row_number; +select @n; +@n +0 +delete from spd; +insert into spd values (1),(2),(3),(13); +update spd set id = id + 10; +ERROR 23000: Duplicate entry '13' for key 'PRIMARY' +get diagnostics condition 1 @n = row_number; +select @n; +@n +0 +drop table spd; +connection child2_1; +drop database auto_test_remote; +connection master_1; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 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 00000000..c088a8a9 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/function.result @@ -0,0 +1,160 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +in() +connection master_1; +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; +connection master_1; +select a from t1 where a in ('15', '120'); +a +120 +15 + +date_sub() +connection master_1; +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); +connection master_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 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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..3c37c2d5 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/ha.result @@ -0,0 +1,286 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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-01-01 00:00:00 +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 +connection master_1; +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 +connection master_1; +ALTER TABLE ta_l +CONNECTION='host "localhost", user "root", password "", + msi "5", mkd "2", + database "auto_test_remote auto_test_remote2", lst "0 2"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; +connection master_1; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +active standby test +create table test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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-01-01 00:00:00 +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 +connection master_1; +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_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_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 +connection master_1; +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"'; +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; +connection master_1; +SELECT spider_flush_table_mon_cache(); +spider_flush_table_mon_cache() +1 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +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; +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; +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/ha_part.result b/storage/spider/mysql-test/spider/r/ha_part.result new file mode 100644 index 00000000..d191cab3 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/ha_part.result @@ -0,0 +1,320 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table with partition test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_1; +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 +connection master_1; +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_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_l2#P#pt2 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_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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; + +create table with partition test +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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 +connection master_1; +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 +connection master_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_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_l2#P#pt2 1 +auto_test_local ta_l2#P#pt2 0 +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_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 +connection master_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"' + ); +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +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; +connection master_1; +CREATE TABLE t (c INT) PARTITION BY LIST COLUMNS (c) (PARTITION p DEFAULT ENGINE=SPIDER); +SHOW FIELDS FROM t; +Field Type Null Key Default Extra +c int(11) YES NULL +SHOW FIELDS FROM t; +Field Type Null Key Default Extra +c int(11) YES NULL +DROP TABLE t; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +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; +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; +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/partition_cond_push.result b/storage/spider/mysql-test/spider/r/partition_cond_push.result new file mode 100644 index 00000000..dd91e4b7 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/partition_cond_push.result @@ -0,0 +1,168 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_3; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_DROP_TABLES +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_3; +CHILD2_3_DROP_TABLES +CHILD2_3_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +CREATE TABLE tbl_a ( +value int NOT NULL +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (value) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (value) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (value) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT value FROM tbl_a WHERE value < 100; +value +4 +5 +10 +11 +16 +17 +22 +23 +28 +29 +0 +1 +6 +7 +12 +13 +18 +19 +24 +25 +2 +3 +8 +9 +14 +15 +20 +21 +26 +27 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `value` from `auto_test_remote`.`tbl_a` where (`value` < 100) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +4 +5 +10 +11 +16 +17 +22 +23 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `value` from `auto_test_remote2`.`tbl_a` where (`value` < 100) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +0 +1 +6 +7 +12 +13 +18 +19 +24 +25 +connection child2_3; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `value` from `auto_test_remote3`.`tbl_a` where (`value` < 100) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +2 +3 +8 +9 +14 +15 +20 +21 +26 +27 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection child2_3; +DROP DATABASE IF EXISTS auto_test_remote3; +SET GLOBAL log_output = @old_log_output; +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/partition_fulltext.result b/storage/spider/mysql-test/spider/r/partition_fulltext.result new file mode 100644 index 00000000..581c731b --- /dev/null +++ b/storage/spider/mysql-test/spider/r/partition_fulltext.result @@ -0,0 +1,126 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_join_cache_level= @@join_cache_level; +set session join_cache_level= 5; +set @old_optimizer_switch= @@optimizer_switch; +set session optimizer_switch= 'mrr=on'; + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_3; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_DROP_TABLES +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_3; +CHILD2_3_DROP_TABLES +CHILD2_3_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +words text NOT NULL, +PRIMARY KEY (pkey), +FULLTEXT (words) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey, words) VALUES (0, 'abc'),(1, 'def'),(2, 'ghi'),(3, 'jkl'),(4, 'mno'),(5, 'pqr'),(6, 'stu'),(7, 'vwx'); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT pkey, words FROM tbl_a WHERE match(words) against('+ghi' in boolean mode); +pkey words +2 ghi +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode)) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +4 +5 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote2`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode)) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +6 +7 +connection child2_3; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select match(`words`)against('+ghi' in boolean mode),`pkey`,`words` from `auto_test_remote3`.`tbl_a` where match(`words`)against('+ghi' in boolean mode) and (match(`words`)against(_latin1'+ghi' in boolean mode)) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +2 +3 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection child2_3; +DROP DATABASE IF EXISTS auto_test_remote3; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session join_cache_level= @old_join_cache_level; +set session optimizer_switch= @old_optimizer_switch; +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/partition_join_pushdown_for_single_partition.result b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result new file mode 100644 index 00000000..3eed8df2 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result @@ -0,0 +1,130 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_3; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_DROP_TABLES2 +CHILD2_1_CREATE_TABLES +CHILD2_1_CREATE_TABLES2 +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_DROP_TABLES +CHILD2_2_DROP_TABLES2 +CHILD2_2_CREATE_TABLES +CHILD2_2_CREATE_TABLES2 +TRUNCATE TABLE mysql.general_log; +connection child2_3; +CHILD2_3_DROP_TABLES +CHILD2_3_DROP_TABLES2 +CHILD2_3_CREATE_TABLES +CHILD2_3_CREATE_TABLES2 +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +CREATE TABLE tbl_a ( +value int NOT NULL, +PRIMARY KEY(value) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +value2 int NOT NULL, +PRIMARY KEY(value2) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +insert into tbl_a values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +insert into tbl_b values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +connection master_1; +SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = b.value2 AND a.value = 5; +sum(a.value) count(b.value2) +5 1 +SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = 5 and b.value2 = 5; +sum(a.value) count(b.value2) +5 1 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +1 +2 +3 +4 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 +select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 +select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5 +select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +5 +6 +7 +8 +9 +connection child2_3; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT value FROM tbl_a ORDER BY value; +value +10 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection child2_3; +DROP DATABASE IF EXISTS auto_test_remote3; +SET GLOBAL log_output = @old_log_output; +connection master_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/partition_mrr.result b/storage/spider/mysql-test/spider/r/partition_mrr.result new file mode 100644 index 00000000..c1b7d6e6 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/partition_mrr.result @@ -0,0 +1,267 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_join_cache_level= @@join_cache_level; +set session join_cache_level= 5; +set @old_optimizer_switch= @@optimizer_switch; +set session optimizer_switch= 'mrr=on'; + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote2; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +connection child2_3; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS auto_test_remote3; +CREATE DATABASE auto_test_remote3; +USE auto_test_remote3; + +create table and insert +connection child2_1; +CHILD2_1_DROP_TABLES +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_DROP_TABLES +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_3; +CHILD2_3_DROP_TABLES +CHILD2_3_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +4 +5 +10 +11 +16 +17 +22 +23 +28 +29 +0 +1 +6 +7 +12 +13 +18 +19 +24 +25 +2 +3 +8 +9 +14 +15 +20 +21 +26 +27 +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey+0 = b.pkey+0 ORDER BY a.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +select a.id,b.`pkey` from auto_test_remote.tmp_spider_bka_xxxx a,`auto_test_remote`.`tbl_b` b where a.c0 <=> b.`pkey` +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +select `pkey` from `auto_test_remote`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote`.`tbl_b` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey ; +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +4 +5 +10 +11 +16 +17 +22 +23 +28 +29 +pkey +2 +3 +8 +9 +14 +15 +20 +21 +26 +27 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_a` order by `pkey` +select a.id,b.`pkey` from auto_test_remote2.tmp_spider_bka_xxxx a,`auto_test_remote2`.`tbl_b` b where a.c0 <=> b.`pkey` +select `pkey` from `auto_test_remote2`.`tbl_a` order by `pkey` +select `pkey` from `auto_test_remote2`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote2`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote2`.`tbl_b` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey ; +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +6 +7 +12 +13 +18 +19 +24 +25 +pkey +4 +5 +10 +11 +16 +17 +22 +23 +28 +29 +connection child2_3; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote3`.`tbl_a` order by `pkey` +select a.id,b.`pkey` from auto_test_remote3.tmp_spider_bka_xxxx a,`auto_test_remote3`.`tbl_b` b where a.c0 <=> b.`pkey` +select `pkey` from `auto_test_remote3`.`tbl_a` order by `pkey` +select `pkey` from `auto_test_remote3`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote3`.`tbl_b` order by `pkey` +select `pkey` from `auto_test_remote3`.`tbl_b` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey ; +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +2 +3 +8 +9 +14 +15 +20 +21 +26 +27 +pkey +0 +1 +6 +7 +12 +13 +18 +19 +24 +25 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection child2_3; +DROP DATABASE IF EXISTS auto_test_remote3; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session join_cache_level= @old_join_cache_level; +set session optimizer_switch= @old_optimizer_switch; +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/pushdown_not_like.result b/storage/spider/mysql-test/spider/r/pushdown_not_like.result new file mode 100644 index 00000000..5c802c90 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/pushdown_not_like.result @@ -0,0 +1,63 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table select test +connection master_1; +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', '2018-11-01 10:21:39'), +(2, 'b', '2015-06-30 23:59:59'), +(3, 'c', '2013-11-01 01:01:01'); + +spider not like bug fix test +connection master_1; +select * from ta_l where b not like 'a%'; +a b c +2 b 2015-06-30 23:59:59 +3 c 2013-11-01 01:01:01 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select%'; +argument +select t0.`a` `a`,t0.`b` `b`,t0.`c` `c` from `auto_test_remote`.`ta_r` t0 where (t0.`b` not like 'a%') +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select%' + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +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/quick_mode_0.result b/storage/spider/mysql-test/spider/r/quick_mode_0.result new file mode 100644 index 00000000..04c8231b --- /dev/null +++ b/storage/spider/mysql-test/spider/r/quick_mode_0.result @@ -0,0 +1,508 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 0; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 6; + +select test 2 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 0; + +select test 3 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +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/quick_mode_1.result b/storage/spider/mysql-test/spider/r/quick_mode_1.result new file mode 100644 index 00000000..820d791d --- /dev/null +++ b/storage/spider/mysql-test/spider/r/quick_mode_1.result @@ -0,0 +1,508 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 1; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 6; + +select test 2 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 0; + +select test 3 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +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/quick_mode_2.result b/storage/spider/mysql-test/spider/r/quick_mode_2.result new file mode 100644 index 00000000..94c5c4cf --- /dev/null +++ b/storage/spider/mysql-test/spider/r/quick_mode_2.result @@ -0,0 +1,508 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 2; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 6; + +select test 2 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 0; + +select test 3 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +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/quick_mode_3.result b/storage/spider/mysql-test/spider/r/quick_mode_3.result new file mode 100644 index 00000000..88a8914c --- /dev/null +++ b/storage/spider/mysql-test/spider/r/quick_mode_3.result @@ -0,0 +1,508 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +set @old_spider_quick_mode= @@spider_quick_mode; +set session spider_quick_mode= 3; +set @old_spider_quick_page_size= @@spider_quick_page_size; +set session spider_quick_page_size= 3; +set @old_spider_quick_page_byte= @@spider_quick_page_byte; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2 +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 6; + +select test 2 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection master_1; +set session spider_quick_page_byte= 0; + +select test 3 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote`.`tbl_a` order by `pkey` +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 0 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 1 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 2 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 3 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 4 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 5 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 6 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 7 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 8 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 9 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 10 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 11 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 12 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 13 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 14 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 15 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 16 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 17 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 18 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 19 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 20 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 21 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 22 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 23 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 24 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 25 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 26 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 27 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 28 +select `pkey` from `auto_test_remote2`.`tbl_b` where `pkey` = 29 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey FROM tbl_b ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_quick_mode= @old_spider_quick_mode; +set session spider_quick_page_size= @old_spider_quick_page_size; +set session spider_quick_page_byte= @old_spider_quick_page_byte; +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/show_system_tables.result b/storage/spider/mysql-test/spider/r/show_system_tables.result new file mode 100644 index 00000000..67411862 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/show_system_tables.result @@ -0,0 +1,37 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +Show system tables on the Spider node +connection master_1; +SELECT table_name, engine FROM information_schema.tables +WHERE table_schema = 'mysql' AND table_name like '%spider_%'; +table_name engine +spider_link_failed_log Aria +spider_link_mon_servers Aria +spider_table_crd Aria +spider_table_position_for_recovery Aria +spider_table_sts Aria +spider_tables Aria +spider_xa Aria +spider_xa_failed_log Aria +spider_xa_member Aria + +deinit +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/slave_trx_isolation.result b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result new file mode 100644 index 00000000..28aaf74f --- /dev/null +++ b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result @@ -0,0 +1,105 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +for slave1_1 +connection slave1_1; +set @old_spider_slave_trx_isolation= @@spider_slave_trx_isolation; +set global spider_slave_trx_isolation= 1; + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +SET SESSION sql_log_bin= 1; +connection slave1_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +connection master_1; +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +connection slave1_1; +connection master_1; +SET SESSION sql_log_bin= 0; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%set %'; +argument +set session time_zone = '+00:00';set @`spider_lc_./auto_test_remote/tbl_a` = '-xxxxxxxxxxxx-xxxxx-./auto_test_local/tbl_a-' +SET NAMES utf8mb3 +set session transaction isolation level read committed;set session autocommit = 1;set session wait_timeout = 604800;set session sql_mode = 'strict_trans_tables,error_for_division_by_zero,no_auto_create_user,no_engine_substitution';start transaction +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%set %' +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +connection slave1_1; +SELECT pkey FROM tbl_a ORDER BY pkey; +pkey +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection slave1_1; +set global spider_slave_trx_isolation= @old_spider_slave_trx_isolation; +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/spider3_fixes.result b/storage/spider/mysql-test/spider/r/spider3_fixes.result new file mode 100644 index 00000000..7a80e102 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider3_fixes.result @@ -0,0 +1,232 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +3.1 +auto_increment +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +connection master_1; +# +# MDEV-28225 Disallow user to create Spider temporary table +# +connection master_1; +CREATE TEMPORARY TABLE t1 ( +a INT +) ENGINE=Spider; +ERROR HY000: Table storage engine 'SPIDER' does not support the create option 'TEMPORARY' + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/spider3_fixes_part.result b/storage/spider/mysql-test/spider/r/spider3_fixes_part.result new file mode 100644 index 00000000..937f222f --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider3_fixes_part.result @@ -0,0 +1,222 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +auto_increment with partition +connection master_1; +connection slave1_1; +connection master_1; +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() +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1554 +2331 +3108 +5000 +10000 +connection master_1; + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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 00000000..273f37a8 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider_fixes.result @@ -0,0 +1,623 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table and insert +connection master_1; +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 "<" +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; +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 "<=" +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; +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 +connection master_1; +UPDATE ta_l SET c = '2000-02-02 00:00:00' WHERE a > 1; +connection master_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; +connection master_1; +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; +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +5 c 2001-12-31 23:59:59 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +2 b 2000-01-01 00:00:00 +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'; +a b c +2 b 2000-01-01 00:00:00 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +4 d 2003-11-30 05:01:03 +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'; +a b c +2 b 2000-01-01 00:00:00 + +2.16 +auto_increment insert with trigger +connection master_1; +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;; +connection master_1; +INSERT INTO ta_l_auto_inc (a, b, c) VALUES +(NULL, 's', '2008-12-31 20:59:59'); +connection master_1; +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 +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); +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 + +2.23 +index merge +connection master_1; +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; +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; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.24 +index scan update without PK +connection master_1; +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 +1 2 3 +2 3 4 +3 4 5 +4 5 6 +5 6 7 +6 7 8 +7 8 9 +8 9 10 +9 10 11 +10 11 12 +11 12 13 +12 13 14 +13 14 15 +14 15 16 +15 16 17 +16 17 18 +INSERT INTO ta_l_int (a, b, c) VALUES (0, 2, 3); +INSERT INTO ta_l_int (a, b, c) VALUES (18, 2, 3); +connection master_1; +UPDATE ta_l_int SET c = 4 WHERE b = 2; +connection master_1; +SELECT a, b, c FROM ta_l_int ORDER BY a; +a b c +1 2 4 +2 3 4 +3 4 5 +4 5 6 +5 6 7 +6 7 8 +7 8 9 +8 9 10 +9 10 11 +10 11 12 +11 12 13 +12 13 14 +13 14 15 +14 15 16 +15 16 17 +16 17 18 +17 2 4 +18 2 4 + +2.25 +direct order limit +connection master_1; +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 +3 4 5 +SHOW STATUS LIKE 'Spider_direct_order_limit'; +Variable_name Value +Spider_direct_order_limit 3 + +2.26 +lock tables +connection master_1; +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 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +CREATE TABLE t2 ( +id int(11) NOT NULL, +PRIMARY KEY (id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_LOCK2 +Warnings: +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +Warning 138 The high availability feature of Spider has been deprecated and will be removed in a future release +LOCK TABLES t1 READ, t2 READ; +UNLOCK TABLES; + +auto_increment +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 +connection master_1; + +read only +connection master_1; +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 +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +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 = 777; +ERROR HY000: Table 'auto_test_local.t1' is read only +DELETE FROM t1 WHERE id = 777; +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 +connection master_1; +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 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 +connection master_1; +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; +connection master_1; +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 +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; +connection master_1; +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +connection master_1; +SET @@global.expire_logs_days=11; +connect master_purge, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK; +SET @@global.binlog_checksum=NONE; +SET @@global.binlog_checksum=$binlog_checksum; +SET @@global.expire_logs_days=$expire_logs_days; +disconnect master_purge; +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_part.result b/storage/spider/mysql-test/spider/r/spider_fixes_part.result new file mode 100644 index 00000000..571af94c --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider_fixes_part.result @@ -0,0 +1,351 @@ +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 +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection master_1; +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'); + +2.17 +partition with sort +connection master_1; +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 +connection master_1; +DROP TABLE IF EXISTS ta_l2; +connection master_1; +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 with partition +connection master_1; +DROP TABLE IF EXISTS ta_l_int; +connection master_1; +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; +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; +a b c +3 4 5 +4 5 6 +5 6 7 + +2.26 +auto_increment with partition +connection master_1; +connection slave1_1; +connection master_1; +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 +connection slave1_1; +SELECT id FROM t1 ORDER BY id; +id +777 +1000 +1554 +2331 +3108 +3885 +4662 +5000 +5439 +6216 +10000 +connection master_1; + +Test ORDER BY with LIMIT and OFFSET +connection master_1; +CREATE TABLE ta_ob ( +a VARCHAR(50) NOT NULL, +b VARCHAR(50) NULL DEFAULT NULL, +c VARCHAR(100) NULL DEFAULT NULL, +d DATETIME(0) NULL DEFAULT NULL, +e INT(11) NOT NULL, +f INT(10) NULL DEFAULT NULL, +PRIMARY KEY (a, e) +) ENGINE=Spider COMMENT='database "auto_test_remote", table "ta_ob"' + PARTITION BY LIST COLUMNS (e) PARTITIONS 1 +(PARTITION pt1 values in (510411) COMMENT = 'srv "s_2_1"') +INSERT INTO ta_ob VALUES ('0B95CD65DF994BC9A09A6AABE53A2733', +'6CFED89FF6A84C7AA55C3C432663D094', +'51041110620304', '2018-08-02 13:41:13', +510411, 1); +INSERT INTO ta_ob VALUES ('15E8D55EF099443BAEE639E60A4650BD', +'879DC2A0B6AC46D9A62E8EA47E2970F2', +'51041110620301', NULL, +510411, 0); +INSERT INTO ta_ob VALUES ('51ECF2C0CD3C48D99C91792E99D3C1A0', +'017B8A460DBC444682B791305EF75356', +'51041110620308', '2018-08-02 13:48:29', +510411, 0); +INSERT INTO ta_ob VALUES ('093B37A93A534DF883787AF5F6799674', +'996C7F14989D480589A553717D735E3E', +'51041110620302', '2018-08-02 13:48:30', +510411, 0); +INSERT INTO ta_ob VALUES ('53F5266FB069499AB6234755CACA2583', +'017B8A460DBC444682B791305EF75356', +'51041110620308', '2018-08-02 13:48:28', +510411, 0); +INSERT INTO ta_ob VALUES ('56E59BC4BDC143868D4A219C2D07A24B', +'821E71E6ABB4404EBAA349BB681089F8', +'51041110620310', '2018-08-02 13:48:27', +510411, 0); +INSERT INTO ta_ob VALUES ('56B68DA68D6D4A04A08B453D09AD7B70', +'821E71E6ABB4404EBAA349BB681089F8', +'51041110620310', '2018-08-02 13:48:28', +510411, 0); +SELECT * FROM ta_ob WHERE c LIKE "%510411106%" AND e = 510411 AND f != 1 ORDER BY d,c LIMIT 5 OFFSET 1; +a b c d e f +56E59BC4BDC143868D4A219C2D07A24B 821E71E6ABB4404EBAA349BB681089F8 51041110620310 2018-08-02 13:48:27 510411 0 +53F5266FB069499AB6234755CACA2583 017B8A460DBC444682B791305EF75356 51041110620308 2018-08-02 13:48:28 510411 0 +56B68DA68D6D4A04A08B453D09AD7B70 821E71E6ABB4404EBAA349BB681089F8 51041110620310 2018-08-02 13:48:28 510411 0 +51ECF2C0CD3C48D99C91792E99D3C1A0 017B8A460DBC444682B791305EF75356 51041110620308 2018-08-02 13:48:29 510411 0 +093B37A93A534DF883787AF5F6799674 996C7F14989D480589A553717D735E3E 51041110620302 2018-08-02 13:48:30 510411 0 +# +# MDEV-25985 Spider handle ">=" as ">" in some cases +# +connection child2_1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a int, +b int, +c int, +PRIMARY KEY (a), +KEY (b,c) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 1); +connection master_1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 ( +a int, +b int, +c int, +PRIMARY KEY (a), +KEY (b,c) +) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "t1"' + PARTITION BY LIST COLUMNS(`a`) ( +PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' + ); +connection master_1; +SELECT * FROM t1 WHERE c > 0 AND b >= 1 AND b <= 2; +a b c +1 1 1 +2 2 1 +SELECT * FROM t1 WHERE c < 3 AND b <= 2; +a b c +1 1 1 +2 2 1 + +Crash from b4a2baffa82e5c07b96a1c752228560dcac1359b (MDEV-11084) +Fixed with 4968049799193394d442f26b4e3a8d95b185be72 +Spider crashed if the first partition was not used first +connection master_1; +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; +Query a Spider table only using the second partition +SELECT a,b,c FROM ta_l2 PARTITION (pt2); +a b c +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 +Query a Spider table only using the first partition +SELECT a,b,c FROM ta_l2 PARTITION (pt1); +a b c +1 a 2008-08-01 10:21:39 +2 b 2000-01-01 00:00:00 +3 e 2007-06-04 20:03:11 +Query a Spider table by all paritions, then the second partition +SELECT min(a), max(a), min(b), max(b) FROM ta_l2; +min(a) max(a) min(b) max(b) +1 5 a e +SELECT a,b,c FROM ta_l2 PARTITION (pt2); +a b c +4 d 2003-11-30 05:01:03 +5 c 2001-12-31 23:59:59 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection slave1_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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_wrapper_protocols.result b/storage/spider/mysql-test/spider/r/spider_wrapper_protocols.result new file mode 100644 index 00000000..f1a7b620 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/spider_wrapper_protocols.result @@ -0,0 +1,22 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +SELECT * FROM information_schema.spider_wrapper_protocols; +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/timestamp.result b/storage/spider/mysql-test/spider/r/timestamp.result new file mode 100644 index 00000000..4618d920 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/timestamp.result @@ -0,0 +1,431 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +Initialize Time Zone +connection master_1; +SET GLOBAL time_zone='MET'; +SET time_zone='MET'; +connection child2_1; +SET GLOBAL time_zone='MET'; +SET time_zone='MET'; + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS ts_test_local; +CREATE DATABASE ts_test_local; +USE ts_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +DROP DATABASE IF EXISTS ts_test_remote; +CREATE DATABASE ts_test_remote; +USE ts_test_remote; + +test select 1 +connection master_1; +SELECT 1; +1 +1 +connection child2_1; +SELECT 1; +1 +1 + +create table +connection child2_1; +CHILD2_1_DROP_TABLE +CHILD2_1_DROP_TABLE_F +CHILD2_1_CREATE_TABLE +CHILD2_1_CREATE_TABLE_F +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP TABLE IF EXISTS tbl_a; +CREATE TABLE tbl_a ( +col_a INT UNSIGNED NOT NULL AUTO_INCREMENT, +col_dt DATETIME, +col_ts TIMESTAMP NOT NULL +DEFAULT current_timestamp() ON UPDATE current_timestamp(), +PRIMARY KEY(col_a), +UNIQUE INDEX i_ts (col_ts) +) MASTER_1_ENGINE MASTER_1_AUTO_INCREMENT_2_1 MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_f ( +col_d DATE, +col_t TIME +) ENGINE=Spider COMMENT='database "ts_test_remote", table "tbl_f", srv "s_2_1"' +SHOW CREATE TABLE tbl_a; +Table Create Table +tbl_a CREATE TABLE `tbl_a` ( + `col_a` int(10) unsigned NOT NULL AUTO_INCREMENT, + `col_dt` datetime DEFAULT NULL, + `col_ts` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`col_a`), + UNIQUE KEY `i_ts` (`col_ts`) +) ENGINE=SPIDER AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='database "ts_test_remote", table "tbl_a", srv "s_2_1"' +SHOW CREATE TABLE tbl_f; +Table Create Table +tbl_f CREATE TABLE `tbl_f` ( + `col_d` date DEFAULT NULL, + `col_t` time DEFAULT NULL +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='database "ts_test_remote", table "tbl_f", srv "s_2_1"' + +Set a different time zone that has DST +SET time_zone='+01:00'; + +Insert Rows +connection master_1; +Min value +SET @@timestamp=1; +INSERT INTO tbl_a VALUES (1, now(), now()); +SET @@timestamp=0; +Ambiguous DST values for MET time zone that result in the +same UTC timestamp +INSERT INTO tbl_a VALUES (2, '2018-03-25 02:00:00', '2018-03-25 02:00:00'); +INSERT INTO tbl_a VALUES (3, '2018-03-25 02:30:00', '2018-03-25 02:30:00'); +Ambiguous DST values for MET time zone in the 2:00 am to 3:00 am hour +that occur twice when transitioning from DST to standard time +SET @@timestamp=1540686600; +INSERT INTO tbl_a VALUES (4, now(), now()); +SET @@timestamp=1540690200; +INSERT INTO tbl_a VALUES (5, now(), now()); +Max value +SET @@timestamp=2147483647; +INSERT INTO tbl_a VALUES (6, now(), now()); +SET @@timestamp=0; + +SELECTs +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 + +DELETEs +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +DELETE FROM tbl_a WHERE col_ts='1970-01-01 01:00:01'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SET @@timestamp=1; +INSERT INTO tbl_a VALUES (1, now(), now()); +SET @@timestamp=0; +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 + +UPDATEs +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +UPDATE tbl_a SET col_ts=col_dt; +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select `col_a`,`col_dt`,`col_ts` from `ts_test_remote`.`tbl_a` for update +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 + +Lookups +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > '2018-01-01'; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts < '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE '2018-10-28 02:30:00' > col_ts; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts BETWEEN '2018-10-28 01:30:00' AND '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts >= '2018-10-28 01:30:00' AND col_ts <= '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 180325020000; +col_a col_dt col_ts unix_timestamp(col_ts) +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 19700101010001; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > _latin1'2017-12-31 23:00:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < _latin1'2018-10-28 01:30:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (_latin1'2018-10-28 01:30:00' > t0.`col_ts`) +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between _latin1'2018-10-28 00:30:00' and _latin1'2018-10-28 01:30:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= _latin1'2018-10-28 00:30:00') and (t0.`col_ts` <= _latin1'2018-10-28 01:30:00')) +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2018-03-25 01:00:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '1970-01-01 00:00:01') +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 + +Drop the index on the timestamp column +connection child2_1; +DROP INDEX i_ts ON tbl_a; +SHOW CREATE TABLE tbl_a; +Table Create Table +tbl_a CREATE TABLE `tbl_a` ( + `col_a` int(10) unsigned NOT NULL AUTO_INCREMENT, + `col_dt` datetime DEFAULT NULL, + `col_ts` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`col_a`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci +TRUNCATE TABLE mysql.general_log; +connection master_1; +DROP INDEX i_ts ON tbl_a; +SHOW CREATE TABLE tbl_a; +Table Create Table +tbl_a CREATE TABLE `tbl_a` ( + `col_a` int(10) unsigned NOT NULL AUTO_INCREMENT, + `col_dt` datetime DEFAULT NULL, + `col_ts` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`col_a`) +) ENGINE=SPIDER AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='database "ts_test_remote", table "tbl_a", srv "s_2_1"' + +Retry lookups on unindexed timestamp column +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > '2018-01-01'; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts < '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE '2018-10-28 02:30:00' > col_ts; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts BETWEEN '2018-10-28 01:30:00' AND '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts >= '2018-10-28 01:30:00' AND col_ts <= '2018-10-28 02:30:00'; +col_a col_dt col_ts unix_timestamp(col_ts) +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 180325020000; +col_a col_dt col_ts unix_timestamp(col_ts) +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 19700101010001; +col_a col_dt col_ts unix_timestamp(col_ts) +2 2018-03-25 02:00:00 2018-03-25 02:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 02:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 01:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > _latin1'2017-12-31 23:00:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` < _latin1'2018-10-28 01:30:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (_latin1'2018-10-28 01:30:00' > t0.`col_ts`) +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` between _latin1'2018-10-28 00:30:00' and _latin1'2018-10-28 01:30:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where ((t0.`col_ts` >= _latin1'2018-10-28 00:30:00') and (t0.`col_ts` <= _latin1'2018-10-28 01:30:00')) +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '2018-03-25 01:00:00') +select t0.`col_a` `col_a`,t0.`col_dt` `col_dt`,t0.`col_ts` `col_ts`,(unix_timestamp(t0.`col_ts`)) `unix_timestamp(col_ts)` from `ts_test_remote`.`tbl_a` t0 where (t0.`col_ts` > '1970-01-01 00:00:01') +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +col_a col_dt col_ts unix_timestamp(col_ts) +1 1970-01-01 01:00:01 1970-01-01 01:00:01 1 +2 2018-03-25 02:00:00 2018-03-25 03:00:00 1521939600 +3 2018-03-25 02:30:00 2018-03-25 03:30:00 1521941400 +4 2018-10-28 01:30:00 2018-10-28 02:30:00 1540686600 +5 2018-10-28 02:30:00 2018-10-28 02:30:00 1540690200 +6 2038-01-19 04:14:07 2038-01-19 04:14:07 2147483647 + +Test the TIMESTAMP function +connection master_1; +INSERT INTO tbl_f VALUES ('2018-06-24', '01:23:45'), +('2018-06-24', '01:23:45'), +('2018-08-01', '12:34:56'); +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT * FROM tbl_f; +col_d col_t +2018-06-24 01:23:45 +2018-06-24 01:23:45 +2018-08-01 12:34:56 +SELECT TIMESTAMP(col_d, col_t) FROM tbl_f; +TIMESTAMP(col_d, col_t) +2018-06-24 01:23:45 +2018-06-24 01:23:45 +2018-08-01 12:34:56 +SELECT TIMESTAMP('2018-06-25', col_t) FROM tbl_f; +TIMESTAMP('2018-06-25', col_t) +2018-06-25 01:23:45 +2018-06-25 01:23:45 +2018-06-25 12:34:56 +SELECT TIMESTAMP(col_d, '10:43:21') FROM tbl_f; +TIMESTAMP(col_d, '10:43:21') +2018-06-24 10:43:21 +2018-06-24 10:43:21 +2018-08-01 10:43:21 +SELECT TIMESTAMP('2018-06-25', '10:43:21') FROM tbl_f; +TIMESTAMP('2018-06-25', '10:43:21') +2018-06-25 10:43:21 +2018-06-25 10:43:21 +2018-06-25 10:43:21 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select t0.`col_d` `col_d`,t0.`col_t` `col_t` from `ts_test_remote`.`tbl_f` t0 +select (timestamp(t0.`col_d` , t0.`col_t`)) `TIMESTAMP(col_d, col_t)` from `ts_test_remote`.`tbl_f` t0 +select (timestamp('2018-06-25' , t0.`col_t`)) `TIMESTAMP('2018-06-25', col_t)` from `ts_test_remote`.`tbl_f` t0 +select (timestamp(t0.`col_d` , '10:43:21')) `TIMESTAMP(col_d, '10:43:21')` from `ts_test_remote`.`tbl_f` t0 +select 1 from `ts_test_remote`.`tbl_f` t0 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT col_d, col_t FROM tbl_f; +col_d col_t +2018-06-24 01:23:45 +2018-06-24 01:23:45 +2018-08-01 12:34:56 + +Restore Time Zone settings +connection master_1; +SET GLOBAL time_zone=DEFAULT; +SET time_zone=DEFAULT; +connection child2_1; +SET GLOBAL time_zone=DEFAULT; +SET time_zone=DEFAULT; + +deinit +connection master_1; +DROP DATABASE IF EXISTS ts_test_local; +connection child2_1; +DROP DATABASE IF EXISTS ts_test_remote; +SET GLOBAL log_output = @old_log_output; +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/udf_pushdown.result b/storage/spider/mysql-test/spider/r/udf_pushdown.result new file mode 100644 index 00000000..4ca73416 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/udf_pushdown.result @@ -0,0 +1,218 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +# +# MDEV-26545 Spider does not correctly handle UDF and stored function in where conds +# + +##### enable general_log ##### +connection child2_1; +SET @general_log_backup = @@global.general_log; +SET @log_output_backup = @@global.log_output; +SET @@global.general_log = 1; +SET @@global.log_output = "TABLE"; +TRUNCATE TABLE mysql.general_log; + +##### create databases ##### +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +##### create tables ##### +connection child2_1; +CHILD_CREATE_TABLE +connection master_1; +MASTER_CREATE_TABLE +CREATE TABLE ta_l ( +id INT NOT NULL, +a INT, +PRIMARY KEY(id) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO ta_l VALUES +(1, 11), +(2, 22), +(3, 33), +(4, 44), +(5, 55); + +##### create functions ##### +connection master_1; +CREATE FUNCTION `plusone`( param INT ) RETURNS INT +BEGIN +RETURN param + 1; +END // +connection child2_1; +CREATE FUNCTION `plusone`( param INT ) RETURNS INT +BEGIN +RETURN param + 1; +END // + +########## spider_use_pushdown_udf=0 ########## +connection master_1; +SET @@spider_use_pushdown_udf = 0; + +##### test SELECTs ##### +connection master_1; +SELECT * FROM ta_l WHERE id = plusone(1); +id a +2 22 +SELECT * FROM ta_l WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +id a +3 33 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE "%select%" AND argument NOT LIKE "%argument%"; +argument +select `id`,`a` from `auto_test_remote`.`ta_r` +select `id`,`a` from `auto_test_remote`.`ta_r` + +##### test UPDATEs ##### +connection master_1; +UPDATE ta_l SET a = plusone(221) WHERE id = plusone(1); +SELECT * FROM ta_l; +id a +1 11 +2 222 +3 33 +4 44 +5 55 +UPDATE ta_l SET a = plusone(332) WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +SELECT * FROM ta_l; +id a +1 11 +2 222 +3 333 +4 44 +5 55 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE "%update%" AND argument NOT LIKE "%argument%"; +argument +select `id`,`a` from `auto_test_remote`.`ta_r` for update +update `auto_test_remote`.`ta_r` set `a` = 222 where `id` = 2 limit 1 +select `id`,`a` from `auto_test_remote`.`ta_r` for update +update `auto_test_remote`.`ta_r` set `a` = 333 where `id` = 3 and `a` = 33 limit 1 + +##### test DELETEs ##### +connection master_1; +DELETE FROM ta_l WHERE id = plusone(1); +SELECT * FROM ta_l; +id a +1 11 +3 333 +4 44 +5 55 +DELETE FROM ta_l WHERE id IN (plusone(1), plusone(2), plusone(3)) AND a = plusone(43); +SELECT * FROM ta_l; +id a +1 11 +3 333 +5 55 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE (argument LIKE "%delete%" OR argument LIKE "%update%") AND argument NOT LIKE "%argument%"; +argument +select `id` from `auto_test_remote`.`ta_r` for update +delete from `auto_test_remote`.`ta_r` where `id` = 2 limit 1 +select `id`,`a` from `auto_test_remote`.`ta_r` for update +delete from `auto_test_remote`.`ta_r` where `id` = 4 and `a` = 44 limit 1 + +##### reset records ##### +connection master_1; +TRUNCATE TABLE ta_l; +INSERT INTO ta_l VALUES +(1, 11), +(2, 22), +(3, 33), +(4, 44), +(5, 55); + +########## spider_use_pushdown_udf=1 ########## +connection master_1; +SET @@spider_use_pushdown_udf = 1; + +##### test SELECTs ##### +connection master_1; +SELECT * FROM ta_l WHERE id = plusone(1); +id a +2 22 +SELECT * FROM ta_l WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +id a +3 33 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE "%select%" AND argument NOT LIKE "%argument%"; +argument +select t0.`id` `id`,t0.`a` `a` from `auto_test_remote`.`ta_r` t0 where (t0.`id` = (`plusone`(1))) +select t0.`id` `id`,t0.`a` `a` from `auto_test_remote`.`ta_r` t0 where ((t0.`id` in( (`plusone`(1)) , (`plusone`(2)))) and (t0.`a` = (`plusone`(32)))) + +##### test UPDATEs ##### +connection master_1; +UPDATE ta_l SET a = plusone(221) WHERE id = plusone(1); +SELECT * FROM ta_l; +id a +1 11 +2 222 +3 33 +4 44 +5 55 +UPDATE ta_l SET a = plusone(332) WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +SELECT * FROM ta_l; +id a +1 11 +2 222 +3 333 +4 44 +5 55 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE "%update%" AND argument NOT LIKE "%argument%"; +argument +update `auto_test_remote`.`ta_r` set `a` = (`plusone`(221)) where (`id` = (`plusone`(1))) +update `auto_test_remote`.`ta_r` set `a` = (`plusone`(332)) where ((`id` in( (`plusone`(1)) , (`plusone`(2)))) and (`a` = (`plusone`(32)))) + +##### test DELETEs ##### +connection master_1; +DELETE FROM ta_l WHERE id = plusone(1); +SELECT * FROM ta_l; +id a +1 11 +3 333 +4 44 +5 55 +DELETE FROM ta_l WHERE id IN (plusone(1), plusone(2), plusone(3)) AND a = plusone(43); +SELECT * FROM ta_l; +id a +1 11 +3 333 +5 55 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE (argument LIKE "%delete%" OR argument LIKE "%update%") AND argument NOT LIKE "%argument%"; +argument +delete from `auto_test_remote`.`ta_r` where (`id` = (`plusone`(1))) +delete from `auto_test_remote`.`ta_r` where ((`id` in( (`plusone`(1)) , (`plusone`(2)) , (`plusone`(3)))) and (`a` = (`plusone`(43)))) + +deinit +connection master_1; +DROP FUNCTION `plusone`; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +SET @@global.general_log = @general_log_backup; +SET @@global.log_output = @log_output_backup; +DROP FUNCTION `plusone`; +DROP DATABASE IF EXISTS auto_test_remote; +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/variable_deprecation.result b/storage/spider/mysql-test/spider/r/variable_deprecation.result new file mode 100644 index 00000000..cea36ff2 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/variable_deprecation.result @@ -0,0 +1,221 @@ +# +# MDEV-27228 Deprecate Spider plugin variables that result in excessive tweak +# +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +# MDEV-28297 Deprecate spider_internal_offset +SET spider_internal_offset = 1; +Warnings: +Warning 1287 '@@spider_internal_offset' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_internal_offset"; +Variable_name Value +spider_internal_offset 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='ios "1"'; +Warnings: +Warning 1287 The table parameter 'ios' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='internal_offset "1"'; +Warnings: +Warning 1287 The table parameter 'internal_offset' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-27981 Deprecate spider_internal_limit +SET spider_internal_limit = 1; +Warnings: +Warning 1287 '@@spider_internal_limit' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_internal_limit"; +Variable_name Value +spider_internal_limit 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='ilm "1"'; +Warnings: +Warning 1287 The table parameter 'ilm' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='internal_limit "1"'; +Warnings: +Warning 1287 The table parameter 'internal_limit' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28244 Deprecate spider_xa_register_mode +SET spider_xa_register_mode = 0; +Warnings: +Warning 1287 '@@spider_xa_register_mode' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_xa_register_mode"; +Variable_name Value +spider_xa_register_mode 0 +# MDEV-28007 Deprecate Spider plugin variables regarding statistics persistence +SET GLOBAL spider_store_last_sts = 0; +Warnings: +Warning 1287 '@@spider_store_last_sts' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_store_last_sts"; +Variable_name Value +spider_store_last_sts 0 +SET GLOBAL spider_store_last_crd = 0; +Warnings: +Warning 1287 '@@spider_store_last_crd' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_store_last_crd"; +Variable_name Value +spider_store_last_crd 0 +SET GLOBAL spider_load_sts_at_startup = 0; +Warnings: +Warning 1287 '@@spider_load_sts_at_startup' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_load_sts_at_startup"; +Variable_name Value +spider_load_sts_at_startup 0 +SET GLOBAL spider_load_crd_at_startup = 0; +Warnings: +Warning 1287 '@@spider_load_crd_at_startup' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_load_crd_at_startup"; +Variable_name Value +spider_load_crd_at_startup 0 +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28008 Deprecate spider_crd_mode and spider_sts_mode +SET spider_crd_mode = 1; +Warnings: +Warning 1287 '@@spider_crd_mode' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_crd_mode"; +Variable_name Value +spider_crd_mode 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='cmd "3"'; +Warnings: +Warning 1287 The table parameter 'cmd' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='crd_mode "3"'; +Warnings: +Warning 1287 The table parameter 'crd_mode' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +SET spider_sts_mode = 1; +Warnings: +Warning 1287 '@@spider_sts_mode' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_sts_mode"; +Variable_name Value +spider_sts_mode 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='smd "3"'; +Warnings: +Warning 1287 The table parameter 'smd' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='sts_mode "3"'; +Warnings: +Warning 1287 The table parameter 'sts_mode' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28010 Deprecate spider_crd_type and spider_crd_weight +SET spider_crd_type = 1; +Warnings: +Warning 1287 '@@spider_crd_type' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_crd_type"; +Variable_name Value +spider_crd_type 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='ctp "1"'; +Warnings: +Warning 1287 The table parameter 'ctp' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='crd_type "1"'; +Warnings: +Warning 1287 The table parameter 'crd_type' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +SET spider_crd_weight = 1; +Warnings: +Warning 1287 '@@spider_crd_weight' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_crd_weight"; +Variable_name Value +spider_crd_weight 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='cwg "1"'; +Warnings: +Warning 1287 The table parameter 'cwg' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='crd_weight "1"'; +Warnings: +Warning 1287 The table parameter 'crd_weight' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28560 Deprecate spider_buffer_size +SET spider_buffer_size = 1; +Warnings: +Warning 1287 '@@spider_buffer_size' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_buffer_size"; +Variable_name Value +spider_buffer_size 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='bfz "1"'; +Warnings: +Warning 1287 The table parameter 'bfz' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='buffer_size "1"'; +Warnings: +Warning 1287 The table parameter 'buffer_size' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-27926 Deprecate spider_init_sql_alloc_size +SET spider_init_sql_alloc_size = 1; +Warnings: +Warning 1287 '@@spider_init_sql_alloc_size' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_init_sql_alloc_size"; +Variable_name Value +spider_init_sql_alloc_size 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='isa "1"'; +Warnings: +Warning 1287 The table parameter 'isa' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='init_sql_alloc_size "1"'; +Warnings: +Warning 1287 The table parameter 'init_sql_alloc_size' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28829 Deprecate spider_semi_table_lock and spider_semi_table_lock_connection +SET spider_semi_table_lock = 1; +Warnings: +Warning 1287 '@@spider_semi_table_lock' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_semi_table_lock"; +Variable_name Value +spider_semi_table_lock 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='stl "1"'; +Warnings: +Warning 1287 The table parameter 'stl' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='semi_table_lock "1"'; +Warnings: +Warning 1287 The table parameter 'semi_table_lock' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +SET spider_semi_table_lock_connection = 0; +Warnings: +Warning 1287 '@@spider_semi_table_lock_connection' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_semi_table_lock_connection"; +Variable_name Value +spider_semi_table_lock_connection 0 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='stc "0"'; +Warnings: +Warning 1287 The table parameter 'stc' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='semi_table_lock_connection "0"'; +Warnings: +Warning 1287 The table parameter 'semi_table_lock_connection' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +# MDEV-28795 Deprecate spider_bka_table_name_type +SET spider_bka_table_name_type = 1; +Warnings: +Warning 1287 '@@spider_bka_table_name_type' is deprecated and will be removed in a future release +SHOW VARIABLES LIKE "spider_bka_table_name_type"; +Variable_name Value +spider_bka_table_name_type 1 +CREATE TABLE tbl_a (a INT) ENGINE=Spider COMMENT='btt "1"'; +Warnings: +Warning 1287 The table parameter 'btt' is deprecated and will be removed in a future release +CREATE TABLE tbl_b (a INT) ENGINE=Spider COMMENT='bka_table_name_type "1"'; +Warnings: +Warning 1287 The table parameter 'bka_table_name_type' is deprecated and will be removed in a future release +DROP TABLE tbl_a; +DROP TABLE tbl_b; +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 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 00000000..cc0e4105 --- /dev/null +++ b/storage/spider/mysql-test/spider/r/vp_fixes.result @@ -0,0 +1,93 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +child3_1 +child3_2 +child3_3 + +drop and create databases +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +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; + +test select 1 +connection master_1; +SELECT 1; +1 +1 + +create table and insert +connection master_1; +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 +connection master_1; +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 +connection master_1; +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); +create un-correspond primary key table +connection master_1; +DROP TABLE IF EXISTS ta_l_int; +connection master_1; +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 +connection master_1; +INSERT INTO ta_l_int (a, b, c) VALUES (2, NULL, 3); + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +connection child2_2; +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/regression/e1121/include/direct_join_by_pkey_key_deinit.inc b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_deinit.inc new file mode 100644 index 00000000..ad30aac5 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_deinit.inc @@ -0,0 +1,12 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_1_2= $MASTER_1_COMMENT_2_1_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_init.inc b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_init.inc new file mode 100644 index 00000000..b3d16987 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_key_init.inc @@ -0,0 +1,36 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_1_2_BACKUP= $MASTER_1_COMMENT_2_1_2 +let $MASTER_1_COMMENT_2_1_2= + COMMENT='table "tbl_b", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a $STR_SEMICOLON + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + KEY idx1 (akey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT akey, val FROM tbl_a ORDER BY akey $STR_SEMICOLON + SELECT bkey, akey FROM tbl_b ORDER BY bkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' $STR_SEMICOLON + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%'; diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_deinit.inc b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_deinit.inc new file mode 100644 index 00000000..ad30aac5 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_deinit.inc @@ -0,0 +1,12 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $MASTER_1_COMMENT_2_1_2= $MASTER_1_COMMENT_2_1_2_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_init.inc b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_init.inc new file mode 100644 index 00000000..000b42e2 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/direct_join_by_pkey_pkey_init.inc @@ -0,0 +1,36 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $MASTER_1_COMMENT_2_1_2_BACKUP= $MASTER_1_COMMENT_2_1_2 +let $MASTER_1_COMMENT_2_1_2= + COMMENT='table "tbl_b", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a $STR_SEMICOLON + DROP TABLE IF EXISTS tbl_b; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (akey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON + CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT akey, val FROM tbl_a ORDER BY akey $STR_SEMICOLON + SELECT bkey, akey FROM tbl_b ORDER BY bkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' $STR_SEMICOLON + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%'; diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_deinit.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_deinit.inc new file mode 100644 index 00000000..f1899d15 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_deinit.inc @@ -0,0 +1,3 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--source load_data_deinit.inc diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_init.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_init.inc new file mode 100644 index 00000000..24f0dc98 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi0_init.inc @@ -0,0 +1,4 @@ +--source load_data_init.inc +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_deinit.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_deinit.inc new file mode 100644 index 00000000..f1899d15 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_deinit.inc @@ -0,0 +1,3 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--source load_data_deinit.inc diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_init.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_init.inc new file mode 100644 index 00000000..50ef8d47 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_ddi1_init.inc @@ -0,0 +1,4 @@ +--source load_data_init.inc +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_deinit.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_deinit.inc new file mode 100644 index 00000000..f8405973 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_deinit.inc @@ -0,0 +1,11 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e1121/include/load_data_init.inc b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_init.inc new file mode 100644 index 00000000..96216e01 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/include/load_data_init.inc @@ -0,0 +1,25 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a", srv "s_2_1"'; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, val FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; diff --git a/storage/spider/mysql-test/spider/regression/e1121/my.cnf b/storage/spider/mysql-test/spider/regression/e1121/my.cnf new file mode 100644 index 00000000..47558d85 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/my.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include my_1_1.cnf +!include my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/regression/e1121/my_1_1.cnf b/storage/spider/mysql-test/spider/regression/e1121/my_1_1.cnf new file mode 100644 index 00000000..5f17295d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/my_1_1.cnf @@ -0,0 +1,44 @@ +[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 + +[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 + +STR_SEMICOLON= ; + +#The followings are set 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 diff --git a/storage/spider/mysql-test/spider/regression/e1121/my_2_1.cnf b/storage/spider/mysql-test/spider/regression/e1121/my_2_1.cnf new file mode 100644 index 00000000..24161645 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/my_2_1.cnf @@ -0,0 +1,56 @@ +[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 + +[ENV] +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_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_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 + +#The followings are set in include/init_xxx.inc files +# 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 diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_key.result b/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_key.result new file mode 100644 index 00000000..a5553304 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_key.result @@ -0,0 +1,94 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18995 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +akey int NOT NULL, +val int NOT NULL, +KEY idx1 (akey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +bkey int NOT NULL, +akey int NOT NULL, +PRIMARY KEY (bkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2 +INSERT INTO tbl_a (akey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_b (bkey,akey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,4),(6,3),(7,2),(8,1),(9,0); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.val, a.akey FROM tbl_a a, tbl_b b WHERE a.akey = b.akey AND b.bkey = 5; +val akey +4 4 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%'; +argument +select t0.`val` `val`,t0.`akey` `akey` from `auto_test_remote`.`tbl_a` t0 where (t0.`akey` = '4') +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%' +argument +select `bkey`,`akey` from `auto_test_remote`.`tbl_b` where `bkey` = 5 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%' +SELECT akey, val FROM tbl_a ORDER BY akey ; +SELECT bkey, akey FROM tbl_b ORDER BY bkey; +akey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 +bkey akey +0 0 +1 1 +2 2 +3 3 +4 4 +5 4 +6 3 +7 2 +8 1 +9 0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_pkey.result b/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_pkey.result new file mode 100644 index 00000000..4ea23c88 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/direct_join_by_pkey_pkey.result @@ -0,0 +1,94 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18995 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +akey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (akey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +CREATE TABLE tbl_b ( +bkey int NOT NULL, +akey int NOT NULL, +PRIMARY KEY (bkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2 +INSERT INTO tbl_a (akey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_b (bkey,akey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,4),(6,3),(7,2),(8,1),(9,0); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT a.val, a.akey FROM tbl_a a, tbl_b b WHERE a.akey = b.akey AND b.bkey = 5; +val akey +4 4 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%'; +argument +select `akey`,`val` from `auto_test_remote`.`tbl_a` where `akey` = 4 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%' +argument +select `bkey`,`akey` from `auto_test_remote`.`tbl_b` where `bkey` = 5 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' ; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_b`%' +SELECT akey, val FROM tbl_a ORDER BY akey ; +SELECT bkey, akey FROM tbl_b ORDER BY bkey; +akey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 +bkey akey +0 0 +1 1 +2 2 +3 3 +4 4 +5 4 +6 3 +7 2 +8 1 +9 0 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi0.result new file mode 100644 index 00000000..9d30f61a --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi0.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi1.result new file mode 100644 index 00000000..594016e1 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi0.result new file mode 100644 index 00000000..e1ba5470 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi0.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +Warnings: +Warning 1062 Duplicate entry '0' for key 'PRIMARY' +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' +Warning 1062 Duplicate entry '6' for key 'PRIMARY' +Warning 1062 Duplicate entry '7' for key 'PRIMARY' +Warning 1062 Duplicate entry '8' for key 'PRIMARY' +Warning 1062 Duplicate entry '9' for key 'PRIMARY' +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(8,8) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi1.result new file mode 100644 index 00000000..af2bcc3d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_ignore_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi0.result new file mode 100644 index 00000000..057d8386 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi0.result @@ -0,0 +1,84 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(8,8) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi1.result new file mode 100644 index 00000000..ba643fa6 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi0.result new file mode 100644 index 00000000..50248d5a --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi0.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +Warnings: +Warning 1062 Duplicate entry '0' for key 'PRIMARY' +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' +Warning 1062 Duplicate entry '6' for key 'PRIMARY' +Warning 1062 Duplicate entry '7' for key 'PRIMARY' +Warning 1062 Duplicate entry '8' for key 'PRIMARY' +Warning 1062 Duplicate entry '9' for key 'PRIMARY' +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(8,8) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi1.result new file mode 100644 index 00000000..bb4c6da7 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_ignore_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +1 2 +2 3 +3 4 +4 5 +5 6 +6 7 +7 8 +8 9 +9 10 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi0.result new file mode 100644 index 00000000..324cdac2 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi0.result @@ -0,0 +1,104 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 0 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 0,`val` = 0 where `pkey` = 0 and `val` = 1 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 1,`val` = 1 where `pkey` = 1 and `val` = 2 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(2,2) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 2 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 2,`val` = 2 where `pkey` = 2 and `val` = 3 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 3 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 3,`val` = 3 where `pkey` = 3 and `val` = 4 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(4,4) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 4 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 4,`val` = 4 where `pkey` = 4 and `val` = 5 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 5 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 5,`val` = 5 where `pkey` = 5 and `val` = 6 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(6,6) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 6 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 6,`val` = 6 where `pkey` = 6 and `val` = 7 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 7 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 7,`val` = 7 where `pkey` = 7 and `val` = 8 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(8,8) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 8 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 8,`val` = 8 where `pkey` = 8 and `val` = 9 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 9 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 9,`val` = 9 where `pkey` = 9 and `val` = 10 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi1.result new file mode 100644 index 00000000..e73b078d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_local_replace_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi0.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi0.result new file mode 100644 index 00000000..dd91e95d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi0.result @@ -0,0 +1,104 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 0 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 0,`val` = 0 where `pkey` = 0 and `val` = 1 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 1,`val` = 1 where `pkey` = 1 and `val` = 2 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(2,2) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 2 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 2,`val` = 2 where `pkey` = 2 and `val` = 3 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 3 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 3,`val` = 3 where `pkey` = 3 and `val` = 4 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(4,4) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 4 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 4,`val` = 4 where `pkey` = 4 and `val` = 5 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 5 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 5,`val` = 5 where `pkey` = 5 and `val` = 6 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(6,6) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 6 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 6,`val` = 6 where `pkey` = 6 and `val` = 7 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 7 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 7,`val` = 7 where `pkey` = 7 and `val` = 8 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(8,8) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 8 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 8,`val` = 8 where `pkey` = 8 and `val` = 9 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 9 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 9,`val` = 9 where `pkey` = 9 and `val` = 10 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi1.result b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi1.result new file mode 100644 index 00000000..974287ab --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/r/load_data_replace_ddi1.result @@ -0,0 +1,75 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/suite.opt b/storage/spider/mysql-test/spider/regression/e1121/suite.opt new file mode 100644 index 00000000..672a3b37 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/suite.opt @@ -0,0 +1 @@ +--loose-innodb --loose-skip-performance-schema diff --git a/storage/spider/mysql-test/spider/regression/e1121/suite.pm b/storage/spider/mysql-test/spider/regression/e1121/suite.pm new file mode 100644 index 00000000..171fa6c4 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/suite.pm @@ -0,0 +1,11 @@ +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; + +sub is_default { 1 } + +bless { }; + diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_key.test b/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_key.test new file mode 100644 index 00000000..ec4639ed --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_key.test @@ -0,0 +1,88 @@ +--source ../include/direct_join_by_pkey_key_init.inc +--echo +--echo this test is for MDEV-18995 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +--disable_ps_protocol +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + KEY idx1 (akey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + KEY idx1 (akey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2; +eval CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1_2; +--enable_query_log +INSERT INTO tbl_a (akey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_b (bkey,akey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,4),(6,3),(7,2),(8,1),(9,0); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_ps2_protocol +SELECT a.val, a.akey FROM tbl_a a, tbl_b b WHERE a.akey = b.akey AND b.bkey = 5; +--enable_ps2_protocol + +--connection child2_1 +--disable_ps_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; +--enable_ps_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/direct_join_by_pkey_key_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_pkey.test b/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_pkey.test new file mode 100644 index 00000000..52d9b52d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/direct_join_by_pkey_pkey.test @@ -0,0 +1,88 @@ +--source ../include/direct_join_by_pkey_pkey_init.inc +--echo +--echo this test is for MDEV-18995 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +--disable_ps_protocol +eval $CHILD2_1_CREATE_TABLES; +--enable_ps_protocol +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (akey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + akey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (akey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2; +eval CREATE TABLE tbl_b ( + bkey int NOT NULL, + akey int NOT NULL, + PRIMARY KEY (bkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1_2; +--enable_query_log +INSERT INTO tbl_a (akey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_b (bkey,akey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,4),(6,3),(7,2),(8,1),(9,0); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_ps2_protocol +SELECT a.val, a.akey FROM tbl_a a, tbl_b b WHERE a.akey = b.akey AND b.bkey = 5; +--enable_ps2_protocol + +--connection child2_1 +--disable_ps_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; +--enable_ps_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/direct_join_by_pkey_pkey_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data.inc b/storage/spider/mysql-test/spider/regression/e1121/t/load_data.inc new file mode 100644 index 00000000..080ba735 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data.inc @@ -0,0 +1,82 @@ +--echo +--echo this test is for MDEV-18987 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +--disable_query_log +--echo SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +--disable_ps2_protocol +eval SELECT pkey,val INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +--enable_ps2_protocol +--enable_query_log +eval $COMMAND_BEFORE_LOAD_DATA; + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +--echo LOAD DATA $OPTION_LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' $OPTION_WORD INTO TABLE tbl_a; +--disable_ps2_protocol +eval LOAD DATA $OPTION_LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' $OPTION_WORD INTO TABLE tbl_a; +--enable_ps2_protocol +--enable_query_log +--remove_file $MYSQLTEST_VARDIR/tmp/spider_outfile.tsv + +--connection child2_1 +--disable_ps2_protocol +eval $CHILD2_1_SELECT_ARGUMENT1; +--enable_ps2_protocol +eval $CHILD2_1_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi0.test new file mode 100644 index 00000000..d43a944d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= +--let OPTION_WORD= +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi1.test new file mode 100644 index 00000000..a73d1ef0 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= +--let OPTION_WORD= +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi0.test new file mode 100644 index 00000000..6fee83e7 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= IGNORE +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi1.test new file mode 100644 index 00000000..1c882791 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_ignore_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= IGNORE +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi0.test new file mode 100644 index 00000000..dadd0224 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi1.test new file mode 100644 index 00000000..95b06505 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi0.test new file mode 100644 index 00000000..2243f892 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= IGNORE +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi1.test new file mode 100644 index 00000000..2ab7307e --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_ignore_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= IGNORE +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi0.test new file mode 100644 index 00000000..1821a9ef --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= REPLACE +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi1.test new file mode 100644 index 00000000..3d53feca --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_local_replace_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= REPLACE +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi0.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi0.test new file mode 100644 index 00000000..4bc402a4 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= REPLACE +--source load_data.inc +--source ../include/load_data_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi1.test b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi1.test new file mode 100644 index 00000000..9dafd24a --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e1121/t/load_data_replace_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= REPLACE +--source load_data.inc +--source ../include/load_data_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc new file mode 100644 index 00000000..2248eef3 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc new file mode 100644 index 00000000..48961d0d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc @@ -0,0 +1,54 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_ok_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(skey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_deinit.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_deinit.inc new file mode 100644 index 00000000..c4191734 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_deinit.inc @@ -0,0 +1,3 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--source load_data_part_deinit.inc diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_init.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_init.inc new file mode 100644 index 00000000..8e69f52c --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi0_init.inc @@ -0,0 +1,4 @@ +--source load_data_part_init.inc +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_deinit.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_deinit.inc new file mode 100644 index 00000000..c4191734 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_deinit.inc @@ -0,0 +1,3 @@ +--connection master_1 +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +--source load_data_part_deinit.inc diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_init.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_init.inc new file mode 100644 index 00000000..b9194ccd --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_ddi1_init.inc @@ -0,0 +1,4 @@ +--source load_data_part_init.inc +--connection master_1 +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_deinit.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_deinit.inc new file mode 100644 index 00000000..2248eef3 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_init.inc b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_init.inc new file mode 100644 index 00000000..23126f77 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/load_data_part_init.inc @@ -0,0 +1,52 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source load_data_part_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, val FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, val FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; diff --git a/storage/spider/mysql-test/spider/regression/e112122/my.cnf b/storage/spider/mysql-test/spider/regression/e112122/my.cnf new file mode 100644 index 00000000..6610e4cf --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include my_1_1.cnf +!include my_2_1.cnf +!include my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf new file mode 100644 index 00000000..5f17295d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf @@ -0,0 +1,44 @@ +[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 + +[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 + +STR_SEMICOLON= ; + +#The followings are set 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 diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf new file mode 100644 index 00000000..24161645 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf @@ -0,0 +1,56 @@ +[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 + +[ENV] +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_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_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 + +#The followings are set in include/init_xxx.inc files +# 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 diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf new file mode 100644 index 00000000..2d3c2a89 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf @@ -0,0 +1,38 @@ +[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 + +[ENV] +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_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_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 + +#The followings are set in include/init_xxx.inc files +# CHILD2_2_DROP_TABLES +# CHILD2_2_CREATE_TABLES +# CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result b/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result new file mode 100644 index 00000000..695ddadc --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result @@ -0,0 +1,126 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18988 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +skey int NOT NULL, +KEY idx1 (pkey), +KEY idx2 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,skey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_a (pkey,skey) VALUES (10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19); +INSERT INTO tbl_a (pkey,skey) VALUES (20,5),(21,6),(22,7),(23,8),(24,9),(25,10),(26,11),(27,12),(28,13),(29,14); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 0 +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; +skey cnt +14 2 +13 2 +12 2 +11 2 +10 2 +SHOW STATUS LIKE 'Spider_direct_aggregate'; +Variable_name Value +Spider_direct_aggregate 20 +set spider_direct_aggregate=@old_spider_direct_aggregate; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote`.`tbl_a` group by `skey` order by count(0) desc,`skey` desc limit 5 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +1 1 +3 3 +5 5 +7 7 +9 9 +11 11 +13 13 +15 15 +17 17 +19 19 +20 5 +22 7 +24 9 +26 11 +28 13 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote2`.`tbl_a` group by `skey` order by count(0) desc,`skey` desc limit 5 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +0 0 +2 2 +4 4 +6 6 +8 8 +10 10 +12 12 +14 14 +16 16 +18 18 +21 6 +23 8 +25 10 +27 12 +29 14 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi0.result new file mode 100644 index 00000000..c32e8793 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi0.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi1.result new file mode 100644 index 00000000..dab51a3e --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi0.result new file mode 100644 index 00000000..7d99878b --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi0.result @@ -0,0 +1,114 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +Warnings: +Warning 1062 Duplicate entry '0' for key 'PRIMARY' +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' +Warning 1062 Duplicate entry '6' for key 'PRIMARY' +Warning 1062 Duplicate entry '7' for key 'PRIMARY' +Warning 1062 Duplicate entry '8' for key 'PRIMARY' +Warning 1062 Duplicate entry '9' for key 'PRIMARY' +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 2 +3 4 +5 6 +7 8 +9 10 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +2 3 +4 5 +6 7 +8 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi1.result new file mode 100644 index 00000000..0ae71b49 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_ignore_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 2 +3 4 +5 6 +7 8 +9 10 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +2 3 +4 5 +6 7 +8 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi0.result new file mode 100644 index 00000000..d2362e46 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi0.result @@ -0,0 +1,103 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi1.result new file mode 100644 index 00000000..c57dc96b --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +TRUNCATE tbl_a; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi0.result new file mode 100644 index 00000000..81005ac8 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi0.result @@ -0,0 +1,114 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +Warnings: +Warning 1062 Duplicate entry '0' for key 'PRIMARY' +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' +Warning 1062 Duplicate entry '6' for key 'PRIMARY' +Warning 1062 Duplicate entry '7' for key 'PRIMARY' +Warning 1062 Duplicate entry '8' for key 'PRIMARY' +Warning 1062 Duplicate entry '9' for key 'PRIMARY' +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +insert high_priority into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 2 +3 4 +5 6 +7 8 +9 10 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(2,2) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(4,4) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(6,6) +insert high_priority into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +2 3 +4 5 +6 7 +8 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi1.result new file mode 100644 index 00000000..d7cea9ed --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_ignore_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' IGNORE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 2 +3 4 +5 6 +7 8 +9 10 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert high_priority ignore into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 1 +2 3 +4 5 +6 7 +8 9 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi0.result new file mode 100644 index 00000000..d6cd973f --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi0.result @@ -0,0 +1,123 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 1,`val` = 1 where `pkey` = 1 and `val` = 2 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 3 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 3,`val` = 3 where `pkey` = 3 and `val` = 4 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 5 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 5,`val` = 5 where `pkey` = 5 and `val` = 6 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 7 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 7,`val` = 7 where `pkey` = 7 and `val` = 8 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 9 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 9,`val` = 9 where `pkey` = 9 and `val` = 10 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 0 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 0,`val` = 0 where `pkey` = 0 and `val` = 1 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(2,2) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 2,`val` = 2 where `pkey` = 2 and `val` = 3 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(4,4) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 4 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 4,`val` = 4 where `pkey` = 4 and `val` = 5 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(6,6) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 6 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 6,`val` = 6 where `pkey` = 6 and `val` = 7 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(8,8) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 8 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 8,`val` = 8 where `pkey` = 8 and `val` = 9 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi1.result new file mode 100644 index 00000000..ac233777 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_local_replace_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi0.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi0.result new file mode 100644 index 00000000..cd4bf6d7 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi0.result @@ -0,0 +1,123 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 0; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 1,`val` = 1 where `pkey` = 1 and `val` = 2 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(3,3) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 3 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 3,`val` = 3 where `pkey` = 3 and `val` = 4 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(5,5) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 5 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 5,`val` = 5 where `pkey` = 5 and `val` = 6 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(7,7) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 7 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 7,`val` = 7 where `pkey` = 7 and `val` = 8 limit 1 +insert into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(9,9) +select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 9 for update +update ignore `auto_test_remote`.`tbl_a` set `pkey` = 9,`val` = 9 where `pkey` = 9 and `val` = 10 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 0 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 0,`val` = 0 where `pkey` = 0 and `val` = 1 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(2,2) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 2,`val` = 2 where `pkey` = 2 and `val` = 3 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(4,4) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 4 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 4,`val` = 4 where `pkey` = 4 and `val` = 5 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(6,6) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 6 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 6,`val` = 6 where `pkey` = 6 and `val` = 7 limit 1 +insert into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(8,8) +select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 8 for update +update ignore `auto_test_remote2`.`tbl_a` set `pkey` = 8,`val` = 8 where `pkey` = 8 and `val` = 9 limit 1 +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi1.result b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi1.result new file mode 100644 index 00000000..98c63603 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/load_data_part_replace_ddi1.result @@ -0,0 +1,95 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection master_1; +set @old_spider_direct_dup_insert= @@spider_direct_dup_insert; +set session spider_direct_dup_insert= 1; + +this test is for MDEV-18987 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +val int NOT NULL, +PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +UPDATE tbl_a SET val = val + 1; + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' REPLACE INTO TABLE tbl_a; +connection child2_1; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote`.`tbl_a`(`pkey`,`val`)values(1,1),(3,3),(5,5),(7,7),(9,9) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +1 1 +3 3 +5 5 +7 7 +9 9 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%'; +argument +replace into `auto_test_remote2`.`tbl_a`(`pkey`,`val`)values(0,0),(2,2),(4,4),(6,6),(8,8) +SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%`tbl_a`%' +SELECT pkey, val FROM tbl_a ORDER BY pkey; +pkey val +0 0 +2 2 +4 4 +6 6 +8 8 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +connection master_1; +set session spider_direct_dup_insert= @old_spider_direct_dup_insert; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/suite.opt b/storage/spider/mysql-test/spider/regression/e112122/suite.opt new file mode 100644 index 00000000..672a3b37 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/suite.opt @@ -0,0 +1 @@ +--loose-innodb --loose-skip-performance-schema diff --git a/storage/spider/mysql-test/spider/regression/e112122/suite.pm b/storage/spider/mysql-test/spider/regression/e112122/suite.pm new file mode 100644 index 00000000..171fa6c4 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/suite.pm @@ -0,0 +1,11 @@ +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; + +sub is_default { 1 } + +bless { }; + diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test b/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test new file mode 100644 index 00000000..e4f3f215 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test @@ -0,0 +1,104 @@ +--source ../include/group_by_order_by_limit_ok_init.inc +--echo +--echo this test is for MDEV-18988 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey,skey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO tbl_a (pkey,skey) VALUES (10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19); +INSERT INTO tbl_a (pkey,skey) VALUES (20,5),(21,6),(22,7),(23,8),(24,9),(25,10),(26,11),(27,12),(28,13),(29,14); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--disable_ps2_protocol +--connection master_1 +set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; +set spider_direct_aggregate=1; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; +SHOW STATUS LIKE 'Spider_direct_aggregate'; +set spider_direct_aggregate=@old_spider_direct_aggregate; + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; +eval $CHILD2_2_SELECT_TABLES; +--enable_ps2_protocol + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/group_by_order_by_limit_ok_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part.inc b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part.inc new file mode 100644 index 00000000..fd31047a --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part.inc @@ -0,0 +1,106 @@ +--echo +--echo this test is for MDEV-18987 +--echo +--echo drop and create databases + +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + val int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey,val) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +--disable_query_log +--echo SELECT pkey,val INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +--disable_ps_protocol +eval SELECT pkey,val INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' FROM tbl_a ORDER BY pkey; +--enable_ps2_protocol +--enable_query_log +eval $COMMAND_BEFORE_LOAD_DATA; + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +--echo LOAD DATA $OPTION_LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' $OPTION_WORD INTO TABLE tbl_a; +--disable_ps2_protocol +eval LOAD DATA $OPTION_LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/spider_outfile.tsv' $OPTION_WORD INTO TABLE tbl_a; +--enable_ps2_protocol +--enable_query_log +--remove_file $MYSQLTEST_VARDIR/tmp/spider_outfile.tsv + +--disable_ps2_protocol +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; +eval $CHILD2_2_SELECT_TABLES; +--enable_ps2_protocol + +--echo +--echo deinit +--disable_warnings + +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi0.test new file mode 100644 index 00000000..b7852909 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= +--let OPTION_WORD= +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi1.test new file mode 100644 index 00000000..a2540077 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= +--let OPTION_WORD= +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi0.test new file mode 100644 index 00000000..a6fb58d6 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= IGNORE +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi1.test new file mode 100644 index 00000000..b9f75894 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_ignore_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= IGNORE +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi0.test new file mode 100644 index 00000000..f44f7ae9 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi1.test new file mode 100644 index 00000000..4c806096 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= TRUNCATE tbl_a +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi0.test new file mode 100644 index 00000000..179bab5b --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= IGNORE +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi1.test new file mode 100644 index 00000000..cd7d8215 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_ignore_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= IGNORE +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi0.test new file mode 100644 index 00000000..5df3f420 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= REPLACE +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi1.test new file mode 100644 index 00000000..bf3c7c93 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_local_replace_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= LOCAL +--let OPTION_WORD= REPLACE +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi0.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi0.test new file mode 100644 index 00000000..910b7e81 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi0.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi0_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= REPLACE +--source load_data_part.inc +--source ../include/load_data_part_ddi0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi1.test b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi1.test new file mode 100644 index 00000000..fc84bf14 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/load_data_part_replace_ddi1.test @@ -0,0 +1,8 @@ +--source ../include/load_data_part_ddi1_init.inc +--let COMMAND_BEFORE_LOAD_DATA= UPDATE tbl_a SET val = val + 1 +--let OPTION_LOCAL= +--let OPTION_WORD= REPLACE +--source load_data_part.inc +--source ../include/load_data_part_ddi1_deinit.inc +--echo +--echo 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 00000000..672a3b37 --- /dev/null +++ b/storage/spider/mysql-test/spider/suite.opt @@ -0,0 +1 @@ +--loose-innodb --loose-skip-performance-schema diff --git a/storage/spider/mysql-test/spider/suite.pm b/storage/spider/mysql-test/spider/suite.pm new file mode 100644 index 00000000..171fa6c4 --- /dev/null +++ b/storage/spider/mysql-test/spider/suite.pm @@ -0,0 +1,11 @@ +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; + +sub is_default { 1 } + +bless { }; + diff --git a/storage/spider/mysql-test/spider/t/auto_increment.test b/storage/spider/mysql-test/spider/t/auto_increment.test new file mode 100644 index 00000000..c5f272f5 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/auto_increment.test @@ -0,0 +1,187 @@ +--source auto_increment_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + col_a INT NOT NULL AUTO_INCREMENT, + col_b VARCHAR(20) DEFAULT 'defg', + col_c INT NOT NULL DEFAULT 100, + PRIMARY KEY(col_a) +) MASTER_1_ENGINE MASTER_1_AUTO_INCREMENT_2_1 MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + col_a INT NOT NULL AUTO_INCREMENT, + col_b VARCHAR(20) DEFAULT 'defg', + col_c INT NOT NULL DEFAULT 100, + PRIMARY KEY(col_a) +) $MASTER_1_ENGINE $MASTER_1_AUTO_INCREMENT_2_1 $MASTER_1_COMMENT_2_1; +--enable_query_log +SHOW CREATE TABLE tbl_a; +INSERT INTO tbl_a () VALUES (); +INSERT INTO tbl_a () VALUES (); +SHOW CREATE TABLE tbl_a; +ALTER TABLE tbl_a MODIFY col_c MEDIUMINT NOT NULL DEFAULT 100; +SHOW CREATE TABLE tbl_a; +RENAME TABLE tbl_a TO tbl_x; +SHOW CREATE TABLE tbl_x; +RENAME TABLE tbl_x TO tbl_a; +SHOW CREATE TABLE tbl_a; +INSERT INTO tbl_a () VALUES (); +INSERT INTO tbl_a () VALUES (); +SHOW CREATE TABLE tbl_a; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT1; +eval $MASTER_1_AUTO_INCREMENT1; +--enable_query_log +SHOW CREATE TABLE tbl_a; +INSERT INTO tbl_a () VALUES (); +INSERT INTO tbl_a () VALUES (); +SHOW CREATE TABLE tbl_a; +--disable_query_log +echo MASTER_1_AUTO_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT2; +--enable_query_log +SHOW CREATE TABLE tbl_a; +INSERT INTO tbl_a () VALUES (); +INSERT INTO tbl_a () VALUES (); +SHOW CREATE TABLE tbl_a; + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT * FROM tbl_a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source auto_increment_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/auto_increment_deinit.inc b/storage/spider/mysql-test/spider/t/auto_increment_deinit.inc new file mode 100644 index 00000000..52be67a1 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/auto_increment_deinit.inc @@ -0,0 +1,13 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $OUTPUT_CHILD_GROUP2= $OUTPUT_CHILD_GROUP2_BACKUP +--let $USE_GENERAL_LOG= $USE_GENERAL_LOG_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/t/auto_increment_init.inc b/storage/spider/mysql-test/spider/t/auto_increment_init.inc new file mode 100644 index 00000000..52245bdd --- /dev/null +++ b/storage/spider/mysql-test/spider/t/auto_increment_init.inc @@ -0,0 +1,38 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='database "auto_test_remote", table "tbl_a", srv "s_2_1", aim "0"'; +let $MASTER_1_AUTO_INCREMENT_2_1= + AUTO_INCREMENT=20; +let $MASTER_1_AUTO_INCREMENT1= + ALTER TABLE tbl_a AUTO_INCREMENT=30; +let $MASTER_1_AUTO_INCREMENT2= + ALTER TABLE tbl_a AUTO_INCREMENT=10; +let $CHILD2_1_CHARSET_AUTO_INCREMENT= + AUTO_INCREMENT=20; +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + col_a INT NOT NULL AUTO_INCREMENT, + col_b VARCHAR(20) DEFAULT 'def', + col_c INT NOT NULL DEFAULT 10, + PRIMARY KEY(col_a) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET_AUTO_INCREMENT $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT col_a, col_b, col_c FROM tbl_a ORDER BY col_a; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +--let $OUTPUT_CHILD_GROUP2_BACKUP= $OUTPUT_CHILD_GROUP2 +--let $OUTPUT_CHILD_GROUP2= 1 +--let $USE_GENERAL_LOG_BACKUP= $USE_GENERAL_LOG +--let $USE_GENERAL_LOG= 1 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 00000000..b5a9b2f4 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/basic_sql.test @@ -0,0 +1,2714 @@ +# This test tests by executing basic SQL +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT found_rows(); +--enable_ps2_protocol + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'replace %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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; + +--connection master_1 +create table t2345678911234567892123456789312345678941234567895123234234(id int) ENGINE=SPIDER + COMMENT='host "192.168.21.1", user "spider", password "password", database "test32738123123123"'; +drop table t2345678911234567892123456789312345678941234567895123234234; + +--echo # +--echo # MDEV-26139 Spider crashes with segmentation fault (signal 11) on CREATE TABLE when COMMENT does not contain embedded double quotes +--echo # +create table mdev_26139 (id int) ENGINE=SPIDER + COMMENT="host '192.168.21.1', user 'spider', password 'password', database 'test'"; +drop table mdev_26139; + +--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/basic_sql_part.test b/storage/spider/mysql-test/spider/t/basic_sql_part.test new file mode 100644 index 00000000..1bb18358 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/basic_sql_part.test @@ -0,0 +1,571 @@ +# This test tests by executing basic SQL +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +--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, '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'); + +--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 command_type != 'Execute' AND argument LIKE '%insert %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'update %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE 'delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 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/checksum_table_with_quick_mode_3.test b/storage/spider/mysql-test/spider/t/checksum_table_with_quick_mode_3.test new file mode 100644 index 00000000..e0fa7a84 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/checksum_table_with_quick_mode_3.test @@ -0,0 +1,128 @@ +--source ../include/checksum_table_with_quick_mode_3_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +FLUSH TABLES; + +--echo +--echo select test 1 +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +CHECKSUM TABLE tbl_a EXTENDED; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --disable_ps2_protocol + eval $CHILD2_1_SELECT_ARGUMENT1; + --enable_ps2_protocol + } + eval $CHILD2_1_SELECT_TABLES; + 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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/checksum_table_with_quick_mode_3_deinit.inc +--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 00000000..15e26031 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child2_1.inc @@ -0,0 +1,2 @@ +--connect (child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK) +--connect (child2_1_2, 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 00000000..75a50821 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/connect_child2_2.inc @@ -0,0 +1,2 @@ +--connect (child2_2, localhost, root, , , $CHILD2_2_MYPORT, $CHILD2_2_MYSOCK) +--connect (child2_2_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 00000000..d356348d --- /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 00000000..03e5c188 --- /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 00000000..d62a7ada --- /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 00000000..fb49f5bf --- /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 00000000..0c129ce5 --- /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 00000000..45a82274 --- /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 00000000..0acff3f6 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_aggregate.test @@ -0,0 +1,191 @@ +--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 + +--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 +--disable_ps2_protocol +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; +--enable_ps2_protocol + +SET spider_direct_aggregate=0; +SELECT COUNT(*) FROM ta_l; +SELECT MAX(a) FROM ta_l; +SELECT MIN(a) FROM ta_l; +SELECT MAX(a) FROM ta_l WHERE a < 5; +SELECT MIN(a) FROM ta_l WHERE a > 1; +eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; +SET spider_direct_aggregate=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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + 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_aggregate_part.test b/storage/spider/mysql-test/spider/t/direct_aggregate_part.test new file mode 100644 index 00000000..8f4c72dc --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_aggregate_part.test @@ -0,0 +1,211 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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 + --disable_ps2_protocol + set @old_spider_direct_aggregate=@@session.spider_direct_aggregate; + set spider_direct_aggregate=1; + + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT COUNT(*) FROM ta_l2; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + SELECT SUM(a) 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; + --enable_ps2_protocol + + SET spider_direct_aggregate=0; + SELECT COUNT(*) FROM ta_l2; + SELECT SUM(a) FROM ta_l2; + SELECT MAX(a) FROM ta_l2; + SELECT MIN(a) FROM ta_l2; + SELECT MAX(a) FROM ta_l2 WHERE a < 5; + SELECT MIN(a) FROM ta_l2 WHERE a > 1; + eval $MASTER_1_CHECK_DIRECT_AGGREGATE_STATUS; + + set spider_direct_aggregate=@old_spider_direct_aggregate; + + 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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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_join.test b/storage/spider/mysql-test/spider/t/direct_join.test new file mode 100644 index 00000000..634b958f --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_join.test @@ -0,0 +1,347 @@ +--source ../include/direct_join_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES5; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + 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 tbl_c ( + 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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c FROM tbl_a a, tbl_b b, tbl_c c WHERE a.a = b.a and a.a = c.a ORDER BY a.b DESC LIMIT 1,2; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo Test JOIN on a constant table. +--echo Spider should NOT push down the join because the tbl_person table +--echo is optimized as a constant 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_CONST_TABLE_JOIN; + echo CHILD2_1_DROP_CONST_TABLE2_JOIN; + echo CHILD2_1_CREATE_CONST_TABLE_JOIN; + echo CHILD2_1_CREATE_CONST_TABLE2_JOIN; + } + --disable_warnings + eval $CHILD2_1_DROP_CONST_TABLE_JOIN; + eval $CHILD2_1_DROP_CONST_TABLE2_JOIN; + --enable_warnings + eval $CHILD2_1_CREATE_CONST_TABLE_JOIN; + eval $CHILD2_1_CREATE_CONST_TABLE2_JOIN; + 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 tbl_person; +DROP TABLE IF EXISTS tbl_ncd_cm_person; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_person ( + id VARCHAR(50) NOT NULL, + hr_status VARCHAR(50) NULL DEFAULT NULL, + region_code VARCHAR(50) NULL DEFAULT NULL, + region INT(11) NOT NULL, + PRIMARY KEY (id, region) USING BTREE + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_CONST_TABLE_JOIN + MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN MASTER_1_PART_CONST_TABLE_JOIN; +eval CREATE TABLE tbl_person ( + id VARCHAR(50) NOT NULL, + hr_status VARCHAR(50) NULL DEFAULT NULL, + region_code VARCHAR(50) NULL DEFAULT NULL, + region INT(11) NOT NULL, + PRIMARY KEY (id, region) USING BTREE + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_CONST_TABLE_JOIN + $MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN $MASTER_1_PART_CONST_TABLE_JOIN; +echo SHOW CREATE TABLE tbl_person; +SHOW CREATE TABLE tbl_person; +echo CREATE TABLE tbl_ncd_cm_person ( + id VARCHAR(50) NOT NULL, + person_id VARCHAR(50) NULL DEFAULT '', + diseaseKind_id VARCHAR(50) NULL DEFAULT NULL, + region INT(11) NOT NULL, + PRIMARY KEY (id, region) USING BTREE + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_CONST_TABLE2_JOIN + MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN MASTER_1_PART_CONST_TABLE2_JOIN; +eval CREATE TABLE tbl_ncd_cm_person ( + id VARCHAR(50) NOT NULL, + person_id VARCHAR(50) NULL DEFAULT '', + diseaseKind_id VARCHAR(50) NULL DEFAULT NULL, + region INT(11) NOT NULL, + PRIMARY KEY (id, region) USING BTREE + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_CONST_TABLE2_JOIN + $MASTER_1_ROW_FORMAT_CONST_TABLE_JOIN $MASTER_1_PART_CONST_TABLE2_JOIN; +echo SHOW CREATE TABLE tbl_ncd_cm_person; +SHOW CREATE TABLE tbl_ncd_cm_person; +--enable_query_log +INSERT INTO tbl_person VALUES ('24FC3F0A5119432BAE13DD65AABAA39C', + '1', '123-51041110620301-321', 510411); +INSERT INTO tbl_person VALUES ('123456789012345678901234567890AB', + '1', '123-51041110620301-321', 510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789', + '24FC3F0A5119432BAE13DD65AABAA39C', + '52A0328740914BCE86ED10A4D2521816', + 510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789AB', + '123456789012345678901234567890AB', + '52A0328740914BCE86ED10A4D2521816', + 510411); +DELETE FROM tbl_ncd_cm_person; +INSERT INTO tbl_ncd_cm_person VALUES ('123456789', + '24FC3F0A5119432BAE13DD65AABAA39C', + '52A0328740914BCE86ED10A4D2521816', + 510411); +INSERT INTO tbl_ncd_cm_person VALUES ('123456789AB', + '123456789012345678901234567890AB', + '52A0328740914BCE86ED10A4D2521816', + 510411); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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_ps2_protocol +SELECT count(0) FROM tbl_person tp INNER JOIN tbl_ncd_cm_person tncp ON tp.id = tncp.person_id WHERE 1 = 1 AND tp.hr_status != "99" AND tp.hr_status != "2" AND tp.region_code LIKE CONCAT(CONCAT('%', '51041110620301', '%')) AND tp.id = '24FC3F0A5119432BAE13DD65AABAA39C' AND tncp.diseaseKind_id = '52A0328740914BCE86ED10A4D2521816' AND tp.region = 510411; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_CONST_TABLE_JOIN; + eval $CHILD2_1_SELECT_CONST_TABLE2_JOIN; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_join_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_join_using.test b/storage/spider/mysql-test/spider/t/direct_join_using.test new file mode 100644 index 00000000..3ecfb292 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_join_using.test @@ -0,0 +1,199 @@ +--source ../include/direct_join_using_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES5; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + 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 tbl_c ( + 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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c FROM tbl_a a join tbl_b b using(a) join tbl_c c using(a) ORDER BY a.b DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_join_using_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_left_join.test b/storage/spider/mysql-test/spider/t/direct_left_join.test new file mode 100644 index 00000000..c9784b04 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_left_join.test @@ -0,0 +1,199 @@ +--source ../include/direct_left_join_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES5; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + 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 tbl_c ( + 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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c FROM tbl_a a left join tbl_b b on a.a = b.a left join tbl_c c on a.a = c.a ORDER BY a.b DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_left_join_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_left_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_left_join_nullable.test new file mode 100644 index 00000000..7c69d73d --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_left_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_left_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_d a left join tbl_c b on a.a = b.a left join tbl_b c on b.c = c.c left join tbl_a d on c.b = d.b ORDER BY a.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_left_join_nullable_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_left_right_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_left_right_join_nullable.test new file mode 100644 index 00000000..dd407482 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_left_right_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_left_right_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_a a left join tbl_b b on a.a = b.a left join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_left_right_join_nullable_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_left_right_left_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_left_right_left_join_nullable.test new file mode 100644 index 00000000..3de0c310 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_left_right_left_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_left_right_left_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_a a left join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c left join tbl_d d on c.b = d.b ORDER BY d.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_left_right_left_join_nullable_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_right_join.test b/storage/spider/mysql-test/spider/t/direct_right_join.test new file mode 100644 index 00000000..d124f75a --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_right_join.test @@ -0,0 +1,199 @@ +--source ../include/direct_right_join_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES5; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES5; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES5; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES5; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + PRIMARY KEY(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + 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 tbl_c ( + 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 tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); +insert into tbl_c values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on a.a = c.a ORDER BY a.b DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_right_join_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_right_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_right_join_nullable.test new file mode 100644 index 00000000..cdb2d4e6 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_right_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_right_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_right_join_nullable_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_right_left_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_right_left_join_nullable.test new file mode 100644 index 00000000..cff40bfd --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_right_left_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_right_left_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a right join tbl_c c on b.c = c.c left join tbl_d d on c.b = d.b ORDER BY d.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_right_left_join_nullable_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/direct_right_left_right_join_nullable.test b/storage/spider/mysql-test/spider/t/direct_right_left_right_join_nullable.test new file mode 100644 index 00000000..cd677a4b --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_right_left_right_join_nullable.test @@ -0,0 +1,214 @@ +--source ../include/direct_right_left_right_join_nullable_init.inc + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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; + 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_DROP_TABLES6; + echo CHILD2_1_DROP_TABLES4; + echo CHILD2_1_DROP_TABLES3; + echo CHILD2_1_CREATE_TABLES; + echo CHILD2_1_CREATE_TABLES6; + echo CHILD2_1_CREATE_TABLES4; + echo CHILD2_1_CREATE_TABLES3; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES; + eval $CHILD2_1_DROP_TABLES6; + eval $CHILD2_1_DROP_TABLES4; + eval $CHILD2_1_DROP_TABLES3; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES; + eval $CHILD2_1_CREATE_TABLES6; + eval $CHILD2_1_CREATE_TABLES4; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT5_2_1; +eval CREATE TABLE tbl_b ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT5_2_1; +echo CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT3_2_1; +eval CREATE TABLE tbl_c ( + a INT AUTO_INCREMENT, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10', + KEY idx0(a), + KEY idx1(b), + KEY idx2(c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT3_2_1; +echo CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT2_2_1; +eval CREATE TABLE tbl_d ( + a INT DEFAULT 10, + b CHAR(1) DEFAULT 'c', + c DATETIME DEFAULT '1999-10-10 10:10:10' +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT2_2_1; +--enable_query_log +insert into tbl_a values (1,'a','2000/01/01'),(2,'b','2000/01/02'); +insert into tbl_b values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'); +insert into tbl_c values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'); +insert into tbl_d values (1,'a','2000/01/01'),(2,'b','2000/01/02'),(3,'c','2000/01/03'),(4,'d','2000/01/04'),(5,'e','2000/01/05'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--connection master_1 +--disable_ps2_protocol +SELECT a.a, c.b, c.c, d.a FROM tbl_a a right join tbl_b b on a.a = b.a left join tbl_c c on b.c = c.c right join tbl_d d on c.b = d.b ORDER BY d.a DESC; + +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/direct_right_left_right_join_nullable_deinit.inc +--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 00000000..94f27e28 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_update.test @@ -0,0 +1,198 @@ +--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 + +--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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_1_SELECT_TABLES; + 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_part.test b/storage/spider/mysql-test/spider/t/direct_update_part.test new file mode 100644 index 00000000..e8f18825 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/direct_update_part.test @@ -0,0 +1,211 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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 command_type != 'Execute' AND argument LIKE '%handler %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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/error_row_number.test b/storage/spider/mysql-test/spider/t/error_row_number.test new file mode 100644 index 00000000..408e7396 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/error_row_number.test @@ -0,0 +1,37 @@ +--echo # +--echo # MDEV-26693 ROW_NUMBER is wrong upon INSERT or UPDATE on Spider table +--echo # + +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +create database auto_test_remote; +use auto_test_remote; +create table ta_r (id int primary key); + +--connection master_1 +evalp create table spd (id int primary key) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + +--error ER_DUP_ENTRY +insert into spd values (1),(2),(1); +get diagnostics condition 1 @n = row_number; +select @n; + +delete from spd; +insert into spd values (1),(2),(3),(13); +--error ER_DUP_ENTRY +update spd set id = id + 10; +get diagnostics condition 1 @n = row_number; +select @n; + +drop table spd; +--connection child2_1 +drop database auto_test_remote; +--connection master_1 +--disable_query_log +--disable_result_log +--source test_deinit.inc 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 00000000..2472e774 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/function.test @@ -0,0 +1,253 @@ +# This test tests for using functions +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 00000000..1924b908 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/ha.test @@ -0,0 +1,882 @@ +# This test tests for ha features +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 + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +eval $MASTER_1_CHANGE_HA_MON; +--enable_ps2_protocol + +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +eval $MASTER_1_CHANGE_HA_MON; +--enable_ps2_protocol + +--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_part.test b/storage/spider/mysql-test/spider/t/ha_part.test new file mode 100644 index 00000000..21b5837c --- /dev/null +++ b/storage/spider/mysql-test/spider/t/ha_part.test @@ -0,0 +1,1024 @@ +# This test tests for ha features +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source ha_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 + } + } +} + +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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 + } + } +} + +--connection master_1 + +CREATE TABLE t (c INT) PARTITION BY LIST COLUMNS (c) (PARTITION p DEFAULT ENGINE=SPIDER); +SHOW FIELDS FROM t; +SHOW FIELDS FROM t; +DROP TABLE t; + +--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 00000000..53d0409d --- /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 00000000..70576ab1 --- /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 00000000..64bef749 --- /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 00000000..e0823e73 --- /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 00000000..b6e69947 --- /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 00000000..316ede9e --- /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 00000000..32de484b --- /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 00000000..7ec2e981 --- /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 00000000..831bf479 --- /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/partition_cond_push.test b/storage/spider/mysql-test/spider/t/partition_cond_push.test new file mode 100644 index 00000000..e47209ef --- /dev/null +++ b/storage/spider/mysql-test/spider/t/partition_cond_push.test @@ -0,0 +1,221 @@ +--source ../include/partition_cond_push_init.inc +if (!$HAVE_PARTITION) +{ + --source ../include/partition_cond_push_deinit.inc + skip Test requires partitioning; +} + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +--enable_warnings + +--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; + } + --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 + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + value int NOT NULL +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + value int NOT NULL +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (value) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (value) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (value) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT value FROM tbl_a WHERE value < 100; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_3_SELECT_ARGUMENT1; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/partition_cond_push_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/partition_fulltext.test b/storage/spider/mysql-test/spider/t/partition_fulltext.test new file mode 100644 index 00000000..1b31fa05 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/partition_fulltext.test @@ -0,0 +1,225 @@ +--source ../include/partition_fulltext_init.inc +if (!$HAVE_PARTITION) +{ + --source ../include/partition_fulltext_deinit.inc + skip Test requires partitioning; +} + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +--enable_warnings + +--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; + } + --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 + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + words text NOT NULL, + PRIMARY KEY (pkey), + FULLTEXT (words) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + words text NOT NULL, + PRIMARY KEY (pkey), + FULLTEXT (words) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +INSERT INTO tbl_a (pkey, words) VALUES (0, 'abc'),(1, 'def'),(2, 'ghi'),(3, 'jkl'),(4, 'mno'),(5, 'pqr'),(6, 'stu'),(7, 'vwx'); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT pkey, words FROM tbl_a WHERE match(words) against('+ghi' in boolean mode); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_3_SELECT_ARGUMENT1; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/partition_fulltext_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/partition_join_pushdown_for_single_partition.test b/storage/spider/mysql-test/spider/t/partition_join_pushdown_for_single_partition.test new file mode 100644 index 00000000..753014d5 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/partition_join_pushdown_for_single_partition.test @@ -0,0 +1,224 @@ +--source ../include/partition_join_pushdown_for_single_partition_init.inc +if (!$HAVE_PARTITION) +{ + --source ../include/partition_join_pushdown_for_single_partition_deinit.inc + skip Test requires partitioning; +} + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +--enable_warnings + +--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_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_DROP_TABLES2; + echo CHILD2_2_CREATE_TABLES; + echo CHILD2_2_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_2_DROP_TABLES; + eval $CHILD2_2_DROP_TABLES2; + --enable_warnings + eval $CHILD2_2_CREATE_TABLES; + eval $CHILD2_2_CREATE_TABLES2; + 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_DROP_TABLES2; + echo CHILD2_3_CREATE_TABLES; + echo CHILD2_3_CREATE_TABLES2; + } + --disable_warnings + eval $CHILD2_3_DROP_TABLES; + eval $CHILD2_3_DROP_TABLES2; + --enable_warnings + eval $CHILD2_3_CREATE_TABLES; + eval $CHILD2_3_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_warnings +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + value int NOT NULL, + PRIMARY KEY(value) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + value int NOT NULL, + PRIMARY KEY(value) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + value2 int NOT NULL, + PRIMARY KEY(value2) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_b ( + value2 int NOT NULL, + PRIMARY KEY(value2) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log + +insert into tbl_a values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +insert into tbl_b values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); + +--connection master_1 +--disable_ps2_protocol +SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = b.value2 AND a.value = 5; +SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = 5 and b.value2 = 5; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_3_SELECT_ARGUMENT1; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/partition_join_pushdown_for_single_partition_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/partition_mrr.test b/storage/spider/mysql-test/spider/t/partition_mrr.test new file mode 100644 index 00000000..840c19d2 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/partition_mrr.test @@ -0,0 +1,239 @@ +--source include/no_protocol.inc +--source ../include/partition_mrr_init.inc +if (!$HAVE_PARTITION) +{ + --source ../include/partition_mrr_deinit.inc + skip Test requires partitioning; +} + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS auto_test_local; +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote; + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote2; + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; + --connection child2_3 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS auto_test_remote3; + CREATE DATABASE auto_test_remote3; + USE auto_test_remote3; +} +--enable_warnings + +--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; + } + --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 + } +} +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS tbl_a; +DROP TABLE IF EXISTS tbl_b; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--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; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey+0 = b.pkey+0 ORDER BY a.pkey; # MDEV-29947 +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { +--replace_regex /tmp_spider_bka_(0x)?[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { +--replace_regex /tmp_spider_bka_(0x)?[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_3 + if ($USE_GENERAL_LOG) + { +--replace_regex /tmp_spider_bka_(0x)?[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_3_SELECT_ARGUMENT1; + } + eval $CHILD2_3_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_3 + DROP DATABASE IF EXISTS auto_test_remote3; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/partition_mrr_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/pushdown_not_like.test b/storage/spider/mysql-test/spider/t/pushdown_not_like.test new file mode 100644 index 00000000..45b88e52 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/pushdown_not_like.test @@ -0,0 +1,139 @@ +--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; +} +--enable_warnings + + +--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) + { + SET @old_log_output = @@global.log_output; + TRUNCATE TABLE mysql.general_log; + set global log_output = 'TABLE'; + } + 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', '2018-11-01 10:21:39'), + (2, 'b', '2015-06-30 23:59:59'), + (3, 'c', '2013-11-01 01:01:01'); + +--echo +--echo spider not like bug fix 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_ps2_protocol +select * from ta_l where b not like 'a%'; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select%'; + } +} +--enable_ps2_protocol + +--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; + SET GLOBAL log_output = @old_log_output; +} + + +--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/quick_mode_0.test b/storage/spider/mysql-test/spider/t/quick_mode_0.test new file mode 100644 index 00000000..070d9e40 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/quick_mode_0.test @@ -0,0 +1,300 @@ +--source ../include/quick_mode_0_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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_CREATE_TABLES; + } + 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 + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_6; + +--echo +--echo select test 2 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_0; + +--echo +--echo select test 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; + } + --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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/quick_mode_0_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/quick_mode_1.test b/storage/spider/mysql-test/spider/t/quick_mode_1.test new file mode 100644 index 00000000..a2c2bf87 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/quick_mode_1.test @@ -0,0 +1,300 @@ +--source ../include/quick_mode_1_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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_CREATE_TABLES; + } + 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 + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_6; + +--echo +--echo select test 2 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_0; + +--echo +--echo select test 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; + } + --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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/quick_mode_1_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/quick_mode_2.test b/storage/spider/mysql-test/spider/t/quick_mode_2.test new file mode 100644 index 00000000..12a48a90 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/quick_mode_2.test @@ -0,0 +1,300 @@ +--source ../include/quick_mode_2_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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_CREATE_TABLES; + } + 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 + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_6; + +--echo +--echo select test 2 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_0; + +--echo +--echo select test 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; + } + --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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/quick_mode_2_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/quick_mode_3.test b/storage/spider/mysql-test/spider/t/quick_mode_3.test new file mode 100644 index 00000000..65851a5b --- /dev/null +++ b/storage/spider/mysql-test/spider/t/quick_mode_3.test @@ -0,0 +1,300 @@ +--source ../include/quick_mode_3_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote2; + USE auto_test_remote2; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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_CREATE_TABLES; + } + 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 + } +} +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_b ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_2; +--enable_query_log +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_a (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_a (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); +INSERT INTO tbl_b (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +INSERT INTO tbl_b (pkey) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19); +INSERT INTO tbl_b (pkey) VALUES (20),(21),(22),(23),(24),(25),(26),(27),(28),(29); + +--echo +--echo select test 1 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_6; + +--echo +--echo select test 2 +if ($USE_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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--connection master_1 +eval $MASTER_1_SET_QUICK_PAGE_BYTE_0; + +--echo +--echo select test 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; + } + --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 +--disable_ps2_protocol +SELECT a.pkey FROM tbl_a a, tbl_b b WHERE a.pkey = b.pkey; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLES; + --connection child2_2 + if ($USE_GENERAL_LOG) + { + --replace_regex /tmp_spider_bka_0x[0-9a-f]*/tmp_spider_bka_xxxx/ + eval $CHILD2_2_SELECT_ARGUMENT1; + } + eval $CHILD2_2_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } + --connection child2_2 + DROP DATABASE IF EXISTS auto_test_remote2; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/quick_mode_3_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/show_system_tables.test b/storage/spider/mysql-test/spider/t/show_system_tables.test new file mode 100644 index 00000000..ae8259b0 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/show_system_tables.test @@ -0,0 +1,26 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings + +--echo +--echo Show system tables on the Spider node +--connection master_1 +--sorted_result +SELECT table_name, engine FROM information_schema.tables + WHERE table_schema = 'mysql' AND table_name like '%spider_%'; + +--echo +--echo deinit +--disable_warnings +--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/slave_test_deinit.inc b/storage/spider/mysql-test/spider/t/slave_test_deinit.inc new file mode 100644 index 00000000..e9d99b7a --- /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 00000000..739d8897 --- /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/slave_trx_isolation.test b/storage/spider/mysql-test/spider/t/slave_trx_isolation.test new file mode 100644 index 00000000..a3a3fad8 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/slave_trx_isolation.test @@ -0,0 +1,151 @@ +--source ../include/slave_trx_isolation_init.inc +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_REPLICATION) +{ + --connection slave1_1 + CREATE DATABASE auto_test_local; + USE auto_test_local; +} +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} +--enable_warnings + +--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_CREATE_TABLES; + } + 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 +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + SET SESSION sql_log_bin= 0; +} +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) MASTER_1_ENGINE2 MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) +) $MASTER_1_ENGINE2 $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +if ($USE_REPLICATION) +{ + SET SESSION sql_log_bin= 1; + --connection slave1_1 + --disable_query_log + echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; + eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + PRIMARY KEY (pkey) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + --enable_query_log + --connection master_1 +} +INSERT INTO tbl_a (pkey) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +if ($USE_REPLICATION) +{ + save_master_pos; + --connection slave1_1 + sync_with_master; + --connection master_1 + SET SESSION sql_log_bin= 0; +} +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + --disable_ps2_protocol + if ($USE_GENERAL_LOG) + { + --replace_regex /-[0-9a-f]{12}-[0-9a-f]+-/-xxxxxxxxxxxx-xxxxx-/ + eval $CHILD2_1_SELECT_ARGUMENT1; + } + --enable_ps2_protocol + eval $CHILD2_1_SELECT_TABLES; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +if ($USE_REPLICATION) +{ + --connection slave1_1 + SELECT pkey FROM tbl_a ORDER BY pkey; +} + +--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; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source ../include/slave_trx_isolation_deinit.inc +--echo +--echo end of test 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 00000000..eb48b0c8 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider3_fixes.test @@ -0,0 +1,304 @@ +# This test tests for Spider 3.0's bug fixes +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 + +--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; +--disable_ps_protocol +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +--enable_ps_protocol +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 command_type != 'Execute' AND 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 # MDEV-28225 Disallow user to create Spider temporary table +--echo # +--connection master_1 +--error ER_ILLEGAL_HA_CREATE_OPTION +CREATE TEMPORARY TABLE t1 ( + a INT +) ENGINE=Spider; + + +--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/spider3_fixes_part.test b/storage/spider/mysql-test/spider/t/spider3_fixes_part.test new file mode 100644 index 00000000..bcd85f42 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider3_fixes_part.test @@ -0,0 +1,347 @@ +# This test tests for Spider 3.0's bug fixes +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 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; + --disable_ps_protocol + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + --enable_ps_protocol + 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 00000000..a5a8f228 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider_fixes.test @@ -0,0 +1,1442 @@ +# This test tests for Spider's bug fixes +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 + +--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 +--disable_ps2_protocol +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a < 5 ORDER BY a DESC LIMIT 3; +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 +--disable_ps2_protocol +SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_l +WHERE a <= 5 ORDER BY a DESC LIMIT 3; +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo 2.23 +--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 command_type != 'Execute' AND 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 (18, 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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; +--disable_ps2_protocol +SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3; +--enable_ps2_protocol +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; +--disable_ps_protocol +eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; +eval $MASTER_1_AUTO_INCREMENT_OFFSET2; +--enable_ps_protocol +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 command_type != 'Execute' AND 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 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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; +} + + +# MDEV-27039 LOCK_global_system_variables attempted to re-acquire +# The test proves no assert anymore. +--connection master_1 +--let $binlog_checksum=`SELECT @@global.binlog_checksum` +--let $expire_logs_days=`SELECT @@global.expire_logs_days` +SET @@global.expire_logs_days=11; + +--connect (master_purge, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK) +SET @@global.binlog_checksum=NONE; +--evalp SET @@global.binlog_checksum=$binlog_checksum +--evalp SET @@global.expire_logs_days=$expire_logs_days +--disconnect master_purge + +--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_part.test b/storage/spider/mysql-test/spider/t/spider_fixes_part.test new file mode 100644 index 00000000..bff2e574 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider_fixes_part.test @@ -0,0 +1,901 @@ +# This test tests for Spider's bug fixes +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 +if (!$HAVE_PARTITION) +{ + --disable_query_log + --disable_result_log + --source slave_test_deinit.inc + --source test_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} + +--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 + +--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 + } +} + +--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'); + +--echo +--echo 2.17 +--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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND 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 command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%insert %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%update %'; + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%delete %'; + } + eval $CHILD2_1_SELECT_TABLES2; + 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo +--echo 2.26 +--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; + --disable_ps_protocol + eval $MASTER_1_AUTO_INCREMENT_INCREMENT2; + eval $MASTER_1_AUTO_INCREMENT_OFFSET2; + --enable_ps_protocol + 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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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 Test ORDER BY with LIMIT and OFFSET +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_TABLES7; + echo CHILD2_1_CREATE_TABLES7; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLES7; + --enable_warnings + eval $CHILD2_1_CREATE_TABLES7; + 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 + --disable_warnings + DROP TABLE IF EXISTS ta_ob; + --enable_warnings + echo CREATE TABLE ta_ob ( + a VARCHAR(50) NOT NULL, + b VARCHAR(50) NULL DEFAULT NULL, + c VARCHAR(100) NULL DEFAULT NULL, + d DATETIME(0) NULL DEFAULT NULL, + e INT(11) NOT NULL, + f INT(10) NULL DEFAULT NULL, + PRIMARY KEY (a, e) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT6_P_1_1; + eval CREATE TABLE ta_ob ( + a VARCHAR(50) NOT NULL, + b VARCHAR(50) NULL DEFAULT NULL, + c VARCHAR(100) NULL DEFAULT NULL, + d DATETIME(0) NULL DEFAULT NULL, + e INT(11) NOT NULL, + f INT(10) NULL DEFAULT NULL, + PRIMARY KEY (a, e) + ) $MASTER_1_ENGINE $MASTER_1_COMMENT6_P_1_1; + --enable_query_log + INSERT INTO ta_ob VALUES ('0B95CD65DF994BC9A09A6AABE53A2733', + '6CFED89FF6A84C7AA55C3C432663D094', + '51041110620304', '2018-08-02 13:41:13', + 510411, 1); + INSERT INTO ta_ob VALUES ('15E8D55EF099443BAEE639E60A4650BD', + '879DC2A0B6AC46D9A62E8EA47E2970F2', + '51041110620301', NULL, + 510411, 0); + INSERT INTO ta_ob VALUES ('51ECF2C0CD3C48D99C91792E99D3C1A0', + '017B8A460DBC444682B791305EF75356', + '51041110620308', '2018-08-02 13:48:29', + 510411, 0); + INSERT INTO ta_ob VALUES ('093B37A93A534DF883787AF5F6799674', + '996C7F14989D480589A553717D735E3E', + '51041110620302', '2018-08-02 13:48:30', + 510411, 0); + INSERT INTO ta_ob VALUES ('53F5266FB069499AB6234755CACA2583', + '017B8A460DBC444682B791305EF75356', + '51041110620308', '2018-08-02 13:48:28', + 510411, 0); + INSERT INTO ta_ob VALUES ('56E59BC4BDC143868D4A219C2D07A24B', + '821E71E6ABB4404EBAA349BB681089F8', + '51041110620310', '2018-08-02 13:48:27', + 510411, 0); + INSERT INTO ta_ob VALUES ('56B68DA68D6D4A04A08B453D09AD7B70', + '821E71E6ABB4404EBAA349BB681089F8', + '51041110620310', '2018-08-02 13:48:28', + 510411, 0); + SELECT * FROM ta_ob WHERE c LIKE "%510411106%" AND e = 510411 AND f != 1 ORDER BY d,c LIMIT 5 OFFSET 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_1_SELECT_TABLES7; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } + } +} + + +--echo # +--echo # MDEV-25985 Spider handle ">=" as ">" in some cases +--echo # + +--connection child2_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +eval CREATE TABLE t1 ( + a int, + b int, + c int, + PRIMARY KEY (a), + KEY (b,c) +) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 1); + +--connection master_1 +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +eval CREATE TABLE t1 ( + a int, + b int, + c int, + PRIMARY KEY (a), + KEY (b,c) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_MDEV_25985; + +--connection master_1 +SELECT * FROM t1 WHERE c > 0 AND b >= 1 AND b <= 2; +SELECT * FROM t1 WHERE c < 3 AND b <= 2; + +--echo +--echo Crash from b4a2baffa82e5c07b96a1c752228560dcac1359b (MDEV-11084) +--echo Fixed with 4968049799193394d442f26b4e3a8d95b185be72 +--echo Spider crashed if the first partition was not used first +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 + --disable_warnings + DROP TABLE IF EXISTS ta_l2; + --enable_warnings + 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; + --echo Query a Spider table only using the second partition + SELECT a,b,c FROM ta_l2 PARTITION (pt2); + --echo Query a Spider table only using the first partition + SELECT a,b,c FROM ta_l2 PARTITION (pt1); + --echo Query a Spider table by all paritions, then the second partition + SELECT min(a), max(a), min(b), max(b) FROM ta_l2; + SELECT a,b,c FROM ta_l2 PARTITION (pt2); + 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 command_type != 'Execute' AND argument LIKE '%select %'; + } + eval $CHILD2_2_SELECT_TABLES; + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; + } + 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_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_wrapper_protocols.test b/storage/spider/mysql-test/spider/t/spider_wrapper_protocols.test new file mode 100644 index 00000000..d0753cf7 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/spider_wrapper_protocols.test @@ -0,0 +1,16 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_query_log + +--connection master_1 +SELECT * FROM information_schema.spider_wrapper_protocols; + +--disable_query_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/test_deinit.inc b/storage/spider/mysql-test/spider/t/test_deinit.inc new file mode 100644 index 00000000..5a82b43c --- /dev/null +++ b/storage/spider/mysql-test/spider/t/test_deinit.inc @@ -0,0 +1,39 @@ +# 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 + --disconnect child2_1_2 + --echo child2_2 + --connection child2_2 + --source ../include/deinit_child2_2.inc + --disconnect child2_2 + --disconnect child2_2_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 00000000..f2cd6c02 --- /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/timestamp.test b/storage/spider/mysql-test/spider/t/timestamp.test new file mode 100644 index 00000000..47d637bb --- /dev/null +++ b/storage/spider/mysql-test/spider/t/timestamp.test @@ -0,0 +1,542 @@ +--source timestamp_init.inc + +--echo +--echo Initialize Time Zone +--connection master_1 +SET GLOBAL time_zone='MET'; +SET time_zone='MET'; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SET GLOBAL time_zone='MET'; + SET time_zone='MET'; +} + +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +DROP DATABASE IF EXISTS ts_test_local; +CREATE DATABASE ts_test_local; +USE ts_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + if ($USE_GENERAL_LOG) + { + SET @old_log_output = @@global.log_output; + SET GLOBAL log_output = 'TABLE,FILE'; + } + DROP DATABASE IF EXISTS ts_test_remote; + CREATE DATABASE ts_test_remote; + USE ts_test_remote; +} +--enable_warnings + +--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; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} + +--echo +--echo create 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_TABLE; + echo CHILD2_1_DROP_TABLE_F; + echo CHILD2_1_CREATE_TABLE; + echo CHILD2_1_CREATE_TABLE_F; + } + --disable_warnings + eval $CHILD2_1_DROP_TABLE; + eval $CHILD2_1_DROP_TABLE_F; + --enable_warnings + eval $CHILD2_1_CREATE_TABLE; + eval $CHILD2_1_CREATE_TABLE_F; + 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 tbl_a; +--enable_warnings +--disable_query_log +echo CREATE TABLE tbl_a ( + col_a INT UNSIGNED NOT NULL AUTO_INCREMENT, + col_dt DATETIME, + col_ts TIMESTAMP NOT NULL + DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY(col_a), + UNIQUE INDEX i_ts (col_ts) +) MASTER_1_ENGINE MASTER_1_AUTO_INCREMENT_2_1 MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + col_a INT UNSIGNED NOT NULL AUTO_INCREMENT, + col_dt DATETIME, + col_ts TIMESTAMP NOT NULL + DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY(col_a), + UNIQUE INDEX i_ts (col_ts) +) $MASTER_1_ENGINE $MASTER_1_AUTO_INCREMENT_2_1 $MASTER_1_COMMENT_2_1; +echo CREATE TABLE tbl_f ( + col_d DATE, + col_t TIME +) $MASTER_1_ENGINE $MASTER_1_COMMENT_2_1_F; +eval CREATE TABLE tbl_f ( + col_d DATE, + col_t TIME +) $MASTER_1_ENGINE $MASTER_1_COMMENT_2_1_F; +--enable_query_log +SHOW CREATE TABLE tbl_a; +SHOW CREATE TABLE tbl_f; + +--echo +--echo Set a different time zone that has DST +SET time_zone='+01:00'; + +--echo +--echo Insert Rows +--connection master_1 +--echo Min value +SET @@timestamp=1; +INSERT INTO tbl_a VALUES (1, now(), now()); +SET @@timestamp=0; +--echo Ambiguous DST values for MET time zone that result in the +--echo same UTC timestamp +INSERT INTO tbl_a VALUES (2, '2018-03-25 02:00:00', '2018-03-25 02:00:00'); +INSERT INTO tbl_a VALUES (3, '2018-03-25 02:30:00', '2018-03-25 02:30:00'); +--echo Ambiguous DST values for MET time zone in the 2:00 am to 3:00 am hour +--echo that occur twice when transitioning from DST to standard time +SET @@timestamp=1540686600; +INSERT INTO tbl_a VALUES (4, now(), now()); +SET @@timestamp=1540690200; +INSERT INTO tbl_a VALUES (5, now(), now()); +--echo Max value +SET @@timestamp=2147483647; +INSERT INTO tbl_a VALUES (6, now(), now()); +SET @@timestamp=0; + +--echo +--echo SELECTs +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo DELETEs +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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 tbl_a WHERE col_ts='1970-01-01 01:00:01'; +--disable_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + TRUNCATE TABLE mysql.general_log; + } + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--connection master_1 +SET @@timestamp=1; +INSERT INTO tbl_a VALUES (1, now(), now()); +SET @@timestamp=0; +--disable_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo UPDATEs +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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 tbl_a SET col_ts=col_dt; +--disable_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo Lookups +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > '2018-01-01'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts < '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE '2018-10-28 02:30:00' > col_ts; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts BETWEEN '2018-10-28 01:30:00' AND '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts >= '2018-10-28 01:30:00' AND col_ts <= '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 180325020000; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 19700101010001; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo Drop the index on the timestamp column +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + eval $CHILD2_1_DROP_INDEX; + eval $CHILD2_1_SHOW_CREATE_TABLE; + 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 +DROP INDEX i_ts ON tbl_a; +SHOW CREATE TABLE tbl_a; + +--echo +--echo Retry lookups on unindexed timestamp column +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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_ps2_protocol +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > '2018-01-01'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts < '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE '2018-10-28 02:30:00' > col_ts; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts BETWEEN '2018-10-28 01:30:00' AND '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts >= '2018-10-28 01:30:00' AND col_ts <= '2018-10-28 02:30:00'; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 180325020000; +SELECT *, unix_timestamp(col_ts) FROM tbl_a WHERE col_ts > 19700101010001; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo Test the TIMESTAMP function +--connection master_1 +INSERT INTO tbl_f VALUES ('2018-06-24', '01:23:45'), + ('2018-06-24', '01:23:45'), + ('2018-08-01', '12:34:56'); +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection 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_ps2_protocol +SELECT * FROM tbl_f; +SELECT TIMESTAMP(col_d, col_t) FROM tbl_f; +SELECT TIMESTAMP('2018-06-25', col_t) FROM tbl_f; +SELECT TIMESTAMP(col_d, '10:43:21') FROM tbl_f; +SELECT TIMESTAMP('2018-06-25', '10:43:21') FROM tbl_f; +if ($USE_CHILD_GROUP2) +{ + if (!$OUTPUT_CHILD_GROUP2) + { + --disable_query_log + --disable_result_log + } + --connection child2_1 + if ($USE_GENERAL_LOG) + { + eval $CHILD2_1_SELECT_ARGUMENT1; + } + eval $CHILD2_1_SELECT_TABLE_F; + if (!$OUTPUT_CHILD_GROUP2) + { + --enable_query_log + --enable_result_log + } +} +--enable_ps2_protocol + +--echo +--echo Restore Time Zone settings +--connection master_1 +SET GLOBAL time_zone=DEFAULT; +SET time_zone=DEFAULT; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SET GLOBAL time_zone=DEFAULT; + SET time_zone=DEFAULT; +} + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS ts_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + DROP DATABASE IF EXISTS ts_test_remote; + if ($USE_GENERAL_LOG) + { + SET GLOBAL log_output = @old_log_output; + } +} +--enable_warnings +--source timestamp_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/t/timestamp_deinit.inc b/storage/spider/mysql-test/spider/t/timestamp_deinit.inc new file mode 100644 index 00000000..52be67a1 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/timestamp_deinit.inc @@ -0,0 +1,13 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $OUTPUT_CHILD_GROUP2= $OUTPUT_CHILD_GROUP2_BACKUP +--let $USE_GENERAL_LOG= $USE_GENERAL_LOG_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/t/timestamp_init.inc b/storage/spider/mysql-test/spider/t/timestamp_init.inc new file mode 100644 index 00000000..22587bcf --- /dev/null +++ b/storage/spider/mysql-test/spider/t/timestamp_init.inc @@ -0,0 +1,62 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +--enable_result_log +--enable_query_log +--enable_warnings + +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +--let $MASTER_1_COMMENT_2_1_F_BACKUP= $MASTER_1_COMMENT_2_1_F +let $MASTER_1_COMMENT_2_1= + COMMENT='database "ts_test_remote", table "tbl_a", srv "s_2_1"'; +let $MASTER_1_COMMENT_2_1_F= + COMMENT='database "ts_test_remote", table "tbl_f", srv "s_2_1"'; +let $MASTER_1_AUTO_INCREMENT_2_1= + AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4; +let $MASTER_1_AUTO_INCREMENT1= + AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4; +let $MASTER_1_AUTO_INCREMENT2= + AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4; +let $CHILD2_1_AUTO_INCREMENT= + AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4; +--let $CHILD2_1_DROP_TABLE_BACKUP= $CHILD2_1_DROP_TABLE +--let $CHILD2_1_DROP_TABLE_F_BACKUP= $CHILD2_1_DROP_TABLE_F +let $CHILD2_1_DROP_TABLE= + DROP TABLE IF EXISTS tbl_a; +let $CHILD2_1_DROP_TABLE_F= + DROP TABLE IF EXISTS tbl_f; +--let $CHILD2_1_CREATE_TABLE_BACKUP= $CHILD2_1_CREATE_TABLE +--let $CHILD2_1_CREATE_TABLE_F_BACKUP= $CHILD2_1_CREATE_TABLE_F +let $CHILD2_1_CREATE_TABLE= + CREATE TABLE tbl_a ( + col_a INT UNSIGNED NOT NULL AUTO_INCREMENT, + col_dt DATETIME, + col_ts TIMESTAMP NOT NULL + DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY(col_a), + UNIQUE INDEX i_ts (col_ts) + ) $CHILD2_1_ENGINE $CHILD2_1_AUTO_INCREMENT; +let $CHILD2_1_CREATE_TABLE_F= + CREATE TABLE tbl_f ( + col_d DATE, + col_t TIME + ) $CHILD2_1_ENGINE; +--let $CHILD2_1_SELECT_TABLE_BACKUP= $CHILD2_1_SELECT_TABLE +--let $CHILD2_1_SELECT_TABLE_F_BACKUP= $CHILD2_1_SELECT_TABLE_F +let $CHILD2_1_SELECT_TABLE= + SELECT col_a, col_dt, col_ts, unix_timestamp(col_ts) FROM tbl_a ORDER BY col_a; +let $CHILD2_1_SELECT_TABLE_F= + SELECT col_d, col_t FROM tbl_f; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'; +let $CHILD2_1_DROP_INDEX= + DROP INDEX i_ts ON tbl_a; +let $CHILD2_1_SHOW_CREATE_TABLE= + SHOW CREATE TABLE tbl_a; +let $CHILD2_1_SHOW_CREATE_TABLE_F= + SHOW CREATE TABLE tbl_f; +--let $OUTPUT_CHILD_GROUP2_BACKUP= $OUTPUT_CHILD_GROUP2 +--let $OUTPUT_CHILD_GROUP2= 1 +--let $USE_GENERAL_LOG_BACKUP= $USE_GENERAL_LOG +--let $USE_GENERAL_LOG= 1 diff --git a/storage/spider/mysql-test/spider/t/udf_pushdown.inc b/storage/spider/mysql-test/spider/t/udf_pushdown.inc new file mode 100644 index 00000000..df9742a3 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/udf_pushdown.inc @@ -0,0 +1,50 @@ +--echo +--echo ##### test SELECTs ##### +--connection master_1 +--disable_ps2_protocol +SELECT * FROM ta_l WHERE id = plusone(1); +SELECT * FROM ta_l WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +--enable_ps2_protocol + +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SELECT argument FROM mysql.general_log WHERE argument LIKE "%select%" AND argument NOT LIKE "%argument%"; + --disable_query_log + TRUNCATE TABLE mysql.general_log; + --enable_query_log +} + +--echo +--echo ##### test UPDATEs ##### +--connection master_1 +UPDATE ta_l SET a = plusone(221) WHERE id = plusone(1); +SELECT * FROM ta_l; +UPDATE ta_l SET a = plusone(332) WHERE id IN (plusone(1), plusone(2)) AND a = plusone(32); +SELECT * FROM ta_l; + +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SELECT argument FROM mysql.general_log WHERE argument LIKE "%update%" AND argument NOT LIKE "%argument%"; + --disable_query_log + TRUNCATE TABLE mysql.general_log; + --enable_query_log +} + +--echo +--echo ##### test DELETEs ##### +--connection master_1 +DELETE FROM ta_l WHERE id = plusone(1); +SELECT * FROM ta_l; +DELETE FROM ta_l WHERE id IN (plusone(1), plusone(2), plusone(3)) AND a = plusone(43); +SELECT * FROM ta_l; + +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SELECT argument FROM mysql.general_log WHERE (argument LIKE "%delete%" OR argument LIKE "%update%") AND argument NOT LIKE "%argument%"; + --disable_query_log + TRUNCATE TABLE mysql.general_log; + --enable_query_log +} diff --git a/storage/spider/mysql-test/spider/t/udf_pushdown.test b/storage/spider/mysql-test/spider/t/udf_pushdown.test new file mode 100644 index 00000000..2eadbbbb --- /dev/null +++ b/storage/spider/mysql-test/spider/t/udf_pushdown.test @@ -0,0 +1,141 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--echo # +--echo # MDEV-26545 Spider does not correctly handle UDF and stored function in where conds +--echo # + +let $CHILD_CREATE_TABLE= + CREATE TABLE ta_r ( + id INT NOT NULL, + a INT, + PRIMARY KEY(id) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; + +let $MASTER_CREATE_TABLE_OUTPUT= + CREATE TABLE ta_l ( + id INT NOT NULL, + a INT, + PRIMARY KEY(id) + ) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; + +let $MASTER_CREATE_TABLE= + CREATE TABLE ta_l ( + id INT NOT NULL, + a INT, + PRIMARY KEY(id) + ) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; + +--echo +--echo ##### enable general_log ##### +--connection child2_1 +SET @general_log_backup = @@global.general_log; +SET @log_output_backup = @@global.log_output; +SET @@global.general_log = 1; +SET @@global.log_output = "TABLE"; +TRUNCATE TABLE mysql.general_log; + +--echo +--echo ##### create databases ##### +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + CREATE DATABASE auto_test_remote; + USE auto_test_remote; +} + +--echo +--echo ##### create tables ##### +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + --disable_query_log + echo CHILD_CREATE_TABLE; + eval $CHILD_CREATE_TABLE; + --enable_query_log +} + +--connection master_1 +--disable_query_log +echo MASTER_CREATE_TABLE; +echo $MASTER_CREATE_TABLE_OUTPUT; +eval $MASTER_CREATE_TABLE; +--enable_query_log + +INSERT INTO ta_l VALUES + (1, 11), + (2, 22), + (3, 33), + (4, 44), + (5, 55); + +--echo +--echo ##### create functions ##### +--connection master_1 +DELIMITER //; +CREATE FUNCTION `plusone`( param INT ) RETURNS INT +BEGIN + RETURN param + 1; +END // +DELIMITER ;// + +--connection child2_1 +DELIMITER //; +CREATE FUNCTION `plusone`( param INT ) RETURNS INT +BEGIN + RETURN param + 1; +END // +DELIMITER ;// + +--echo +--echo ########## spider_use_pushdown_udf=0 ########## +--connection master_1 +SET @@spider_use_pushdown_udf = 0; +--source udf_pushdown.inc + +--echo +--echo ##### reset records ##### +--connection master_1 +TRUNCATE TABLE ta_l; +INSERT INTO ta_l VALUES + (1, 11), + (2, 22), + (3, 33), + (4, 44), + (5, 55); + +--echo +--echo ########## spider_use_pushdown_udf=1 ########## +--connection master_1 +SET @@spider_use_pushdown_udf = 1; +--source udf_pushdown.inc + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP FUNCTION `plusone`; +DROP DATABASE IF EXISTS auto_test_local; +if ($USE_CHILD_GROUP2) +{ + --connection child2_1 + SET @@global.general_log = @general_log_backup; + SET @@global.log_output = @log_output_backup; + DROP FUNCTION `plusone`; + DROP DATABASE IF EXISTS auto_test_remote; +} +--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/variable_deprecation.test b/storage/spider/mysql-test/spider/t/variable_deprecation.test new file mode 100644 index 00000000..3ed8dcf5 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/variable_deprecation.test @@ -0,0 +1,137 @@ +--echo # +--echo # MDEV-27228 Deprecate Spider plugin variables that result in excessive tweak +--echo # + +--disable_query_log +--disable_result_log +--source test_init.inc +--enable_result_log +--enable_query_log + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--echo # MDEV-28297 Deprecate spider_internal_offset +SET spider_internal_offset = 1; +SHOW VARIABLES LIKE "spider_internal_offset"; + +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='ios "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='internal_offset "1"'; +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-27981 Deprecate spider_internal_limit +SET spider_internal_limit = 1; +SHOW VARIABLES LIKE "spider_internal_limit"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='ilm "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='internal_limit "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28244 Deprecate spider_xa_register_mode +SET spider_xa_register_mode = 0; +SHOW VARIABLES LIKE "spider_xa_register_mode"; + +--echo # MDEV-28007 Deprecate Spider plugin variables regarding statistics persistence +SET GLOBAL spider_store_last_sts = 0; +SHOW VARIABLES LIKE "spider_store_last_sts"; + +SET GLOBAL spider_store_last_crd = 0; +SHOW VARIABLES LIKE "spider_store_last_crd"; + +SET GLOBAL spider_load_sts_at_startup = 0; +SHOW VARIABLES LIKE "spider_load_sts_at_startup"; + +SET GLOBAL spider_load_crd_at_startup = 0; +SHOW VARIABLES LIKE "spider_load_crd_at_startup"; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28008 Deprecate spider_crd_mode and spider_sts_mode +SET spider_crd_mode = 1; +SHOW VARIABLES LIKE "spider_crd_mode"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='cmd "3"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='crd_mode "3"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +SET spider_sts_mode = 1; +SHOW VARIABLES LIKE "spider_sts_mode"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='smd "3"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='sts_mode "3"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28010 Deprecate spider_crd_type and spider_crd_weight +SET spider_crd_type = 1; +SHOW VARIABLES LIKE "spider_crd_type"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='ctp "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='crd_type "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +SET spider_crd_weight = 1; +SHOW VARIABLES LIKE "spider_crd_weight"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='cwg "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='crd_weight "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28560 Deprecate spider_buffer_size +SET spider_buffer_size = 1; +SHOW VARIABLES LIKE "spider_buffer_size"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='bfz "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='buffer_size "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-27926 Deprecate spider_init_sql_alloc_size +SET spider_init_sql_alloc_size = 1; +SHOW VARIABLES LIKE "spider_init_sql_alloc_size"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='isa "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='init_sql_alloc_size "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28829 Deprecate spider_semi_table_lock and spider_semi_table_lock_connection +SET spider_semi_table_lock = 1; +SHOW VARIABLES LIKE "spider_semi_table_lock"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='stl "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='semi_table_lock "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +SET spider_semi_table_lock_connection = 0; +SHOW VARIABLES LIKE "spider_semi_table_lock_connection"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='stc "0"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='semi_table_lock_connection "0"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +--echo # MDEV-28795 Deprecate spider_bka_table_name_type +SET spider_bka_table_name_type = 1; +SHOW VARIABLES LIKE "spider_bka_table_name_type"; +eval CREATE TABLE tbl_a (a INT) $MASTER_1_ENGINE COMMENT='btt "1"'; +eval CREATE TABLE tbl_b (a INT) $MASTER_1_ENGINE COMMENT='bka_table_name_type "1"'; + +DROP TABLE tbl_a; +DROP TABLE tbl_b; + +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source test_deinit.inc +--enable_result_log +--enable_query_log 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 00000000..2c3e1523 --- /dev/null +++ b/storage/spider/mysql-test/spider/t/vp_fixes.test @@ -0,0 +1,335 @@ +# This test tests for VP's bug fixes +--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 + +--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 command_type != 'Execute' AND 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 command_type != 'Execute' AND 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/spd_conn.cc b/storage/spider/spd_conn.cc new file mode 100644 index 00000000..443912b5 --- /dev/null +++ b/storage/spider/spd_conn.cc @@ -0,0 +1,4119 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019, 2020, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_table.h" +#include "tztime.h" +#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_table.h" +#include "spd_direct_sql.h" +#include "spd_ping_table.h" +#include "spd_malloc.h" +#include "spd_err.h" + +#ifdef SPIDER_HAS_NEXT_THREAD_ID +#define SPIDER_set_next_thread_id(A) +#else +extern ulong *spd_db_att_thread_id; +inline void SPIDER_set_next_thread_id(THD *A) +{ + pthread_mutex_lock(&LOCK_thread_count); + A->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +} +#endif + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern struct charset_info_st *spd_charset_utf8mb3_bin; +extern LEX_CSTRING spider_unique_id; +pthread_mutex_t spider_conn_id_mutex; +pthread_mutex_t spider_ipport_conn_mutex; +ulonglong spider_conn_id = 1; + +extern pthread_attr_t spider_pt_attr; + +#ifdef HAVE_PSI_INTERFACE +extern PSI_mutex_key spd_key_mutex_mta_conn; +extern PSI_mutex_key spd_key_mutex_conn_i; +extern PSI_mutex_key spd_key_mutex_conn_loop_check; +extern PSI_cond_key spd_key_cond_conn_i; +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_cond_key spd_key_cond_bg_mon_sleep; +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 + +/* UTC time zone for timestamp columns */ +extern Time_zone *UTC; + +extern sql_mode_t full_sql_mode; +extern sql_mode_t pushdown_sql_mode; + +HASH spider_open_connections; +uint spider_open_connections_id; +HASH spider_ipport_conns; +long spider_conn_mutex_id = 0; + +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; + +/* 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)); +#ifdef DBUG_TRACE + spider_print_keys(conn->conn_key, conn->conn_key_length); +#endif + DBUG_RETURN((uchar*) conn->conn_key); +} + +uchar *spider_ipport_conn_get_key( + SPIDER_IP_PORT_CONN *ip_port, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) +{ + DBUG_ENTER("spider_ipport_conn_get_key"); + *length = ip_port->key_len; + DBUG_RETURN((uchar*) ip_port->key); +} + +static uchar *spider_loop_check_full_get_key( + SPIDER_CONN_LOOP_CHECK *ptr, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_loop_check_full_get_key"); + *length = ptr->full_name.length; + DBUG_RETURN((uchar*) ptr->full_name.str); +} + +static uchar *spider_loop_check_to_get_key( + SPIDER_CONN_LOOP_CHECK *ptr, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_loop_check_to_get_key"); + *length = ptr->to_name.length; + DBUG_RETURN((uchar*) ptr->to_name.str); +} + +int spider_conn_init( + SPIDER_CONN *conn +) { + int error_num = HA_ERR_OUT_OF_MEM; + DBUG_ENTER("spider_conn_init"); + if (mysql_mutex_init(spd_key_mutex_conn_loop_check, &conn->loop_check_mutex, + MY_MUTEX_INIT_FAST)) + { + goto error_loop_check_mutex_init; + } + if ( + my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_checked, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_loop_check_full_get_key, 0, 0) + ) { + goto error_loop_checked_hash_init; + } + spider_alloc_calc_mem_init(conn->loop_checked, 268); + spider_alloc_calc_mem(spider_current_trx, + conn->loop_checked, + conn->loop_checked.array.max_element * + conn->loop_checked.array.size_of_element); + if ( + my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_check_queue, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_loop_check_to_get_key, 0, 0) + ) { + goto error_loop_check_queue_hash_init; + } + spider_alloc_calc_mem_init(conn->loop_check_queue, 269); + spider_alloc_calc_mem(spider_current_trx, + conn->loop_check_queue, + conn->loop_check_queue.array.max_element * + conn->loop_check_queue.array.size_of_element); + DBUG_RETURN(0); + +error_loop_check_queue_hash_init: + spider_free_mem_calc(spider_current_trx, + conn->loop_checked_id, + conn->loop_checked.array.max_element * + conn->loop_checked.array.size_of_element); + my_hash_free(&conn->loop_checked); +error_loop_checked_hash_init: + pthread_mutex_destroy(&conn->loop_check_mutex); +error_loop_check_mutex_init: + DBUG_RETURN(error_num); +} + +void spider_conn_done( + SPIDER_CONN *conn +) { + SPIDER_CONN_LOOP_CHECK *lcptr; + DBUG_ENTER("spider_conn_done"); + uint l = 0; + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_checked, l))) + { + spider_free(spider_current_trx, lcptr, MYF(0)); + ++l; + } + spider_free_mem_calc(spider_current_trx, + conn->loop_check_queue_id, + conn->loop_check_queue.array.max_element * + conn->loop_check_queue.array.size_of_element); + my_hash_free(&conn->loop_check_queue); + spider_free_mem_calc(spider_current_trx, + conn->loop_checked_id, + conn->loop_checked.array.max_element * + conn->loop_checked.array.size_of_element); + my_hash_free(&conn->loop_checked); + pthread_mutex_destroy(&conn->loop_check_mutex); + DBUG_VOID_RETURN; +} + +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(); + conn->wait_timeout = spider_param_remote_wait_timeout(thd); + conn->sql_mode = full_sql_mode + 1; + myf utf8_flag= thd->get_utf8_flag(); + 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(utf8_flag | 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(spider_conn_reset_queue_loop_check(conn)); +} + +int spider_free_conn_alloc( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_free_conn_alloc"); + spider_free_conn_thread(conn); + spider_db_disconnect(conn); + if (conn->db_conn) + { + delete conn->db_conn; + conn->db_conn = NULL; + } + spider_conn_done(conn); + 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; + SPIDER_IP_PORT_CONN *ip_port_conn = conn->ip_port_conn; + DBUG_ENTER("spider_free_conn_from_trx"); + spider_conn_clear_queue(conn); + conn->use_for_active_standby = FALSE; + conn->error_mode = 1; + 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; + my_hash_delete(&trx->trx_another_conn_hash, (uchar*) conn); + 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 { + my_hash_delete(&trx->trx_conn_hash, (uchar*) conn); + } + + 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'; + conn->casual_read_base_conn = NULL; + 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; + if (my_hash_insert(&spider_open_connections, (uchar*) conn)) + { + pthread_mutex_unlock(&spider_conn_mutex); + spider_free_conn(conn); + } else { + if (ip_port_conn) + { /* exists */ + if (ip_port_conn->waiting_count) + { + pthread_mutex_lock(&ip_port_conn->mutex); + pthread_cond_signal(&ip_port_conn->cond); + pthread_mutex_unlock(&ip_port_conn->mutex); + } + } + 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 */ + if (conn->quick_target) + { + spider_db_free_result((ha_spider *) conn->quick_target, TRUE); + } + spider_free_conn(conn); + } + } else if (roop_count) + (*roop_count)++; + 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; + SPIDER_IP_PORT_CONN *ip_port_conn; + char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket; + char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert; + char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group; + char *tmp_dsn, *tmp_filedsn, *tmp_driver; + DBUG_ENTER("spider_create_conn"); + + if (unlikely(!UTC)) + { + /* UTC time zone for timestamp columns */ + String tz_00_name(STRING_WITH_LEN("+00:00"), &my_charset_bin); + UTC = my_tz_find(current_thd, &tz_00_name); + } + + bool tables_on_different_db_are_joinable; + if (share->sql_dbton_ids[link_idx] != SPIDER_DBTON_SIZE) + { + tables_on_different_db_are_joinable = + spider_dbton[share->sql_dbton_ids[link_idx]].db_util-> + tables_on_different_db_are_joinable(); + } else { + tables_on_different_db_are_joinable = TRUE; + } + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 18, MYF(MY_WME | MY_ZEROFILL), + &conn, (uint) (sizeof(*conn)), + &tmp_name, (uint) (share->conn_keys_lengths[link_idx] + 1), + &tmp_host, (uint) (share->tgt_hosts_lengths[link_idx] + 1), + &tmp_username, + (uint) (share->tgt_usernames_lengths[link_idx] + 1), + &tmp_password, + (uint) (share->tgt_passwords_lengths[link_idx] + 1), + &tmp_socket, (uint) (share->tgt_sockets_lengths[link_idx] + 1), + &tmp_wrapper, + (uint) (share->tgt_wrappers_lengths[link_idx] + 1), + &tmp_db, (uint) (tables_on_different_db_are_joinable ? + 0 : share->tgt_dbs_lengths[link_idx] + 1), + &tmp_ssl_ca, (uint) (share->tgt_ssl_cas_lengths[link_idx] + 1), + &tmp_ssl_capath, + (uint) (share->tgt_ssl_capaths_lengths[link_idx] + 1), + &tmp_ssl_cert, + (uint) (share->tgt_ssl_certs_lengths[link_idx] + 1), + &tmp_ssl_cipher, + (uint) (share->tgt_ssl_ciphers_lengths[link_idx] + 1), + &tmp_ssl_key, + (uint) (share->tgt_ssl_keys_lengths[link_idx] + 1), + &tmp_default_file, + (uint) (share->tgt_default_files_lengths[link_idx] + 1), + &tmp_default_group, + (uint) (share->tgt_default_groups_lengths[link_idx] + 1), + &tmp_dsn, + (uint) (share->tgt_dsns_lengths[link_idx] + 1), + &tmp_filedsn, + (uint) (share->tgt_filedsns_lengths[link_idx] + 1), + &tmp_driver, + (uint) (share->tgt_drivers_lengths[link_idx] + 1), + &need_mon, (uint) (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]); + conn->conn_key_hash_value = share->conn_keys_hash_value[link_idx]; + 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; + if (conn->tgt_username_length) + 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; + if (conn->tgt_password_length) + 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; + if (conn->tgt_socket_length) + 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]); + if (!tables_on_different_db_are_joinable) + { + conn->tgt_db_length = share->tgt_dbs_lengths[link_idx]; + conn->tgt_db = tmp_db; + memcpy(conn->tgt_db, share->tgt_dbs[link_idx], + share->tgt_dbs_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_dsn_length = + share->tgt_dsns_lengths[link_idx]; + if (conn->tgt_dsn_length) + { + conn->tgt_dsn = tmp_dsn; + memcpy(conn->tgt_dsn, share->tgt_dsns[link_idx], + share->tgt_dsns_lengths[link_idx]); + } else + conn->tgt_dsn = NULL; + conn->tgt_filedsn_length = + share->tgt_filedsns_lengths[link_idx]; + if (conn->tgt_filedsn_length) + { + conn->tgt_filedsn = tmp_filedsn; + memcpy(conn->tgt_filedsn, share->tgt_filedsns[link_idx], + share->tgt_filedsns_lengths[link_idx]); + } else + conn->tgt_filedsn = NULL; + conn->tgt_driver_length = + share->tgt_drivers_lengths[link_idx]; + if (conn->tgt_driver_length) + { + conn->tgt_driver = tmp_driver; + memcpy(conn->tgt_driver, share->tgt_drivers[link_idx], + share->tgt_drivers_lengths[link_idx]); + } else + conn->tgt_driver = 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 (conn->dbton_id == SPIDER_DBTON_SIZE) + { + my_printf_error( + ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR, + MYF(0), conn->tgt_wrapper); + *error_num = ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM; + goto error_invalid_wrapper; + } + 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_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, + MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_mta_conn_mutex_init; + } + + if (unlikely((*error_num = spider_conn_init(conn)))) + { + goto error_conn_init; + } + + spider_conn_queue_connect(share, conn, link_idx); + conn->ping_time = (time_t) time((time_t*) 0); + conn->connect_error_time = conn->ping_time; + pthread_mutex_lock(&spider_conn_id_mutex); + conn->conn_id = spider_conn_id; + ++spider_conn_id; + pthread_mutex_unlock(&spider_conn_id_mutex); + + pthread_mutex_lock(&spider_ipport_conn_mutex); + if ((ip_port_conn = (SPIDER_IP_PORT_CONN*) my_hash_search_using_hash_value( + &spider_ipport_conns, conn->conn_key_hash_value, + (uchar*)conn->conn_key, conn->conn_key_length))) + { /* exists, +1 */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + pthread_mutex_lock(&ip_port_conn->mutex); + if (spider_param_max_connections()) + { /* enable conncetion pool */ + if (ip_port_conn->ip_port_count >= spider_param_max_connections()) + { /* bigger than the max num of connections, free conn and return NULL */ + pthread_mutex_unlock(&ip_port_conn->mutex); + *error_num = ER_SPIDER_CON_COUNT_ERROR; + goto error_too_many_ipport_count; + } + } + ip_port_conn->ip_port_count++; + pthread_mutex_unlock(&ip_port_conn->mutex); + } + else + {// do not exist + ip_port_conn = spider_create_ipport_conn(conn); + if (!ip_port_conn) { + /* failed, always do not effect 'create conn' */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + DBUG_RETURN(conn); + } + if (my_hash_insert(&spider_ipport_conns, (uchar *)ip_port_conn)) { + /* insert failed, always do not effect 'create conn' */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + DBUG_RETURN(conn); + } + pthread_mutex_unlock(&spider_ipport_conn_mutex); + } + conn->ip_port_conn = ip_port_conn; + + DBUG_RETURN(conn); + +error_too_many_ipport_count: + spider_conn_done(conn); +error_conn_init: + pthread_mutex_destroy(&conn->mta_conn_mutex); +error_mta_conn_mutex_init: +error_db_conn_init: + delete conn->db_conn; +error_db_conn_create: +error_invalid_wrapper: + 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)); + +#ifdef DBUG_TRACE + spider_print_keys(conn_key, share->conn_keys_lengths[link_idx]); +#endif + if ( + (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 ( + !trx->thd || + ( + (spider_param_conn_recycle_mode(trx->thd) & 1) || + spider_param_conn_recycle_strict(trx->thd) + ) + ) { + pthread_mutex_lock(&spider_conn_mutex); + 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]))) + { + pthread_mutex_unlock(&spider_conn_mutex); + if (spider_param_max_connections()) + { /* enable connection pool */ + conn = spider_get_conn_from_idle_connection(share, link_idx, conn_key, spider, conn_kind, base_link_idx, error_num); + /* failed get conn, goto error */ + if (!conn) + goto error; + + } + else + { /* did not enable conncetion pool , create_conn */ + 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 { + my_hash_delete(&spider_open_connections, (uchar*) conn); + 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; + } + } + } 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) + { + spider->conns[base_link_idx] = conn; + 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 (another) + { + uint old_elements = trx->trx_another_conn_hash.array.max_element; + if (my_hash_insert(&trx->trx_another_conn_hash, (uchar*) conn)) + { + 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; + if (my_hash_insert(&trx->trx_conn_hash, (uchar*) conn)) + { + 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); + } + } + } else 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; + } + conn->link_idx = base_link_idx; + + if (conn->queued_connect) + spider_conn_queue_connect_rewrite(share, conn, link_idx); + + if (conn->queued_ping) + { + if (spider) + spider_conn_queue_ping_rewrite(spider, conn, base_link_idx); + else + conn->queued_ping = FALSE; + } + + if (unlikely(spider && spider->wide_handler->top_share && + (*error_num = spider_conn_queue_loop_check( + conn, spider, base_link_idx)))) + { + goto error; + } + + 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_IP_PORT_CONN* ip_port_conn = conn->ip_port_conn; + if (ip_port_conn) + { /* free conn, ip_port_count-- */ + pthread_mutex_lock(&ip_port_conn->mutex); + if (ip_port_conn->ip_port_count > 0) + ip_port_conn->ip_port_count--; + pthread_mutex_unlock(&ip_port_conn->mutex); + } + if (conn->conn_holder_for_direct_join) + conn->conn_holder_for_direct_join->conn= NULL; + spider_free_conn_alloc(conn); + spider_free(spider_current_trx, conn, MYF(0)); + DBUG_RETURN(0); +} + +/** + May get or create a connection spawning a background thread + + For each link (data node, formally representable as the tuple + (spider, link_idx)), there is an associated casual read value + (`spider->result_list.casual_read[link_idx]'). + + If the CRV is 0, do nothing. Otherwise, An casual read id + (`conn->casual_read_current_id`) is associated with the link and + query id. The CRI starts from 2, and is used only when CRV is 1, to + update the CRV (see below). The updated CRV is then used to + construct the connection key used for get or create a connection + that spawns a background thread to execute queries. + + If the CRV is 1, it is assigned CRI. The latter is then incremented + by 1. The CRI will only go up to 63, before "wrapping" back to 2. + + If 2 <= CRV <= 63, it is left alone. + + Note that this function relies on the assumption that the CRV is + reset (e.g. using `spider_param_casual_read()') between consecutive + calls of this function for the CRV == 1 case to auto-increment as + expected. +*/ +int spider_check_and_get_casual_read_conn( + THD *thd, + ha_spider *spider, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_check_and_get_casual_read_conn"); + if (!spider->result_list.casual_read[link_idx]) + DBUG_RETURN(0); + SPIDER_CONN *conn = spider->conns[link_idx]; + if (conn->casual_read_query_id != thd->query_id) + { + conn->casual_read_query_id = thd->query_id; + conn->casual_read_current_id = 2; + } + if (spider->result_list.casual_read[link_idx] == 1) + { + spider->result_list.casual_read[link_idx] = conn->casual_read_current_id; + ++conn->casual_read_current_id; + if (conn->casual_read_current_id > 63) + conn->casual_read_current_id = 2; + } + char first_byte_bak = *spider->conn_keys[link_idx]; + *spider->conn_keys[link_idx] = + '0' + spider->result_list.casual_read[link_idx]; + if (!(spider->conns[link_idx]= spider_get_conn( + spider->share, link_idx, spider->conn_keys[link_idx], + spider->wide_handler->trx, spider, FALSE, TRUE, + SPIDER_CONN_KIND_MYSQL, &error_num))) + { + *spider->conn_keys[link_idx] = first_byte_bak; + DBUG_RETURN(error_num); + } + *spider->conn_keys[link_idx] = first_byte_bak; + spider->conns[link_idx]->casual_read_base_conn = conn; + spider_check_and_set_autocommit(thd, spider->conns[link_idx], NULL); + DBUG_RETURN(0); +} + +int spider_check_and_init_casual_read( + THD *thd, + ha_spider *spider, + int link_idx +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_check_and_init_casual_read"); + if ( + spider_param_sync_autocommit(thd) && + (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) && + ( + result_list->direct_order_limit + || result_list->direct_aggregate + ) + ) { + if (!result_list->casual_read[link_idx]) + { + result_list->casual_read[link_idx] = + spider_param_casual_read(thd, share->casual_read); + } + if ((error_num = spider_check_and_get_casual_read_conn(thd, spider, + link_idx))) + { + DBUG_RETURN(error_num); + } + SPIDER_CONN *conn = spider->conns[link_idx]; + if ( + conn->casual_read_base_conn && + (error_num = spider_create_conn_thread(conn)) + ) { + DBUG_RETURN(error_num); + } + } + 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_ping_rewrite( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_conn_queue_ping_rewrite"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + 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_wait_timeout( + SPIDER_CONN *conn, + int wait_timeout +) { + DBUG_ENTER("spider_conn_queue_wait_timeout"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + if (wait_timeout > 0) + { + conn->queued_wait_timeout = TRUE; + conn->queued_wait_timeout_val = wait_timeout; + } + DBUG_VOID_RETURN; +} + +void spider_conn_queue_sql_mode( + SPIDER_CONN *conn, + sql_mode_t sql_mode +) { + DBUG_ENTER("spider_conn_queue_sql_mode"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + DBUG_ASSERT(!(sql_mode & ~full_sql_mode)); + conn->queued_sql_mode = TRUE; + conn->queued_sql_mode_val = (sql_mode & pushdown_sql_mode); + 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_UTC_time_zone( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_conn_queue_UTC_time_zone"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + spider_conn_queue_time_zone(conn, UTC); + DBUG_VOID_RETURN; +} + +int spider_conn_queue_and_merge_loop_check( + SPIDER_CONN *conn, + SPIDER_CONN_LOOP_CHECK *lcptr +) { + int error_num = HA_ERR_OUT_OF_MEM; + char *tmp_name, *from_name, *cur_name, *to_name, *full_name, *from_value, + *merged_value; + SPIDER_CONN_LOOP_CHECK *lcqptr, *lcrptr; + DBUG_ENTER("spider_conn_queue_and_merge_loop_check"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + if (unlikely(!(lcqptr = (SPIDER_CONN_LOOP_CHECK *) + my_hash_search_using_hash_value(&conn->loop_check_queue, + lcptr->hash_value_to, + (uchar *) lcptr->to_name.str, lcptr->to_name.length)))) + { + DBUG_PRINT("info", ("spider create merged_value and insert")); + lcptr->merged_value.length = spider_unique_id.length + + lcptr->cur_name.length + lcptr->from_value.length + 1; + tmp_name = (char *) lcptr->merged_value.str; + memcpy(tmp_name, spider_unique_id.str, spider_unique_id.length); + tmp_name += spider_unique_id.length; + memcpy(tmp_name, lcptr->cur_name.str, lcptr->cur_name.length); + tmp_name += lcptr->cur_name.length; + *tmp_name = '-'; + ++tmp_name; + memcpy(tmp_name, lcptr->from_value.str, lcptr->from_value.length + 1); + if (unlikely(my_hash_insert(&conn->loop_check_queue, (uchar *) lcptr))) + { + goto error_hash_insert_queue; + } + lcptr->flag |= SPIDER_LOP_CHK_QUEUED; + } else { + DBUG_PRINT("info", ("spider append merged_value and replace")); + if (unlikely(!spider_bulk_malloc(spider_current_trx, 271, MYF(MY_WME), + &lcrptr, (uint) (sizeof(SPIDER_CONN_LOOP_CHECK)), + &from_name, (uint) (lcqptr->from_name.length + 1), + &cur_name, (uint) (lcqptr->cur_name.length + 1), + &to_name, (uint) (lcqptr->to_name.length + 1), + &full_name, (uint) (lcqptr->full_name.length + 1), + &from_value, (uint) (lcqptr->from_value.length + 1), + &merged_value, (uint) (lcqptr->merged_value.length + + spider_unique_id.length + lcptr->cur_name.length + + lcptr->from_value.length + 2), + NullS) + )) { + goto error_alloc_loop_check_replace; + } + lcrptr->hash_value_to = lcqptr->hash_value_to; + lcrptr->hash_value_full = lcqptr->hash_value_full; + lcrptr->from_name.str = from_name; + lcrptr->from_name.length = lcqptr->from_name.length; + memcpy(from_name, lcqptr->from_name.str, lcqptr->from_name.length + 1); + lcrptr->cur_name.str = cur_name; + lcrptr->cur_name.length = lcqptr->cur_name.length; + memcpy(cur_name, lcqptr->cur_name.str, lcqptr->cur_name.length + 1); + lcrptr->to_name.str = to_name; + lcrptr->to_name.length = lcqptr->to_name.length; + memcpy(to_name, lcqptr->to_name.str, lcqptr->to_name.length + 1); + lcrptr->full_name.str = full_name; + lcrptr->full_name.length = lcqptr->full_name.length; + memcpy(full_name, lcqptr->full_name.str, lcqptr->full_name.length + 1); + lcrptr->from_value.str = from_value; + lcrptr->from_value.length = lcqptr->from_value.length; + memcpy(from_value, lcqptr->from_value.str, lcqptr->from_value.length + 1); + lcrptr->merged_value.str = merged_value; + lcrptr->merged_value.length = lcqptr->merged_value.length; + memcpy(merged_value, + lcqptr->merged_value.str, lcqptr->merged_value.length); + merged_value += lcqptr->merged_value.length; + memcpy(merged_value, spider_unique_id.str, spider_unique_id.length); + merged_value += spider_unique_id.length; + memcpy(merged_value, lcptr->cur_name.str, lcptr->cur_name.length); + merged_value += lcptr->cur_name.length; + *merged_value = '-'; + ++merged_value; + memcpy(merged_value, lcptr->from_value.str, lcptr->from_value.length + 1); + + DBUG_PRINT("info", ("spider free lcqptr")); + my_hash_delete(&conn->loop_checked, (uchar*) lcqptr); + my_hash_delete(&conn->loop_check_queue, (uchar*) lcqptr); + spider_free(spider_current_trx, lcqptr, MYF(0)); + + lcptr = lcrptr; + if (unlikely(my_hash_insert(&conn->loop_checked, (uchar *) lcptr))) + { + goto error_hash_insert; + } + if (unlikely(my_hash_insert(&conn->loop_check_queue, (uchar *) lcptr))) + { + goto error_hash_insert_queue; + } + lcptr->flag = SPIDER_LOP_CHK_MERAGED; + lcptr->next = NULL; + if (!conn->loop_check_meraged_first) + { + conn->loop_check_meraged_first = lcptr; + conn->loop_check_meraged_last = lcptr; + } else { + conn->loop_check_meraged_last->next = lcptr; + conn->loop_check_meraged_last = lcptr; + } + } + DBUG_RETURN(0); + +error_alloc_loop_check_replace: +error_hash_insert_queue: + my_hash_delete(&conn->loop_checked, (uchar*) lcptr); +error_hash_insert: + spider_free(spider_current_trx, lcptr, MYF(0)); + pthread_mutex_unlock(&conn->loop_check_mutex); + DBUG_RETURN(error_num); +} + +int spider_conn_reset_queue_loop_check( + SPIDER_CONN *conn +) { + int error_num; + SPIDER_CONN_LOOP_CHECK *lcptr; + DBUG_ENTER("spider_conn_reset_queue_loop_check"); + uint l = 0; + pthread_mutex_lock(&conn->loop_check_mutex); + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_checked, l))) + { + if (!lcptr->flag) + { + DBUG_PRINT("info", ("spider free lcptr")); + my_hash_delete(&conn->loop_checked, (uchar*) lcptr); + spider_free(spider_current_trx, lcptr, MYF(0)); + } + ++l; + } + + lcptr = conn->loop_check_ignored_first; + while (lcptr) + { + lcptr->flag = 0; + if ((error_num = spider_conn_queue_and_merge_loop_check(conn, lcptr))) + { + goto error_queue_and_merge; + } + lcptr = lcptr->next; + } + conn->loop_check_meraged_first = NULL; + pthread_mutex_unlock(&conn->loop_check_mutex); + DBUG_RETURN(0); + +error_queue_and_merge: + lcptr = lcptr->next; + while (lcptr) + { + lcptr->flag = 0; + lcptr = lcptr->next; + } + conn->loop_check_meraged_first = NULL; + pthread_mutex_unlock(&conn->loop_check_mutex); + DBUG_RETURN(error_num); +} + +int spider_conn_queue_loop_check( + SPIDER_CONN *conn, + ha_spider *spider, + int link_idx +) { + int error_num = HA_ERR_OUT_OF_MEM; + uint conn_link_idx = spider->conn_link_idx[link_idx], buf_sz; + char path[FN_REFLEN + 1]; + char *tmp_name, *from_name, *cur_name, *to_name, *full_name, *from_value, + *merged_value; + user_var_entry *loop_check; + char *loop_check_buf; + THD *thd = spider->wide_handler->trx->thd; + TABLE_SHARE *top_share = spider->wide_handler->top_share; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN_LOOP_CHECK *lcptr; + LEX_CSTRING lex_str, from_str, to_str; + DBUG_ENTER("spider_conn_queue_loop_check"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + lex_str.length = top_share->path.length + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN; + buf_sz = lex_str.length + 2; + loop_check_buf = (char *) my_alloca(buf_sz); + if (unlikely(!loop_check_buf)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + lex_str.str = loop_check_buf; + memcpy(loop_check_buf, + SPIDER_SQL_LOP_CHK_PRM_PRF_STR, SPIDER_SQL_LOP_CHK_PRM_PRF_LEN); + memcpy(loop_check_buf + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN, + top_share->path.str, top_share->path.length); + loop_check_buf[lex_str.length] = '\0'; + DBUG_PRINT("info", ("spider param name=%s", lex_str.str)); + loop_check = get_variable(&thd->user_vars, &lex_str, FALSE); + if (!loop_check || loop_check->type != STRING_RESULT) + { + DBUG_PRINT("info", ("spider client is not Spider")); + lex_str.str = ""; + lex_str.length = 0; + from_str.str = ""; + from_str.length = 0; + } else { + lex_str.str = loop_check->value; + lex_str.length = loop_check->length; + DBUG_PRINT("info", ("spider from_str=%s", lex_str.str)); + if (unlikely(!(tmp_name = strchr(loop_check->value, '-')))) + { + DBUG_PRINT("info", ("spider invalid value for loop checking 1")); + from_str.str = ""; + from_str.length = 0; + } + else if (unlikely(!(tmp_name = strchr(tmp_name + 1, '-')))) + { + DBUG_PRINT("info", ("spider invalid value for loop checking 2")); + from_str.str = ""; + from_str.length = 0; + } + else if (unlikely(!(tmp_name = strchr(tmp_name + 1, '-')))) + { + DBUG_PRINT("info", ("spider invalid value for loop checking 3")); + from_str.str = ""; + from_str.length = 0; + } + else if (unlikely(!(tmp_name = strchr(tmp_name + 1, '-')))) + { + DBUG_PRINT("info", ("spider invalid value for loop checking 4")); + from_str.str = ""; + from_str.length = 0; + } + else + { + from_str.str = lex_str.str; + from_str.length = tmp_name - lex_str.str + 1; + } + } + my_afree(loop_check_buf); + + to_str.length = build_table_filename(path, FN_REFLEN, + share->tgt_dbs[conn_link_idx] ? share->tgt_dbs[conn_link_idx] : "", + share->tgt_table_names[conn_link_idx], "", 0); + to_str.str = path; + DBUG_PRINT("info", ("spider to=%s", to_str.str)); + buf_sz = from_str.length + top_share->path.length + to_str.length + 3; + loop_check_buf = (char *) my_alloca(buf_sz); + if (unlikely(!loop_check_buf)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info", ("spider top_share->path=%s", top_share->path.str)); + memcpy(loop_check_buf, from_str.str, from_str.length); + tmp_name = loop_check_buf + from_str.length; + *tmp_name = '-'; + ++tmp_name; + memcpy(tmp_name, top_share->path.str, top_share->path.length); + tmp_name += top_share->path.length; + *tmp_name = '-'; + ++tmp_name; + memcpy(tmp_name, to_str.str, to_str.length); + tmp_name += to_str.length; + *tmp_name = '\0'; + my_hash_value_type hash_value = my_calc_hash(&conn->loop_checked, + (uchar *) loop_check_buf, buf_sz - 1); + pthread_mutex_lock(&conn->loop_check_mutex); + lcptr = (SPIDER_CONN_LOOP_CHECK *) + my_hash_search_using_hash_value(&conn->loop_checked, hash_value, + (uchar *) loop_check_buf, buf_sz - 1); + if (unlikely( + !lcptr || + ( + !lcptr->flag && + ( + lcptr->from_value.length != lex_str.length || + memcmp(lcptr->from_value.str, lex_str.str, lex_str.length) + ) + ) + )) + { + if (unlikely(lcptr)) + { + DBUG_PRINT("info", ("spider free lcptr")); + my_hash_delete(&conn->loop_checked, (uchar*) lcptr); + spider_free(spider_current_trx, lcptr, MYF(0)); + } + DBUG_PRINT("info", ("spider alloc_lcptr")); + if (unlikely(!spider_bulk_malloc(spider_current_trx, 272, MYF(MY_WME), + &lcptr, (uint) (sizeof(SPIDER_CONN_LOOP_CHECK)), + &from_name, (uint) (from_str.length + 1), + &cur_name, (uint) (top_share->path.length + 1), + &to_name, (uint) (to_str.length + 1), + &full_name, (uint) (buf_sz), + &from_value, (uint) (lex_str.length + 1), + &merged_value, (uint) (spider_unique_id.length + top_share->path.length + + lex_str.length + 2), + NullS) + )) { + my_afree(loop_check_buf); + goto error_alloc_loop_check; + } + lcptr->flag = 0; + lcptr->from_name.str = from_name; + lcptr->from_name.length = from_str.length; + memcpy(from_name, from_str.str, from_str.length + 1); + lcptr->cur_name.str = cur_name; + lcptr->cur_name.length = top_share->path.length; + memcpy(cur_name, top_share->path.str, top_share->path.length + 1); + lcptr->to_name.str = to_name; + lcptr->to_name.length = to_str.length; + memcpy(to_name, to_str.str, to_str.length + 1); + lcptr->full_name.str = full_name; + lcptr->full_name.length = buf_sz - 1; + memcpy(full_name, loop_check_buf, buf_sz); + lcptr->from_value.str = from_value; + lcptr->from_value.length = lex_str.length; + memcpy(from_value, lex_str.str, lex_str.length + 1); + lcptr->merged_value.str = merged_value; + lcptr->hash_value_to = my_calc_hash(&conn->loop_checked, + (uchar *) to_str.str, to_str.length); + lcptr->hash_value_full = hash_value; + if (unlikely(my_hash_insert(&conn->loop_checked, (uchar *) lcptr))) + { + my_afree(loop_check_buf); + goto error_hash_insert; + } + } else { + if (!lcptr->flag) + { + DBUG_PRINT("info", ("spider add to ignored list")); + lcptr->flag |= SPIDER_LOP_CHK_IGNORED; + lcptr->next = NULL; + if (!conn->loop_check_ignored_first) + { + conn->loop_check_ignored_first = lcptr; + conn->loop_check_ignored_last = lcptr; + } else { + conn->loop_check_ignored_last->next = lcptr; + conn->loop_check_ignored_last = lcptr; + } + } + pthread_mutex_unlock(&conn->loop_check_mutex); + my_afree(loop_check_buf); + DBUG_PRINT("info", ("spider be sent or queued already")); + DBUG_RETURN(0); + } + my_afree(loop_check_buf); + + if ((error_num = spider_conn_queue_and_merge_loop_check(conn, lcptr))) + { + goto error_queue_and_merge; + } + pthread_mutex_unlock(&conn->loop_check_mutex); + DBUG_RETURN(0); + +error_hash_insert: + spider_free(spider_current_trx, lcptr, MYF(0)); +error_queue_and_merge: + pthread_mutex_unlock(&conn->loop_check_mutex); +error_alloc_loop_check: + DBUG_RETURN(error_num); +} + +void spider_conn_queue_start_transaction( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_conn_queue_start_transaction"); + DBUG_PRINT("info", ("spider conn=%p", conn)); + DBUG_ASSERT(!conn->trx_start); + 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_wait_timeout = FALSE; + conn->queued_sql_mode = 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)); + if (conn->queued_trx_start) + { + conn->queued_trx_start = FALSE; + conn->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; +} + +/** + Insert a connection to a binary tree ordered by priority + + Starting from `top', find the correct spot for `conn' and insert it. +*/ +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; +} + +/* Returns the connection with the smallest priority in a tree */ +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); +} + +/* Returns the connection with the biggest priority in a tree */ +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); +} + +/* + Returns the next connection + + Find the connection in the tree with the smallest priority that is + bigger than that of the current connection. +*/ +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); +} + +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; + SPIDER_WIDE_HANDLER *wide_handler = spider->wide_handler; + THD *thd = wide_handler->trx->thd; + DBUG_ENTER("spider_set_conn_bg_param"); + DBUG_PRINT("info",("spider spider=%p", spider)); + bgs_mode = + spider_param_bgs_mode(thd, share->bgs_mode); + if (bgs_mode == 0) + result_list->bgs_phase = 0; + else if ( + bgs_mode <= 2 && + (wide_handler->external_lock_type == F_WRLCK || + wide_handler->lock_mode == 2) + ) + result_list->bgs_phase = 0; + else if (bgs_mode <= 1 && wide_handler->lock_mode == 1) + result_list->bgs_phase = 0; + else { + result_list->bgs_phase = 1; + + result_list->bgs_split_read = spider_bg_split_read_param(spider); + if (spider->use_pre_call) + { + DBUG_PRINT("info",("spider use_pre_call=TRUE")); + result_list->bgs_first_read = result_list->bgs_split_read; + result_list->bgs_second_read = result_list->bgs_split_read; + } else { + DBUG_PRINT("info",("spider use_pre_call=FALSE")); + 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); + } + DBUG_PRINT("info",("spider bgs_split_read=%lld", + result_list->bgs_split_read)); + DBUG_PRINT("info",("spider bgs_first_read=%lld", share->bgs_first_read)); + DBUG_PRINT("info",("spider bgs_second_read=%lld", share->bgs_second_read)); + + 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) + { + if (spider->use_fields) + { + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + spider_fields *fields = spider->fields; + fields->set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = fields->get_next_link_idx_chain())) + { + if ((error_num = spider_create_conn_thread(link_idx_chain->conn))) + DBUG_RETURN(error_num); + } + } else { + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + spider->wide_handler->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->wide_handler->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); + } + } + } + DBUG_RETURN(0); +} + +/** + Creates a background thread on `conn' to run `spider_bg_conn_action()' + + Does not create when `conn' is NULL or a bg thread has already been + created for `conn'. +*/ +int spider_create_conn_thread( + SPIDER_CONN *conn +) { + int error_num; + DBUG_ENTER("spider_create_conn_thread"); + if (conn && !conn->bg_init) + { + if (mysql_mutex_init(spd_key_mutex_bg_conn_chain, + &conn->bg_conn_chain_mutex, MY_MUTEX_INIT_FAST)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_chain_mutex_init; + } + conn->bg_conn_chain_mutex_ptr = NULL; + if (mysql_mutex_init(spd_key_mutex_bg_conn_sync, + &conn->bg_conn_sync_mutex, MY_MUTEX_INIT_FAST)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_mutex_init; + } + if (mysql_mutex_init(spd_key_mutex_bg_conn, &conn->bg_conn_mutex, + MY_MUTEX_INIT_FAST)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mutex_init; + } + if (mysql_mutex_init(spd_key_mutex_bg_job_stack, &conn->bg_job_stack_mutex, + MY_MUTEX_INIT_FAST)) + { + 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_cond_init(spd_key_cond_bg_conn_sync, + &conn->bg_conn_sync_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } + if (mysql_cond_init(spd_key_cond_bg_conn, + &conn->bg_conn_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + pthread_mutex_lock(&conn->bg_conn_mutex); + if (mysql_thread_create(spd_key_thd_bg, &conn->bg_thread, + &spider_pt_attr, spider_bg_conn_action, (void *) conn) + ) + { + 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]; + if (conn && result_list->bgs_working) + spider_bg_conn_wait(conn); + } + DBUG_VOID_RETURN; +} + +int spider_bg_all_conn_pre_next( + ha_spider *spider, + int link_idx +) { + 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; + DBUG_ENTER("spider_bg_all_conn_pre_next"); + 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); + } + } + 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]; + if (conn && result_list->bgs_working) + spider_bg_conn_break(conn, spider); + if (spider->quick_targets[roop_count]) + { + spider_db_free_one_quick_result((SPIDER_RESULT *) result_list->current); + 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"); + DBUG_PRINT("info",("spider spider=%p", spider)); + 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 (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->bgs_working || !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); + } + DBUG_PRINT("info",("spider result_list->quick_mode=%d", + result_list->quick_mode)); + DBUG_PRINT("info",("spider result_list->bgs_current->result=%p", + result_list->bgs_current->result)); + if ( + result_list->quick_mode == 0 || + !result_list->bgs_current->result + ) { + DBUG_PRINT("info",("spider result_list->bgs_second_read=%lld", + result_list->bgs_second_read)); + DBUG_PRINT("info",("spider result_list->bgs_split_read=%lld", + result_list->bgs_split_read)); + 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 ((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); + } + } + } + result_list->bgs_phase = 2; + if (conn->db_conn->limit_mode() == 1) + { + conn->db_conn->set_limit(result_list->limit_num); + if (!discard_result) + { + if ((error_num = spider_db_store_result_for_reuse_cursor( + spider, link_idx, result_list->table))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(0); + } + } + 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; + conn->link_idx_chain = spider->link_idx_chain; + 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")); + if (result_list->bgs_error) + { + DBUG_PRINT("info",("spider bg error")); + if (result_list->bgs_error != HA_ERR_END_OF_FILE) + { + 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); + } + } + } + } else { + DBUG_PRINT("info",("spider bg current->finish_flg=%s", + result_list->current ? + (result_list->current->finish_flg ? "TRUE" : "FALSE") : "NULL")); + if (result_list->bgs_error) + { + DBUG_PRINT("info",("spider bg error")); + if (result_list->bgs_error != HA_ERR_END_OF_FILE) + { + 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); + } + } + } + } 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) + { + DBUG_PRINT("info",("spider result_list->quick_mode=%d", + result_list->quick_mode)); + DBUG_PRINT("info",("spider result_list->bgs_current->result=%p", + result_list->bgs_current->result)); + 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 ((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 (conn->db_conn->limit_mode() == 1) + { + conn->db_conn->set_limit(result_list->limit_num); + if (!discard_result) + { + if ((error_num = spider_db_store_result_for_reuse_cursor( + spider, link_idx, result_list->table))) + { + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(0); + } + } + conn->bg_target = spider; + conn->link_idx = link_idx; + conn->bg_discard_result = discard_result; + conn->link_idx_chain = spider->link_idx_chain; + 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, + bool caller_wait, + void *target, + uint link_idx, + int *error_num +) { + DBUG_ENTER("spider_bg_conn_simple_action"); + pthread_mutex_lock(&conn->bg_conn_mutex); + conn->bg_target = target; + conn->link_idx = link_idx; + conn->bg_simple_action = simple_action; + conn->bg_error_num = error_num; + if (caller_wait) + { + conn->bg_caller_wait = TRUE; + pthread_mutex_lock(&conn->bg_conn_sync_mutex); + } else { + 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); + if (caller_wait) + { + 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; + } else { + 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_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 = SPIDER_new_THD(next_thread_id()))) + { + 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); + } + SPIDER_set_next_thread_id(thd); +#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; + 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) + set_current_thd(nullptr); +#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")); +#ifndef DBUG_OFF + DBUG_PRINT("info",("spider conn->thd=%p", conn->thd)); + if (conn->thd) + { + DBUG_PRINT("info",("spider query_id=%lld", conn->thd->query_id)); + } +#endif + 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; + 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) + set_current_thd(nullptr); +#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; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_TMP_SQL; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if (spider->use_fields) + { + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + conn->link_idx, conn->link_idx_chain))) + { + result_list->bgs_error = error_num; + if ((result_list->bgs_error_with_message = thd->is_error())) + strmov(result_list->bgs_error_msg, spider_stmt_da_message(thd)); + } + } else { + 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())) + strmov(result_list->bgs_error_msg, spider_stmt_da_message(thd)); + } + } + 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)); + if (!result_list->bgs_error) + { + conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (!(result_list->bgs_error = + spider_db_set_names(spider, conn, conn->link_idx))) + { + if ( + result_list->tmp_table_join && spider->bka_mode != 2 && + 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->wide_handler->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())) + strmov(result_list->bgs_error_msg, + spider_stmt_da_message(thd)); + } 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->wide_handler->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())) + strmov(result_list->bgs_error_msg, + spider_stmt_da_message(thd)); + } 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())) + strmov(result_list->bgs_error_msg, + spider_stmt_da_message(thd)); + } + } 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())) + strmov(result_list->bgs_error_msg, + spider_stmt_da_message(thd)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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())) + strmov(result_list->bgs_error_msg, spider_stmt_da_message(thd)); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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()) + { + if ( + direct_sql->error_rw_mode && + spider_db_conn_is_network_error(error_num) + ) { + thd->clear_error(); + } else { + SPIDER_BG_DIRECT_SQL *bg_direct_sql = + (SPIDER_BG_DIRECT_SQL *) direct_sql->parent; + pthread_mutex_lock(direct_sql->bg_mutex); + bg_direct_sql->bg_error = spider_stmt_da_sql_errno(thd); + strmov((char *) bg_direct_sql->bg_error_msg, + spider_stmt_da_message(thd)); + 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; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + *conn->bg_error_num = spider_db_query_with_set_names( + conn->bg_sql_type, + spider, + conn, + conn->link_idx + ); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->bg_exec_sql = FALSE; + continue; + } + if (conn->bg_simple_action) + { + switch (conn->bg_simple_action) + { + case SPIDER_SIMPLE_CONNECT: + conn->db_conn->bg_connect(); + break; + case SPIDER_SIMPLE_DISCONNECT: + conn->db_conn->bg_disconnect(); + break; + default: + spider = (ha_spider*) conn->bg_target; + *conn->bg_error_num = + spider_db_simple_action(conn->bg_simple_action, + spider->dbton_handler[conn->dbton_id], conn->link_idx); + break; + } + conn->bg_simple_action = SPIDER_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_cond_init(spd_key_cond_bg_sts, + &share->bg_sts_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + if (mysql_cond_init(spd_key_cond_bg_sts_sync, + &share->bg_sts_sync_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } + if (mysql_thread_create(spd_key_thd_bg_sts, &share->bg_sts_thread, + &spider_pt_attr, spider_bg_sts_action, (void *) share) + ) + { + 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; + SPIDER_WIDE_HANDLER wide_handler; + int *need_mons; + SPIDER_CONN **conns; + uint *conn_link_idx; + uchar *conn_can_fo; + char **conn_keys; + spider_db_handler **dbton_hdl; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_sts_action"); + /* init start */ + char *ptr; + ptr = (char *) my_alloca( + (sizeof(int) * share->link_count) + + (sizeof(SPIDER_CONN *) * share->link_count) + + (sizeof(uint) * share->link_count) + + (sizeof(uchar) * share->link_bitmap_size) + + (sizeof(char *) * share->link_count) + + (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE)); + if (!ptr) + { + 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); + } + need_mons = (int *) ptr; + ptr += (sizeof(int) * share->link_count); + conns = (SPIDER_CONN **) ptr; + ptr += (sizeof(SPIDER_CONN *) * share->link_count); + conn_link_idx = (uint *) ptr; + ptr += (sizeof(uint) * share->link_count); + conn_can_fo = (uchar *) ptr; + ptr += (sizeof(uchar) * share->link_bitmap_size); + conn_keys = (char **) ptr; + ptr += (sizeof(char *) * share->link_count); + dbton_hdl = (spider_db_handler **) ptr; + pthread_mutex_lock(&share->sts_mutex); + if (!(thd = SPIDER_new_THD(next_thread_id()))) + { + 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(); + my_afree(need_mons); + DBUG_RETURN(NULL); + } + SPIDER_set_next_thread_id(thd); +#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; + 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) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + DBUG_RETURN(NULL); + } + share->bg_sts_thd = thd; + spider.wide_handler = &wide_handler; + wide_handler.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; + 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; + 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) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + 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; + pthread_cond_signal(&share->bg_sts_sync_cond); + pthread_mutex_unlock(&share->sts_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + DBUG_RETURN(NULL); + } + if (spider.search_link_idx < 0) + { + 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); +*/ + 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); + } + 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]) + { + spider_get_conn(share, spider.search_link_idx, + share->conn_keys[spider.search_link_idx], + trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + conns[spider.search_link_idx]->error_mode = 0; +/* + 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( + trx, + thd, + share, + spider.search_link_idx, + (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], + share->monitoring_flag[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } +*/ + spider.search_link_idx = -1; + } + if (spider.search_link_idx != -1 && conns[spider.search_link_idx]) + { + 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)) + { +/* + 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( + trx, + thd, + share, + spider.search_link_idx, + (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], + share->monitoring_flag[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_cond_init(spd_key_cond_bg_crd, + &share->bg_crd_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + if (mysql_cond_init(spd_key_cond_bg_crd_sync, + &share->bg_crd_sync_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } + if (mysql_thread_create(spd_key_thd_bg_crd, &share->bg_crd_thread, + &spider_pt_attr, spider_bg_crd_action, (void *) share) + ) + { + 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; + SPIDER_WIDE_HANDLER wide_handler; + TABLE table; + int *need_mons; + SPIDER_CONN **conns; + uint *conn_link_idx; + uchar *conn_can_fo; + char **conn_keys; + spider_db_handler **dbton_hdl; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_bg_crd_action"); + /* init start */ + char *ptr; + ptr = (char *) my_alloca( + (sizeof(int) * share->link_count) + + (sizeof(SPIDER_CONN *) * share->link_count) + + (sizeof(uint) * share->link_count) + + (sizeof(uchar) * share->link_bitmap_size) + + (sizeof(char *) * share->link_count) + + (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE)); + if (!ptr) + { + 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); + } + need_mons = (int *) ptr; + ptr += (sizeof(int) * share->link_count); + conns = (SPIDER_CONN **) ptr; + ptr += (sizeof(SPIDER_CONN *) * share->link_count); + conn_link_idx = (uint *) ptr; + ptr += (sizeof(uint) * share->link_count); + conn_can_fo = (uchar *) ptr; + ptr += (sizeof(uchar) * share->link_bitmap_size); + conn_keys = (char **) ptr; + ptr += (sizeof(char *) * share->link_count); + dbton_hdl = (spider_db_handler **) ptr; + pthread_mutex_lock(&share->crd_mutex); + if (!(thd = SPIDER_new_THD(next_thread_id()))) + { + 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(); + my_afree(need_mons); + DBUG_RETURN(NULL); + } + SPIDER_set_next_thread_id(thd); +#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; + 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) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + 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.wide_handler = &wide_handler; + wide_handler.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; + 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; + 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) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + 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; + pthread_cond_signal(&share->bg_crd_sync_cond); + pthread_mutex_unlock(&share->crd_mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + my_afree(need_mons); + DBUG_RETURN(NULL); + } + if (spider.search_link_idx < 0) + { + 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); +*/ + 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); + } + 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]) + { + spider_get_conn(share, spider.search_link_idx, + share->conn_keys[spider.search_link_idx], + trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + conns[spider.search_link_idx]->error_mode = 0; +/* + 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( + trx, + thd, + share, + spider.search_link_idx, + (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], + share->monitoring_flag[spider.search_link_idx], + TRUE + ); + lex_end(thd->lex); + } +*/ + spider.search_link_idx = -1; + } + if (spider.search_link_idx != -1 && conns[spider.search_link_idx]) + { + 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)) + { +/* + 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( + trx, + thd, + share, + spider.search_link_idx, + (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], + share->monitoring_flag[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; + char *buf = (char *) my_alloca(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); + 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); + if (share->static_link_ids[roop_count]) + { + memcpy(link_idx_str, share->static_link_ids[roop_count], + share->static_link_ids_lengths[roop_count] + 1); + link_idx_str_length = share->static_link_ids_lengths[roop_count]; + } else { + 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, + share->static_link_ids[roop_count], + share->static_link_ids_lengths[roop_count], + (uint32) share->monitoring_sid[roop_count], FALSE, &error_num))) + { + my_afree(buf); + 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, + (uint) (sizeof(THD *) * share->all_link_count), + &share->bg_mon_threads, + (uint) (sizeof(pthread_t) * share->all_link_count), + &share->bg_mon_mutexes, + (uint) (sizeof(pthread_mutex_t) * share->all_link_count), + &share->bg_mon_conds, + (uint) (sizeof(pthread_cond_t) * share->all_link_count), + &share->bg_mon_sleep_conds, + (uint) (sizeof(pthread_cond_t) * share->all_link_count), + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_afree(buf); + goto error_alloc_base; + } + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if ( + share->monitoring_bg_kind[roop_count] && + mysql_mutex_init(spd_key_mutex_bg_mon, + &share->bg_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_afree(buf); + goto error_mutex_init; + } + } + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if ( + share->monitoring_bg_kind[roop_count] && + mysql_cond_init(spd_key_cond_bg_mon, + &share->bg_mon_conds[roop_count], NULL) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_afree(buf); + goto error_cond_init; + } + } + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + if ( + share->monitoring_bg_kind[roop_count] && + mysql_cond_init(spd_key_cond_bg_mon_sleep, + &share->bg_mon_sleep_conds[roop_count], NULL) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_afree(buf); + goto error_sleep_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_thread_create(spd_key_thd_bg_mon, + &share->bg_mon_threads[roop_count], &spider_pt_attr, + spider_bg_mon_action, (void *) &link_pack) + ) + { + error_num = HA_ERR_OUT_OF_MEM; + my_afree(buf); + 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; + my_afree(buf); + } + } + 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_sleep_cond_init: + for (roop_count--; roop_count >= 0; roop_count--) + { + if (share->monitoring_bg_kind[roop_count]) + pthread_cond_destroy(&share->bg_mon_sleep_conds[roop_count]); + } + 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] && + share->bg_mon_thds[roop_count] + ) { + share->bg_mon_thds[roop_count]->killed = SPIDER_THD_KILL_CONNECTION; + } + } + 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_signal(&share->bg_mon_sleep_conds[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_cond_destroy(&share->bg_mon_sleep_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 = SPIDER_new_THD(next_thread_id()))) + { + 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); + } + SPIDER_set_next_thread_id(thd); +#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; + 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) + set_current_thd(nullptr); +#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) + { + struct timespec abstime; + set_timespec_nsec(abstime, + share->monitoring_bg_interval[link_idx] * 1000); + pthread_cond_timedwait(&share->bg_mon_sleep_conds[link_idx], + &share->bg_mon_mutexes[link_idx], &abstime); +/* + 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(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#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( + trx, + thd, + share, + link_idx, + (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], + share->monitoring_bg_flag[link_idx], + TRUE + ); + lex_end(thd->lex); + } + } +} + +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; + int *link_idxs, link_idx; + long *balances; + DBUG_ENTER("spider_conn_first_link_idx"); + char *ptr; + ptr = (char *) my_alloca((sizeof(int) * link_count) + (sizeof(long) * link_count)); + if (!ptr) + { + DBUG_PRINT("info",("spider out of memory")); + DBUG_RETURN(-2); + } + link_idxs = (int *) ptr; + ptr += sizeof(int) * link_count; + balances = (long *) ptr; + 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")); + my_afree(link_idxs); + DBUG_RETURN(-1); + } + DBUG_PRINT("info",("spider server_id=%lu", thd->variables.server_id)); + DBUG_PRINT("info",("spider thread_id=%lu", thd_get_thread_id(thd))); + rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); + 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])); + link_idx = link_idxs[roop_count]; + my_afree(link_idxs); + DBUG_RETURN(link_idx); +} + +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_get_link_status( + long *link_statuses, + uint *conn_link_idx, + int link_idx +) { + DBUG_ENTER("spider_conn_get_link_status"); + DBUG_PRINT("info",("spider link_status=%d", + (int) link_statuses[conn_link_idx[link_idx]])); + DBUG_RETURN((int) link_statuses[conn_link_idx[link_idx]]); +} + +int spider_conn_lock_mode( + ha_spider *spider +) { + SPIDER_WIDE_HANDLER *wide_handler = spider->wide_handler; + DBUG_ENTER("spider_conn_lock_mode"); + if (wide_handler->external_lock_type == F_WRLCK || + wide_handler->lock_mode == 2) + DBUG_RETURN(SPIDER_LOCK_MODE_EXCLUSIVE); + else if (wide_handler->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); +} + +SPIDER_CONN* spider_get_conn_from_idle_connection( + SPIDER_SHARE *share, + int link_idx, + char *conn_key, + ha_spider *spider, + uint conn_kind, + int base_link_idx, + int *error_num + ) +{ + DBUG_ENTER("spider_get_conn_from_idle_connection"); + SPIDER_IP_PORT_CONN *ip_port_conn; + SPIDER_CONN *conn = NULL; + uint spider_max_connections = spider_param_max_connections(); + struct timespec abstime; + ulonglong start, inter_val = 0; + longlong last_ntime = 0; + ulonglong wait_time = (ulonglong)spider_param_conn_wait_timeout()*1000*1000*1000; // default 10s + + unsigned long ip_port_count = 0; // init 0 + + set_timespec(abstime, 0); + + pthread_mutex_lock(&spider_ipport_conn_mutex); + if ((ip_port_conn = (SPIDER_IP_PORT_CONN*) my_hash_search_using_hash_value( + &spider_ipport_conns, share->conn_keys_hash_value[link_idx], + (uchar*) share->conn_keys[link_idx], share->conn_keys_lengths[link_idx]))) + { /* exists */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + pthread_mutex_lock(&ip_port_conn->mutex); + ip_port_count = ip_port_conn->ip_port_count; + } else { + pthread_mutex_unlock(&spider_ipport_conn_mutex); + } + + if ( + ip_port_conn && + ip_port_count >= spider_max_connections && + spider_max_connections > 0 + ) { /* no idle conn && enable connection pool, wait */ + pthread_mutex_unlock(&ip_port_conn->mutex); + start = my_hrtime().val; + while(1) + { + int error; + inter_val = my_hrtime().val - start; // us + last_ntime = wait_time - inter_val*1000; // *1000, to ns + if(last_ntime <= 0) + {/* wait timeout */ + *error_num = ER_SPIDER_CON_COUNT_ERROR; + DBUG_RETURN(NULL); + } + set_timespec_nsec(abstime, last_ntime); + pthread_mutex_lock(&ip_port_conn->mutex); + ++ip_port_conn->waiting_count; + error = pthread_cond_timedwait(&ip_port_conn->cond, &ip_port_conn->mutex, &abstime); + --ip_port_conn->waiting_count; + pthread_mutex_unlock(&ip_port_conn->mutex); + if (error == ETIMEDOUT || error == ETIME || error != 0 ) + { + *error_num = ER_SPIDER_CON_COUNT_ERROR; + DBUG_RETURN(NULL); + } + + pthread_mutex_lock(&spider_conn_mutex); + 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]))) + { + /* get conn from spider_open_connections, then delete conn in spider_open_connections */ + my_hash_delete(&spider_open_connections, (uchar*) conn); + 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; + } + DBUG_RETURN(conn); + } + else + { + pthread_mutex_unlock(&spider_conn_mutex); + } + } + } + else + { /* create conn */ + if (ip_port_conn) + pthread_mutex_unlock(&ip_port_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))) + DBUG_RETURN(conn); + *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; + } + } + + DBUG_RETURN(conn); +} + + +SPIDER_IP_PORT_CONN* spider_create_ipport_conn(SPIDER_CONN *conn) +{ + DBUG_ENTER("spider_create_ipport_conn"); + if (conn) + { + SPIDER_IP_PORT_CONN *ret = (SPIDER_IP_PORT_CONN *) + my_malloc(PSI_INSTRUMENT_ME, sizeof(*ret), MY_ZEROFILL | MY_WME); + if (!ret) + { + goto err_return_direct; + } + + if (mysql_mutex_init(spd_key_mutex_conn_i, &ret->mutex, MY_MUTEX_INIT_FAST)) + { + //error + goto err_malloc_key; + } + + if (mysql_cond_init(spd_key_cond_conn_i, &ret->cond, NULL)) + { + pthread_mutex_destroy(&ret->mutex); + goto err_malloc_key; + //error + } + + ret->key_len = conn->conn_key_length; + if (ret->key_len <= 0) { + pthread_cond_destroy(&ret->cond); + pthread_mutex_destroy(&ret->mutex); + goto err_malloc_key; + } + + ret->key = (char *) my_malloc(PSI_INSTRUMENT_ME, ret->key_len + + conn->tgt_host_length + 1, MY_ZEROFILL | MY_WME); + if (!ret->key) { + pthread_cond_destroy(&ret->cond); + pthread_mutex_destroy(&ret->mutex); + goto err_malloc_key; + } + ret->remote_ip_str = ret->key + ret->key_len; + + memcpy(ret->key, conn->conn_key, ret->key_len); + + memcpy(ret->remote_ip_str, conn->tgt_host, conn->tgt_host_length); + ret->remote_port = conn->tgt_port; + ret->conn_id = conn->conn_id; + ret->ip_port_count = 1; // init + + ret->key_hash_value = conn->conn_key_hash_value; + DBUG_RETURN(ret); +err_malloc_key: + spider_my_free(ret, MYF(0)); +err_return_direct: + DBUG_RETURN(NULL); + } + DBUG_RETURN(NULL); +} + + +void spider_free_ipport_conn(void *info) +{ + DBUG_ENTER("spider_free_ipport_conn"); + if (info) + { + SPIDER_IP_PORT_CONN *p = (SPIDER_IP_PORT_CONN *)info; + pthread_cond_destroy(&p->cond); + pthread_mutex_destroy(&p->mutex); + spider_my_free(p->key, MYF(0)); + spider_my_free(p, MYF(0)); + } + DBUG_VOID_RETURN; +} diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h new file mode 100644 index 00000000..807e1474 --- /dev/null +++ b/storage/spider/spd_conn.h @@ -0,0 +1,404 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define SPIDER_LOCK_MODE_NO_LOCK 0 +#define SPIDER_LOCK_MODE_SHARED 1 +#define SPIDER_LOCK_MODE_EXCLUSIVE 2 + +#define SPIDER_SIMPLE_NO_ACTION 0 +#define SPIDER_SIMPLE_CONNECT 1 +#define SPIDER_SIMPLE_DISCONNECT 2 +#define SPIDER_SIMPLE_RECORDS 3 +#define SPIDER_SIMPLE_CHECKSUM_TABLE 4 + +#define SPIDER_LOP_CHK_QUEUED (1 << 0) +#define SPIDER_LOP_CHK_MERAGED (1 << 1) +#define SPIDER_LOP_CHK_IGNORED (1 << 2) + +typedef struct st_spider_conn_loop_check +{ + uint flag; + my_hash_value_type hash_value_to; + my_hash_value_type hash_value_full; + LEX_CSTRING from_name; + LEX_CSTRING cur_name; + LEX_CSTRING to_name; + LEX_CSTRING full_name; + LEX_CSTRING from_value; + LEX_CSTRING merged_value; + st_spider_conn_loop_check *next; +} SPIDER_CONN_LOOP_CHECK; + +uchar *spider_conn_get_key( + SPIDER_CONN *conn, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +uchar *spider_ipport_conn_get_key( + SPIDER_IP_PORT_CONN *ip_port, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +int spider_conn_init( + SPIDER_CONN *conn +); + +void spider_conn_done( + SPIDER_CONN *conn +); + +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 +); + +int spider_check_and_get_casual_read_conn( + THD *thd, + ha_spider *spider, + int link_idx +); + +int spider_check_and_init_casual_read( + THD *thd, + ha_spider *spider, + int link_idx +); + +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_ping_rewrite( + 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_wait_timeout( + SPIDER_CONN *conn, + int wait_timeout +); + +void spider_conn_queue_sql_mode( + SPIDER_CONN *conn, + sql_mode_t sql_mode +); + +void spider_conn_queue_time_zone( + SPIDER_CONN *conn, + Time_zone *time_zone +); + +void spider_conn_queue_UTC_time_zone( + SPIDER_CONN *conn +); + +int spider_conn_queue_and_merge_loop_check( + SPIDER_CONN *conn, + SPIDER_CONN_LOOP_CHECK *lcptr +); + +int spider_conn_reset_queue_loop_check( + SPIDER_CONN *conn +); + +int spider_conn_queue_loop_check( + SPIDER_CONN *conn, + ha_spider *spider, + int link_idx +); + +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 +); + +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, + bool caller_wait, + void *target, + uint link_idx, + int *error_num +); + +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 +); + +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_get_link_status( + long *link_statuses, + uint *conn_link_idx, + int link_idx +); + +int spider_conn_lock_mode( + ha_spider *spider +); + +bool spider_conn_check_recovery_link( + SPIDER_SHARE *share +); + +SPIDER_IP_PORT_CONN *spider_create_ipport_conn(SPIDER_CONN *conn); +SPIDER_CONN* spider_get_conn_from_idle_connection +( + SPIDER_SHARE *share, + int link_idx, + char *conn_key, + ha_spider *spider, + uint conn_kind, + int base_link_idx, + int *error_num + ); +void spider_free_ipport_conn(void *info); diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc new file mode 100644 index 00000000..ab1f8d35 --- /dev/null +++ b/storage/spider/spd_copy_tables.cc @@ -0,0 +1,1220 @@ +/* Copyright (C) 2009-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_base.h" +#include "sql_partition.h" +#include "transaction.h" +#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 = SPIDER_THD_db_length(copy_tables->trx->thd); + if ( + !(copy_tables->database = spider_create_string( + SPIDER_THD_db_str(copy_tables->trx->thd), + 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_transaction == -1) + copy_tables->use_transaction = 1; + if (copy_tables->bg_mode == -1) + copy_tables->bg_mode = 0; + DBUG_RETURN(0); +} + +#define SPIDER_PARAM_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!copy_tables->param_name) \ + { \ + if ((copy_tables->param_name = spider_create_string(parse.start_value, \ + value_length))) \ + copy_tables->SPIDER_PARAM_LEN(param_name) = strlen(copy_tables->param_name); \ + else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider " title_name "=%s", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (copy_tables->param_name == -1) \ + { \ + copy_tables->param_name = atoi(parse.start_value); \ + 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; \ + DBUG_PRINT("info",("spider " title_name "=%d", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (copy_tables->param_name == -1) \ + { \ + copy_tables->param_name = atoi(parse.start_value); \ + if (copy_tables->param_name < min_val) \ + copy_tables->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%d", copy_tables->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (copy_tables->param_name == -1) \ + { \ + copy_tables->param_name = \ + my_strtoll10(parse.start_value, (char**) NULL, &error_num); \ + if (copy_tables->param_name < min_val) \ + copy_tables->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%lld", \ + copy_tables->param_name)); \ + } \ + break; \ + } + +static void spider_minus_1(SPIDER_COPY_TABLES *copy_tables) +{ + copy_tables->bulk_insert_interval = -1; + copy_tables->bulk_insert_rows = -1; + copy_tables->use_table_charset = -1; + copy_tables->use_transaction = -1; + copy_tables->bg_mode = -1; +} + +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 *start_param; + int title_length, value_length; + SPIDER_PARAM_STRING_PARSE parse; + DBUG_ENTER("spider_udf_parse_copy_tables_param"); + spider_minus_1(copy_tables); + 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)); + + start_param = param_string; + parse.error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + while (*start_param != '\0') + { + if (parse.locate_param_def(start_param)) + { + error_num= parse.fail(false); + goto error; + } + /* Null the end of the parameter value. */ + *parse.end_value= '\0'; + value_length= (int) (parse.end_value - parse.start_value); + + switch (title_length = (int) (parse.end_title - parse.start_title)) + { + case 0: + error_num= parse.fail(true); + goto error; + case 3: + SPIDER_PARAM_INT_WITH_MAX("bgm", bg_mode, 0, 1); + 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= parse.fail(true); + goto error; + case 7: + SPIDER_PARAM_INT_WITH_MAX("bg_mode", bg_mode, 0, 1); + error_num= parse.fail(true); + goto error; + case 8: + SPIDER_PARAM_STR("database", database); + error_num= parse.fail(true); + goto error; + case 15: + SPIDER_PARAM_INT_WITH_MAX("use_transaction", use_transaction, 0, 1); + error_num= parse.fail(true); + goto error; + case 16: + SPIDER_PARAM_LONGLONG("bulk_insert_rows", bulk_insert_rows, 1); + error_num= parse.fail(true); + goto error; + case 17: + SPIDER_PARAM_INT_WITH_MAX( + "use_table_charset", use_table_charset, 0, 1); + error_num= parse.fail(true); + goto error; + case 20: + SPIDER_PARAM_INT("bulk_insert_interval", bulk_insert_interval, 0); + error_num= parse.fail(true); + goto error; + default: + error_num= parse.fail(true); + goto error; + } + /* Restore delim */ + *parse.end_value= parse.delim_value; + } + +set_default: + error_num = spider_udf_set_copy_tables_param_default(copy_tables); +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; + SPIDER_Open_tables_backup open_tables_backup; + 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, (uint) (sizeof(SPIDER_COPY_TABLE_CONN)), + &tmp_share, (uint) (sizeof(SPIDER_SHARE)), + &tmp_connect_info, + (uint) (sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT), + &tmp_connect_info_length, + (uint) (sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT), + &tmp_long, (uint) (sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT), + &tmp_longlong, + (uint) (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, + NULL, + NULL, + 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], + (uint) (sizeof(int) * copy_tables->link_idx_count[0]), + ©_tables->link_idxs[1], + (uint) (sizeof(int) * copy_tables->link_idx_count[1]), + &tmp_name_ptr, (uint) (sizeof(char) * ( + spider_table_name_length * 2 + copy_tables->database_length + 3 + )), + 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); +} + +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); +} + +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_WIDE_HANDLER *wide_handler; + spider_db_copy_table *select_ct, *insert_ct; + MEM_ROOT mem_root; + longlong bulk_insert_rows; + Reprepare_observer *reprepare_observer_backup; + uint tmp_conn_link_idx = 0; + DBUG_ENTER("spider_copy_tables_body"); + if ( + thd->open_tables != 0 || + thd->handler_tables_hash.records != 0 || + thd->derived_tables != 0 || + thd->lock != 0 || + thd->locked_tables_list.locked_tables() || + thd->locked_tables_mode != LTM_NONE + ) { + 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); + } 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); + } + goto error; + } + + if (!(copy_tables = (SPIDER_COPY_TABLES *) + spider_bulk_malloc(spider_current_trx, 27, MYF(MY_WME | MY_ZEROFILL), + ©_tables, (uint) (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; + SPIDER_TABLE_LIST_db_str(table_list) = copy_tables->spider_db_name; + SPIDER_TABLE_LIST_db_length(table_list) = copy_tables->spider_db_name_length; + SPIDER_TABLE_LIST_alias_str(table_list) = + SPIDER_TABLE_LIST_table_name_str(table_list) = + copy_tables->spider_real_table_name; + SPIDER_TABLE_LIST_table_name_length(table_list) = + copy_tables->spider_real_table_name_length; +#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias + SPIDER_TABLE_LIST_alias_length(table_list) = + SPIDER_TABLE_LIST_table_name_length(table_list); +#endif + table_list->lock_type = TL_READ; + + DBUG_PRINT("info",("spider db=%s", SPIDER_TABLE_LIST_db_str(table_list))); + DBUG_PRINT("info",("spider db_length=%zd", SPIDER_TABLE_LIST_db_length(table_list))); + DBUG_PRINT("info",("spider table_name=%s", + SPIDER_TABLE_LIST_table_name_str(table_list))); + DBUG_PRINT("info",("spider table_name_length=%zd", + SPIDER_TABLE_LIST_table_name_length(table_list))); + reprepare_observer_backup = thd->m_reprepare_observer; + thd->m_reprepare_observer = NULL; + copy_tables->trx->trx_start = TRUE; + copy_tables->trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); + + MDL_REQUEST_INIT(&table_list->mdl_request, + MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(table_list), + SPIDER_TABLE_LIST_table_name_str(table_list), + MDL_SHARED_READ, + MDL_TRANSACTION + ); + if (open_and_lock_tables(thd, table_list, FALSE, 0)) + { + thd->m_reprepare_observer = reprepare_observer_backup; + copy_tables->trx->trx_start = FALSE; + copy_tables->trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); + my_printf_error(ER_SPIDER_UDF_CANT_OPEN_TABLE_NUM, + ER_SPIDER_UDF_CANT_OPEN_TABLE_STR, MYF(0), + SPIDER_TABLE_LIST_db_str(table_list), + SPIDER_TABLE_LIST_table_name_str(table_list)); + goto error; + } + thd->m_reprepare_observer = reprepare_observer_backup; + copy_tables->trx->trx_start = FALSE; + copy_tables->trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); + + 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), + SPIDER_TABLE_LIST_db_str(table_list), + SPIDER_TABLE_LIST_table_name_str(table_list)); + 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; + + bulk_insert_rows= copy_tables->bulk_insert_rows; + for (src_tbl_conn = copy_tables->table_conn[0]; src_tbl_conn; + src_tbl_conn = src_tbl_conn->next) + { + 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(); + + 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; + } + + 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; + } + } + + 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; + spider[roop_count].change_table_ptr(table, table_share); + } + 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, + &wide_handler, sizeof(SPIDER_WIDE_HANDLER), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + tmp_spider->share = table_conn->share; + tmp_spider->wide_handler = wide_handler; + wide_handler->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->wide_handler->lock_type = TL_READ; + tmp_spider->conn_link_idx = &tmp_conn_link_idx; + 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, + &wide_handler, sizeof(SPIDER_WIDE_HANDLER), + NullS)) + ) { + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + tmp_spider->share = table_conn->share; + tmp_spider->wide_handler = wide_handler; + wide_handler->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->wide_handler->lock_type = TL_WRITE; + tmp_spider->conn_link_idx = &tmp_conn_link_idx; + 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 ((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) + { + (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); + 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) + { + (thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd)); + 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_copy_table_free_trx_conn(trx); + DBUG_VOID_RETURN; +} diff --git a/storage/spider/spd_copy_tables.h b/storage/spider/spd_copy_tables.h new file mode 100644 index 00000000..4f7ba779 --- /dev/null +++ b/storage/spider/spd_copy_tables.h @@ -0,0 +1,53 @@ +/* Copyright (C) 2010-2014 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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 +); + +int spider_udf_bg_copy_exec_sql( + SPIDER_COPY_TABLE_CONN *table_conn +); diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc new file mode 100644 index 00000000..a541a5db --- /dev/null +++ b/storage/spider/spd_db_conn.cc @@ -0,0 +1,9856 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019, 2022, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#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" +#include "errmsg.h" +#include "sql_select.h" +#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_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) + +extern HASH spider_open_connections; +pthread_mutex_t spider_open_conn_mutex; +const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +/* UTC time zone for timestamp columns */ +Time_zone *UTC = 0; + +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)); + DBUG_PRINT("info",("spider conn=%p", conn)); + + if (conn->connect_error) + { + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_PRINT("info",("spider diff=%f", + difftime(tmp_time, conn->connect_error_time))); + if ( + ( + conn->thd && + conn->thd == conn->connect_error_thd && + conn->thd->query_id == conn->connect_error_query_id + ) || + ( + difftime(tmp_time, conn->connect_error_time) < + spider_param_connect_error_interval() + ) + ) { + DBUG_PRINT("info",("spider set same error")); + if (conn->connect_error_with_message) + my_message(conn->connect_error, conn->connect_error_msg, MYF(0)); + DBUG_RETURN(conn->connect_error); + } + } + + 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); + if (conn->disable_connect_retry) + connect_retry_count = 0; + else + 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 ((error_num = spider_reset_conn_setted_parameter(conn, thd))) + DBUG_RETURN(error_num); + + if (conn->dbton_id == SPIDER_DBTON_SIZE) + { + 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 ((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))) + { + if (conn->thd) + { + conn->connect_error_thd = conn->thd; + conn->connect_error_query_id = conn->thd->query_id; + conn->connect_error_time = (time_t) time((time_t*) 0); + conn->connect_error = error_num; + if ((conn->connect_error_with_message = thd->is_error())) + strmov(conn->connect_error_msg, spider_stmt_da_message(thd)); + } + DBUG_RETURN(error_num); + } + + conn->connect_error = 0; + conn->opened_handlers = 0; + ++conn->connection_id; + + /* Set the connection's time zone to UTC */ + spider_conn_queue_UTC_time_zone(conn); + DBUG_RETURN(0); +} + +int spider_db_ping_internal( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int all_link_idx, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_db_ping_internal"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if (conn->server_lost || conn->queued_connect) + { + if ((error_num = spider_db_connect(share, conn, all_link_idx))) + { + pthread_mutex_assert_owner(&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(share, conn, all_link_idx))) + { + DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); + conn->server_lost = TRUE; + pthread_mutex_assert_owner(&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; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + } + conn->ping_time = (time_t) time((time_t*) 0); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_RETURN(0); +} + +int spider_db_ping( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + DBUG_ENTER("spider_db_ping"); +#ifndef DBUG_OFF + if (spider->wide_handler->trx->thd) + DBUG_PRINT("info", ("spider thd->query_id is %lld", + spider->wide_handler->trx->thd->query_id)); +#endif + DBUG_RETURN(spider_db_ping_internal(spider->share, conn, + spider->conn_link_idx[link_idx], &spider->need_mons[link_idx])); +} + +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; + } + + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + 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_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout && + conn->db_conn->set_wait_timeout_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_wait_timeout(&sql_str, conn->queued_wait_timeout_val)) + ) || + ( + conn->queued_sql_mode && + conn->queued_sql_mode_val != conn->sql_mode && + conn->db_conn->set_sql_mode_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_sql_mode(&sql_str, conn->queued_sql_mode_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->loop_check_queue.records && + conn->db_conn->set_loop_check_in_bulk_sql() && + (error_num = spider_dbton[conn->dbton_id].db_util-> + append_loop_check(&sql_str, conn)) + ) || + ( + 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 = conn->db_conn-> + set_autocommit(conn->queued_autocommit_val, (int *) conn->need_mon)) + ) { + 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 = conn->db_conn-> + set_sql_log_off(conn->queued_sql_log_off_val, (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout && + !conn->db_conn->set_wait_timeout_in_bulk_sql() && + (error_num = conn->db_conn-> + set_wait_timeout(conn->queued_wait_timeout_val, + (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->queued_sql_mode && + conn->queued_sql_mode_val != conn->sql_mode && + !conn->db_conn->set_sql_mode_in_bulk_sql() && + (error_num = conn->db_conn-> + set_sql_mode(conn->queued_sql_mode_val, + (int *) conn->need_mon)) + ) { + 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 = conn->db_conn-> + set_time_zone(conn->queued_time_zone_val, + (int *) conn->need_mon)) + ) { + DBUG_RETURN(error_num); + } + if ( + conn->loop_check_queue.records && + !conn->db_conn->set_loop_check_in_bulk_sql() && + (error_num = conn->db_conn->set_loop_check((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->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_wait_timeout && + conn->queued_wait_timeout_val != conn->wait_timeout + ) { + conn->wait_timeout = conn->queued_wait_timeout_val; + } + + if ( + conn->queued_sql_mode && + conn->queued_sql_mode_val != conn->sql_mode + ) { + conn->sql_mode = conn->queued_sql_mode_val; + } + + 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)); + } + + if (conn->loop_check_queue.records) + { + conn->db_conn->fin_loop_check(); + } + spider_conn_clear_queue(conn); + 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); + if (conn->bg_search) + spider_bg_conn_break(conn, NULL); + conn->in_before_query = TRUE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ((error_num = spider_db_conn_queue_action(conn))) + { + conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + if (conn->server_lost) + { + conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + 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; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + 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; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + 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"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + 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); +} + +int spider_db_errorno( + SPIDER_CONN *conn +) { + int error_num; + DBUG_ENTER("spider_db_errorno"); + DBUG_ASSERT(conn->need_mon); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + if (conn->server_lost) + { + *conn->need_mon = ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM; + if (!current_thd->is_error()) + { + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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, SPIDER_WARN_LEVEL_WARN, + error_num, conn->db_conn->get_error()); + if (spider_param_log_result_errors() >= 3) + { + 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 [WARN SPIDER RESULT] " + "to %lld: %d %s\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, + (long long int) current_thd->thread_id, error_num, + conn->db_conn->get_error()); + } + if (!conn->mta_conn_mutex_unlock_later) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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 (spider_param_log_result_errors() >= 1) + { + 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 SPIDER RESULT] " + "to %lld: %d %s\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, + (long long int) current_thd->thread_id, error_num, + conn->db_conn->get_error()); + } + if (!conn->mta_conn_mutex_unlock_later) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + if (!conn->mta_conn_mutex_unlock_later) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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 +) { + DBUG_ENTER("spider_db_set_names_internal"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + if ( + !conn->access_charset || + share->access_charset->cset != conn->access_charset->cset + ) { + if ( + spider_db_before_query(conn, need_mon) || + conn->db_conn->set_character_set(share->access_charset->cs_name.str) + ) { + DBUG_RETURN(spider_db_errorno(conn)); + } + conn->access_charset = share->access_charset; + } + if ( + spider_param_use_default_database(trx->thd) && + share->tgt_dbs[all_link_idx] && + ( + !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])); + if ( + spider_db_before_query(conn, need_mon) || + conn->db_conn->select_db(share->tgt_dbs[all_link_idx]) + ) { + 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]); + } + 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->wide_handler->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_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + if ((error_num = spider_db_set_names(spider, conn, link_idx))) + { + if ( + share->monitoring_kind[link_idx] && + spider->need_mons[link_idx] + ) { + error_num = spider_ping_table_mon_from_table( + spider->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + link_idx, + (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], + share->monitoring_flag[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->trx->thd, + share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[link_idx]) + ) { + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + link_idx, + (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], + share->monitoring_flag[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_query_for_bulk_update( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx, + ha_rows *dup_key_found +) { + int error_num; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_db_query_for_bulk_update"); + + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + link_idx, + (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], + share->monitoring_flag[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + link_idx, + (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], + share->monitoring_flag[link_idx], + TRUE + ); + } + if ( + spider->wide_handler->ignore_dup_key && + ( + error_num == ER_DUP_ENTRY || + error_num == ER_DUP_KEY || + error_num == HA_ERR_FOUND_DUPP_KEY + ) + ) { + ++(*dup_key_found); + spider->wide_handler->trx->thd->clear_error(); + 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)) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + link_idx, + (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], + share->monitoring_flag[link_idx], + TRUE + ); + } + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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, "%lu", 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, + const char *name, + uint dbton_id +) { + DBUG_ENTER("spider_db_append_name_with_quote_str"); + DBUG_RETURN(spider_db_append_name_with_quote_str_internal( + str, name, strlen(name), system_charset_info, dbton_id)); +} + +int spider_db_append_name_with_quote_str( + spider_string *str, + LEX_CSTRING &name, + uint dbton_id +) { + DBUG_ENTER("spider_db_append_name_with_quote_str"); + DBUG_RETURN(spider_db_append_name_with_quote_str_internal( + str, name.str, name.length, system_charset_info, dbton_id)); +} + +int spider_db_append_name_with_quote_str_internal( + spider_string *str, + const char *name, + int length, + uint dbton_id +) { + DBUG_ENTER("spider_db_append_name_with_quote_str_internal"); + DBUG_RETURN(spider_db_append_name_with_quote_str_internal( + str, name, length, system_charset_info, dbton_id)); +} + +int spider_db_append_name_with_quote_str_internal( + spider_string *str, + const char *name, + int length, + CHARSET_INFO *cs, + uint dbton_id +) { + int error_num; + const char *name_end; + char head_code; + DBUG_ENTER("spider_db_append_name_with_quote_str_internal"); + for (name_end = name + length; name < name_end; name += length) + { + head_code = *name; + if ((length = my_ci_charlen(cs, (const uchar *) name, (const uchar *) name_end)) < 1) + { + 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, cs)) + 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 ((error_num = spider->append_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + 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 ( + result_list->direct_aggregate && + (error_num = spider->append_sum_select_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL, NULL, 0)) + ) + DBUG_RETURN(error_num); + 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); + } + } + 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(spider_user_defined_key_parts(key_info)); + 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 spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + 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_INDEX_FORCE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + hint_str += 2; + str->q_append(SPIDER_SQL_INDEX_FORCE_STR, SPIDER_SQL_INDEX_FORCE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_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_INDEX_USE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + hint_str += 2; + str->q_append(SPIDER_SQL_INDEX_USE_STR, SPIDER_SQL_INDEX_USE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_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_INDEX_IGNORE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + hint_str += 3; + str->q_append(SPIDER_SQL_INDEX_IGNORE_STR, SPIDER_SQL_INDEX_IGNORE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_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 (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 (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; + uint current_pos = str->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; + 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"); + + if (key_info) + full_key_part_map = + make_prev_keypart_map(spider_user_defined_key_parts(key_info)); + 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; + result_list->end_key = end_key; + } else { + end_key_part_map = 0; + use_both = FALSE; + } + DBUG_PRINT("info", ("spider spider_user_defined_key_parts=%u", key_info ? + spider_user_defined_key_parts(key_info) : 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 *tmp_map = dbug_tmp_use_all_columns(table, &table->read_set); +#endif + + if (!start_key_part_map && !end_key_part_map) + { + result_list->key_order = 0; + goto end; + } else if (use_both && (!start_key_part_map || !end_key_part_map)) + { + result_list->key_order = 0; + 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 (start_key_part_map == end_key_part_map) + result_list->use_both_key = TRUE; + + { + 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 ( + 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++ + ) { + DBUG_PRINT("info", ("spider tgt_key_part_map=%lu", tgt_key_part_map)); + bool rev = key_part->key_part_flag & HA_REVERSE_SORT; + 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) + ) { + bool tgt_final = (use_key == start_key && + (tgt_key_part_map == 1 || !end_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, tgt_final)) + ) { + if (error_num > 0) + DBUG_RETURN(error_num); + if (!set_order && start_key->flag != HA_READ_KEY_EXACT) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (key_eq) + { + DBUG_PRINT("info", ("spider key_eq")); + { + 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, FALSE, share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } else { + DBUG_PRINT("info", ("spider start_key->flag=%d", start_key->flag)); + const char *op_str; + uint32 op_len; + switch (start_key->flag) + { + case HA_READ_PREFIX_LAST: + result_list->desc_flg = TRUE; + /* fall through */ + case HA_READ_KEY_EXACT: { + 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); + + bool is_like= MY_TEST(key_part->key_part_flag & HA_PART_KEY_SEG); + if (is_like) + { + if (str->append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + else + { + if (str->append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (spider_dbton[dbton_id].db_util->append_column_value( + spider, str, field, ptr, is_like, share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + break; + } + case HA_READ_AFTER_KEY: + if (start_key_part_map == 1) + { + op_str= rev ? SPIDER_SQL_LT_STR : SPIDER_SQL_GT_STR; + op_len= rev ? SPIDER_SQL_LT_LEN : SPIDER_SQL_GT_LEN; + } + else + { + op_str= rev ? SPIDER_SQL_LTEQUAL_STR : SPIDER_SQL_GTEQUAL_STR; + op_len= rev ? SPIDER_SQL_LTEQUAL_LEN : SPIDER_SQL_GTEQUAL_LEN; + } + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(op_str, op_len); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, false, + 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; + } + break; + case HA_READ_BEFORE_KEY: + result_list->desc_flg = TRUE; + if (start_key_part_map == 1) + { + op_str= rev ? SPIDER_SQL_GT_STR : SPIDER_SQL_LT_STR; + op_len= rev ? SPIDER_SQL_GT_LEN : SPIDER_SQL_LT_LEN; + } + else + { + op_str= rev ? SPIDER_SQL_GTEQUAL_STR : SPIDER_SQL_LTEQUAL_STR; + op_len= rev ? SPIDER_SQL_GTEQUAL_LEN : SPIDER_SQL_LTEQUAL_LEN; + } + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(op_str, op_len); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, false, + 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; + } + break; + case HA_READ_KEY_OR_PREV: + case HA_READ_PREFIX_LAST_OR_PREV: + result_list->desc_flg = TRUE; + 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); + if (rev) + str->q_append(SPIDER_SQL_GTEQUAL_STR, SPIDER_SQL_GTEQUAL_LEN); + else + 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, false, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order= key_count; + set_order= TRUE; + } + 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, FALSE, 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, FALSE, 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, FALSE, 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, FALSE, 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, FALSE, 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 (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); + if (rev) + str->q_append(SPIDER_SQL_LTEQUAL_STR, SPIDER_SQL_LTEQUAL_LEN); + else + 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, false, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order= key_count; + set_order= TRUE; + } + break; + } + } + 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 ( + (key_eq && use_key == end_key) || + (!key_eq && end_key_part_map) + ) { + bool tgt_final = (use_key == end_key && tgt_key_part_map == 1); + ptr = end_key->key + length; + if ((error_num = dbton_hdl->append_is_null_part(sql_type, key_part, + end_key, &ptr, key_eq, tgt_final))) + { + if (error_num > 0) + DBUG_RETURN(error_num); + if (!set_order && end_key->flag != HA_READ_KEY_EXACT) + { + result_list->key_order = key_count; + set_order = TRUE; + } + } else if (key_eq) + { + DBUG_PRINT("info", ("spider key_eq")); + 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, false, + 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: + const char *op_str; + uint32 op_len; + if (end_key_part_map == 1) + { + op_str= rev ? SPIDER_SQL_GT_STR : SPIDER_SQL_LT_STR; + op_len= rev ? SPIDER_SQL_GT_LEN : SPIDER_SQL_LT_LEN; + } + else + { + op_str= rev ? SPIDER_SQL_GTEQUAL_STR : SPIDER_SQL_LTEQUAL_STR; + op_len= rev ? SPIDER_SQL_GTEQUAL_LEN : SPIDER_SQL_LTEQUAL_LEN; + } + if (str->reserve(store_length + key_name_length + + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dbton_share->append_column_name(str, field->field_index); + str->q_append(op_str, op_len); + if (spider_dbton[dbton_id].db_util-> + append_column_value(spider, str, field, ptr, false, + 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; + } + break; + default: + 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); + if (rev) + str->q_append(SPIDER_SQL_GTEQUAL_STR, SPIDER_SQL_GTEQUAL_LEN); + else + 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, false, + share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!set_order) + { + result_list->key_order= key_count; + set_order= TRUE; + } + break; + } + } + { + 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 (use_both && (!start_key_part_map || !end_key_part_map)) + break; + } + if ((error_num = dbton_hdl->append_where_terminator_part(sql_type, + set_order, key_count))) + DBUG_RETURN(error_num); + +end: + if (spider->multi_range_num && current_pos == str->length()) + { + DBUG_PRINT("info", ("spider no key where condition")); + dbton_hdl->no_where_cond = TRUE; + } + /* use condition */ + if (dbton_hdl->append_condition_part(NULL, 0, sql_type, FALSE)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + { + 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"); + { + 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); + } + DBUG_RETURN(0); +} + +int spider_db_append_charset_name_before_string( + spider_string *str, + CHARSET_INFO *cs +) { + const char *csname = cs->cs_name.str; + uint csname_length = cs->cs_name.length; + DBUG_ENTER("spider_db_append_charset_name_before_string"); + if (str->reserve(SPIDER_SQL_UNDERSCORE_LEN + csname_length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_UNDERSCORE_STR, SPIDER_SQL_UNDERSCORE_LEN); + str->q_append(csname, csname_length); + DBUG_RETURN(0); +} + +int spider_db_refetch_for_item_sum_funcs( + ha_spider *spider +) { + int error_num; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + DBUG_ENTER("spider_db_refetch_for_item_sum_funcs"); + if (result_list->snap_direct_aggregate) + { + SPIDER_DB_ROW *row = result_list->snap_row; + row->first(); + if (result_list->snap_mrr_with_cnt) + { + row->next(); + } + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +/** + Directly add field values in a row to aggregate items. + + Iterate over the result row fields and aggregate items, and call + direct_add on the latter with the values from the former. + + @param row The result row + @param spider The spider handler + @retval 0 Success + @retval nonzero Failure +*/ +int spider_db_fetch_for_item_sum_funcs( + SPIDER_DB_ROW *row, + ha_spider *spider +) { + int error_num; + st_select_lex *select_lex; + DBUG_ENTER("spider_db_fetch_for_item_sum_funcs"); + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + Item_sum **item_sum_ptr; + spider->direct_aggregate_item_current = NULL; + for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr) + { + if ((error_num = spider_db_fetch_for_item_sum_func(row, *item_sum_ptr, + spider))) + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +/** + Directly add one field of a row to an item for direct aggregate. + + Call direct_add on an Item_sum with the value stored in a field. + + @param row A row whose `row` points to the field to be added + @param item_sum The Item_sum to be added the field + @param ha_spider The spider handler + @retval 0 Success + @retval nonzero Failure +*/ +int spider_db_fetch_for_item_sum_func( + SPIDER_DB_ROW *row, + Item_sum *item_sum, + ha_spider *spider +) { + int error_num; + SPIDER_SHARE *share = spider->share; + THD *thd = spider->wide_handler->trx->thd; + DBUG_ENTER("spider_db_fetch_for_item_sum_func"); + DBUG_PRINT("info",("spider Sumfunctype = %d", item_sum->sum_func())); + switch (item_sum->sum_func()) + { + case Item_sum::COUNT_FUNC: + { + Item_sum_count *item_sum_count = (Item_sum_count *) item_sum; + if (!row->is_null()) + item_sum_count->direct_add(row->val_int()); + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + break; + case Item_sum::SUM_FUNC: + { + Item_sum_sum *item_sum_sum = (Item_sum_sum *) item_sum; + if (item_sum_sum->result_type() == DECIMAL_RESULT) + { + my_decimal decimal_value; + item_sum_sum->direct_add(row->val_decimal(&decimal_value, + share->access_charset)); + } else { + item_sum_sum->direct_add(row->val_real(), row->is_null()); + } + row->next(); + } + break; + case Item_sum::MIN_FUNC: + case Item_sum::MAX_FUNC: + { + if (!spider->direct_aggregate_item_current) + { + if (!spider->direct_aggregate_item_first) + { + if (!spider_bulk_malloc(spider_current_trx, 240, MYF(MY_WME), + &spider->direct_aggregate_item_first, + (uint) (sizeof(SPIDER_ITEM_HLD)), + NullS) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider->direct_aggregate_item_first->next = NULL; + spider->direct_aggregate_item_first->item = NULL; + spider->direct_aggregate_item_first->tgt_num = 0; + spider->direct_aggregate_item_first->init_mem_root = FALSE; + } + spider->direct_aggregate_item_current = + spider->direct_aggregate_item_first; + } else { + if (!spider->direct_aggregate_item_current->next) + { + if (!spider_bulk_malloc(spider_current_trx, 241, MYF(MY_WME), + &spider->direct_aggregate_item_current->next, + (uint) (sizeof(SPIDER_ITEM_HLD)), NullS) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider->direct_aggregate_item_current->next->next = NULL; + spider->direct_aggregate_item_current->next->item = NULL; + spider->direct_aggregate_item_current->next->tgt_num = + spider->direct_aggregate_item_current->tgt_num + 1; + spider->direct_aggregate_item_current->next->init_mem_root = FALSE; + } + spider->direct_aggregate_item_current = + spider->direct_aggregate_item_current->next; + } + if (!spider->direct_aggregate_item_current->item) + { + if (!spider->direct_aggregate_item_current->init_mem_root) + { + SPD_INIT_ALLOC_ROOT( + &spider->direct_aggregate_item_current->mem_root, + 4096, 0, MYF(MY_WME)); + spider->direct_aggregate_item_current->init_mem_root = TRUE; + } + Item *free_list = thd->free_list; + spider->direct_aggregate_item_current->item = + new (&spider->direct_aggregate_item_current->mem_root) + Item_string(thd, "", 0, share->access_charset); + if (!spider->direct_aggregate_item_current->item) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + thd->free_list = free_list; + } + + Item_sum_min_max *item_sum_min_max = (Item_sum_min_max *) item_sum; + Item_string *item = + (Item_string *) spider->direct_aggregate_item_current->item; + if (row->is_null()) + { + item->val_str(NULL)->length(0); + item->append(NULL, 0); + item->null_value = TRUE; + } else { + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, share->access_charset); + tmp_str.init_calc_mem(242); + tmp_str.length(0); + if ((error_num = row->append_to_str(&tmp_str))) + DBUG_RETURN(error_num); + item->val_str(NULL)->length(0); + item->append((char *) tmp_str.ptr(), tmp_str.length()); + item->null_value = FALSE; + } + item_sum_min_max->direct_add(item); + row->next(); + } + break; + case Item_sum::COUNT_DISTINCT_FUNC: + case Item_sum::SUM_DISTINCT_FUNC: + case Item_sum::AVG_FUNC: + case Item_sum::AVG_DISTINCT_FUNC: + case Item_sum::STD_FUNC: + case Item_sum::VARIANCE_FUNC: + case Item_sum::SUM_BIT_FUNC: + case Item_sum::UDF_SUM_FUNC: + case Item_sum::GROUP_CONCAT_FUNC: + default: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + spider->wide_handler->trx->direct_aggregate_count++; + 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_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 ( + (error_num = current->result_tmp_tbl->file->ha_rnd_next( + current->result_tmp_tbl->record[0])) + ) { + 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 ( + (error_num = tmp_tbl->file->ha_rnd_pos(tmp_tbl->record[0], + (uchar *) &pos->tmp_tbl_pos)) + ) { + 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; + THD *thd = field->table->in_use; + Time_zone *saved_time_zone = thd->variables.time_zone; + DBUG_ENTER("spider_db_fetch_row"); + DBUG_PRINT("info", ("spider field_name %s", SPIDER_field_name_str(field))); + DBUG_PRINT("info", ("spider fieldcharset %s", field->charset()->cs_name.str)); + + thd->variables.time_zone = UTC; + + field->move_field_offset(ptr_diff); + error_num = row->store_to_field(field, share->access_charset); + field->move_field_offset(-ptr_diff); + + thd->variables.time_zone = saved_time_zone; + + 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 (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) + { + if (!current->first_position) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + 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); + } + } + } + + DBUG_PRINT("info", ("spider row=%p", row)); + DBUG_PRINT("info", ("spider direct_aggregate=%s", + result_list->direct_aggregate ? "TRUE" : "FALSE")); + result_list->snap_mrr_with_cnt = spider->mrr_with_cnt; + result_list->snap_direct_aggregate = result_list->direct_aggregate; + result_list->snap_row = row; + + /* 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 if (result_list->direct_aggregate) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + } + + /* for direct_aggregate */ + if (result_list->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + if (!spider->use_fields) + { + 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++ + ) { + if (( + bitmap_is_set(table->read_set, (*field)->field_index) | + bitmap_is_set(table->write_set, (*field)->field_index) + )) { +#ifndef DBUG_OFF + MY_BITMAP *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(*field))); + 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 + } else { + DBUG_PRINT("info", ("spider bitmap is not set %s", + SPIDER_field_name_str(*field))); + } + row->next(); + } + 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) + { + if (!current->first_position) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + 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); + } + } + } + + DBUG_PRINT("info", ("spider row=%p", row)); + DBUG_PRINT("info", ("spider direct_aggregate=%s", + result_list->direct_aggregate ? "TRUE" : "FALSE")); + result_list->snap_mrr_with_cnt = spider->mrr_with_cnt; + result_list->snap_direct_aggregate = result_list->direct_aggregate; + result_list->snap_row = row; + + /* 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 if (result_list->direct_aggregate) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + + /* for direct_aggregate */ + if (result_list->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + 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 < spider_user_defined_key_parts(key_info); + 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 *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(field))); + 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; + spider_db_handler *dbton_hdl; + 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) + { + DBUG_PRINT("info", ("spider current=%p", current)); + DBUG_PRINT("info", ("spider first_position=%p", current->first_position)); + if (!current->first_position) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + DBUG_PRINT("info", ("spider current_row_num=%lld", result_list->current_row_num)); + DBUG_PRINT("info", ("spider first_position[]=%p", ¤t->first_position[result_list->current_row_num])); + 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); + } + } + } + + DBUG_PRINT("info", ("spider row=%p", row)); + DBUG_PRINT("info", ("spider direct_aggregate=%s", + result_list->direct_aggregate ? "TRUE" : "FALSE")); + result_list->snap_mrr_with_cnt = spider->mrr_with_cnt; + result_list->snap_direct_aggregate = result_list->direct_aggregate; + result_list->snap_row = row; + + /* 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 if (result_list->direct_aggregate) + { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + else + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + row->next(); + } + + /* for direct_aggregate */ + if (result_list->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + if ((error_num = spider_db_append_match_fetch(spider, + spider->ft_first, spider->ft_current, row))) + DBUG_RETURN(error_num); + + dbton_hdl = spider->dbton_handler[row->dbton_id]; + 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->wide_handler->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 (dbton_hdl->minimum_select_bit_is_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 *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(*field))); + 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 (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->tmp_tbl_use_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; + } + } + 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; + } + } + if (result_list->quick_mode == 3) + { + if (!result->first_pos_use_position) + { + spider_free(spider_current_trx, position, MYF(0)); + result->first_position = NULL; + } + if (result->result) + { + result->result->free_result(); + if (!result->tmp_tbl_use_position) + { + delete result->result; + result->result = NULL; + } + } + if (!result->tmp_tbl_use_position) + { + 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; + } + } + } + } + } + DBUG_VOID_RETURN; +} + +void spider_db_free_one_quick_result( + SPIDER_RESULT *result +) { + DBUG_ENTER("spider_db_free_one_quick_result"); + if (result && result->result) + { + result->result->free_result(); + if (!result->result_tmp_tbl) + { + delete result->result; + result->result = 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->wide_handler->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 ( + 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)) + { + 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->first_pos_use_position = FALSE; + result->tmp_tbl_use_position = 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; + result_list->bgs_phase = 0; + 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"); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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 ( + result_list->bgs_phase > 0 || + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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 ( + result_list->bgs_phase == 1 || + result_list->quick_phase == 2 + ) { + if (result_list->low_mem_read && + result_list->current->result->limit_mode() == 0) + { + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + DBUG_RETURN(error_num); + } + bool call_db_errorno = FALSE; + if (error_num != HA_ERR_END_OF_FILE) + { + call_db_errorno = TRUE; + if ((error_num = spider_db_errorno(conn))) + DBUG_RETURN(error_num); + } + 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; + if (result_list->bgs_phase <= 1) + { + result_list->current_row_num = 0; + table->status = STATUS_NOT_FOUND; + } + if (!conn->mta_conn_mutex_unlock_later && !call_db_errorno) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + current->record_num = current->result->num_rows(); + current->dbton_id = current->result->dbton_id; + 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)); + 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)); + if ( + result_list->internal_limit <= result_list->record_num || + result_list->split_read > current->record_num + ) { + 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; + } + if (result_list->bgs_phase <= 1) + { + result_list->current_row_num = 0; + } + } + } 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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(spider, &request_key, + &error_num))) + { + if (!error_num) + { + error_num = spider_db_errorno(conn); + } else { + if (!conn->mta_conn_mutex_unlock_later) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + 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) + { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + current->dbton_id = current->result->dbton_id; + SPIDER_DB_ROW *row; + if (!(row = current->result->fetch_row())) + { + error_num = current->result->get_errno(); + 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 ( + result_list->bgs_phase <= 1 && + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + table->status = STATUS_NOT_FOUND; + } + if (error_num) + DBUG_RETURN(error_num); + 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; + int roop_count = 0; + if (!result_list->quick_page_size) + { + if (result_list->quick_mode == 3) + { + page_size = 0; + } else { + result_list->quick_page_size = result_list->limit_num; + page_size = result_list->limit_num; + } + } else { + page_size = + result_list->limit_num < result_list->quick_page_size ? + result_list->limit_num : result_list->quick_page_size; + } + current->field_count = field_count; + if (!(position = (SPIDER_POSITION *) + spider_bulk_malloc(spider_current_trx, 7, MYF(MY_WME | MY_ZEROFILL), + &position, (uint) (sizeof(SPIDER_POSITION) * page_size), + &tmp_row, (uint) (sizeof(SPIDER_DB_ROW) * 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; + if (result_list->quick_mode == 3) + { + while (page_size > roop_count && row) + { + if (result_list->quick_page_byte < row->get_byte_size()) + { + current->pos_page_size = roop_count; + page_size = roop_count; + result_list->quick_page_size = roop_count; + result_list->quick_page_byte = 0; + break; + } else { + result_list->quick_page_byte -= row->get_byte_size(); + } + if (!(position->row = row->clone())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + position++; + roop_count++; + row = current->result->fetch_row(); + } + } else { + do { + if (!(position->row = row->clone())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + position++; + roop_count++; + if (result_list->quick_page_byte < row->get_byte_size()) + { + current->pos_page_size = roop_count; + page_size = roop_count; + result_list->quick_page_size = roop_count; + result_list->quick_page_byte = 0; + break; + } else { + result_list->quick_page_byte -= row->get_byte_size(); + } + } 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 + ) { + 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); +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor + LEX_CSTRING field_name1 = {STRING_WITH_LEN("a")}; + LEX_CSTRING field_name2 = {STRING_WITH_LEN("b")}; + LEX_CSTRING field_name3 = {STRING_WITH_LEN("c")}; + if (!(current->result_tmp_tbl = spider_mk_sys_tmp_table_for_result( + thd, table, ¤t->result_tmp_tbl_prm, &field_name1, &field_name2, + &field_name3, &my_charset_bin))) +#else + 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))) +#endif + { + 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 || + ( + result_list->quick_mode == 3 && + result_list->limit_num > 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->quick_mode == 3 || + result_list->limit_num == roop_count + ) { + if ( + result_list->limit_num != roop_count || + conn->db_conn->limit_mode() != 1 + ) { + 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; + } + } + DBUG_PRINT("info", ("spider bgs_phase=%d", result_list->bgs_phase)); + DBUG_PRINT("info", ("spider quick_phase=%d", result_list->quick_phase)); + if ( + result_list->bgs_phase <= 1 && + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + } + DBUG_PRINT("info", ("spider result_list->current=%p", result_list->current)); + DBUG_PRINT("info", ("spider current=%p", current)); + DBUG_PRINT("info", ("spider first_position=%p", current->first_position)); + DBUG_PRINT("info", ("spider current_row_num=%lld", result_list->current_row_num)); + DBUG_PRINT("info", ("spider first_position[]=%p", ¤t->first_position[result_list->current_row_num])); + DBUG_PRINT("info", ("spider row=%p", current->first_position[result_list->current_row_num].row)); + } + DBUG_RETURN(0); +} + +int spider_db_store_result_for_reuse_cursor( + ha_spider *spider, + int link_idx, + TABLE *table +) { + int error_num; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_RESULT *current; + DBUG_ENTER("spider_db_store_result_for_reuse_cursor"); + 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)); + DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM); + } + 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))) + ) { + 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 ( + result_list->bgs_phase > 0 || + 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))) + ) { + 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 ( + result_list->bgs_phase == 1 || + result_list->quick_phase == 2 + ) { + 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))) + ) { + 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); + } + current->result = current->prev->result; + current->result->set_limit(result_list->limit_num); + current->record_num = current->result->num_rows(); + current->dbton_id = current->result->dbton_id; + 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)); + 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)); + if ( + result_list->internal_limit <= result_list->record_num || + result_list->split_read > current->record_num + ) { + 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; + } + if (result_list->bgs_phase <= 1) + { + result_list->current_row_num = 0; + } + } else { + DBUG_ASSERT(current->prev); + DBUG_ASSERT(current->prev->result); + /* has_result() for case of result with result_tmp_tbl */ + if (current->prev->result->has_result()) + { + current->result = current->prev->result; + current->result->set_limit(result_list->limit_num); + current->prev->result = NULL; + result_list->limit_num -= current->prev->record_num; + } else { + if (spider_bit_is_set(spider->db_request_phase, link_idx)) + { + spider_clear_bit(spider->db_request_phase, link_idx); + } + current->result = current->prev->result; + current->result->set_limit(result_list->limit_num); + DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", conn, spider)); + conn->quick_target = spider; + spider->quick_targets[link_idx] = spider; + } + current->dbton_id = current->result->dbton_id; + SPIDER_DB_ROW *row; + if (!(row = current->result->fetch_row())) + { + error_num = current->result->get_errno(); + 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 ( + result_list->bgs_phase <= 1 && + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + table->status = STATUS_NOT_FOUND; + } + if (error_num && error_num != HA_ERR_END_OF_FILE) + DBUG_RETURN(error_num); + /* This shouldn't return HA_ERR_END_OF_FILE */ + DBUG_RETURN(0); + } + SPIDER_DB_ROW *tmp_row; + uint field_count = current->result->num_fields(); + SPIDER_POSITION *position; + longlong page_size; + int roop_count = 0; + if (!result_list->quick_page_size) + { + if (result_list->quick_mode == 3) + { + page_size = 0; + } else { + result_list->quick_page_size = result_list->limit_num; + page_size = result_list->limit_num; + } + } else { + page_size = + result_list->limit_num < result_list->quick_page_size ? + result_list->limit_num : result_list->quick_page_size; + } + current->field_count = field_count; + if (!(position = (SPIDER_POSITION *) + spider_bulk_malloc(spider_current_trx, 7, MYF(MY_WME | MY_ZEROFILL), + &position, (uint) (sizeof(SPIDER_POSITION) * page_size), + &tmp_row, (uint) (sizeof(SPIDER_DB_ROW) * 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; + if (result_list->quick_mode == 3) + { + while (page_size > roop_count && row) + { + if (result_list->quick_page_byte < row->get_byte_size()) + { + current->pos_page_size = roop_count; + page_size = roop_count; + result_list->quick_page_size = roop_count; + result_list->quick_page_byte = 0; + break; + } else { + result_list->quick_page_byte -= row->get_byte_size(); + } + if (!(position->row = row->clone())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + position++; + roop_count++; + row = current->result->fetch_row(); + } + } else { + do { + if (!(position->row = row->clone())) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + position++; + roop_count++; + if (result_list->quick_page_byte < row->get_byte_size()) + { + current->pos_page_size = roop_count; + page_size = roop_count; + result_list->quick_page_size = roop_count; + result_list->quick_page_byte = 0; + break; + } else { + result_list->quick_page_byte -= row->get_byte_size(); + } + } 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 + ) { + 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); +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor + LEX_CSTRING field_name1 = {STRING_WITH_LEN("a")}; + LEX_CSTRING field_name2 = {STRING_WITH_LEN("b")}; + LEX_CSTRING field_name3 = {STRING_WITH_LEN("c")}; + if (!(current->result_tmp_tbl = spider_mk_sys_tmp_table_for_result( + thd, table, ¤t->result_tmp_tbl_prm, &field_name1, &field_name2, + &field_name3, &my_charset_bin))) +#else + 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))) +#endif + { + 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 || + ( + result_list->quick_mode == 3 && + result_list->limit_num > 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->quick_mode == 3 || + result_list->limit_num == roop_count + ) { + 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; + } + } + DBUG_PRINT("info", ("spider bgs_phase=%d", result_list->bgs_phase)); + DBUG_PRINT("info", ("spider quick_phase=%d", result_list->quick_phase)); + if ( + result_list->bgs_phase <= 1 && + result_list->quick_phase == 0 + ) { + result_list->current_row_num = 0; + } + DBUG_PRINT("info", ("spider result_list->current=%p", result_list->current)); + DBUG_PRINT("info", ("spider current=%p", current)); + DBUG_PRINT("info", ("spider first_position=%p", current->first_position)); + DBUG_PRINT("info", ("spider current_row_num=%lld", result_list->current_row_num)); + DBUG_PRINT("info", ("spider first_position[]=%p", ¤t->first_position[result_list->current_row_num])); + DBUG_PRINT("info", ("spider row=%p", current->first_position[result_list->current_row_num].row)); + } + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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(spider, &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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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(spider, &request_key, &error_num))) + { + result->free_result(); + delete result; + } + } while (!conn->db_conn->next_result()); + DBUG_VOID_RETURN; +} + + +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->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); + } + 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 ( + 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 = 0, roop_end = 1, roop_count, lock_mode, link_ok = 0; + if (!spider->use_fields) + { + 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; + } + } + + if (result_list->bgs_phase > 0) + { + if (spider->use_fields) + { + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + spider_fields *fields = spider->fields; + fields->set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = fields->get_next_link_idx_chain())) + { + conn = link_idx_chain->conn; + link_idx_holder = link_idx_chain->link_idx_holder; + spider_db_handler *dbton_hdl = + spider->dbton_handler[conn->dbton_id]; + spider->link_idx_chain = link_idx_chain; + if ((error_num = spider_bg_conn_search(spider, + link_idx_holder->link_idx, dbton_hdl->first_link_idx, + FALSE, FALSE, + !fields->is_first_link_ok_chain(link_idx_chain)))) + { + DBUG_PRINT("info",("spider error_num 1=%d", error_num)); + DBUG_RETURN(error_num); + } + } + } else { + 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 { + 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->quick_mode == 3 || + !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 ((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->use_fields) + { + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + spider_fields *fields = spider->fields; + fields->set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = fields->get_next_link_idx_chain())) + { + ulong sql_type; + conn = link_idx_chain->conn; + sql_type = SPIDER_SQL_TYPE_SELECT_SQL; + link_idx_holder = link_idx_chain->link_idx_holder; + link_idx = link_idx_holder->link_idx; + spider_db_handler *dbton_handler = + spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + link_idx))) + { + DBUG_PRINT("info",("spider error_num 6=%d", error_num)); + DBUG_RETURN(error_num); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + if (conn->db_conn->limit_mode() == 1) + { + conn->db_conn->set_limit(result_list->limit_num); + if (fields->is_first_link_ok_chain(link_idx_chain)) + { + if ((error_num = spider_db_store_result_for_reuse_cursor( + spider, link_idx, table))) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + } else { + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 ( + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + DBUG_PRINT("info",("spider error_num 7a=%d", error_num)); + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->trx->thd, share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + DBUG_PRINT("info",("spider error_num 8a=%d", error_num)); + DBUG_RETURN(error_num); + } + spider->connection_ids[link_idx] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (fields->is_first_link_ok_chain(link_idx_chain)) + { + if ((error_num = spider_db_store_result(spider, link_idx, + table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + spider->need_mons[link_idx] + ) { + error_num = + fields->ping_table_mon_from_table(link_idx_chain); + } + DBUG_PRINT("info",("spider error_num 9a=%d", error_num)); + DBUG_RETURN(error_num); + } + spider->result_link_idx = link_ok; + } else { + spider_db_discard_result(spider, link_idx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + } + } else { + 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]; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + spider_db_handler *dbton_handler = + spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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); + } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + if (conn->db_conn->limit_mode() == 1) + { + conn->db_conn->set_limit(result_list->limit_num); + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result_for_reuse_cursor( + spider, link_idx, table))) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + } else { + conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->trx->thd, share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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); + } + } + } + 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 ((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); + } + + 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; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + conn = spider->conns[roop_count]; + spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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)); + if (conn->db_conn->limit_mode() == 1) + { + conn->db_conn->set_limit(result_list->limit_num); + if (roop_count == link_ok) + { + if ((error_num = spider_db_store_result_for_reuse_cursor( + spider, roop_count, table))) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + DBUG_RETURN(error_num); + } + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->bg_conn_mutex); + } else { + conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->trx->thd, + share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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; + { + 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 && + (error_num = spider->append_select_lock_sql_part( + SPIDER_SQL_TYPE_SELECT_SQL)) + ) + ) + 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; + sql_type= SPIDER_SQL_TYPE_SELECT_SQL; + conn = spider->conns[roop_count]; + spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) + { + DBUG_RETURN(error_num); + } + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->trx->thd, + share); + if (dbton_handler->execute_sql( + sql_type, + conn, + result_list->quick_mode, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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; + current->first_pos_use_position = TRUE; + } 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->tmp_tbl_use_position = TRUE; + } + } + current->use_position = TRUE; + pos->use_position = TRUE; + pos->mrr_with_cnt = spider->mrr_with_cnt; + pos->direct_aggregate = result_list->direct_aggregate; + pos->position_bitmap = spider->wide_handler->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->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); + } + + 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; +*/ + } + + DBUG_PRINT("info", ("spider row=%p", row)); + if (!spider->result_list.in_cmp_ref) + { + DBUG_PRINT("info", ("spider direct_aggregate=%s", + pos->direct_aggregate ? "TRUE" : "FALSE")); + spider->result_list.snap_mrr_with_cnt = pos->mrr_with_cnt; + spider->result_list.snap_direct_aggregate = pos->direct_aggregate; + spider->result_list.snap_row = row; + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + { + row->next(); + } + } + + /* for direct_aggregate */ + if (pos->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + 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 *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(*field))); + 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; +*/ + } + + DBUG_PRINT("info", ("spider row=%p", row)); + if (!spider->result_list.in_cmp_ref) + { + DBUG_PRINT("info", ("spider direct_aggregate=%s", + pos->direct_aggregate ? "TRUE" : "FALSE")); + spider->result_list.snap_mrr_with_cnt = pos->mrr_with_cnt; + spider->result_list.snap_direct_aggregate = pos->direct_aggregate; + spider->result_list.snap_row = row; + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + row->next(); + } + + /* for direct_aggregate */ + if (pos->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + 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 < spider_user_defined_key_parts(key_info); + 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 *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(field))); + 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; +*/ + } + + DBUG_PRINT("info", ("spider row=%p", row)); + if (!spider->result_list.in_cmp_ref) + { + DBUG_PRINT("info", ("spider direct_aggregate=%s", + pos->direct_aggregate ? "TRUE" : "FALSE")); + spider->result_list.snap_mrr_with_cnt = pos->mrr_with_cnt; + spider->result_list.snap_direct_aggregate = pos->direct_aggregate; + spider->result_list.snap_row = row; + } + + /* for mrr */ + if (pos->mrr_with_cnt) + { + DBUG_PRINT("info", ("spider mrr_with_cnt")); + row->next(); + } + + /* for direct_aggregate */ + if (pos->direct_aggregate) + { + if ((error_num = spider_db_fetch_for_item_sum_funcs(row, spider))) + DBUG_RETURN(error_num); + } + + 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 *tmp_map = + dbug_tmp_use_all_columns(table, &table->write_set); +#endif + DBUG_PRINT("info", ("spider bitmap is set %s", + SPIDER_field_name_str(*field))); + 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", + SPIDER_field_name_str(*field))); + 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_simple_action( + uint simple_action, + spider_db_handler *db_handler, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_db_simple_action"); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + error_num = db_handler->show_records( + link_idx + ); + break; + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + error_num = db_handler->checksum_table( + link_idx + ); + break; + default: + DBUG_ASSERT(0); + error_num = HA_ERR_CRASHED; + break; + } + DBUG_RETURN(error_num); +} + +int spider_db_simple_action( + uint simple_action, + ha_spider *spider, + int link_idx, + bool pre_call +) { + int error_num; + THD *thd = spider->wide_handler->trx->thd; + SPIDER_CONN *conn; + DBUG_ENTER("spider_db_simple_action"); + if (pre_call) + { + if (spider_param_bgs_mode(thd, spider->share->bgs_mode)) + { + if ((error_num = spider_check_and_get_casual_read_conn(thd, spider, + link_idx))) + { + DBUG_RETURN(error_num); + } + conn = spider->conns[link_idx]; + if (!(error_num = spider_create_conn_thread(conn))) + { + spider_bg_conn_simple_action(conn, simple_action, FALSE, + spider, link_idx, (int *) &spider->result_list.bgs_error); + } + } else { + conn = spider->conns[link_idx]; + error_num = spider_db_simple_action( + simple_action, + spider->dbton_handler[conn->dbton_id], + link_idx + ); + } + } else { + conn = spider->conns[link_idx]; + if (spider->use_pre_action) + { + if (spider_param_bgs_mode(thd, spider->share->bgs_mode)) + { + spider_bg_conn_wait(conn); + error_num = spider->result_list.bgs_error; + if (conn->casual_read_base_conn) + { + spider->conns[link_idx] = conn->casual_read_base_conn; + } + } else { + error_num = 0; + } + } else { + error_num = spider_db_simple_action( + simple_action, + spider->dbton_handler[conn->dbton_id], + 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) spider_user_defined_key_parts(key_info); + roop_count2++) + { + key_part = &key_info->key_part[roop_count2]; + field = key_part->field; + if (share->cardinality[field->field_index]) + { + rec_per_key = (ha_rows) share->stat.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; + } else { + key_info->rec_per_key[roop_count2] = 1; + } + 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( + const key_range *start_key, + const 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->reset_sql_sql(SPIDER_SQL_TYPE_INSERT_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) + ) { + if (spider->conns[roop_count]) + spider->conns[roop_count]->ignore_dup_key = + spider->wide_handler->ignore_dup_key; + } + if ( + (error_num = spider->append_insert_sql_part()) || + (error_num = spider->append_into_sql_part( + SPIDER_SQL_TYPE_INSERT_SQL)) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + +int spider_db_bulk_insert( + ha_spider *spider, + TABLE *table, + ha_copy_info *copy_info, + bool bulk_end +) { + int error_num, first_insert_link_idx = -1; + SPIDER_SHARE *share = spider->share; + THD *thd = spider->wide_handler->trx->thd; + DBUG_ENTER("spider_db_bulk_insert"); + + if (!bulk_end) + { + if ((error_num = spider->append_insert_values_sql_part( + SPIDER_SQL_TYPE_INSERT_SQL))) + { + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + DBUG_RETURN(error_num); + } + } + + 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))) + { + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + DBUG_RETURN(error_num); + } + bool insert_info = FALSE; + 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; + sql_type = SPIDER_SQL_TYPE_INSERT_SQL; + conn = spider->conns[roop_count2]; + dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_handler->set_sql_for_exec(sql_type, + roop_count2))) + { + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + 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[roop_count2]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_count2] && + spider->need_mons[roop_count2] + ) { + error_num = spider_ping_table_mon_from_table( + spider->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count2, + (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], + share->monitoring_flag[roop_count2], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count2, + spider->wide_handler->trx->thd, + share); + if (dbton_handler->execute_sql(sql_type, conn, -1, + &spider->need_mons[roop_count2])) + { + 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); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 != 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count2, + (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], + share->monitoring_flag[roop_count2], + TRUE + ); + } + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (!insert_info && copy_info) + { + insert_info = + conn->db_conn->inserted_info(dbton_handler, copy_info); + } + 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_assert_not_owner(&conn->mta_conn_mutex); + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later= TRUE; + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + 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)) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + } + if ( + (bulk_end || !spider->bulk_insert) && + (error_num = spider_trx_check_link_idx_failed(spider)) + ) + DBUG_RETURN(error_num); + DBUG_RETURN(0); +} + + +int spider_db_update_auto_increment( + ha_spider *spider, + int link_idx +) { + int roop_count; + THD *thd = spider->wide_handler->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(); + affected_rows = spider->conns[link_idx]->db_conn->affected_rows(); + DBUG_PRINT("info",("spider last_insert_id=%llu", last_insert_id)); + share->lgtm_tblhnd_share->auto_increment_value = + last_insert_id + affected_rows; + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); +/* + 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() && + !thd->is_current_stmt_binlog_format_row() + ) { + 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, SPIDER_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() && + !thd->is_current_stmt_binlog_format_row() + ) { + for (roop_count = 0; roop_count < (int) affected_rows; roop_count++) + push_warning_printf(thd, SPIDER_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; + ha_rows 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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + 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))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + } + 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, + ha_rows *dup_key_found +) { + int error_num = 0, error_num2, roop_count; + THD *thd = spider->wide_handler->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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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) + { + continue; + } + DBUG_RETURN(error_num); + } + 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))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + goto error_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + } + } + 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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) + { + DBUG_RETURN(error_num); + } + 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))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + goto error_last_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + } + } + } + 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]; + conn->ignore_dup_key = spider->wide_handler->ignore_dup_key; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) + { + 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[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_UPDATE_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_INSERT_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +int spider_db_direct_update( + ha_spider *spider, + TABLE *table, + ha_rows *update_rows, + ha_rows *found_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 ((error_num = spider->append_update_sql_part())) + DBUG_RETURN(error_num); + + if (!spider->do_direct_update) + { + if ((error_num= spider->append_update_set_sql_part())) + { + DBUG_RETURN(error_num); + } + } else { + if ((error_num= spider->append_direct_update_set_sql_part())) + { + DBUG_RETURN(error_num); + } + } + + 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 ( + (error_num = spider->append_key_where_sql_part( + NULL, + 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); + } + } + + 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; + DBUG_PRINT("info", ("spider exec sql")); + conn = spider->conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_UPDATE_SQL; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + 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[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->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->wide_handler->ignore_dup_key) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + if (!counted) + { + *update_rows = spider->conns[roop_count]->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider update_rows = %llu", *update_rows)); + *found_rows = spider->conns[roop_count]->db_conn->matched_rows(); + DBUG_PRINT("info", ("spider found_rows = %llu", *found_rows)); + counted = TRUE; + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + DBUG_RETURN(0); +} + + +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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) + { + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_query_with_set_names( + SPIDER_SQL_TYPE_DELETE_SQL, spider, conn, roop_count))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_direct_delete( + ha_spider *spider, + TABLE *table, + ha_rows *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; + { + 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( + NULL, + 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); + } + } + + 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; + DBUG_PRINT("info", ("spider exec sql")); + conn = spider->conns[roop_count]; + sql_type = SPIDER_SQL_TYPE_DELETE_SQL; + spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) + { + 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[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->trx->thd, + share); + if (dbton_hdl->execute_sql( + sql_type, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (!counted) + { + *delete_rows = spider->conns[roop_count]->db_conn->affected_rows(); + DBUG_PRINT("info", ("spider delete_rows = %llu", *delete_rows)); + counted = TRUE; + } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + int error_num2 = 0; + { + if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) + error_num2 = error_num; + } + DBUG_RETURN(error_num2); +} + +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]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = dbton_hdl->set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) + { + 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[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + if ((error_num = spider_db_set_names(spider, conn, roop_count))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, roop_count, + spider->wide_handler->trx->thd, + share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_DELETE_SQL, + conn, + -1, + &spider->need_mons[roop_count]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +/** + Find the field among the items in an expression tree. + + @param item_list List of items of the expression. + @param item_count Number of items in the item list. + @param start_item Index of the first item to consider. + @param str String into which the expression is to be printed. + @param func_name Function or operator name. + @param func_name_length Length of function or operator name. + + @return Pointer to the field in the item list if the list + contains only one field; NULL otherwise. +*/ + +Field *spider_db_find_field_in_item_list( + Item **item_list, + uint item_count, + uint start_item, + spider_string *str, + const char *func_name, + int func_name_length +) { + uint item_num; + Item *item; + Field *field = NULL; + DBUG_ENTER("spider_db_find_field_in_item_list"); + + if (str && func_name_length) + { + if (strncasecmp(func_name, ",", 1)) + { + /* A known function or operator */ + for (item_num = start_item; item_num < item_count; item_num++) + { + item = item_list[item_num]; + + if (item->type() == Item::FIELD_ITEM) + { + if (field) + { + /* Field is not relevant if there are multiple fields */ + DBUG_RETURN(NULL); + } + + field = ((Item_field *) item)->field; + } + } + } + } + + DBUG_RETURN(field); +} + +/** + Print an operand value within a statement generated for an expression. + + @param item Operand value to print. + @param field Field related to the operand value. + @param spider Spider. + @param str String into which the value is to be printed. + @param alias Name related to the operand. + @param alias_length Length of the name. + @param dbton_id Spider Db/Table id. + @param use_fields Use fields or exchange fields. + @param fields Array of fields in the expression. + + @return Error code. +*/ + +int spider_db_print_item_type( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + DBUG_ENTER("spider_db_print_item_type"); + DBUG_PRINT("info",("spider COND type=%d", item->type())); + + if (item->type() == Item::REF_ITEM && + ((Item_ref*)item)->ref_type() == Item_ref::DIRECT_REF) + { + item= item->real_item(); + DBUG_PRINT("info",("spider new 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, use_fields, fields)); + case Item::SUM_FUNC_ITEM: + DBUG_RETURN(spider_db_open_item_sum_func((Item_sum *)item, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case Item::COND_ITEM: + DBUG_RETURN(spider_db_open_item_cond((Item_cond *) item, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case Item::FIELD_ITEM: + DBUG_RETURN(spider_db_open_item_field((Item_field *) item, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case Item::REF_ITEM: + DBUG_RETURN(spider_db_open_item_ref((Item_ref *) item, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case Item::ROW_ITEM: + DBUG_RETURN(spider_db_open_item_row((Item_row *) item, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case Item::CONST_ITEM: + { + switch (item->cmp_type()) { + case TIME_RESULT: + case STRING_RESULT: + DBUG_RETURN(spider_db_open_item_string(item, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + case INT_RESULT: + case REAL_RESULT: + case DECIMAL_RESULT: + DBUG_RETURN(spider_db_open_item_int(item, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + default: + DBUG_ASSERT(FALSE); + DBUG_RETURN(spider_db_print_item_type_default(item, spider, str)); + } + } + case Item::CACHE_ITEM: + DBUG_RETURN(spider_db_open_item_cache((Item_cache *) item, field, spider, + str, alias, alias_length, dbton_id, use_fields, fields)); + case Item::INSERT_VALUE_ITEM: + DBUG_RETURN(spider_db_open_item_insert_value((Item_insert_value *) item, + field, spider, str, alias, alias_length, dbton_id, use_fields, fields)); + case Item::SUBSELECT_ITEM: + case Item::TRIGGER_FIELD_ITEM: + case Item::EXPR_CACHE_ITEM: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + default: + DBUG_RETURN(spider_db_print_item_type_default(item, spider, str)); + } + + DBUG_RETURN(0); +} + +int spider_db_print_item_type_default( + Item *item, + ha_spider *spider, + spider_string *str +) { + DBUG_ENTER("spider_db_print_item_type_default"); + THD *thd = spider->wide_handler->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) + { + item->print(str->get_str(), QT_TO_SYSTEM_CHARSET); + } else { + item->print(str->get_str(), QT_ORDINARY); + } + str->mem_calc(); + } + 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, + bool use_fields, + spider_fields *fields +) { + int error_num = 0; + List_iterator_fast lif(*(item_cond->argument_list())); + Item *item; + LEX_CSTRING func_name= {0,0}; + int 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, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + { + 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.str) + func_name= item_cond->func_name_cstring(); + + 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.str, func_name.length); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } + + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + { + 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, + bool use_fields, + spider_fields *fields +) { + 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, use_fields, fields)); +} + +int spider_db_open_item_sum_func( + Item_sum *item_sum, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + DBUG_ENTER("spider_db_open_item_func"); + DBUG_RETURN(spider_dbton[dbton_id].db_util->open_item_sum_func( + item_sum, spider, str, alias, alias_length, use_fields, fields)); +} + +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, + bool use_fields, + spider_fields *fields +) { + 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]; + DBUG_PRINT("info",("spider use cached_field_index")); + DBUG_PRINT("info",("spider const_table=%s", + field->table->const_table ? "TRUE" : "FALSE")); + if (field->table->const_table) + { + if (str) + { + String str_value; + String *tmp_str; + tmp_str = field->val_str(&str_value); + if (!tmp_str) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + + tmp_str->length() * 2)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->append_escape_string(tmp_str->ptr(), tmp_str->length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + } else { + if (!use_fields) + { + if (!(field = spider->field_exchange(field))) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + 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); + } + } else { + if (str) + { + SPIDER_FIELD_CHAIN *field_chain = fields->get_next_field_chain(); + SPIDER_FIELD_HOLDER *field_holder = field_chain->field_holder; + spider = field_holder->spider; + share = spider->share; + if ((error_num = share->dbton_share[dbton_id]-> + append_column_name_with_alias(str, field->field_index, + field_holder->alias->ptr(), field_holder->alias->length()))) + DBUG_RETURN(error_num); + } else { + if ((error_num = fields->add_field(field))) + { + DBUG_RETURN(error_num); + } + } + } + } + DBUG_RETURN(0); + } + if (str) + { + if (item_ident->field_name.str) + field_name_length = item_ident->field_name.length; + 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_escaped_name(str, item_ident->field_name.str, + 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_escaped_name_with_charset(str, item_ident->field_name.str, + 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, + bool use_fields, + spider_fields *fields +) { + 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)); + DBUG_PRINT("info",("spider db=%s", field->table->s->db.str)); + DBUG_PRINT("info",("spider table_name=%s", + field->table->s->table_name.str)); + DBUG_PRINT("info",("spider const_table=%s", + field->table->const_table ? "TRUE" : "FALSE")); + if (field->table->const_table) + { + if (str) + { + String str_value; + String *tmp_str; + tmp_str = field->val_str(&str_value); + if (!tmp_str) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + + tmp_str->length() * 2)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->append_escape_string(tmp_str->ptr(), tmp_str->length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + DBUG_RETURN(0); + } else { + DBUG_PRINT("info",("spider tmp_table=%u", field->table->s->tmp_table)); + if (field->table->s->tmp_table != INTERNAL_TMP_TABLE) + { + if (!use_fields) + { + if (!(field = spider->field_exchange(field))) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + 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); + } else { + if (str) + { + SPIDER_FIELD_CHAIN *field_chain = fields->get_next_field_chain(); + SPIDER_FIELD_HOLDER *field_holder = field_chain->field_holder; + spider = field_holder->spider; + share = spider->share; + field = spider->field_exchange(field); + DBUG_ASSERT(field); + if ((error_num = share->dbton_share[dbton_id]-> + append_column_name_with_alias(str, field->field_index, + field_holder->alias->ptr(), field_holder->alias->length()))) + DBUG_RETURN(error_num); + } else { + if ((error_num = fields->add_field(field))) + { + 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, + use_fields, fields)); +} + +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, + bool use_fields, + spider_fields *fields +) { + 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.str && + item_ref->name.str && + item_ref->alias_name_used + ) + { + if (str) + { + uint length = item_ref->name.length; + 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.str, length))) + { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); + } + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); // MDEV-25116 + } + DBUG_RETURN(spider_db_open_item_ident((Item_ident *) item_ref, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); +} + +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, + bool use_fields, + spider_fields *fields +) { + 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, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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); +} + +/** + Print a string value within a generated statement. + + @param item String value to print. + @param field Field related to the string value. + @param spider Spider. + @param str String into which the value is to be printed. + @param alias Name related to the string value. + @param alias_length Length of the name. + @param dbton_id Spider Db/Table id. + @param use_fields Use fields or exchange fields. + @param fields Array of fields in an expression containing + the string value. + + @return Error code. +*/ + +int spider_db_open_item_string( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + int error_num = 0; + DBUG_ENTER("spider_db_open_item_string"); + + if (str) + { + THD *thd = NULL; + TABLE *UNINIT_VAR(table); + MY_BITMAP *saved_map = NULL; + Time_zone *UNINIT_VAR(saved_time_zone); + String str_value; + 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()))) + { + if (str->reserve(SPIDER_SQL_NULL_LEN)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN); + } else { + if ( + field && + field->type() == FIELD_TYPE_TIMESTAMP && + field->table->in_use->variables.time_zone != UTC + ) { + /* + Store the string value in the field. This is necessary + when the statement contains more than one value for the + same field. + */ + table = field->table; + thd = table->in_use; + saved_map = dbug_tmp_use_all_columns(table, &table->write_set); + item->save_in_field(field, FALSE); + saved_time_zone = thd->variables.time_zone; + thd->variables.time_zone = UTC; + + /* Retrieve the stored value converted to UTC */ + tmp_str2 = field->val_str(&str_value); + + if (!tmp_str2) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + } + DBUG_PRINT("info",("spider dbton_id=%u", dbton_id)); + if (str->charset() != tmp_str2->charset() && + spider_dbton[dbton_id].db_util->append_charset_name_before_string()) + { + if ((error_num = spider_db_append_charset_name_before_string(str, + tmp_str2->charset()))) + { + goto end; + } + } + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + + tmp_str2->length() * 2)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + if (!thd) + tmp_str.mem_calc(); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->append_escape_string(tmp_str2->ptr(), tmp_str2->length(), + tmp_str2->charset()); + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } + +end: + if (thd) + { + thd->variables.time_zone = saved_time_zone; + dbug_tmp_restore_column_map(&table->write_set, saved_map); + } + } + + DBUG_RETURN(error_num); +} + +/** + Print an integer value within a generated statement. + + @param item Integer value to print. + @param field Field related to the integer value. + @param spider Spider. + @param str String into which the value is to be printed. + @param alias Name related to the integer value. + @param alias_length Length of the name. + @param dbton_id Spider Db/Table id. + @param use_fields Use fields or exchange fields. + @param fields Array of fields in an expression containing + the integer value. + + @return Error code. +*/ + +int spider_db_open_item_int( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + int error_num = 0; + DBUG_ENTER("spider_db_open_item_int"); + + if (str) + { + THD *thd = NULL; + TABLE *table; + MY_BITMAP *saved_map; + Time_zone *saved_time_zone; + String str_value; + bool print_quoted_string; + 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(127); + + if (!(tmp_str2 = item->val_str(tmp_str.get_str()))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + tmp_str.mem_calc(); + + if ( + field && + field->type() == FIELD_TYPE_TIMESTAMP && + field->table->in_use->variables.time_zone != UTC + ) { + /* + Store the int value in the field. This is necessary + when the statement contains more than one value for the + same field. + */ + table = field->table; + thd = table->in_use; + saved_map = dbug_tmp_use_all_columns(table, &table->write_set); + item->save_in_field(field, FALSE); + saved_time_zone = thd->variables.time_zone; + thd->variables.time_zone = UTC; + print_quoted_string = TRUE; + } else { + DBUG_PRINT("info",("spider cmp_type=%u", item->cmp_type())); + if (item->cmp_type() == TIME_RESULT) + print_quoted_string = TRUE; + else + print_quoted_string = FALSE; + } + + if (print_quoted_string) + { + if (thd) + { + /* Retrieve the stored value converted to UTC */ + tmp_str2 = field->val_str(&str_value); + + if (!tmp_str2) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + } + + if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN * 2 + tmp_str2->length())) + { + error_num = HA_ERR_OUT_OF_MEM; + goto end; + } + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->append(*tmp_str2); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else { + if (str->append(*tmp_str2)) + error_num = HA_ERR_OUT_OF_MEM; + } + +end: + if (thd) + { + thd->variables.time_zone = saved_time_zone; + dbug_tmp_restore_column_map(&table->write_set, saved_map); + } + } + + DBUG_RETURN(error_num); +} + +/** + Print a cached value within a generated statement. + + @param item Cached value to print. + @param field Field related to the cached value. + @param spider Spider. + @param str String into which the value is to be printed. + @param alias Name related to the cached value. + @param alias_length Length of the name. + @param dbton_id Spider Db/Table id. + @param use_fields Use fields or exchange fields. + @param fields Array of fields in the expression containing + the cached value. + + @return Error code. +*/ + +int spider_db_open_item_cache( + Item_cache *item_cache, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + DBUG_ENTER("spider_db_open_item_cache"); + if (!item_cache->const_item()) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + DBUG_PRINT("info",("spider result_type=%u", item_cache->result_type())); + + switch (item_cache->result_type()) + { + case STRING_RESULT: + DBUG_RETURN(spider_db_open_item_string(item_cache, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + 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), NULL, + spider, str, alias, alias_length, dbton_id, use_fields, fields + ))) { + 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), NULL, + spider, str, alias, alias_length, dbton_id, use_fields, fields + ))) { + 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, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); +} + +/** + Print an INSERT value within a generated INSERT statement. + + @param item INSERT value to print. + @param field Field related to the INSERT value. + @param spider Spider. + @param str String into which the value is to be printed. + @param alias Name related to the INSERT value. + @param alias_length Length of the name. + @param dbton_id Spider Db/Table id. + @param use_fields Use fields or exchange fields. + @param fields Array of fields in the expression. + + @return Error code. +*/ + +int spider_db_open_item_insert_value( + Item_insert_value *item_insert_value, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + int error_num; + DBUG_ENTER("spider_db_open_item_insert_value"); + + if (item_insert_value->arg) + { + if (str) + { + 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); + } + if ((error_num = spider_db_print_item_type(item_insert_value->arg, field, + spider, str, alias, alias_length, dbton_id, use_fields, fields))) + 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_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 ((error_num = spider->append_condition_sql_part( + alias, alias_length, SPIDER_SQL_TYPE_SELECT_SQL, FALSE))) + DBUG_RETURN(error_num); + } + } else { + if (spider->wide_handler->cond_check) + DBUG_RETURN(spider->wide_handler->cond_check_error); + spider->wide_handler->cond_check = TRUE; + if ((spider->wide_handler->cond_check_error = + spider->append_condition_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL, TRUE))) + DBUG_RETURN(spider->wide_handler->cond_check_error); + } + DBUG_RETURN(0); +} + +int spider_db_append_update_columns( + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +) { + int error_num; + bool add_comma = FALSE; + List_iterator_fast fi(*spider->wide_handler->direct_update_fields), + vi(*spider->wide_handler->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, NULL, spider, str, alias, alias_length, dbton_id, + use_fields, fields))) + { + if ( + error_num == ER_SPIDER_COND_SKIP_NUM && + field->type() == Item::FIELD_ITEM && + ((Item_field *) field)->field + ) { + DBUG_PRINT("info",("spider no match field(ex. vp child table)")); + 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, ((Item_field *) field)->field, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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); + add_comma = TRUE; + } + } + if (str && add_comma) + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +bool spider_db_check_select_colum_in_group( + st_select_lex *select_lex, + Field *field +) { + ORDER *group; + DBUG_ENTER("spider_db_check_select_colum_in_group"); + for (group = (ORDER *) select_lex->group_list.first; group; + group = group->next) + { + Item *item = *group->item; + if (item->type() == Item::FIELD_ITEM) + { + Item_field *item_field = (Item_field *) item; + if (item_field->field == field) + { + /* This field can be used directly */ + DBUG_RETURN(TRUE); + } + } + } + DBUG_RETURN(FALSE); +} + +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 == spider_user_defined_key_parts(key_info) + ) { + 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 < spider_user_defined_key_parts(key_info); + 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 *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 ((error_num = spider_reset_conn_setted_parameter(conn, thd))) + DBUG_RETURN(error_num); + + if (conn->dbton_id == SPIDER_DBTON_SIZE) + { + 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 (!(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 ((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); + } + } + 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) direct_sql->bulk_insert_rows; + int table_loop_mode= 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; + enum_sql_command sql_command_backup; + DBUG_ENTER("spider_db_udf_direct_sql"); + if (direct_sql->real_table_used) + { + if (spider_sys_open_and_lock_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; + } + + if (c_thd != thd) + { + need_all_commit = TRUE; + need_trx_end = TRUE; + } else { + need_all_commit = FALSE; + if (direct_sql->real_table_used) + { + need_trx_end = TRUE; + } else { + if (c_thd->transaction->stmt.ha_list) + need_trx_end = FALSE; + else + need_trx_end = TRUE; + } + } + + 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); + } + + sql_command_backup = c_thd->lex->sql_command; + c_thd->lex->sql_command = SQLCOM_INSERT; + + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + 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)) + ) { + 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; + 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(NULL, &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_udf_table_lock_mutex_count); + udf_table_mutex_index+= + spider_udf_calc_hash(direct_sql->table_names[roop_count], + spider_udf_table_lock_mutex_count); + udf_table_mutex_index%= spider_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); + + { + 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 ( + table->s->tmp_table == NO_TMP_TABLE && + 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; + } + } + } + + 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); + } + { + table->file->ha_external_unlock(table->in_use); + if ( + table->s->tmp_table == NO_TMP_TABLE && + 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; + } + } + } + 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); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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)); + } + } + } + c_thd->lex->sql_command = sql_command_backup; + 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; + SPIDER_DB_CONN *db_conn = conn->db_conn; + DBUG_ENTER("spider_db_udf_direct_sql_select_db"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + if ( + spider_dbton[conn->dbton_id].db_util->database_has_default_value() + ) { + 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) + ) { + 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)); + 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); + } + } + 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; + DBUG_ENTER("spider_db_udf_direct_sql_set_names"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + if ( + !conn->access_charset || + trx->udf_access_charset->cset != conn->access_charset->cset + ) { + if ( + ( + spider_db_before_query(conn, &need_mon) || + conn->db_conn->set_character_set(trx->udf_access_charset->cs_name.str) + ) && + (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)); + } + DBUG_RETURN(error_num); + } + conn->access_charset = trx->udf_access_charset; + } + 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; + DBUG_ENTER("spider_db_udf_ping_table"); + if (!pthread_mutex_trylock(&table_mon_list->monitor_mutex)) + { + int need_mon = 0; + uint tmp_conn_link_idx = 0; + ha_spider spider; + SPIDER_WIDE_HANDLER wide_handler; + uchar db_request_phase = 0; + ulonglong db_request_id = 0; + spider.share = share; + spider.wide_handler = &wide_handler; + wide_handler.trx = trx; + spider.need_mons = &need_mon; + spider.conn_link_idx = &tmp_conn_link_idx; + spider.db_request_phase = &db_request_phase; + spider.db_request_id = &db_request_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_ping(&spider, conn, 0))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + if (error_num == ER_CON_COUNT_ERROR) + { + my_error(ER_CON_COUNT_ERROR, MYF(0)); + DBUG_RETURN(ER_CON_COUNT_ERROR); + } + my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), + share->server_names[0]); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + char *sql_buf = (char *) my_alloca(init_sql_alloc_size * 2); + if (!sql_buf) + { + 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); + } + char *where_buf = sql_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); + 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)); + my_afree(sql_buf); + 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)); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_set_names(&spider, conn, 0))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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)); + my_afree(sql_buf); + 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) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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)); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); + my_afree(sql_buf); + } + 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 *static_link_id, + uint static_link_id_length, + 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) + + ( + static_link_id ? + (SPIDER_SQL_INT_LEN * 5) + + (SPIDER_SQL_VALUE_QUOTE_LEN * 2) + + (static_link_id_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); + str->append_escape_string(child_table_name_str.ptr(), child_table_name_str.length()); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + if (static_link_id) + { + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->append_for_single_quote(static_link_id, static_link_id_length); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + } else { + 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); + str->append_escape_string(where_clause_str.ptr(), where_clause_str.length()); + 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 (share->tgt_dbs[0]) + { + 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); + + if (spider_dbton[dbton_id].db_util->limit_mode() == 1) + { + if (use_where) + { + if (str->reserve(where_str->length() * 2)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->append_escape_string(where_str->ptr(), where_str->length()); + } + } else { + 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) + { + str->append_escape_string(where_str->ptr(), where_str->length()); + } + 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); + ha_spider spider; + SPIDER_WIDE_HANDLER wide_handler; + SPIDER_TRX trx; + DBUG_ENTER("spider_db_udf_ping_table_mon_next"); + char *sql_buf = (char *) my_alloca(init_sql_alloc_size); + if (!sql_buf) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_string sql_str(sql_buf, sizeof(sql_buf), + thd->variables.character_set_client); + sql_str.init_calc_mem(132); + sql_str.length(0); + trx.thd = thd; + spider.share = share; + spider.wide_handler = &wide_handler; + wide_handler.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, + table_mon->parent->share->static_link_ids[0], + table_mon->parent->share->static_link_ids_lengths[0], + 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)); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_ping(&spider, conn, 0))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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]); + my_afree(sql_buf); + DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); + } + if ((error_num = spider_db_set_names(&spider, conn, 0))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_afree(sql_buf); + 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) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + my_afree(sql_buf); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + my_afree(sql_buf); + DBUG_RETURN(error_num); + } + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + my_afree(sql_buf); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_afree(sql_buf); + 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.str, 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]; + 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, (uint) (sizeof(ulong) * table->s->fields), + &last_lengths, (uint) (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]; + /* disable transaction */ + spider_conn_clear_queue_at_commit(tmp_conn); + if (!tmp_conn->trx_start) + { + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_ping(tmp_spider, tmp_conn, 0)) + { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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)) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + goto error_start_transaction; + } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + } + } + } else { + for (roop_count = 0; roop_count < all_link_cnt; roop_count++) + { + tmp_spider = &spider[roop_count]; + tmp_conn = tmp_spider->conns[0]; + /* disable transaction */ + spider_conn_clear_queue_at_commit(tmp_conn); + 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]; + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_ping(tmp_spider, tmp_conn, 0)) + { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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)) + ) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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; + } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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); + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &src_tbl_conn->need_mon; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; + if (select_ct->exec_query( + tmp_conn, + -1, + &src_tbl_conn->need_mon) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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 { + 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(NULL, &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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + goto error_db_query; + } + } + ++roop_count; + } + error_num = result->get_errno(); + if (error_num == HA_ERR_END_OF_FILE) + { + if (roop_count < 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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + goto error_db_query; + } + 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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + goto error_db_query; + } + result->free_result(); + delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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) + { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + 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; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + } + } + + if (!error_num && roop_count) + { +/* + 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; + } + } +*/ + 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 { + 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_assert_not_owner(&tmp_conn->mta_conn_mutex); + 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; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + 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) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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 { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + 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); + } + } + } + + 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; + } + } + } + } + + 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")); + my_sleep(copy_tables->bulk_insert_interval); + } + } + spider_free(spider_current_trx, last_row_pos, MYF(0)); + DBUG_RETURN(0); + +error_db_query: + 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); + } + } + } +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); +} + +bool spider_db_conn_is_network_error( + int error_num +) { + DBUG_ENTER("spider_db_conn_is_network_error"); + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM || + error_num == ER_CONNECT_TO_FOREIGN_DATA_SOURCE || + ( + error_num >= CR_MIN_ERROR && + error_num <= CR_MAX_ERROR + ) + ) { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h new file mode 100644 index 00000000..1de59f43 --- /dev/null +++ b/storage/spider/spd_db_conn.h @@ -0,0 +1,1143 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define SPIDER_DB_WRAPPER_STR "mariadb" +#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_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_OPEN_BRACE_STR "{" +#define SPIDER_SQL_OPEN_BRACE_LEN (sizeof(SPIDER_SQL_OPEN_BRACE_STR) - 1) +#define SPIDER_SQL_CLOSE_BRACE_STR "}" +#define SPIDER_SQL_CLOSE_BRACE_LEN (sizeof(SPIDER_SQL_CLOSE_BRACE_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_DISTINCT_STR "distinct " +#define SPIDER_SQL_DISTINCT_LEN (sizeof(SPIDER_SQL_DISTINCT_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_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_HAVING_STR " having " +#define SPIDER_SQL_HAVING_LEN (sizeof(SPIDER_SQL_HAVING_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_YEAR_STR "year" +#define SPIDER_SQL_YEAR_LEN (sizeof(SPIDER_SQL_YEAR_STR) - 1) +#define SPIDER_SQL_QUARTER_STR "quarter" +#define SPIDER_SQL_QUARTER_LEN (sizeof(SPIDER_SQL_QUARTER_STR) - 1) +#define SPIDER_SQL_MONTH_STR "month" +#define SPIDER_SQL_MONTH_LEN (sizeof(SPIDER_SQL_MONTH_STR) - 1) +#define SPIDER_SQL_WEEK_STR "week" +#define SPIDER_SQL_WEEK_LEN (sizeof(SPIDER_SQL_WEEK_STR) - 1) +#define SPIDER_SQL_DAY_STR "day" +#define SPIDER_SQL_DAY_LEN (sizeof(SPIDER_SQL_DAY_STR) - 1) +#define SPIDER_SQL_HOUR_STR "hour" +#define SPIDER_SQL_HOUR_LEN (sizeof(SPIDER_SQL_HOUR_STR) - 1) +#define SPIDER_SQL_MINUTE_STR "minute" +#define SPIDER_SQL_MINUTE_LEN (sizeof(SPIDER_SQL_MINUTE_STR) - 1) +#define SPIDER_SQL_SECOND_STR "second" +#define SPIDER_SQL_SECOND_LEN (sizeof(SPIDER_SQL_SECOND_STR) - 1) +#define SPIDER_SQL_MICROSECOND_STR "microsecond" +#define SPIDER_SQL_MICROSECOND_LEN (sizeof(SPIDER_SQL_MICROSECOND_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_TRIM_STR "trim" +#define SPIDER_SQL_TRIM_LEN sizeof(SPIDER_SQL_TRIM_STR) - 1 +#define SPIDER_SQL_TRIM_BOTH_STR "both " +#define SPIDER_SQL_TRIM_BOTH_LEN sizeof(SPIDER_SQL_TRIM_BOTH_STR) - 1 +#define SPIDER_SQL_TRIM_LEADING_STR "leading " +#define SPIDER_SQL_TRIM_LEADING_LEN sizeof(SPIDER_SQL_TRIM_LEADING_STR) - 1 +#define SPIDER_SQL_TRIM_TRAILING_STR "trailing " +#define SPIDER_SQL_TRIM_TRAILING_LEN sizeof(SPIDER_SQL_TRIM_TRAILING_STR) - 1 + +#define SPIDER_SQL_INDEX_IGNORE_STR " IGNORE INDEX " +#define SPIDER_SQL_INDEX_IGNORE_LEN (sizeof(SPIDER_SQL_INDEX_IGNORE_STR) - 1) +#define SPIDER_SQL_INDEX_USE_STR " USE INDEX " +#define SPIDER_SQL_INDEX_USE_LEN (sizeof(SPIDER_SQL_INDEX_USE_STR) - 1) +#define SPIDER_SQL_INDEX_FORCE_STR " FORCE INDEX " +#define SPIDER_SQL_INDEX_FORCE_LEN (sizeof(SPIDER_SQL_INDEX_FORCE_STR) - 1) + +#define SPIDER_SQL_INT_LEN 20 +#define SPIDER_UDF_PING_TABLE_PING_ONLY (1 << 0) +#define SPIDER_UDF_PING_TABLE_USE_WHERE (1 << 1) +#define SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES (1 << 2) + +int spider_db_connect( + const SPIDER_SHARE *share, + SPIDER_CONN *conn, + int link_idx +); + +int spider_db_ping_internal( + SPIDER_SHARE *share, + SPIDER_CONN *conn, + int all_link_idx, + int *need_mon +); + +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, + ha_rows *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, + const char *name, + uint dbton_id +); + +int spider_db_append_name_with_quote_str( + spider_string *str, + LEX_CSTRING &name, + uint dbton_id +); + +int spider_db_append_name_with_quote_str_internal( + spider_string *str, + const char *name, + int length, + uint dbton_id +); + +int spider_db_append_name_with_quote_str_internal( + spider_string *str, + const char *name, + int length, + CHARSET_INFO *cs, + 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_charset_name_before_string( + spider_string *str, + CHARSET_INFO *cs +); + +int spider_db_refetch_for_item_sum_funcs( + ha_spider *spider +); + +int spider_db_fetch_for_item_sum_funcs( + SPIDER_DB_ROW *row, + ha_spider *spider +); + +int spider_db_fetch_for_item_sum_func( + SPIDER_DB_ROW *row, + Item_sum *item_sum, + 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_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 +); + +void spider_db_free_one_quick_result( + 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 +); + +int spider_db_store_result_for_reuse_cursor( + 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 +); + + +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_simple_action( + uint simple_action, + spider_db_handler *db_handler, + int link_idx +); + +int spider_db_simple_action( + uint simple_action, + ha_spider *spider, + int link_idx, + bool pre_call +); + +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( + const key_range *start_key, + const 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, + ha_copy_info *copy_info, + bool bulk_end +); + + +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, + ha_rows *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 +); + +int spider_db_direct_update( + ha_spider *spider, + TABLE *table, + ha_rows *update_rows, + ha_rows *found_rows +); + + +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 +); + +int spider_db_direct_delete( + ha_spider *spider, + TABLE *table, + ha_rows *delete_rows +); + +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 +); + +Field *spider_db_find_field_in_item_list( + Item **item_list, + uint item_count, + uint start_item, + spider_string *str, + const char *func_name, + int func_name_length +); + +int spider_db_print_item_type( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +int spider_db_print_item_type_default( + Item *item, + ha_spider *spider, + spider_string *str +); + +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, + bool use_fields, + spider_fields *fields +); + +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, + bool use_fields, + spider_fields *fields +); + +int spider_db_open_item_sum_func( + Item_sum *item_sum, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +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, + bool use_fields, + spider_fields *fields +); + +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, + bool use_fields, + spider_fields *fields +); + +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, + bool use_fields, + spider_fields *fields +); + +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, + bool use_fields, + spider_fields *fields +); + +int spider_db_open_item_string( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +int spider_db_open_item_int( + Item *item, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +int spider_db_open_item_cache( + Item_cache *item_cache, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +int spider_db_open_item_insert_value( + Item_insert_value *item_insert_value, + Field *field, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +int spider_db_append_condition( + ha_spider *spider, + const char *alias, + uint alias_length, + bool test_flg +); + +int spider_db_append_update_columns( + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + uint dbton_id, + bool use_fields, + spider_fields *fields +); + +bool spider_db_check_select_colum_in_group( + st_select_lex *select_lex, + Field *field +); + +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 +); + +bool spider_db_conn_is_network_error( + int error_num +); diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc new file mode 100644 index 00000000..a4d7d4b4 --- /dev/null +++ b/storage/spider/spd_db_include.cc @@ -0,0 +1,236 @@ +/* Copyright (C) 2018-2020 Kentoku Shiba + Copyright (C) 2018-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_common.h" +#include +#include +#include "spd_err.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "spd_conn.h" + +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +spider_db_result::spider_db_result( + SPIDER_DB_CONN *in_db_conn +) : db_conn(in_db_conn), dbton_id(in_db_conn->dbton_id) +{ + DBUG_ENTER("spider_db_result::spider_db_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_result::fetch_table_checksum( + ha_spider *spider +) { + DBUG_ENTER("spider_db_result::fetch_table_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +uint spider_db_result::limit_mode() +{ + DBUG_ENTER("spider_db_result::limit_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(spider_dbton[dbton_id].db_util->limit_mode()); +} + +spider_db_conn::spider_db_conn( + SPIDER_CONN *in_conn +) : conn(in_conn), dbton_id(in_conn->dbton_id) +{ + DBUG_ENTER("spider_db_conn::spider_db_conn"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +bool spider_db_conn::set_loop_check_in_bulk_sql() +{ + DBUG_ENTER("spider_db_conn::set_loop_check_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_conn::set_loop_check( + int *need_mon +) { + DBUG_ENTER("spider_db_conn::set_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +int spider_db_conn::fin_loop_check() +{ + st_spider_conn_loop_check *lcptr; + DBUG_ENTER("spider_db_conn::fin_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->loop_check_queue.records) + { + uint l = 0; + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_check_queue, l))) + { + lcptr->flag = 0; + ++l; + } + my_hash_reset(&conn->loop_check_queue); + } + lcptr = conn->loop_check_ignored_first; + while (lcptr) + { + lcptr->flag = 0; + lcptr = lcptr->next; + } + conn->loop_check_ignored_first = NULL; + lcptr = conn->loop_check_meraged_first; + while (lcptr) + { + lcptr->flag = 0; + lcptr = lcptr->next; + } + conn->loop_check_meraged_first = NULL; + DBUG_RETURN(0); +} + +uint spider_db_conn::limit_mode() +{ + DBUG_ENTER("spider_db_conn::limit_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(spider_dbton[dbton_id].db_util->limit_mode()); +} + +int spider_db_util::append_loop_check( + spider_string *str, + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_db_util::append_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + /* nothing to do */ + DBUG_RETURN(0); +} + +bool spider_db_util::tables_on_different_db_are_joinable() +{ + DBUG_ENTER("spider_db_util::tables_on_different_db_are_joinable"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::socket_has_default_value() +{ + DBUG_ENTER("spider_db_util::socket_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::database_has_default_value() +{ + DBUG_ENTER("spider_db_util::database_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::default_file_has_default_value() +{ + DBUG_ENTER("spider_db_util::default_file_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::host_has_default_value() +{ + DBUG_ENTER("spider_db_util::host_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::port_has_default_value() +{ + DBUG_ENTER("spider_db_util::port_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_db_util::append_charset_name_before_string() +{ + DBUG_ENTER("spider_db_util::append_charset_name_before_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +uint spider_db_util::limit_mode() +{ + DBUG_ENTER("spider_db_util::limit_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_db_share::checksum_support() +{ + DBUG_ENTER("spider_db_share::checksum_support"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +int spider_db_handler::checksum_table( + int link_idx +) { + DBUG_ENTER("spider_db_handler::checksum_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +bool spider_db_handler::check_direct_update( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + DBUG_ENTER("spider_db_handler::check_direct_update"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + select_limit != 9223372036854775807LL || + offset_limit != 0 || + select_lex->order_list.elements + ) { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +bool spider_db_handler::check_direct_delete( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + DBUG_ENTER("spider_db_handler::check_direct_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + select_limit != 9223372036854775807LL || + offset_limit != 0 || + select_lex->order_list.elements + ) { + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h new file mode 100644 index 00000000..ef0fb8f2 --- /dev/null +++ b/storage/spider/spd_db_include.h @@ -0,0 +1,1822 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019, 2022, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define SPD_INIT_DYNAMIC_ARRAY2(A, B, C, D, E, F) \ + my_init_dynamic_array2(PSI_INSTRUMENT_ME, A, B, C, D, E, F) +#define SPD_INIT_ALLOC_ROOT(A, B, C, D) \ + init_alloc_root(PSI_INSTRUMENT_ME, A, B, C, D) + +#define SPIDER_DBTON_SIZE 15 + +#ifndef SIZEOF_STORED_DOUBLE +#define SIZEOF_STORED_DOUBLE 8 +#endif + +#define SPIDER_DB_WRAPPER_MYSQL "mysql" +#define SPIDER_DB_WRAPPER_MARIADB "mariadb" + +#define PLUGIN_VAR_CAN_MEMALLOC + +#define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE +#define SPIDER_HAS_SHOW_SIMPLE_FUNC +#define SPIDER_HAS_JT_HASH_INDEX_MERGE +#define SPIDER_HAS_TIME_STATUS +#define SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE +#define SPIDER_ORDER_HAS_ENUM_ORDER +#define SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR +#define SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR + +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_COLON_STR ":" +#define SPIDER_SQL_COLON_LEN sizeof(SPIDER_SQL_COLON_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_PERCENT_STR "%" +#define SPIDER_SQL_PERCENT_LEN (sizeof(SPIDER_SQL_PERCENT_STR) - 1) +#define SPIDER_SQL_HYPHEN_STR "-" +#define SPIDER_SQL_HYPHEN_LEN (sizeof(SPIDER_SQL_HYPHEN_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 + +#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_TO_FLOAT_STR "/* create function to_float(a decimal(20,6)) returns float return a */ to_float(" +#define SPIDER_SQL_TO_FLOAT_LEN (sizeof(SPIDER_SQL_TO_FLOAT_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_LIKE_STR " like " +#define SPIDER_SQL_LIKE_LEN (sizeof(SPIDER_SQL_LIKE_STR) - 1) +#define SPIDER_SQL_NOT_LIKE_STR "not like" +#define SPIDER_SQL_NOT_LIKE_LEN (sizeof(SPIDER_SQL_NOT_LIKE_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_AS_FLOAT_STR " as float" +#define SPIDER_SQL_AS_FLOAT_LEN (sizeof(SPIDER_SQL_AS_FLOAT_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_CHARACTER_SET_STR " character set " +#define SPIDER_SQL_CHARACTER_SET_LEN (sizeof(SPIDER_SQL_CHARACTER_SET_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_SQL_MIN_STR "min" +#define SPIDER_SQL_MIN_LEN (sizeof(SPIDER_SQL_MIN_STR) - 1) + +#define SPIDER_SQL_LOP_CHK_PRM_PRF_STR "spider_lc_" +#define SPIDER_SQL_LOP_CHK_PRM_PRF_LEN (sizeof(SPIDER_SQL_LOP_CHK_PRM_PRF_STR) - 1) + +#define SPIDER_CONN_KIND_MYSQL (1 << 0) + +#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_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 +}; + +enum spider_index_rnd_init { + SPD_NONE, + SPD_INDEX, + SPD_RND +}; + +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_db_handler; + +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 + ); + 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 + ); + 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 + ); + void append_escape_string( + const char *st, + uint len + ); + void append_escape_string( + const char *st, + uint len, + CHARSET_INFO *cs + ); + bool append_for_single_quote( + const char *st, + uint len + ); + bool append_for_single_quote( + const String *s + ); + bool append_for_single_quote( + const char *st + ); + void print( + String *print + ); + void swap( + spider_string &s + ); + bool uses_buffer_owned_by( + const String *s + ) const; + bool is_ascii() const; +}; + +typedef struct spider_table_link_idx_holder SPIDER_TABLE_LINK_IDX_HOLDER; +typedef struct spider_table_holder SPIDER_TABLE_HOLDER; + +typedef struct spider_link_idx_holder +{ + spider_table_link_idx_holder *table_link_idx_holder; + int link_idx; + int link_status; + spider_link_idx_holder *next_table; + spider_link_idx_holder *next; +} SPIDER_LINK_IDX_HOLDER; + +typedef struct spider_link_idx_chain +{ + SPIDER_CONN *conn; + spider_link_idx_holder *link_idx_holder; + spider_link_idx_holder *current_link_idx_holder; + int link_status; + spider_link_idx_chain *next; +} SPIDER_LINK_IDX_CHAIN; + +typedef struct spider_table_link_idx_holder +{ + spider_table_holder *table_holder; + spider_link_idx_holder *first_link_idx_holder; + spider_link_idx_holder *last_link_idx_holder; + spider_link_idx_holder *current_link_idx_holder; + uint link_idx_holder_count; +} SPIDER_TABLE_LINK_IDX_HOLDER; + +typedef struct spider_conn_holder +{ + SPIDER_CONN *conn; + spider_table_link_idx_holder *table_link_idx_holder; + uint link_idx_holder_count_max; + bool checked_for_same_conn; + long access_balance; + spider_conn_holder *prev; + spider_conn_holder *next; +} SPIDER_CONN_HOLDER; + +typedef struct spider_table_holder +{ + TABLE *table; + ha_spider *spider; + spider_string *alias; +} SPIDER_TABLE_HOLDER; + +typedef struct spider_field_holder +{ + Field *field; + ha_spider *spider; + spider_string *alias; + spider_field_holder *next; +} SPIDER_FIELD_HOLDER; + +typedef struct spider_field_chain +{ + spider_field_holder *field_holder; + spider_field_chain *next; +} SPIDER_FIELD_CHAIN; + +class spider_fields +{ + uint dbton_count; + uint current_dbton_num; + uint dbton_ids[SPIDER_DBTON_SIZE]; + uint table_count; + uint current_table_num; + SPIDER_TABLE_HOLDER *table_holder; + SPIDER_LINK_IDX_CHAIN *first_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *last_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *current_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *first_ok_link_idx_chain; + SPIDER_CONN_HOLDER *first_conn_holder; + SPIDER_CONN_HOLDER *last_conn_holder; + SPIDER_CONN_HOLDER *current_conn_holder; + SPIDER_FIELD_HOLDER *first_field_holder; + SPIDER_FIELD_HOLDER *last_field_holder; + SPIDER_FIELD_HOLDER *current_field_holder; + SPIDER_FIELD_CHAIN *first_field_chain; + SPIDER_FIELD_CHAIN *last_field_chain; + SPIDER_FIELD_CHAIN *current_field_chain; + Field **first_field_ptr; + Field **current_field_ptr; +public: + spider_fields(); + virtual ~spider_fields(); + void add_dbton_id( + uint dbton_id_arg + ); + void set_pos_to_first_dbton_id(); + uint get_next_dbton_id(); + int make_link_idx_chain( + int link_status + ); + SPIDER_LINK_IDX_CHAIN *create_link_idx_chain(); + void set_pos_to_first_link_idx_chain(); + SPIDER_LINK_IDX_CHAIN *get_next_link_idx_chain(); + SPIDER_LINK_IDX_HOLDER *get_dup_link_idx_holder( + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder, + SPIDER_LINK_IDX_HOLDER *current + ); + bool check_link_ok_chain(); + bool is_first_link_ok_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + int get_ok_link_idx(); + void set_first_link_idx(); + int add_link_idx( + SPIDER_CONN_HOLDER *conn_holder_arg, + ha_spider *spider_arg, + int link_idx + ); + SPIDER_LINK_IDX_HOLDER *create_link_idx_holder(); + void set_pos_to_first_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + SPIDER_LINK_IDX_HOLDER *get_next_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + SPIDER_CONN_HOLDER *add_conn( + SPIDER_CONN *conn_arg, + long access_balance + ); + SPIDER_CONN_HOLDER *create_conn_holder(); + void set_pos_to_first_conn_holder(); + SPIDER_CONN_HOLDER *get_next_conn_holder(); + bool has_conn_holder(); + void clear_conn_holder_from_conn(); + bool check_conn_same_conn( + SPIDER_CONN *conn_arg + ); + bool remove_conn_if_not_checked(); + void check_support_dbton( + uchar *dbton_bitmap + ); + void choose_a_conn(); + void free_conn_holder( + SPIDER_CONN_HOLDER *conn_holder_arg + ); + SPIDER_TABLE_HOLDER *add_table( + ha_spider *spider_arg + ); + bool all_query_fields_are_query_table_members(); + int create_table_holder( + uint table_count_arg + ); + void set_pos_to_first_table_holder(); + SPIDER_TABLE_HOLDER *get_next_table_holder(); + SPIDER_TABLE_HOLDER *get_table_holder(TABLE *table); + uint get_table_count(); + int add_field(Field *field_arg); + SPIDER_FIELD_HOLDER *create_field_holder(); + void set_pos_to_first_field_holder(); + SPIDER_FIELD_HOLDER *get_next_field_holder(); + SPIDER_FIELD_CHAIN *create_field_chain(); + void set_pos_to_first_field_chain(); + SPIDER_FIELD_CHAIN *get_next_field_chain(); + void set_field_ptr(Field **field_arg); + Field **get_next_field_ptr(); + int ping_table_mon_from_table( + SPIDER_LINK_IDX_CHAIN *link_idx_chain + ); +}; + +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: + uint dbton_id; + spider_db_util() = default; + virtual ~spider_db_util() = default; + 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 int append_escaped_name( + spider_string *str, + const char *name, + uint name_length + ) = 0; + virtual int append_escaped_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, + bool is_like, + 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_wait_timeout( + spider_string *str, + int wait_timeout + ) = 0; + virtual int append_sql_mode( + spider_string *str, + sql_mode_t sql_mode + ) = 0; + virtual int append_time_zone( + spider_string *str, + Time_zone *time_zone + ) = 0; + virtual int append_loop_check( + spider_string *str, + SPIDER_CONN *conn + ); + 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, + bool use_fields, + spider_fields *fields + ) = 0; + virtual int open_item_sum_func( + Item_sum *item_sum, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ) = 0; + virtual int append_escaped_util( + spider_string *to, + String *from + ) = 0; + virtual int append_from_and_tables( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + uint table_count + ) = 0; + virtual int reappend_tables( + spider_fields *fields, + SPIDER_LINK_IDX_CHAIN *link_idx_chain, + spider_string *str + ) = 0; + virtual int append_where( + spider_string *str + ) = 0; + virtual int append_having( + spider_string *str + ) = 0; + virtual bool tables_on_different_db_are_joinable(); + virtual bool socket_has_default_value(); + virtual bool database_has_default_value(); + virtual bool default_file_has_default_value(); + virtual bool host_has_default_value(); + virtual bool port_has_default_value(); + virtual bool append_charset_name_before_string(); + virtual uint limit_mode(); +}; + +class spider_db_row +{ +public: + uint dbton_id; + SPIDER_DB_ROW *next_pos; + spider_db_row(uint in_dbton_id) : dbton_id(in_dbton_id), next_pos(NULL) {} + virtual ~spider_db_row() = default; + 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 my_decimal *val_decimal( + my_decimal *decimal_value, + CHARSET_INFO *access_charset + ) = 0; + virtual SPIDER_DB_ROW *clone() = 0; + virtual int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ) = 0; + virtual uint get_byte_size() = 0; +}; + +class spider_db_result_buffer +{ +public: + spider_db_result_buffer() = default; + virtual ~spider_db_result_buffer() = default; + virtual void clear() = 0; + virtual bool check_size( + longlong size + ) = 0; +}; + +class spider_db_result +{ +public: + SPIDER_DB_CONN *db_conn; + uint dbton_id; + spider_db_result(SPIDER_DB_CONN *in_db_conn); + virtual ~spider_db_result() = default; + virtual void set_limit(longlong value) {} + 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_statistics &stat + ) = 0; + virtual int fetch_table_records( + int mode, + ha_rows &records + ) = 0; + virtual int fetch_table_checksum( + ha_spider *spider + ); + 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; + 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; + virtual int fetch_table_for_discover_table_structure( + spider_string *str, + SPIDER_SHARE *spider_share, + CHARSET_INFO *access_charset + ) = 0; + virtual uint limit_mode(); +}; + +class spider_db_conn +{ +public: + SPIDER_CONN *conn; + uint dbton_id; + spider_db_conn( + SPIDER_CONN *in_conn + ); + virtual ~spider_db_conn() = default; + virtual int init() = 0; + virtual void set_limit(longlong value) {} + 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( + ha_spider *spider, + st_spider_db_request_key *request_key, + int *error_num + ) = 0; + virtual int next_result() = 0; + virtual uint affected_rows() = 0; + virtual uint matched_rows() = 0; + virtual bool inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info + ) = 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_wait_timeout_in_bulk_sql() = 0; + virtual int set_wait_timeout( + int wait_timeout, + int *need_mon + ) = 0; + virtual bool set_sql_mode_in_bulk_sql() = 0; + virtual int set_sql_mode( + sql_mode_t sql_mode, + 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; + virtual bool set_loop_check_in_bulk_sql(); + virtual int set_loop_check( + int *need_mon + ); + virtual int fin_loop_check(); + virtual int show_master_status( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + int mode, + SPIDER_DB_RESULT **res1, + SPIDER_DB_RESULT **res2 + ) = 0; + 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 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; + virtual uint limit_mode(); +}; + +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: + uint dbton_id; + st_spider_share *spider_share; + spider_db_share( + st_spider_share *share, + uint dbton_id + ) : dbton_id(dbton_id), spider_share(share) {} + virtual ~spider_db_share() = default; + 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; + virtual int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ) = 0; + virtual bool checksum_support(); +}; + +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: + uint dbton_id; + ha_spider *spider; + spider_db_share *db_share; + int first_link_idx; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + bool strict_group_by; + bool no_where_cond; + spider_db_handler(ha_spider *spider, spider_db_share *db_share) : + dbton_id(db_share->dbton_id), spider(spider), db_share(db_share), + first_link_idx(-1) {} + virtual ~spider_db_handler() = default; + virtual int init() = 0; + virtual int append_index_hint( + spider_string *str, + int link_idx, + ulong sql_type + ) = 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_union_table_and_sql_for_bka( + const key_range *start_key + ) = 0; + virtual int reuse_union_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; + virtual int append_update_set_part() = 0; + 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; + virtual int append_select_part( + ulong sql_type + ) = 0; + virtual int append_select( + spider_string *str, + 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_union_table_connector_part( + ulong sql_type + ) = 0; + virtual int append_union_table_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_column_values_with_name_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, + bool tgt_final + ) = 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 int append_sum_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_group_by_part( + const char *alias, + uint alias_length, + 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_multi_range_cnt_with_name_part( + ulong sql_type, + uint multi_range_cnt + ) = 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( + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + int link_idx + ) = 0; + virtual bool is_sole_projection_field( + uint16 field_index + ) = 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; + virtual int set_sql_for_exec( + ulong sql_type, + int link_idx, + SPIDER_LINK_IDX_CHAIN *link_idx_chain + ) = 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 checksum_table( + int link_idx + ); + virtual int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ) = 0; + virtual ha_rows explain_select( + const key_range *start_key, + const 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 sync_from_clone_source( + spider_db_handler *dbton_hdl + ) = 0; + virtual bool minimum_select_bit_is_set( + uint field_index + ) = 0; + virtual void copy_minimum_select_bitmap( + uchar *bitmap + ) = 0; + virtual int init_union_table_name_pos() = 0; + virtual int set_union_table_name_pos() = 0; + virtual int reset_union_table_name( + spider_string *str, + int link_idx, + ulong sql_type + ) = 0; + virtual int append_from_and_tables_part( + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int reappend_tables_part( + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_where_part( + ulong sql_type + ) = 0; + virtual int append_having_part( + ulong sql_type + ) = 0; + virtual int append_item_type_part( + Item *item, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_list_item_select_part( + List *select, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_group_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_order_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual bool check_direct_update( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); + virtual bool check_direct_delete( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); +}; + +class spider_db_copy_table +{ +public: + uint dbton_id; + spider_db_share *db_share; + spider_db_copy_table(spider_db_share *db_share) : + dbton_id(db_share->dbton_id), db_share(db_share) {} + virtual ~spider_db_copy_table() = default; + 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 +}; + +#define SPIDER_MATURITY_UNKNOWN 0 +#define SPIDER_MATURITY_EXPERIMENTAL 1 +#define SPIDER_MATURITY_ALPHA 2 +#define SPIDER_MATURITY_BETA 3 +#define SPIDER_MATURITY_GAMMA 4 +#define SPIDER_MATURITY_STABLE 5 + +static const LEX_CSTRING maturity_name[] = +{ + { STRING_WITH_LEN("Unknown") }, + { STRING_WITH_LEN("Experimental") }, + { STRING_WITH_LEN("Alpha") }, + { STRING_WITH_LEN("Beta") }, + { STRING_WITH_LEN("Gamma") }, + { STRING_WITH_LEN("Stable") } +}; + +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); + bool (*support_direct_join)(); + spider_db_util *db_util; + const char *descr; + const char *version_info; + unsigned int maturity; +} SPIDER_DBTON; + +typedef struct st_spider_position +{ + SPIDER_DB_ROW *row; + uint pos_mode; + bool use_position; + bool mrr_with_cnt; + bool direct_aggregate; + 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 +{ + uint dbton_id; + SPIDER_DB_RESULT *result; + volatile + st_spider_result *prev; + volatile + 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; + bool first_pos_use_position; + bool tmp_tbl_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 +{ + volatile + SPIDER_RESULT *first; + volatile + SPIDER_RESULT *last; + volatile + SPIDER_RESULT *current; + KEY *key_info; + int key_order; + spider_string *sqls; + int ha_read_kind; + bool use_union; + bool use_both_key; + const key_range *end_key; + 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; + longlong quick_page_byte; + 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; + /* the limit_offeset, without where condition */ + bool direct_limit_offset; + bool direct_distinct; + bool direct_aggregate; + bool snap_mrr_with_cnt; + bool snap_direct_aggregate; + SPIDER_DB_ROW *snap_row; + bool in_cmp_ref; + 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; + int *casual_read; + /* 0:nomal 1:store 2:store end */ + volatile + int quick_phase; + bool keyread; + TABLE *table; + 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 + 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 00000000..e0dffe57 --- /dev/null +++ b/storage/spider/spd_db_mysql.cc @@ -0,0 +1,16182 @@ +/* Copyright (C) 2012-2018 Kentoku Shiba + Copyright (c) 2020, 2022, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#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" +#include "sql_select.h" +#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_utf8mb3_bin; +extern bool volatile *spd_abort_loop; + +extern handlerton *spider_hton_ptr; +extern pthread_mutex_t spider_open_conn_mutex; +extern HASH spider_open_connections; +extern HASH spider_ipport_conns; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern const char spider_dig_upper[]; +extern const char **spd_mysqld_unix_port; +extern uint *spd_mysqld_port; + +spider_db_mysql_util spider_db_mysql_utility; +spider_db_mariadb_util spider_db_mariadb_utility; + +#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_WAIT_TIMEOUT_STR "set session wait_timeout = " +#define SPIDER_SQL_WAIT_TIMEOUT_LEN sizeof(SPIDER_SQL_WAIT_TIMEOUT_STR) - 1 + +#define SPIDER_SQL_SQL_MODE_STR "set session sql_mode = '" +#define SPIDER_SQL_SQL_MODE_LEN sizeof(SPIDER_SQL_SQL_MODE_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_SET_USER_VAL_STR "set @`" +#define SPIDER_SQL_SET_USER_VAL_LEN sizeof(SPIDER_SQL_SET_USER_VAL_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_LEFT_JOIN_STR " left join " +#define SPIDER_SQL_LEFT_JOIN_LEN (sizeof(SPIDER_SQL_LEFT_JOIN_STR) - 1) +#define SPIDER_SQL_RIGHT_JOIN_STR " right join " +#define SPIDER_SQL_RIGHT_JOIN_LEN (sizeof(SPIDER_SQL_RIGHT_JOIN_STR) - 1) +#define SPIDER_SQL_JOIN_STR " join " +#define SPIDER_SQL_JOIN_LEN (sizeof(SPIDER_SQL_JOIN_STR) - 1) +#define SPIDER_SQL_ON_STR " on " +#define SPIDER_SQL_ON_LEN (sizeof(SPIDER_SQL_ON_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`,`checksum` 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_SHOW_WARNINGS_STR "show warnings" +#define SPIDER_SQL_SHOW_WARNINGS_LEN sizeof(SPIDER_SQL_SHOW_WARNINGS_STR) - 1 + +#define SPIDER_SQL_SHOW_MASTER_STATUS_STR "show master status" +#define SPIDER_SQL_SHOW_MASTER_STATUS_LEN sizeof(SPIDER_SQL_SHOW_MASTER_STATUS_STR) - 1 +#define SPIDER_SQL_BINLOG_GTID_POS_STR "select binlog_gtid_pos" +#define SPIDER_SQL_BINLOG_GTID_POS_LEN sizeof(SPIDER_SQL_BINLOG_GTID_POS_STR) - 1 + +#define SPIDER_SQL_SHOW_COLUMNS_STR "show columns from " +#define SPIDER_SQL_SHOW_COLUMNS_LEN sizeof(SPIDER_SQL_SHOW_COLUMNS_STR) - 1 +#define SPIDER_SQL_SELECT_COLUMNS_STR "select `column_name`,`column_default`,`is_nullable`,`character_set_name`,`collation_name`,`column_type`,`extra` from `information_schema`.`columns` where `table_schema` = " +#define SPIDER_SQL_SELECT_COLUMNS_LEN sizeof(SPIDER_SQL_SELECT_COLUMNS_STR) - 1 + +#define SPIDER_SQL_AUTO_INCREMENT_STR " auto_increment" +#define SPIDER_SQL_AUTO_INCREMENT_LEN sizeof(SPIDER_SQL_AUTO_INCREMENT_STR) - 1 +#define SPIDER_SQL_ORDINAL_POSITION_STR "ordinal_position" +#define SPIDER_SQL_ORDINAL_POSITION_LEN sizeof(SPIDER_SQL_ORDINAL_POSITION_STR) - 1 +#define SPIDER_SQL_FULLTEXT_STR "fulltext" +#define SPIDER_SQL_FULLTEXT_LEN sizeof(SPIDER_SQL_FULLTEXT_STR) - 1 +#define SPIDER_SQL_SPATIAL_STR "spatial" +#define SPIDER_SQL_SPATIAL_LEN sizeof(SPIDER_SQL_SPATIAL_STR) - 1 +#define SPIDER_SQL_USING_HASH_STR " using hash" +#define SPIDER_SQL_USING_HASH_LEN sizeof(SPIDER_SQL_USING_HASH_STR) - 1 + +#define SPIDER_SQL_SHOW_RECORDS_RECORDS_POS 0 +#define SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS 8 + +#define SPIDER_SQL_CHECKSUM_CHECKSUM_POS 1 +#define SPIDER_SQL_CHECKSUM_TABLE_STR "checksum table " +#define SPIDER_SQL_CHECKSUM_TABLE_LEN (sizeof(SPIDER_SQL_CHECKSUM_TABLE_STR) - 1) + +#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) + +#define SPIDER_SQL_DIRECT_INSERT_KIND_INSERT 0 +#define SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE 1 +#define SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE 2 +#define SPIDER_SQL_DIRECT_INSERT_KIND_DUP_UPDATE 3 + +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" +}; + +/* UTC time zone for timestamp columns */ +extern Time_zone *UTC; + +int spider_mysql_init() +{ + DBUG_ENTER("spider_mysql_init"); + DBUG_RETURN(0); +} + +int spider_mariadb_init() +{ + DBUG_ENTER("spider_mariadb_init"); + DBUG_RETURN(0); +} + +int spider_mysql_deinit() +{ + DBUG_ENTER("spider_mysql_deinit"); + DBUG_RETURN(0); +} + +int spider_mariadb_deinit() +{ + DBUG_ENTER("spider_mariadb_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_share *spider_mariadb_create_share( + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_mariadb_create_share"); + DBUG_RETURN(new spider_mariadb_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_mbase_share *) db_share)); +} + +spider_db_handler *spider_mariadb_create_handler( + ha_spider *spider, + spider_db_share *db_share +) { + DBUG_ENTER("spider_mariadb_create_handler"); + DBUG_RETURN(new spider_mariadb_handler(spider, + (spider_mbase_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_mbase_share *) db_share)); +} + +spider_db_copy_table *spider_mariadb_create_copy_table( + spider_db_share *db_share +) { + DBUG_ENTER("spider_mariadb_create_copy_table"); + DBUG_RETURN(new spider_mariadb_copy_table( + (spider_mbase_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_CONN *spider_mariadb_create_conn( + SPIDER_CONN *conn +) { + DBUG_ENTER("spider_mariadb_create_conn"); + DBUG_RETURN(new spider_db_mariadb(conn)); +} + +bool spider_mysql_support_direct_join( +) { + DBUG_ENTER("spider_mysql_support_direct_join"); + DBUG_RETURN(TRUE); +} + +bool spider_mariadb_support_direct_join( +) { + DBUG_ENTER("spider_mariadb_support_direct_join"); + DBUG_RETURN(TRUE); +} + +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_mysql_support_direct_join, + &spider_db_mysql_utility, + "For communicating to MySQL using native protocol", + "3.4.0", + SPIDER_MATURITY_STABLE +}; + +SPIDER_DBTON spider_dbton_mariadb = { + 0, + SPIDER_DB_WRAPPER_MARIADB, + SPIDER_DB_ACCESS_TYPE_SQL, + spider_mariadb_init, + spider_mariadb_deinit, + spider_mariadb_create_share, + spider_mariadb_create_handler, + spider_mariadb_create_copy_table, + spider_mariadb_create_conn, + spider_mariadb_support_direct_join, + &spider_db_mariadb_utility, + "For communicating to MariaDB using native protocol", + "3.4.0", + SPIDER_MATURITY_STABLE +}; + +spider_db_mbase_row::spider_db_mbase_row( + uint dbton_id +) : spider_db_row(dbton_id), + row(NULL), lengths(NULL), cloned(FALSE) +{ + DBUG_ENTER("spider_db_mbase_row::spider_db_mbase_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_row::spider_db_mysql_row() : + spider_db_mbase_row(spider_db_mysql_utility.dbton_id) +{ + DBUG_ENTER("spider_db_mysql_row::spider_db_mysql_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb_row::spider_db_mariadb_row() : + spider_db_mbase_row(spider_db_mariadb_utility.dbton_id) +{ + DBUG_ENTER("spider_db_mariadb_row::spider_db_mariadb_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mbase_row::~spider_db_mbase_row() +{ + DBUG_ENTER("spider_db_mbase_row::~spider_db_mbase_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (cloned) + { + spider_free(spider_current_trx, row_first, MYF(0)); + } + 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)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb_row::~spider_db_mariadb_row() +{ + DBUG_ENTER("spider_db_mariadb_row::~spider_db_mariadb_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mbase_row::store_to_field( + Field *field, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_mbase_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_mbase_row::append_to_str( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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_mbase_row::append_escaped_to_str( + spider_string *str, + uint dbton_id +) { + DBUG_ENTER("spider_db_mbase_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_mbase_row::first() +{ + DBUG_ENTER("spider_db_mbase_row::first"); + DBUG_PRINT("info",("spider this=%p", this)); + row = row_first; + lengths = lengths_first; + DBUG_VOID_RETURN; +} + +void spider_db_mbase_row::next() +{ + DBUG_ENTER("spider_db_mbase_row::next"); + DBUG_PRINT("info",("spider this=%p", this)); + row++; + lengths++; + DBUG_VOID_RETURN; +} + +bool spider_db_mbase_row::is_null() +{ + DBUG_ENTER("spider_db_mbase_row::is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(!(*row)); +} + +int spider_db_mbase_row::val_int() +{ + DBUG_ENTER("spider_db_mbase_row::val_int"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(*row ? atoi(*row) : 0); +} + +double spider_db_mbase_row::val_real() +{ + DBUG_ENTER("spider_db_mbase_row::val_real"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(*row ? my_atof(*row) : 0.0); +} + +my_decimal *spider_db_mbase_row::val_decimal( + my_decimal *decimal_value, + CHARSET_INFO *access_charset +) { + DBUG_ENTER("spider_db_mbase_row::val_decimal"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!*row) + DBUG_RETURN(NULL); + +#ifdef SPIDER_HAS_DECIMAL_OPERATION_RESULTS_VALUE_TYPE + decimal_operation_results(str2my_decimal(0, *row, *lengths, access_charset, + decimal_value), "", ""); +#else + decimal_operation_results(str2my_decimal(0, *row, *lengths, access_charset, + decimal_value)); +#endif + + DBUG_RETURN(decimal_value); +} + +SPIDER_DB_ROW *spider_db_mbase_row::clone() +{ + spider_db_mbase_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_mbase_row::clone"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(clone_row = new spider_db_mbase_row(dbton_id))) + { + DBUG_RETURN(NULL); + } + if (!record_size) + { + row_size = field_count; + for (i = 0; i < field_count; i++) + { + row_size += *tmp_lengths; + tmp_lengths++; + } + record_size = row_size - field_count; + } else { + row_size = record_size + field_count; + } + if (!spider_bulk_malloc( + spider_current_trx, 29, MYF(MY_WME), + &clone_row->row, (uint) (sizeof(char*) * (field_count + 1)), + &tmp_char, (uint) (row_size), + &clone_row->lengths, (uint) (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->row[field_count] = NULL; + clone_row->field_count = field_count; + clone_row->record_size = record_size; + 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_mbase_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_mbase_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])); +} + +uint spider_db_mbase_row::get_byte_size() +{ + ulong *tmp_lengths = lengths_first; + uint i; + DBUG_ENTER("spider_db_mbase_row::get_byte_size"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!record_size) + { + for (i = 0; i < field_count; i++) + { + record_size += *tmp_lengths; + tmp_lengths++; + } + } + DBUG_RETURN(record_size); +} + +spider_db_mbase_result::spider_db_mbase_result( + SPIDER_DB_CONN *in_db_conn +) : spider_db_result(in_db_conn), + db_result(NULL), row(in_db_conn->dbton_id) +{ + DBUG_ENTER("spider_db_mbase_result::spider_db_mbase_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_result::spider_db_mysql_result( + SPIDER_DB_CONN *in_db_conn +) : spider_db_mbase_result(in_db_conn) +{ + DBUG_ENTER("spider_db_mysql_result::spider_db_mysql_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb_result::spider_db_mariadb_result( + SPIDER_DB_CONN *in_db_conn +) : spider_db_mbase_result(in_db_conn) +{ + DBUG_ENTER("spider_db_mariadb_result::spider_db_mariadb_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mbase_result::~spider_db_mbase_result() +{ + DBUG_ENTER("spider_db_mbase_result::~spider_db_mbase_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if (db_result) + { + free_result(); + } + 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)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb_result::~spider_db_mariadb_result() +{ + DBUG_ENTER("spider_db_mariadb_result::~spider_db_mariadb_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +bool spider_db_mbase_result::has_result() +{ + DBUG_ENTER("spider_db_mbase_result::has_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(db_result); +} + +void spider_db_mbase_result::free_result() +{ + DBUG_ENTER("spider_db_mbase_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_mbase_result::current_row() +{ + DBUG_ENTER("spider_db_mbase_result::current_row"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_DB_ROW *) row.clone()); +} + +SPIDER_DB_ROW *spider_db_mbase_result::fetch_row() +{ + DBUG_ENTER("spider_db_mbase_result::fetch_row"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(row.row = mysql_fetch_row(db_result))) + { + if (mysql_errno(((spider_db_mbase *) db_conn)->db_conn)) + { + store_error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn); + my_message(store_error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + } else + 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[row.field_count] = NULL; + row.row_first = row.row; + row.lengths_first = row.lengths; + row.record_size = 0; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_mbase_result::fetch_row_from_result_buffer( + spider_db_result_buffer *spider_res_buf +) { + DBUG_ENTER("spider_db_mbase_result::fetch_row_from_result_buffer"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(row.row = mysql_fetch_row(db_result))) + { + if (mysql_errno(((spider_db_mbase *) db_conn)->db_conn)) + { + store_error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn); + my_message(store_error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + } else + 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; + row.record_size = 0; + DBUG_RETURN((SPIDER_DB_ROW *) &row); +} + +SPIDER_DB_ROW *spider_db_mbase_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_mbase_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; + row.record_size = tmp_str2.length(); + 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_mbase_result::fetch_table_status( + int mode, + ha_statistics &stat +) { + int error_num; + MYSQL_ROW mysql_row; + MYSQL_TIME mysql_time; + uint not_used_uint; +#ifdef SPIDER_HAS_TIME_STATUS + MYSQL_TIME_STATUS time_status; +#else + int time_status; +#endif + long not_used_long; + DBUG_ENTER("spider_db_mbase_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")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); + } + if (mode == 1) + { + /* Ok to test for 18 fields as all new fields are added last */ + if (num_fields() < 18) + { + DBUG_PRINT("info",("spider field_count < 18")); + DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM); + } + + if (mysql_row[4]) + stat.records = + (ha_rows) my_strtoll10(mysql_row[4], (char**) NULL, &error_num); + else + stat.records = (ha_rows) 0; + DBUG_PRINT("info", + ("spider records=%lld", stat.records)); + if (mysql_row[5]) + stat.mean_rec_length = + (ulong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num); + else + stat.mean_rec_length = 0; + DBUG_PRINT("info", + ("spider mean_rec_length=%lu", stat.mean_rec_length)); + if (mysql_row[6]) + stat.data_file_length = + (ulonglong) my_strtoll10(mysql_row[6], (char**) NULL, &error_num); + else + stat.data_file_length = 0; + DBUG_PRINT("info", + ("spider data_file_length=%lld", stat.data_file_length)); + if (mysql_row[7]) + stat.max_data_file_length = + (ulonglong) my_strtoll10(mysql_row[7], (char**) NULL, &error_num); + else + stat.max_data_file_length = 0; + DBUG_PRINT("info", + ("spider max_data_file_length=%lld", stat.max_data_file_length)); + if (mysql_row[8]) + stat.index_file_length = + (ulonglong) my_strtoll10(mysql_row[8], (char**) NULL, &error_num); + else + stat.index_file_length = 0; + DBUG_PRINT("info", + ("spider index_file_length=%lld", stat.index_file_length)); + if (mysql_row[10]) + stat.auto_increment_value = + (ulonglong) my_strtoll10(mysql_row[10], (char**) NULL, &error_num); + else + stat.auto_increment_value = 1; + DBUG_PRINT("info", + ("spider auto_increment_value=%lld", stat.auto_increment_value)); + if (mysql_row[11]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[11], strlen(mysql_row[11]), + &mysql_time, 0, &time_status); + stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.create_time = (time_t) 0; +#ifdef DBUG_TRACE + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.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]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[12], strlen(mysql_row[12]), + &mysql_time, 0, &time_status); + stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.update_time = (time_t) 0; +#ifndef DBUG_OFF + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.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]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[13], strlen(mysql_row[13]), + &mysql_time, 0, &time_status); + stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.check_time = (time_t) 0; +#ifdef DBUG_TRACE + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.check_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider check_time=%s", buf)); + } +#endif + if (mysql_row[15]) + { + stat.checksum_null = FALSE; + stat.checksum = + (ha_checksum) my_strtoll10(mysql_row[15], (char**) NULL, &error_num); + DBUG_PRINT("info", ("spider checksum=%lu", (ulong) stat.checksum)); + } else { + stat.checksum_null = TRUE; + stat.checksum = (ha_checksum) 0; + DBUG_PRINT("info", ("spider checksum is null")); + } + } else { + if (mysql_row[0]) + stat.records = + (ha_rows) my_strtoll10(mysql_row[0], (char**) NULL, &error_num); + else + stat.records = (ha_rows) 0; + DBUG_PRINT("info", + ("spider records=%lld", stat.records)); + if (mysql_row[1]) + stat.mean_rec_length = + (ulong) my_strtoll10(mysql_row[1], (char**) NULL, &error_num); + else + stat.mean_rec_length = 0; + DBUG_PRINT("info", + ("spider mean_rec_length=%lu", stat.mean_rec_length)); + if (mysql_row[2]) + stat.data_file_length = + (ulonglong) my_strtoll10(mysql_row[2], (char**) NULL, &error_num); + else + stat.data_file_length = 0; + DBUG_PRINT("info", + ("spider data_file_length=%lld", stat.data_file_length)); + if (mysql_row[3]) + stat.max_data_file_length = + (ulonglong) my_strtoll10(mysql_row[3], (char**) NULL, &error_num); + else + stat.max_data_file_length = 0; + DBUG_PRINT("info", + ("spider max_data_file_length=%lld", stat.max_data_file_length)); + if (mysql_row[4]) + stat.index_file_length = + (ulonglong) my_strtoll10(mysql_row[4], (char**) NULL, &error_num); + else + stat.index_file_length = 0; + DBUG_PRINT("info", + ("spider index_file_length=%lld", stat.index_file_length)); + if (mysql_row[5]) + stat.auto_increment_value = + (ulonglong) my_strtoll10(mysql_row[5], (char**) NULL, &error_num); + else + stat.auto_increment_value = 1; + DBUG_PRINT("info", + ("spider auto_increment_value=%lld", stat.auto_increment_value)); + if (mysql_row[6]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[6], strlen(mysql_row[6]), + &mysql_time, 0, &time_status); + stat.create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.create_time = (time_t) 0; +#ifdef DBUG_TRACE + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.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]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[7], strlen(mysql_row[7]), + &mysql_time, 0, &time_status); + stat.update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.update_time = (time_t) 0; +#ifdef DBUG_TRACE + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.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]) + { +#ifdef SPIDER_HAS_TIME_STATUS + my_time_status_init(&time_status); +#endif + SPIDER_str_to_datetime(mysql_row[8], strlen(mysql_row[8]), + &mysql_time, 0, &time_status); + stat.check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + } else + stat.check_time = (time_t) 0; +#ifdef DBUG_TRACE + { + struct tm *ts, tmp_ts; + char buf[80]; + ts = localtime_r(&stat.check_time, &tmp_ts); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); + DBUG_PRINT("info",("spider check_time=%s", buf)); + } +#endif + if (mysql_row[9]) + { + stat.checksum_null = FALSE; + stat.checksum = + (ha_checksum) my_strtoll10(mysql_row[9], (char**) NULL, &error_num); + DBUG_PRINT("info", ("spider checksum=%lu", (ulong) stat.checksum)); + } else { + stat.checksum_null = TRUE; + stat.checksum = (ha_checksum) 0; + DBUG_PRINT("info", ("spider checksum is null")); + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_simple_action( + uint simple_action, + uint position, + void *param +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_result::fetch_simple_action"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + if (num_fields() <= position) + { + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + { + ha_rows *records = (ha_rows *) param; + if (mysql_row[position]) + { + *records = + (ha_rows) my_strtoll10(mysql_row[position], (char**) NULL, + &error_num); + } else { + *records = (ha_rows) 0; + } + DBUG_PRINT("info", ("spider records=%lld", *records)); + break; + } + case SPIDER_SIMPLE_CHECKSUM_TABLE: + { + ha_spider *spider = (ha_spider *) param; + if (mysql_row[position]) + { + spider->checksum_val = + (ha_checksum) my_strtoll10(mysql_row[position], (char**) NULL, + &error_num); + DBUG_PRINT("info", ("spider checksum=%llu", (ulonglong)spider->checksum_val)); + spider->checksum_null = FALSE; + } else { + spider->checksum_null = TRUE; + DBUG_PRINT("info", ("spider checksum is null")); + } + break; + } + default: + DBUG_ASSERT(0); + break; + } + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_table_records( + int mode, + ha_rows &records +) { + DBUG_ENTER("spider_db_mbase_result::fetch_table_records"); + DBUG_PRINT("info",("spider this=%p", this)); + if (mode == 1) + { + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS, + SPIDER_SQL_SHOW_RECORDS_RECORDS_POS, &records)); + } else { + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_RECORDS, + SPIDER_SQL_EXPLAIN_SELECT_RECORDS_POS, &records)); + } +} + +int spider_db_mbase_result::fetch_table_checksum( + ha_spider *spider +) { + DBUG_ENTER("spider_db_mbase_result::fetch_table_checksum"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(fetch_simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, + SPIDER_SQL_CHECKSUM_CHECKSUM_POS, spider)); +} + +int spider_db_mbase_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_mbase_result::fetch_table_cardinality"); + DBUG_PRINT("info",("spider this=%p", this)); + memset((uchar *) cardinality_upd, 0, sizeof(uchar) * bitmap_size); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + /* no index */ + DBUG_RETURN(0); + } + if (mode == 1) + { + uint num_fields = this->num_fields(); + if (num_fields < 12 || num_fields > 14) + { + 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); + } + } + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_table_mon_status( + int &status +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_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")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + 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); +} + +int spider_db_mbase_result::fetch_show_master_status( + const char **binlog_file_name, + const char **binlog_pos +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_result::fetch_show_master_status"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + if (num_fields() != 4) + { + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + + *binlog_file_name = mysql_row[0]; + DBUG_PRINT("info",("spider binlog_file_name=%s", *binlog_file_name)); + *binlog_pos = mysql_row[1]; + DBUG_PRINT("info",("spider binlog_pos=%s", *binlog_pos)); + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_select_binlog_gtid_pos( + const char **gtid_pos +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_result::fetch_select_binlog_gtid_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!(mysql_row = mysql_fetch_row(db_result))) + { + DBUG_PRINT("info",("spider fetch row is null")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + if (num_fields() != 1) + { + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + + *gtid_pos = mysql_row[0]; + DBUG_PRINT("info",("spider gtid_pos=%s", *gtid_pos)); + DBUG_RETURN(0); +} + +longlong spider_db_mbase_result::num_rows() +{ + DBUG_ENTER("spider_db_mbase_result::num_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((longlong) mysql_num_rows(db_result)); +} + +uint spider_db_mbase_result::num_fields() +{ + DBUG_ENTER("spider_db_mbase_result::num_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(mysql_num_fields(db_result)); +} + +void spider_db_mbase_result::move_to_pos( + longlong pos +) { + DBUG_ENTER("spider_db_mbase_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_mbase_result::get_errno() +{ + DBUG_ENTER("spider_db_mbase_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); +} + +int spider_db_mbase_result::fetch_columns_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + int error_num; + uint length; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_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")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (num_fields() != 7) + { + DBUG_PRINT("info",("spider num_fields != 7")); + 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[5], strlen(mysql_row[5]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (mysql_row[3]) + { + length = strlen(mysql_row[3]); + if (str->reserve(SPIDER_SQL_CHARACTER_SET_LEN + length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CHARACTER_SET_STR, SPIDER_SQL_CHARACTER_SET_LEN); + str->q_append(mysql_row[3], length); + } + if (mysql_row[4]) + { + length = strlen(mysql_row[4]); + if (str->reserve(SPIDER_SQL_COLLATE_LEN + length)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str->q_append(mysql_row[4], length); + } + 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[1]) + { + 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->append(mysql_row[1], strlen(mysql_row[1]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + } 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[1]) + { + if (str->append(mysql_row[1], strlen(mysql_row[1]), access_charset)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } 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 (mysql_row[6] && !strcmp(mysql_row[6], "auto_increment")) + { + if (str->reserve(SPIDER_SQL_AUTO_INCREMENT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_AUTO_INCREMENT_STR, SPIDER_SQL_AUTO_INCREMENT_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))); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_index_for_discover_table_structure( + spider_string *str, + CHARSET_INFO *access_charset +) { + int error_num; + MYSQL_ROW mysql_row; + DBUG_ENTER("spider_db_mbase_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")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); + } + 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; + bool without_size = FALSE; + bool using_hash = FALSE; + do { + if (!strcmp(mysql_row[3], "1")) + { + without_size = FALSE; + if (first) + { + first = FALSE; + } else { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN + + (using_hash ? SPIDER_SQL_USING_HASH_LEN : 0))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + if (using_hash) + str->q_append(SPIDER_SQL_USING_HASH_STR, SPIDER_SQL_USING_HASH_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); + } else if (mysql_row[10] && !strcmp(mysql_row[10], "FULLTEXT")) + { + /* fulltext key */ + if (str->reserve(SPIDER_SQL_FULLTEXT_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_FULLTEXT_STR, SPIDER_SQL_FULLTEXT_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } else if (mysql_row[10] && !strcmp(mysql_row[10], "SPATIAL")) + { + /* spatial key */ + without_size = TRUE; + if (str->reserve(SPIDER_SQL_SPATIAL_LEN + SPIDER_SQL_SPACE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_SPATIAL_STR, SPIDER_SQL_SPATIAL_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] && !without_size) + { + 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] && !without_size) + { + 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); + } + } + if (mysql_row[10] && !strcmp(mysql_row[10], "HASH")) + using_hash = TRUE; + else + using_hash = FALSE; + } while ((mysql_row = mysql_fetch_row(db_result))); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + if (!first) + { + if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN + + (using_hash ? SPIDER_SQL_USING_HASH_LEN : 0))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + if (using_hash) + str->q_append(SPIDER_SQL_USING_HASH_STR, SPIDER_SQL_USING_HASH_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_result::fetch_table_for_discover_table_structure( + spider_string *str, + SPIDER_SHARE *spider_share, + CHARSET_INFO *access_charset +) { + int error_num; + MYSQL_ROW mysql_row; + myf utf8_flag= global_system_variables.old_behavior & + OLD_MODE_UTF8_IS_UTF8MB3 ? MY_UTF8_IS_UTF8MB3 : 0; + DBUG_ENTER("spider_db_mbase_result::fetch_table_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")); + if ((error_num = mysql_errno(((spider_db_mbase *) db_conn)->db_conn))) + { + my_message(error_num, + mysql_error(((spider_db_mbase *) db_conn)->db_conn), MYF(0)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + if (num_fields() < 18) + { + DBUG_PRINT("info",("spider num_fields != 18")); + my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + if (!mysql_row[14]) + { + DBUG_PRINT("info",("spider mysql_row[14] is null")); + my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0)); + DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); + } + DBUG_PRINT("info",("spider mysql_row[14]=%s", mysql_row[14])); + if (!spider_share->table_share->table_charset) + { + spider_share->table_share->table_charset = get_charset_by_name(mysql_row[14], + MYF(utf8_flag | MY_WME)); + } + DBUG_RETURN(0); +} + +spider_db_mbase::spider_db_mbase( + SPIDER_CONN *conn, + spider_db_mbase_util *spider_db_mbase_utility +) : spider_db_conn(conn), spider_db_mbase_utility(spider_db_mbase_utility), + lock_table_hash_inited(FALSE) +{ + DBUG_ENTER("spider_db_mbase::spider_db_mbase"); + DBUG_PRINT("info",("spider this=%p", this)); + db_conn = NULL; + DBUG_VOID_RETURN; +} + +spider_db_mysql::spider_db_mysql( + SPIDER_CONN *conn +) : spider_db_mbase(conn, &spider_db_mysql_utility) +{ + DBUG_ENTER("spider_db_mysql::spider_db_mysql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb::spider_db_mariadb( + SPIDER_CONN *conn +) : spider_db_mbase(conn, &spider_db_mariadb_utility) +{ + DBUG_ENTER("spider_db_mariadb::spider_db_mariadb"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mbase::~spider_db_mbase() +{ + DBUG_ENTER("spider_db_mbase::~spider_db_mbase"); + DBUG_PRINT("info",("spider this=%p", this)); + 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; +} + +spider_db_mysql::~spider_db_mysql() +{ + DBUG_ENTER("spider_db_mysql::~spider_db_mysql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb::~spider_db_mariadb() +{ + DBUG_ENTER("spider_db_mariadb::~spider_db_mariadb"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mbase::init() +{ + DBUG_ENTER("spider_db_mbase::init"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + my_hash_init(PSI_INSTRUMENT_ME, &lock_table_hash, spd_charset_utf8mb3_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; + + DBUG_RETURN(0); +} + +bool spider_db_mbase::is_connected() +{ + DBUG_ENTER("spider_db_mbase::is_connected"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(db_conn); +} + +void spider_db_mbase::bg_connect() +{ + DBUG_ENTER("spider_db_mbase::bg_connect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mbase::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_mbase::connect"); + DBUG_PRINT("info",("spider this=%p", this)); + while (TRUE) + { + THD *thd = current_thd; + DBUG_PRINT("info",("spider thd->killed=%s", + thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL")); + DBUG_PRINT("info",("spider abort_loop=%s", + *spd_abort_loop ? "TRUE" : "FALSE")); + if ( + (thd && thd->killed) || + *spd_abort_loop + ) { + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + + 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_options(db_conn, MYSQL_OPT_SSL_KEY, conn->tgt_ssl_key); + mysql_options(db_conn, MYSQL_OPT_SSL_CERT, conn->tgt_ssl_cert); + mysql_options(db_conn, MYSQL_OPT_SSL_CA, conn->tgt_ssl_ca); + mysql_options(db_conn, MYSQL_OPT_SSL_CAPATH, conn->tgt_ssl_capath); + mysql_options(db_conn, MYSQL_OPT_SSL_CIPHER, 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 (!spider_param_same_server_link(thd)) + { + if (!strcmp(tgt_host, my_localhost)) + { + if (!strcmp(tgt_socket, *spd_mysqld_unix_port)) + { + my_printf_error(ER_SPIDER_SAME_SERVER_LINK_NUM, + ER_SPIDER_SAME_SERVER_LINK_STR1, MYF(0), + tgt_host, tgt_socket); + DBUG_RETURN(ER_SPIDER_SAME_SERVER_LINK_NUM); + } + } else if (!strcmp(tgt_host, "127.0.0.1") || + !strcmp(tgt_host, glob_hostname)) + { + if (tgt_port == (long) *spd_mysqld_port) + { + my_printf_error(ER_SPIDER_SAME_SERVER_LINK_NUM, + ER_SPIDER_SAME_SERVER_LINK_STR2, MYF(0), + tgt_host, tgt_port); + DBUG_RETURN(ER_SPIDER_SAME_SERVER_LINK_NUM); + } + } + } + + if (connect_mutex) + pthread_mutex_lock(&spider_open_conn_mutex); + /* tgt_db not use */ + if ( + !spider_param_dry_access() && + !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(); + DBUG_PRINT("info",("spider thd->killed=%s", + thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL")); + DBUG_PRINT("info",("spider abort_loop=%s", + *spd_abort_loop ? "TRUE" : "FALSE")); + if ( + (thd && thd->killed) || + *spd_abort_loop + ) { + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + if ( + ( + error_num != CR_CONN_HOST_ERROR && + error_num != CR_CONNECTION_ERROR + ) || + !connect_retry_count + ) { + if (error_num == ER_CON_COUNT_ERROR) + { + *conn->need_mon = 0; + my_error(ER_CON_COUNT_ERROR, MYF(0)); + DBUG_RETURN(ER_CON_COUNT_ERROR); + } + *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 { +#ifdef SPIDER_NET_HAS_THD + db_conn->net.thd = NULL; +#endif + if (connect_mutex) + pthread_mutex_unlock(&spider_open_conn_mutex); + break; + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase::ping( +) { + DBUG_ENTER("spider_db_mbase::ping"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_dry_access()) + DBUG_RETURN(0); + DBUG_RETURN(simple_command(db_conn, COM_PING, 0, 0, 0)); +} + +void spider_db_mbase::bg_disconnect() +{ + DBUG_ENTER("spider_db_mbase::bg_disconnect"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +void spider_db_mbase::disconnect() +{ + DBUG_ENTER("spider_db_mbase::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_mbase::set_net_timeout() +{ + DBUG_ENTER("spider_db_mbase::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_mbase::exec_query( + const char *query, + uint length, + int quick_mode +) { + int error_num = 0; + uint log_result_errors = spider_param_log_result_errors(); + DBUG_ENTER("spider_db_mbase::exec_query"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_general_log()) + { + const char *tgt_str = conn->tgt_host; + uint32 tgt_len = conn->tgt_host_length; + spider_string tmp_query_str; + tmp_query_str.init_calc_mem(230); + if (tmp_query_str.reserve( + length + conn->tgt_wrapper_length + + tgt_len + (SPIDER_SQL_SPACE_LEN * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length); + tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + tmp_query_str.q_append(tgt_str, tgt_len); + tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + tmp_query_str.q_append(query, length); + general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(), + tmp_query_str.length()); + } + if (!spider_param_dry_access()) + { + error_num = mysql_real_query(db_conn, query, length); + } + if ( + (error_num && log_result_errors >= 1) || + (log_result_errors >= 2 && db_conn->warning_count > 0) || + (log_result_errors >= 4) + ) { + THD *thd = current_thd; + uint log_result_error_with_sql = spider_param_log_result_error_with_sql(); + if (log_result_error_with_sql) + { + time_t cur_time = (time_t) time((time_t*) 0); + struct tm lt; + struct tm *l_time = localtime_r(&cur_time, <); + spider_string tmp_query_str; + tmp_query_str.init_calc_mem(243); + uint query_length = thd->query_length(); + if ((log_result_error_with_sql & 2) && query_length) + { + Security_context *security_ctx = thd->security_ctx; + tmp_query_str.length(0); + if (tmp_query_str.reserve(query_length + 1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_query_str.q_append(thd->query(), query_length); + fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [RECV SPIDER SQL] " + "from [%s][%s] to %ld: " + "sql: %s\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, + security_ctx->user ? security_ctx->user : "system user", + security_ctx->host_or_ip, + (ulong) thd->thread_id, + tmp_query_str.c_ptr_safe()); + } + if (log_result_error_with_sql & 1) + { + tmp_query_str.length(0); + if (tmp_query_str.reserve(length + 1)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + tmp_query_str.q_append(query, length); + fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [SEND SPIDER SQL] " + "from %ld to [%s] %ld: " + "sql: %s\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, + (ulong) thd->thread_id, conn->tgt_host, (ulong) db_conn->thread_id, + tmp_query_str.c_ptr_safe()); + } + } + if (log_result_errors >= 2 && db_conn->warning_count > 0) + { + 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 [WARN SPIDER RESULT] " + "from [%s] %ld to %ld: " + "affected_rows: %llu id: %llu status: %u warning_count: %u\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, + conn->tgt_host, (ulong) db_conn->thread_id, (ulong) thd->thread_id, + db_conn->affected_rows, db_conn->insert_id, + db_conn->server_status, db_conn->warning_count); + if (spider_param_log_result_errors() >= 3) + fetch_and_print_warnings(l_time); + } else if (log_result_errors >= 4) + { + 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 [INFO SPIDER RESULT] " + "from [%s] %ld to %ld: " + "affected_rows: %llu id: %llu status: %u warning_count: %u\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, + conn->tgt_host, (ulong) db_conn->thread_id, (ulong) thd->thread_id, + db_conn->affected_rows, db_conn->insert_id, + db_conn->server_status, db_conn->warning_count); + } + } + DBUG_RETURN(error_num); +} + +int spider_db_mbase::get_errno() +{ + DBUG_ENTER("spider_db_mbase::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_mbase::get_error() +{ + const char *error_ptr; + DBUG_ENTER("spider_db_mbase::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_mbase::is_server_gone_error( + int error_num +) { + bool server_gone; + DBUG_ENTER("spider_db_mbase::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_mbase::is_dup_entry_error( + int error_num +) { + bool dup_entry; + DBUG_ENTER("spider_db_mbase::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_mbase::is_xa_nota_error( + int error_num +) { + bool xa_nota; + DBUG_ENTER("spider_db_mbase::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); +} + +int spider_db_mbase::fetch_and_print_warnings(struct tm *l_time) +{ + int error_num = 0; + DBUG_ENTER("spider_db_mbase::fetch_and_print_warnings"); + DBUG_PRINT("info",("spider this=%p", this)); + + if (spider_param_dry_access() || db_conn->status != MYSQL_STATUS_READY || + db_conn->server_status & SERVER_MORE_RESULTS_EXISTS || + !db_conn->warning_count) + DBUG_RETURN(0); + + if (mysql_real_query(db_conn, SPIDER_SQL_SHOW_WARNINGS_STR, + SPIDER_SQL_SHOW_WARNINGS_LEN)) + DBUG_RETURN(0); + + MYSQL_RES *res= mysql_store_result(db_conn); + if (!res) + DBUG_RETURN(0); + + uint num_fields= mysql_num_fields(res); + if (num_fields != 3) + { + mysql_free_result(res); + DBUG_RETURN(0); + } + + MYSQL_ROW row= mysql_fetch_row(res); + if (l_time) + { + while (row) + { + fprintf(stderr, + "%04d%02d%02d %02d:%02d:%02d [WARN SPIDER RESULT] from [%s] %ld " + "to %ld: %s %s %s\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, conn->tgt_host, + (ulong) db_conn->thread_id, (ulong) current_thd->thread_id, row[0], + row[1], row[2]); + row= mysql_fetch_row(res); + } + } else { + while (row) + { + DBUG_PRINT("info",("spider row[0]=%s", row[0])); + DBUG_PRINT("info",("spider row[1]=%s", row[1])); + DBUG_PRINT("info",("spider row[2]=%s", row[2])); + longlong res_num = + (longlong) my_strtoll10(row[1], (char**) NULL, &error_num); + DBUG_PRINT("info",("spider res_num=%lld", res_num)); + my_printf_error((int) res_num, row[2], MYF(0)); + error_num = (int) res_num; + row = mysql_fetch_row(res); + } + } + + mysql_free_result(res); + + DBUG_RETURN(error_num); +} + +spider_db_result *spider_db_mbase::store_result( + spider_db_result_buffer **spider_res_buf, + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_mbase_result *result; + DBUG_ENTER("spider_db_mbase::store_result"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(!spider_res_buf); + if ((result = new spider_db_mbase_result(this))) + { + *error_num = 0; + if ( + spider_param_dry_access() || + !(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_mbase::use_result( + ha_spider *spider, + st_spider_db_request_key *request_key, + int *error_num +) { + spider_db_mbase_result *result; + DBUG_ENTER("spider_db_mbase::use_result"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((result = new spider_db_mbase_result(this))) + { + *error_num = 0; + if ( + spider_param_dry_access() || + !(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_mbase::next_result() +{ + int status; + DBUG_ENTER("spider_db_mbase::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 (db_conn->server_status & SERVER_MORE_RESULTS_EXISTS) + { + 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_mbase::affected_rows() +{ + MYSQL *last_used_con; + DBUG_ENTER("spider_db_mbase::affected_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + last_used_con = db_conn; + DBUG_RETURN((uint) last_used_con->affected_rows); +} + +uint spider_db_mbase::matched_rows() +{ + MYSQL *last_used_con; + DBUG_ENTER("spider_db_mysql::matched_rows"); + DBUG_PRINT("info", ("spider this=%p", this)); + last_used_con = db_conn; + /* Rows matched: 65 Changed: 65 Warnings: 0 */ + const char *info = last_used_con->info; + if (!info) + DBUG_RETURN(0); + DBUG_PRINT("info", ("spider info=%s", info)); + const char *begin = strstr(info, "Rows matched: "); + if (!begin) + DBUG_RETURN(0); + DBUG_RETURN(atoi(begin + strlen("Rows matched: "))); +} + +bool spider_db_mbase::inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info +) { + MYSQL *last_used_con; + uchar direct_insert_kind = + ((spider_mbase_handler *) handler)->direct_insert_kind; + DBUG_ENTER("spider_db_mysql::inserted_info"); + DBUG_PRINT("info", ("spider this=%p", this)); + if (direct_insert_kind == SPIDER_SQL_DIRECT_INSERT_KIND_INSERT) + { + DBUG_RETURN(TRUE); + } + last_used_con = db_conn; + /* Records: 10 Duplicates: 4 Warnings: 0 */ + const char *info = last_used_con->info; + if (!info) + DBUG_RETURN(FALSE); + DBUG_PRINT("info", ("spider info=%s", info)); + const char *begin = strstr(info, "Records: "); + if (!begin) + DBUG_RETURN(FALSE); + begin += strlen("Records: "); + uint records = atoi(begin); + begin = strstr(begin, "Duplicates: "); + if (!begin) + DBUG_RETURN(FALSE); + uint duplicates = atoi(begin + strlen("Duplicates: ")); + copy_info->records+= records; + switch (direct_insert_kind) + { + case SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE: + copy_info->copied+= duplicates; + break; + case SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE: + copy_info->copied+= records; + copy_info->deleted+= duplicates; + break; + case SPIDER_SQL_DIRECT_INSERT_KIND_DUP_UPDATE: + copy_info->touched+= (last_used_con->affected_rows - (duplicates * 2)); + copy_info->copied+= (last_used_con->affected_rows - duplicates); + copy_info->updated+= duplicates; + break; + default: + DBUG_ASSERT(0); + DBUG_RETURN(FALSE); + } + DBUG_RETURN(TRUE); +} + +ulonglong spider_db_mbase::last_insert_id() +{ + MYSQL *last_used_con; + DBUG_ENTER("spider_db_mbase::last_insert_id"); + DBUG_PRINT("info",("spider this=%p", this)); + last_used_con = db_conn; + DBUG_RETURN((uint) last_used_con->insert_id); +} + +int spider_db_mbase::set_character_set( + const char *csname +) { + DBUG_ENTER("spider_db_mbase::set_character_set"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_dry_access()) + DBUG_RETURN(0); + DBUG_RETURN(mysql_set_character_set(db_conn, csname)); +} + +int spider_db_mbase::select_db( + const char *dbname +) { + DBUG_ENTER("spider_db_mbase::select_db"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider_param_dry_access()) + DBUG_RETURN(0); + DBUG_RETURN(mysql_select_db(db_conn, dbname)); +} + +int spider_db_mbase::consistent_snapshot( + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::consistent_snapshot"); + DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR, + SPIDER_SQL_START_CONSISTENT_SNAPSHOT_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::trx_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::trx_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::start_transaction( + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::start_transaction"); + DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + if (spider_db_query( + conn, + SPIDER_SQL_START_TRANSACTION_STR, + SPIDER_SQL_START_TRANSACTION_LEN, + -1, + need_mon) + ) { + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_RETURN(0); +} + +int spider_db_mbase::commit( + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::commit"); + DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_COMMIT_STR, + SPIDER_SQL_COMMIT_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::rollback( + int *need_mon +) { + bool is_error; + int error_num; + DBUG_ENTER("spider_db_mbase::rollback"); + DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_ROLLBACK_STR, + SPIDER_SQL_ROLLBACK_LEN, + -1, + need_mon) + ) { + is_error = conn->thd->is_error(); + error_num = spider_db_errorno(conn); + if ( + error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && + !is_error + ) + conn->thd->clear_error(); + else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::xa_start( + XID *xid, + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::xa_start"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} + +bool spider_db_mbase::xa_start_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::xa_start_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::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_mbase::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); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::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_mbase::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); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::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_mbase::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); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::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_mbase::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); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_trx_isolation_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_trx_isolation_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_trx_isolation( + int trx_isolation, + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::set_trx_isolation"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (trx_isolation) + { + case ISO_READ_UNCOMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_ISO_READ_UNCOMMITTED_STR, + SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_READ_COMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_ISO_READ_COMMITTED_STR, + SPIDER_SQL_ISO_READ_COMMITTED_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_REPEATABLE_READ: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_ISO_REPEATABLE_READ_STR, + SPIDER_SQL_ISO_REPEATABLE_READ_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + break; + case ISO_SERIALIZABLE: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_ISO_SERIALIZABLE_STR, + SPIDER_SQL_ISO_SERIALIZABLE_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + 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_mbase::set_autocommit_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_autocommit_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_autocommit( + bool autocommit, + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::set_autocommit"); + DBUG_PRINT("info",("spider this=%p", this)); + if (autocommit) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_ON_STR, + SPIDER_SQL_AUTOCOMMIT_ON_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_AUTOCOMMIT_OFF_STR, + SPIDER_SQL_AUTOCOMMIT_OFF_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_sql_log_off_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_sql_log_off_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_sql_log_off( + bool sql_log_off, + int *need_mon +) { + DBUG_ENTER("spider_db_mbase::set_sql_log_off"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_log_off) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_SQL_LOG_ON_STR, + SPIDER_SQL_SQL_LOG_ON_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_SQL_LOG_OFF_STR, + SPIDER_SQL_SQL_LOG_OFF_LEN, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_wait_timeout_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_wait_timeout_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_wait_timeout( + int wait_timeout, + int *need_mon +) { + char sql_buf[MAX_FIELD_WIDTH]; + char timeout_str[SPIDER_SQL_INT_LEN]; + int timeout_str_length; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mbase::set_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(264); + sql_str.length(0); + timeout_str_length = + my_sprintf(timeout_str, (timeout_str, "%d", wait_timeout)); + if (sql_str.reserve(SPIDER_SQL_WAIT_TIMEOUT_LEN + timeout_str_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_str.q_append(SPIDER_SQL_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); + sql_str.q_append(timeout_str, timeout_str_length); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_sql_mode_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_sql_mode_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_sql_mode( + sql_mode_t sql_mode, + int *need_mon +) { + int error_num; + char sql_buf[MAX_FIELD_WIDTH]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mbase::set_sql_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(265); + sql_str.length(0); + if (sql_str.reserve(SPIDER_SQL_SQL_MODE_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql_str.q_append(SPIDER_SQL_SQL_MODE_STR, SPIDER_SQL_SQL_MODE_LEN); + if ((error_num = spider_db_mbase_utility->append_sql_mode_internal(&sql_str, sql_mode))) + { + DBUG_RETURN(error_num); + } + if (sql_str.length() > SPIDER_SQL_SQL_MODE_LEN) + { + sql_str.length(sql_str.length() - SPIDER_SQL_COMMA_LEN); + } else { + if (sql_str.reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_time_zone_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_time_zone_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::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_mbase::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); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_db_mbase::set_loop_check_in_bulk_sql() +{ + DBUG_ENTER("spider_db_mbase::set_loop_check_in_bulk_sql"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_db_mbase::set_loop_check( + int *need_mon +) { + SPIDER_CONN_LOOP_CHECK *lcptr; + char sql_buf[MAX_FIELD_WIDTH]; + spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin); + DBUG_ENTER("spider_db_mbase::set_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + sql_str.init_calc_mem(270); + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_check_queue, 0))) + { + sql_str.length(0); + if (sql_str.reserve(SPIDER_SQL_SET_USER_VAL_LEN + + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN + lcptr->to_name.length + + SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_EQUAL_LEN + + SPIDER_SQL_VALUE_QUOTE_LEN + + lcptr->merged_value.length + SPIDER_SQL_VALUE_QUOTE_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql_str.q_append(SPIDER_SQL_SET_USER_VAL_STR, SPIDER_SQL_SET_USER_VAL_LEN); + sql_str.q_append(SPIDER_SQL_LOP_CHK_PRM_PRF_STR, + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN); + sql_str.q_append(lcptr->to_name.str, lcptr->to_name.length); + sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql_str.q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(lcptr->merged_value.str, lcptr->merged_value.length); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + sql_str.ptr(), + sql_str.length(), + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_hash_delete(&conn->loop_check_queue, (uchar*) lcptr); + } + DBUG_RETURN(0); +} + +int spider_db_mbase::fin_loop_check() +{ + st_spider_conn_loop_check *lcptr; + DBUG_ENTER("spider_db_mbase::fin_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + if (conn->loop_check_queue.records) + { + uint l = 0; + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_check_queue, l))) + { + lcptr->flag = 0; + ++l; + } + my_hash_reset(&conn->loop_check_queue); + } + lcptr = conn->loop_check_ignored_first; + while (lcptr) + { + lcptr->flag = 0; + lcptr = lcptr->next; + } + conn->loop_check_ignored_first = NULL; + lcptr = conn->loop_check_meraged_first; + while (lcptr) + { + lcptr->flag = 0; + lcptr = lcptr->next; + } + conn->loop_check_meraged_first = NULL; + DBUG_RETURN(0); +} + +int spider_db_mbase::exec_simple_sql_with_result( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + const char *sql, + uint sql_length, + int all_link_idx, + int *need_mon, + SPIDER_DB_RESULT **res +) { + int error_num; + DBUG_ENTER("spider_db_mbase::exec_simple_sql_with_result"); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, all_link_idx, trx->thd, + share); + if ( + (error_num = spider_db_set_names_internal(trx, share, conn, + all_link_idx, need_mon)) || + ( + spider_db_query( + conn, + sql, + sql_length, + -1, + need_mon) && + (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_internal(share, conn, + all_link_idx, need_mon))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_internal(trx, share, conn, + all_link_idx, need_mon))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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, all_link_idx, trx->thd, + share); + if (spider_db_query( + conn, + sql, + sql_length, + -1, + need_mon) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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 { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + } + if (!(*res = store_result(NULL, NULL, &error_num))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 7", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase::show_master_status( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + int mode, + SPIDER_DB_RESULT **res1, + SPIDER_DB_RESULT **res2 +) { + int error_num; + const char *binlog_file_name, *binlog_pos; + uint binlog_file_name_length, binlog_pos_length; + DBUG_ENTER("spider_db_mbase::show_master_status"); + if ((error_num = exec_simple_sql_with_result(trx, share, + SPIDER_SQL_SHOW_MASTER_STATUS_STR, SPIDER_SQL_SHOW_MASTER_STATUS_LEN, + all_link_idx, need_mon, res1)) + ) { + DBUG_PRINT("info", ("spider error_num=%d 1", error_num)); + DBUG_RETURN(error_num); + } + + if (!(error_num = ((spider_db_mbase_result *)*res1)->fetch_show_master_status( + &binlog_file_name, &binlog_pos)) + ) { + binlog_file_name_length = strlen(binlog_file_name); + binlog_pos_length = strlen(binlog_pos); + spider_store_binlog_pos_binlog_file(table, + binlog_file_name, binlog_file_name_length, + binlog_pos, binlog_pos_length, conn->access_charset); + if (mode > 0) + { + error_num = select_binlog_gtid_pos( + trx, + share, + all_link_idx, + need_mon, + table, + str, + binlog_file_name, + binlog_file_name_length, + binlog_pos, + binlog_pos_length, + res2 + ); + } else { + spider_store_binlog_pos_gtid(table, NULL, 0, conn->access_charset); + } + } +/* + res->free_result(); + delete res; +*/ + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 2", error_num)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_mbase::select_binlog_gtid_pos( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + const char *binlog_file_name, + uint binlog_file_name_length, + const char *binlog_pos, + uint binlog_pos_length, + SPIDER_DB_RESULT **res +) { + int error_num; + size_t length; + const char *gtid_pos; + DBUG_ENTER("spider_db_mbase::select_binlog_gtid_pos"); + str->length(0); + if (str->reserve( + SPIDER_SQL_BINLOG_GTID_POS_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + + SPIDER_SQL_VALUE_QUOTE_LEN + + binlog_file_name_length * 2 + + SPIDER_SQL_VALUE_QUOTE_LEN + + SPIDER_SQL_COMMA_LEN + + SPIDER_SQL_VALUE_QUOTE_LEN + + binlog_pos_length * 2 + + SPIDER_SQL_VALUE_QUOTE_LEN + + SPIDER_SQL_CLOSE_PAREN_LEN + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_BINLOG_GTID_POS_STR, + SPIDER_SQL_BINLOG_GTID_POS_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + length = conn->db_conn->escape_string((char *)str->ptr() + str->length(), + binlog_file_name, binlog_file_name_length); + str->length(str->length() + length); + 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(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + length = conn->db_conn->escape_string((char *)str->ptr() + str->length(), + binlog_pos, binlog_pos_length); + str->length(str->length() + length); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + + if ((error_num = exec_simple_sql_with_result(trx, share, + str->ptr(), str->length(), all_link_idx, need_mon, res))) + { + DBUG_PRINT("info", ("spider error_num=%d 1", error_num)); + DBUG_RETURN(error_num); + } + if (!(error_num = ((spider_db_mbase_result *)*res)->fetch_select_binlog_gtid_pos(>id_pos))) + { + spider_store_binlog_pos_gtid(table, gtid_pos, strlen(gtid_pos), conn->access_charset); + } +/* + res->free_result(); + delete res; +*/ + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 2", error_num)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +size_t spider_db_mbase::escape_string( + char *to, + const char *from, + size_t from_length +) { + my_bool overflow; + DBUG_ENTER("spider_db_mbase::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, &overflow)); + DBUG_RETURN(escape_string_for_mysql(db_conn->charset, to, 0, + from, from_length, &overflow)); +} + +bool spider_db_mbase::have_lock_table_list() +{ + DBUG_ENTER("spider_db_mbase::have_lock_table_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +int spider_db_mbase::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_mbase::lock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_mbase_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->wide_handler->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->wide_handler->lock_type)); + DBUG_RETURN(0); + } + conn_link_idx = tmp_spider->conn_link_idx[tmp_link_idx]; + spider_mbase_share *db_share = (spider_mbase_share *) + tmp_spider->share->dbton_share[conn->dbton_id]; + + 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; + + 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; + + if ((error_num = spider_db_mbase_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); + } + my_hash_delete(&lock_table_hash, (uchar*) tmp_link_for_hash); + } + if ((error_num = spider_db_mbase_utility->append_lock_table_tail(str))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_db_mbase::append_unlock_tables( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_db_mbase::append_unlock_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_mbase_utility->append_unlock_table(str))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +uint spider_db_mbase::get_lock_table_hash_count() +{ + DBUG_ENTER("spider_db_mbase::get_lock_table_hash_count"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(lock_table_hash.records); +} + +void spider_db_mbase::reset_lock_table_hash() +{ + DBUG_ENTER("spider_db_mbase::reset_lock_table_hash"); + DBUG_PRINT("info",("spider this=%p", this)); + my_hash_reset(&lock_table_hash); + DBUG_VOID_RETURN; +} + +void spider_db_mbase::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; + const char *key_name; + DBUG_ENTER("spider_db_mbase::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->key_info[roop_count].name.str; + key_name_length = table->key_info[roop_count].name.length; + } + 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_mbase::cmp_request_key_to_snd( + st_spider_db_request_key *request_key +) { + DBUG_ENTER("spider_db_mbase::cmp_request_key_to_snd"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +spider_db_mbase_util::spider_db_mbase_util() : spider_db_util() +{ + DBUG_ENTER("spider_db_mbase_util::spider_db_mbase_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mysql_util::spider_db_mysql_util() : spider_db_mbase_util() +{ + DBUG_ENTER("spider_db_mysql_util::spider_db_mysql_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mariadb_util::spider_db_mariadb_util() : spider_db_mbase_util() +{ + DBUG_ENTER("spider_db_mariadb_util::spider_db_mariadb_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_db_mbase_util::~spider_db_mbase_util() +{ + DBUG_ENTER("spider_db_mbase_util::~spider_db_mbase_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; +} + +spider_db_mariadb_util::~spider_db_mariadb_util() +{ + DBUG_ENTER("spider_db_mariadb_util::~spider_db_mariadb_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_db_mbase_util::append_name( + spider_string *str, + const char *name, + uint name_length +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset +) { + DBUG_ENTER("spider_db_mbase_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); +} + +int spider_db_mbase_util::append_escaped_name( + spider_string *str, + const char *name, + uint name_length +) { + int error_num; + DBUG_ENTER("spider_db_mbase_util::append_name"); + 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); + if ((error_num = spider_db_append_name_with_quote_str_internal( + str, name, name_length, dbton_id))) + { + DBUG_RETURN(error_num); + } + 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); +} + +int spider_db_mbase_util::append_escaped_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset +) { + int error_num; + DBUG_ENTER("spider_db_mbase_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); + if ((error_num = spider_db_append_name_with_quote_str_internal( + str, name, name_length, name_charset, dbton_id))) + { + DBUG_RETURN(error_num); + } + 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_mbase_util::is_name_quote( + const char head_code +) { + DBUG_ENTER("spider_db_mbase_util::is_name_quote"); + DBUG_RETURN(head_code == *name_quote_str); +} + +int spider_db_mbase_util::append_escaped_name_quote( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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_mariadb_util::append_column_value(ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + bool is_like, + CHARSET_INFO *access_charset) +{ + bool float_value = FALSE; + int error_num; + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, field->charset()); + String *ptr; + uint length; + THD *thd = field->table->in_use; + Time_zone *saved_time_zone = thd->variables.time_zone; + DBUG_ENTER("spider_db_mariadb_util::append_column_value"); + tmp_str.init_calc_mem(113); + + thd->variables.time_zone = UTC; + + if (new_ptr) + { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR + ) { + length = uint2korr(new_ptr); + tmp_str.set((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, + field->charset()); + ptr = tmp_str.get_str(); + } else if (field->type() == MYSQL_TYPE_GEOMETRY) + { +#ifdef DBUG_TRACE + double 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)); +#endif + 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(); + if (field->type() == MYSQL_TYPE_FLOAT) + { + float_value = TRUE; + } + } + + thd->variables.time_zone = saved_time_zone; + + DBUG_PRINT("info", ("spider field->type() is %d", field->type())); + DBUG_PRINT("info", ("spider ptr->length() is %d", ptr->length())); + + if (field->result_type() == STRING_RESULT) + { + DBUG_PRINT("info", ("spider STRING_RESULT")); + if (str->charset() != field->charset()) + { + if ((error_num = spider_db_append_charset_name_before_string(str, + field->charset()))) + { + DBUG_RETURN(error_num); + } + } + 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, field->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); + + if (is_like && + str->append(SPIDER_SQL_PERCENT_STR, SPIDER_SQL_PERCENT_LEN)) + 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->charset() != field->charset()) + { + if ((error_num = spider_db_append_charset_name_before_string(str, + field->charset()))) + { + DBUG_RETURN(error_num); + } + } + 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 (float_value) + { + if (str->reserve(SPIDER_SQL_CAST_LEN + ptr->length() + + SPIDER_SQL_AS_FLOAT_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CAST_STR, SPIDER_SQL_CAST_LEN); + str->q_append(ptr->ptr(), ptr->length()); + str->q_append(SPIDER_SQL_AS_FLOAT_STR, SPIDER_SQL_AS_FLOAT_LEN); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (str->append(*ptr)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + DBUG_RETURN(0); +} + +int spider_db_mysql_util::append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + bool is_like, + CHARSET_INFO *access_charset +) { + bool float_value = FALSE; + int error_num; + char buf[MAX_FIELD_WIDTH]; + spider_string tmp_str(buf, MAX_FIELD_WIDTH, field->charset()); + String *ptr; + uint length; + THD *thd = field->table->in_use; + Time_zone *saved_time_zone = thd->variables.time_zone; + DBUG_ENTER("spider_db_mysql_util::append_column_value"); + tmp_str.init_calc_mem(266); + + thd->variables.time_zone = UTC; + + if (new_ptr) + { + if ( + field->type() == MYSQL_TYPE_BLOB || + field->real_type() == MYSQL_TYPE_VARCHAR + ) { + length = uint2korr(new_ptr); + tmp_str.set((char *) new_ptr + HA_KEY_BLOB_LENGTH, length, + field->charset()); + 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); +*/ +#ifdef DBUG_TRACE + 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((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(); + if (field->type() == MYSQL_TYPE_FLOAT) + { + float_value = TRUE; + } + } + + thd->variables.time_zone = saved_time_zone; + + 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->charset() != field->charset()) + { + if ((error_num = spider_db_append_charset_name_before_string(str, + field->charset()))) + { + DBUG_RETURN(error_num); + } + } + 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, field->charset()); + tmp_str2.init_calc_mem(267); + 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); + if (is_like && + str->append(SPIDER_SQL_PERCENT_STR, SPIDER_SQL_PERCENT_LEN)) + 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->charset() != field->charset()) + { + if ((error_num = spider_db_append_charset_name_before_string(str, + field->charset()))) + { + DBUG_RETURN(error_num); + } + } + 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 (float_value) + { + if (str->reserve(SPIDER_SQL_TO_FLOAT_LEN + ptr->length() + + SPIDER_SQL_CLOSE_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_TO_FLOAT_STR, SPIDER_SQL_TO_FLOAT_LEN); + str->q_append(ptr->ptr(), ptr->length()); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else if (str->append(*ptr)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_column_value(ha_spider *, spider_string *, + Field *, const uchar *, bool, + CHARSET_INFO *) +{ + MY_ASSERT_UNREACHABLE(); + return 0; +} + +int spider_db_mbase_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_mbase_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_mbase_util::append_trx_isolation( + spider_string *str, + int trx_isolation +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_autocommit( + spider_string *str, + bool autocommit +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_sql_log_off( + spider_string *str, + bool sql_log_off +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_wait_timeout( + spider_string *str, + int wait_timeout +) { + char timeout_str[SPIDER_SQL_INT_LEN]; + int timeout_str_length; + DBUG_ENTER("spider_db_mbase_util::append_wait_timeout"); + DBUG_PRINT("info",("spider this=%p", this)); + timeout_str_length = + my_sprintf(timeout_str, (timeout_str, "%d", wait_timeout)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_WAIT_TIMEOUT_LEN + + timeout_str_length)) + { + 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_WAIT_TIMEOUT_STR, SPIDER_SQL_WAIT_TIMEOUT_LEN); + str->q_append(timeout_str, timeout_str_length); + DBUG_RETURN(0); +} + +#define SPIDER_REAL_AS_FLOAT_STR "real_as_float" +#define SPIDER_REAL_AS_FLOAT_LEN (sizeof(SPIDER_REAL_AS_FLOAT_STR) - 1) +#define SPIDER_PIPES_AS_CONCAT_STR "pipes_as_concat" +#define SPIDER_PIPES_AS_CONCAT_LEN (sizeof(SPIDER_PIPES_AS_CONCAT_STR) - 1) +#define SPIDER_ANSI_QUOTES_STR "ansi_quotes" +#define SPIDER_ANSI_QUOTES_LEN (sizeof(SPIDER_ANSI_QUOTES_STR) - 1) +#define SPIDER_IGNORE_SPACE_STR "ignore_space" +#define SPIDER_IGNORE_SPACE_LEN (sizeof(SPIDER_IGNORE_SPACE_STR) - 1) +#define SPIDER_IGNORE_BAD_TABLE_OPTIONS_STR "ignore_bad_table_options" +#define SPIDER_IGNORE_BAD_TABLE_OPTIONS_LEN (sizeof(SPIDER_IGNORE_BAD_TABLE_OPTIONS_STR) - 1) +#define SPIDER_ONLY_FULL_GROUP_BY_STR "only_full_group_by" +#define SPIDER_ONLY_FULL_GROUP_BY_LEN (sizeof(SPIDER_ONLY_FULL_GROUP_BY_STR) - 1) +#define SPIDER_NO_UNSIGNED_SUBTRACTION_STR "no_unsigned_subtraction" +#define SPIDER_NO_UNSIGNED_SUBTRACTION_LEN (sizeof(SPIDER_NO_UNSIGNED_SUBTRACTION_STR) - 1) +#define SPIDER_NO_DIR_IN_CREATE_STR "no_dir_in_create" +#define SPIDER_NO_DIR_IN_CREATE_LEN (sizeof(SPIDER_NO_DIR_IN_CREATE_STR) - 1) +#define SPIDER_POSTGRESQL_STR "postgresql" +#define SPIDER_POSTGRESQL_LEN (sizeof(SPIDER_POSTGRESQL_STR) - 1) +#define SPIDER_ORACLE_STR "oracle" +#define SPIDER_ORACLE_LEN (sizeof(SPIDER_ORACLE_STR) - 1) +#define SPIDER_MSSQL_STR "mssql" +#define SPIDER_MSSQL_LEN (sizeof(SPIDER_MSSQL_STR) - 1) +#define SPIDER_DB2_STR "db2" +#define SPIDER_DB2_LEN (sizeof(SPIDER_DB2_STR) - 1) +#define SPIDER_MAXDB_STR "maxdb" +#define SPIDER_MAXDB_LEN (sizeof(SPIDER_MAXDB_STR) - 1) +#define SPIDER_NO_KEY_OPTIONS_STR "no_key_options" +#define SPIDER_NO_KEY_OPTIONS_LEN (sizeof(SPIDER_NO_KEY_OPTIONS_STR) - 1) +#define SPIDER_NO_TABLE_OPTIONS_STR "no_table_options" +#define SPIDER_NO_TABLE_OPTIONS_LEN (sizeof(SPIDER_NO_TABLE_OPTIONS_STR) - 1) +#define SPIDER_NO_FIELD_OPTIONS_STR "no_field_options" +#define SPIDER_NO_FIELD_OPTIONS_LEN (sizeof(SPIDER_NO_FIELD_OPTIONS_STR) - 1) +#define SPIDER_MYSQL323_STR "mysql323" +#define SPIDER_MYSQL323_LEN (sizeof(SPIDER_MYSQL323_STR) - 1) +#define SPIDER_MYSQL40_STR "mysql40" +#define SPIDER_MYSQL40_LEN (sizeof(SPIDER_MYSQL40_STR) - 1) +#define SPIDER_ANSI_STR "ansi" +#define SPIDER_ANSI_LEN (sizeof(SPIDER_ANSI_STR) - 1) +#define SPIDER_NO_AUTO_VALUE_ON_ZERO_STR "no_auto_value_on_zero" +#define SPIDER_NO_AUTO_VALUE_ON_ZERO_LEN (sizeof(SPIDER_NO_AUTO_VALUE_ON_ZERO_STR) - 1) +#define SPIDER_NO_BACKSLASH_ESCAPES_STR "no_backslash_escapes" +#define SPIDER_NO_BACKSLASH_ESCAPES_LEN (sizeof(SPIDER_NO_BACKSLASH_ESCAPES_STR) - 1) +#define SPIDER_STRICT_TRANS_TABLES_STR "strict_trans_tables" +#define SPIDER_STRICT_TRANS_TABLES_LEN (sizeof(SPIDER_STRICT_TRANS_TABLES_STR) - 1) +#define SPIDER_STRICT_ALL_TABLES_STR "strict_all_tables" +#define SPIDER_STRICT_ALL_TABLES_LEN (sizeof(SPIDER_STRICT_ALL_TABLES_STR) - 1) +#define SPIDER_NO_ZERO_IN_DATE_STR "no_zero_in_date" +#define SPIDER_NO_ZERO_IN_DATE_LEN (sizeof(SPIDER_NO_ZERO_IN_DATE_STR) - 1) +#define SPIDER_NO_ZERO_DATE_STR "no_zero_date" +#define SPIDER_NO_ZERO_DATE_LEN (sizeof(SPIDER_NO_ZERO_DATE_STR) - 1) +#define SPIDER_INVALID_DATES_STR "allow_invalid_dates" +#define SPIDER_INVALID_DATES_LEN (sizeof(SPIDER_INVALID_DATES_STR) - 1) +#define SPIDER_ERROR_FOR_DIVISION_BY_ZERO_STR "error_for_division_by_zero" +#define SPIDER_ERROR_FOR_DIVISION_BY_ZERO_LEN (sizeof(SPIDER_ERROR_FOR_DIVISION_BY_ZERO_STR) - 1) +#define SPIDER_TRADITIONAL_STR "traditional" +#define SPIDER_TRADITIONAL_LEN (sizeof(SPIDER_TRADITIONAL_STR) - 1) +#define SPIDER_NO_AUTO_CREATE_USER_STR "no_auto_create_user" +#define SPIDER_NO_AUTO_CREATE_USER_LEN (sizeof(SPIDER_NO_AUTO_CREATE_USER_STR) - 1) +#define SPIDER_HIGH_NOT_PRECEDENCE_STR "high_not_precedence" +#define SPIDER_HIGH_NOT_PRECEDENCE_LEN (sizeof(SPIDER_HIGH_NOT_PRECEDENCE_STR) - 1) +#define SPIDER_NO_ENGINE_SUBSTITUTION_STR "no_engine_substitution" +#define SPIDER_NO_ENGINE_SUBSTITUTION_LEN (sizeof(SPIDER_NO_ENGINE_SUBSTITUTION_STR) - 1) +#define SPIDER_PAD_CHAR_TO_FULL_LENGTH_STR "pad_char_to_full_length" +#define SPIDER_PAD_CHAR_TO_FULL_LENGTH_LEN (sizeof(SPIDER_PAD_CHAR_TO_FULL_LENGTH_STR) - 1) +#define SPIDER_EMPTY_STRING_IS_NULL_STR "empty_string_is_null" +#define SPIDER_EMPTY_STRING_IS_NULL_LEN (sizeof(SPIDER_EMPTY_STRING_IS_NULL_STR) - 1) +#define SPIDER_SIMULTANEOUS_ASSIGNMENT_STR "simultaneous_assignment" +#define SPIDER_SIMULTANEOUS_ASSIGNMENT_LEN (sizeof(SPIDER_SIMULTANEOUS_ASSIGNMENT_STR) - 1) +#define SPIDER_TIME_ROUND_FRACTIONAL_STR "time_round_fractional" +#define SPIDER_TIME_ROUND_FRACTIONAL_LEN (sizeof(SPIDER_TIME_ROUND_FRACTIONAL_STR) - 1) + +sql_mode_t full_sql_mode = +#ifdef MODE_REAL_AS_FLOAT + MODE_REAL_AS_FLOAT | +#endif +#ifdef MODE_PIPES_AS_CONCAT + MODE_PIPES_AS_CONCAT | +#endif +#ifdef MODE_ANSI_QUOTES + MODE_ANSI_QUOTES | +#endif +#ifdef MODE_IGNORE_SPACE + MODE_IGNORE_SPACE | +#endif +#ifdef MODE_IGNORE_BAD_TABLE_OPTIONS + MODE_IGNORE_BAD_TABLE_OPTIONS | +#endif +#ifdef MODE_ONLY_FULL_GROUP_BY + MODE_ONLY_FULL_GROUP_BY | +#endif +#ifdef MODE_NO_UNSIGNED_SUBTRACTION + MODE_NO_UNSIGNED_SUBTRACTION | +#endif +#ifdef MODE_NO_DIR_IN_CREATE + MODE_NO_DIR_IN_CREATE | +#endif +#ifdef MODE_POSTGRESQL + MODE_POSTGRESQL | +#endif +#ifdef MODE_ORACLE + MODE_ORACLE | +#endif +#ifdef MODE_MSSQL + MODE_MSSQL | +#endif +#ifdef MODE_DB2 + MODE_DB2 | +#endif +#ifdef MODE_MAXDB + MODE_MAXDB | +#endif +#ifdef MODE_NO_KEY_OPTIONS + MODE_NO_KEY_OPTIONS | +#endif +#ifdef MODE_NO_TABLE_OPTIONS + MODE_NO_TABLE_OPTIONS | +#endif +#ifdef MODE_NO_FIELD_OPTIONS + MODE_NO_FIELD_OPTIONS | +#endif +#ifdef MODE_MYSQL323 + MODE_MYSQL323 | +#endif +#ifdef MODE_MYSQL40 + MODE_MYSQL40 | +#endif +#ifdef MODE_ANSI + MODE_ANSI | +#endif +#ifdef MODE_NO_AUTO_VALUE_ON_ZERO + MODE_NO_AUTO_VALUE_ON_ZERO | +#endif +#ifdef MODE_NO_BACKSLASH_ESCAPES + MODE_NO_BACKSLASH_ESCAPES | +#endif +#ifdef MODE_STRICT_TRANS_TABLES + MODE_STRICT_TRANS_TABLES | +#endif +#ifdef MODE_STRICT_ALL_TABLES + MODE_STRICT_ALL_TABLES | +#endif +#ifdef MODE_NO_ZERO_IN_DATE + MODE_NO_ZERO_IN_DATE | +#endif +#ifdef MODE_NO_ZERO_DATE + MODE_NO_ZERO_DATE | +#endif +#ifdef MODE_INVALID_DATES + MODE_INVALID_DATES | +#endif +#ifdef MODE_ERROR_FOR_DIVISION_BY_ZERO + MODE_ERROR_FOR_DIVISION_BY_ZERO | +#endif +#ifdef MODE_TRADITIONAL + MODE_TRADITIONAL | +#endif +#ifdef MODE_NO_AUTO_CREATE_USER + MODE_NO_AUTO_CREATE_USER | +#endif +#ifdef MODE_HIGH_NOT_PRECEDENCE + MODE_HIGH_NOT_PRECEDENCE | +#endif +#ifdef MODE_NO_ENGINE_SUBSTITUTION + MODE_NO_ENGINE_SUBSTITUTION | +#endif +#ifdef MODE_PAD_CHAR_TO_FULL_LENGTH + MODE_PAD_CHAR_TO_FULL_LENGTH | +#endif +#ifdef MODE_EMPTY_STRING_IS_NULL + MODE_EMPTY_STRING_IS_NULL | +#endif +#ifdef MODE_SIMULTANEOUS_ASSIGNMENT + MODE_SIMULTANEOUS_ASSIGNMENT | +#endif +#ifdef MODE_TIME_ROUND_FRACTIONAL + MODE_TIME_ROUND_FRACTIONAL | +#endif + 0; + +#ifdef MODE_REAL_AS_FLOAT +/* pushdown */ +#define SPIDER_SQL_MODE_REAL_AS_FLOAT +#endif +#ifdef MODE_PIPES_AS_CONCAT +/* no pushdown */ +#endif +#ifdef MODE_ANSI_QUOTES +/* no pushdown */ +#endif +#ifdef MODE_IGNORE_SPACE +/* no pushdown */ +#endif +#ifdef MODE_IGNORE_BAD_TABLE_OPTIONS +/* pushdown */ +#define SPIDER_SQL_MODE_IGNORE_BAD_TABLE_OPTIONS +#endif +#ifdef MODE_ONLY_FULL_GROUP_BY +/* no pushdown */ +#endif +#ifdef MODE_NO_UNSIGNED_SUBTRACTION +/* pushdown */ +#define SPIDER_SQL_MODE_NO_UNSIGNED_SUBTRACTION +#endif +#ifdef MODE_NO_DIR_IN_CREATE +/* pushdown */ +#define SPIDER_SQL_MODE_NO_DIR_IN_CREATE +#endif +#ifdef MODE_POSTGRESQL +/* no pushdown */ +#endif +#ifdef MODE_ORACLE +/* no pushdown */ +#endif +#ifdef MODE_MSSQL +/* no pushdown */ +#endif +#ifdef MODE_DB2 +/* no pushdown */ +#endif +#ifdef MODE_MAXDB +/* no pushdown */ +#endif +#ifdef MODE_NO_KEY_OPTIONS +/* no pushdown */ +#endif +#ifdef MODE_NO_TABLE_OPTIONS +/* no pushdown */ +#endif +#ifdef MODE_NO_FIELD_OPTIONS +/* no pushdown */ +#endif +#ifdef MODE_MYSQL323 +/* no pushdown */ +#endif +#ifdef MODE_MYSQL40 +/* no pushdown */ +#endif +#ifdef MODE_ANSI +/* no pushdown */ +#endif +#ifdef MODE_NO_AUTO_VALUE_ON_ZERO +/* pushdown */ +#define SPIDER_SQL_MODE_NO_AUTO_VALUE_ON_ZERO +#endif +#ifdef MODE_NO_BACKSLASH_ESCAPES +/* no pushdown */ +#endif +#ifdef MODE_STRICT_TRANS_TABLES +/* pushdown */ +#define SPIDER_SQL_MODE_STRICT_TRANS_TABLES +#endif +#ifdef MODE_STRICT_ALL_TABLES +/* pushdown */ +#define SPIDER_SQL_MODE_STRICT_ALL_TABLES +#endif +#ifdef MODE_NO_ZERO_IN_DATE +/* pushdown */ +#define SPIDER_SQL_MODE_NO_ZERO_IN_DATE +#endif +#ifdef MODE_NO_ZERO_DATE +/* pushdown */ +#define SPIDER_SQL_MODE_NO_ZERO_DATE +#endif +#ifdef MODE_INVALID_DATES +/* pushdown */ +#define SPIDER_SQL_MODE_INVALID_DATES +#endif +#ifdef MODE_ERROR_FOR_DIVISION_BY_ZERO +/* pushdown */ +#define SPIDER_SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO +#endif +#ifdef MODE_TRADITIONAL +/* no pushdown */ +#endif +#ifdef MODE_NO_AUTO_CREATE_USER +/* pushdown */ +#define SPIDER_SQL_MODE_NO_AUTO_CREATE_USER +#endif +#ifdef MODE_HIGH_NOT_PRECEDENCE +/* pushdown */ +#define SPIDER_SQL_MODE_HIGH_NOT_PRECEDENCE +#endif +#ifdef MODE_NO_ENGINE_SUBSTITUTION +/* pushdown */ +#define SPIDER_SQL_MODE_NO_ENGINE_SUBSTITUTION +#endif +#ifdef MODE_PAD_CHAR_TO_FULL_LENGTH +/* pushdown */ +#define SPIDER_SQL_MODE_PAD_CHAR_TO_FULL_LENGTH +#endif +#ifdef MODE_EMPTY_STRING_IS_NULL +/* pushdown */ +#define SPIDER_SQL_MODE_EMPTY_STRING_IS_NULL +#endif +#ifdef MODE_SIMULTANEOUS_ASSIGNMENT +/* pushdown */ +#define SPIDER_SQL_MODE_SIMULTANEOUS_ASSIGNMENT +#endif +#ifdef MODE_TIME_ROUND_FRACTIONAL +/* pushdown */ +#define SPIDER_SQL_MODE_TIME_ROUND_FRACTIONAL +#endif + +sql_mode_t pushdown_sql_mode = +#ifdef SPIDER_SQL_MODE_REAL_AS_FLOAT + MODE_REAL_AS_FLOAT | +#endif +#ifdef SPIDER_SQL_MODE_PIPES_AS_CONCAT + MODE_PIPES_AS_CONCAT | +#endif +#ifdef SPIDER_SQL_MODE_ANSI_QUOTES + MODE_ANSI_QUOTES | +#endif +#ifdef SPIDER_SQL_MODE_IGNORE_SPACE + MODE_IGNORE_SPACE | +#endif +#ifdef SPIDER_SQL_MODE_IGNORE_BAD_TABLE_OPTIONS + MODE_IGNORE_BAD_TABLE_OPTIONS | +#endif +#ifdef SPIDER_SQL_MODE_ONLY_FULL_GROUP_BY + MODE_ONLY_FULL_GROUP_BY | +#endif +#ifdef SPIDER_SQL_MODE_NO_UNSIGNED_SUBTRACTION + MODE_NO_UNSIGNED_SUBTRACTION | +#endif +#ifdef SPIDER_SQL_MODE_NO_DIR_IN_CREATE + MODE_NO_DIR_IN_CREATE | +#endif +#ifdef SPIDER_SQL_MODE_POSTGRESQL + MODE_POSTGRESQL | +#endif +#ifdef SPIDER_SQL_MODE_ORACLE + MODE_ORACLE | +#endif +#ifdef SPIDER_SQL_MODE_MSSQL + MODE_MSSQL | +#endif +#ifdef SPIDER_SQL_MODE_DB2 + MODE_DB2 | +#endif +#ifdef SPIDER_SQL_MODE_MAXDB + MODE_MAXDB | +#endif +#ifdef SPIDER_SQL_MODE_NO_KEY_OPTIONS + MODE_NO_KEY_OPTIONS | +#endif +#ifdef SPIDER_SQL_MODE_NO_TABLE_OPTIONS + MODE_NO_TABLE_OPTIONS | +#endif +#ifdef SPIDER_SQL_MODE_NO_FIELD_OPTIONS + MODE_NO_FIELD_OPTIONS | +#endif +#ifdef SPIDER_SQL_MODE_MYSQL323 + MODE_MYSQL323 | +#endif +#ifdef SPIDER_SQL_MODE_MYSQL40 + MODE_MYSQL40 | +#endif +#ifdef SPIDER_SQL_MODE_ANSI + MODE_ANSI | +#endif +#ifdef SPIDER_SQL_MODE_NO_AUTO_VALUE_ON_ZERO + MODE_NO_AUTO_VALUE_ON_ZERO | +#endif +#ifdef SPIDER_SQL_MODE_NO_BACKSLASH_ESCAPES + MODE_NO_BACKSLASH_ESCAPES | +#endif +#ifdef SPIDER_SQL_MODE_STRICT_TRANS_TABLES + MODE_STRICT_TRANS_TABLES | +#endif +#ifdef SPIDER_SQL_MODE_STRICT_ALL_TABLES + MODE_STRICT_ALL_TABLES | +#endif +#ifdef SPIDER_SQL_MODE_NO_ZERO_IN_DATE + MODE_NO_ZERO_IN_DATE | +#endif +#ifdef SPIDER_SQL_MODE_NO_ZERO_DATE + MODE_NO_ZERO_DATE | +#endif +#ifdef SPIDER_SQL_MODE_INVALID_DATES + MODE_INVALID_DATES | +#endif +#ifdef SPIDER_SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO + MODE_ERROR_FOR_DIVISION_BY_ZERO | +#endif +#ifdef SPIDER_SQL_MODE_TRADITIONAL + MODE_TRADITIONAL | +#endif +#ifdef SPIDER_SQL_MODE_NO_AUTO_CREATE_USER + MODE_NO_AUTO_CREATE_USER | +#endif +#ifdef SPIDER_SQL_MODE_HIGH_NOT_PRECEDENCE + MODE_HIGH_NOT_PRECEDENCE | +#endif +#ifdef SPIDER_SQL_MODE_NO_ENGINE_SUBSTITUTION + MODE_NO_ENGINE_SUBSTITUTION | +#endif +#ifdef SPIDER_SQL_MODE_PAD_CHAR_TO_FULL_LENGTH + MODE_PAD_CHAR_TO_FULL_LENGTH | +#endif +#ifdef SPIDER_SQL_MODE_EMPTY_STRING_IS_NULL + MODE_EMPTY_STRING_IS_NULL | +#endif +#ifdef SPIDER_SQL_MODE_SIMULTANEOUS_ASSIGNMENT + MODE_SIMULTANEOUS_ASSIGNMENT | +#endif +#ifdef SPIDER_SQL_MODE_TIME_ROUND_FRACTIONAL + MODE_TIME_ROUND_FRACTIONAL | +#endif + 0; + +int spider_db_mbase_util::append_sql_mode_internal( + spider_string *str, + sql_mode_t sql_mode +) { + DBUG_ENTER("spider_db_mbase_util::append_sql_mode_internal"); + DBUG_PRINT("info",("spider this=%p", this)); +#ifdef SPIDER_SQL_MODE_REAL_AS_FLOAT + if (sql_mode & MODE_REAL_AS_FLOAT) + { + if (str->reserve(SPIDER_REAL_AS_FLOAT_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_REAL_AS_FLOAT_STR, SPIDER_REAL_AS_FLOAT_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_PIPES_AS_CONCAT + if (sql_mode & MODE_PIPES_AS_CONCAT) + { + if (str->reserve(SPIDER_PIPES_AS_CONCAT_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_PIPES_AS_CONCAT_STR, SPIDER_PIPES_AS_CONCAT_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_ANSI_QUOTES + if (sql_mode & MODE_ANSI_QUOTES) + { + if (str->reserve(SPIDER_ANSI_QUOTES_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_ANSI_QUOTES_STR, SPIDER_ANSI_QUOTES_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_IGNORE_SPACE + if (sql_mode & MODE_IGNORE_SPACE) + { + if (str->reserve(SPIDER_IGNORE_SPACE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_IGNORE_SPACE_STR, SPIDER_IGNORE_SPACE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_IGNORE_BAD_TABLE_OPTIONS + if (sql_mode & MODE_IGNORE_BAD_TABLE_OPTIONS) + { + if (str->reserve(SPIDER_IGNORE_BAD_TABLE_OPTIONS_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_IGNORE_BAD_TABLE_OPTIONS_STR, SPIDER_IGNORE_BAD_TABLE_OPTIONS_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_ONLY_FULL_GROUP_BY + if (sql_mode & MODE_ONLY_FULL_GROUP_BY) + { + if (str->reserve(SPIDER_ONLY_FULL_GROUP_BY_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_ONLY_FULL_GROUP_BY_STR, SPIDER_ONLY_FULL_GROUP_BY_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_UNSIGNED_SUBTRACTION + if (sql_mode & MODE_NO_UNSIGNED_SUBTRACTION) + { + if (str->reserve(SPIDER_NO_UNSIGNED_SUBTRACTION_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_UNSIGNED_SUBTRACTION_STR, SPIDER_NO_UNSIGNED_SUBTRACTION_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_DIR_IN_CREATE + if (sql_mode & MODE_NO_DIR_IN_CREATE) + { + if (str->reserve(SPIDER_NO_DIR_IN_CREATE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_DIR_IN_CREATE_STR, SPIDER_NO_DIR_IN_CREATE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_POSTGRESQL + if (sql_mode & MODE_POSTGRESQL) + { + if (str->reserve(SPIDER_POSTGRESQL_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_POSTGRESQL_STR, SPIDER_POSTGRESQL_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_ORACLE + if (sql_mode & MODE_ORACLE) + { + if (str->reserve(SPIDER_ORACLE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_ORACLE_STR, SPIDER_ORACLE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_MSSQL + if (sql_mode & MODE_MSSQL) + { + if (str->reserve(SPIDER_MSSQL_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_MSSQL_STR, SPIDER_MSSQL_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_DB2 + if (sql_mode & MODE_DB2) + { + if (str->reserve(SPIDER_DB2_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_DB2_STR, SPIDER_DB2_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_MAXDB + if (sql_mode & MODE_MAXDB) + { + if (str->reserve(SPIDER_MAXDB_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_MAXDB_STR, SPIDER_MAXDB_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_KEY_OPTIONS + if (sql_mode & MODE_NO_KEY_OPTIONS) + { + if (str->reserve(SPIDER_NO_KEY_OPTIONS_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_KEY_OPTIONS_STR, SPIDER_NO_KEY_OPTIONS_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_TABLE_OPTIONS + if (sql_mode & MODE_NO_TABLE_OPTIONS) + { + if (str->reserve(SPIDER_NO_TABLE_OPTIONS_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_TABLE_OPTIONS_STR, SPIDER_NO_TABLE_OPTIONS_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_FIELD_OPTIONS + if (sql_mode & MODE_NO_FIELD_OPTIONS) + { + if (str->reserve(SPIDER_NO_FIELD_OPTIONS_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_FIELD_OPTIONS_STR, SPIDER_NO_FIELD_OPTIONS_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_MYSQL323 + if (sql_mode & MODE_MYSQL323) + { + if (str->reserve(SPIDER_MYSQL323_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_MYSQL323_STR, SPIDER_MYSQL323_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_MYSQL40 + if (sql_mode & MODE_MYSQL40) + { + if (str->reserve(SPIDER_MYSQL40_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_MYSQL40_STR, SPIDER_MYSQL40_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_ANSI + if (sql_mode & MODE_ANSI) + { + if (str->reserve(SPIDER_ANSI_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_ANSI_STR, SPIDER_ANSI_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_AUTO_VALUE_ON_ZERO + if (sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + { + if (str->reserve(SPIDER_NO_AUTO_VALUE_ON_ZERO_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_AUTO_VALUE_ON_ZERO_STR, SPIDER_NO_AUTO_VALUE_ON_ZERO_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_BACKSLASH_ESCAPES + if (sql_mode & MODE_NO_BACKSLASH_ESCAPES) + { + if (str->reserve(SPIDER_NO_BACKSLASH_ESCAPES_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_BACKSLASH_ESCAPES_STR, SPIDER_NO_BACKSLASH_ESCAPES_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_STRICT_TRANS_TABLES + if (sql_mode & MODE_STRICT_TRANS_TABLES) + { + if (str->reserve(SPIDER_STRICT_TRANS_TABLES_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_STRICT_TRANS_TABLES_STR, SPIDER_STRICT_TRANS_TABLES_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_STRICT_ALL_TABLES + if (sql_mode & MODE_STRICT_ALL_TABLES) + { + if (str->reserve(SPIDER_STRICT_ALL_TABLES_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_STRICT_ALL_TABLES_STR, SPIDER_STRICT_ALL_TABLES_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_ZERO_IN_DATE + if (sql_mode & MODE_NO_ZERO_IN_DATE) + { + if (str->reserve(SPIDER_NO_ZERO_IN_DATE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_ZERO_IN_DATE_STR, SPIDER_NO_ZERO_IN_DATE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_ZERO_DATE + if (sql_mode & MODE_NO_ZERO_DATE) + { + if (str->reserve(SPIDER_NO_ZERO_DATE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_ZERO_DATE_STR, SPIDER_NO_ZERO_DATE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_INVALID_DATES + if (sql_mode & MODE_INVALID_DATES) + { + if (str->reserve(SPIDER_INVALID_DATES_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_INVALID_DATES_STR, SPIDER_INVALID_DATES_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO + if (sql_mode & MODE_ERROR_FOR_DIVISION_BY_ZERO) + { + if (str->reserve(SPIDER_ERROR_FOR_DIVISION_BY_ZERO_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_ERROR_FOR_DIVISION_BY_ZERO_STR, SPIDER_ERROR_FOR_DIVISION_BY_ZERO_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_TRADITIONAL + if (sql_mode & MODE_TRADITIONAL) + { + if (str->reserve(SPIDER_TRADITIONAL_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_TRADITIONAL_STR, SPIDER_TRADITIONAL_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_AUTO_CREATE_USER + if (sql_mode & MODE_NO_AUTO_CREATE_USER) + { + if (str->reserve(SPIDER_NO_AUTO_CREATE_USER_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_AUTO_CREATE_USER_STR, SPIDER_NO_AUTO_CREATE_USER_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_HIGH_NOT_PRECEDENCE + if (sql_mode & MODE_HIGH_NOT_PRECEDENCE) + { + if (str->reserve(SPIDER_HIGH_NOT_PRECEDENCE_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_HIGH_NOT_PRECEDENCE_STR, SPIDER_HIGH_NOT_PRECEDENCE_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_NO_ENGINE_SUBSTITUTION + if (sql_mode & MODE_NO_ENGINE_SUBSTITUTION) + { + if (str->reserve(SPIDER_NO_ENGINE_SUBSTITUTION_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_NO_ENGINE_SUBSTITUTION_STR, SPIDER_NO_ENGINE_SUBSTITUTION_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_PAD_CHAR_TO_FULL_LENGTH + if (sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH) + { + if (str->reserve(SPIDER_PAD_CHAR_TO_FULL_LENGTH_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_PAD_CHAR_TO_FULL_LENGTH_STR, SPIDER_PAD_CHAR_TO_FULL_LENGTH_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif + DBUG_RETURN(0); +} + +int spider_db_mariadb_util::append_sql_mode_internal( + spider_string *str, + sql_mode_t sql_mode +) { + int error_num; + DBUG_ENTER("spider_db_mbase_util::append_sql_mode_internal"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((error_num = spider_db_mbase_util::append_sql_mode_internal( + str, sql_mode))) + { + DBUG_RETURN(error_num); + } +#ifdef SPIDER_SQL_MODE_EMPTY_STRING_IS_NULL + if (sql_mode & MODE_EMPTY_STRING_IS_NULL) + { + if (str->reserve(SPIDER_EMPTY_STRING_IS_NULL_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_EMPTY_STRING_IS_NULL_STR, SPIDER_EMPTY_STRING_IS_NULL_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_SIMULTANEOUS_ASSIGNMENT + if (sql_mode & MODE_SIMULTANEOUS_ASSIGNMENT) + { + if (str->reserve(SPIDER_SIMULTANEOUS_ASSIGNMENT_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SIMULTANEOUS_ASSIGNMENT_STR, SPIDER_SIMULTANEOUS_ASSIGNMENT_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif +#ifdef SPIDER_SQL_MODE_TIME_ROUND_FRACTIONAL + if (sql_mode & MODE_TIME_ROUND_FRACTIONAL) + { + if (str->reserve(SPIDER_TIME_ROUND_FRACTIONAL_LEN + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_TIME_ROUND_FRACTIONAL_STR, SPIDER_TIME_ROUND_FRACTIONAL_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } +#endif + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_sql_mode( + spider_string *str, + sql_mode_t sql_mode +) { + int error_num; + uint length; + DBUG_ENTER("spider_db_mbase_util::append_sql_mode"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_SQL_MODE_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_SQL_MODE_STR, SPIDER_SQL_SQL_MODE_LEN); + length = str->length(); + if ((error_num = append_sql_mode_internal(str, sql_mode))) + { + DBUG_RETURN(error_num); + } + if (str->length() > length) + { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } else { + 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); + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_time_zone( + spider_string *str, + Time_zone *time_zone +) { + const String *tz_str = time_zone->get_name(); + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_loop_check( + spider_string *str, + SPIDER_CONN *conn +) { + SPIDER_CONN_LOOP_CHECK *lcptr; + DBUG_ENTER("spider_db_mbase_util::append_loop_check"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider str=%s", str->c_ptr_safe())); + uint l = 0; + while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element( + &conn->loop_check_queue, l))) + { + DBUG_PRINT("info",("spider lcptr=%p", lcptr)); + if (str->reserve(SPIDER_SQL_SEMICOLON_LEN + SPIDER_SQL_SET_USER_VAL_LEN + + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN + lcptr->to_name.length + + SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_EQUAL_LEN + + SPIDER_SQL_VALUE_QUOTE_LEN + + lcptr->merged_value.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_SET_USER_VAL_STR, SPIDER_SQL_SET_USER_VAL_LEN); + str->q_append(SPIDER_SQL_LOP_CHK_PRM_PRF_STR, + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN); + str->q_append(lcptr->to_name.str, lcptr->to_name.length); + str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_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(lcptr->merged_value.str, lcptr->merged_value.length); + str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + + ++l; + DBUG_PRINT("info",("spider str=%s", str->c_ptr_safe())); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_start_transaction( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_xa_start( + spider_string *str, + XID *xid +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_lock_table_head( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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_mbase_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_mbase_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_mbase_util::append_lock_table_tail( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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_mbase_util::append_unlock_table( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_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); +} + +/** + The function check if the given item_func and its arguments can be pushed + down to a data node. If so and str != NULL, the function also print, to str, + the string corresponding to the item_func. + + @return 0: success, otherwise: error + */ +int spider_db_mbase_util::open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + DBUG_ENTER("spider_db_mbase_util::open_item_func"); + + int error = check_item_func(item_func, spider, alias, + alias_length, use_fields, fields); + if (error) + DBUG_RETURN(error); + if (!str) + DBUG_RETURN(0); + + DBUG_RETURN(print_item_func(item_func, spider, str, alias, + alias_length, use_fields, fields)); +} + +static bool item_func_is_timestampdiff( + const char *func_name, + int func_name_length +) { + return func_name_length == 13 && + !strncasecmp("timestampdiff", func_name, func_name_length); +} + +static bool not_func_should_be_skipped( + Item_func *item_func +){ + DBUG_ENTER("not_func_should_be_skipped"); + DBUG_ASSERT(item_func->functype() == Item_func::NOT_FUNC); + Item **item_list = item_func->arguments(); + + if (item_list[0]->type() == Item::COND_ITEM) + { + DBUG_PRINT("info",("spider item_list[0] is COND_ITEM")); + Item_cond *item_cond = (Item_cond *) item_list[0]; + if (item_cond->functype() == Item_func::COND_AND_FUNC) + { + DBUG_PRINT("info",("spider item_cond is COND_AND_FUNC")); + List_iterator_fast lif(*(item_cond->argument_list())); + bool has_expr_cache_item = FALSE; + bool has_isnotnull_func = FALSE; + bool has_other_item = FALSE; + while(Item *item = lif++) + { + if ( + item->type() == Item::EXPR_CACHE_ITEM + ) { + DBUG_PRINT("info",("spider EXPR_CACHE_ITEM")); + has_expr_cache_item = TRUE; + } else + if ( + item->type() == Item::FUNC_ITEM && + ((Item_func *) item)->functype() == Item_func::ISNOTNULL_FUNC + ) { + DBUG_PRINT("info",("spider ISNOTNULL_FUNC")); + has_isnotnull_func = TRUE; + } else { + DBUG_PRINT("info",("spider has other item")); + DBUG_PRINT("info",("spider COND type=%d", item->type())); + has_other_item = TRUE; + } + } + if (has_expr_cache_item && has_isnotnull_func && !has_other_item) + { + DBUG_PRINT("info",("spider NOT EXISTS skip")); + DBUG_RETURN(TRUE); + } + } + } + DBUG_RETURN(FALSE); +} + +/** + Check if the given item_func and its arguments can be pushed down to + a data node. This function is recursive because we need to also check + the arguments of the item_func. + + @return 0: success, otherwise: error + */ +int spider_db_mbase_util::check_item_func( + Item_func *item_func, + ha_spider *spider, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + int use_pushdown_udf; + DBUG_ENTER("spider_db_mbase_util::check_item_func"); + + Item_func::Functype func_type = item_func->functype(); + DBUG_PRINT("info",("spider functype = %d", func_type)); + + const char *func_name = (char*) item_func->func_name(); + int func_name_length = strlen(func_name); + DBUG_PRINT("info",("spider func_name = %s", func_name)); + + /* The blacklist of the functions that cannot be pushed down */ + switch (func_type) + { + case Item_func::TRIG_COND_FUNC: + case Item_func::CASE_SEARCHED_FUNC: + case Item_func::CASE_SIMPLE_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::NOT_FUNC: + /* Why the following check is necessary? */ + if (not_func_should_be_skipped(item_func)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + break; + case Item_func::FUNC_SP: + case Item_func::UDF_FUNC: + /* Notes on merging regarding MDEV-29447: please refer to the + following commits for build error or merge conflicts: + 10.6: 1ed20b993b0dd4e95450cab2e8347e5bf4617a69 + 10.9: dd316b6e20265cfd832bb5585cb4c96e716387c8 + 10.10-11: 3f67f110ba1b23a89c5ede0fbeeb203cf5e164f4 + 11.0-1: 17ba6748afa8834df5658361088e6c8e65aca16f + Please remove this comment after merging. */ + use_pushdown_udf= spider_param_use_pushdown_udf( + spider->wide_handler->trx->thd, spider->share->use_pushdown_udf); + if (!use_pushdown_udf) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + break; + case Item_func::FT_FUNC: + if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + break; +#ifndef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC + case Item_func::UNKNOWN_FUNC: + if (item_func_is_timestampdiff(func_name, func_name_length)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + break; +#endif + default: + break; + } + /* End of the blacklist */ + + /* Check the arguments recursively */ + if (uint item_count = item_func->argument_count()) + { + Item **item_list = item_func->arguments(); + for (uint roop_count = 0; roop_count < item_count; roop_count++) + { + Item *item = item_list[roop_count]; + if (int error_num = spider_db_print_item_type(item, NULL, spider, NULL, + alias, alias_length, dbton_id, use_fields, fields)) + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +/** + The function print the string corresponding to the given item_func to str. + The function is assumed to be called only when the check by the function + check_item_func() has passed. + + @return 0: success, otherwise: error + */ +int spider_db_mbase_util::print_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + int error_num; + Item *item, **item_list = item_func->arguments(); + Field *field; + spider_string tmp_str; + uint roop_count, item_count = item_func->argument_count(), start_item = 0; + LEX_CSTRING org_func_name= {SPIDER_SQL_NULL_CHAR_STR, + SPIDER_SQL_NULL_CHAR_LEN}; + const char *func_name = SPIDER_SQL_NULL_CHAR_STR, + *separator_str = SPIDER_SQL_NULL_CHAR_STR, + *last_str = SPIDER_SQL_NULL_CHAR_STR; + int func_name_length = SPIDER_SQL_NULL_CHAR_LEN, + separator_str_length = SPIDER_SQL_NULL_CHAR_LEN, + last_str_length = SPIDER_SQL_NULL_CHAR_LEN; + int use_pushdown_udf; + bool merge_func = FALSE; + DBUG_ENTER("spider_db_mbase_util::print_item_func"); + DBUG_ASSERT(!check_item_func(item_func, spider, alias, alias_length, + use_fields, fields)); + DBUG_ASSERT(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: + org_func_name= item_func->func_name_cstring(); + func_name= org_func_name.str; + func_name_length = org_func_name.length; + 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->argument_count() + ) { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + } else if ( + !strncasecmp("trim", func_name, func_name_length) && + item_count == 2 + ) { + /* item_count == 1 means this TRIM() is without a remove_str */ + item = item_list[0]; + Item *item_tmp = item_list[1]; + + if (item_tmp->is_of_type(Item::CONST_ITEM, STRING_RESULT)) + { + /* 1. append 'TRIM(BOTH ' */ + if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + SPIDER_SQL_TRIM_BOTH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_TRIM_BOTH_STR, SPIDER_SQL_TRIM_BOTH_LEN); + /* 2. append "remove_str"*/ + if ((error_num = spider_db_print_item_type( + item_tmp, NULL, spider, str, alias, alias_length, dbton_id, + use_fields, fields))) + DBUG_RETURN(error_num); + /* 3. append ' FROM ' */ + if (str->reserve(SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + /* 4. append `field` */ + if ((error_num = spider_db_print_item_type( + item, NULL, spider, str, alias, alias_length, dbton_id, + use_fields, fields))) + DBUG_RETURN(error_num); + /* 5. append ')' */ + 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); + } + item_count -= 2; + break; + } + } else if (func_name_length == 5) + { + if ( + (!strncasecmp("ltrim", func_name, func_name_length) || + !strncasecmp("rtrim", func_name, func_name_length)) && + (item_count == 2) + ) { + /* the func_name for TRIM(LEADING ...) is LTRIM, for TRIM(TRAILING) is RTRIM */ + /* item_count == 2 means this TRIM(LEADING/TRAILING ...) is with a remove_str */ + item = item_list[0]; + Item *item_tmp = item_list[1]; + if (item_tmp->is_of_type(Item::CONST_ITEM, STRING_RESULT)) + { + /* 1. append 'TRIM(LEADING ' or 'TRIM(TRAILING ' */ + if (func_name[0] == 'l' || func_name[0] == 'L') + { /* ltrim */ + if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + SPIDER_SQL_TRIM_LEADING_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_TRIM_LEADING_STR, SPIDER_SQL_TRIM_LEADING_LEN); + } else + { /* rtrim */ + if (str->reserve(SPIDER_SQL_TRIM_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + SPIDER_SQL_TRIM_TRAILING_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_TRIM_STR, SPIDER_SQL_TRIM_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(SPIDER_SQL_TRIM_TRAILING_STR, SPIDER_SQL_TRIM_TRAILING_LEN); + } + /* 2. append "remove_str"*/ + if ((error_num = spider_db_print_item_type( + item_tmp, NULL, spider, str, alias, alias_length, dbton_id, + use_fields, fields))) + DBUG_RETURN(error_num); + /* 3. append ' FROM ' */ + if (str->reserve(SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + /* 4. append `field` */ + if ((error_num = spider_db_print_item_type( + item, NULL, spider, str, alias, alias_length, dbton_id, + use_fields, fields))) + DBUG_RETURN(error_num); + /* 5. append ')' */ + 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); + } + item_count -= 2; + break; + } + } 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) + ) { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + } else if ( + !strncasecmp("convert", func_name, func_name_length) + ) { + 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) + ) + ) { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + } 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) + { + if (!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 (!strncasecmp("column_get", func_name, func_name_length)) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_str_length = SPIDER_SQL_COMMA_LEN; + break; + } + } else if (func_name_length == 12) + { + if (!strncasecmp("cast_as_date", func_name, func_name_length)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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) + { + if (!strncasecmp("utc_timestamp", func_name, func_name_length)) + { + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + } else if (!strncasecmp("timestampdiff", func_name, func_name_length)) + { +#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC + Item_func_timestamp_diff *item_func_timestamp_diff = + (Item_func_timestamp_diff *) item_func; + const char *interval_str; + uint interval_len; + switch (item_func_timestamp_diff->int_type) + { + case INTERVAL_YEAR: + interval_str = SPIDER_SQL_YEAR_STR; + interval_len = SPIDER_SQL_YEAR_LEN; + break; + case INTERVAL_QUARTER: + interval_str = SPIDER_SQL_QUARTER_STR; + interval_len = SPIDER_SQL_QUARTER_LEN; + break; + case INTERVAL_MONTH: + interval_str = SPIDER_SQL_MONTH_STR; + interval_len = SPIDER_SQL_MONTH_LEN; + break; + case INTERVAL_WEEK: + interval_str = SPIDER_SQL_WEEK_STR; + interval_len = SPIDER_SQL_WEEK_LEN; + break; + case INTERVAL_DAY: + interval_str = SPIDER_SQL_DAY_STR; + interval_len = SPIDER_SQL_DAY_LEN; + break; + case INTERVAL_HOUR: + interval_str = SPIDER_SQL_HOUR_STR; + interval_len = SPIDER_SQL_HOUR_LEN; + break; + case INTERVAL_MINUTE: + interval_str = SPIDER_SQL_MINUTE_STR; + interval_len = SPIDER_SQL_MINUTE_LEN; + break; + case INTERVAL_SECOND: + interval_str = SPIDER_SQL_SECOND_STR; + interval_len = SPIDER_SQL_SECOND_LEN; + break; + case INTERVAL_MICROSECOND: + interval_str = SPIDER_SQL_MICROSECOND_STR; + interval_len = SPIDER_SQL_MICROSECOND_LEN; + break; + default: + interval_str = ""; + interval_len = 0; + break; + } + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (str->reserve(func_name_length + SPIDER_SQL_OPEN_PAREN_LEN + + interval_len + SPIDER_SQL_COMMA_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); + str->q_append(interval_str, interval_len); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + + if ((error_num = spider_db_print_item_type(item_list[0], NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + 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_print_item_type(item_list[1], NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + 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); +#else + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); +#endif + } + } else if (func_name_length == 14) + { + if (!strncasecmp("cast_as_binary", func_name, func_name_length)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + char *tmp_ptr, *tmp_ptr2; + DBUG_ASSERT(tmp_str.length() == 0); + tmp_str.set_charset(str->charset()); + tmp_str.init_calc_mem(123); + tmp_str.reserve(MAX_FIELD_WIDTH); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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); + } + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); + 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)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + char *tmp_ptr, *tmp_ptr2; + DBUG_ASSERT(tmp_str.length() == 0); + tmp_str.set_charset(str->charset()); + tmp_str.init_calc_mem(124); + tmp_str.reserve(MAX_FIELD_WIDTH); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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); + } + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); + 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)) + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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], NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + 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], NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + 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->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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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: + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(spider_db_open_item_string(item_func, NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields)); + case Item_func::CHAR_TYPECAST_FUNC: + DBUG_PRINT("info",("spider CHAR_TYPECAST_FUNC")); + { + item = item_list[0]; + if (item->type() == Item::FUNC_ITEM) + { + DBUG_PRINT("info",("spider child is FUNC_ITEM")); + Item_func *ifunc = (Item_func *) item; + if (ifunc->functype() == Item_func::UNKNOWN_FUNC) + { + const char *child_func_name; + int child_func_name_length; + LEX_CSTRING org_func_name= ifunc->func_name_cstring(); + DBUG_PRINT("info",("spider child is UNKNOWN_FUNC")); + child_func_name = org_func_name.str; + child_func_name_length = org_func_name.length; + DBUG_PRINT("info",("spider child func_name is %s", child_func_name)); + if ( + child_func_name_length == 10 && + !strncasecmp("column_get", child_func_name, child_func_name_length) + ) { + DBUG_PRINT("info",("spider this is merge func")); + merge_func = TRUE; + } + } + } + + char *tmp_ptr, *tmp_ptr2; + DBUG_ASSERT(tmp_str.length() == 0); + tmp_str.set_charset(str->charset()); + tmp_str.init_calc_mem(125); + tmp_str.reserve(MAX_FIELD_WIDTH); + str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN); + if (!merge_func) + { + 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); + } + item_func->print(tmp_str.get_str(), QT_TO_SYSTEM_CHARSET); + 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: + DBUG_PRINT("info",("spider NOT_FUNC")); + /* Why the following check is necessary? */ + if (not_func_should_be_skipped(item_func)) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + } + 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::NEG_FUNC: + { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + } + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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; + separator_str = SPIDER_SQL_AND_STR; + separator_str_length = SPIDER_SQL_AND_LEN; + } else { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + separator_str = SPIDER_SQL_AND_STR; + separator_str_length = SPIDER_SQL_AND_LEN; + } + break; + case Item_func::FUNC_SP: + case Item_func::UDF_FUNC: + use_pushdown_udf = spider_param_use_pushdown_udf( + spider->wide_handler->trx->thd, + spider->share->use_pushdown_udf); + if (!use_pushdown_udf) + /* + This is the default behavior because the remote nodes may deal with + the function in an unexpected way (e.g. not having the same + definition). Users can turn it on if they know what they are doing. + */ + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + } + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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::TRIG_COND_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::GUSERVAR_FUNC: + 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, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + else + DBUG_RETURN(spider_db_open_item_int(item_func, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields)); + 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->reserve(SPIDER_SQL_MATCH_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MATCH_STR, SPIDER_SQL_MATCH_LEN); + separator_str = SPIDER_SQL_COMMA_STR; + separator_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: + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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: + { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + } + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_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::XOR_FUNC: + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + break; + case Item_func::LIKE_FUNC: + if (((Item_func_like *)item_func)->get_negated()) + { + func_name = SPIDER_SQL_NOT_LIKE_STR; + func_name_length = SPIDER_SQL_NOT_LIKE_LEN; + } + else + { + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + } + break; + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::CASE_SEARCHED_FUNC: + case Item_func::CASE_SIMPLE_FUNC: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + case Item_func::JSON_EXTRACT_FUNC: + func_name = (char*) item_func->func_name(); + func_name_length = strlen(func_name); + 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; + separator_str = SPIDER_SQL_COMMA_STR; + separator_str_length = SPIDER_SQL_COMMA_LEN; + last_str = SPIDER_SQL_CLOSE_PAREN_STR; + last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN; + break; + default: + THD *thd = spider->wide_handler->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); + LEX_CSTRING org_func_name= item_func->func_name_cstring(); + func_name = org_func_name.str; + func_name_length = org_func_name.length; + 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 separator_str = %s", separator_str)); + DBUG_PRINT("info",("spider separator_str_length = %d", separator_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) + { + /* Find the field in the list of items of the expression tree */ + field = spider_db_find_field_in_item_list(item_list, + item_count, start_item, + str, + func_name, func_name_length); + item_count--; + /* + Loop through the items of the current function expression to + print its portion of the statement + */ + 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, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + if (roop_count == 1) + { + /* Remaining operands need to be preceded by the separator */ + func_name = separator_str; + func_name_length = separator_str_length; + } + 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); + } + + /* Print the last operand value */ + item = item_list[roop_count]; + if ((error_num = spider_db_print_item_type(item, field, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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->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, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + DBUG_RETURN(error_num); + if (str->reserve( + ((item_func_match->match_flags & FT_BOOL) ? + SPIDER_SQL_IN_BOOLEAN_MODE_LEN : 0) + + ((item_func_match->match_flags & FT_EXPAND) ? + SPIDER_SQL_WITH_QUERY_EXPANSION_LEN : 0) + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (item_func_match->match_flags & FT_BOOL) + str->q_append(SPIDER_SQL_IN_BOOLEAN_MODE_STR, + SPIDER_SQL_IN_BOOLEAN_MODE_LEN); + if (item_func_match->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) + ) { + Item_func_conv_charset *item_func_conv_charset = + (Item_func_conv_charset *)item_func; + CHARSET_INFO *conv_charset = + item_func_conv_charset->SPIDER_Item_func_conv_charset_conv_charset; + uint cset_length = conv_charset->cs_name.length; + 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->cs_name.str, cset_length); + } + } + if (merge_func) + str->length(str->length() - SPIDER_SQL_CLOSE_PAREN_LEN); + 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_mbase_util::open_item_sum_func( + Item_sum *item_sum, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + uint roop_count, item_count = item_sum->get_arg_count(); + int error_num; + DBUG_ENTER("spider_db_mbase_util::open_item_sum_func"); + DBUG_PRINT("info",("spider Sumfunctype = %d", item_sum->sum_func())); + switch (item_sum->sum_func()) + { + case Item_sum::COUNT_FUNC: + case Item_sum::SUM_FUNC: + case Item_sum::MIN_FUNC: + case Item_sum::MAX_FUNC: + { + LEX_CSTRING org_func_name= item_sum->func_name_cstring(); + const char *func_name = org_func_name.str; + uint func_name_length = org_func_name.length; + Item *item, **args = item_sum->get_args(); + if (str) + { + if (str->reserve(func_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + } + if (item_count) + { + item_count--; + for (roop_count = 0; roop_count < item_count; roop_count++) + { + item = args[roop_count]; + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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 = args[roop_count]; + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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); + } + } + break; + case Item_sum::COUNT_DISTINCT_FUNC: + case Item_sum::SUM_DISTINCT_FUNC: + case Item_sum::AVG_FUNC: + case Item_sum::AVG_DISTINCT_FUNC: + { + if (!use_fields) + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + LEX_CSTRING org_func_name= item_sum->func_name_cstring(); + const char *func_name = org_func_name.str; + uint func_name_length = org_func_name.length; + Item *item, **args = item_sum->get_args(); + if (str) + { + if (str->reserve(func_name_length)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(func_name, func_name_length); + } + if (item_count) + { + item_count--; + for (roop_count = 0; roop_count < item_count; roop_count++) + { + item = args[roop_count]; + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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 = args[roop_count]; + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + 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); + } + } + break; + case Item_sum::STD_FUNC: + case Item_sum::VARIANCE_FUNC: + case Item_sum::SUM_BIT_FUNC: + case Item_sum::UDF_SUM_FUNC: + case Item_sum::GROUP_CONCAT_FUNC: + default: + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_escaped_util( + spider_string *to, + String *from +) { + DBUG_ENTER("spider_db_mbase_util::append_escaped_util"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider from=%s", from->charset()->cs_name.str)); + DBUG_PRINT("info",("spider to=%s", to->charset()->cs_name.str)); + to->append_escape_string(from->ptr(), from->length()); + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_table( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr, + bool top_down, + bool first +) { + int error_num; + bool use_cond_table_list = FALSE; + spider_mbase_share *db_share; + spider_mbase_handler *dbton_hdl; + SPIDER_TABLE_HOLDER *table_holder; + TABLE_LIST *cond_table_list = *cond_table_list_ptr; + ha_spider *spd; + DBUG_ENTER("spider_db_mbase_util::append_table"); + DBUG_PRINT("info",("spider table_list=%p", table_list)); + DBUG_PRINT("info",("spider table_list->outer_join=%u", + table_list->outer_join)); + DBUG_PRINT("info",("spider table_list->on_expr=%p", + table_list->on_expr)); + DBUG_PRINT("info",("spider table_list->join_using_fields=%p", + table_list->join_using_fields)); + DBUG_PRINT("info",("spider table_list->table=%p", + table_list->table)); + if (!top_down && table_list->embedding) + { + if ((error_num = append_embedding_tables(spider, fields, str, + table_list->embedding, used_table_list, current_pos, + cond_table_list_ptr))) + DBUG_RETURN(error_num); + } else if (!table_list->table) + { + if ((error_num = append_tables_top_down(spider, fields, str, table_list, + used_table_list, current_pos, cond_table_list_ptr))) + DBUG_RETURN(error_num); + } else { + if ( + table_list->outer_join || + table_list->on_expr || + table_list->join_using_fields + ) { + DBUG_PRINT("info",("spider use table_list")); + if (table_list->outer_join & JOIN_TYPE_LEFT) + { + if (str) + { + if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN); + } + } else { + if (str) + { + if (str->reserve(SPIDER_SQL_JOIN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN); + } + } + } else if ( + cond_table_list && + ( + cond_table_list->outer_join || + cond_table_list->on_expr || + cond_table_list->join_using_fields + ) + ) { + DBUG_PRINT("info",("spider use cond_table_list")); + if (cond_table_list->outer_join & (JOIN_TYPE_LEFT | JOIN_TYPE_RIGHT)) + { + if (str) + { + if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN); + } + } else { + if (str) + { + if (str->reserve(SPIDER_SQL_JOIN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN); + } + } + use_cond_table_list = TRUE; + } else if (*current_pos > 0 && !first) + { + DBUG_PRINT("info",("spider no condition")); + if (str) + { + if (str->reserve(SPIDER_SQL_JOIN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN); + } + } + + if (str) + { + table_holder = fields->get_table_holder(table_list->table); + spd = table_holder->spider; + db_share = (spider_mbase_share *) + spd->share->dbton_share[dbton_id]; + dbton_hdl = (spider_mbase_handler *) + spd->dbton_handler[dbton_id]; + + dbton_hdl->table_name_pos = str->length(); + + if (str->reserve( + db_share->db_nm_max_length + + SPIDER_SQL_DOT_LEN + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 + + db_share->table_nm_max_length + SPIDER_SQL_SPACE_LEN + + table_holder->alias->length() - SPIDER_SQL_DOT_LEN + )) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + if ((error_num = db_share->append_table_name_with_adjusting(str, + spd->conn_link_idx[dbton_hdl->first_link_idx]))) + { + DBUG_RETURN(error_num); + } + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(table_holder->alias->ptr(), + table_holder->alias->length() - SPIDER_SQL_DOT_LEN); + } + used_table_list[(*current_pos)++] = table_list; + + if (str) + { + List *join_using_fields = table_list->join_using_fields; + if (!join_using_fields && cond_table_list) + { + join_using_fields = cond_table_list->join_using_fields; + } + + if (join_using_fields) + { + if (str->reserve(SPIDER_SQL_USING_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + List_iterator_fast it2(*join_using_fields); + String *ptr; + while ((ptr = it2++)) + { + if (str->reserve(ptr->length() + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(ptr->ptr(), ptr->length()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + 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); + } + } + + Item *on_expr = table_list->on_expr; + if (!on_expr && cond_table_list) + { + on_expr = cond_table_list->on_expr; + } + + if (on_expr) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ON_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_ON_STR, SPIDER_SQL_ON_LEN); + } + if ((error_num = spider_db_print_item_type(on_expr, NULL, + spider, str, NULL, 0, dbton_id, TRUE, fields))) + { + DBUG_RETURN(error_num); + } + } + + if (use_cond_table_list) + { + (*cond_table_list_ptr) = NULL; + DBUG_PRINT("info",("spider cond_table_list=%p", (*cond_table_list_ptr))); + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_tables_top_down( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr +) { + int error_num; + uint outer_join_backup; + TABLE_LIST *cur_table_list, *prev_table_list = NULL, *cond_table_list = NULL; + bool first = TRUE; + DBUG_ENTER("spider_db_mbase_util::append_tables_top_down"); + DBUG_PRINT("info",("spider this=%p", this)); + if ( + table_list->outer_join || + table_list->on_expr || + table_list->join_using_fields + ) { + DBUG_ASSERT(!(*cond_table_list_ptr)); + (*cond_table_list_ptr) = table_list; + DBUG_PRINT("info",("spider cond_table_list=%p", table_list)); + } + List_iterator_fast it1(table_list->nested_join->join_list); + cur_table_list = it1++; + if (cur_table_list->outer_join & JOIN_TYPE_RIGHT) + { + first = FALSE; + prev_table_list = cur_table_list; + cur_table_list = it1++; + } else if (*cond_table_list_ptr) + { + first = TRUE; + cond_table_list = (*cond_table_list_ptr); + (*cond_table_list_ptr) = NULL; + if (cond_table_list->outer_join & JOIN_TYPE_LEFT) + { + if (str) + { + if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + } else { + if (str) + { + if (str->reserve(SPIDER_SQL_JOIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + } + } + } + + do { + if (cur_table_list->outer_join & JOIN_TYPE_RIGHT) + { + prev_table_list = cur_table_list; + } else { + if ((error_num = append_table(spider, fields, str, cur_table_list, + used_table_list, current_pos, cond_table_list_ptr, TRUE, first))) + DBUG_RETURN(error_num); + first = FALSE; + if (prev_table_list) + { + outer_join_backup = prev_table_list->outer_join; + prev_table_list->outer_join = JOIN_TYPE_LEFT; + if ((error_num = append_table(spider, fields, str, prev_table_list, + used_table_list, current_pos, cond_table_list_ptr, TRUE, FALSE))) + { + prev_table_list->outer_join = outer_join_backup; + DBUG_RETURN(error_num); + } + prev_table_list->outer_join = outer_join_backup; + prev_table_list = NULL; + } + } + } while ((cur_table_list = it1++)); + + if (cond_table_list) + { + 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); + + List *join_using_fields = cond_table_list->join_using_fields; + if (join_using_fields) + { + if (str->reserve(SPIDER_SQL_USING_LEN + SPIDER_SQL_OPEN_PAREN_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, + SPIDER_SQL_OPEN_PAREN_LEN); + List_iterator_fast it2(*join_using_fields); + String *ptr; + while ((ptr = it2++)) + { + if (str->reserve(ptr->length() + SPIDER_SQL_COMMA_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(ptr->ptr(), ptr->length()); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + 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); + } + } + + Item *on_expr = cond_table_list->on_expr; + if (on_expr) + { + if (str) + { + if (str->reserve(SPIDER_SQL_ON_LEN)) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_ON_STR, SPIDER_SQL_ON_LEN); + } + if ((error_num = spider_db_print_item_type(on_expr, NULL, + spider, str, NULL, 0, dbton_id, TRUE, fields))) + { + DBUG_RETURN(error_num); + } + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_tables_top_down_check( + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos +) { + int error_num; + TABLE_LIST *cur_table_list; + DBUG_ENTER("spider_db_mbase_util::append_tables_top_down_check"); + DBUG_PRINT("info",("spider this=%p", this)); + List_iterator_fast it1(table_list->nested_join->join_list); + while ((cur_table_list = it1++)) + { + if (!cur_table_list->table) + { + if ((error_num = append_tables_top_down_check( + cur_table_list, used_table_list, current_pos))) + DBUG_RETURN(error_num); + } else { + used_table_list[(*current_pos)++] = cur_table_list; + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_embedding_tables( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr +) { + int error_num; + TABLE_LIST *embedding = table_list->embedding; + DBUG_ENTER("spider_db_mbase_util::append_embedding_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + if (embedding) + { + DBUG_PRINT("info",("spider embedding=%p", embedding)); + DBUG_PRINT("info",("spider embedding->outer_join=%u", + embedding->outer_join)); + DBUG_PRINT("info",("spider embedding->on_expr=%p", + embedding->on_expr)); + DBUG_PRINT("info",("spider embedding->join_using_fields=%p", + embedding->join_using_fields)); + DBUG_PRINT("info",("spider embedding->table=%p", + embedding->table)); + if ((error_num = append_embedding_tables(spider, fields, str, embedding, + used_table_list, current_pos, cond_table_list_ptr))) + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info",("spider table_list=%p", table_list)); + DBUG_PRINT("info",("spider table_list->outer_join=%u", + table_list->outer_join)); + DBUG_PRINT("info",("spider table_list->on_expr=%p", + table_list->on_expr)); + DBUG_PRINT("info",("spider table_list->join_using_fields=%p", + table_list->join_using_fields)); + DBUG_PRINT("info",("spider table_list->table=%p", + table_list->table)); + if (table_list->outer_join & JOIN_TYPE_RIGHT) + { + if ((error_num = append_tables_top_down_check(table_list, + used_table_list, current_pos))) + DBUG_RETURN(error_num); + DBUG_ASSERT(!(*cond_table_list_ptr)); + (*cond_table_list_ptr) = table_list; + DBUG_PRINT("info",("spider cond_table_list=%p", table_list)); + } else { + if ((error_num = append_tables_top_down(spider, fields, str, table_list, + used_table_list, current_pos, cond_table_list_ptr))) + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_from_and_tables( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + uint table_count +) { + int error_num; + uint current_pos = 0, roop_count, backup_pos, outer_join_backup; + TABLE *table; + TABLE_LIST **used_table_list, *prev_table_list = NULL, + *cond_table_list = NULL; + DBUG_ENTER("spider_db_mbase_util::append_from_and_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + used_table_list = (TABLE_LIST **) + my_alloca(sizeof(TABLE_LIST *) * table_count); + if (!used_table_list) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + + if (str) + { + if (str->reserve(SPIDER_SQL_FROM_LEN)) + { + my_afree(used_table_list); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + } + + do { + table = table_list->table; + if (table->const_table) + continue; + + for (roop_count = 0; roop_count < current_pos; ++roop_count) + { + if (used_table_list[roop_count] == table_list) + break; + } + if (roop_count < current_pos) + continue; + + if (prev_table_list) + current_pos = backup_pos; + else + backup_pos = current_pos; + if ((error_num = append_table(spider, fields, str, table_list, used_table_list, + ¤t_pos, &cond_table_list, FALSE, FALSE))) + { + my_afree(used_table_list); + DBUG_RETURN(error_num); + } + if (prev_table_list) + { + outer_join_backup = prev_table_list->outer_join; + prev_table_list->outer_join = JOIN_TYPE_LEFT; + if ((error_num = append_table(spider, fields, str, prev_table_list, + used_table_list, ¤t_pos, &cond_table_list, FALSE, FALSE))) + { + prev_table_list->outer_join = outer_join_backup; + my_afree(used_table_list); + DBUG_RETURN(error_num); + } + prev_table_list->outer_join = outer_join_backup; + prev_table_list = NULL; + } + if (cond_table_list && (cond_table_list->outer_join & JOIN_TYPE_RIGHT)) + { + prev_table_list = cond_table_list; + cond_table_list = NULL; + DBUG_PRINT("info",("spider cond_table_list=%p", cond_table_list)); + } + } while ((table_list = table_list->next_local)); + my_afree(used_table_list); + DBUG_RETURN(0); +} + +int spider_db_mbase_util::reappend_tables( + spider_fields *fields, + SPIDER_LINK_IDX_CHAIN *link_idx_chain, + spider_string *str +) { + int error_num; + uint32 length; + ha_spider *spider; + spider_mbase_share *db_share; + spider_mbase_handler *dbton_hdl; + SPIDER_TABLE_HOLDER *table_holder; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + DBUG_ENTER("spider_db_mbase_util::reappend_tables"); + DBUG_PRINT("info",("spider this=%p", this)); + length = str->length(); + fields->set_pos_to_first_table_on_link_idx_chain(link_idx_chain); + fields->set_pos_to_first_table_holder(); + while ((table_holder = fields->get_next_table_holder())) + { + link_idx_holder = + fields->get_next_table_on_link_idx_chain(link_idx_chain); + spider = table_holder->spider; + db_share = (spider_mbase_share *) + spider->share->dbton_share[dbton_id]; + if (!db_share->same_db_table_name) + { + dbton_hdl = (spider_mbase_handler *) spider->dbton_handler[dbton_id]; + str->length(dbton_hdl->table_name_pos); + if ((error_num = db_share->append_table_name_with_adjusting(str, + spider->conn_link_idx[link_idx_holder->link_idx]))) + { + DBUG_RETURN(error_num); + } + } + } + str->length(length); + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_where( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_util::append_where"); + DBUG_PRINT("info",("spider this=%p", this)); + 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); + DBUG_RETURN(0); +} + +int spider_db_mbase_util::append_having( + spider_string *str +) { + DBUG_ENTER("spider_db_mbase_util::append_having"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve(SPIDER_SQL_HAVING_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_HAVING_STR, SPIDER_SQL_HAVING_LEN); + DBUG_RETURN(0); +} + +bool spider_db_mbase_util::tables_on_different_db_are_joinable() +{ + DBUG_ENTER("spider_db_mbase_util::tables_on_different_db_are_joinable"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::socket_has_default_value() +{ + DBUG_ENTER("spider_db_mbase_util::socket_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::database_has_default_value() +{ + DBUG_ENTER("spider_db_mbase_util::database_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::default_file_has_default_value() +{ + DBUG_ENTER("spider_db_mbase_util::default_file_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::host_has_default_value() +{ + DBUG_ENTER("spider_db_mbase_util::host_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::port_has_default_value() +{ + DBUG_ENTER("spider_db_mbase_util::port_has_default_value"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_db_mbase_util::append_charset_name_before_string() +{ + DBUG_ENTER("spider_db_mbase_util::append_charset_name_before_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +spider_mbase_share::spider_mbase_share( + st_spider_share *share, + uint dbton_id, + spider_db_mbase_util *spider_db_mbase_utility +) : spider_db_share( + share, + dbton_id +), + spider_db_mbase_utility(spider_db_mbase_utility), + 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), + db_table_str_hash_value(NULL), + 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_mbase_share::spider_mbase_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( + st_spider_share *share +) : spider_mbase_share( + share, + spider_db_mysql_utility.dbton_id, + &spider_db_mysql_utility +) { + DBUG_ENTER("spider_mysql_share::spider_mysql_share"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} +spider_mariadb_share::spider_mariadb_share( + st_spider_share *share +) : spider_mbase_share( + share, + spider_db_mariadb_utility.dbton_id, + &spider_db_mariadb_utility +) { + DBUG_ENTER("spider_mariadb_share::spider_mariadb_share"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mbase_share::~spider_mbase_share() +{ + DBUG_ENTER("spider_mbase_share::~spider_mbase_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; +} + +spider_mysql_share::~spider_mysql_share() +{ + DBUG_ENTER("spider_mysql_share::~spider_mysql_share"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mariadb_share::~spider_mariadb_share() +{ + DBUG_ENTER("spider_mariadb_share::~spider_mariadb_share"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_mbase_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_mbase_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, + &db_table_str_hash_value, + sizeof(my_hash_value_type) * spider_share->all_link_count, + 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_mbase_share::get_column_name_length( + uint field_index +) { + DBUG_ENTER("spider_mbase_share::get_column_name_length"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(column_name_str[field_index].length()); +} + +int spider_mbase_share::append_column_name( + spider_string *str, + uint field_index +) { + int error_num; + DBUG_ENTER("spider_mbase_share::append_column_name"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_mbase_utility->append_name(str, + column_name_str[field_index].ptr(), column_name_str[field_index].length()); + DBUG_RETURN(error_num); +} + +int spider_mbase_share::append_column_name_with_alias( + spider_string *str, + uint field_index, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_utility->append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mbase_utility->append_name(str, table_nm, table_nm_len); + DBUG_RETURN(0); +} + +int spider_mbase_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_mbase_share::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_db_mbase_utility->append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mbase_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_mbase_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_mbase_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_mbase_utility->append_name(str, db_nm, db_nm_len); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + spider_db_mbase_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_mbase_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; + DBUG_ENTER("spider_mbase_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; + } + db_table_str_hash_value[roop_count] = my_calc_hash( + &spider_open_connections, (uchar*) str->ptr(), str->length()); + } + 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_mbase_share::free_table_names_str() +{ + DBUG_ENTER("spider_mbase_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_mbase_share::create_column_name_str() +{ + spider_string *str; + int error_num; + Field **field; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_mbase_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, + (*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_mbase_share::free_column_name_str() +{ + DBUG_ENTER("spider_mbase_share::free_column_name_str"); + if (column_name_str) + { + delete [] column_name_str; + column_name_str = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_share::convert_key_hint_str() +{ + spider_string *tmp_key_hint; + int roop_count; + TABLE_SHARE *table_share = spider_share->table_share; + DBUG_ENTER("spider_mbase_share::convert_key_hint_str"); + if (spider_share->access_charset->cset != system_charset_info->cset) + { + /* need conversion */ + 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_mbase_share::append_show_table_status() +{ + int roop_count; + spider_string *str; + 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_mbase_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_mbase_share::append_show_records() +{ + int roop_count; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_share::free_show_records() +{ + DBUG_ENTER("spider_mbase_share::free_show_records"); + if (show_records) + { + delete [] show_records; + show_records = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_share::append_show_index() +{ + int roop_count; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_share::free_show_index() +{ + DBUG_ENTER("spider_mbase_share::free_show_index"); + if (show_index) + { + delete [] show_index; + show_index = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_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_mbase_share::append_table_select"); + + if (!*table_share->field) + DBUG_RETURN(0); + + 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_mbase_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_mbase_share::append_key_select"); + + if (!spider_user_defined_key_parts(key_info)) + DBUG_RETURN(0); + + for (key_part = key_info->key_part, part_num = 0; + part_num < spider_user_defined_key_parts(key_info); 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_mbase_share::need_change_db_table_name() +{ + DBUG_ENTER("spider_mbase_share::need_change_db_table_name"); + DBUG_RETURN(!same_db_table_name); +} + +int spider_mbase_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 strlen = str->length(); + DBUG_ENTER("spider_mbase_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_SELECT_COLUMNS_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_ORDER_LEN + + SPIDER_SQL_ORDINAL_POSITION_LEN + + /* SPIDER_SQL_VALUE_QUOTE_LEN */ 8 + + 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 + + SPIDER_SQL_SEMICOLON_LEN + + 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 */ 4 + )) { + DBUG_PRINT("info",("spider alloc sql_str error")); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + sql_str.q_append(SPIDER_SQL_SELECT_COLUMNS_STR, + SPIDER_SQL_SELECT_COLUMNS_LEN); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN); + sql_str.q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN); + sql_str.q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN); + sql_str.q_append(SPIDER_SQL_ORDINAL_POSITION_STR, + SPIDER_SQL_ORDINAL_POSITION_LEN); + 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); + sql_str.q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + sql_str.q_append( + SPIDER_SQL_SHOW_TABLE_STATUS_STR, SPIDER_SQL_SHOW_TABLE_STATUS_LEN); + sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql_str.q_append(db_names_str[roop_count].ptr(), + db_names_str[roop_count].length()); + sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN); + sql_str.q_append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + sql_str.q_append(table_names_str[roop_count].ptr(), + table_names_str[roop_count].length()); + sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + + 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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (!conn->disable_reconnect) + { + ha_spider tmp_spider; + SPIDER_WIDE_HANDLER wide_handler; + int need_mon = 0; + uint tmp_conn_link_idx = 0; + tmp_spider.wide_handler = &wide_handler; + wide_handler.trx = trx; + tmp_spider.share = spider_share; + tmp_spider.need_mons = &need_mon; + tmp_spider.conn_link_idx = &tmp_conn_link_idx; + if ((error_num = spider_db_ping(&tmp_spider, conn, 0))) + { + DBUG_PRINT("info",("spider spider_db_ping error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + } + } + 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")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, + ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), + db_names_str[roop_count].ptr(), + table_names_str[roop_count].ptr()); + error_num = ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM; + continue; + } + res->free_result(); + delete res; + if (conn->db_conn->next_result()) + { + DBUG_PRINT("info",("spider single result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 dual result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 table info */ + 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 table store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 table no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_table_for_discover_table_structure(str, + spider_share, spider_share->access_charset))) + { + DBUG_PRINT("info",("spider table fetch error")); + res->free_result(); + delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); +} + +bool spider_mbase_share::checksum_support() +{ + DBUG_ENTER("spider_mbase_share::checksum_support"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +spider_mbase_handler::spider_mbase_handler( + ha_spider *spider, + spider_mbase_share *db_share, + spider_db_mbase_util *spider_db_mbase_utility +) : spider_db_handler( + spider, + db_share +), + spider_db_mbase_utility(spider_db_mbase_utility), + 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), + union_table_name_pos_first(NULL), + union_table_name_pos_current(NULL), + mysql_share(db_share), + link_for_hash(NULL) +{ + DBUG_ENTER("spider_mbase_handler::spider_mbase_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( + ha_spider *spider, + spider_mbase_share *db_share +) : spider_mbase_handler( + spider, + db_share, + &spider_db_mysql_utility +) { + DBUG_ENTER("spider_mysql_handler::spider_mysql_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mariadb_handler::spider_mariadb_handler( + ha_spider *spider, + spider_mbase_share *db_share +) : spider_mbase_handler( + spider, + db_share, + &spider_db_mariadb_utility +) { + DBUG_ENTER("spider_mariadb_handler::spider_mariadb_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mbase_handler::~spider_mbase_handler() +{ + DBUG_ENTER("spider_mbase_handler::~spider_mbase_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + while (union_table_name_pos_first) + { + SPIDER_INT_HLD *tmp_pos = union_table_name_pos_first; + union_table_name_pos_first = tmp_pos->next; + spider_free(spider_current_trx, tmp_pos, MYF(0)); + } + 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; +} + +spider_mysql_handler::~spider_mysql_handler() +{ + DBUG_ENTER("spider_mysql_handler::~spider_mysql_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mariadb_handler::~spider_mariadb_handler() +{ + DBUG_ENTER("spider_mariadb_handler::~spider_mariadb_handler"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_mbase_handler::init() +{ + uint roop_count; + THD *thd = spider->wide_handler->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); + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_mbase_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); + sql_part2.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); + dup_update_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, + &minimum_select_bitmap, + table ? sizeof(uchar) * no_bytes_in_map(table->read_set) : 0, + 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]; + link_for_hash[roop_count].db_table_str_hash_value = + mysql_share->db_table_str_hash_value[roop_count]; + } + DBUG_RETURN(0); +} + + +int spider_mbase_handler::append_index_hint( + spider_string *str, + int link_idx, + ulong sql_type + ) +{ + List *index_hints = spider_get_index_hints(spider); + List_iterator iter(*index_hints); + Index_hint *hint; +// THD *thd = current_thd; + int error_num = 0; + DBUG_ENTER("spider_mbase_handler::append_index_hint"); + DBUG_PRINT("info",("spider this=%p", this)); + + while(index_hints && (hint = iter++)) + { + { + switch(hint->type) + { + case INDEX_HINT_IGNORE: + if (str->reserve(hint->key_name.length+ SPIDER_SQL_INDEX_IGNORE_LEN + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INDEX_IGNORE_STR,SPIDER_SQL_INDEX_IGNORE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR,SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(hint->key_name.str, hint->key_name.length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case INDEX_HINT_USE: + if (str->reserve(hint->key_name.length+ SPIDER_SQL_INDEX_USE_LEN + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INDEX_USE_STR,SPIDER_SQL_INDEX_USE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR,SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(hint->key_name.str, hint->key_name.length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,SPIDER_SQL_CLOSE_PAREN_LEN); + break; + case INDEX_HINT_FORCE: + if (str->reserve(hint->key_name.length+ SPIDER_SQL_INDEX_FORCE_LEN + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_INDEX_FORCE_STR,SPIDER_SQL_INDEX_FORCE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR,SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(hint->key_name.str, hint->key_name.length); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,SPIDER_SQL_CLOSE_PAREN_LEN); + break; + default: + // SPIDER_SQL_COMMA_STR + break; + } + } + } + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_table_name_with_adjusting( + spider_string *str, + int link_idx, + ulong sql_type +) { + int error_num = 0; + DBUG_ENTER("spider_mbase_handler::append_table_name_with_adjusting"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = mysql_share->append_table_name_with_adjusting(str, + spider->conn_link_idx[link_idx]); + DBUG_RETURN(error_num); +} + +int spider_mbase_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(spider_user_defined_key_parts(key_info)); + 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_mbase_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 spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + 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 = cs->coll_name.length; + 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->coll_name.str, 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_mbase_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(spider_user_defined_key_parts(key_info)); + 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_mbase_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 spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + 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_mbase_handler::append_tmp_table_and_sql_for_bka( + const key_range *start_key +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_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)) + ) + DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((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); + } + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } + + DBUG_RETURN(0); +} + +int spider_mbase_handler::reuse_tmp_table_and_sql_for_bka() +{ + DBUG_ENTER("spider_mbase_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_mbase_handler::create_tmp_bka_table_name( + char *tmp_table_name, + int *tmp_table_name_length, + int link_idx +) { + uint adjust_length, length; + DBUG_ENTER("spider_mbase_handler::create_tmp_bka_table_name"); + if (spider_param_bka_table_name_type(current_thd, + mysql_share->spider_share-> + bka_table_name_types[spider->conn_link_idx[link_idx]]) == 1) + { + 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(); + *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()); + } else { + adjust_length = + mysql_share->db_nm_max_length - + mysql_share->db_names_str[spider->conn_link_idx[link_idx]].length(); + *tmp_table_name_length = mysql_share->db_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", SPIDER_SQL_DOT_STR, SPIDER_SQL_TMP_BKA_STR, spider)); + *tmp_table_name_length += length; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_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->wide_handler->trx->thd; + char *bka_engine = spider_param_bka_engine(thd, share->bka_engine); + uint bka_engine_length = strlen(bka_engine), + cset_length = table_charset->cs_name.length, + coll_length = table_charset->coll_name.length; + DBUG_ENTER("spider_mbase_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->cs_name.str, cset_length); + str->q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str->q_append(table_charset->coll_name.str, coll_length); + str->q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_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_mbase_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_mbase_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_mbase_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_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_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_VALUES_STR, SPIDER_SQL_VALUES_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_union_table_and_sql_for_bka( + const key_range *start_key +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::append_union_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + char tgt_table_name[MAX_FIELD_WIDTH * 2]; + 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(233); + tgt_table_name_str.length(0); + 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] = ""; + table_names[1] = tgt_table_name_str.c_ptr_safe(); + table_name_lengths[0] = 0; + 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 = 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))) + DBUG_RETURN(error_num); + if (sql.reserve(SPIDER_SQL_FROM_LEN + (SPIDER_SQL_OPEN_PAREN_LEN * 2))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + sql.q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + tmp_sql_pos1 = sql.length(); + + if ( + (error_num = spider_db_mbase_utility->append_from_with_alias(&tmp_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, + &tmp_sql, &mysql_share->key_hint[spider->active_index])) + ) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + where_pos = tmp_sql.length(); + if ( + (error_num = append_key_join_columns_for_bka( + start_key, &tmp_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_TMP_SQL, FALSE)) + ) + DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias(&tmp_sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) + ) + DBUG_RETURN(error_num); + } + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } + + DBUG_RETURN(0); +} + +int spider_mbase_handler::reuse_union_table_and_sql_for_bka() +{ + DBUG_ENTER("spider_mbase_handler::reuse_union_table_and_sql_for_bka"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.length(tmp_sql_pos1); + DBUG_RETURN(0); +} + +int spider_mbase_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_mbase_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_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_LEN + + SPIDER_SQL_OPEN_PAREN_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + insert_sql->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + 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_mbase_utility->append_column_value(spider, insert_sql, + *field, NULL, false, + 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_mbase_handler::append_update( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_handler::append_delete( + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + int error_num; + spider_string *str = &update_sql; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_handler::append_insert_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_handler::append_insert_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_insert(&insert_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_insert( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_mbase_handler::append_insert"); + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_INSERT; + if ( + ( + spider->wide_handler->write_can_replace || + /* for direct_dup_insert without patch for partition */ + spider->wide_handler->sql_command == SQLCOM_REPLACE || + spider->wide_handler->sql_command == SQLCOM_REPLACE_SELECT + ) && + spider->direct_dup_insert + ) { + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_REPLACE; + 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->wide_handler->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->wide_handler->lock_type >= TL_WRITE && + !spider->wide_handler->write_can_replace && + /* for direct_dup_insert without patch for partition */ + spider->wide_handler->sql_command != SQLCOM_REPLACE && + spider->wide_handler->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->wide_handler->ignore_dup_key && + spider->direct_dup_insert && + !spider->wide_handler->write_can_replace && + (!spider->wide_handler->insert_with_update || !dup_update_sql.length()) && + /* for direct_dup_insert without patch for partition */ + spider->wide_handler->sql_command != SQLCOM_REPLACE && + spider->wide_handler->sql_command != SQLCOM_REPLACE_SELECT + ) { + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_IGNORE; + 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_mbase_handler::append_update_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_handler::append_update_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_update(&update_sql, 0); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_update( + spider_string *str, + int link_idx +) { + DBUG_ENTER("spider_mbase_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->wide_handler->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->wide_handler->ignore_dup_key && + !spider->wide_handler->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_mbase_handler::append_delete_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_handler::append_delete_part"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = append_delete(&update_sql); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_delete( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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->wide_handler->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->wide_handler->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->wide_handler->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); +} + +int spider_mbase_handler::append_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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 *tmp_map = dbug_tmp_use_all_columns(table, &table->read_set); +#endif + if (spider_db_mbase_utility->append_column_value( + spider, str, *fields, NULL, FALSE, 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_mbase_handler::append_direct_update_set_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_direct_update_set( + spider_string *str +) { + DBUG_ENTER("spider_mbase_handler::append_direct_update_set"); + if (spider->wide_handler->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, + dbton_id, FALSE, NULL)); + } + + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_dup_update_pushdown_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_update_columns_part( + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::check_update_columns_part() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_update_columns( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::append_update_columns"); + error_num = spider_db_append_update_columns(spider, str, + alias, alias_length, dbton_id, FALSE, NULL); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_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_select(str, sql_type); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_select( + spider_string *str, + ulong sql_type +) { + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_WIDE_HANDLER *wide_handler = spider->wide_handler; + DBUG_ENTER("spider_mbase_handler::append_select"); + { + 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->direct_distinct) + { + if (str->reserve(SPIDER_SQL_DISTINCT_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_DISTINCT_STR, SPIDER_SQL_DISTINCT_LEN); + } + if (wide_handler->external_lock_type != F_WRLCK && + wide_handler->lock_mode < 1) + { + /* no lock */ + LEX *lex = wide_handler->trx->thd->lex; + if ( + lex->sql_cache == LEX::SQL_CACHE && + (spider->share->query_cache_sync & 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 ( + lex->sql_cache == LEX::SQL_NO_CACHE && + (spider->share->query_cache_sync & 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); + } else 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 (wide_handler->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_mbase_handler::append_table_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_table_select( + spider_string *str +) { + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_table_select"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + if (select_lex) + { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + for (field = table->field; *field; field++) + { + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (!spider_db_check_select_colum_in_group(select_lex, *field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } else { + 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_mbase_handler::append_key_select_part( + ulong sql_type, + uint idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_key_select( + spider_string *str, + uint idx +) { + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_key_select"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + if (select_lex) + { + TABLE *table = spider->get_table(); + KEY *key_info = &table->key_info[idx]; + KEY_PART_INFO *key_part; + Field *field; + uint part_num; + int field_length; + for (key_part = key_info->key_part, part_num = 0; + part_num < spider_user_defined_key_parts(key_info); + key_part++, part_num++) + { + field = key_part->field; + field_length = mysql_share->column_name_str[field->field_index].length(); + if (!spider_db_check_select_colum_in_group(select_lex, field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } else { + 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_mbase_handler::append_minimum_select_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_minimum_select( + spider_string *str, + ulong sql_type +) { + TABLE *table = spider->get_table(); + Field **field; + int field_length; + bool appended = FALSE; + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_minimum_select"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + minimum_select_bitmap_create(); + for (field = table->field; *field; field++) + { + if (minimum_select_bit_is_set((*field)->field_index)) + { +/* + spider_set_bit(minimum_select_bitmap, (*field)->field_index); +*/ + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (select_lex && + !spider_db_check_select_colum_in_group(select_lex, *field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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_mbase_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; + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_table_select_with_alias"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + for (field = table->field; *field; field++) + { + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (select_lex && + !spider_db_check_select_colum_in_group(select_lex, *field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + alias_length + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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_mbase_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; + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_key_select_with_alias"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + for (key_part = key_info->key_part, part_num = 0; + part_num < spider_user_defined_key_parts(key_info); key_part++, part_num++) + { + field = key_part->field; + field_length = mysql_share->column_name_str[field->field_index].length(); + if (select_lex && + !spider_db_check_select_colum_in_group(select_lex, field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + alias_length + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, field->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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_mbase_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; + st_select_lex *select_lex = NULL; + bool sgb = (spider->result_list.direct_aggregate && + spider_param_strict_group_by(current_thd, (strict_group_by ? 1 : 0)) == 1); + DBUG_ENTER("spider_mbase_handler::append_minimum_select_with_alias"); + if (sgb) + { + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + if (!(*join->sum_funcs) && !select_lex->group_list.elements) + { + select_lex = NULL; + } + } + minimum_select_bitmap_create(); + for (field = table->field; *field; field++) + { + if (minimum_select_bit_is_set((*field)->field_index)) + { +/* + spider_set_bit(minimum_select_bitmap, (*field)->field_index); +*/ + field_length = + mysql_share->column_name_str[(*field)->field_index].length(); + if (select_lex && + !spider_db_check_select_colum_in_group(select_lex, *field)) + { + if (str->reserve(SPIDER_SQL_MIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN + + alias_length + field_length + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_MIN_STR, SPIDER_SQL_MIN_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(alias, alias_length); + mysql_share->append_column_name(str, (*field)->field_index); + str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); + } else { + 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_mbase_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_mbase_handler::append_select_columns_with_alias"); + if ( + result_list->direct_aggregate && + (error_num = append_sum_select(str, alias, alias_length)) + ) + DBUG_RETURN(error_num); + 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_mbase_handler::append_hint_after_table_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_hint_after_table(str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_hint_after_table( + spider_string *str +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::set_where_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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; + default: + break; + } + DBUG_VOID_RETURN; +} + +void spider_mbase_handler::set_where_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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; + default: + break; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_handler::check_item_type( + Item *item +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::check_item_type"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = spider_db_print_item_type(item, NULL, spider, NULL, NULL, 0, + dbton_id, FALSE, NULL); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_values_connector_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_values_connector( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_values_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_values_terminator( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_table_connector_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_union_table_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_union_table_connector(str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_union_table_connector( + spider_string *str +) { + DBUG_ENTER("spider_mbase_handler::append_union_table_connector"); + DBUG_PRINT("info",("spider this=%p", this)); + if (str->reserve((SPIDER_SQL_SPACE_LEN * 2) + SPIDER_SQL_UNION_ALL_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(SPIDER_SQL_UNION_ALL_STR, SPIDER_SQL_UNION_ALL_LEN); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_union_table_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_union_table_terminator_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_table_terminator(str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_union_table_terminator( + spider_string *str +) { + DBUG_ENTER("spider_mbase_handler::append_union_table_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + str->length(str->length() - + ((SPIDER_SQL_SPACE_LEN * 2) + SPIDER_SQL_UNION_ALL_LEN)); + 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); + table_name_pos = str->length() + SPIDER_SQL_SPACE_LEN + SPIDER_SQL_A_LEN + + SPIDER_SQL_COMMA_LEN; + if (str->reserve(tmp_sql.length() - SPIDER_SQL_FROM_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(tmp_sql.ptr() + SPIDER_SQL_FROM_LEN, + tmp_sql.length() - SPIDER_SQL_FROM_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_key_column_values_part( + const key_range *start_key, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_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(spider_user_defined_key_parts(key_info)); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + DBUG_ENTER("spider_mbase_handler::append_key_column_values"); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + 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_mbase_utility->append_column_value( + spider, str, field, ptr, FALSE, 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_mbase_handler::append_key_column_values_with_name_part( + const key_range *start_key, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_key_column_values_with_name_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_with_name(str, start_key); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_key_column_values_with_name( + 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 key_name_length, key_count; + uint store_length; + key_part_map full_key_part_map = + make_prev_keypart_map(spider_user_defined_key_parts(key_info)); + key_part_map start_key_part_map; + KEY_PART_INFO *key_part; + Field *field; + char tmp_buf[MAX_FIELD_WIDTH]; + DBUG_ENTER("spider_mbase_handler::append_key_column_values_with_name"); + start_key_part_map = start_key->keypart_map & full_key_part_map; + DBUG_PRINT("info", ("spider spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + 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, + key_count = 0; + start_key_part_map; + start_key_part_map >>= 1, + key_part++, + length += store_length, + key_count++ + ) { + 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_mbase_utility->append_column_value( + spider, str, field, ptr, FALSE, share->access_charset)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + + key_name_length = my_sprintf(tmp_buf, (tmp_buf, "c%u", key_count)); + if (str->reserve(SPIDER_SQL_SPACE_LEN + key_name_length + + SPIDER_SQL_COMMA_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + 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_mbase_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_mbase_handler::append_key_where_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + set_order = FALSE; + break; + case SPIDER_SQL_TYPE_TMP_SQL: + str = &tmp_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; + 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_mbase_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_mbase_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, + dbton_id); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_is_null_part( + ulong sql_type, + KEY_PART_INFO *key_part, + const key_range *key, + const uchar **ptr, + bool key_eq, + bool tgt_final +) { + int error_num; + spider_string *str, *str_part = NULL, *str_part2 = NULL; + DBUG_ENTER("spider_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_is_null(sql_type, str, str_part, str_part2, + key_part, key, ptr, key_eq, tgt_final); + DBUG_RETURN(error_num); +} + +int spider_mbase_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, + bool tgt_final +) { + DBUG_ENTER("spider_mbase_handler::append_is_null"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider key_eq=%s", key_eq ? "TRUE" : "FALSE")); + if (key_part->null_bit) + { + if (*(*ptr)++) + { + 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_mbase_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_mbase_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; + 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_mbase_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_mbase_handler::append_where_terminator"); + DBUG_PRINT("info", ("spider this=%p", this)); + + str->length(str->length() - SPIDER_SQL_AND_LEN); + if (!set_order) + result_list->key_order= key_count; + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_match_where_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_handler::append_update_where( + spider_string *str, + const TABLE *table, + my_ptrdiff_t ptr_diff +) { + uint field_name_length; + Field **field; + THD *thd = spider->wide_handler->trx->thd; + SPIDER_SHARE *share = spider->share; + bool no_pk = (table->s->primary_key == MAX_KEY); + DBUG_ENTER("spider_mbase_handler::append_update_where"); + DBUG_PRINT("info", ("spider table->s->primary_key=%s", + table->s->primary_key != MAX_KEY ? "TRUE" : "FALSE")); + uint str_len_bakup = str->length(); + 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); + + if ( + no_pk || + spider_param_use_cond_other_than_pk_for_update(thd) + ) { + for (field = table->field; *field; field++) + { + if ( + no_pk || + 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_mbase_utility->append_column_value( + spider, str, *field, NULL, FALSE, 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); + } + } + } else { + KEY *key_info = &table->key_info[table->s->primary_key]; + KEY_PART_INFO *key_part; + uint part_num; + for ( + key_part = key_info->key_part, part_num = 0; + part_num < spider_user_defined_key_parts(key_info); + key_part++, part_num++ + ) { + field = &key_part->field; + 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_mbase_utility->append_column_value( + spider, str, *field, NULL, FALSE, 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); + } + } + if (str->length() == str_len_bakup + SPIDER_SQL_WHERE_LEN) + { + /* no condition */ + str->length(str_len_bakup); + } else { + 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_mbase_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_mbase_handler::append_condition_part"); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + if (test_flg) + { + str = NULL; + } else { + str = &sql; + start_where = ((int) str->length() == where_pos); + } + break; + case SPIDER_SQL_TYPE_TMP_SQL: + if (test_flg) + { + str = NULL; + } else { + str = &tmp_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; + default: + DBUG_RETURN(0); + } + error_num = append_condition(str, alias, alias_length, start_where, + sql_type); + DBUG_RETURN(error_num); +} + +int spider_mbase_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->wide_handler->condition; + DBUG_ENTER("spider_mbase_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->wide_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, NULL, spider, str, alias, alias_length, + dbton_id, FALSE, NULL))) + { + 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_mbase_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_mbase_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_mbase_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_mbase_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 spider_user_defined_key_parts=%u", + spider_user_defined_key_parts(key_info))); + + for ( + key_part = key_info->key_part, + key_count = 0; + key_count < (int) spider_user_defined_key_parts(key_info); + 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_mbase_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_mbase_handler::append_match_select_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_match_select( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + DBUG_ENTER("spider_mbase_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); +} + +int spider_mbase_handler::append_sum_select_part( + ulong sql_type, + const char *alias, + uint alias_length +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_sum_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_sum_select(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_sum_select( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + st_select_lex *select_lex; + DBUG_ENTER("spider_mbase_handler::append_sum_select"); + DBUG_PRINT("info",("spider this=%p", this)); + select_lex = spider_get_select_lex(spider); + JOIN *join = select_lex->join; + Item_sum **item_sum_ptr; + for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr) + { + if ((error_num = spider_db_mbase_utility->open_item_sum_func(*item_sum_ptr, + spider, str, alias, alias_length, FALSE, NULL))) + { + 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); + } + DBUG_RETURN(0); +} + +void spider_mbase_handler::set_order_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +void spider_mbase_handler::set_order_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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; + default: + DBUG_ASSERT(0); + break; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_handler::append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_group_by_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; + default: + DBUG_RETURN(0); + } + error_num = append_group_by(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_group_by( + spider_string *str, + const char *alias, + uint alias_length +) { + int error_num; + st_select_lex *select_lex; + DBUG_ENTER("spider_mbase_handler::append_group_by"); + DBUG_PRINT("info",("spider this=%p", this)); + select_lex = spider_get_select_lex(spider); + ORDER *group = (ORDER *) select_lex->group_list.first; + if (group) + { + if (str->reserve(SPIDER_SQL_GROUP_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); + for (; group; group = group->next) + { + if ((error_num = spider_db_print_item_type((*group->item), NULL, spider, + str, alias, alias_length, dbton_id, FALSE, NULL))) + { + 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); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mbase_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_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_for_merge_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mbase_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_mbase_handler::append_key_order_for_merge_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->result_list.direct_aggregate) + { + int error_num; + if ((error_num = append_group_by(str, alias, alias_length))) + DBUG_RETURN(error_num); + } + 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) spider_user_defined_key_parts(key_info); + 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_mbase_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_mbase_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; + 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_mbase_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_mbase_handler::append_key_order_for_direct_order_limit_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->result_list.direct_aggregate) + { + if ((error_num = append_group_by(str, alias, alias_length))) + DBUG_RETURN(error_num); + } + 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), NULL, spider, str, alias, + alias_length, dbton_id, FALSE, NULL))) + { + DBUG_PRINT("info",("spider error=%d", error_num)); + DBUG_RETURN(error_num); + } + if (SPIDER_order_direction_is_asc(order)) + { + 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_mbase_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_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_key_order_with_alias(str, alias, alias_length); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_key_order_for_handler( + spider_string *str, + const char *alias, + uint alias_length +) { + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_handler::append_key_order_with_alias"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->result_list.direct_aggregate) + { + int error_num; + if ((error_num = append_group_by(str, alias, alias_length))) + DBUG_RETURN(error_num); + } + 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) spider_user_defined_key_parts(key_info) && + 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) spider_user_defined_key_parts(key_info) && + 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) spider_user_defined_key_parts(key_info) && + 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) spider_user_defined_key_parts(key_info) && + 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_mbase_handler::append_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::reappend_limit_part( + longlong offset, + longlong limit, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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; + default: + DBUG_RETURN(0); + } + error_num = append_limit(str, offset, limit); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_limit( + spider_string *str, + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_mbase_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.longlong10_to_str)( + 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.longlong10_to_str)( + buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + str->q_append(buf, length); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_select_lock_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_select_lock( + spider_string *str +) { + int lock_mode = spider_conn_lock_mode(spider); + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all_start_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all_start( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all_end_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_union_all_end( + spider_string *str +) { + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_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_mbase_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_mbase_handler::append_multi_range_cnt_with_name_part( + ulong sql_type, + uint multi_range_cnt +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_multi_range_cnt_with_name_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_with_name(str, multi_range_cnt); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_multi_range_cnt_with_name( + spider_string *str, + uint multi_range_cnt +) { + int range_cnt_length; + char range_cnt_str[SPIDER_SQL_INT_LEN]; + DBUG_ENTER("spider_mbase_handler::append_multi_range_cnt_with_name"); + DBUG_PRINT("info",("spider this=%p", this)); + range_cnt_length = my_sprintf(range_cnt_str, (range_cnt_str, "%u", + multi_range_cnt)); + if (str->reserve(range_cnt_length + SPIDER_SQL_SPACE_LEN + + SPIDER_SQL_ID_LEN + 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_SPACE_STR, SPIDER_SQL_SPACE_LEN); + str->q_append(SPIDER_SQL_ID_STR, SPIDER_SQL_ID_LEN); + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_insert_terminator_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_insert_terminator( + spider_string *str +) { + DBUG_ENTER("spider_mbase_handler::append_insert_terminator"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider dup_update_sql.length=%u", dup_update_sql.length())); + if ( + spider->result_list.insert_dup_update_pushdown && + dup_update_sql.length() + ) { + DBUG_PRINT("info",("spider add duplicate key update")); + direct_insert_kind = SPIDER_SQL_DIRECT_INSERT_KIND_DUP_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_mbase_handler::append_insert_values_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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 *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_mbase_utility->append_column_value( + spider, str, *field, NULL, FALSE, 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_mbase_handler::append_into_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_into( + spider_string *str +) { + const TABLE *table = spider->get_table(); + Field **field; + uint field_name_length = 0; + DBUG_ENTER("spider_mbase_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_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_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_VALUES_STR, SPIDER_SQL_VALUES_LEN); + insert_pos = str->length(); + DBUG_RETURN(0); +} + +void spider_mbase_handler::set_insert_to_pos( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_from_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_from_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + 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_mbase_handler::append_from( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_mbase_handler::append_from"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider link_idx=%d", link_idx)); + int error_num= 0; + 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); + if (spider_param_index_hint_pushdown(spider->wide_handler->trx->thd)) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_flush_tables_part( + ulong sql_type, + int link_idx, + bool lock +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_flush_tables( + spider_string *str, + int link_idx, + bool lock +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_optimize_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_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->wide_handler->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_analyze_table_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_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->wide_handler->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_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->wide_handler->trx->thd, + share->internal_optimize_local) * SPIDER_SQL_SQL_LOCAL_LEN; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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_mbase_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_mbase_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_mbase_handler::append_enable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_enable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_disable_keys_part( + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_disable_keys( + spider_string *str, + int link_idx +) { + int conn_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_delete_all_rows_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_delete_all_rows( + spider_string *str, + ulong sql_type +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::append_delete_all_rows"); + DBUG_PRINT("info",("spider this=%p", this)); + if (spider->wide_handler->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_mbase_handler::append_truncate( + spider_string *str, + ulong sql_type, + int link_idx +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::append_explain_select_part( + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_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_mbase_handler::append_explain_select( + spider_string *str, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mbase_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); +} + +/******************************************************************** + * Determine whether the current query's projection list + * consists solely of the specified column. + * + * Params IN - field_index: + * Field index of the column of interest within + * its table. + * + * Returns TRUE - if the query's projection list consists + * solely of the specified column. + * FALSE - otherwise. + ********************************************************************/ +bool spider_mbase_handler::is_sole_projection_field( + uint16 field_index +) { + // Determine whether the projection list consists solely of the field of interest + bool is_field_in_projection_list = FALSE; + TABLE* table = spider->get_table(); + uint16 projection_field_count = 0; + uint16 projection_field_index; + Field** field; + DBUG_ENTER( "spider_mbase_handler::is_sole_projection_field" ); + + for ( field = table->field; *field ; field++ ) + { + projection_field_index = ( *field )->field_index; + + if ( !( minimum_select_bit_is_set( projection_field_index ) ) ) + { + // Current field is not in the projection list + continue; + } + + projection_field_count++; + + if ( !is_field_in_projection_list ) + { + if ( field_index == projection_field_index ) + { + // Field of interest is in the projection list + is_field_in_projection_list = TRUE; + } + } + + if ( is_field_in_projection_list && ( projection_field_count != 1 ) ) + { + // Field of interest is not the sole column in the projection list + DBUG_RETURN( FALSE ); + } + } + + if ( is_field_in_projection_list && ( projection_field_count == 1 ) ) + { + // Field of interest is the only column in the projection list + DBUG_RETURN( TRUE ); + } + + DBUG_RETURN( FALSE ); +} + +bool spider_mbase_handler::is_bulk_insert_exec_period( + bool bulk_end +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::sql_is_filled_up( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_handler::sql_is_filled_up"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(filled_up); +} + +bool spider_mbase_handler::sql_is_empty( + ulong sql_type +) { + bool is_empty; + DBUG_ENTER("spider_mbase_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; + default: + is_empty = TRUE; + break; + } + DBUG_RETURN(is_empty); +} + +bool spider_mbase_handler::support_multi_split_read() +{ + DBUG_ENTER("spider_mbase_handler::support_multi_split_read"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +bool spider_mbase_handler::support_bulk_update() +{ + DBUG_ENTER("spider_mbase_handler::support_bulk_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(TRUE); +} + +int spider_mbase_handler::bulk_tmp_table_insert() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::bulk_tmp_table_insert( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::bulk_tmp_table_end_bulk_insert() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::bulk_tmp_table_rnd_init() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::bulk_tmp_table_rnd_next() +{ + int error_num; + DBUG_ENTER("spider_mbase_handler::bulk_tmp_table_rnd_next"); + DBUG_PRINT("info",("spider this=%p", this)); + error_num = upd_tmp_tbl->file->ha_rnd_next(upd_tmp_tbl->record[0]); + if (!error_num) + { + error_num = restore_sql_from_bulk_tmp_table(&insert_sql, upd_tmp_tbl); + } + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::bulk_tmp_table_rnd_end() +{ + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::need_copy_for_update( + int link_idx +) { + int all_link_idx = spider->conn_link_idx[link_idx]; + DBUG_ENTER("spider_mbase_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_mbase_handler::bulk_tmp_table_created() +{ + DBUG_ENTER("spider_mbase_handler::bulk_tmp_table_created"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(upd_tmp_tbl); +} + +int spider_mbase_handler::mk_bulk_tmp_table_and_bulk_start() +{ + THD *thd = spider->wide_handler->trx->thd; + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_mbase_handler::mk_bulk_tmp_table_and_bulk_start"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!upd_tmp_tbl) + { +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor + LEX_CSTRING field_name = {STRING_WITH_LEN("a")}; + if (!(upd_tmp_tbl = spider_mk_sys_tmp_table( + thd, table, &upd_tmp_tbl_prm, &field_name, update_sql.charset()))) +#else + if (!(upd_tmp_tbl = spider_mk_sys_tmp_table( + thd, table, &upd_tmp_tbl_prm, "a", update_sql.charset()))) +#endif + { + 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_mbase_handler::rm_bulk_tmp_table() +{ + DBUG_ENTER("spider_mbase_handler::rm_bulk_tmp_table"); + DBUG_PRINT("info",("spider this=%p", this)); + if (upd_tmp_tbl) + { + spider_rm_sys_tmp_table(spider->wide_handler->trx->thd, upd_tmp_tbl, + &upd_tmp_tbl_prm); + upd_tmp_tbl = NULL; + } + DBUG_VOID_RETURN; +} + +int spider_mbase_handler::store_sql_to_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_handler::restore_sql_from_bulk_tmp_table( + spider_string *str, + TABLE *tmp_table +) { + DBUG_ENTER("spider_mbase_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_mbase_handler::insert_lock_tables_list( + SPIDER_CONN *conn, + int link_idx +) { + spider_db_mbase *db_conn = (spider_db_mbase *) conn->db_conn; + SPIDER_LINK_FOR_HASH *tmp_link_for_hash2 = &link_for_hash[link_idx]; + DBUG_ENTER("spider_mbase_handler::insert_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + uint old_elements = + db_conn->lock_table_hash.array.max_element; + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) + { + 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_mbase_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_mbase *db_conn = (spider_db_mbase *) conn->db_conn; + DBUG_ENTER("spider_mbase_handler::append_lock_tables_list"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider db_conn=%p", db_conn)); + tmp_link_for_hash2 = &link_for_hash[link_idx]; + tmp_link_for_hash2->db_table_str = + &mysql_share->db_table_str[conn_link_idx]; + DBUG_PRINT("info",("spider db_table_str=%s", + tmp_link_for_hash2->db_table_str->c_ptr_safe())); + 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()))) + { + if ((error_num = insert_lock_tables_list(conn, link_idx))) + DBUG_RETURN(error_num); + *appended = 1; + } else { + if (tmp_link_for_hash->spider->wide_handler->lock_type < + spider->wide_handler->lock_type) + { + my_hash_delete(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash); + uint old_elements = + db_conn->lock_table_hash.array.max_element; + if (my_hash_insert(&db_conn->lock_table_hash, + (uchar*) tmp_link_for_hash2)) + { + 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_mbase_handler::realloc_sql( + ulong *realloced +) { + THD *thd = spider->wide_handler->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_mbase_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_mbase_handler::reset_sql( + ulong sql_type +) { + DBUG_ENTER("spider_mbase_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); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::set_sql_for_exec( + ulong sql_type, + int link_idx, + SPIDER_LINK_IDX_CHAIN *link_idx_chain +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::set_sql_for_exec"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL) + { + if ((error_num = spider_db_mbase_utility->reappend_tables( + spider->fields, link_idx_chain, &sql))) + DBUG_RETURN(error_num); + exec_sql = &sql; + } + DBUG_RETURN(0); +} + +int spider_mbase_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_mbase_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 && spider->bka_mode != 2) + { + 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.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 if (result_list->use_union) + { + if ((error_num = reset_union_table_name(exec_sql, link_idx, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } else { + tmp_pos = exec_sql->length(); + exec_sql->length(table_name_pos); + if (result_list->tmp_table_join && spider->bka_mode != 2) + { + if ((error_num = spider_db_mbase_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); + exec_sql->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + } 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 && spider->bka_mode != 2) + { + 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); + } + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::set_sql_for_exec( + spider_db_copy_table *tgt_ct, + ulong sql_type +) { + spider_mbase_copy_table *mysql_ct = (spider_mbase_copy_table *) tgt_ct; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_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; + 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_mbase_handler::reset() +{ + DBUG_ENTER("spider_mbase_handler::reset"); + DBUG_PRINT("info",("spider this=%p", this)); + update_sql.length(0); + DBUG_RETURN(0); +} + +int spider_mbase_handler::sts_mode_exchange( + int sts_mode +) { + DBUG_ENTER("spider_mbase_handler::sts_mode_exchange"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + DBUG_RETURN(sts_mode); +} + +int spider_mbase_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]); + ulonglong auto_increment_value = 0; + DBUG_ENTER("spider_mbase_handler::show_table_status"); + DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); + + if (sts_mode == 1) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + conn->disable_connect_retry = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (spider_param_dry_access()) + { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + else if ((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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->stat + ); + auto_increment_value = share->stat.auto_increment_value; + 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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + conn->disable_connect_retry = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->trx->thd->query_id; + request_key.handler = spider; + request_key.request_id = 1; + request_key.next = NULL; + if (spider_param_dry_access()) + { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) + { + conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->stat + ); + auto_increment_value = share->stat.auto_increment_value; + 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); + } + } + if ((error_num = ((spider_db_mbase *) conn->db_conn)->fetch_and_print_warnings(NULL))) + { + DBUG_RETURN(error_num); + } + if (share->static_records_for_status != -1) + { + share->stat.records = (ha_rows) share->static_records_for_status; + } + if (share->static_mean_rec_length != -1) + { + share->stat.mean_rec_length = (ulong) share->static_mean_rec_length; + } + if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value) + { + share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value; + DBUG_PRINT("info",("spider auto_increment_value=%llu", + share->lgtm_tblhnd_share->auto_increment_value)); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::crd_mode_exchange( + int crd_mode +) { + DBUG_ENTER("spider_mbase_handler::crd_mode_exchange"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + DBUG_RETURN(crd_mode); +} + +int spider_mbase_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_mbase_handler::show_index"); + DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); + if (crd_mode == 1) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 */ + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 uninitialized 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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 */ + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 uninitialized 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_mbase_handler::simple_action( + uint simple_action, + 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]; + spider_string *str = NULL; + DBUG_ENTER("spider_mbase_handler::simple_action"); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + str = &mysql_share->show_records[pos]; + break; + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + str = &spider->result_list.sqls[link_idx]; + str->length(0); + if (str->reserve( + SPIDER_SQL_CHECKSUM_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->action_flags & T_QUICK) ? SPIDER_SQL_SQL_QUICK_LEN : 0) + + ((spider->action_flags & T_EXTEND) ? SPIDER_SQL_SQL_EXTENDED_LEN : 0) + )) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + str->q_append(SPIDER_SQL_CHECKSUM_TABLE_STR, + SPIDER_SQL_CHECKSUM_TABLE_LEN); + mysql_share->append_table_name(str, pos); + if (spider->action_flags & T_QUICK) + { + str->q_append(SPIDER_SQL_SQL_QUICK_STR, SPIDER_SQL_SQL_QUICK_LEN); + } + if (spider->action_flags & T_EXTEND) + { + str->q_append(SPIDER_SQL_SQL_EXTENDED_STR, + SPIDER_SQL_SQL_EXTENDED_LEN); + } + break; + default: + DBUG_ASSERT(0); + DBUG_RETURN(0); + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->trx->thd, + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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 { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); + } else { + DBUG_PRINT("info", ("spider error_num=%d 7", + ER_QUERY_ON_FOREIGN_DATA_SOURCE)); + DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + switch (simple_action) + { + case SPIDER_SIMPLE_RECORDS: + DBUG_PRINT("info",("spider simple records")); + error_num = res->fetch_table_records(1, spider->table_rows); + break; + case SPIDER_SIMPLE_CHECKSUM_TABLE: + DBUG_PRINT("info",("spider simple checksum_table")); + error_num = res->fetch_table_checksum(spider); + break; + default: + DBUG_ASSERT(0); + break; + } + res->free_result(); + delete res; + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d 7", error_num)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::show_records( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::show_records"); + error_num = simple_action(SPIDER_SIMPLE_RECORDS, link_idx); + if (error_num) + { + DBUG_PRINT("info", ("spider error_num=%d", error_num)); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::checksum_table( + int link_idx +) { + DBUG_ENTER("spider_mbase_handler::checksum_table"); + DBUG_RETURN(simple_action(SPIDER_SIMPLE_CHECKSUM_TABLE, link_idx)); + DBUG_RETURN(0); +} + +int spider_mbase_handler::show_last_insert_id( + int link_idx, + ulonglong &last_insert_id +) { + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_mbase_handler::show_last_insert_id"); + last_insert_id = conn->db_conn->last_insert_id(); + DBUG_RETURN(0); +} + +ha_rows spider_mbase_handler::explain_select( + const key_range *start_key, + const 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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->spider_thread_id; + request_key.query_id = spider->wide_handler->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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_handler::lock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + spider_string *str = &sql; + DBUG_ENTER("spider_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + spider->share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->locked_connections++; + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::unlock_tables( + int link_idx +) { + int error_num; + SPIDER_CONN *conn = spider->conns[link_idx]; + DBUG_ENTER("spider_mbase_handler::unlock_tables"); + if (conn->table_locked) + { + spider_string *str = &sql; + conn->table_locked = FALSE; + spider->wide_handler->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->wide_handler->trx->thd, + spider->share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->trx->thd, + share); + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_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_mbase_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->wide_handler->trx->thd, + share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + str->ptr(), + str->length(), + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_handler::flush_logs( + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_SHARE *share = spider->share; + DBUG_ENTER("spider_mbase_handler::flush_logs"); + DBUG_PRINT("info",("spider this=%p", this)); + spider_conn_set_timeout_from_share(conn, link_idx, + spider->wide_handler->trx->thd, + share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + 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_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if (spider_db_query( + conn, + SPIDER_SQL_FLUSH_LOGS_STR, + SPIDER_SQL_FLUSH_LOGS_LEN, + -1, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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_mbase_handler::sync_from_clone_source( + spider_db_handler *dbton_hdl +) { + DBUG_ENTER("spider_mbase_handler::sync_from_clone_source"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(0); +} + +void spider_mbase_handler::minimum_select_bitmap_create() +{ + TABLE *table = spider->get_table(); + Field **field_p; + DBUG_ENTER("spider_mbase_handler::minimum_select_bitmap_create"); + DBUG_PRINT("info",("spider this=%p", this)); + memset(minimum_select_bitmap, 0, no_bytes_in_map(table->read_set)); + if ( + spider->use_index_merge || + spider->is_clone + ) { + /* need preparing for cmp_ref */ + TABLE_SHARE *table_share = table->s; + if ( + table_share->primary_key == MAX_KEY + ) { + /* need all columns */ + memset(minimum_select_bitmap, 0xFF, no_bytes_in_map(table->read_set)); + DBUG_VOID_RETURN; + } else { + /* need primary key columns */ + uint roop_count; + KEY *key_info; + KEY_PART_INFO *key_part; + Field *field; + key_info = &table_share->key_info[table_share->primary_key]; + key_part = key_info->key_part; + for (roop_count = 0; + roop_count < spider_user_defined_key_parts(key_info); + roop_count++) + { + field = key_part[roop_count].field; + spider_set_bit(minimum_select_bitmap, field->field_index); + } + } + } + DBUG_PRINT("info",("spider searched_bitmap=%p", + spider->wide_handler->searched_bitmap)); + for (field_p = table->field; *field_p; field_p++) + { + uint field_index = (*field_p)->field_index; + DBUG_PRINT("info",("spider field_index=%u", field_index)); + DBUG_PRINT("info",("spider ft_discard_bitmap=%s", + spider_bit_is_set(spider->wide_handler->ft_discard_bitmap, field_index) ? + "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider searched_bitmap=%s", + spider_bit_is_set(spider->wide_handler->searched_bitmap, field_index) ? + "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider read_set=%s", + bitmap_is_set(table->read_set, field_index) ? + "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider write_set=%s", + bitmap_is_set(table->write_set, field_index) ? + "TRUE" : "FALSE")); + if ( + spider_bit_is_set(spider->wide_handler->ft_discard_bitmap, field_index) && + ( + spider_bit_is_set(spider->wide_handler->searched_bitmap, field_index) || + bitmap_is_set(table->read_set, field_index) || + bitmap_is_set(table->write_set, field_index) + ) + ) { + spider_set_bit(minimum_select_bitmap, field_index); + } + } + DBUG_VOID_RETURN; +} + +bool spider_mbase_handler::minimum_select_bit_is_set( + uint field_index +) { + DBUG_ENTER("spider_mbase_handler::minimum_select_bit_is_set"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider field_index=%u", field_index)); + DBUG_PRINT("info",("spider minimum_select_bitmap=%s", + spider_bit_is_set(minimum_select_bitmap, field_index) ? + "TRUE" : "FALSE")); + DBUG_RETURN(spider_bit_is_set(minimum_select_bitmap, field_index)); +} + +void spider_mbase_handler::copy_minimum_select_bitmap( + uchar *bitmap +) { + int roop_count; + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_mbase_handler::copy_minimum_select_bitmap"); + for (roop_count = 0; + roop_count < (int) ((table->s->fields + 7) / 8); + roop_count++) + { + bitmap[roop_count] = + minimum_select_bitmap[roop_count]; + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + DBUG_PRINT("info",("spider bitmap=%d", + bitmap[roop_count])); + } + DBUG_VOID_RETURN; +} + +int spider_mbase_handler::init_union_table_name_pos() +{ + DBUG_ENTER("spider_mbase_handler::init_union_table_name_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!union_table_name_pos_first) + { + if (!spider_bulk_malloc(spider_current_trx, 236, MYF(MY_WME), + &union_table_name_pos_first, (uint) (sizeof(SPIDER_INT_HLD)), + NullS) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + union_table_name_pos_first->next = NULL; + } + union_table_name_pos_current = union_table_name_pos_first; + union_table_name_pos_current->tgt_num = 0; + DBUG_RETURN(0); +} + +int spider_mbase_handler::set_union_table_name_pos() +{ + DBUG_ENTER("spider_mbase_handler::set_union_table_name_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + if (union_table_name_pos_current->tgt_num >= SPIDER_INT_HLD_TGT_SIZE) + { + if (!union_table_name_pos_current->next) + { + if (!spider_bulk_malloc(spider_current_trx, 237, MYF(MY_WME), + &union_table_name_pos_current->next, (uint) (sizeof(SPIDER_INT_HLD)), + NullS) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + union_table_name_pos_current->next->next = NULL; + } + union_table_name_pos_current = union_table_name_pos_current->next; + union_table_name_pos_current->tgt_num = 0; + } + union_table_name_pos_current->tgt[union_table_name_pos_current->tgt_num] = + table_name_pos; + ++union_table_name_pos_current->tgt_num; + DBUG_RETURN(0); +} + +int spider_mbase_handler::reset_union_table_name( + spider_string *str, + int link_idx, + ulong sql_type +) { + DBUG_ENTER("spider_mbase_handler::reset_union_table_name"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!union_table_name_pos_current) + DBUG_RETURN(0); + + SPIDER_INT_HLD *tmp_pos = union_table_name_pos_first; + uint cur_num, pos_backup = str->length(); + while(TRUE) + { + for (cur_num = 0; cur_num < tmp_pos->tgt_num; ++cur_num) + { + str->length(tmp_pos->tgt[cur_num]); + append_table_name_with_adjusting(str, link_idx, sql_type); + } + if (tmp_pos == union_table_name_pos_current) + break; + tmp_pos = tmp_pos->next; + } + str->length(pos_backup); + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_from_and_tables_part( + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + SPIDER_TABLE_HOLDER *table_holder; + TABLE_LIST *table_list; + DBUG_ENTER("spider_mbase_handler::append_from_and_tables_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + str = &sql; + break; + default: + DBUG_RETURN(0); + } + fields->set_pos_to_first_table_holder(); + table_holder = fields->get_next_table_holder(); + table_list = table_holder->table->pos_in_table_list; + error_num = spider_db_mbase_utility->append_from_and_tables( + table_holder->spider, fields, str, + table_list, fields->get_table_count()); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::reappend_tables_part( + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::reappend_tables_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 = spider_db_mbase_utility->reappend_tables(fields, + link_idx_chain, str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_where_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_where_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 = spider_db_mbase_utility->append_where(str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_having_part( + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_having_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 = spider_db_mbase_utility->append_having(str); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_item_type_part( + Item *item, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_item_type_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 = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_list_item_select_part( + List *select, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_list_item_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_list_item_select(select, str, alias, alias_length, + use_fields, fields); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_list_item_select( + List *select, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + int error_num; + uint32 length, begin; + List_iterator_fast it(*select); + Item *item; + Field *field; + const char *item_name; + DBUG_ENTER("spider_mbase_handler::append_list_item_select"); + DBUG_PRINT("info",("spider this=%p", this)); + begin = str->length(); + while ((item = it++)) + { + if (item->const_item()) + { + DBUG_PRINT("info",("spider const item")); + continue; + } + if ((error_num = spider_db_print_item_type(item, NULL, spider, str, + alias, alias_length, dbton_id, use_fields, fields))) + { + DBUG_RETURN(error_num); + } + field = *(fields->get_next_field_ptr()); + if (field) + { + item_name = SPIDER_field_name_str(field); + length = SPIDER_field_name_length(field); + } else { + item_name = SPIDER_item_name_str(item); + length = SPIDER_item_name_length(item); + } + if (str->reserve( + SPIDER_SQL_COMMA_LEN + /* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + + SPIDER_SQL_SPACE_LEN + length + )) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN); + if ((error_num = spider_db_mbase_utility->append_escaped_name(str, + item_name, length))) + { + DBUG_RETURN(error_num); + } + str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN); + } + if (begin == str->length()) + { + /* no columns */ + 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); + } else { + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_group_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_group_by_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_group_by(order, str, alias, alias_length, + use_fields, fields); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_group_by( + ORDER *order, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::append_group_by"); + DBUG_PRINT("info",("spider this=%p", this)); + if (order) + { + if (str->reserve(SPIDER_SQL_GROUP_LEN)) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + str->q_append(SPIDER_SQL_GROUP_STR, SPIDER_SQL_GROUP_LEN); + for (; order; order = order->next) + { + if ((error_num = spider_db_print_item_type((*order->item), NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + { + 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); + } + str->length(str->length() - SPIDER_SQL_COMMA_LEN); + } + DBUG_RETURN(0); +} + +int spider_mbase_handler::append_order_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mbase_handler::append_order_by_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_order_by(order, str, alias, alias_length, + use_fields, fields); + DBUG_RETURN(error_num); +} + +int spider_mbase_handler::append_order_by( + ORDER *order, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields +) { + int error_num; + DBUG_ENTER("spider_mbase_handler::append_order_by"); + DBUG_PRINT("info",("spider this=%p", this)); + if (order) + { + 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 = order->next) + { + if ((error_num = spider_db_print_item_type((*order->item), NULL, spider, + str, alias, alias_length, dbton_id, use_fields, fields))) + { + DBUG_RETURN(error_num); + } + if (SPIDER_order_direction_is_asc(order)) + { + 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_COMMA_LEN + SPIDER_SQL_DESC_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); + } + DBUG_RETURN(0); +} + +bool spider_mbase_handler::check_direct_update( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + DBUG_ENTER("spider_mbase_handler::check_direct_update"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +bool spider_mbase_handler::check_direct_delete( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit +) { + DBUG_ENTER("spider_mbase_handler::check_direct_delete"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(FALSE); +} + +spider_mbase_copy_table::spider_mbase_copy_table( + spider_mbase_share *db_share +) : spider_db_copy_table( + db_share +), + mysql_share(db_share) +{ + DBUG_ENTER("spider_mbase_copy_table::spider_mbase_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mysql_copy_table::spider_mysql_copy_table( + spider_mbase_share *db_share +) : spider_mbase_copy_table( + db_share +) { + DBUG_ENTER("spider_mysql_copy_table::spider_mysql_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mariadb_copy_table::spider_mariadb_copy_table( + spider_mbase_share *db_share +) : spider_mbase_copy_table( + db_share +) { + DBUG_ENTER("spider_mariadb_copy_table::spider_mariadb_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_mbase_copy_table::~spider_mbase_copy_table() +{ + DBUG_ENTER("spider_mbase_copy_table::~spider_mbase_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; +} + +spider_mariadb_copy_table::~spider_mariadb_copy_table() +{ + DBUG_ENTER("spider_mariadb_copy_table::~spider_mariadb_copy_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +int spider_mbase_copy_table::init() +{ + DBUG_ENTER("spider_mbase_copy_table::init"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.init_calc_mem(78); + DBUG_RETURN(0); +} + +void spider_mbase_copy_table::set_sql_charset( + CHARSET_INFO *cs +) { + DBUG_ENTER("spider_mbase_copy_table::set_sql_charset"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.set_charset(cs); + DBUG_VOID_RETURN; +} + +int spider_mbase_copy_table::append_select_str() +{ + DBUG_ENTER("spider_mbase_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_mbase_copy_table::append_insert_str( + int insert_flg +) { + DBUG_ENTER("spider_mbase_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_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_mbase_copy_table::append_table_columns( + TABLE_SHARE *table_share +) { + int error_num; + Field **field; + DBUG_ENTER("spider_mbase_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, + (*field)->field_name, 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_mbase_copy_table::append_from_str() +{ + DBUG_ENTER("spider_mbase_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_mbase_copy_table::append_table_name( + int link_idx +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_copy_table::set_sql_pos() +{ + DBUG_ENTER("spider_mbase_copy_table::set_sql_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + pos = sql.length(); + DBUG_VOID_RETURN; +} + +void spider_mbase_copy_table::set_sql_to_pos() +{ + DBUG_ENTER("spider_mbase_copy_table::set_sql_to_pos"); + DBUG_PRINT("info",("spider this=%p", this)); + sql.length(pos); + DBUG_VOID_RETURN; +} + +int spider_mbase_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_mbase_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 = spider_user_defined_key_parts(key_info) - 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_mbase_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_mbase_copy_table::append_key_order_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if ((int) spider_user_defined_key_parts(key_info) > 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) spider_user_defined_key_parts(key_info); + 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, + field->field_name, 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) spider_user_defined_key_parts(key_info); + 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, + field->field_name, 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_mbase_copy_table::append_limit( + longlong offset, + longlong limit +) { + char buf[SPIDER_LONGLONG_LEN + 1]; + uint32 length; + DBUG_ENTER("spider_mbase_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.longlong10_to_str)( + 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.longlong10_to_str)( + buf, SPIDER_LONGLONG_LEN + 1, -10, limit); + sql.q_append(buf, length); + } + DBUG_RETURN(0); +} + +int spider_mbase_copy_table::append_into_str() +{ + DBUG_ENTER("spider_mbase_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_mbase_copy_table::append_open_paren_str() +{ + DBUG_ENTER("spider_mbase_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_mbase_copy_table::append_values_str() +{ + DBUG_ENTER("spider_mbase_copy_table::append_values_str"); + DBUG_PRINT("info",("spider this=%p", this)); + if (sql.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_VALUES_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_VALUES_STR, SPIDER_SQL_VALUES_LEN); + sql.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + DBUG_RETURN(0); +} + +int spider_mbase_copy_table::append_select_lock_str( + int lock_mode +) { + DBUG_ENTER("spider_mbase_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_mbase_copy_table::exec_query( + SPIDER_CONN *conn, + int quick_mode, + int *need_mon +) { + int error_num; + DBUG_ENTER("spider_mbase_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_mbase_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_mbase_copy_table *) source_ct)->sql; + DBUG_ENTER("spider_mbase_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, + field->field_name, 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_mbase_copy_table::copy_row( + Field *field, + SPIDER_DB_ROW *row +) { + int error_num; + DBUG_ENTER("spider_mbase_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, + 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_mbase_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_mbase_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_mbase_copy_table::copy_rows( + TABLE *table, + SPIDER_DB_ROW *row +) { + int error_num; + Field **field; + DBUG_ENTER("spider_mbase_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_mbase_copy_table::append_insert_terminator() +{ + DBUG_ENTER("spider_mbase_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_mbase_copy_table::copy_insert_values( + spider_db_copy_table *source_ct +) { + spider_mbase_copy_table *tmp_ct = (spider_mbase_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_mbase_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 00000000..ec72a97f --- /dev/null +++ b/storage/spider/spd_db_mysql.h @@ -0,0 +1,1683 @@ +/* Copyright (C) 2012-2018 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +class spider_db_mbase_util: public spider_db_util +{ +public: + spider_db_mbase_util(); + virtual ~spider_db_mbase_util(); + int append_name( + spider_string *str, + const char *name, + uint name_length + ) override; + int append_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ) override; + int append_escaped_name( + spider_string *str, + const char *name, + uint name_length + ) override; + int append_escaped_name_with_charset( + spider_string *str, + const char *name, + uint name_length, + CHARSET_INFO *name_charset + ) override; + bool is_name_quote( + const char head_code + ) override; + int append_escaped_name_quote( + spider_string *str + ) override; + int append_column_value(ha_spider *spider, spider_string *str, Field *field, + const uchar *new_ptr, bool is_like, + CHARSET_INFO *access_charset) override; + 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 + ) override; + int append_autocommit( + spider_string *str, + bool autocommit + ) override; + int append_sql_log_off( + spider_string *str, + bool sql_log_off + ) override; + int append_wait_timeout( + spider_string *str, + int wait_timeout + ) override; + virtual int append_sql_mode_internal( + spider_string *str, + sql_mode_t sql_mode + ); + int append_sql_mode( + spider_string *str, + sql_mode_t sql_mode + ) override; + int append_time_zone( + spider_string *str, + Time_zone *time_zone + ) override; + int append_loop_check( + spider_string *str, + SPIDER_CONN *conn + ) override; + int append_start_transaction( + spider_string *str + ) override; + int append_xa_start( + spider_string *str, + XID *xid + ) override; + int append_lock_table_head( + spider_string *str + ) override; + 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 + ) override; + int append_lock_table_tail( + spider_string *str + ) override; + int append_unlock_table( + spider_string *str + ) override; + int open_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ) override; +protected: + int check_item_func( + Item_func *item_func, + ha_spider *spider, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ); + int print_item_func( + Item_func *item_func, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ); +public: + int open_item_sum_func( + Item_sum *item_sum, + ha_spider *spider, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ) override; + int append_escaped_util( + spider_string *to, + String *from + ) override; + int append_table( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr, + bool top_down, + bool first + ); + int append_tables_top_down( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr + ); + int append_tables_top_down_check( + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos + ); + int append_embedding_tables( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + TABLE_LIST **used_table_list, + uint *current_pos, + TABLE_LIST **cond_table_list_ptr + ); + int append_from_and_tables( + ha_spider *spider, + spider_fields *fields, + spider_string *str, + TABLE_LIST *table_list, + uint table_count + ) override; + int reappend_tables( + spider_fields *fields, + SPIDER_LINK_IDX_CHAIN *link_idx_chain, + spider_string *str + ) override; + int append_where( + spider_string *str + ) override; + int append_having( + spider_string *str + ) override; + bool tables_on_different_db_are_joinable() override; + bool socket_has_default_value() override; + bool database_has_default_value() override; + bool default_file_has_default_value() override; + bool host_has_default_value() override; + bool port_has_default_value() override; + bool append_charset_name_before_string() override; +}; + +class spider_db_mysql_util: public spider_db_mbase_util +{ +public: + spider_db_mysql_util(); + ~spider_db_mysql_util(); + int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + bool is_like, + CHARSET_INFO *access_charset + ) override; +}; + +class spider_db_mariadb_util: public spider_db_mbase_util +{ +public: + spider_db_mariadb_util(); + ~spider_db_mariadb_util(); + int append_sql_mode_internal( + spider_string *str, + sql_mode_t sql_mode + ) override; + int append_column_value( + ha_spider *spider, + spider_string *str, + Field *field, + const uchar *new_ptr, + bool is_like, + CHARSET_INFO *access_charset + ) override; +}; + +class spider_db_mbase_row: public spider_db_row +{ +public: + MYSQL_ROW row; + MYSQL_ROW row_first; + ulong *lengths; + ulong *lengths_first; + uint field_count; + uint record_size; + bool cloned; + spider_db_mbase_row( + uint dbton_id + ); + virtual ~spider_db_mbase_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(); + my_decimal *val_decimal( + my_decimal *decimal_value, + CHARSET_INFO *access_charset + ); + SPIDER_DB_ROW *clone(); + int store_to_tmp_table( + TABLE *tmp_table, + spider_string *str + ); + uint get_byte_size(); +}; + +class spider_db_mysql_row: public spider_db_mbase_row +{ +public: + spider_db_mysql_row(); + ~spider_db_mysql_row(); +}; + +class spider_db_mariadb_row: public spider_db_mbase_row +{ +public: + spider_db_mariadb_row(); + ~spider_db_mariadb_row(); +}; + +class spider_db_mbase_result: public spider_db_result +{ +public: + MYSQL_RES *db_result; + spider_db_mbase_row row; + MYSQL_ROW_OFFSET first_row; + int store_error_num; + spider_db_mbase_result( + SPIDER_DB_CONN *in_db_conn + ); + virtual ~spider_db_mbase_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_statistics &stat + ); + int fetch_simple_action( + uint simple_action, + uint position, + void *param + ); + int fetch_table_records( + int mode, + ha_rows &records + ); + int fetch_table_checksum( + ha_spider *spider + ); + int fetch_table_cardinality( + int mode, + TABLE *table, + longlong *cardinality, + uchar *cardinality_upd, + int bitmap_size + ); + int fetch_table_mon_status( + int &status + ); + int fetch_show_master_status( + const char **binlog_file_name, + const char **binlog_pos + ); + int fetch_select_binlog_gtid_pos( + const char **gtid_pos + ); + longlong num_rows(); + uint num_fields(); + void move_to_pos( + longlong pos + ); + int get_errno(); + 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 + ); + int fetch_table_for_discover_table_structure( + spider_string *str, + SPIDER_SHARE *spider_share, + CHARSET_INFO *access_charset + ); +}; + +class spider_db_mysql_result: public spider_db_mbase_result +{ +public: + spider_db_mysql_result( + SPIDER_DB_CONN *in_db_conn + ); + ~spider_db_mysql_result(); +}; + +class spider_db_mariadb_result: public spider_db_mbase_result +{ +public: + spider_db_mariadb_result( + SPIDER_DB_CONN *in_db_conn + ); + ~spider_db_mariadb_result(); +}; + +class spider_db_mbase: public spider_db_conn +{ +protected: + int stored_error; + spider_db_mbase_util *spider_db_mbase_utility; +public: + MYSQL *db_conn; + 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; + spider_db_mbase( + SPIDER_CONN *conn, + spider_db_mbase_util *spider_db_mbase_utility + ); + virtual ~spider_db_mbase(); + 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 + ); + int fetch_and_print_warnings(struct tm *l_time); + 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( + ha_spider *spider, + st_spider_db_request_key *request_key, + int *error_num + ); + int next_result(); + uint affected_rows(); + uint matched_rows(); + bool inserted_info( + spider_db_handler *handler, + ha_copy_info *copy_info + ); + 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_wait_timeout_in_bulk_sql(); + int set_wait_timeout( + int wait_timeout, + int *need_mon + ); + bool set_sql_mode_in_bulk_sql(); + int set_sql_mode( + sql_mode_t sql_mode, + int *need_mon + ); + bool set_time_zone_in_bulk_sql(); + int set_time_zone( + Time_zone *time_zone, + int *need_mon + ); + bool set_loop_check_in_bulk_sql(); + int set_loop_check( + int *need_mon + ); + int fin_loop_check(); + int exec_simple_sql_with_result( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + const char *sql, + uint sql_length, + int all_link_idx, + int *need_mon, + SPIDER_DB_RESULT **res + ); + int show_master_status( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + int mode, + SPIDER_DB_RESULT **res1, + SPIDER_DB_RESULT **res2 + ); + int select_binlog_gtid_pos( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + const char *binlog_file_name, + uint binlog_file_name_length, + const char *binlog_pos, + uint binlog_pos_length, + SPIDER_DB_RESULT **res + ); + 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(); + 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_db_mysql: public spider_db_mbase +{ +public: + spider_db_mysql( + SPIDER_CONN *conn + ); + ~spider_db_mysql(); +}; + +class spider_db_mariadb: public spider_db_mbase +{ +public: + spider_db_mariadb( + SPIDER_CONN *conn + ); + ~spider_db_mariadb(); +}; + +class spider_mbase_share: public spider_db_share +{ +protected: + spider_db_mbase_util *spider_db_mbase_utility; +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; + my_hash_value_type *db_table_str_hash_value; + 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_mbase_share( + st_spider_share *share, + uint dbton_id, + spider_db_mbase_util *spider_db_mbase_utility + ); + virtual ~spider_mbase_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(); + int discover_table_structure( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str + ); + bool checksum_support(); +protected: + 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_share: public spider_mbase_share +{ +public: + spider_mysql_share( + st_spider_share *share + ); + ~spider_mysql_share(); +}; + +class spider_mariadb_share: public spider_mbase_share +{ +public: + spider_mariadb_share( + st_spider_share *share + ); + ~spider_mariadb_share(); +}; + +class spider_mbase_handler: public spider_db_handler +{ +protected: + spider_db_mbase_util *spider_db_mbase_utility; + spider_string sql; + spider_string sql_part; + spider_string sql_part2; + spider_string ha_sql; + int where_pos; + int order_pos; + int limit_pos; +public: + int table_name_pos; +protected: + 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; + SPIDER_INT_HLD *union_table_name_pos_first; + SPIDER_INT_HLD *union_table_name_pos_current; +public: + spider_mbase_share *mysql_share; + SPIDER_LINK_FOR_HASH *link_for_hash; + uchar *minimum_select_bitmap; + uchar direct_insert_kind; + spider_mbase_handler( + ha_spider *spider, + spider_mbase_share *share, + spider_db_mbase_util *spider_db_mbase_utility + ); + virtual ~spider_mbase_handler(); + int init(); + int append_index_hint( + spider_string *str, + int link_idx, + ulong sql_type + ); + 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_union_table_and_sql_for_bka( + const key_range *start_key + ); + int reuse_union_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_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 + ); + int append_update_set_part(); + int append_update_set( + spider_string *str + ); + 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 + ); + 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_union_table_connector_part( + ulong sql_type + ); + int append_union_table_connector( + spider_string *str + ); + int append_union_table_terminator_part( + ulong sql_type + ); + int append_union_table_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_column_values_with_name_part( + const key_range *start_key, + ulong sql_type + ); + int append_key_column_values_with_name( + 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, + bool tgt_final + ); + 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, + bool tgt_final + ); + 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 + ); + int append_sum_select_part( + ulong sql_type, + const char *alias, + uint alias_length + ); + int append_sum_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_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type + ); + int append_group_by( + spider_string *str, + const char *alias, + uint alias_length + ); + 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_multi_range_cnt_with_name_part( + ulong sql_type, + uint multi_range_cnt + ); + int append_multi_range_cnt_with_name( + spider_string *str, + uint multi_range_cnt + ); + 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( + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + int link_idx + ); + int append_explain_select( + spider_string *str, + const key_range *start_key, + const key_range *end_key, + ulong sql_type, + int link_idx + ); + bool is_sole_projection_field( + uint16 field_index + ); + 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 + ); + int set_sql_for_exec( + ulong sql_type, + int link_idx, + SPIDER_LINK_IDX_CHAIN *link_idx_chain + ); + 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 simple_action( + uint simple_action, + int link_idx + ); + int show_records( + int link_idx + ); + int checksum_table( + int link_idx + ); + int show_last_insert_id( + int link_idx, + ulonglong &last_insert_id + ); + ha_rows explain_select( + const key_range *start_key, + const 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 sync_from_clone_source( + spider_db_handler *dbton_hdl + ); + void minimum_select_bitmap_create(); + bool minimum_select_bit_is_set( + uint field_index + ); + void copy_minimum_select_bitmap( + uchar *bitmap + ); + int init_union_table_name_pos(); + int set_union_table_name_pos(); + int reset_union_table_name( + spider_string *str, + int link_idx, + ulong sql_type + ); + int append_from_and_tables_part( + spider_fields *fields, + ulong sql_type + ); + int reappend_tables_part( + spider_fields *fields, + ulong sql_type + ); + int append_where_part( + ulong sql_type + ); + int append_having_part( + ulong sql_type + ); + int append_item_type_part( + Item *item, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ); + int append_list_item_select_part( + List *select, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ); + int append_list_item_select( + List *select, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ); + int append_group_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ); + int append_group_by( + ORDER *order, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ); + int append_order_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ); + int append_order_by( + ORDER *order, + spider_string *str, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields + ); + bool check_direct_update( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); + bool check_direct_delete( + st_select_lex *select_lex, + longlong select_limit, + longlong offset_limit + ); +}; + +class spider_mysql_handler: public spider_mbase_handler +{ +public: + spider_mysql_handler( + ha_spider *spider, + spider_mbase_share *share + ); + ~spider_mysql_handler(); +}; + +class spider_mariadb_handler: public spider_mbase_handler +{ +public: + spider_mariadb_handler( + ha_spider *spider, + spider_mbase_share *share + ); + ~spider_mariadb_handler(); +}; + +class spider_mbase_copy_table: public spider_db_copy_table +{ +public: + spider_mbase_share *mysql_share; + spider_string sql; + uint pos; + spider_mbase_copy_table( + spider_mbase_share *db_share + ); + virtual ~spider_mbase_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 + ); +}; + +class spider_mysql_copy_table: public spider_mbase_copy_table +{ +public: + spider_mysql_copy_table( + spider_mbase_share *db_share + ); + ~spider_mysql_copy_table(); +}; + +class spider_mariadb_copy_table: public spider_mbase_copy_table +{ +public: + spider_mariadb_copy_table( + spider_mbase_share *db_share + ); + ~spider_mariadb_copy_table(); +}; diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc new file mode 100644 index 00000000..dbf7cc8f --- /dev/null +++ b/storage/spider/spd_direct_sql.cc @@ -0,0 +1,1817 @@ +/* Copyright (C) 2009-2020 Kentoku Shiba + Copyright (C) 2019-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_base.h" +#include "sql_servers.h" +#include "tztime.h" +#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" + +#define SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE + +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 HASH spider_ipport_conns; +extern pthread_mutex_t spider_conn_mutex; +extern pthread_mutex_t spider_conn_id_mutex; +extern pthread_mutex_t spider_ipport_conn_mutex; +extern ulonglong spider_conn_id; + +/* UTC time zone for timestamp columns */ +extern Time_zone *UTC; + +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 (!(direct_sql->db_names = (char**) + spider_bulk_malloc(spider_current_trx, 31, MYF(MY_WME | MY_ZEROFILL), + &direct_sql->db_names, (uint) (sizeof(char*) * table_count), + &direct_sql->table_names, (uint) (sizeof(char*) * table_count), + &direct_sql->tables, (uint) (sizeof(TABLE*) * table_count), + &tmp_name_ptr, (uint) (sizeof(char) * ( + table_name_list_length + + SPIDER_THD_db_length(thd) * table_count + + 2 * table_count + )), + &direct_sql->iop, (uint) (sizeof(int) * table_count), + &direct_sql->table_list, (uint) (sizeof(TABLE_LIST) * table_count), + &direct_sql->real_table_bitmap, + (uint) (sizeof(uchar) * ((table_count + 7) / 8)), + NullS)) + ) + 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 (SPIDER_THD_db_str(thd)) + { + memcpy(tmp_name_ptr, SPIDER_THD_db_str(thd), + SPIDER_THD_db_length(thd) + 1); + tmp_name_ptr += SPIDER_THD_db_length(thd) + 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"); + + uint roop_count2; + bool tables_on_different_db_are_joinable = TRUE; + 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 (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { + direct_sql->dbton_id = roop_count2; + break; + } + } + } + if (direct_sql->dbton_id == SPIDER_DBTON_SIZE) + { + my_printf_error( + ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM, + ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR, + MYF(0), direct_sql->tgt_wrapper); + DBUG_RETURN(ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM); + } + tables_on_different_db_are_joinable = + spider_dbton[direct_sql->dbton_id].db_util-> + tables_on_different_db_are_joinable(); + 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 + + (tables_on_different_db_are_joinable ? + 0 : direct_sql->tgt_default_db_name_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 + 1 + + direct_sql->tgt_dsn_length + 1 + + direct_sql->tgt_filedsn_length + 1 + + direct_sql->tgt_driver_length; + 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); + if (direct_sql->tgt_host) + { + DBUG_PRINT("info",("spider tgt_host=%s", direct_sql->tgt_host)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_host); + } else { + DBUG_PRINT("info",("spider tgt_host=NULL")); + tmp_name++; + } + 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 (!tables_on_different_db_are_joinable) + { + if (direct_sql->tgt_default_db_name) + { + DBUG_PRINT("info",("spider tgt_default_db_name=%s", + direct_sql->tgt_default_db_name)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_default_db_name); + } else + tmp_name++; + } + 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 (direct_sql->tgt_dsn) + { + DBUG_PRINT("info",("spider tgt_dsn=%s", + direct_sql->tgt_dsn)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_dsn); + } else + tmp_name++; + if (direct_sql->tgt_filedsn) + { + DBUG_PRINT("info",("spider tgt_filedsn=%s", + direct_sql->tgt_filedsn)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_filedsn); + } else + tmp_name++; + if (direct_sql->tgt_driver) + { + DBUG_PRINT("info",("spider tgt_driver=%s", + direct_sql->tgt_driver)); + tmp_name = strmov(tmp_name + 1, direct_sql->tgt_driver); + } else + tmp_name++; + direct_sql->conn_key_hash_value = my_calc_hash(&spider_open_connections, + (uchar*) direct_sql->conn_key, direct_sql->conn_key_length); + DBUG_RETURN(0); +} + +SPIDER_CONN *spider_udf_direct_sql_create_conn( + const SPIDER_DIRECT_SQL *direct_sql, + int *error_num +) { + SPIDER_CONN *conn; + SPIDER_IP_PORT_CONN *ip_port_conn; + char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket; + char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert; + char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group; + char *tmp_dsn, *tmp_filedsn, *tmp_driver; + int *need_mon; + bool tables_on_different_db_are_joinable = TRUE; + DBUG_ENTER("spider_udf_direct_sql_create_conn"); + + if (unlikely(!UTC)) + { + /* UTC time zone for timestamp columns */ + String tz_00_name(STRING_WITH_LEN("+00:00"), &my_charset_bin); + UTC = my_tz_find(current_thd, &tz_00_name); + } + + tables_on_different_db_are_joinable = + spider_dbton[direct_sql->dbton_id].db_util-> + tables_on_different_db_are_joinable(); + if (!(conn = (SPIDER_CONN *) + spider_bulk_malloc(spider_current_trx, 32, MYF(MY_WME | MY_ZEROFILL), + &conn, (uint) (sizeof(*conn)), + &tmp_name, (uint) (direct_sql->conn_key_length + 1), + &tmp_host, (uint) (direct_sql->tgt_host_length + 1), + &tmp_username, (uint) (direct_sql->tgt_username_length + 1), + &tmp_password, (uint) (direct_sql->tgt_password_length + 1), + &tmp_socket, (uint) (direct_sql->tgt_socket_length + 1), + &tmp_wrapper, (uint) (direct_sql->tgt_wrapper_length + 1), + &tmp_db, (uint) (tables_on_different_db_are_joinable ? + 0 : direct_sql->tgt_default_db_name_length + 1), + &tmp_ssl_ca, (uint) (direct_sql->tgt_ssl_ca_length + 1), + &tmp_ssl_capath, (uint) (direct_sql->tgt_ssl_capath_length + 1), + &tmp_ssl_cert, (uint) (direct_sql->tgt_ssl_cert_length + 1), + &tmp_ssl_cipher, (uint) (direct_sql->tgt_ssl_cipher_length + 1), + &tmp_ssl_key, (uint) (direct_sql->tgt_ssl_key_length + 1), + &tmp_default_file, + (uint) (direct_sql->tgt_default_file_length + 1), + &tmp_default_group, + (uint) (direct_sql->tgt_default_group_length + 1), + &tmp_dsn, + (uint) (direct_sql->tgt_dsn_length + 1), + &tmp_filedsn, + (uint) (direct_sql->tgt_filedsn_length + 1), + &tmp_driver, + (uint) (direct_sql->tgt_driver_length + 1), + &need_mon, (uint) (sizeof(int)), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_conn; + } + conn->default_database.init_calc_mem(138); + + 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); + 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); + if (!tables_on_different_db_are_joinable) + { + conn->tgt_db_length = direct_sql->tgt_default_db_name_length; + conn->tgt_db = tmp_db; + memcpy(conn->tgt_db, direct_sql->tgt_default_db_name, + direct_sql->tgt_default_db_name_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_dsn_length = direct_sql->tgt_dsn_length; + if (conn->tgt_dsn_length) + { + conn->tgt_dsn = tmp_dsn; + memcpy(conn->tgt_dsn, direct_sql->tgt_dsn, + direct_sql->tgt_dsn_length); + } else + conn->tgt_dsn = NULL; + conn->tgt_filedsn_length = direct_sql->tgt_filedsn_length; + if (conn->tgt_filedsn_length) + { + conn->tgt_filedsn = tmp_filedsn; + memcpy(conn->tgt_filedsn, direct_sql->tgt_filedsn, + direct_sql->tgt_filedsn_length); + } else + conn->tgt_filedsn = NULL; + conn->tgt_driver_length = direct_sql->tgt_driver_length; + if (conn->tgt_driver_length) + { + conn->tgt_driver = tmp_driver; + memcpy(conn->tgt_driver, direct_sql->tgt_driver, + direct_sql->tgt_driver_length); + } else + conn->tgt_driver = NULL; + conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc; + 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; + conn->conn_kind = SPIDER_CONN_KIND_MYSQL; + + if (mysql_mutex_init(spd_key_mutex_mta_conn, &conn->mta_conn_mutex, + MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_mta_conn_mutex_init; + } + + if (unlikely((*error_num = spider_conn_init(conn)))) + { + goto error_conn_init; + } + + if ((*error_num = spider_db_udf_direct_sql_connect(direct_sql, conn))) + goto error; + conn->ping_time = (time_t) time((time_t*) 0); + conn->connect_error_time = conn->ping_time; + pthread_mutex_lock(&spider_conn_id_mutex); + conn->conn_id = spider_conn_id; + ++spider_conn_id; + pthread_mutex_unlock(&spider_conn_id_mutex); + + pthread_mutex_lock(&spider_ipport_conn_mutex); + if ((ip_port_conn = (SPIDER_IP_PORT_CONN*) my_hash_search_using_hash_value( + &spider_ipport_conns, conn->conn_key_hash_value, + (uchar*)conn->conn_key, conn->conn_key_length))) + { /* exists, +1 */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + pthread_mutex_lock(&ip_port_conn->mutex); + if (spider_param_max_connections()) + { /* enable conncetion pool */ + if (ip_port_conn->ip_port_count >= spider_param_max_connections()) + { /* bigger than the max num of connections, free conn and return NULL */ + pthread_mutex_unlock(&ip_port_conn->mutex); + goto error_too_many_ipport_count; + } + } + ip_port_conn->ip_port_count++; + pthread_mutex_unlock(&ip_port_conn->mutex); + } + else + {// do not exist + ip_port_conn = spider_create_ipport_conn(conn); + if (!ip_port_conn) { + /* failed, always do not effect 'create conn' */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + DBUG_RETURN(conn); + } + if (my_hash_insert(&spider_ipport_conns, (uchar *)ip_port_conn)) { + /* insert failed, always do not effect 'create conn' */ + pthread_mutex_unlock(&spider_ipport_conn_mutex); + DBUG_RETURN(conn); + } + pthread_mutex_unlock(&spider_ipport_conn_mutex); + } + conn->ip_port_conn = ip_port_conn; + + DBUG_RETURN(conn); + +error: + DBUG_ASSERT(!conn->mta_conn_mutex_file_pos.file_name); +error_too_many_ipport_count: + spider_conn_done(conn); +error_conn_init: + 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 ( + !(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 ( + ( + (spider_param_conn_recycle_mode(trx->thd) & 1) || + spider_param_conn_recycle_strict(trx->thd) + ) + ) { + pthread_mutex_lock(&spider_conn_mutex); + 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))) + { + 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 { + my_hash_delete(&spider_open_connections, (uchar*) conn); + pthread_mutex_unlock(&spider_conn_mutex); + DBUG_PRINT("info",("spider get global conn")); + } + } 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; + + uint old_elements = trx->trx_conn_hash.array.max_element; + if (my_hash_insert(&trx->trx_conn_hash, (uchar*) conn)) + { + 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 (conn->queued_connect) + { + if ((*error_num = spider_db_udf_direct_sql_connect(direct_sql, conn))) + goto error; + conn->queued_connect = FALSE; + } + + if (conn->queued_ping) + conn->queued_ping = FALSE; + + 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_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!direct_sql->param_name) \ + { \ + if ((direct_sql->param_name = spider_create_string(parse.start_value, \ + value_length))) \ + direct_sql->SPIDER_PARAM_LEN(param_name) = strlen(direct_sql->param_name); \ + else { \ + error_num= parse.fail(true); \ + 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(parse.start_title, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(parse.start_title + 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= parse.fail(true); \ + goto error; \ + } else if (direct_sql->param_name[hint_num] != -1) \ + break; \ + direct_sql->param_name[hint_num] = atoi(parse.start_value); \ + 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; \ + DBUG_PRINT("info",("spider " title_name "[%d]=%d", hint_num, \ + direct_sql->param_name[hint_num])); \ + } else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (direct_sql->param_name == -1) \ + { \ + direct_sql->param_name = atoi(parse.start_value); \ + 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; \ + 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(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (direct_sql->param_name == -1) \ + { \ + direct_sql->param_name = atoi(parse.start_value); \ + if (direct_sql->param_name < min_val) \ + direct_sql->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%d", direct_sql->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (direct_sql->param_name == -1) \ + { \ + direct_sql->param_name = my_strtoll10(parse.start_value, (char**) NULL, \ + &error_num); \ + if (direct_sql->param_name < min_val) \ + direct_sql->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%lld", direct_sql->param_name)); \ + } \ + break; \ + } + +static void spider_minus_1(SPIDER_DIRECT_SQL *direct_sql) +{ + 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; + direct_sql->use_real_table = -1; + direct_sql->error_rw_mode = -1; + for (int i = 0; i < direct_sql->table_count; i++) + direct_sql->iop[i] = -1; +} + +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; + char *param_string = NULL; + char *start_param; + int title_length, value_length; + SPIDER_PARAM_STRING_PARSE parse; + DBUG_ENTER("spider_udf_parse_direct_sql_param"); + + spider_minus_1(direct_sql); + 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)); + + start_param = param_string; + parse.error_num = ER_SPIDER_INVALID_UDF_PARAM_NUM; + while (*start_param != '\0') + { + if (parse.locate_param_def(start_param)) + { + error_num= parse.fail(false); + goto error; + } + /* Null the end of the parameter value. */ + *parse.end_value= '\0'; + value_length= (int) (parse.end_value - parse.start_value); + + switch (title_length = (int) (parse.end_title - parse.start_title)) + { + case 0: + error_num= parse.fail(true); + goto error; + case 3: + 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_STR("drv", tgt_driver); + SPIDER_PARAM_STR("dsn", tgt_dsn); + SPIDER_PARAM_STR("fds", tgt_filedsn); + 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); + SPIDER_PARAM_INT_WITH_MAX("urt", use_real_table, 0, 1); + SPIDER_PARAM_INT("wto", net_write_timeout, 0); + error_num= parse.fail(true); + goto error; + case 4: + SPIDER_PARAM_INT_WITH_MAX("erwm", error_rw_mode, 0, 1); + SPIDER_PARAM_STR("host", tgt_host); + SPIDER_PARAM_INT_WITH_MAX("port", tgt_port, 0, 65535); + SPIDER_PARAM_STR("user", tgt_username); + error_num= parse.fail(true); + goto error; + case 6: + SPIDER_PARAM_STR("driver", tgt_driver); + 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= parse.fail(true); + goto error; + case 7: + SPIDER_PARAM_STR("filedsn", tgt_filedsn); + SPIDER_PARAM_STR("wrapper", tgt_wrapper); + SPIDER_PARAM_STR("ssl_key", tgt_ssl_key); + error_num= parse.fail(true); + 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= parse.fail(true); + goto error; + case 10: + SPIDER_PARAM_STR("ssl_cipher", tgt_ssl_cipher); + SPIDER_PARAM_STR("ssl_capath", tgt_ssl_capath); + error_num= parse.fail(true); + goto error; + case 11: + error_num= parse.fail(true); + goto error; + case 12: + SPIDER_PARAM_STR("default_file", tgt_default_file); + error_num= parse.fail(true); + goto error; + case 13: + SPIDER_PARAM_STR("default_group", tgt_default_group); + SPIDER_PARAM_INT_WITH_MAX("error_rw_mode", error_rw_mode, 0, 1); + error_num= parse.fail(true); + goto error; + case 14: + SPIDER_PARAM_INT_WITH_MAX("use_real_table", use_real_table, 0, 1); + error_num= parse.fail(true); + 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= parse.fail(true); + 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= parse.fail(true); + goto error; + case 17: + SPIDER_PARAM_INT("net_write_timeout", net_write_timeout, 0); + error_num= parse.fail(true); + goto error; + case 18: + SPIDER_PARAM_INT_WITH_MAX( + "connection_channel", connection_channel, 0, 63); + error_num= parse.fail(true); + goto error; + case 22: + SPIDER_PARAM_INT_WITH_MAX("ssl_verify_server_cert", tgt_ssl_vsc, 0, 1); + error_num= parse.fail(true); + goto error; + default: + error_num= parse.fail(true); + goto error; + } + /* Restore delim */ + *parse.end_value= parse.delim_value; + } + +set_default: + error_num = spider_udf_set_direct_sql_param_default(trx, direct_sql); +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 +) { + bool check_socket; + bool check_database; + bool check_default_file; + bool check_host; + bool check_port; + bool socket_has_default_value; + bool database_has_default_value; + bool default_file_has_default_value; + bool host_has_default_value; + bool port_has_default_value; + 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_socket && + (!direct_sql->tgt_host || !strcmp(direct_sql->tgt_host, my_localhost)) + ) { + check_socket = TRUE; + } else { + check_socket = FALSE; + } + if (!direct_sql->tgt_default_db_name) + { + check_database = TRUE; + } else { + check_database = FALSE; + } + if ( + !direct_sql->tgt_default_file && + direct_sql->tgt_default_group && + (*spd_defaults_file || *spd_defaults_extra_file) + ) { + check_default_file = TRUE; + } else { + check_default_file = FALSE; + } + if (!direct_sql->tgt_host) + { + check_host = TRUE; + } else { + check_host = FALSE; + } + if (direct_sql->tgt_port == -1) + { + check_port = TRUE; + } else { + check_port = FALSE; + } + if (check_socket || check_database || check_default_file || check_host || + check_port) + { + socket_has_default_value = check_socket; + database_has_default_value = check_database; + default_file_has_default_value = check_default_file; + host_has_default_value = check_host; + port_has_default_value = check_port; + if (direct_sql->tgt_wrapper) + { + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + DBUG_PRINT("info",("spider direct_sql->tgt_wrapper=%s", + direct_sql->tgt_wrapper)); + DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count, + spider_dbton[roop_count].wrapper ? + spider_dbton[roop_count].wrapper : "NULL")); + if ( + spider_dbton[roop_count].wrapper && + !strcmp(direct_sql->tgt_wrapper, + spider_dbton[roop_count].wrapper) + ) { + if (spider_dbton[roop_count].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { + if (check_socket) + { + socket_has_default_value = spider_dbton[roop_count]. + db_util->socket_has_default_value(); + } + if (check_database) + { + database_has_default_value = spider_dbton[roop_count]. + db_util->database_has_default_value(); + } + if (check_default_file) + { + default_file_has_default_value = spider_dbton[roop_count]. + db_util->default_file_has_default_value(); + } + if (check_host) + { + host_has_default_value = spider_dbton[roop_count]. + db_util->host_has_default_value(); + } + if (check_port) + { + port_has_default_value = spider_dbton[roop_count]. + db_util->port_has_default_value(); + } + break; + } + } + } + } + } else { + socket_has_default_value = FALSE; + database_has_default_value = FALSE; + default_file_has_default_value = FALSE; + host_has_default_value = FALSE; + port_has_default_value = FALSE; + } + + if (database_has_default_value) + { + DBUG_PRINT("info",("spider create default tgt_default_db_name")); + direct_sql->tgt_default_db_name_length = SPIDER_THD_db_length(trx->thd); + if ( + !(direct_sql->tgt_default_db_name = spider_create_string( + SPIDER_THD_db_str(trx->thd), + 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 (host_has_default_value) + { + 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 (default_file_has_default_value) + { + 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 (port_has_default_value) + { + 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 (socket_has_default_value) + { + 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->bulk_insert_rows == -1) + direct_sql->bulk_insert_rows = 3000; + if (direct_sql->connection_channel == -1) + direct_sql->connection_channel = 0; + if (direct_sql->use_real_table == -1) + direct_sql->use_real_table = 0; + if (direct_sql->error_rw_mode == -1) + direct_sql->error_rw_mode = 0; + 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"); + 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); + } + 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); + } + 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->tgt_dsn) + { + spider_free(spider_current_trx, direct_sql->tgt_dsn, MYF(0)); + } + if (direct_sql->tgt_filedsn) + { + spider_free(spider_current_trx, direct_sql->tgt_filedsn, MYF(0)); + } + if (direct_sql->tgt_driver) + { + spider_free(spider_current_trx, direct_sql->tgt_driver, 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; + TABLE_LIST *real_table_list_last = NULL; + uint use_real_table = 0; + DBUG_ENTER("spider_direct_sql_body"); + SPIDER_BACKUP_DASTATUS; + if (!(direct_sql = (SPIDER_DIRECT_SQL *) + spider_bulk_malloc(spider_current_trx, 34, MYF(MY_WME | MY_ZEROFILL), + &direct_sql, (uint) (sizeof(SPIDER_DIRECT_SQL)), + &sql, (uint) (sizeof(char) * args->lengths[0]), + NullS)) + ) { + error_num = HA_ERR_OUT_OF_MEM; + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + 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++; + } + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + direct_sql->trx = trx; + + if (args->args[1]) + { + if ((error_num = spider_udf_direct_sql_create_table_list( + direct_sql, + args->args[1], + args->lengths[1] + ))) { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } else { + if ((error_num = spider_udf_direct_sql_create_table_list( + direct_sql, + (char *) "", + 0 + ))) { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } + if (args->args[2]) + { + if ((error_num = spider_udf_parse_direct_sql_param( + trx, + direct_sql, + args->args[2], + args->lengths[2] + ))) { + goto error; + } + } else { + if ((error_num = spider_udf_parse_direct_sql_param( + trx, + direct_sql, + "", + 0 + ))) { + goto error; + } + } + trx->updated_in_this_trx = TRUE; + DBUG_PRINT("info",("spider trx->updated_in_this_trx=TRUE")); + use_real_table= direct_sql->use_real_table; + for (roop_count= 0; roop_count < direct_sql->table_count; roop_count++) + { +#ifdef SPIDER_NEED_INIT_ONE_TABLE_FOR_FIND_TEMPORARY_TABLE +#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias + LEX_CSTRING db_name = + { + direct_sql->db_names[roop_count], + strlen(direct_sql->db_names[roop_count]) + }; + LEX_CSTRING tbl_name = + { + direct_sql->table_names[roop_count], + strlen(direct_sql->table_names[roop_count]) + }; + table_list.init_one_table(&db_name, &tbl_name, 0, TL_WRITE); +#else + table_list.init_one_table(direct_sql->db_names[roop_count], + strlen(direct_sql->db_names[roop_count]), + direct_sql->table_names[roop_count], + strlen(direct_sql->table_names[roop_count]), + direct_sql->table_names[roop_count], TL_WRITE); +#endif +#else + SPIDER_TABLE_LIST_db_str(&table_list) = direct_sql->db_names[roop_count]; + SPIDER_TABLE_LIST_table_name_str(&table_list) = + direct_sql->table_names[roop_count]; +#endif + if (!(direct_sql->tables[roop_count] = + spider_find_temporary_table(thd, &table_list))) + { + if (!use_real_table) + { + error_num = ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM; + my_printf_error(ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_NUM, + ER_SPIDER_UDF_TMP_TABLE_NOT_FOUND_STR, + MYF(0), SPIDER_TABLE_LIST_db_str(&table_list), + SPIDER_TABLE_LIST_table_name_str(&table_list)); + goto error; + } + TABLE_LIST *tables = &direct_sql->table_list[roop_count]; + MDL_REQUEST_INIT(&tables->mdl_request, MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(&table_list), + SPIDER_TABLE_LIST_table_name_str(&table_list), + 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; + } + } + if ((error_num = spider_udf_direct_sql_create_conn_key(direct_sql))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + if (!(conn = spider_udf_direct_sql_get_conn(direct_sql, trx, &error_num))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + conn->error_mode = 0; + direct_sql->conn = conn; + if ((error_num = spider_db_udf_check_and_set_set_names(trx))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + 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; + + if (bg) + { + if ((error_num = spider_udf_bg_direct_sql(direct_sql))) + { + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + goto error; + } + } else { + if (conn->bg_init) + pthread_mutex_lock(&conn->bg_conn_mutex); + if ((error_num = 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; + if (error_num == HA_ERR_OUT_OF_MEM) + my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); + 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; + } + if (!bg) + { + spider_udf_free_direct_sql_alloc(direct_sql, FALSE); + } + DBUG_RETURN(1); + +error: + if (direct_sql) + { + if ( + direct_sql->error_rw_mode && + spider_db_conn_is_network_error(error_num) + ) { + SPIDER_RESTORE_DASTATUS; + spider_udf_free_direct_sql_alloc(direct_sql, bg); + DBUG_RETURN(1); + } + 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; + } + 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_mutex_init(spd_key_mutex_bg_direct_sql, + &bg_direct_sql->bg_mutex, MY_MUTEX_INIT_FAST)) + { + strcpy(message, "spider_bg_direct_sql() out of memory"); + goto error_mutex_init; + } + if (mysql_cond_init(spd_key_cond_bg_direct_sql, + &bg_direct_sql->bg_cond, NULL)) + { + strcpy(message, "spider_bg_direct_sql() out of memory"); + goto error_cond_init; + } + initid->ptr = (char *) bg_direct_sql; + } + DBUG_RETURN(FALSE); + +error_cond_init: + pthread_mutex_destroy(&bg_direct_sql->bg_mutex); +error_mutex_init: + spider_free(spider_current_trx, bg_direct_sql, MYF(0)); +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_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 *thd = current_thd; + thd->transaction->stmt.modified_non_trans_table = TRUE; + } + 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; +} + +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); +} diff --git a/storage/spider/spd_direct_sql.h b/storage/spider/spd_direct_sql.h new file mode 100644 index 00000000..fa5f00f2 --- /dev/null +++ b/storage/spider/spd_direct_sql.h @@ -0,0 +1,65 @@ +/* Copyright (C) 2009-2014 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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 +); + +int spider_udf_bg_direct_sql( + SPIDER_DIRECT_SQL *direct_sql +); diff --git a/storage/spider/spd_environ.h b/storage/spider/spd_environ.h new file mode 100644 index 00000000..ccdc7009 --- /dev/null +++ b/storage/spider/spd_environ.h @@ -0,0 +1,29 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2017-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +/* + Define functionality offered by MySQL or MariaDB +*/ + +#ifndef SPD_ENVIRON_INCLUDED + +#define SPIDER_NET_HAS_THD +#define HANDLER_HAS_TOP_TABLE_FIELDS +#define PARTITION_HAS_GET_PART_SPEC +#define HA_EXTRA_HAS_STARTING_ORDERED_INDEX_SCAN +#define HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT +#define SPIDER_UPDATE_ROW_HAS_CONST_NEW_DATA +#endif /* SPD_ENVIRON_INCLUDED */ diff --git a/storage/spider/spd_err.h b/storage/spider/spd_err.h new file mode 100644 index 00000000..e9a4a419 --- /dev/null +++ b/storage/spider/spd_err.h @@ -0,0 +1,141 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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_PARAM_TOO_LONG_NUM 12505 +#define ER_SPIDER_UDF_PARAM_TOO_LONG_STR "The UDF parameter '%-.64s' is too long" +#define ER_SPIDER_UDF_PARAM_REQIRED_NUM 12506 +#define ER_SPIDER_UDF_PARAM_REQIRED_STR "The UDF parameter '%-.64s' is 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_OPEN_SYS_TABLE_NUM 12524 +#define ER_SPIDER_CANT_OPEN_SYS_TABLE_STR "Can't open system table %s.%s" +#define ER_SPIDER_LINK_MON_JUST_NG_NUM 12525 +#define ER_SPIDER_LINK_MON_JUST_NG_STR "Table '%s.%s' just got a problem" +#define ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_NUM 12526 +#define ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_STR "The connect info '%-.64s' for %s cannot start with number" +#define ER_SPIDER_INVALID_CONNECT_INFO_SAME_NUM 12527 +#define ER_SPIDER_INVALID_CONNECT_INFO_SAME_STR "The connect info '%-.64s' for %s cannot use same name in same table" + +#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 MariaDB 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_DATASOURCE_STR "Error from %s %d %s %s" +#define ER_SPIDER_DATASOURCE_NUM 12712 +#define ER_SPIDER_CON_COUNT_ERROR 12713 +#define ER_SPIDER_CON_COUNT_ERROR_STR "Too many connections between spider and remote" +#define ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM 12714 +#define ER_SPIDER_TABLE_OPEN_TIMEOUT_STR "Table %s.%s open timeout" +#define ER_SPIDER_INFINITE_LOOP_NUM 12719 +#define ER_SPIDER_INFINITE_LOOP_STR "An infinite loop is detected when opening table %s.%s" +#define ER_SPIDER_SAME_SERVER_LINK_NUM 12720 +#define ER_SPIDER_SAME_SERVER_LINK_STR1 "Host:%s and Socket:%s aim self server. Please change spider_same_server_link parameter if this link is required." +#define ER_SPIDER_SAME_SERVER_LINK_STR2 "Host:%s and Port:%ld aim self server. Please change spider_same_server_link parameter if this link is required." +#define ER_SPIDER_CANT_NUM 12721 +#define ER_SPIDER_CANT_STR1 "Can't %s%d" +#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_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc new file mode 100644 index 00000000..3cd299c6 --- /dev/null +++ b/storage/spider/spd_group_by_handler.cc @@ -0,0 +1,2065 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "ha_partition.h" +#include "sql_common.h" +#include +#include "spd_err.h" +#include "spd_param.h" +#include "spd_db_include.h" +#include "spd_include.h" +#include "ha_spider.h" +#include "spd_conn.h" +#include "spd_db_conn.h" +#include "spd_malloc.h" +#include "spd_table.h" +#include "spd_ping_table.h" +#include "spd_group_by_handler.h" + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +spider_fields::spider_fields() : + dbton_count(0), current_dbton_num(0), + table_count(0), current_table_num(0), table_holder(NULL), + first_link_idx_chain(NULL), last_link_idx_chain(NULL), current_link_idx_chain(NULL), + first_conn_holder(NULL), last_conn_holder(NULL), current_conn_holder(NULL), + first_field_holder(NULL), last_field_holder(NULL), current_field_holder(NULL), + first_field_chain(NULL), last_field_chain(NULL), current_field_chain(NULL) +{ + DBUG_ENTER("spider_fields::spider_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_VOID_RETURN; +} + +spider_fields::~spider_fields() +{ + DBUG_ENTER("spider_fields::~spider_fields"); + DBUG_PRINT("info",("spider this=%p", this)); + if (first_link_idx_chain) + { + while ((current_link_idx_chain = first_link_idx_chain)) + { + first_link_idx_chain = current_link_idx_chain->next; + spider_free(spider_current_trx, current_link_idx_chain, MYF(0)); + } + } + if (first_field_chain) + { + while ((current_field_chain = first_field_chain)) + { + first_field_chain = current_field_chain->next; + spider_free(spider_current_trx, current_field_chain, MYF(0)); + } + } + if (first_field_holder) + { + while ((current_field_holder = first_field_holder)) + { + first_field_holder = current_field_holder->next; + spider_free(spider_current_trx, current_field_holder, MYF(0)); + } + } + if (table_holder) + spider_free(spider_current_trx, table_holder, MYF(0)); + if (first_conn_holder) + { + while ((current_conn_holder = first_conn_holder)) + { + first_conn_holder = current_conn_holder->next; + free_conn_holder(current_conn_holder); + } + } + DBUG_VOID_RETURN; +} + +void spider_fields::add_dbton_id( + uint dbton_id_arg +) { + uint roop_count; + DBUG_ENTER("spider_fields::add_dbton_id"); + DBUG_PRINT("info",("spider this=%p", this)); + for (roop_count = 0; roop_count < dbton_count; ++roop_count) + { + if (dbton_ids[roop_count] == dbton_id_arg) + { + DBUG_VOID_RETURN; + } + } + dbton_ids[roop_count] = dbton_id_arg; + ++dbton_count; + DBUG_VOID_RETURN; +} + +void spider_fields::set_pos_to_first_dbton_id( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_dbton_id"); + DBUG_PRINT("info",("spider this=%p", this)); + current_dbton_num = 0; + DBUG_VOID_RETURN; +} + +uint spider_fields::get_next_dbton_id( +) { + uint return_dbton_id; + DBUG_ENTER("spider_fields::get_next_dbton_id"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_dbton_num >= dbton_count) + DBUG_RETURN(SPIDER_DBTON_SIZE); + return_dbton_id = dbton_ids[current_dbton_num]; + ++current_dbton_num; + DBUG_RETURN(return_dbton_id); +} + +int spider_fields::make_link_idx_chain( + int link_status +) { + uint roop_count, roop_count2; + SPIDER_CONN *conn; + SPIDER_CONN_HOLDER *conn_holder; + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder; + SPIDER_LINK_IDX_HOLDER *link_idx_holder, *add_link_idx_holder, + *dup_link_idx_holder, *current_link_idx_holder; + ha_spider *spider; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_SHARE *share; + DBUG_ENTER("spider_fields::make_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + conn_holder = first_conn_holder; + bool has_remain, skip; + do { + for (roop_count2 = 0; roop_count2 < table_count; ++roop_count2) + { + table_link_idx_holder = &conn_holder->table_link_idx_holder[roop_count2]; + link_idx_holder = table_link_idx_holder->first_link_idx_holder; + dup_link_idx_holder = NULL; + for (roop_count = 0; + roop_count < conn_holder->link_idx_holder_count_max - 1; ++roop_count) + { + if (!link_idx_holder->next) + { + DBUG_PRINT("info",("spider fill link_idx_holder for %u", + roop_count2)); + if (!(add_link_idx_holder = create_link_idx_holder())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + dup_link_idx_holder = get_dup_link_idx_holder( + table_link_idx_holder, dup_link_idx_holder); + add_link_idx_holder->table_link_idx_holder = + dup_link_idx_holder->table_link_idx_holder; + add_link_idx_holder->link_idx = dup_link_idx_holder->link_idx; + add_link_idx_holder->link_status = dup_link_idx_holder->link_status; + link_idx_holder->next = add_link_idx_holder; + } + link_idx_holder = link_idx_holder->next; + } + } + + for (roop_count2 = 0; roop_count2 < table_count; ++roop_count2) + { + table_link_idx_holder = &conn_holder->table_link_idx_holder[roop_count2]; + table_link_idx_holder->current_link_idx_holder = + table_link_idx_holder->first_link_idx_holder; + } + for (roop_count = 0; + roop_count < conn_holder->link_idx_holder_count_max; ++roop_count) + { + link_idx_holder = NULL; + for (roop_count2 = 0; roop_count2 < table_count; ++roop_count2) + { + table_link_idx_holder = + &conn_holder->table_link_idx_holder[roop_count2]; + if (link_idx_holder) + { + link_idx_holder->next_table = + table_link_idx_holder->current_link_idx_holder; + } + link_idx_holder = table_link_idx_holder->current_link_idx_holder; + table_link_idx_holder->current_link_idx_holder = link_idx_holder->next; + } + } + } while ((conn_holder = conn_holder->next)); + + current_conn_holder = first_conn_holder; + do { + table_link_idx_holder = + ¤t_conn_holder->table_link_idx_holder[0]; + table_link_idx_holder->current_link_idx_holder = + table_link_idx_holder->first_link_idx_holder; + } while ((current_conn_holder = current_conn_holder->next)); + + spider = table_holder[0].spider; + share = spider->share; + DBUG_PRINT("info",("spider create link_idx_chain sorted by 0")); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + link_status); + roop_count < share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + link_status) + ) { + conn = spider->conns[roop_count]; + if (!conn->conn_holder_for_direct_join) + { + continue; + } + table_link_idx_holder = + &conn->conn_holder_for_direct_join->table_link_idx_holder[0]; + link_idx_holder = table_link_idx_holder->current_link_idx_holder; + table_link_idx_holder->current_link_idx_holder = link_idx_holder->next; + DBUG_ASSERT(link_idx_holder->link_idx == (int) roop_count); + if (!(link_idx_chain = create_link_idx_chain())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!first_link_idx_chain) + { + first_link_idx_chain = link_idx_chain; + } else { + last_link_idx_chain->next = link_idx_chain; + } + last_link_idx_chain = link_idx_chain; + link_idx_chain->conn = conn; + link_idx_chain->link_idx_holder = link_idx_holder; + do { + if (link_idx_chain->link_status < link_idx_holder->link_status) + { + link_idx_chain->link_status = link_idx_holder->link_status; + } + } while ((link_idx_holder = link_idx_holder->next_table)); + } + + do { + has_remain = FALSE; + current_conn_holder = first_conn_holder; + do { + table_link_idx_holder = + ¤t_conn_holder->table_link_idx_holder[0]; + link_idx_holder = table_link_idx_holder->current_link_idx_holder; + if (link_idx_holder) + { + has_remain = TRUE; + for (roop_count2 = 1; roop_count2 < table_count; ++roop_count2) + { + if (table_link_idx_holder[roop_count2].link_idx_holder_count == + current_conn_holder->link_idx_holder_count_max) + { + break; + } + } + break; + } + } while ((current_conn_holder = current_conn_holder->next)); + + if (has_remain) + { + current_conn_holder = first_conn_holder; + do { + table_link_idx_holder = + ¤t_conn_holder->table_link_idx_holder[0]; + link_idx_holder = table_link_idx_holder->current_link_idx_holder; + if (link_idx_holder) + { + for (roop_count = 1; roop_count <= roop_count2; ++roop_count) + { + link_idx_holder = link_idx_holder->next_table; + } + table_link_idx_holder[roop_count2].current_link_idx_holder = + link_idx_holder; + } else { + table_link_idx_holder[roop_count2].current_link_idx_holder = NULL; + } + } while ((current_conn_holder = current_conn_holder->next)); + + spider = table_holder[roop_count2].spider; + share = spider->share; + DBUG_PRINT("info",("spider create link_idx_chain sorted by %d", + roop_count2)); + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + link_status); + roop_count < share->link_count; + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, roop_count, share->link_count, + link_status) + ) { + conn = spider->conns[roop_count]; + if (!conn->conn_holder_for_direct_join) + { + continue; + } + table_link_idx_holder = + &conn->conn_holder_for_direct_join->table_link_idx_holder[0]; + link_idx_holder = + table_link_idx_holder[roop_count2].current_link_idx_holder; + skip = FALSE; + if (link_idx_holder) + { + current_link_idx_holder = table_link_idx_holder->first_link_idx_holder; + while (current_link_idx_holder != link_idx_holder) + { + if (current_link_idx_holder->link_idx == + link_idx_holder->link_idx) + { + skip = TRUE; + break; + } + current_link_idx_holder = current_link_idx_holder->next; + } + } + if (skip) + { + continue; + } + DBUG_PRINT("info",("spider create link_idx_chain for %d", + roop_count2)); + table_link_idx_holder[roop_count2].current_link_idx_holder = + link_idx_holder->next; + link_idx_holder = + table_link_idx_holder->current_link_idx_holder; + table_link_idx_holder->current_link_idx_holder = + link_idx_holder->next; + if (!(link_idx_chain = create_link_idx_chain())) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + DBUG_ASSERT(first_link_idx_chain); + last_link_idx_chain->next = link_idx_chain; + last_link_idx_chain = link_idx_chain; + link_idx_chain->conn = conn; + link_idx_chain->link_idx_holder = link_idx_holder; + do { + if (link_idx_chain->link_status < link_idx_holder->link_status) + { + link_idx_chain->link_status = link_idx_holder->link_status; + } + } while ((link_idx_holder = link_idx_holder->next_table)); + } + } + } while (has_remain); + DBUG_RETURN(0); +} + +SPIDER_LINK_IDX_CHAIN *spider_fields::create_link_idx_chain( +) { + DBUG_ENTER("spider_fields::create_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_LINK_IDX_CHAIN *) + spider_malloc(spider_current_trx, 254, sizeof(SPIDER_LINK_IDX_CHAIN), + MYF(MY_WME | MY_ZEROFILL))); +} + +void spider_fields::set_pos_to_first_link_idx_chain( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + current_link_idx_chain = first_link_idx_chain; + DBUG_VOID_RETURN; +} + +SPIDER_LINK_IDX_CHAIN *spider_fields::get_next_link_idx_chain( +) { + SPIDER_LINK_IDX_CHAIN *return_link_idx_chain = current_link_idx_chain; + DBUG_ENTER("spider_fields::get_next_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_link_idx_chain) + current_link_idx_chain = current_link_idx_chain->next; + DBUG_RETURN(return_link_idx_chain); +} + +SPIDER_LINK_IDX_HOLDER *spider_fields::get_dup_link_idx_holder( + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder, + SPIDER_LINK_IDX_HOLDER *current +) { + SPIDER_LINK_IDX_HOLDER *return_link_idx_holder; + DBUG_ENTER("spider_fields::get_dup_link_idx_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!current) + { + return_link_idx_holder = table_link_idx_holder->first_link_idx_holder; + do { + if (return_link_idx_holder->link_status == SPIDER_LINK_STATUS_OK) + break; + } while ((return_link_idx_holder = return_link_idx_holder->next)); + if (!return_link_idx_holder) + { + return_link_idx_holder = table_link_idx_holder->first_link_idx_holder; + } + } else { + if (current->link_status == SPIDER_LINK_STATUS_OK) + { + return_link_idx_holder = current; + while ((return_link_idx_holder = return_link_idx_holder->next)) + { + if (return_link_idx_holder->link_status == SPIDER_LINK_STATUS_OK) + break; + } + if (!return_link_idx_holder) + { + return_link_idx_holder = table_link_idx_holder->first_link_idx_holder; + do { + if ( + return_link_idx_holder->link_status == SPIDER_LINK_STATUS_OK + ) + break; + DBUG_ASSERT(return_link_idx_holder != current); + } while ((return_link_idx_holder = return_link_idx_holder->next)); + } + } else { + if (!current->next) + { + return_link_idx_holder = table_link_idx_holder->first_link_idx_holder; + } else { + return_link_idx_holder = current->next; + } + } + } + DBUG_RETURN(return_link_idx_holder); +} + +bool spider_fields::check_link_ok_chain( +) { + DBUG_ENTER("spider_fields::check_link_ok_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + for (current_link_idx_chain = first_link_idx_chain; current_link_idx_chain; + current_link_idx_chain = current_link_idx_chain->next) + { + DBUG_PRINT("info",("spider current_link_idx_chain=%p", current_link_idx_chain)); + DBUG_PRINT("info",("spider current_link_idx_chain->link_status=%d", current_link_idx_chain->link_status)); + if (current_link_idx_chain->link_status == SPIDER_LINK_STATUS_OK) + { + first_ok_link_idx_chain = current_link_idx_chain; + DBUG_RETURN(FALSE); + } + } + DBUG_RETURN(TRUE); +} + +bool spider_fields::is_first_link_ok_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg +) { + DBUG_ENTER("spider_fields::is_first_link_ok_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(first_ok_link_idx_chain == link_idx_chain_arg); +} + +int spider_fields::get_ok_link_idx( +) { + DBUG_ENTER("spider_fields::get_ok_link_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(first_ok_link_idx_chain->link_idx_holder->link_idx); +} + +void spider_fields::set_first_link_idx( +) { + SPIDER_TABLE_HOLDER *table_holder; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + uint dbton_id; + ha_spider *spider; + spider_db_handler *dbton_hdl; + DBUG_ENTER("spider_fields::set_first_link_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + set_pos_to_first_dbton_id(); + while ((dbton_id = get_next_dbton_id()) < SPIDER_DBTON_SIZE) + { + set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = get_next_link_idx_chain())) + { + if (link_idx_chain->conn->dbton_id == dbton_id) + { + break; + } + } + DBUG_ASSERT(link_idx_chain); + set_pos_to_first_table_on_link_idx_chain(link_idx_chain); + + set_pos_to_first_table_holder(); + while ((table_holder = get_next_table_holder())) + { + link_idx_holder = get_next_table_on_link_idx_chain(link_idx_chain); + spider = table_holder->spider; + dbton_hdl = spider->dbton_handler[dbton_id]; + dbton_hdl->first_link_idx = link_idx_holder->link_idx; + } + } + DBUG_VOID_RETURN; +} + +int spider_fields::add_link_idx( + SPIDER_CONN_HOLDER *conn_holder_arg, + ha_spider *spider_arg, + int link_idx +) { + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + DBUG_ENTER("spider_fields::add_link_idx"); + DBUG_PRINT("info",("spider this=%p", this)); + table_link_idx_holder = + &conn_holder_arg->table_link_idx_holder[spider_arg->idx_for_direct_join]; + if (!table_link_idx_holder->first_link_idx_holder) + { + link_idx_holder = create_link_idx_holder(); + DBUG_PRINT("info",("spider link_idx_holder=%p", link_idx_holder)); + if (!link_idx_holder) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + table_link_idx_holder->first_link_idx_holder = link_idx_holder; + table_link_idx_holder->last_link_idx_holder = link_idx_holder; + table_link_idx_holder->table_holder = + &table_holder[spider_arg->idx_for_direct_join]; + } else { + link_idx_holder = create_link_idx_holder(); + DBUG_PRINT("info",("spider link_idx_holder=%p", link_idx_holder)); + if (!link_idx_holder) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + table_link_idx_holder->last_link_idx_holder->next = link_idx_holder; + table_link_idx_holder->last_link_idx_holder = link_idx_holder; + } + link_idx_holder->table_link_idx_holder = table_link_idx_holder; + link_idx_holder->link_idx = link_idx; + link_idx_holder->link_status = spider_conn_get_link_status( + spider_arg->share->link_statuses, spider_arg->conn_link_idx, + link_idx); + ++table_link_idx_holder->link_idx_holder_count; + if (conn_holder_arg->link_idx_holder_count_max < + table_link_idx_holder->link_idx_holder_count) + { + conn_holder_arg->link_idx_holder_count_max = + table_link_idx_holder->link_idx_holder_count; + } + DBUG_RETURN(0); +} + +SPIDER_LINK_IDX_HOLDER *spider_fields::create_link_idx_holder( +) { + DBUG_ENTER("spider_fields::create_link_idx_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_LINK_IDX_HOLDER *) + spider_malloc(spider_current_trx, 253, sizeof(SPIDER_LINK_IDX_HOLDER), + MYF(MY_WME | MY_ZEROFILL))); +} + +void spider_fields::set_pos_to_first_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg +) { + DBUG_ENTER("spider_fields::set_pos_to_first_table_on_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + link_idx_chain_arg->current_link_idx_holder = + link_idx_chain_arg->link_idx_holder; + DBUG_VOID_RETURN; +} + +SPIDER_LINK_IDX_HOLDER *spider_fields::get_next_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg +) { + SPIDER_LINK_IDX_HOLDER *return_link_idx_holder; + DBUG_ENTER("spider_fields::get_next_table_on_link_idx_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!link_idx_chain_arg->current_link_idx_holder) + DBUG_RETURN(NULL); + return_link_idx_holder = link_idx_chain_arg->current_link_idx_holder; + link_idx_chain_arg->current_link_idx_holder = + link_idx_chain_arg->current_link_idx_holder->next_table; + DBUG_RETURN(return_link_idx_holder); +} + +SPIDER_CONN_HOLDER *spider_fields::add_conn( + SPIDER_CONN *conn_arg, + long access_balance +) { + SPIDER_CONN_HOLDER *conn_holder; + DBUG_ENTER("spider_fields::add_conn"); + DBUG_PRINT("info",("spider this=%p", this)); + if (!first_conn_holder) + { + conn_holder = create_conn_holder(); + DBUG_PRINT("info",("spider conn_holder=%p", conn_holder)); + if (!conn_holder) + DBUG_RETURN(NULL); + conn_holder->conn = conn_arg; + conn_holder->access_balance = access_balance; + first_conn_holder = conn_holder; + last_conn_holder = conn_holder; + conn_arg->conn_holder_for_direct_join = conn_holder; + add_dbton_id(conn_arg->dbton_id); + } else { + conn_holder = first_conn_holder; + do { + if (conn_holder->conn == conn_arg) + break; + } while ((conn_holder = conn_holder->next)); + if (!conn_holder) + { + conn_holder = create_conn_holder(); + DBUG_PRINT("info",("spider conn_holder=%p", conn_holder)); + if (!conn_holder) + DBUG_RETURN(NULL); + conn_holder->conn = conn_arg; + conn_holder->access_balance = access_balance; + conn_holder->prev = last_conn_holder; + last_conn_holder->next = conn_holder; + last_conn_holder = conn_holder; + conn_arg->conn_holder_for_direct_join = conn_holder; + add_dbton_id(conn_arg->dbton_id); + } + } + DBUG_RETURN(conn_holder); +} + +SPIDER_CONN_HOLDER *spider_fields::create_conn_holder( +) { + SPIDER_CONN_HOLDER *return_conn_holder; + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder; + DBUG_ENTER("spider_fields::create_conn_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + return_conn_holder = (SPIDER_CONN_HOLDER *) + spider_bulk_malloc(spider_current_trx, 252, MYF(MY_WME | MY_ZEROFILL), + &return_conn_holder, (uint) (sizeof(SPIDER_CONN_HOLDER)), + &table_link_idx_holder, + (uint) (table_count * sizeof(SPIDER_TABLE_LINK_IDX_HOLDER)), + NullS + ); + if (!return_conn_holder) + DBUG_RETURN(NULL); + DBUG_PRINT("info",("spider table_count=%u", table_count)); + DBUG_PRINT("info",("spider table_link_idx_holder=%p", table_link_idx_holder)); + return_conn_holder->table_link_idx_holder = table_link_idx_holder; + DBUG_RETURN(return_conn_holder); +} + +void spider_fields::set_pos_to_first_conn_holder( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_conn_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + current_conn_holder = first_conn_holder; + DBUG_VOID_RETURN; +} + +SPIDER_CONN_HOLDER *spider_fields::get_next_conn_holder( +) { + SPIDER_CONN_HOLDER *return_conn_holder = current_conn_holder; + DBUG_ENTER("spider_fields::get_next_conn_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_conn_holder) + current_conn_holder = current_conn_holder->next; + DBUG_RETURN(return_conn_holder); +} + +bool spider_fields::has_conn_holder( +) { + DBUG_ENTER("spider_fields::has_conn_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(first_conn_holder); +} + +void spider_fields::clear_conn_holder_from_conn( +) { + DBUG_ENTER("spider_fields::clear_conn_checked_for_same_conn"); + DBUG_PRINT("info",("spider this=%p", this)); + for (current_conn_holder = first_conn_holder; current_conn_holder; + current_conn_holder = current_conn_holder->next) + { + current_conn_holder->checked_for_same_conn = FALSE; + } + DBUG_VOID_RETURN; +} + +bool spider_fields::check_conn_same_conn( + SPIDER_CONN *conn_arg +) { + DBUG_ENTER("spider_fields::check_conn_same_conn"); + DBUG_PRINT("info",("spider this=%p", this)); + for (current_conn_holder = first_conn_holder; current_conn_holder; + current_conn_holder = current_conn_holder->next) + { + if (current_conn_holder->conn == conn_arg) + { + current_conn_holder->checked_for_same_conn = TRUE; + DBUG_RETURN(TRUE); + } + } + DBUG_RETURN(FALSE); +} + +bool spider_fields::remove_conn_if_not_checked( +) { + SPIDER_CONN_HOLDER *conn_holder; + bool removed = FALSE; + DBUG_ENTER("spider_fields::remove_conn_if_not_checked"); + DBUG_PRINT("info",("spider this=%p", this)); + current_conn_holder = first_conn_holder; + while (current_conn_holder) + { + if (!current_conn_holder->checked_for_same_conn) + { + removed = TRUE; + DBUG_PRINT("info",("spider remove connection %p", + current_conn_holder->conn)); + if (!current_conn_holder->prev) + { + first_conn_holder = current_conn_holder->next; + if (current_conn_holder->next) + { + current_conn_holder->next->prev = NULL; + } else { + last_conn_holder = NULL; + } + } else { + current_conn_holder->prev->next = current_conn_holder->next; + if (current_conn_holder->next) + { + current_conn_holder->next->prev = current_conn_holder->prev; + } else { + last_conn_holder = current_conn_holder->prev; + last_conn_holder->next = NULL; + } + } + conn_holder = current_conn_holder->next; + free_conn_holder(current_conn_holder); + current_conn_holder = conn_holder; + } else { + current_conn_holder = current_conn_holder->next; + } + } + DBUG_RETURN(removed); +} + +void spider_fields::check_support_dbton( + uchar *dbton_bitmap +) { + SPIDER_CONN_HOLDER *conn_holder; + DBUG_ENTER("spider_fields::check_support_dbton"); + DBUG_PRINT("info",("spider this=%p", this)); + current_conn_holder = first_conn_holder; + while (current_conn_holder) + { + if (!spider_bit_is_set(dbton_bitmap, current_conn_holder->conn->dbton_id)) + { + DBUG_PRINT("info",("spider remove connection %p", + current_conn_holder->conn)); + if (!current_conn_holder->prev) + { + first_conn_holder = current_conn_holder->next; + if (current_conn_holder->next) + { + current_conn_holder->next->prev = NULL; + } else { + last_conn_holder = NULL; + } + } else { + current_conn_holder->prev->next = current_conn_holder->next; + if (current_conn_holder->next) + { + current_conn_holder->next->prev = current_conn_holder->prev; + } else { + last_conn_holder = current_conn_holder->prev; + last_conn_holder->next = NULL; + } + } + conn_holder = current_conn_holder->next; + free_conn_holder(current_conn_holder); + current_conn_holder = conn_holder; + } else { + current_conn_holder = current_conn_holder->next; + } + } + DBUG_VOID_RETURN; +} + +void spider_fields::choose_a_conn( +) { + SPIDER_CONN_HOLDER *conn_holder; + longlong balance_total = 0, balance_val; + double rand_val; + THD *thd = table_holder[0].spider->wide_handler->trx->thd; + DBUG_ENTER("spider_fields::choose_a_conn"); + DBUG_PRINT("info",("spider this=%p", this)); + for (current_conn_holder = first_conn_holder; current_conn_holder; + current_conn_holder = current_conn_holder->next) + { + balance_total += current_conn_holder->access_balance; + } + + rand_val = spider_rand(thd->variables.server_id + thd_get_thread_id(thd)); + balance_val = (longlong) (rand_val * balance_total); + + current_conn_holder = first_conn_holder; + while (current_conn_holder) + { + if (balance_val < current_conn_holder->access_balance) + break; + balance_val -= current_conn_holder->access_balance; + + DBUG_PRINT("info",("spider remove connection %p", + current_conn_holder->conn)); + first_conn_holder = current_conn_holder->next; + DBUG_ASSERT(current_conn_holder->next); + first_conn_holder->prev = NULL; + free_conn_holder(current_conn_holder); + current_conn_holder = first_conn_holder; + } + + DBUG_PRINT("info",("spider chosen connection is %p", + current_conn_holder->conn)); + last_conn_holder = current_conn_holder; + current_conn_holder = current_conn_holder->next; + last_conn_holder->next = NULL; + + while (current_conn_holder) + { + DBUG_PRINT("info",("spider remove connection %p", + current_conn_holder->conn)); + conn_holder = current_conn_holder->next; + free_conn_holder(current_conn_holder); + current_conn_holder = conn_holder; + } + DBUG_VOID_RETURN; +} + +void spider_fields::free_conn_holder( + SPIDER_CONN_HOLDER *conn_holder_arg +) { + uint roop_count; + DBUG_ENTER("spider_fields::free_conn_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + for (roop_count = 0; roop_count < table_count; ++roop_count) + { + if (conn_holder_arg->table_link_idx_holder[roop_count].first_link_idx_holder) + { + SPIDER_LINK_IDX_HOLDER *first_link_idx_holder, *current_link_idx_holder; + first_link_idx_holder = + conn_holder_arg->table_link_idx_holder[roop_count].first_link_idx_holder; + while ((current_link_idx_holder = first_link_idx_holder)) + { + first_link_idx_holder = current_link_idx_holder->next; + spider_free(spider_current_trx, current_link_idx_holder, MYF(0)); + } + } + } + if (conn_holder_arg->conn) + conn_holder_arg->conn->conn_holder_for_direct_join = NULL; + DBUG_PRINT("info",("spider free conn_holder=%p", conn_holder_arg)); + spider_free(spider_current_trx, conn_holder_arg, MYF(0)); + DBUG_VOID_RETURN; +} + +SPIDER_TABLE_HOLDER *spider_fields::add_table( + ha_spider *spider_arg +) { + spider_string *str; + uint length; + char tmp_buf[SPIDER_SQL_INT_LEN + 2]; + SPIDER_TABLE_HOLDER *return_table_holder; + SPIDER_FIELD_HOLDER *field_holder; + TABLE *table = spider_arg->get_table(); + Field *field; + DBUG_ENTER("spider_fields::add_table"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider table_count=%u", table_count)); + DBUG_PRINT("info",("spider idx_for_direct_join=%u", + spider_arg->idx_for_direct_join)); + length = my_sprintf(tmp_buf, (tmp_buf, "t%u", + spider_arg->idx_for_direct_join)); + str = &spider_arg->result_list.tmp_sqls[0]; + str->length(0); + if (str->reserve(length + SPIDER_SQL_DOT_LEN)) + { + DBUG_RETURN(NULL); + } + str->q_append(tmp_buf, length); + str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); + + return_table_holder = &table_holder[spider_arg->idx_for_direct_join]; + return_table_holder->table = spider_arg->get_table(); + return_table_holder->spider = spider_arg; + return_table_holder->alias = str; + + set_pos_to_first_field_holder(); + while ((field_holder = get_next_field_holder())) + { + if (!field_holder->spider) + { + field = field_holder->field; + if ( + field->field_index < table->s->fields && + field == table->field[field->field_index] + ) { + field_holder->spider = spider_arg; + field_holder->alias = str; + } + } + } + DBUG_RETURN(return_table_holder); +} + +/** + Verify that all fields in the query are members of tables that are in the + query. + + @return TRUE All fields in the query are members of tables + that are in the query. + FALSE At least one field in the query is not a + member of a table that is in the query. +*/ + +bool spider_fields::all_query_fields_are_query_table_members() +{ + SPIDER_FIELD_HOLDER *field_holder; + DBUG_ENTER("spider_fields::all_query_fields_are_query_table_members"); + DBUG_PRINT("info",("spider this=%p", this)); + + set_pos_to_first_field_holder(); + while ((field_holder = get_next_field_holder())) + { + if (!field_holder->spider) + { + DBUG_PRINT("info", ("spider field is not a member of a query table")); + DBUG_RETURN(FALSE); + } + } + + DBUG_RETURN(TRUE); +} + +int spider_fields::create_table_holder( + uint table_count_arg +) { + DBUG_ENTER("spider_fields::create_table_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(!table_holder); + table_holder = (SPIDER_TABLE_HOLDER *) + spider_malloc(spider_current_trx, 249, + table_count_arg * sizeof(SPIDER_TABLE_HOLDER), + MYF(MY_WME | MY_ZEROFILL)); + if (!table_holder) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + table_count = table_count_arg; + current_table_num = 0; + DBUG_RETURN(0); +} + +void spider_fields::set_pos_to_first_table_holder( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_table_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + current_table_num = 0; + DBUG_VOID_RETURN; +} + +SPIDER_TABLE_HOLDER *spider_fields::get_next_table_holder( +) { + SPIDER_TABLE_HOLDER *return_table_holder; + DBUG_ENTER("spider_fields::get_next_table_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_table_num >= table_count) + DBUG_RETURN(NULL); + return_table_holder = &table_holder[current_table_num]; + ++current_table_num; + DBUG_RETURN(return_table_holder); +} + +SPIDER_TABLE_HOLDER *spider_fields::get_table_holder(TABLE *table) +{ + uint table_num; + DBUG_ENTER("spider_fields::get_table_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + for (table_num = 0; table_num < table_count; ++table_num) + { + if (table_holder[table_num].table == table) + DBUG_RETURN(&table_holder[table_num]); + } + DBUG_RETURN(NULL); +} + +uint spider_fields::get_table_count() +{ + DBUG_ENTER("spider_fields::get_table_count"); + DBUG_RETURN(table_count); +} + +int spider_fields::add_field( + Field *field_arg +) { + SPIDER_FIELD_HOLDER *field_holder; + SPIDER_FIELD_CHAIN *field_chain; + DBUG_ENTER("spider_fields::add_field"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider field=%p", field_arg)); + if (!first_field_holder) + { + field_holder = create_field_holder(); + DBUG_PRINT("info",("spider field_holder=%p", field_holder)); + if (!field_holder) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + field_holder->field = field_arg; + first_field_holder = field_holder; + last_field_holder = field_holder; + } else { + field_holder = first_field_holder; + do { + if (field_holder->field == field_arg) + break; + } while ((field_holder = field_holder->next)); + if (!field_holder) + { + field_holder = create_field_holder(); + DBUG_PRINT("info",("spider field_holder=%p", field_holder)); + if (!field_holder) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + field_holder->field = field_arg; + last_field_holder->next = field_holder; + last_field_holder = field_holder; + } + } + field_chain = create_field_chain(); + DBUG_PRINT("info",("spider field_chain=%p", field_chain)); + if (!field_chain) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + field_chain->field_holder = field_holder; + if (!first_field_chain) + { + first_field_chain = field_chain; + last_field_chain = field_chain; + } else { + last_field_chain->next = field_chain; + last_field_chain = field_chain; + } + DBUG_RETURN(0); +} + +SPIDER_FIELD_HOLDER *spider_fields::create_field_holder( +) { + DBUG_ENTER("spider_fields::create_field_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_FIELD_HOLDER *) + spider_malloc(spider_current_trx, 250, sizeof(SPIDER_FIELD_HOLDER), + MYF(MY_WME | MY_ZEROFILL))); +} + +void spider_fields::set_pos_to_first_field_holder( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_field_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + current_field_holder = first_field_holder; + DBUG_VOID_RETURN; +} + +SPIDER_FIELD_HOLDER *spider_fields::get_next_field_holder( +) { + SPIDER_FIELD_HOLDER *return_field_holder = current_field_holder; + DBUG_ENTER("spider_fields::get_next_field_holder"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_field_holder) + current_field_holder = current_field_holder->next; + DBUG_RETURN(return_field_holder); +} + +SPIDER_FIELD_CHAIN *spider_fields::create_field_chain( +) { + DBUG_ENTER("spider_fields::create_field_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN((SPIDER_FIELD_CHAIN *) + spider_malloc(spider_current_trx, 251, sizeof(SPIDER_FIELD_CHAIN), + MYF(MY_WME | MY_ZEROFILL))); +} + +void spider_fields::set_pos_to_first_field_chain( +) { + DBUG_ENTER("spider_fields::set_pos_to_first_field_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + current_field_chain = first_field_chain; + DBUG_VOID_RETURN; +} + +SPIDER_FIELD_CHAIN *spider_fields::get_next_field_chain( +) { + SPIDER_FIELD_CHAIN *return_field_chain = current_field_chain; + DBUG_ENTER("spider_fields::get_next_field_chain"); + DBUG_PRINT("info",("spider this=%p", this)); + if (current_field_chain) + current_field_chain = current_field_chain->next; + DBUG_RETURN(return_field_chain); +} + +void spider_fields::set_field_ptr( + Field **field_arg +) { + DBUG_ENTER("spider_fields::set_field_ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_PRINT("info",("spider field_ptr=%p", field_arg)); + first_field_ptr = field_arg; + current_field_ptr = field_arg; + DBUG_VOID_RETURN; +} + +Field **spider_fields::get_next_field_ptr( +) { + Field **return_field_ptr = current_field_ptr; + DBUG_ENTER("spider_fields::get_next_field_ptr"); + DBUG_PRINT("info",("spider this=%p", this)); + if (*current_field_ptr) + current_field_ptr++; + DBUG_PRINT("info",("spider field_ptr=%p", return_field_ptr)); + DBUG_RETURN(return_field_ptr); +} + +int spider_fields::ping_table_mon_from_table( + SPIDER_LINK_IDX_CHAIN *link_idx_chain +) { + int error_num = 0, error_num_buf; + ha_spider *tmp_spider; + SPIDER_SHARE *tmp_share; + int tmp_link_idx; + SPIDER_TABLE_HOLDER *table_holder; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + DBUG_ENTER("spider_fields::ping_table_mon_from_table"); + set_pos_to_first_table_on_link_idx_chain(link_idx_chain); + set_pos_to_first_table_holder(); + while ((table_holder = get_next_table_holder())) + { + link_idx_holder = get_next_table_on_link_idx_chain(link_idx_chain); + tmp_spider = table_holder->spider; + tmp_link_idx = link_idx_holder->link_idx; + tmp_share = tmp_spider->share; + if (tmp_share->monitoring_kind[tmp_link_idx]) + { + error_num_buf = spider_ping_table_mon_from_table( + tmp_spider->wide_handler->trx, + tmp_spider->wide_handler->trx->thd, + tmp_share, + tmp_link_idx, + (uint32) tmp_share->monitoring_sid[tmp_link_idx], + tmp_share->table_name, + tmp_share->table_name_length, + tmp_spider->conn_link_idx[tmp_link_idx], + NULL, + 0, + tmp_share->monitoring_kind[tmp_link_idx], + tmp_share->monitoring_limit[tmp_link_idx], + tmp_share->monitoring_flag[tmp_link_idx], + TRUE + ); + if (!error_num) + error_num = error_num_buf; + } + } + DBUG_RETURN(error_num); +} + +spider_group_by_handler::spider_group_by_handler( + THD *thd_arg, + Query *query_arg, + spider_fields *fields_arg +) : group_by_handler(thd_arg, spider_hton_ptr), + query(*query_arg), fields(fields_arg) +{ + DBUG_ENTER("spider_group_by_handler::spider_group_by_handler"); + fields->set_pos_to_first_table_holder(); + SPIDER_TABLE_HOLDER *table_holder = fields->get_next_table_holder(); + spider = table_holder->spider; + trx = spider->wide_handler->trx; + DBUG_VOID_RETURN; +} + +spider_group_by_handler::~spider_group_by_handler() +{ + DBUG_ENTER("spider_group_by_handler::~spider_group_by_handler"); + delete fields; + DBUG_VOID_RETURN; +} + +int spider_group_by_handler::init_scan() +{ + int error_num, link_idx; + uint dbton_id; + spider_db_handler *dbton_hdl; + st_select_lex *select_lex; + longlong select_limit; + longlong direct_order_limit; + SPIDER_SHARE *share = spider->share; + SPIDER_CONN *conn; + SPIDER_RESULT_LIST *result_list = &spider->result_list; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + DBUG_ENTER("spider_group_by_handler::init_scan"); + store_error = 0; +#ifndef DBUG_OFF + Field **field; + for ( + field = table->field; + *field; + field++ + ) { + DBUG_PRINT("info",("spider field_name=%s", + SPIDER_field_name_str(*field))); + } +#endif + + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + + spider->use_fields = TRUE; + spider->fields = fields; + + spider->check_pre_call(TRUE); + + spider->pushed_pos = NULL; + result_list->sorted = (query.group_by || query.order_by); + spider_set_result_list_param(spider); + spider->mrr_with_cnt = FALSE; + spider->init_index_handler = FALSE; + spider->use_spatial_index = FALSE; + result_list->check_direct_order_limit = FALSE; + /* Disable direct aggregate when GBH is on (MDEV-29502). */ + result_list->direct_aggregate = FALSE; + spider->select_column_mode = 0; + spider->search_link_idx = fields->get_ok_link_idx(); + spider->result_link_idx = spider->search_link_idx; + + spider_db_free_one_result_for_start_next(spider); + + spider->do_direct_update = FALSE; + spider->direct_update_kinds = 0; + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + direct_order_limit = spider_param_direct_order_limit(thd, + share->direct_order_limit); + if ( + direct_order_limit && + select_lex->limit_params.explicit_limit && + !(select_lex->options & OPTION_FOUND_ROWS) && + select_limit < direct_order_limit /* - offset_limit */ + ) { + result_list->internal_limit = select_limit /* + offset_limit */; + result_list->split_read = select_limit /* + offset_limit */; + result_list->bgs_split_read = select_limit /* + offset_limit */; + + result_list->split_read_base = 9223372036854775807LL; + result_list->semi_split_read = 0; + result_list->semi_split_read_limit = 9223372036854775807LL; + result_list->first_read = 9223372036854775807LL; + result_list->second_read = 9223372036854775807LL; + trx->direct_order_limit_count++; + } + result_list->semi_split_read_base = 0; + result_list->set_split_read = TRUE; + if ((error_num = spider_set_conn_bg_param(spider))) + DBUG_RETURN(error_num); + DBUG_PRINT("info",("spider result_list.finish_flg = FALSE")); + result_list->finish_flg = FALSE; + result_list->record_num = 0; + result_list->keyread = FALSE; + result_list->desc_flg = FALSE; + result_list->sorted = FALSE; + result_list->key_info = NULL; + 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 (select_lex->limit_params.explicit_limit) + { + result_list->internal_offset += offset_limit; + } else { + offset_limit = 0; + } + + /* making a query */ + fields->set_pos_to_first_dbton_id(); + while ((dbton_id = fields->get_next_dbton_id()) < SPIDER_DBTON_SIZE) + { + dbton_hdl = spider->dbton_handler[dbton_id]; + result_list->direct_distinct = query.distinct; + fields->set_pos_to_first_field_chain(); + if ((error_num = dbton_hdl->reset_sql(SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = dbton_hdl->append_select_part(SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + fields->set_field_ptr(table->field); + if ((error_num = dbton_hdl->append_list_item_select_part( + query.select, NULL, 0, TRUE, fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = dbton_hdl->append_from_and_tables_part( + fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if (query.where) + { + if ((error_num = + dbton_hdl->append_where_part(SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = dbton_hdl->append_item_type_part( + query.where, NULL, 0, TRUE, fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + if (query.group_by) + { + if ((error_num = dbton_hdl->append_group_by_part( + query.group_by, NULL, 0, TRUE, fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + if (query.having) + { + if ((error_num = + dbton_hdl->append_having_part(SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = dbton_hdl->append_item_type_part( + query.having, NULL, 0, TRUE, fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + if (query.order_by) + { + if ((error_num = dbton_hdl->append_order_by_part( + query.order_by, NULL, 0, TRUE, fields, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + if ((error_num = dbton_hdl->append_limit_part(result_list->internal_offset, + result_list->limit_num, SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + if ((error_num = dbton_hdl->append_select_lock_part( + SPIDER_SQL_TYPE_SELECT_SQL))) + { + DBUG_RETURN(error_num); + } + } + + fields->set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = fields->get_next_link_idx_chain())) + { + conn = link_idx_chain->conn; + link_idx_holder = link_idx_chain->link_idx_holder; + link_idx = link_idx_holder->link_idx; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + spider->link_idx_chain = link_idx_chain; + if (result_list->bgs_phase > 0) + { + if ((error_num = spider_check_and_init_casual_read(trx->thd, spider, + link_idx))) + DBUG_RETURN(error_num); + if ((error_num = spider_bg_conn_search(spider, link_idx, + dbton_hdl->first_link_idx, TRUE, FALSE, + !fields->is_first_link_ok_chain(link_idx_chain)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + store_error = HA_ERR_END_OF_FILE; + error_num = 0; + } + DBUG_RETURN(error_num); + } + } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + if ((error_num = + dbton_hdl->set_sql_for_exec(SPIDER_SQL_TYPE_SELECT_SQL, link_idx, + link_idx_chain))) + { + 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]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + 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))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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 ( + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + store_error = HA_ERR_END_OF_FILE; + error_num = 0; + } + DBUG_RETURN(error_num); + } + spider_conn_set_timeout_from_share(conn, link_idx, + trx->thd, share); + if (dbton_hdl->execute_sql( + SPIDER_SQL_TYPE_SELECT_SQL, + conn, + spider->result_list.quick_mode, + &spider->need_mons[link_idx]) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + error_num = spider_db_errorno(conn); + if ( + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + store_error = HA_ERR_END_OF_FILE; + error_num = 0; + } + DBUG_RETURN(error_num); + } + spider->connection_ids[link_idx] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; + if (fields->is_first_link_ok_chain(link_idx_chain)) + { + if ((error_num = spider_db_store_result(spider, link_idx, table))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + store_error = HA_ERR_END_OF_FILE; + error_num = 0; + } + DBUG_RETURN(error_num); + } + spider->result_link_idx = link_idx; + spider->result_link_idx_chain = link_idx_chain; + } else { + spider_db_discard_result(spider, link_idx, conn); + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } + } + } + + first = TRUE; + DBUG_RETURN(0); +} + +int spider_group_by_handler::next_row() +{ + int error_num, link_idx; + spider_db_handler *dbton_hdl; + SPIDER_CONN *conn; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_LINK_IDX_HOLDER *link_idx_holder; + DBUG_ENTER("spider_group_by_handler::next_row"); + if (trx->thd->killed) + { + my_error(ER_QUERY_INTERRUPTED, MYF(0)); + DBUG_RETURN(ER_QUERY_INTERRUPTED); + } + if (store_error) + { + if (store_error == HA_ERR_END_OF_FILE) + { + table->status = STATUS_NOT_FOUND; + } + DBUG_RETURN(store_error); + } + if (first) + { + first = FALSE; + if (spider->use_pre_call) + { + if (spider->store_error_num) + { + if (spider->store_error_num == HA_ERR_END_OF_FILE) + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(spider->store_error_num); + } + if (spider->result_list.bgs_phase > 0) + { + fields->set_pos_to_first_link_idx_chain(); + while ((link_idx_chain = fields->get_next_link_idx_chain())) + { + conn = link_idx_chain->conn; + link_idx_holder = link_idx_chain->link_idx_holder; + link_idx = link_idx_holder->link_idx; + dbton_hdl = spider->dbton_handler[conn->dbton_id]; + spider->link_idx_chain = link_idx_chain; + if ((error_num = spider_bg_conn_search(spider, link_idx, + dbton_hdl->first_link_idx, TRUE, TRUE, + !fields->is_first_link_ok_chain(link_idx_chain)))) + { + if ( + error_num != HA_ERR_END_OF_FILE && + spider->need_mons[link_idx] + ) { + error_num = fields->ping_table_mon_from_table(link_idx_chain); + } + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + table->status = STATUS_NOT_FOUND; + } + DBUG_RETURN(error_num); + } + } + } + spider->use_pre_call = FALSE; + } + } else if (offset_limit) + { + --offset_limit; + DBUG_RETURN(0); + } + if ((error_num = spider_db_seek_next(table->record[0], spider, + spider->search_link_idx, table))) + { + if ((error_num = spider->check_error_mode_eof(error_num)) == HA_ERR_END_OF_FILE) + { + table->status = STATUS_NOT_FOUND; + } + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_group_by_handler::end_scan() +{ + DBUG_ENTER("spider_group_by_handler::end_scan"); + DBUG_RETURN(0); +} + +group_by_handler *spider_create_group_by_handler( + THD *thd, + Query *query +) { + spider_group_by_handler *group_by_handler; + Item *item; + TABLE_LIST *from; + SPIDER_CONN *conn; + ha_spider *spider; + SPIDER_SHARE *share; + int roop_count, lock_mode; + List_iterator_fast it(*query->select); + uchar dbton_bitmap[spider_bitmap_size(SPIDER_DBTON_SIZE)]; + uchar dbton_bitmap_tmp[spider_bitmap_size(SPIDER_DBTON_SIZE)]; + ORDER *order; + bool keep_going; + bool find_dbton = FALSE; + spider_fields *fields = NULL, *fields_arg = NULL; + uint table_idx, dbton_id; + long tgt_link_status; + DBUG_ENTER("spider_create_group_by_handler"); + + if (spider_param_disable_group_by_handler(thd)) + DBUG_RETURN(NULL); + + switch (thd_sql_command(thd)) + { + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + DBUG_PRINT("info",("spider update and delete does not support this feature")); + DBUG_RETURN(NULL); + default: + break; + } + + from = query->from; + do { + DBUG_PRINT("info",("spider from=%p", from)); + if (from->table->const_table) + continue; + if (from->table->part_info) + { + DBUG_PRINT("info",("spider partition handler")); + partition_info *part_info = from->table->part_info; + uint bits = bitmap_bits_set(&part_info->read_partitions); + DBUG_PRINT("info",("spider bits=%u", bits)); + if (bits != 1) + { + DBUG_PRINT("info",("spider using multiple partitions is not supported by this feature yet")); + DBUG_RETURN(NULL); + } + } + } while ((from = from->next_local)); + + table_idx = 0; + from = query->from; + while (from && from->table->const_table) + { + from = from->next_local; + } + if (!from) + { + /* all tables are const_table */ + DBUG_RETURN(NULL); + } + if (from->table->part_info) + { + partition_info *part_info = from->table->part_info; + uint part = bitmap_get_first_set(&part_info->read_partitions); + ha_partition *partition = (ha_partition *) from->table->file; + handler **handlers = partition->get_child_handlers(); + spider = (ha_spider *) handlers[part]; + } else { + spider = (ha_spider *) from->table->file; + } + share = spider->share; + spider->idx_for_direct_join = table_idx; + ++table_idx; + memset(dbton_bitmap, 0, spider_bitmap_size(SPIDER_DBTON_SIZE)); + for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + if ( + spider_dbton[dbton_id].support_direct_join && + spider_dbton[dbton_id].support_direct_join() + ) { + spider_set_bit(dbton_bitmap, dbton_id); + } + } + while ((from = from->next_local)) + { + if (from->table->const_table) + continue; + if (from->table->part_info) + { + partition_info *part_info = from->table->part_info; + uint part = bitmap_get_first_set(&part_info->read_partitions); + ha_partition *partition = (ha_partition *) from->table->file; + handler **handlers = partition->get_child_handlers(); + spider = (ha_spider *) handlers[part]; + } else { + spider = (ha_spider *) from->table->file; + } + share = spider->share; + spider->idx_for_direct_join = table_idx; + ++table_idx; + memset(dbton_bitmap_tmp, 0, spider_bitmap_size(SPIDER_DBTON_SIZE)); + for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + if ( + spider_dbton[dbton_id].support_direct_join && + spider_dbton[dbton_id].support_direct_join() + ) { + spider_set_bit(dbton_bitmap_tmp, dbton_id); + } + } + for (roop_count = 0; + roop_count < spider_bitmap_size(SPIDER_DBTON_SIZE); ++roop_count) + { + dbton_bitmap[roop_count] &= dbton_bitmap_tmp[roop_count]; + } + } + + from = query->from; + do { + if (from->table->const_table) + continue; + if (from->table->part_info) + { + partition_info *part_info = from->table->part_info; + uint part = bitmap_get_first_set(&part_info->read_partitions); + ha_partition *partition = (ha_partition *) from->table->file; + handler **handlers = partition->get_child_handlers(); + spider = (ha_spider *) handlers[part]; + } else { + spider = (ha_spider *) from->table->file; + } + share = spider->share; + if (spider_param_skip_default_condition(thd, + share->skip_default_condition)) + { + /* find skip_default_condition = 1 */ + break; + } + } while ((from = from->next_local)); + + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; ++roop_count) + { + if (spider_bit_is_set(dbton_bitmap, roop_count)) + { + if (!fields) + { + fields_arg = new spider_fields(); + if (!fields_arg) + { + DBUG_RETURN(NULL); + } + } + keep_going = TRUE; + it.init(*query->select); + while ((item = it++)) + { + DBUG_PRINT("info",("spider select item=%p", item)); + if (item->const_item()) + { + DBUG_PRINT("info",("spider const item")); + continue; + } + if (spider_db_print_item_type(item, NULL, spider, NULL, NULL, 0, + roop_count, TRUE, fields_arg)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create select", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + break; + } + } + if (keep_going) + { + if (spider_dbton[roop_count].db_util->append_from_and_tables( + spider, fields_arg, NULL, query->from, table_idx)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create from", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + } + } + if (keep_going) + { + DBUG_PRINT("info",("spider query->where=%p", query->where)); + if (query->where) + { + if (spider_db_print_item_type(query->where, NULL, spider, NULL, NULL, 0, + roop_count, TRUE, fields_arg)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create where", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + } + } + } + if (keep_going) + { + DBUG_PRINT("info",("spider query->group_by=%p", query->group_by)); + if (query->group_by) + { + for (order = query->group_by; order; order = order->next) + { + if (spider_db_print_item_type((*order->item), NULL, spider, NULL, NULL, 0, + roop_count, TRUE, fields_arg)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create group by", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + break; + } + } + } + } + if (keep_going) + { + DBUG_PRINT("info",("spider query->order_by=%p", query->order_by)); + if (query->order_by) + { + for (order = query->order_by; order; order = order->next) + { + if ((*order->item)->type() == Item::SUM_FUNC_ITEM) + continue; + if (spider_db_print_item_type((*order->item), NULL, spider, NULL, NULL, 0, + roop_count, TRUE, fields_arg)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create order by", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + break; + } + } + } + } + if (keep_going) + { + DBUG_PRINT("info",("spider query->having=%p", query->having)); + if (query->having) + { + if (spider_db_print_item_type(query->having, NULL, spider, NULL, NULL, 0, + roop_count, TRUE, fields_arg)) + { + DBUG_PRINT("info",("spider dbton_id=%d can't create having", roop_count)); + spider_clear_bit(dbton_bitmap, roop_count); + keep_going = FALSE; + } + } + } + if (keep_going) + { + find_dbton = TRUE; + fields = fields_arg; + fields_arg = NULL; + } else { + delete fields_arg; + } + } + } + if (!find_dbton) + { + DBUG_RETURN(NULL); + } + + if (fields->create_table_holder(table_idx)) + { + delete fields; + DBUG_RETURN(NULL); + } + + from = query->from; + while (from->table->const_table) + { + from = from->next_local; + } + if (from->table->part_info) + { + partition_info *part_info = from->table->part_info; + uint part = bitmap_get_first_set(&part_info->read_partitions); + ha_partition *partition = (ha_partition *) from->table->file; + handler **handlers = partition->get_child_handlers(); + spider = (ha_spider *) handlers[part]; + } else { + spider = (ha_spider *) from->table->file; + } + share = spider->share; + lock_mode = spider_conn_lock_mode(spider); + if (lock_mode) + { + tgt_link_status = SPIDER_LINK_STATUS_RECOVERY; + } else { + tgt_link_status = SPIDER_LINK_STATUS_OK; + } + DBUG_PRINT("info",("spider s->db=%s", from->table->s->db.str)); + DBUG_PRINT("info",("spider s->table_name=%s", from->table->s->table_name.str)); + if (!fields->add_table(spider)) + { + DBUG_PRINT("info",("spider can not add a table")); + delete fields; + DBUG_RETURN(NULL); + } + if (spider->dml_init()) + { + DBUG_PRINT("info",("spider can not init for dml")); + delete fields; + DBUG_RETURN(NULL); + } + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + tgt_link_status); + 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, + tgt_link_status) + ) { + conn = spider->conns[roop_count]; + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_ASSERT(conn); + if (conn->table_lock) + { + DBUG_PRINT("info",("spider direct_join does not support with lock tables yet")); + if (lock_mode) + { + delete fields; + DBUG_RETURN(NULL); + } + continue; + } + if (!fields->add_conn(conn, + share->access_balances[spider->conn_link_idx[roop_count]])) + { + DBUG_PRINT("info",("spider can not create conn_holder")); + delete fields; + DBUG_RETURN(NULL); + } + if (fields->add_link_idx(conn->conn_holder_for_direct_join, spider, roop_count)) + { + DBUG_PRINT("info",("spider can not create link_idx_holder")); + delete fields; + DBUG_RETURN(NULL); + } + } + if (!fields->has_conn_holder()) + { + delete fields; + DBUG_RETURN(NULL); + } + + while ((from = from->next_local)) + { + if (from->table->const_table) + continue; + fields->clear_conn_holder_from_conn(); + + if (from->table->part_info) + { + partition_info *part_info = from->table->part_info; + uint part = bitmap_get_first_set(&part_info->read_partitions); + ha_partition *partition = (ha_partition *) from->table->file; + handler **handlers = partition->get_child_handlers(); + spider = (ha_spider *) handlers[part]; + } else { + spider = (ha_spider *) from->table->file; + } + share = spider->share; + if (!fields->add_table(spider)) + { + DBUG_PRINT("info",("spider can not add a table")); + delete fields; + DBUG_RETURN(NULL); + } + DBUG_PRINT("info",("spider s->db=%s", from->table->s->db.str)); + DBUG_PRINT("info",("spider s->table_name=%s", from->table->s->table_name.str)); + if (spider->dml_init()) + { + DBUG_PRINT("info",("spider can not init for dml")); + delete fields; + DBUG_RETURN(NULL); + } + for ( + roop_count = spider_conn_link_idx_next(share->link_statuses, + spider->conn_link_idx, -1, share->link_count, + tgt_link_status); + 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, + tgt_link_status) + ) { + DBUG_PRINT("info",("spider roop_count=%d", roop_count)); + conn = spider->conns[roop_count]; + DBUG_PRINT("info",("spider conn=%p", conn)); + if (!fields->check_conn_same_conn(conn)) + { + DBUG_PRINT("info",("spider connection %p can not be used for this query with locking", + conn)); + if (lock_mode) + { + delete fields; + DBUG_RETURN(NULL); + } + continue; + } + if (fields->add_link_idx(conn->conn_holder_for_direct_join, spider, roop_count)) + { + DBUG_PRINT("info",("spider can not create link_idx_holder")); + delete fields; + DBUG_RETURN(NULL); + } + } + + if (fields->remove_conn_if_not_checked()) + { + if (lock_mode) + { + DBUG_PRINT("info",("spider some connections can not be used for this query with locking")); + delete fields; + DBUG_RETURN(NULL); + } + } + if (!fields->has_conn_holder()) + { + delete fields; + DBUG_RETURN(NULL); + } + } + + if (!fields->all_query_fields_are_query_table_members()) + { + DBUG_PRINT("info", ("spider found a query field that is not a query table member")); + delete fields; + DBUG_RETURN(NULL); + } + + fields->check_support_dbton(dbton_bitmap); + if (!fields->has_conn_holder()) + { + DBUG_PRINT("info",("spider all chosen connections can't match dbton_id")); + delete fields; + DBUG_RETURN(NULL); + } + + /* choose a connection */ + if (!lock_mode) + { + fields->choose_a_conn(); + } + + if (fields->make_link_idx_chain(tgt_link_status)) + { + DBUG_PRINT("info",("spider can not create link_idx_chain")); + delete fields; + DBUG_RETURN(NULL); + } + + /* choose link_id */ + if (fields->check_link_ok_chain()) + { + DBUG_PRINT("info",("spider do not have link ok status")); + delete fields; + DBUG_RETURN(NULL); + } + + fields->set_first_link_idx(); + + if (!(group_by_handler = new spider_group_by_handler(thd, query, fields))) + { + DBUG_PRINT("info",("spider can't create group_by_handler")); + delete fields; + DBUG_RETURN(NULL); + } + query->distinct = FALSE; + query->where = NULL; + query->group_by = NULL; + query->having = NULL; + query->order_by = NULL; + DBUG_RETURN(group_by_handler); +} diff --git a/storage/spider/spd_group_by_handler.h b/storage/spider/spd_group_by_handler.h new file mode 100644 index 00000000..b8e85a3d --- /dev/null +++ b/storage/spider/spd_group_by_handler.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +class spider_group_by_handler: public group_by_handler +{ + Query query; + spider_fields *fields; + ha_spider *spider; + SPIDER_TRX *trx; + spider_db_result *result; + bool first; + longlong offset_limit; + int store_error; + +public: + spider_group_by_handler( + THD *thd_arg, + Query *query_arg, + spider_fields *fields_arg + ); + ~spider_group_by_handler(); + int init_scan(); + int next_row(); + int end_scan(); +}; + +group_by_handler *spider_create_group_by_handler( + THD *thd, + Query *query +); diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc new file mode 100644 index 00000000..7db95371 --- /dev/null +++ b/storage/spider/spd_i_s.cc @@ -0,0 +1,265 @@ +/* Copyright (C) 2012-2020 Kentoku Shiba + Copyright (C) 2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_show.h" +#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 }; + +namespace Show { +static ST_FIELD_INFO spider_i_s_alloc_mem_fields_info[] = +{ + Column("ID", ULong(10), NOT_NULL, "id"), + Column("FUNC_NAME", Varchar(64), NULLABLE, "func_name"), + Column("FILE_NAME", Varchar(64), NULLABLE, "file_name"), + Column("LINE_NO", ULong(10), NULLABLE, "line_no"), + Column("TOTAL_ALLOC_MEM", ULonglong(20), NULLABLE, "total_alloc_mem"), + Column("CURRENT_ALLOC_MEM", SLonglong(20), NULLABLE, "current_alloc_mem"), + Column("ALLOC_MEM_COUNT", ULonglong(20), NULLABLE, "alloc_mem_count"), + Column("FREE_MEM_COUNT", ULonglong(20), NULLABLE, "free_mem_count"), + CEnd() +}; +} // namespace Show + +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 = Show::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, + 0, +}; + +struct st_maria_plugin spider_i_s_alloc_mem_maria = +{ + 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, + 0x0100, + NULL, + NULL, + "1.0", + MariaDB_PLUGIN_MATURITY_STABLE, +}; + +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; + +namespace Show { +static ST_FIELD_INFO spider_i_s_wrapper_protocols_fields_info[] = +{ + Column("WRAPPER_NAME", Varchar(NAME_CHAR_LEN), NOT_NULL, ""), + Column("WRAPPER_VERSION", Varchar(20), NOT_NULL, ""), + Column("WRAPPER_DESCRIPTION", Longtext(65535), NULLABLE, ""), + Column("WRAPPER_MATURITY", Varchar(12), NOT_NULL, ""), + CEnd() +}; +} // namespace Show + +static int spider_i_s_wrapper_protocols_fill_table( + THD *thd, + TABLE_LIST *tables, + COND *cond +) { + uint roop_count; + SPIDER_DBTON *dbton; + TABLE *table = tables->table; + DBUG_ENTER("spider_i_s_wrapper_protocols_fill_table"); + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) + { + dbton = &spider_dbton[roop_count]; + if (!dbton->wrapper) + { + continue; + } + table->field[0]->store(dbton->wrapper, + strlen(dbton->wrapper), system_charset_info); + table->field[1]->store(dbton->version_info, + strlen(dbton->version_info), system_charset_info); + if (dbton->descr) + { + table->field[2]->set_notnull(); + table->field[2]->store(dbton->descr, + strlen(dbton->descr), system_charset_info); + } else { + table->field[2]->set_null(); + } + if (dbton->maturity <= SPIDER_MATURITY_STABLE) + { + table->field[3]->store(maturity_name[dbton->maturity].str, + maturity_name[dbton->maturity].length, system_charset_info); + } else { + table->field[3]->store(maturity_name[0].str, + maturity_name[0].length, system_charset_info); + } + if (schema_table_store_record(thd, table)) + { + DBUG_RETURN(1); + } + } + DBUG_RETURN(0); +} + +static int spider_i_s_wrapper_protocols_init( + void *p +) { + ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p; + DBUG_ENTER("spider_i_s_wrapper_protocols_init"); + schema->fields_info = Show::spider_i_s_wrapper_protocols_fields_info; + schema->fill_table = spider_i_s_wrapper_protocols_fill_table; + schema->idx_field1 = 0; + DBUG_RETURN(0); +} + +static int spider_i_s_wrapper_protocols_deinit( + void *p +) { + DBUG_ENTER("spider_i_s_wrapper_protocols_deinit"); + DBUG_RETURN(0); +} + +struct st_mysql_plugin spider_i_s_wrapper_protocols = +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &spider_i_s_info, + "SPIDER_WRAPPER_PROTOCOLS", + "Kentoku Shiba, MariaDB Corp", + "Available wrapper protocols of Spider", + PLUGIN_LICENSE_GPL, + spider_i_s_wrapper_protocols_init, + spider_i_s_wrapper_protocols_deinit, + 0x0001, + NULL, + NULL, + NULL, + 0, +}; + +struct st_maria_plugin spider_i_s_wrapper_protocols_maria = +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &spider_i_s_info, + "SPIDER_WRAPPER_PROTOCOLS", + "Kentoku Shiba, MariaDB Corp", + "Available wrapper protocols of Spider", + PLUGIN_LICENSE_GPL, + spider_i_s_wrapper_protocols_init, + spider_i_s_wrapper_protocols_deinit, + 0x0100, + NULL, + NULL, + "1.0", + MariaDB_PLUGIN_MATURITY_STABLE, +}; diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h new file mode 100644 index 00000000..4763cd89 --- /dev/null +++ b/storage/spider/spd_include.h @@ -0,0 +1,1265 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019-2022 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define SPIDER_DETAIL_VERSION PACKAGE_VERSION +#define SPIDER_HEX_VERSION (MYSQL_VERSION_MAJOR << 8 | MYSQL_VERSION_MINOR) + +#define spider_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 +#define pthread_mutex_assert_owner(A) mysql_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) mysql_mutex_assert_not_owner(A) +#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_timedwait +#undef pthread_cond_timedwait +#endif +#define pthread_cond_timedwait mysql_cond_timedwait +#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 + +#define spider_stmt_da_message(A) thd_get_error_message(A) +#define spider_stmt_da_sql_errno(A) thd_get_error_number(A) +#define spider_user_defined_key_parts(A) (A)->user_defined_key_parts +#define spider_join_table_count(A) (A)->table_count +#define SPIDER_CAN_BG_UPDATE (1LL << 39) +#define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD +#define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP +#define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE +#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE +#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG +#define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD +#define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN +#define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE +#define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION + +#define SPIDER_HAS_EXPLAIN_QUERY + +#define SPIDER_TEST(A) MY_TEST(A) + +#define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR +#define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON + +#define SPIDER_Item_args_arg_count_IS_PROTECTED + +#define SPIDER_Item_func_conv_charset_conv_charset collation.collation + +#define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT +#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H) +#define SPIDER_HAS_NEXT_THREAD_ID +#define SPIDER_new_THD(A) (new THD(A)) +#define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC) + +#define SPIDER_open_temporary_table + +#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G) + +#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F) +#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F) +#define SPIDER_free_part_syntax(A,B) + +#define SPIDER_read_record_read_record(A) read_record() +#define SPIDER_has_Item_with_subquery +#define SPIDER_use_LEX_CSTRING_for_Field_blob_constructor +#define SPIDER_use_LEX_CSTRING_for_database_tablename_alias +#define SPIDER_THD_db_str(A) (A)->db.str +#define SPIDER_THD_db_length(A) (A)->db.length +#define SPIDER_TABLE_LIST_db_str(A) (A)->db.str +#define SPIDER_TABLE_LIST_db_length(A) (A)->db.length +#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name.str +#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name.length +#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias.str +#define SPIDER_TABLE_LIST_alias_length(A) (A)->alias.length +#define SPIDER_field_name_str(A) (A)->field_name.str +#define SPIDER_field_name_length(A) (A)->field_name.length +#define SPIDER_item_name_str(A) (A)->name.str +#define SPIDER_item_name_length(A) (A)->name.length +const LEX_CSTRING SPIDER_empty_string = {"", 0}; + +#define SPIDER_date_mode_t(A) date_mode_t(A) +#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E) +#define SPIDER_get_linkage(A) A->get_linkage() + +typedef start_new_trans *SPIDER_Open_tables_backup; + +#define SPIDER_reset_n_backup_open_tables_state(A,B,C) do { \ + if (!(*(B) = new start_new_trans(A))) \ + { \ + DBUG_RETURN(C); \ + } \ +} while (0) +#define SPIDER_restore_backup_open_tables_state(A,B) do { \ + (*(B))->restore_old_transaction(); \ + delete *(B); \ +} while (0) +#define SPIDER_sys_close_thread_tables(A) (A)->commit_whole_transaction_and_close_tables() + +#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 23 +#define SPIDER_TMP_SHARE_UINT_COUNT SPIDER_TMP_SHARE_CHAR_PTR_COUNT +#define SPIDER_TMP_SHARE_LONG_COUNT 19 +#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3 + +#define SPIDER_MEM_CALC_LIST_NUM 314 +#define SPIDER_CONN_META_BUF_LEN 64 + +#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) \ + {DBUG_PRINT("info", ("spider thd=%p func_name=%s file_name=%s line_no=%lu", (A)->thd, (A)->func_name ? (A)->func_name : "NULL", (A)->file_name ? (A)->file_name : "NULL", (A)->line_no)); (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_table_mon_list SPIDER_TABLE_MON_LIST; +typedef struct st_spider_ip_port_conn SPIDER_IP_PORT_CONN; + +typedef struct st_spider_thread +{ + uint thread_idx; + THD *thd; + volatile bool killed; + volatile bool thd_wait; + volatile bool first_free_wait; + volatile int error; + pthread_t thread; + pthread_cond_t cond; + pthread_mutex_t mutex; + pthread_cond_t sync_cond; + volatile SPIDER_SHARE *queue_first; + volatile SPIDER_SHARE *queue_last; +} SPIDER_THREAD; + +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; + my_hash_value_type db_table_str_hash_value; +} 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; + my_hash_value_type table_name_hash_value; + 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; + char **tmp_tgt_dsns; + char **tmp_tgt_filedsns; + char **tmp_tgt_drivers; + char **tmp_static_link_ids; + long *tmp_tgt_ports; + long *tmp_tgt_ssl_vscs; + long *tmp_monitoring_binlog_pos_at_failing; + 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_tgt_dsns_lengths; + uint *tmp_tgt_filedsns_lengths; + uint *tmp_tgt_drivers_lengths; + uint *tmp_static_link_ids_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_tgt_dsns_charlen; + uint tmp_tgt_filedsns_charlen; + uint tmp_tgt_drivers_charlen; + uint tmp_static_link_ids_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_dsns_length; + uint tmp_tgt_filedsns_length; + uint tmp_tgt_drivers_length; + uint tmp_static_link_ids_length; + uint tmp_tgt_ports_length; + uint tmp_tgt_ssl_vscs_length; + uint tmp_monitoring_binlog_pos_at_failing_length; + uint tmp_link_statuses_length; +} SPIDER_ALTER_TABLE; + +typedef struct st_spider_conn_loop_check SPIDER_CONN_LOOP_CHECK; + +/* database connection */ +typedef struct st_spider_conn +{ + uint conn_kind; + char *conn_key; + uint conn_key_length; + my_hash_value_type conn_key_hash_value; + int link_idx; + spider_db_conn *db_conn; + uint opened_handlers; + ulonglong conn_id; + ulonglong connection_id; + query_id_t casual_read_query_id; + uint casual_read_current_id; + st_spider_conn *casual_read_base_conn; + 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; + int wait_timeout; + sql_mode_t sql_mode; + THD *thd; + void *another_ha_first; + void *another_ha_last; + /* Exactly one of p_small and p_big is not null */ + /* The parent node in the binary tree ordered by priority with a + smaller or equal priority */ + st_spider_conn *p_small; + /* The parent node in the binary tree ordered by priority with a + bigger priority */ + st_spider_conn *p_big; + /* The child node in the binary tree ordered by priority with a + smaller priority */ + st_spider_conn *c_small; + /* The child node in the binary tree ordered by priority with a + bigger or equal priority */ + 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_db; /* for not joinable tables on different db */ + 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 *tgt_dsn; + char *tgt_filedsn; + char *tgt_driver; + long tgt_port; + long tgt_ssl_vsc; + + uint tgt_host_length; + uint tgt_username_length; + uint tgt_password_length; + uint tgt_socket_length; + uint tgt_wrapper_length; + uint tgt_db_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 tgt_dsn_length; + uint tgt_filedsn_length; + uint tgt_driver_length; + uint dbton_id; + + volatile + void *quick_target; + 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; + volatile + 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_wait_timeout; + bool queued_autocommit; + bool queued_sql_log_off; + bool queued_sql_mode; + 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; + int queued_wait_timeout_val; + bool queued_autocommit_val; + bool queued_sql_log_off_val; + sql_mode_t queued_sql_mode_val; + Time_zone *queued_time_zone_val; + XID *queued_xa_start_xid; + + + bool disable_connect_retry; /* TRUE if it is unnecessary to + retry to connect after a + connection error */ + bool connect_error_with_message; + char connect_error_msg[MYSQL_ERRMSG_SIZE]; + int connect_error; + THD *connect_error_thd; + query_id_t connect_error_query_id; + time_t connect_error_time; + + SPIDER_CONN_HOLDER *conn_holder_for_direct_join; + SPIDER_LINK_IDX_CHAIN *link_idx_chain; + SPIDER_IP_PORT_CONN *ip_port_conn; + + pthread_mutex_t loop_check_mutex; + HASH loop_checked; + uint loop_checked_id; + const char *loop_checked_func_name; + const char *loop_checked_file_name; + ulong loop_checked_line_no; + HASH loop_check_queue; + uint loop_check_queue_id; + const char *loop_check_queue_func_name; + const char *loop_check_queue_file_name; + ulong loop_check_queue_line_no; + SPIDER_CONN_LOOP_CHECK *loop_check_ignored_first; + SPIDER_CONN_LOOP_CHECK *loop_check_ignored_last; + SPIDER_CONN_LOOP_CHECK *loop_check_meraged_first; + SPIDER_CONN_LOOP_CHECK *loop_check_meraged_last; +} SPIDER_CONN; + +typedef struct st_spider_lgtm_tblhnd_share +{ + char *table_name; + uint table_name_length; + my_hash_value_type table_path_hash_value; + pthread_mutex_t auto_increment_mutex; + volatile bool auto_increment_init; + volatile ulonglong auto_increment_lclval; + ulonglong auto_increment_value; +} SPIDER_LGTM_TBLHND_SHARE; + +typedef struct st_spider_patition_handler +{ + bool clone_bitmap_init; + query_id_t parallel_search_query_id; + uint no_parts; + TABLE *table; + ha_spider *owner; + ha_spider **handlers; +} SPIDER_PARTITION_HANDLER; + +typedef struct st_spider_wide_share +{ + char *table_name; + uint table_name_length; + my_hash_value_type table_path_hash_value; + uint use_count; + THR_LOCK lock; + pthread_mutex_t sts_mutex; + pthread_mutex_t crd_mutex; + + volatile bool sts_init; + volatile bool crd_init; + volatile time_t sts_get_time; + volatile time_t crd_get_time; + ha_statistics stat; + + longlong *cardinality; +} SPIDER_WIDE_SHARE; + +enum spider_hnd_stage { + SPD_HND_STAGE_NONE, + SPD_HND_STAGE_STORE_LOCK, + SPD_HND_STAGE_EXTERNAL_LOCK, + SPD_HND_STAGE_START_STMT, + SPD_HND_STAGE_EXTRA, + SPD_HND_STAGE_COND_PUSH, + SPD_HND_STAGE_COND_POP, + SPD_HND_STAGE_INFO_PUSH, + SPD_HND_STAGE_SET_TOP_TABLE_AND_FIELDS, + SPD_HND_STAGE_CLEAR_TOP_TABLE_FIELDS +}; + +typedef struct st_spider_wide_handler +{ + spider_hnd_stage stage; + handler *stage_executor; + THR_LOCK_DATA lock; + SPIDER_TRX *trx; + uchar *searched_bitmap; + uchar *ft_discard_bitmap; + uchar *position_bitmap; + uchar *idx_read_bitmap; + uchar *idx_write_bitmap; + uchar *rnd_read_bitmap; + uchar *rnd_write_bitmap; + SPIDER_CONDITION *condition; + void *owner; + SPIDER_PARTITION_HANDLER *partition_handler; + List *direct_update_fields; + List *direct_update_values; + TABLE_SHARE *top_share; + enum thr_lock_type lock_type; + uchar lock_table_type; + int lock_mode; + int external_lock_type; + int cond_check_error; + uint sql_command; + uint top_table_fields; +#ifdef INFO_KIND_FORCE_LIMIT_BEGIN + longlong info_limit; +#endif + bool between_flg; + bool idx_bitmap_is_set; + bool rnd_bitmap_is_set; + bool position_bitmap_init; + bool semi_trx_isolation_chk; + bool semi_trx_chk; + bool low_priority; + bool high_priority; + bool consistent_snapshot; + bool quick_mode; + bool keyread; + bool update_request; + bool ignore_dup_key; + bool write_can_replace; + bool insert_with_update; + bool cond_check; + bool semi_table_lock; +} SPIDER_WIDE_HANDLER; + +typedef struct st_spider_transaction +{ + bool trx_start; + bool trx_xa; + bool trx_consistent_snapshot; + bool trx_xa_prepared; + + bool use_consistent_snapshot; + bool internal_xa; + uint internal_xa_snapshot; + + query_id_t query_id; + bool tmp_flg; + bool registed_allocated_thds; + + bool updated_in_this_trx; + + THD *thd; + 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; + 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; + uint locked_connections; + + ulonglong direct_update_count; + ulonglong direct_delete_count; + ulonglong direct_order_limit_count; + ulonglong direct_aggregate_count; + ulonglong parallel_search_count; + + + 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]; + + MEM_ROOT mem_root; + + /* for transaction level query */ + SPIDER_SHARE *tmp_share; + 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]; + ha_spider *tmp_spider; + int tmp_need_mon; + spider_db_handler *tmp_dbton_handler[SPIDER_DBTON_SIZE]; +} 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; +*/ + TABLE_SHARE *table_share; + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; + my_hash_value_type table_name_hash_value; + my_hash_value_type table_path_hash_value; + + volatile bool init; + volatile bool init_error; + volatile time_t init_error_time; + volatile bool link_status_init; + uchar *table_mon_mutex_bitmap; + volatile bool sts_init; + volatile time_t sts_get_time; + volatile time_t bg_sts_try_time; + volatile double bg_sts_interval; + volatile int bg_sts_mode; + volatile int bg_sts_sync; + 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; + volatile time_t crd_get_time; + volatile time_t bg_crd_try_time; + volatile double bg_crd_interval; + volatile int bg_crd_mode; + volatile int bg_crd_sync; + 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; + 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; + pthread_cond_t *bg_mon_sleep_conds; + /* static bg thread for sts and crd */ + TABLE table; + ha_spider *sts_spider; + ha_spider *crd_spider; + SPIDER_THREAD *sts_thread; + SPIDER_THREAD *crd_thread; + volatile bool sts_spider_init; + volatile bool sts_working; + volatile bool sts_wait; + volatile bool crd_spider_init; + volatile bool crd_working; + volatile bool crd_wait; + volatile SPIDER_SHARE *sts_prev; + volatile SPIDER_SHARE *sts_next; + volatile SPIDER_SHARE *crd_prev; + volatile SPIDER_SHARE *crd_next; + + MEM_ROOT mem_root; + +/* + volatile bool auto_increment_init; + volatile ulonglong auto_increment_lclval; +*/ + ha_statistics stat; + + longlong static_records_for_status; + longlong static_mean_rec_length; + + int bitmap_size; + spider_string *key_hint; + CHARSET_INFO *access_charset; + longlong *static_key_cardinality; + longlong *cardinality; + uchar *cardinality_upd; + longlong additional_table_flags; + bool have_recovery_link; + + int sts_bg_mode; + double sts_interval; + int sts_mode; + int sts_sync; + int store_last_sts; + int load_sts_at_startup; + int crd_bg_mode; + double crd_interval; + int crd_mode; + int crd_sync; + int store_last_crd; + int load_crd_at_startup; + 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 query_cache_sync; + int bulk_size; + int bulk_update_mode; + int bulk_update_size; + int buffer_size; + int internal_optimize; + int internal_optimize_local; + double scan_rate; + double read_rate; + longlong priority; + int quick_mode; + longlong quick_page_size; + longlong quick_page_byte; + int low_mem_read; + int table_count_mode; + int select_column_mode; + int bgs_mode; + longlong bgs_first_read; + longlong bgs_second_read; + longlong first_read; + longlong second_read; + int auto_increment_mode; + int use_table_charset; + int use_pushdown_udf; + int skip_default_condition; + int skip_parallel_search; + int direct_dup_insert; + longlong direct_order_limit; + int read_only_mode; + int error_read_mode; + int error_write_mode; + int active_link_count; +#ifdef HA_CAN_FORCE_BULK_UPDATE + int force_bulk_update; +#endif +#ifdef HA_CAN_FORCE_BULK_DELETE + int force_bulk_delete; +#endif + int casual_read; + int delete_all_rows_type; + + int bka_mode; + char *bka_engine; + int bka_engine_length; + + my_hash_value_type *conn_keys_hash_value; + 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_dsns; + char **tgt_filedsns; + char **tgt_drivers; + char **static_link_ids; + char **tgt_pk_names; + char **tgt_sequence_names; + char **conn_keys; + long *tgt_ports; + long *tgt_ssl_vscs; + long *link_statuses; + long *monitoring_bg_flag; + long *monitoring_bg_kind; + long *monitoring_binlog_pos_at_failing; + long *monitoring_flag; + long *monitoring_kind; + longlong *monitoring_bg_interval; + longlong *monitoring_limit; + longlong *monitoring_sid; + long *connect_timeouts; + long *net_read_timeouts; + long *net_write_timeouts; + long *access_balances; + long *bka_table_name_types; + long *strict_group_bys; + + 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_dsns_lengths; + uint *tgt_filedsns_lengths; + uint *tgt_drivers_lengths; + uint *static_link_ids_lengths; + uint *tgt_pk_names_lengths; + uint *tgt_sequence_names_lengths; + uint *conn_keys_lengths; + uint *sql_dbton_ids; + + 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_dsns_charlen; + uint tgt_filedsns_charlen; + uint tgt_drivers_charlen; + uint static_link_ids_charlen; + uint tgt_pk_names_charlen; + uint tgt_sequence_names_charlen; + uint conn_keys_charlen; + + 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_dsns_length; + uint tgt_filedsns_length; + uint tgt_drivers_length; + uint static_link_ids_length; + uint tgt_pk_names_length; + uint tgt_sequence_names_length; + uint conn_keys_length; + uint tgt_ports_length; + uint tgt_ssl_vscs_length; + uint link_statuses_length; + uint monitoring_bg_flag_length; + uint monitoring_bg_kind_length; + uint monitoring_binlog_pos_at_failing_length; + uint monitoring_flag_length; + uint monitoring_kind_length; + uint monitoring_bg_interval_length; + uint monitoring_limit_length; + uint monitoring_sid_length; + uint connect_timeouts_length; + uint net_read_timeouts_length; + uint net_write_timeouts_length; + uint access_balances_length; + uint bka_table_name_types_length; + uint strict_group_bys_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]; + + SPIDER_ALTER_TABLE alter_table; + SPIDER_WIDE_SHARE *wide_share; +} 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; + my_hash_value_type table_name_hash_value; + 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; + + /* for using real table */ + bool real_table_used; + TABLE_LIST *table_list_first; + TABLE_LIST *table_list; + uchar *real_table_bitmap; + SPIDER_Open_tables_backup open_tables_backup; + THD *open_tables_thd; + + 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; + int use_real_table; + int error_rw_mode; + + 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 *tgt_dsn; + char *tgt_filedsn; + char *tgt_driver; + 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 tgt_dsn_length; + uint tgt_filedsn_length; + uint tgt_driver_length; + uint conn_key_length; + uint dbton_id; + my_hash_value_type conn_key_hash_value; + + 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_list *parent; + st_spider_table_mon *next; +} SPIDER_TABLE_MON; + +typedef struct st_spider_table_mon_list +{ + char *key; + uint key_length; + my_hash_value_type key_hash_value; + + 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; + int bg_error_num; + 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; + int bg_mode; + + 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; + + +#define SPIDER_INT_HLD_TGT_SIZE 100 +typedef struct st_spider_int_hld +{ + uint tgt_num; + int tgt[SPIDER_INT_HLD_TGT_SIZE]; + st_spider_int_hld *next; +} SPIDER_INT_HLD; + +typedef struct st_spider_item_hld +{ + uint tgt_num; + Item *item; + bool init_mem_root; + MEM_ROOT mem_root; + st_spider_item_hld *next; +} SPIDER_ITEM_HLD; + +char *spider_create_string( + const char *str, + uint length +); + + +typedef struct st_spider_ip_port_conn { + char *key; + size_t key_len; + my_hash_value_type key_hash_value; + char *remote_ip_str; + long remote_port; + ulong ip_port_count; + volatile ulong waiting_count; + pthread_mutex_t mutex; + pthread_cond_t cond; + ulonglong conn_id; /* each conn has it's own conn_id */ +} SPIDER_IP_PORT_CONN; diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h new file mode 100644 index 00000000..fdf6b22f --- /dev/null +++ b/storage/spider/spd_init_query.h @@ -0,0 +1,744 @@ +/* Copyright (C) 2010-2020 Kentoku Shiba + Copyright (C) 2019-2020 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +/* + This SQL script creates system tables for SPIDER + or fixes incompatibilities if ones already exist. +*/ + +static LEX_STRING spider_init_queries[] = { + {C_STRING_WITH_LEN( + "create table if not exists 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" + )}, + {C_STRING_WITH_LEN( + "create table if not exists 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," + " username char(64) not null default ''," + " password char(64) not null default ''," + " ssl_ca text," + " ssl_capath text," + " ssl_cert text," + " ssl_cipher char(64) default null," + " ssl_key text," + " ssl_verify_server_cert tinyint not null default 0," + " default_file text," + " default_group char(64) default null," + " dsn char(64) default null," + " filedsn text default null," + " driver char(64) default null," + " key idx1 (data, format_id, gtrid_length, host)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_xa_failed_log(" + " 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," + " username char(64) not null default ''," + " password char(64) not null default ''," + " ssl_ca text," + " ssl_capath text," + " ssl_cert text," + " ssl_cipher char(64) default null," + " ssl_key text," + " ssl_verify_server_cert tinyint not null default 0," + " default_file text," + " default_group char(64) default null," + " dsn char(64) default null," + " filedsn text default null," + " driver char(64) default null," + " thread_id int default null," + " status char(8) not null default ''," + " failed_time timestamp not null default current_timestamp," + " key idx1 (data, format_id, gtrid_length, host)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_tables(" + " db_name char(64) not null default ''," + " table_name char(199) 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," + " username char(64) default null," + " password char(64) default null," + " ssl_ca text," + " ssl_capath text," + " ssl_cert text," + " ssl_cipher char(64) default null," + " ssl_key text," + " ssl_verify_server_cert tinyint not null default 0," + " monitoring_binlog_pos_at_failing tinyint not null default 0," + " default_file text," + " default_group char(64) default null," + " dsn char(64) default null," + " filedsn text default null," + " driver 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," + " block_status tinyint not null default 0," + " static_link_id char(64) default null," + " primary key (db_name, table_name, link_id)," + " key idx1 (priority)," + " unique key uidx1 (db_name, table_name, static_link_id)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_link_mon_servers(" + " db_name char(64) not null default ''," + " table_name char(199) not null default ''," + " link_id char(64) not null default ''," + " sid int unsigned 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," + " username char(64) default null," + " password char(64) default null," + " ssl_ca text," + " ssl_capath text," + " ssl_cert text," + " ssl_cipher char(64) default null," + " ssl_key text," + " ssl_verify_server_cert tinyint not null default 0," + " default_file text," + " default_group char(64) default null," + " dsn char(64) default null," + " filedsn text default null," + " driver char(64) default null," + " primary key (db_name, table_name, link_id, sid)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_link_failed_log(" + " db_name char(64) not null default ''," + " table_name char(199) not null default ''," + " link_id char(64) not null default ''," + " failed_time timestamp not null default current_timestamp" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_table_position_for_recovery(" + " db_name char(64) not null default ''," + " table_name char(199) not null default ''," + " failed_link_id int not null default 0," + " source_link_id int not null default 0," + " file text," + " position text," + " gtid text," + " primary key (db_name, table_name, failed_link_id, source_link_id)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_table_sts(" + " db_name char(64) not null default ''," + " table_name char(199) not null default ''," + " data_file_length bigint unsigned not null default 0," + " max_data_file_length bigint unsigned not null default 0," + " index_file_length bigint unsigned not null default 0," + " records bigint unsigned not null default 0," + " mean_rec_length bigint unsigned not null default 0," + " check_time datetime not null default '0000-00-00 00:00:00'," + " create_time datetime not null default '0000-00-00 00:00:00'," + " update_time datetime not null default '0000-00-00 00:00:00'," + " checksum bigint unsigned default null," + " primary key (db_name, table_name)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, + {C_STRING_WITH_LEN( + "create table if not exists mysql.spider_table_crd(" + " db_name char(64) not null default ''," + " table_name char(199) not null default ''," + " key_seq int unsigned not null default 0," + " cardinality bigint not null default 0," + " primary key (db_name, table_name, key_seq)" + ") engine=MyISAM default charset=utf8 collate=utf8_bin" + )}, +/* + If tables already exist and their definition differ + from the latest ones, we fix them here. +*/ +/* + Fix for 0.5 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add if not exists server char(64) default null," + " add if not exists scheme char(64) default null," + " add if not exists host char(64) default null," + " add if not exists port char(5) default null," + " add if not exists socket char(64) default null," + " add if not exists username char(64) default null," + " add if not exists password char(64) default null," + " add if not exists tgt_db_name char(64) default null," + " add if not exists tgt_table_name char(64) default null," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for version 0.17 +*/ + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa'" + " AND COLUMN_NAME = 'data';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'binary(128)' then" + " alter table mysql.spider_xa" + " modify data binary(128) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa_member'" + " AND COLUMN_NAME = 'data';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'binary(128)' then" + " alter table mysql.spider_xa_member" + " modify data binary(128) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 2.7 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists link_id int not null default 0 after table_name," + " drop primary key," + " add primary key (db_name, table_name, link_id)," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for version 2.8 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists link_status tinyint not null default 1," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for version 2.10 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_member" + " add column if not exists ssl_ca char(64) default null after password," + " add column if not exists ssl_capath char(64) default null after ssl_ca," + " add column if not exists ssl_cert char(64) default null after ssl_capath," + " add column if not exists ssl_cipher char(64) default null after ssl_cert," + " add column if not exists ssl_key char(64) default null after ssl_cipher," + " add column if not exists ssl_verify_server_cert tinyint not null default 0" + " after ssl_key," + " add column if not exists default_file char(64) default null" + " after ssl_verify_server_cert," + " add column if not exists default_group char(64) default null after default_file," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists ssl_ca char(64) default null after password," + " add column if not exists ssl_capath char(64) default null after ssl_ca," + " add column if not exists ssl_cert char(64) default null after ssl_capath," + " add column if not exists ssl_cipher char(64) default null after ssl_cert," + " add column if not exists ssl_key char(64) default null after ssl_cipher," + " add column if not exists ssl_verify_server_cert tinyint not null default 0" + " after ssl_key," + " add column if not exists default_file char(64) default null" + " after ssl_verify_server_cert," + " add column if not exists default_group char(64) default null after default_file," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_link_mon_servers" + " add column if not exists ssl_ca char(64) default null after password," + " add column if not exists ssl_capath char(64) default null after ssl_ca," + " add column if not exists ssl_cert char(64) default null after ssl_capath," + " add column if not exists ssl_cipher char(64) default null after ssl_cert," + " add column if not exists ssl_key char(64) default null after ssl_cipher," + " add column if not exists ssl_verify_server_cert tinyint not null default 0" + " after ssl_key," + " add column if not exists default_file char(64) default null" + " after ssl_verify_server_cert," + " add column if not exists default_group char(64) default null after default_file," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for version 2.28 +*/ + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_mon_servers'" + " AND COLUMN_NAME = 'sid';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'int(10) unsigned' then" + " alter table mysql.spider_link_mon_servers" + " modify sid int unsigned not null default 0," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 3.1 +*/ + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa_member'" + " AND COLUMN_NAME = 'socket';" + )}, + {C_STRING_WITH_LEN( + "if @col_type = 'char(64)' then" + " alter table mysql.spider_xa_member" + " drop primary key," + " add index idx1 (data, format_id, gtrid_length, host)," + " modify socket text not null," + " modify ssl_ca text," + " modify ssl_capath text," + " modify ssl_cert text," + " modify ssl_key text," + " modify default_file text," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_tables'" + " AND COLUMN_NAME = 'socket';" + )}, + {C_STRING_WITH_LEN( + "if @col_type = 'char(64)' then" + " alter table mysql.spider_tables" + " modify socket text," + " modify ssl_ca text," + " modify ssl_capath text," + " modify ssl_cert text," + " modify ssl_key text," + " modify default_file text," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_mon_servers'" + " AND COLUMN_NAME = 'socket';" + )}, + {C_STRING_WITH_LEN( + "if @col_type = 'char(64)' then" + " alter table mysql.spider_link_mon_servers" + " modify socket text," + " modify ssl_ca text," + " modify ssl_capath text," + " modify ssl_cert text," + " modify ssl_key text," + " modify default_file text," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 3.3.0 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add if not exists monitoring_binlog_pos_at_failing tinyint not null default 0" + " after ssl_verify_server_cert," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for version 3.3.6 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists block_status tinyint not null default 0" + " after link_status," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists static_link_id char(64) default null after block_status," + " add unique index if not exists uidx1 (db_name, table_name, static_link_id)," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_mon_servers'" + " AND COLUMN_NAME = 'link_id';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(64)' then" + " alter table mysql.spider_link_mon_servers" + " modify link_id char(64) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_failed_log'" + " AND COLUMN_NAME = 'link_id';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(64)' then" + " alter table mysql.spider_link_failed_log" + " modify link_id char(64) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 3.3.10 +*/ + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_tables'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_tables" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_mon_servers'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_link_mon_servers" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_failed_log'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_link_failed_log" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_position_for_recovery'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_table_position_for_recovery" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_sts'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_table_sts" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select COLUMN_TYPE INTO @col_type from INFORMATION_SCHEMA.COLUMNS" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_crd'" + " AND COLUMN_NAME = 'table_name';" + )}, + {C_STRING_WITH_LEN( + "if @col_type != 'char(199)' then" + " alter table mysql.spider_table_crd" + " modify table_name char(199) not null default ''," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 3.3.15 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_table_sts" + " add column if not exists checksum bigint unsigned default null after update_time," + " algorithm=copy, lock=shared;" + )}, +/* + Fix for MariaDB 10.4: Crash-Safe system tables +*/ + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_failed_log';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_link_failed_log" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_link_mon_servers';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_link_mon_servers" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_crd';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_table_crd" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_position_for_recovery';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_table_position_for_recovery" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_table_sts';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_table_sts" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_tables';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_tables" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_xa" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa_failed_log';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_xa_failed_log" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, + {C_STRING_WITH_LEN( + "select ENGINE INTO @engine_name from INFORMATION_SCHEMA.TABLES" + " where TABLE_SCHEMA = 'mysql'" + " AND TABLE_NAME = 'spider_xa_member';" + )}, + {C_STRING_WITH_LEN( + "if @engine_name != 'Aria' then" + " alter table mysql.spider_xa_member" + " engine=Aria transactional=1," + " algorithm=copy, lock=shared;" + "end if;" + )}, +/* + Fix for version 3.4 +*/ + {C_STRING_WITH_LEN( + "alter table mysql.spider_link_mon_servers" + " add column if not exists dsn char(64) default null after default_group," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists dsn char(64) default null after default_group," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_failed_log" + " add column if not exists dsn char(64) default null after default_group," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_member" + " add column if not exists dsn char(64) default null after default_group," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_link_mon_servers" + " add column if not exists filedsn text default null after dsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists filedsn text default null after dsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_failed_log" + " add column if not exists filedsn text default null after dsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_member" + " add column if not exists filedsn text default null after dsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_link_mon_servers" + " add column if not exists driver char(64) default null after filedsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_tables" + " add column if not exists driver char(64) default null after filedsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_failed_log" + " add column if not exists driver char(64) default null after filedsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "alter table mysql.spider_xa_member" + " add column if not exists driver char(64) default null after filedsn," + " algorithm=copy, lock=shared;" + )}, + {C_STRING_WITH_LEN( + "set @win_plugin := IF(@@version_compile_os like 'Win%', 1, 0);" + )}, + /* Install UDFs. If udf is not initialised, then install by + inserting into mysql.func */ + {C_STRING_WITH_LEN( + "if @win_plugin = 0 then" + " begin not atomic" + " declare exit handler for 1041, 1123" + " replace into mysql.func values" + " ('spider_direct_sql', 2, 'ha_spider.so', 'function')," + " ('spider_bg_direct_sql', 2, 'ha_spider.so', 'aggregate')," + " ('spider_ping_table', 2, 'ha_spider.so', 'function')," + " ('spider_copy_tables', 2, 'ha_spider.so', 'function')," + " ('spider_flush_table_mon_cache', 2, 'ha_spider.so', 'function');" + " create function if not exists spider_direct_sql returns int" + " soname 'ha_spider.so';" + " create aggregate function if not exists spider_bg_direct_sql returns int" + " soname 'ha_spider.so';" + " create function if not exists spider_ping_table returns int" + " soname 'ha_spider.so';" + " create function if not exists spider_copy_tables returns int" + " soname 'ha_spider.so';" + " create function if not exists spider_flush_table_mon_cache returns int" + " soname 'ha_spider.so';" + " end;" + "else" + " begin not atomic" + " declare exit handler for 1041, 1123" + " replace into mysql.func values" + " ('spider_direct_sql', 2, 'ha_spider.dll', 'function')," + " ('spider_bg_direct_sql', 2, 'ha_spider.dll', 'aggregate')," + " ('spider_ping_table', 2, 'ha_spider.dll', 'function')," + " ('spider_copy_tables', 2, 'ha_spider.dll', 'function')," + " ('spider_flush_table_mon_cache', 2, 'ha_spider.dll', 'function');" + " create function if not exists spider_direct_sql returns int" + " soname 'ha_spider.dll';" + " create aggregate function if not exists spider_bg_direct_sql returns int" + " soname 'ha_spider.dll';" + " create function if not exists spider_ping_table returns int" + " soname 'ha_spider.dll';" + " create function if not exists spider_copy_tables returns int" + " soname 'ha_spider.dll';" + " create function if not exists spider_flush_table_mon_cache returns int" + " soname 'ha_spider.dll';" + " end;" + "end if;" + )} +}; diff --git a/storage/spider/spd_malloc.cc b/storage/spider/spd_malloc.cc new file mode 100644 index 00000000..5a7ef404 --- /dev/null +++ b/storage/spider/spd_malloc.cc @@ -0,0 +1,1306 @@ +/* Copyright (C) 2012-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_analyse.h" +#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); + spider_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(PSI_INSTRUMENT_ME, 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(PSI_INSTRUMENT_ME, 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, strlen(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 +{ + LEX_STRING res= { (char*) str.ptr(), str.length() }; + DBUG_ENTER("spider_string::lex_string"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_RETURN(res); +} + +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); +} + +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, strlen(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); +} + +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)); + DBUG_ASSERT(str.alloced_length() >= str.length() + data_len); + 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); +} + +void spider_string::append_escape_string( + const char *st, + uint len +) { + my_bool overflow; + DBUG_ENTER("spider_string::append_escape_string"); + 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.length(str.length() + escape_string_for_mysql( + str.charset(), (char *) str.ptr() + str.length(), 0, st, len, + &overflow)); + DBUG_VOID_RETURN; +} + +void spider_string::append_escape_string( + const char *st, + uint len, + CHARSET_INFO *cs +) { + my_bool overflow; + DBUG_ENTER("spider_string::append_escape_string"); + 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.length(str.length() + escape_string_for_mysql( + cs, (char *) str.ptr() + str.length(), 0, st, len, &overflow)); + DBUG_VOID_RETURN; +} + +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()); +#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE + bool res = str.append_for_single_quote(st, len); +#else + String ststr(st, len, str.charset()); + bool res = append_escaped(&str, &ststr); +#endif + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append_for_single_quote( + const String *s +) { + 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()); +#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE + bool res = str.append_for_single_quote(s); +#else + bool res = append_escaped(&str, (String *) s); +#endif + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +bool spider_string::append_for_single_quote( + const char *st +) { + 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()); +#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE + bool res = str.append_for_single_quote(st, strlen(st)); +#else + String ststr(st, str.charset()); + bool res = append_escaped(&str, &ststr); +#endif + SPIDER_STRING_CALC_MEM; + DBUG_RETURN(res); +} + +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 00000000..9e97e039 --- /dev/null +++ b/storage/spider/spd_malloc.h @@ -0,0 +1,80 @@ +/* Copyright (C) 2012-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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_hton_ptr->slot != HA_SLOT_UNDEF ? ((SPIDER_TRX *) thd_get_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 00000000..2328cce7 --- /dev/null +++ b/storage/spider/spd_param.cc @@ -0,0 +1,2538 @@ +/* Copyright (C) 2008-2018 Kentoku Shiba + Copyright (C) 2023 MariaDB plc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/** + @file + + There are several kinds of spider parameters. + + - sysvar/thdvar that are not table parameters. These variables do + not appear in a `SPIDER_SHARE`. Examples include `support_xa` and + `conn_recycle_mode`. Their values are commonly retrieved by + `SPIDER_SYSVAR_VALUE_FUNC()` and `SPIDER_THDVAR_VALUE_FUNC()` + - sysvar/thdvar that are also table parameters. These variables + commonly appear in a `SPIDER_SHARE`. Examples include + `read_only_mode` and `use_table_charset`. Table parameter values + override variable values, and their values are commonly retrieved + by `SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC()` and + `SPIDER_THDVAR_OVERRIDE_VALUE_FUNC()`. + - table parameters that are not sysvar/thdvar. Examples include + host and username. They are not handled in this file which is only + concerned with global/session variables +*/ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#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 struct st_mysql_plugin spider_i_s_wrapper_protocols; +extern struct st_maria_plugin spider_i_s_alloc_mem_maria; +extern struct st_maria_plugin spider_i_s_wrapper_protocols_maria; + +extern volatile ulonglong spider_mon_table_cache_version; +extern volatile ulonglong spider_mon_table_cache_version_req; + +/* + Define a function returning the value of a global variable. +*/ +#define SPIDER_SYSVAR_VALUE_FUNC(param_type, param_name) \ + param_type spider_param_ ## param_name() \ + { \ + return SYSVAR(param_name); \ + } + +/* + Define a function returning the value of a session variable. +*/ +#define SPIDER_THDVAR_VALUE_FUNC(param_type, param_name) \ + param_type spider_param_ ## param_name(THD *thd) \ + { \ + return THDVAR(thd, param_name); \ + } + +/* + Define a function returning the value of a table param that is also a + global variable. + + If the table param value is not -1, use the table param value. + Otherwise if the variable value is not -1, use the variable value. + Otherwise use the default variable value. +*/ +#define SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(param_type, param_name) \ + param_type spider_param_ ## param_name(param_type param_name) \ + { \ + return param_name != -1 ? param_name : \ + SYSVAR(param_name) != -1 ? SYSVAR(param_name) : \ + MYSQL_SYSVAR_NAME(param_name).def_val; \ + } + +/* + Define a function returning the value of a table param that is also a + session variable. + + If the table param value is not -1, use the table param value. + Otherwise if the variable value is not -1, use the variable value. + Otherwise use the default variable value. +*/ +#define SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(param_type, param_name) \ + param_type spider_param_ ## param_name(THD* thd, \ + param_type param_name) \ + { \ + return param_name != -1 ? param_name : \ + THDVAR(thd, param_name) != -1 ? THDVAR(thd, param_name) : \ + MYSQL_SYSVAR_NAME(param_name).def_val; \ + } + +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); +} + +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); +} + +static int spider_parallel_search(THD *thd, SHOW_VAR *var, char *buff) +{ + int error_num = 0; + SPIDER_TRX *trx; + DBUG_ENTER("spider_parallel_search"); + var->type = SHOW_LONGLONG; + if ((trx = spider_get_trx(thd, TRUE, &error_num))) + var->value = (char *) &trx->parallel_search_count; + DBUG_RETURN(error_num); +} + +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 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 +#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}, + {"Spider_parallel_search", + (char *) &spider_parallel_search, SHOW_SIMPLE_FUNC}, +#else + {"Spider_direct_order_limit", + (char *) &spider_direct_order_limit, SHOW_FUNC}, + {"Spider_direct_aggregate", + (char *) &spider_direct_aggregate, SHOW_FUNC}, + {"Spider_parallel_search", + (char *) &spider_parallel_search, SHOW_FUNC}, +#endif + {NullS, NullS, SHOW_LONG} +}; + +typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int); +extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, + bool is_unsignd, longlong v); + +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 +); + +static void spider_var_deprecated_int(THD *thd, st_mysql_sys_var *, + void *var_ptr, const void *save) +{ + int val= *static_cast(save); + *static_cast(var_ptr)= val; + if (val == -1) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + HA_ERR_UNSUPPORTED, + "The option value -1 (fallback to default) is " + "deprecated and will be removed in a future release"); + } +} + +static void spider_var_deprecated_longlong(THD *thd, st_mysql_sys_var *, + void *var_ptr, const void *save) +{ + longlong val= *static_cast(save); + *static_cast(var_ptr)= val; + if (val == -1) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + HA_ERR_UNSUPPORTED, + "The option value -1 (fallback to default) is " + "deprecated and will be removed in a future release"); + } +} + +SPIDER_SYSVAR_VALUE_FUNC(my_bool, 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 +); + +SPIDER_SYSVAR_VALUE_FUNC(my_bool, connect_mutex) + +static uint spider_connect_error_interval; +/* + 0-: interval + */ +static MYSQL_SYSVAR_UINT( + connect_error_interval, + spider_connect_error_interval, + PLUGIN_VAR_RQCMDARG, + "Return same error code until interval passes if connection is failed", + NULL, + NULL, + 1, + 0, + 4294967295U, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, connect_error_interval) + +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 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, table_init_error_interval) + +static int spider_use_table_charset; +/* + -1 :fallback to default + 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, + spider_var_deprecated_int, + 1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, force_commit) + +/* + 0: register all XA transaction + 1: register only write XA transaction + */ +static MYSQL_THDVAR_UINT( + xa_register_mode, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Mode of XA transaction register into system table", /* comment */ + NULL, /* check */ + NULL, /* update */ + 1, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, xa_register_mode) + +/* + -1 :fallback to default + 0-:offset + */ +static MYSQL_THDVAR_LONGLONG( + internal_offset, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Internal offset", /* comment */ + NULL, /* check */ + spider_var_deprecated_longlong, /* update */ + 0, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, internal_offset) + +/* + -1 :fallback to default + 0-:limit + */ +static MYSQL_THDVAR_LONGLONG( + internal_limit, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Internal limit", /* comment */ + NULL, /* check */ + spider_var_deprecated_longlong, /* update */ + 9223372036854775807LL, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, internal_limit) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_longlong, /* update */ + 9223372036854775807LL, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, split_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(double, semi_split_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_longlong, /* update */ + 9223372036854775807LL, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, semi_split_read_limit) + +/* + -1 :fallback to default + 0 :no alloc + 1-:alloc size + */ +static MYSQL_THDVAR_INT( + init_sql_alloc_size, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Initial sql string alloc size", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 1024, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, init_sql_alloc_size) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, reset_sql_alloc) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 100, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, multi_split_read) + +/* + -1 :fallback to default + 0-:max order columns + */ +static MYSQL_THDVAR_INT( + max_order, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Max columns for order by", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 32767, /* def */ + -1, /* min */ + 32767, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(int, 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); + DBUG_RETURN(throw_bounds_warning(thd, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, + (longlong) tmp)); +} + +/* + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + semi_table_lock, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Table lock during execute a sql", /* comment */ + &spider_param_semi_table_lock_check, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, 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); + DBUG_RETURN(throw_bounds_warning(thd, + ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE, + (longlong) tmp)); +} + +/* + -1 :off + 0 :use same connection + 1 :use different connection + */ +static MYSQL_THDVAR_INT( + semi_table_lock_connection, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Use different connection if semi_table_lock is enabled", /* comment */ + &spider_param_semi_table_lock_connection_check, /* check */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, block_size) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, sync_autocommit) + +/* + 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, use_default_database) + +/* +-1 :don't know or does not matter; don't send 'SET SQL_LOG_OFF' statement + 0 :do send 'SET SQL_LOG_OFF 0' statement to data nodes + 1 :do send 'SET SQL_LOG_OFF 1' statement to data nodes +*/ +static MYSQL_THDVAR_INT( + internal_sql_log_off, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Manage SQL_LOG_OFF mode statement to the data nodes", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* default */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_VALUE_FUNC(int, internal_sql_log_off) + +/* + -1 :fallback to default + 0-:bulk insert size + */ +static MYSQL_THDVAR_INT( + bulk_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Bulk insert size", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 16000, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bulk_size) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bulk_update_mode) + +/* + -1 :fallback to default + 0-:bulk update size + */ +static MYSQL_THDVAR_INT( + bulk_update_size, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Bulk update size", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 16000, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bulk_update_size) + +/* + -1 :fallback to default + 0-:buffer size + */ +static MYSQL_THDVAR_INT( + buffer_size, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Buffer size", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 16000, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, buffer_size) + +/* + -1 :fallback to default + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + internal_optimize, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Execute optimize to remote server", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, internal_optimize) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(int, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, semi_trx) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 6, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, connect_timeout) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 600, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, net_read_timeout) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 600, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, net_write_timeout) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 3, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, quick_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1024, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, quick_page_size) + +/* + -1 :fallback to default + 0-:the limitation of memory size + */ +static MYSQL_THDVAR_LONGLONG( + quick_page_byte, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The limitation of memory size in a page when acquisition one by one", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 10485760, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, quick_page_byte) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, low_mem_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, select_column_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bgs_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, bgs_first_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 100, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, bgs_second_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, first_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, second_read) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 51, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(double, crd_interval) + +/* + -1 :fallback to default + 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 | PLUGIN_VAR_DEPRECATED, /* opt */ + "Mode of cardinality confirmation.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, crd_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, crd_sync) + +/* + -1 :fallback to default + 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 | PLUGIN_VAR_DEPRECATED, /* opt */ + "Type of cardinality calculation.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, crd_type) + +/* + -1 :fallback to default + 0-:weight + */ +static MYSQL_THDVAR_INT( + crd_weight, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Weight coefficient to calculate effectiveness of index from cardinality of column.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(double, crd_weight) + +/* + -1 :fallback to default + 0 :Background confirmation is disabled + 1 :Background confirmation is enabled (create thread per table/partition) + 2 :Background confirmation is enabled (use static threads) + */ +static MYSQL_THDVAR_INT( + crd_bg_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of cardinality confirmation at background.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, crd_bg_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 10, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(double, sts_interval) + +/* + -1 :fallback to default + 0 :use table parameter + 1 :use show command + 2 :use information schema + */ +static MYSQL_THDVAR_INT( + sts_mode, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "Mode of table state confirmation.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, sts_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, sts_sync) + +/* + -1 :fallback to default + 0 :Background confirmation is disabled + 1 :Background confirmation is enabled (create thread per table/partition) + 2 :Background confirmation is enabled (use static threads) + */ +static MYSQL_THDVAR_INT( + sts_bg_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Mode of table state confirmation at background.", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 2, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, sts_bg_mode) + +/* + 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(double, ping_interval_at_trx_start) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, auto_increment_mode) + +/* + FALSE: off + TRUE: on + */ +static MYSQL_THDVAR_BOOL( + same_server_link, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Permit one to link same server's table", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, 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 */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, local_lock_table) + +/* + -1 :fallback to default + 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 */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, use_pushdown_udf) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, direct_dup_insert) + +static char *spider_remote_access_charset; +/* + */ +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 +); + +SPIDER_SYSVAR_VALUE_FUNC(char*, 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 +); + +SPIDER_SYSVAR_VALUE_FUNC(int, remote_autocommit) + +static char *spider_remote_time_zone; +/* + */ +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 +); + +SPIDER_SYSVAR_VALUE_FUNC(char *, remote_time_zone) + +static int spider_remote_sql_log_off; +/* + -1 :don't know the value on all data nodes, or does not matter + 0 :sql_log_off = 0 on all data nodes + 1 :sql_log_off = 1 on all data nodes + */ +static MYSQL_SYSVAR_INT( + remote_sql_log_off, + spider_remote_sql_log_off, + PLUGIN_VAR_RQCMDARG, + "Set SQL_LOG_OFF mode on connecting for improved performance of connection, if you know", + NULL, + NULL, + -1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(int, 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 +); + +SPIDER_SYSVAR_VALUE_FUNC(int, remote_trx_isolation) + +static char *spider_remote_default_database; +/* + */ +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 +); + +SPIDER_SYSVAR_VALUE_FUNC(char *, 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); +} + +/* + */ +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 */ +); + +char *spider_param_bka_engine( + THD *thd, + char *bka_engine +) { + DBUG_ENTER("spider_param_bka_engine"); + DBUG_RETURN(bka_engine ? bka_engine : THDVAR(thd, bka_engine)); +} + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 2, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bka_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, error_read_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, error_write_mode) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, skip_default_condition) + +/* + -1 :fallback to default + 0 :not skip + 1 :skip parallel search if query is not SELECT statement + 2 :skip parallel search if query has SQL_NO_CACHE + 3 :1+2 + */ +static MYSQL_THDVAR_INT( + skip_parallel_search, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Skip parallel search by specific conditions", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, skip_parallel_search) + +/* + -1 :fallback to default + 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 */ + spider_var_deprecated_longlong, /* update */ + 9223372036854775807LL, /* def */ + -1, /* min */ + 9223372036854775807LL, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(longlong, direct_order_limit) + +/* + -1 :fallback to default + 0 :writable + 1 :read only + */ +static MYSQL_THDVAR_INT( + read_only_mode, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Read only", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, read_only_mode) + +static my_bool spider_general_log; +static MYSQL_SYSVAR_BOOL( + general_log, + spider_general_log, + PLUGIN_VAR_OPCMDARG, + "Log query to remote server in general log", + NULL, + NULL, + FALSE +); + +SPIDER_SYSVAR_VALUE_FUNC(my_bool, general_log) + +/* + FALSE: no pushdown hints + TRUE: pushdown hints + */ +static MYSQL_THDVAR_BOOL( + index_hint_pushdown, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "switch to control if push down index hint, like force_index", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +SPIDER_THDVAR_VALUE_FUNC(my_bool, index_hint_pushdown) + +static uint spider_max_connections; +static MYSQL_SYSVAR_UINT( + max_connections, + spider_max_connections, + PLUGIN_VAR_RQCMDARG, + "the values, as the max conncetion from spider to remote mysql. Default 0, mean unlimit the connections", + NULL, + NULL, + 0, /* def */ + 0, /* min */ + 99999, /* max */ + 0 /* blk */ +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, max_connections) + +static uint spider_conn_wait_timeout; +static MYSQL_SYSVAR_UINT( + conn_wait_timeout, + spider_conn_wait_timeout, + PLUGIN_VAR_RQCMDARG, + "the values, as the max waiting time when spider get a remote conn", + NULL, + NULL, + 10, /* def */ + 0, /* min */ + 1000, /* max */ + 0 /* blk */ +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, conn_wait_timeout) + +static uint spider_log_result_errors; +/* + 0: no log + 1: log error + 2: log warning summary + 3: log warning + 4: log info + */ +static MYSQL_SYSVAR_UINT( + log_result_errors, + spider_log_result_errors, + PLUGIN_VAR_RQCMDARG, + "Log error from remote server in error log", + NULL, + NULL, + 0, + 0, + 4, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, log_result_errors) + +static uint spider_log_result_error_with_sql; +/* + 0: no log + 1: log spider sql at logging result errors + 2: log user sql at logging result errors + 3: log both sql at logging result errors + */ +static MYSQL_SYSVAR_UINT( + log_result_error_with_sql, + spider_log_result_error_with_sql, + PLUGIN_VAR_RQCMDARG, + "Log sql at logging result errors", + NULL, + NULL, + 0, + 0, + 3, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, log_result_error_with_sql) + +/* + 0: server_id + thread_id + 1: server_id + thread_id + query_id + */ +static MYSQL_THDVAR_UINT( + internal_xa_id_type, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The type of internal_xa id", /* comment */ + NULL, /* check */ + NULL, /* update */ + 0, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_VALUE_FUNC(uint, internal_xa_id_type) + +/* + -1 :fallback to default + 0 :OFF + 1 :automatic channel + 2-63 :use custom channel + */ +static MYSQL_THDVAR_INT( + casual_read, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Read casually if it is possible", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 63, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, casual_read) + +static my_bool spider_dry_access; +static MYSQL_SYSVAR_BOOL( + dry_access, + spider_dry_access, + PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, + "dry access", + NULL, + NULL, + FALSE +); + +SPIDER_SYSVAR_VALUE_FUNC(my_bool, dry_access) + +/* + -1 :fallback to default + 0 :fast + 1 :correct delete row number + */ +static MYSQL_THDVAR_INT( + delete_all_rows_type, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "The type of delete_all_rows", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, delete_all_rows_type) + +/* + -1 :fallback to default + 0 :compact + 1 :add original table name + */ +static MYSQL_THDVAR_INT( + bka_table_name_type, /* name */ + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */ + "The type of temporary table name for bka", /* comment */ + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 0, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, bka_table_name_type) + +/* + -1 :fallback to default + 0 :off + 1 :on + */ +static MYSQL_THDVAR_INT( + use_cond_other_than_pk_for_update, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use all conditions even if condition has pk", /* comment */ + NULL, /* check */ + NULL, /* update */ + 1, /* def */ + 0, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_VALUE_FUNC(int, use_cond_other_than_pk_for_update) + +static int spider_store_last_sts; +/* + -1 : fallback to default + 0 : do not store + 1 : do store + */ +static MYSQL_SYSVAR_INT( + store_last_sts, + spider_store_last_sts, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, + "Store last sts result into system table", + NULL, + spider_var_deprecated_int, + 1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(int, store_last_sts) + +static int spider_store_last_crd; +/* + -1 : fallback to default + 0 : do not store + 1 : do store + */ +static MYSQL_SYSVAR_INT( + store_last_crd, + spider_store_last_crd, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, + "Store last crd result into system table", + NULL, + spider_var_deprecated_int, + 1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(int, store_last_crd) + +static int spider_load_sts_at_startup; +/* + -1 : fallback to default + 0 : do not load + 1 : do load + */ +static MYSQL_SYSVAR_INT( + load_sts_at_startup, + spider_load_sts_at_startup, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, + "Load sts from system table at startup", + NULL, + spider_var_deprecated_int, + 1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(int, load_sts_at_startup) + +static int spider_load_crd_at_startup; +/* + -1 : fallback to default + 0 : do not load + 1 : do load + */ +static MYSQL_SYSVAR_INT( + load_crd_at_startup, + spider_load_crd_at_startup, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, + "Load crd from system table at startup", + NULL, + spider_var_deprecated_int, + 1, + -1, + 1, + 0 +); + +SPIDER_SYSVAR_OVERRIDE_VALUE_FUNC(int, load_crd_at_startup) + +static uint spider_table_sts_thread_count; +/* + 1-: thread count + */ +static MYSQL_SYSVAR_UINT( + table_sts_thread_count, + spider_table_sts_thread_count, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Static thread count of table sts", + NULL, + NULL, + 10, + 1, + 4294967295U, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, table_sts_thread_count) + +static uint spider_table_crd_thread_count; +/* + 1-: thread count + */ +static MYSQL_SYSVAR_UINT( + table_crd_thread_count, + spider_table_crd_thread_count, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Static thread count of table crd", + NULL, + NULL, + 10, + 1, + 4294967295U, + 0 +); + +SPIDER_SYSVAR_VALUE_FUNC(uint, table_crd_thread_count) + +static int spider_slave_trx_isolation; +/* + -1 :off + 0 :read uncommitted + 1 :read committed + 2 :repeatable read + 3 :serializable + */ +static MYSQL_SYSVAR_INT( + slave_trx_isolation, + spider_slave_trx_isolation, + PLUGIN_VAR_RQCMDARG, + "Transaction isolation level when Spider table is used by slave SQL thread", + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 3, /* max */ + 0 /* blk */ +); + +SPIDER_SYSVAR_VALUE_FUNC(int, slave_trx_isolation) + +/* + -1 :not set + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + remote_wait_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout on remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + -1, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_remote_wait_timeout( + THD *thd +) { + DBUG_ENTER("spider_param_remote_wait_timeout"); + if (likely(thd)) + DBUG_RETURN(THDVAR(thd, remote_wait_timeout)); + DBUG_RETURN(-1); +} + +/* + -1 :not set + 0-:seconds of timeout + */ +static MYSQL_THDVAR_INT( + wait_timeout, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Wait timeout of setting to remote server", /* comment */ + NULL, /* check */ + NULL, /* update */ + 604800, /* def */ + -1, /* min */ + 2147483647, /* max */ + 0 /* blk */ +); + +int spider_param_wait_timeout( + THD *thd +) { + DBUG_ENTER("spider_param_wait_timeout"); + if (likely(thd)) + DBUG_RETURN(THDVAR(thd, wait_timeout)); + DBUG_RETURN(604800); +} + +/* + FALSE: no sync + TRUE: sync + */ +static MYSQL_THDVAR_BOOL( + sync_sql_mode, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Sync sql_mode", /* comment */ + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, sync_sql_mode) + +/* + -1 : fallback to default + 0 : do not strict + 1 : do strict + */ +static MYSQL_THDVAR_INT( + strict_group_by, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Use columns in select clause strictly for group by clause", + NULL, /* check */ + spider_var_deprecated_int, /* update */ + 1, /* def */ + -1, /* min */ + 1, /* max */ + 0 /* blk */ +); + +SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, strict_group_by) + +/* + -1 : use table parameter + 0 : do not strict + 1 : do strict + */ +static MYSQL_THDVAR_BOOL( + direct_aggregate, /* name */ + PLUGIN_VAR_RQCMDARG, /* opt */ + "Whether to enable direct aggregate", + NULL, /* check */ + NULL, /* update */ + TRUE /* def */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, direct_aggregate) + +static MYSQL_THDVAR_BOOL( + disable_group_by_handler, /* name */ + PLUGIN_VAR_OPCMDARG, /* opt */ + "Disables the group by handler", /* comment */ + NULL, /* check */ + NULL, /* update */ + FALSE /* def */ +); + +SPIDER_THDVAR_VALUE_FUNC(bool, disable_group_by_handler) + +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(xa_register_mode), + 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), + 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(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(buffer_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(quick_page_byte), + MYSQL_SYSVAR(low_mem_read), + MYSQL_SYSVAR(select_column_mode), + MYSQL_SYSVAR(bgs_mode), + MYSQL_SYSVAR(bgs_first_read), + MYSQL_SYSVAR(bgs_second_read), + MYSQL_SYSVAR(first_read), + MYSQL_SYSVAR(second_read), + MYSQL_SYSVAR(crd_interval), + MYSQL_SYSVAR(crd_mode), + MYSQL_SYSVAR(crd_sync), + MYSQL_SYSVAR(store_last_crd), + MYSQL_SYSVAR(load_crd_at_startup), + MYSQL_SYSVAR(crd_type), + MYSQL_SYSVAR(crd_weight), + MYSQL_SYSVAR(crd_bg_mode), + MYSQL_SYSVAR(sts_interval), + MYSQL_SYSVAR(sts_mode), + MYSQL_SYSVAR(sts_sync), + MYSQL_SYSVAR(store_last_sts), + MYSQL_SYSVAR(load_sts_at_startup), + MYSQL_SYSVAR(sts_bg_mode), + MYSQL_SYSVAR(ping_interval_at_trx_start), + 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(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(error_read_mode), + MYSQL_SYSVAR(error_write_mode), + MYSQL_SYSVAR(skip_default_condition), + MYSQL_SYSVAR(skip_parallel_search), + MYSQL_SYSVAR(direct_order_limit), + MYSQL_SYSVAR(read_only_mode), + MYSQL_SYSVAR(general_log), + MYSQL_SYSVAR(index_hint_pushdown), + MYSQL_SYSVAR(max_connections), + MYSQL_SYSVAR(conn_wait_timeout), + MYSQL_SYSVAR(log_result_errors), + MYSQL_SYSVAR(log_result_error_with_sql), + MYSQL_SYSVAR(internal_xa_id_type), + MYSQL_SYSVAR(casual_read), + MYSQL_SYSVAR(dry_access), + MYSQL_SYSVAR(delete_all_rows_type), + MYSQL_SYSVAR(bka_table_name_type), + MYSQL_SYSVAR(use_cond_other_than_pk_for_update), + MYSQL_SYSVAR(connect_error_interval), + MYSQL_SYSVAR(table_sts_thread_count), + MYSQL_SYSVAR(table_crd_thread_count), + MYSQL_SYSVAR(slave_trx_isolation), + MYSQL_SYSVAR(remote_wait_timeout), + MYSQL_SYSVAR(wait_timeout), + MYSQL_SYSVAR(sync_sql_mode), + MYSQL_SYSVAR(strict_group_by), + MYSQL_SYSVAR(direct_aggregate), + MYSQL_SYSVAR(disable_group_by_handler), + 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, + SPIDER_HEX_VERSION, + spider_status_variables, + spider_system_variables, + NULL, + 0, +}, +spider_i_s_alloc_mem, +spider_i_s_wrapper_protocols +mysql_declare_plugin_end; + +maria_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, + SPIDER_HEX_VERSION, + spider_status_variables, + spider_system_variables, + SPIDER_DETAIL_VERSION, + MariaDB_PLUGIN_MATURITY_STABLE +}, +spider_i_s_alloc_mem_maria, +spider_i_s_wrapper_protocols_maria +maria_declare_plugin_end; diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h new file mode 100644 index 00000000..4c26e66c --- /dev/null +++ b/storage/spider/spd_param.h @@ -0,0 +1,370 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software); you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation); version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY); without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program); if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +constexpr uint spider_udf_table_lock_mutex_count= 20; +constexpr uint spider_udf_table_mon_mutex_count= 20; + +my_bool spider_param_support_xa(); +my_bool spider_param_connect_mutex(); +uint spider_param_connect_error_interval(); +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 +); +uint spider_param_xa_register_mode( + 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 +); +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_use_default_database( + THD *thd +); +int 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_buffer_size( + THD *thd, + int buffer_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 +); +longlong spider_param_quick_page_byte( + THD *thd, + longlong quick_page_byte +); +int spider_param_low_mem_read( + THD *thd, + int low_mem_read +); +int spider_param_select_column_mode( + THD *thd, + int select_column_mode +); +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 +); +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 +); +int spider_param_crd_sync( + THD *thd, + int crd_sync +); +int spider_param_crd_type( + THD *thd, + int crd_type +); +double spider_param_crd_weight( + THD *thd, + double crd_weight +); +int spider_param_crd_bg_mode( + THD *thd, + int crd_bg_mode +); +double spider_param_sts_interval( + THD *thd, + double sts_interval +); +int spider_param_sts_mode( + THD *thd, + int sts_mode +); +int spider_param_sts_sync( + THD *thd, + int sts_sync +); +int spider_param_sts_bg_mode( + THD *thd, + int sts_bg_mode +); +double spider_param_ping_interval_at_trx_start( + THD *thd +); +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 +); +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_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 +); +int spider_param_skip_parallel_search( + THD *thd, + int skip_parallel_search +); +longlong spider_param_direct_order_limit( + THD *thd, + longlong direct_order_limit +); +int spider_param_read_only_mode( + THD *thd, + int read_only_mode +); +my_bool spider_param_general_log(); +my_bool spider_param_index_hint_pushdown( + THD *thd +); +uint spider_param_max_connections(); +uint spider_param_conn_wait_timeout(); +uint spider_param_internal_lock_wait_timeout(); +uint spider_param_log_result_errors(); +uint spider_param_log_result_error_with_sql(); +uint spider_param_internal_xa_id_type( + THD *thd +); +int spider_param_casual_read( + THD *thd, + int casual_read +); +my_bool spider_param_dry_access(); +int spider_param_delete_all_rows_type( + THD *thd, + int delete_all_rows_type +); +int spider_param_bka_table_name_type( + THD *thd, + int bka_table_name_type +); +int spider_param_use_cond_other_than_pk_for_update( + THD *thd +); +int spider_param_store_last_sts( + int store_last_sts +); +int spider_param_store_last_crd( + int store_last_crd +); +int spider_param_load_sts_at_startup( + int load_sts_at_startup +); +int spider_param_load_crd_at_startup( + int load_crd_at_startup +); +uint spider_param_table_sts_thread_count(); +uint spider_param_table_crd_thread_count(); +int spider_param_slave_trx_isolation(); +int spider_param_remote_wait_timeout( + THD *thd +); +int spider_param_wait_timeout( + THD *thd +); +bool spider_param_sync_sql_mode( + THD *thd +); +int spider_param_strict_group_by( + THD *thd, + int strict_group_by +); +bool spider_param_direct_aggregate(THD *thd); +bool spider_param_disable_group_by_handler(THD *thd); diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc new file mode 100644 index 00000000..b331a9fe --- /dev/null +++ b/storage/spider/spd_ping_table.cc @@ -0,0 +1,1825 @@ +/* Copyright (C) 2009-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_acl.h" +#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 bool volatile *spd_abort_loop; + +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 + +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, + char *static_link_id, + uint static_link_id_length, + 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; + my_hash_value_type hash_value; + 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_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())); + hash_value = my_calc_hash( + &spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) str->c_ptr(), str->length()); + pthread_mutex_lock(&spider_udf_table_mon_mutexes[mutex_hash]); + mon_table_cache_version = (ulonglong) spider_mon_table_cache_version; + 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 + ) + { + 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, static_link_id, static_link_id_length, + 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; + table_mon_list->key_hash_value = hash_value; + if (my_hash_insert(&spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) table_mon_list)) + { + 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"); + my_hash_delete(&spider_udf_table_mon_list_hash[mutex_hash], + (uchar*) table_mon_list); + 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; +} + +int 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_CONNECT_INFO_MAX_LEN + 1]; + 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)); + char *buf = (char *) my_alloca(conv_name_length + link_idx_str_length + 1); + if (!buf) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + spider_string conv_name_str(buf, conv_name_length + link_idx_str_length + 1, + system_charset_info); + 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_udf_table_mon_mutex_count); + 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()); + pthread_mutex_lock(&spider_udf_table_mon_mutexes[mutex_hash]); + 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()))) + spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list); + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[mutex_hash]); + my_afree(buf); + DBUG_RETURN(0); +} + +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; + SPIDER_Open_tables_backup open_tables_backup; + 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; + } + if (table_mon_list->share->static_link_ids[0]) + { + spider_store_tables_name(table_link_mon, name, name_length); + spider_store_tables_link_idx_str(table_link_mon, + table_mon_list->share->static_link_ids[0], + table_mon_list->share->static_link_ids_lengths[0]); + 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; + } + } + 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, (uint) (sizeof(SPIDER_TABLE_MON)), + &tmp_share, (uint) (sizeof(SPIDER_SHARE)), + &tmp_connect_info, + (uint) (sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT), + &tmp_connect_info_length, + (uint) (sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT), + &tmp_long, (uint) (sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT), + &tmp_longlong, + (uint) (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; + table_mon->parent = table_mon_list; + 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, + NULL, + NULL, + 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, + char *static_link_id, + uint static_link_id_length, + uint32 server_id, + spider_string *str, + bool need_lock, + int *error_num +) { + TABLE *table_tables = NULL; + SPIDER_Open_tables_backup open_tables_backup; + 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, (uint) (sizeof(SPIDER_TABLE_MON_LIST)), + &tmp_share, (uint) (sizeof(SPIDER_SHARE)), + &tmp_connect_info, + (uint) (sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT), + &tmp_connect_info_length, + (uint) (sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT), + &tmp_long, + (uint) (sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT), + &tmp_longlong, + (uint) (sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT), + &key_str, (uint) (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); + if (static_link_id) + { + spider_store_tables_static_link_id(table_tables, + static_link_id, static_link_id_length); + if ( + (*error_num = spider_get_sys_table_by_idx(table_tables, table_key, 2, + SPIDER_SYS_TABLES_UIDX1_COL_CNT)) || + (*error_num = spider_get_sys_tables_link_idx( + table_tables, &link_idx, &mem_root)) + ) { + table_tables->file->print_error(*error_num, MYF(0)); + goto error; + } + } else { + spider_store_tables_link_idx(table_tables, link_idx); + if ( + (*error_num = spider_check_sys_table(table_tables, table_key)) + ) { + table_tables->file->print_error(*error_num, MYF(0)); + goto error; + } + } + 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)) + ) { + 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, + NULL, + NULL, + 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_mutex_init(spd_key_mutex_mon_list_caller, + &table_mon_list->caller_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_caller_mutex_init; + } + if (mysql_mutex_init(spd_key_mutex_mon_list_receptor, + &table_mon_list->receptor_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_receptor_mutex_init; + } + if (mysql_mutex_init(spd_key_mutex_mon_list_monitor, + &table_mon_list->monitor_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_monitor_mutex_init; + } + if (mysql_mutex_init(spd_key_mutex_mon_list_update_status, + &table_mon_list->update_status_mutex, MY_MUTEX_INIT_FAST)) + { + *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"); + if ( + !(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]); + *error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; + goto error; + } +#ifndef DBUG_OFF + DBUG_PRINT("info",("spider conn->thd=%p", conn->thd)); + if (conn->thd) + { + DBUG_PRINT("info",("spider query_id=%lld", conn->thd->query_id)); + } +#endif + conn->error_mode = 0; + DBUG_RETURN(conn); + +error: + DBUG_RETURN(NULL); +} + +int spider_get_ping_table_gtid_pos( + SPIDER_TRX *trx, + THD *thd, + spider_string *str, + uint conv_name_length, + int failed_link_idx, + uint32 server_id, + bool need_lock, + spider_string *tmp_str +) { + int error_num, source_link_idx, need_mon; + char table_key[MAX_KEY_LENGTH]; + TABLE *table_tables, *table_gtid_pos; + SPIDER_Open_tables_backup open_tables_backup_tables; +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + SPIDER_Open_tables_backup open_tables_backup_gtid_pos; +#endif + MEM_ROOT mem_root; + long link_status; + long monitoring_binlog_pos_at_failing; + SPIDER_TABLE_MON_LIST *table_mon_list; + SPIDER_CONN *ping_conn = NULL; + char *static_link_id; + uint static_link_id_length; + DBUG_ENTER("spider_get_ping_table_gtid_pos"); + + /* + select * from + mysql.spider_tables + where + db_name = setted db_name and + table_name = setted table_name + */ +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup_tables, + need_lock, &error_num)) + ) + goto error_open_table_tables; + + if ( + !(table_gtid_pos = spider_open_sys_table( + thd, SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR, + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN, TRUE, + &open_tables_backup_gtid_pos, need_lock, &error_num)) + ) + goto error_open_table_gtid_pos; +#else + TABLE_LIST tables_tables; + TABLE_LIST tables_gtid_pos; + TABLE_LIST *tables = &tables_tables; + LEX_CSTRING db_name = + { + "mysql", + sizeof("mysql") - 1 + }; + LEX_CSTRING tbl_name_tables = + { + SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN + }; + LEX_CSTRING tbl_name_gtid_pos = + { + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR, + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN + }; + tables_tables.init_one_table(&db_name, &tbl_name_tables, 0, TL_READ); + tables_gtid_pos.init_one_table(&db_name, &tbl_name_gtid_pos, 0, TL_READ); + MDL_REQUEST_INIT(&tables_tables.mdl_request, MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(&tables_tables), + SPIDER_TABLE_LIST_table_name_str(&tables_tables), + MDL_SHARED_READ, MDL_TRANSACTION); + MDL_REQUEST_INIT(&tables_gtid_pos.mdl_request, MDL_key::TABLE, + SPIDER_TABLE_LIST_db_str(&tables_gtid_pos), + SPIDER_TABLE_LIST_table_name_str(&tables_gtid_pos), + MDL_SHARED_READ, MDL_TRANSACTION); + tables_tables.next_global = &tables_gtid_pos; + if (spider_sys_open_and_lock_tables(thd, &tables, + &open_tables_backup_tables)) + { + error_num = my_errno; + goto error_open_table_tables; + } + table_tables = tables_tables.table; + table_gtid_pos = tables_gtid_pos.table; +#endif + + table_tables->use_all_columns(); + table_gtid_pos->use_all_columns(); + spider_store_tables_name(table_tables, str->ptr(), conv_name_length); + spider_store_tables_name(table_gtid_pos, str->ptr(), conv_name_length); + spider_store_binlog_pos_failed_link_idx(table_gtid_pos, failed_link_idx); + if ((error_num = spider_get_sys_table_by_idx(table_tables, table_key, 0, + SPIDER_SYS_TABLES_PK_COL_CNT - 1))) + { + if (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE) + { + error_num = 0; + } + goto error_get_sys_table_by_idx; + } + + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + do { + if ( + (error_num = spider_get_sys_tables_link_status(table_tables, + &link_status, &mem_root)) || + (error_num = spider_get_sys_tables_static_link_id(table_tables, + &static_link_id, &static_link_id_length, &mem_root)) || + (error_num = spider_get_sys_tables_monitoring_binlog_pos_at_failing( + table_tables, &monitoring_binlog_pos_at_failing, &mem_root)) + ) { + goto error_get_sys_tables_link_status; + } + + if (link_status == 1 && monitoring_binlog_pos_at_failing > 0) + { + if ((error_num = spider_get_sys_tables_link_idx(table_tables, + &source_link_idx, &mem_root))) + { + goto error_get_sys_tables_link_idx; + } + if ( + (table_mon_list = spider_get_ping_table_mon_list( + trx, + thd, + str, + conv_name_length, + source_link_idx, + static_link_id, + static_link_id_length, + server_id, + need_lock, + &error_num + )) + ) { + SPIDER_DB_RESULT *res1 = NULL; + SPIDER_DB_RESULT *res2 = NULL; + if ( + (ping_conn = spider_get_ping_table_tgt_conn(trx, + table_mon_list->share, &error_num + )) && + !(error_num = ping_conn->db_conn->show_master_status( + trx, table_mon_list->share, 0, &need_mon, table_gtid_pos, tmp_str, + monitoring_binlog_pos_at_failing == 1 ? 0 : 1, &res1, &res2)) + ) { + spider_store_binlog_pos_source_link_idx( + table_gtid_pos, source_link_idx); + spider_insert_sys_table(table_gtid_pos); + } + if (res1) + { + res1->free_result(); + delete res1; + } + if (res2) + { + res2->free_result(); + delete res2; + } + spider_free_ping_table_mon_list(table_mon_list); + } + } + + error_num = spider_sys_index_next_same(table_tables, table_key); + } while (error_num == 0); + free_root(&mem_root, MYF(0)); + + if ((error_num = spider_sys_index_end(table_tables))) + { + goto error_sys_index_end; + } +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + spider_close_sys_table(thd, table_gtid_pos, + &open_tables_backup_gtid_pos, need_lock); +#endif + spider_close_sys_table(thd, table_tables, &open_tables_backup_tables, + need_lock); + + DBUG_RETURN(0); + +error_get_sys_tables_link_idx: +error_get_sys_tables_link_status: + free_root(&mem_root, MYF(0)); + spider_sys_index_end(table_tables); +error_sys_index_end: +error_get_sys_table_by_idx: +#ifdef SPIDER_REQUIRE_DEFINE_FOR_SECONDARY_OPEN_TABLES_BACKUP + spider_close_sys_table(thd, table_gtid_pos, + &open_tables_backup_gtid_pos, + need_lock); +error_open_table_gtid_pos: +#endif + spider_close_sys_table(thd, table_tables, &open_tables_backup_tables, + need_lock); +error_open_table_tables: + DBUG_RETURN(error_num); +} + +int spider_init_ping_table_mon_cache( + THD *thd, + MEM_ROOT *mem_root, + bool need_lock +) { + int error_num, same; + uint old_elements; + TABLE *table_link_mon = NULL; + SPIDER_Open_tables_backup open_tables_backup; + 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); + old_elements = spider_mon_table_cache.max_element; + if (push_dynamic(&spider_mon_table_cache, (uchar *) &mon_key)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_push_dynamic; + } + if (spider_mon_table_cache.max_element != old_elements) + { + spider_free_mem_calc(spider_current_trx, + spider_mon_table_cache_id, + old_elements * + spider_mon_table_cache.size_of_element); + spider_alloc_calc_mem(spider_current_trx, + spider_mon_table_cache, + spider_mon_table_cache.max_element * + spider_mon_table_cache.size_of_element); + } + } + + 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); + 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, + old_elements * + spider_mon_table_cache.size_of_element); + spider_alloc_calc_mem(spider_current_trx, + spider_mon_table_cache, + 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]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(table_name = get_field(mem_root, table->field[1]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(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, server_id; + 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], buf2[MAX_FIELD_WIDTH]; + spider_string conv_name(buf, sizeof(buf), system_charset_info); + spider_string tmp_str(buf2, sizeof(buf2), system_charset_info); + int conv_name_length; + char link_idx_str[SPIDER_CONNECT_INFO_MAX_LEN + 1]; + int link_idx_str_length; + char *static_link_id = NULL; + int static_link_id_length = 0; + bool get_lock = FALSE, status_changed_to_ng = FALSE; + DBUG_ENTER("spider_ping_table_body"); + conv_name.init_calc_mem(135); + tmp_str.init_calc_mem(247); + conv_name.length(0); + server_id = global_system_variables.server_id; + if ( + thd->open_tables != 0 || + thd->handler_tables_hash.records != 0 || + thd->derived_tables != 0 || + thd->lock != 0 || + thd->locked_tables_list.locked_tables() || + thd->locked_tables_mode != LTM_NONE + ) { + 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); + } 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); + } + goto error; + } + + if ( + args->lengths[0] > SPIDER_CONNECT_INFO_MAX_LEN + ) { + my_printf_error(ER_SPIDER_UDF_PARAM_TOO_LONG_NUM, + ER_SPIDER_UDF_PARAM_TOO_LONG_STR, MYF(0), "table name"); + goto error; + } + if ( + args->lengths[0] == 0 + ) { + my_printf_error(ER_SPIDER_UDF_PARAM_REQIRED_NUM, + ER_SPIDER_UDF_PARAM_REQIRED_STR, MYF(0), "table name"); + goto error; + } + if (args->arg_type[1] == STRING_RESULT) + { + if ( + !args->args[1] + ) { + my_printf_error(ER_SPIDER_UDF_PARAM_REQIRED_NUM, + ER_SPIDER_UDF_PARAM_REQIRED_STR, MYF(0), "link id"); + goto error; + } + if ( + args->lengths[1] > SPIDER_CONNECT_INFO_MAX_LEN + ) { + my_printf_error(ER_SPIDER_UDF_PARAM_TOO_LONG_NUM, + ER_SPIDER_UDF_PARAM_TOO_LONG_STR, MYF(0), "link id"); + goto error; + } + link_idx_str_length = args->lengths[1]; + memcpy(link_idx_str, args->args[1], link_idx_str_length + 1); + if (link_idx_str[0] >= '0' && link_idx_str[0] <= '9') + { + link_idx = atoi(link_idx_str); + } else { + link_idx = -1; + static_link_id = link_idx_str; + static_link_id_length = link_idx_str_length; + } + } else { + link_idx = (int) (args->args[1] ? *((longlong *) args->args[1]) : 0); + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d", + link_idx)); + } + 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 *) ""; + + 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 (!(table_mon_list = spider_get_ping_table_mon_list(trx, trx->thd, + &conv_name, conv_name_length, link_idx, + static_link_id, static_link_id_length, + server_id, TRUE, &error_num))) + 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 { + first_sid = server_id; + 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 + )) + ) { + DBUG_PRINT("info",("spider table_mon_list->mon_status == SPIDER_LINK_MON_NG:%s", + table_mon_list->mon_status == SPIDER_LINK_MON_NG ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider error_num=%d", error_num)); + DBUG_PRINT("info",("spider tmp_error_num=%d", tmp_error_num)); + if (tmp_error_num == HA_ERR_OUT_OF_MEM) + goto error_with_free_table_mon_list; + else if(tmp_error_num) + thd->clear_error(); + if (tmp_error_num != ER_CON_COUNT_ERROR) + { + fault_count++; + error_num = 0; + if ( + !(flags & SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES) && + 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); +*/ + pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + 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_update_link_status_for_share(conv_name.c_ptr(), + conv_name_length, link_idx, 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); + status_changed_to_ng = TRUE; + } +/* + pthread_mutex_unlock(&table_mon_list->update_status_mutex); +*/ + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + if (status_changed_to_ng) + { + bool is_error = trx->thd->is_error(); + spider_get_ping_table_gtid_pos(trx, trx->thd, + &conv_name, conv_name_length, link_idx, server_id, TRUE, + &tmp_str); + if (!is_error && trx->thd->is_error()) + trx->thd->clear_error(); + } + } + goto end; + } + } + } else { + success_count++; + if ( + !(flags & SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES) && + 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 ( + (flags & SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES) && + 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 3")); + if (table_mon_list->mon_status != SPIDER_LINK_MON_NG) + { +/* + pthread_mutex_lock(&table_mon_list->update_status_mutex); +*/ + pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + 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_update_link_status_for_share(conv_name.c_ptr(), + conv_name_length, link_idx, 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); + status_changed_to_ng = TRUE; + } +/* + pthread_mutex_unlock(&table_mon_list->update_status_mutex); +*/ + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + if (status_changed_to_ng) + { + bool is_error = trx->thd->is_error(); + spider_get_ping_table_gtid_pos(trx, trx->thd, + &conv_name, conv_name_length, link_idx, server_id, TRUE, + &tmp_str); + if (!is_error && trx->thd->is_error()) + trx->thd->clear_error(); + } + } + } else if ( + (flags & SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES) && + 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 2")); + } else 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); +*/ + pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + 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_update_link_status_for_share(conv_name.c_ptr(), + conv_name_length, link_idx, 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); + status_changed_to_ng = TRUE; + } +/* + pthread_mutex_unlock(&table_mon_list->update_status_mutex); +*/ + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + if (status_changed_to_ng) + { + bool is_error = trx->thd->is_error(); + spider_get_ping_table_gtid_pos(trx, trx->thd, + &conv_name, conv_name_length, link_idx, server_id, TRUE, + &tmp_str); + if (!is_error && trx->thd->is_error()) + trx->thd->clear_error(); + } + } + 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[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 3rd, 4,6,7,8," + "9th and 10th argument"); + goto error; + } + if ( + args->arg_type[1] != INT_RESULT && + args->arg_type[1] != STRING_RESULT + ) { + strcpy(message, "spider_ping_table() requires string or integer for " + "2nd argument"); + goto error; + } + + if (!(trx = spider_get_trx(thd, TRUE, &error_num))) + { + my_error(error_num, MYF(0)); + strcpy(message, spider_stmt_da_message(thd)); + 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, + int base_link_idx, + 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, + long monitoring_flag, + 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_CONNECT_INFO_MAX_LEN + 1]; + 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); + } + DBUG_PRINT("info",("spider thd->killed=%s", + thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL")); + DBUG_PRINT("info",("spider abort_loop=%s", + *spd_abort_loop ? "TRUE" : "FALSE")); + if ( + (thd && thd->killed) || + *spd_abort_loop + ) { + DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); + } + + if (share->static_link_ids[link_idx]) + { + memcpy(link_idx_str, share->static_link_ids[link_idx], + share->static_link_ids_lengths[link_idx] + 1); + link_idx_str_length = share->static_link_ids_lengths[link_idx]; + } else { + link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d", + link_idx)); + } + char *buf = (char *) my_alloca(conv_name_length + link_idx_str_length + 1); + if (!buf) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + 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); + 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 (monitoring_flag & 1) + flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES; + + if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd, + &conv_name_str, conv_name_length, link_idx, + share->static_link_ids[link_idx], + share->static_link_ids_lengths[link_idx], + server_id, need_lock, &error_num))) + { + my_afree(buf); + 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)); + pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG; + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + 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]); + my_afree(buf); + 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) + { + DBUG_PRINT("info",("spider thd->killed=%s", + thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL")); + DBUG_PRINT("info",("spider abort_loop=%s", + *spd_abort_loop ? "TRUE" : "FALSE")); + if ( + (thd && thd->killed) || + *spd_abort_loop + ) { + error_num = ER_SPIDER_COND_SKIP_NUM; + break; + } else { + 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; + } + int prev_error = 0; + char prev_error_msg[MYSQL_ERRMSG_SIZE]; + if (thd->is_error()) + { + prev_error = spider_stmt_da_sql_errno(thd); + strmov(prev_error_msg, spider_stmt_da_message(thd)); + 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); +*/ + pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + 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); +*/ + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]); + } + table_mon_list->last_caller_result = mon_table_result.result_status; + if (mon_table_result.result_status == SPIDER_LINK_MON_OK) + { + if (prev_error) + my_message(prev_error, prev_error_msg, MYF(0)); + 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); + DBUG_PRINT("info",("spider thd->killed=%s", + thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL")); + DBUG_PRINT("info",("spider abort_loop=%s", + *spd_abort_loop ? "TRUE" : "FALSE")); + if ( + (thd && thd->killed) || + *spd_abort_loop + ) { + error_num = ER_SPIDER_COND_SKIP_NUM; + } else { + 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); + } + + my_afree(buf); +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 00000000..586ee7af --- /dev/null +++ b/storage/spider/spd_ping_table.h @@ -0,0 +1,119 @@ +/* Copyright (C) 2009-2017 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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, + char *static_link_id, + uint static_link_id_length, + 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 +); + +int 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, + char *static_link_id, + uint static_link_id_length, + 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_get_ping_table_gtid_pos( + SPIDER_TRX *trx, + THD *thd, + spider_string *str, + uint conv_name_length, + int failed_link_idx, + uint32 server_id, + bool need_lock, + spider_string *tmp_str +); + +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, + int base_link_idx, + 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, + long monitoring_flag, + bool need_lock +); diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc new file mode 100644 index 00000000..a0cf104d --- /dev/null +++ b/storage/spider/spd_sys_table.cc @@ -0,0 +1,3776 @@ +/* Copyright (C) 2008-2018 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "key.h" +#include "sql_base.h" +#include "tztime.h" +#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; +extern Time_zone *spd_tz_system; + +#define SPIDER_XA_FORMAT_ID_POS 0 +#define SPIDER_XA_GTRID_LENGTH_POS 1 +#define SPIDER_XA_BQUAL_LENGTH_POS 2 +#define SPIDER_XA_DATA_POS 3 +#define SPIDER_XA_STATUS_POS 4 + +#define SPIDER_XA_MEMBER_FORMAT_ID_POS 0 +#define SPIDER_XA_MEMBER_GTRID_LENGTH_POS 1 +#define SPIDER_XA_MEMBER_BQUAL_LENGTH_POS 2 +#define SPIDER_XA_MEMBER_DATA_POS 3 +#define SPIDER_XA_MEMBER_SCHEME_POS 4 +#define SPIDER_XA_MEMBER_HOST_POS 5 +#define SPIDER_XA_MEMBER_PORT_POS 6 +#define SPIDER_XA_MEMBER_SOCKET_POS 7 +#define SPIDER_XA_MEMBER_USERNAME_POS 8 +#define SPIDER_XA_MEMBER_PASSWORD_POS 9 +#define SPIDER_XA_MEMBER_SSL_CA_POS 10 +#define SPIDER_XA_MEMBER_SSL_CAPATH_POS 11 +#define SPIDER_XA_MEMBER_SSL_CERT_POS 12 +#define SPIDER_XA_MEMBER_SSL_CIPHER_POS 13 +#define SPIDER_XA_MEMBER_SSL_KEY_POS 14 +#define SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS 15 +#define SPIDER_XA_MEMBER_DEFAULT_FILE_POS 16 +#define SPIDER_XA_MEMBER_DEFAULT_GROUP_POS 17 +#define SPIDER_XA_MEMBER_DSN_POS 18 +#define SPIDER_XA_MEMBER_FILEDSN_POS 19 +#define SPIDER_XA_MEMBER_DRIVER_POS 20 +#define SPIDER_XA_FAILED_LOG_THREAD_ID_POS 21 +#define SPIDER_XA_FAILED_LOG_STATUS_POS 22 +#define SPIDER_XA_FAILED_LOG_FAILED_TIME_POS 23 + +#define SPIDER_TABLES_DB_NAME_POS 0 +#define SPIDER_TABLES_TABLE_NAME_POS 1 +#define SPIDER_TABLES_LINK_ID_POS 2 +#define SPIDER_TABLES_PRIORITY_POS 3 +#define SPIDER_TABLES_SERVER_POS 4 +#define SPIDER_TABLES_SCHEME_POS 5 +#define SPIDER_TABLES_HOST_POS 6 +#define SPIDER_TABLES_PORT_POS 7 +#define SPIDER_TABLES_SOCKET_POS 8 +#define SPIDER_TABLES_USERNAME_POS 9 +#define SPIDER_TABLES_PASSWORD_POS 10 +#define SPIDER_TABLES_SSL_CA_POS 11 +#define SPIDER_TABLES_SSL_CAPATH_POS 12 +#define SPIDER_TABLES_SSL_CERT_POS 13 +#define SPIDER_TABLES_SSL_CIPHER_POS 14 +#define SPIDER_TABLES_SSL_KEY_POS 15 +#define SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS 16 +#define SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS 17 +#define SPIDER_TABLES_DEFAULT_FILE_POS 18 +#define SPIDER_TABLES_DEFAULT_GROUP_POS 19 +#define SPIDER_TABLES_DSN_POS 20 +#define SPIDER_TABLES_FILEDSN_POS 21 +#define SPIDER_TABLES_DRIVER_POS 22 +#define SPIDER_TABLES_TGT_DB_NAME_POS 23 +#define SPIDER_TABLES_TGT_TABLE_NAME_POS 24 +#define SPIDER_TABLES_LINK_STATUS_POS 25 +#define SPIDER_TABLES_BLOCK_STATUS_POS 26 +#define SPIDER_TABLES_STATIC_LINK_ID_POS 27 + +#define SPIDER_LINK_MON_SERVERS_DB_NAME_POS 0 +#define SPIDER_LINK_MON_SERVERS_TABLE_NAME_POS 1 +#define SPIDER_LINK_MON_SERVERS_LINK_ID_POS 2 +#define SPIDER_LINK_MON_SERVERS_SID_POS 3 +#define SPIDER_LINK_MON_SERVERS_SERVER_POS 4 +#define SPIDER_LINK_MON_SERVERS_SCHEME_POS 5 +#define SPIDER_LINK_MON_SERVERS_HOST_POS 6 +#define SPIDER_LINK_MON_SERVERS_PORT_POS 7 +#define SPIDER_LINK_MON_SERVERS_SOCKET_POS 8 +#define SPIDER_LINK_MON_SERVERS_USERNAME_POS 9 +#define SPIDER_LINK_MON_SERVERS_PASSWORD_POS 10 +#define SPIDER_LINK_MON_SERVERS_SSL_CA_POS 11 +#define SPIDER_LINK_MON_SERVERS_SSL_CAPATH_POS 12 +#define SPIDER_LINK_MON_SERVERS_SSL_CERT_POS 13 +#define SPIDER_LINK_MON_SERVERS_SSL_CIPHER_POS 14 +#define SPIDER_LINK_MON_SERVERS_SSL_KEY_POS 15 +#define SPIDER_LINK_MON_SERVERS_SSL_VERIFY_SERVER_CERT_POS 16 +#define SPIDER_LINK_MON_SERVERS_DEFAULT_FILE_POS 17 +#define SPIDER_LINK_MON_SERVERS_DEFAULT_GROUP_POS 18 +#define SPIDER_LINK_MON_SERVERS_DSN_POS 19 +#define SPIDER_LINK_MON_SERVERS_FILEDSN_POS 20 +#define SPIDER_LINK_MON_SERVERS_DRIVER_POS 21 + +#define SPIDER_LINK_FAILED_LOG_DB_NAME_POS 0 +#define SPIDER_LINK_FAILED_LOG_TABLE_NAME_POS 1 +#define SPIDER_LINK_FAILED_LOG_LINK_ID_POS 2 +#define SPIDER_LINK_FAILED_LOG_FAILED_TIME_POS 3 + +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_DB_NAME_POS 0 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_TABLE_NAME_POS 1 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_FAILED_LINK_ID_POS 2 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_SOURCE_LINK_ID_POS 3 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS 4 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS 5 +#define SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS 6 + +#define SPIDER_TABLE_STS_DB_NAME_POS 0 +#define SPIDER_TABLE_STS_TABLE_NAME_POS 1 +#define SPIDER_TABLE_STS_DATA_FILE_LENGTH_POS 2 +#define SPIDER_TABLE_STS_MAX_DATA_FILE_LENGTH_POS 3 +#define SPIDER_TABLE_STS_INDEX_FILE_LENGTH_POS 4 +#define SPIDER_TABLE_STS_RECORDS_POS 5 +#define SPIDER_TABLE_STS_MEAN_REC_LENGTH_POS 6 +#define SPIDER_TABLE_STS_CHECK_TIME_POS 7 +#define SPIDER_TABLE_STS_CREATE_TIME_POS 8 +#define SPIDER_TABLE_STS_UPDATE_TIME_POS 9 +#define SPIDER_TABLE_STS_CHECKSUM_POS 10 + +#define SPIDER_TABLE_CRD_DB_NAME_POS 0 +#define SPIDER_TABLE_CRD_TABLE_NAME_POS 1 +#define SPIDER_TABLE_CRD_KEY_SEQ_POS 2 +#define SPIDER_TABLE_CRD_CARDINALITY_POS 3 + +/** + Insert a Spider system table row. + + @param table The spider system table. + @param do_handle_error TRUE if an error message should be printed + before returning. + + @return Error code returned by the write. +*/ + +inline int spider_write_sys_table_row(TABLE *table, bool do_handle_error = TRUE) +{ + int error_num; + THD *thd = table->in_use; + + tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */ + error_num = table->file->ha_write_row(table->record[0]); + reenable_binlog(thd); + + if (error_num && do_handle_error) + table->file->print_error(error_num, MYF(0)); + + return error_num; +} + +/** + Update a Spider system table row. + + @param table The spider system table. + @param do_handle_error TRUE if an error message should be printed + before returning. + + @return Error code returned by the update. +*/ + +inline int spider_update_sys_table_row(TABLE *table, bool do_handle_error = TRUE) +{ + int error_num; + THD *thd = table->in_use; + + tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */ + error_num = table->file->ha_update_row(table->record[1], table->record[0]); + reenable_binlog(thd); + + if (error_num && do_handle_error) + { + if (error_num == HA_ERR_RECORD_IS_THE_SAME) + error_num = 0; + else + table->file->print_error(error_num, MYF(0)); + } + + return error_num; +} + +/** + Delete a Spider system table row. + + @param table The spider system table. + @param record_number Location of the record: 0 or 1. + @param do_handle_error TRUE if an error message should be printed + before returning. + + @return Error code returned by the delete. +*/ + +inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0, + bool do_handle_error = TRUE) +{ + int error_num; + THD *thd = table->in_use; + + tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */ + error_num = table->file->ha_delete_row(table->record[record_number]); + reenable_binlog(thd); + + if (error_num && do_handle_error) + table->file->print_error(error_num, MYF(0)); + + return error_num; +} + +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + SPIDER_Open_tables_backup *open_tables_backup, + bool need_lock, + int *error_num +) { + TABLE *table; + TABLE_LIST tables; + DBUG_ENTER("spider_open_sys_table"); + + +#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias + LEX_CSTRING db_name = + { + "mysql", + sizeof("mysql") - 1 + }; + LEX_CSTRING tbl_name = + { + table_name, + (size_t) table_name_length + }; + tables.init_one_table(&db_name, &tbl_name, 0, (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 (!(table = spider_sys_open_table(thd, &tables, open_tables_backup))) + { + my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM, + ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0), + "mysql", table_name); + *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM; + DBUG_RETURN(NULL); + } + switch (table_name_length) + { + case 9: + if (!memcmp(table_name, SPIDER_SYS_XA_TABLE_NAME_STR, + SPIDER_SYS_XA_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_XA")); + if (table->s->fields != SPIDER_SYS_XA_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + 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; + } + break; + } + DBUG_ASSERT(0); + break; + case 13: + if (!memcmp(table_name, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_TABLES")); + if (table->s->fields != SPIDER_SYS_TABLES_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + 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; + } + break; + } + DBUG_ASSERT(0); + break; + case 16: + if (!memcmp(table_name, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR, + SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_XA_MEMBER")); + if (table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + 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; + } + break; + } + if (!memcmp(table_name, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR, + SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_TABLE_STS")); + if (table->s->fields != SPIDER_SYS_TABLE_STS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_TABLE_STS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + if (!memcmp(table_name, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR, + SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_TABLE_CRD")); + if (table->s->fields != SPIDER_SYS_TABLE_CRD_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 20: + if (!memcmp(table_name, SPIDER_SYS_XA_FAILED_TABLE_NAME_STR, + SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_XA_FAILED")); + if (table->s->fields != SPIDER_SYS_XA_FAILED_TABLE_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_XA_FAILED_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 21: + if (!memcmp(table_name, SPIDER_SYS_RW_TBLS_TABLE_NAME_STR, + SPIDER_SYS_RW_TBLS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_RW_TBLS")); + if (table->s->fields != SPIDER_SYS_RW_TBLS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_RW_TBLS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + } + DBUG_ASSERT(0); + break; + case 22: + if (!memcmp(table_name, SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR, + SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_LINK_FAILED")); + if (table->s->fields != SPIDER_SYS_LINK_FAILED_TABLE_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 23: + if (!memcmp(table_name, SPIDER_SYS_LINK_MON_TABLE_NAME_STR, + SPIDER_SYS_LINK_MON_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_LINK_MON")); + if (table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = 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); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + if (!memcmp(table_name, SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR, + SPIDER_SYS_RWN_TBLS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_RWN_TBLS")); + if (table->s->fields != SPIDER_SYS_RWN_TBLS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 27: + if (!memcmp(table_name, SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR, + SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_RW_TBL_TBLS")); + if (table->s->fields != SPIDER_SYS_RW_TBL_TBLS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 31: + if (!memcmp(table_name, SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR, + SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_RW_TBL_PTTS")); + if (table->s->fields != SPIDER_SYS_RW_TBL_PTTS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + case 34: + if (!memcmp(table_name, SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR, + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_POS_FOR_RECOVERY")); + if (table->s->fields != SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + if (!memcmp(table_name, SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR, + SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_LEN)) + { + DBUG_PRINT("info",("spider checking for SYS_RW_TBL_SPTTS")); + if (table->s->fields != SPIDER_SYS_RW_TBL_SPTTS_COL_CNT) + { + spider_close_sys_table(thd, table, open_tables_backup, need_lock); + table = NULL; + my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM, + ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0), + SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR); + *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM; + goto error_col_num_chk; + } + break; + } + DBUG_ASSERT(0); + break; + default: + DBUG_ASSERT(0); + break; + } + DBUG_RETURN(table); +error_col_num_chk: + DBUG_RETURN(NULL); +} + +void spider_close_sys_table( + THD *thd, + TABLE *table, + SPIDER_Open_tables_backup *open_tables_backup, + bool need_lock +) { + DBUG_ENTER("spider_close_sys_table"); + spider_sys_close_table(thd, open_tables_backup); + DBUG_VOID_RETURN; +} + +bool spider_sys_open_and_lock_tables( + THD *thd, + TABLE_LIST **tables, + SPIDER_Open_tables_backup *open_tables_backup +) { + uint counter; + uint flags = MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | + MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY | MYSQL_OPEN_IGNORE_FLUSH | + MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE; + ulonglong utime_after_lock_backup = thd->utime_after_lock; + DBUG_ENTER("spider_sys_open_and_lock_tables"); + SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, TRUE); + if (open_tables(thd, tables, &counter, flags)) + { + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(TRUE); + } + if (lock_tables(thd, *tables, counter, flags)) + { + SPIDER_sys_close_thread_tables(thd); + SPIDER_restore_backup_open_tables_state(thd, 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, + SPIDER_Open_tables_backup *open_tables_backup +) { + TABLE *table; + ulonglong utime_after_lock_backup = thd->utime_after_lock; + DBUG_ENTER("spider_sys_open_table"); + if (open_tables_backup) + { + SPIDER_reset_n_backup_open_tables_state(thd, open_tables_backup, NULL); + } + 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->s->no_replicate = 1; + } else if (open_tables_backup) + { + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + } + thd->utime_after_lock = utime_after_lock_backup; + DBUG_RETURN(table); +} + +void spider_sys_close_table( + THD *thd, + SPIDER_Open_tables_backup *open_tables_backup +) { + DBUG_ENTER("spider_sys_close_table"); + if (open_tables_backup) + { + SPIDER_sys_close_thread_tables(thd); + SPIDER_restore_backup_open_tables_state(thd, open_tables_backup); + } + DBUG_VOID_RETURN; +} + +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); + + DBUG_RETURN(table->file->ha_index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, HA_READ_KEY_EXACT)); +} + +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); + + DBUG_RETURN(table->file->ha_index_read_idx_map( + table->record[0], 0, (uchar *) table_key, + HA_WHOLE_KEY, find_flag)); +} + +int spider_check_sys_table_for_update_all_columns( + TABLE *table, + char *table_key +) { + DBUG_ENTER("spider_check_sys_table_for_update_all_columns"); + + key_copy( + (uchar *) table_key, + table->record[0], + table->key_info, + table->key_info->key_length); + + DBUG_RETURN(table->file->ha_index_read_idx_map( + table->record[1], 0, (uchar *) table_key, + HA_WHOLE_KEY, HA_READ_KEY_EXACT)); +} + +int spider_get_sys_table_by_idx( + TABLE *table, + char *table_key, + const int idx, + const int col_count +) { + int error_num; + uint key_length; + KEY *key_info = table->key_info + idx; + DBUG_ENTER("spider_get_sys_table_by_idx"); + if ((error_num = spider_sys_index_init(table, idx, FALSE))) + DBUG_RETURN(error_num); + + if ((int) spider_user_defined_key_parts(key_info) == col_count) + { + key_length = key_info->key_length; + } else { + int roop_count; + key_length = 0; + for (roop_count = 0; roop_count < col_count; ++roop_count) + { + key_length += key_info->key_part[roop_count].store_length; + } + } + + key_copy( + (uchar *) table_key, + table->record[0], + key_info, + key_length); + + if ( + (error_num = table->file->ha_index_read_map( + table->record[0], (uchar *) table_key, + make_prev_keypart_map(col_count), HA_READ_KEY_EXACT)) + ) { + 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"); + DBUG_RETURN(table->file->ha_index_next_same( + table->record[0], + (const uchar*) table_key, + table->key_info->key_length)); +} + +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 ( + (error_num = table->file->ha_index_first(table->record[0])) + ) { + spider_sys_index_end(table); + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_sys_index_last( + TABLE *table, + const int idx +) { + int error_num; + DBUG_ENTER("spider_sys_index_last"); + if ((error_num = spider_sys_index_init(table, idx, FALSE))) + DBUG_RETURN(error_num); + + if ( + (error_num = table->file->ha_index_last(table->record[0])) + ) { + 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"); + DBUG_RETURN(table->file->ha_index_next(table->record[0])); +} + +void spider_store_xa_pk( + TABLE *table, + XID *xid +) { + DBUG_ENTER("spider_store_xa_pk"); + table->field[SPIDER_XA_FORMAT_ID_POS]->store(xid->formatID); + table->field[SPIDER_XA_GTRID_LENGTH_POS]->store(xid->gtrid_length); + table->field[SPIDER_XA_DATA_POS]->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[SPIDER_XA_BQUAL_LENGTH_POS]->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[SPIDER_XA_STATUS_POS]->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[SPIDER_XA_MEMBER_FORMAT_ID_POS]->store(xid->formatID); + table->field[SPIDER_XA_MEMBER_GTRID_LENGTH_POS]->store(xid->gtrid_length); + table->field[SPIDER_XA_MEMBER_DATA_POS]->store( + xid->data, + (uint) xid->gtrid_length + xid->bqual_length, + system_charset_info); + table->field[SPIDER_XA_MEMBER_HOST_POS]->store( + conn->tgt_host, + (uint) conn->tgt_host_length, + system_charset_info); + table->field[SPIDER_XA_MEMBER_PORT_POS]->store( + conn->tgt_port); + table->field[SPIDER_XA_MEMBER_SOCKET_POS]->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[SPIDER_XA_MEMBER_BQUAL_LENGTH_POS]->store(xid->bqual_length); + table->field[SPIDER_XA_MEMBER_SCHEME_POS]->store( + conn->tgt_wrapper, + (uint) conn->tgt_wrapper_length, + system_charset_info); + table->field[SPIDER_XA_MEMBER_USERNAME_POS]->store( + conn->tgt_username, + (uint) conn->tgt_username_length, + system_charset_info); + table->field[SPIDER_XA_MEMBER_PASSWORD_POS]->store( + conn->tgt_password, + (uint) conn->tgt_password_length, + system_charset_info); + if (conn->tgt_ssl_ca) + { + table->field[SPIDER_XA_MEMBER_SSL_CA_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_CA_POS]->store( + conn->tgt_ssl_ca, + (uint) conn->tgt_ssl_ca_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_SSL_CA_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_CA_POS]->reset(); + } + if (conn->tgt_ssl_capath) + { + table->field[SPIDER_XA_MEMBER_SSL_CAPATH_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_CAPATH_POS]->store( + conn->tgt_ssl_capath, + (uint) conn->tgt_ssl_capath_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_SSL_CAPATH_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_CAPATH_POS]->reset(); + } + if (conn->tgt_ssl_cert) + { + table->field[SPIDER_XA_MEMBER_SSL_CERT_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_CERT_POS]->store( + conn->tgt_ssl_cert, + (uint) conn->tgt_ssl_cert_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_SSL_CERT_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_CERT_POS]->reset(); + } + if (conn->tgt_ssl_cipher) + { + table->field[SPIDER_XA_MEMBER_SSL_CIPHER_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_CIPHER_POS]->store( + conn->tgt_ssl_cipher, + (uint) conn->tgt_ssl_cipher_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_SSL_CIPHER_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_CIPHER_POS]->reset(); + } + if (conn->tgt_ssl_key) + { + table->field[SPIDER_XA_MEMBER_SSL_KEY_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_KEY_POS]->store( + conn->tgt_ssl_key, + (uint) conn->tgt_ssl_key_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_SSL_KEY_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_KEY_POS]->reset(); + } + if (conn->tgt_ssl_vsc >= 0) + { + table->field[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS]->store( + conn->tgt_ssl_vsc); + } else { + table->field[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS]->reset(); + } + if (conn->tgt_default_file) + { + table->field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS]->store( + conn->tgt_default_file, + (uint) conn->tgt_default_file_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS]->reset(); + } + if (conn->tgt_default_group) + { + table->field[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS]->store( + conn->tgt_default_group, + (uint) conn->tgt_default_group_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS]->reset(); + } + if (conn->tgt_dsn) + { + table->field[SPIDER_XA_MEMBER_DSN_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_DSN_POS]->store( + conn->tgt_dsn, + (uint) conn->tgt_dsn_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_DSN_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_DSN_POS]->reset(); + } + if (conn->tgt_filedsn) + { + table->field[SPIDER_XA_MEMBER_FILEDSN_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_FILEDSN_POS]->store( + conn->tgt_filedsn, + (uint) conn->tgt_filedsn_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_FILEDSN_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_FILEDSN_POS]->reset(); + } + if (conn->tgt_driver) + { + table->field[SPIDER_XA_MEMBER_DRIVER_POS]->set_notnull(); + table->field[SPIDER_XA_MEMBER_DRIVER_POS]->store( + conn->tgt_driver, + (uint) conn->tgt_driver_length, + system_charset_info); + } else { + table->field[SPIDER_XA_MEMBER_DRIVER_POS]->set_null(); + table->field[SPIDER_XA_MEMBER_DRIVER_POS]->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[SPIDER_TABLES_DB_NAME_POS]->store( + ptr_db, + (uint)(ptr_diff_table - 1), + system_charset_info); + DBUG_PRINT("info",("spider field[%u]->null_bit = %d", + SPIDER_TABLES_DB_NAME_POS, + table->field[SPIDER_TABLES_DB_NAME_POS]->null_bit)); + table->field[SPIDER_TABLES_TABLE_NAME_POS]->store( + ptr_table, + (uint) ((my_ptrdiff_t) name_length - ptr_diff_db - ptr_diff_table), + system_charset_info); + DBUG_PRINT("info",("spider field[%u]->null_bit = %d", + SPIDER_TABLES_TABLE_NAME_POS, + table->field[SPIDER_TABLES_TABLE_NAME_POS]->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[SPIDER_TABLES_DB_NAME_POS]->store( + db_name, + db_name_length, + system_charset_info); + DBUG_PRINT("info",("spider field[%u]->null_bit = %d", + SPIDER_TABLES_DB_NAME_POS, + table->field[SPIDER_TABLES_DB_NAME_POS]->null_bit)); + table->field[SPIDER_TABLES_TABLE_NAME_POS]->store( + table_name, + table_name_length, + system_charset_info); + DBUG_PRINT("info",("spider field[%u]->null_bit = %d", + SPIDER_TABLES_TABLE_NAME_POS, + table->field[SPIDER_TABLES_TABLE_NAME_POS]->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[SPIDER_TABLES_LINK_ID_POS]->set_notnull(); + table->field[SPIDER_TABLES_LINK_ID_POS]->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[SPIDER_TABLES_LINK_ID_POS]->store( + link_idx, + link_idx_length, + system_charset_info); + DBUG_PRINT("info",("spider field[%u]->null_bit = %d", + SPIDER_TABLES_LINK_ID_POS, + table->field[SPIDER_TABLES_LINK_ID_POS]->null_bit)); + DBUG_VOID_RETURN; +} + +void spider_store_tables_static_link_id( + TABLE *table, + const char *static_link_id, + const uint static_link_id_length +) { + DBUG_ENTER("spider_store_tables_static_link_id"); + if (static_link_id) + { + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->set_notnull(); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->store( + static_link_id, + static_link_id_length, + system_charset_info); + } else { + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->set_null(); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->reset(); + } + 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[SPIDER_TABLES_PRIORITY_POS]->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[SPIDER_TABLES_SERVER_POS]->set_notnull(); + table->field[SPIDER_TABLES_SERVER_POS]->store( + alter_table->tmp_server_names[link_idx], + (uint) alter_table->tmp_server_names_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_SERVER_POS]->set_null(); + table->field[SPIDER_TABLES_SERVER_POS]->reset(); + } + if (alter_table->tmp_tgt_wrappers[link_idx]) + { + table->field[SPIDER_TABLES_SCHEME_POS]->set_notnull(); + table->field[SPIDER_TABLES_SCHEME_POS]->store( + alter_table->tmp_tgt_wrappers[link_idx], + (uint) alter_table->tmp_tgt_wrappers_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_SCHEME_POS]->set_null(); + table->field[SPIDER_TABLES_SCHEME_POS]->reset(); + } + if (alter_table->tmp_tgt_hosts[link_idx]) + { + table->field[SPIDER_TABLES_HOST_POS]->set_notnull(); + table->field[SPIDER_TABLES_HOST_POS]->store( + alter_table->tmp_tgt_hosts[link_idx], + (uint) alter_table->tmp_tgt_hosts_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_HOST_POS]->set_null(); + table->field[SPIDER_TABLES_HOST_POS]->reset(); + } + if (alter_table->tmp_tgt_ports[link_idx] >= 0) + { + table->field[SPIDER_TABLES_PORT_POS]->set_notnull(); + table->field[SPIDER_TABLES_PORT_POS]->store( + alter_table->tmp_tgt_ports[link_idx]); + } else { + table->field[SPIDER_TABLES_PORT_POS]->set_null(); + table->field[SPIDER_TABLES_PORT_POS]->reset(); + } + if (alter_table->tmp_tgt_sockets[link_idx]) + { + table->field[SPIDER_TABLES_SOCKET_POS]->set_notnull(); + table->field[SPIDER_TABLES_SOCKET_POS]->store( + alter_table->tmp_tgt_sockets[link_idx], + (uint) alter_table->tmp_tgt_sockets_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_SOCKET_POS]->set_null(); + table->field[SPIDER_TABLES_SOCKET_POS]->reset(); + } + if (alter_table->tmp_tgt_usernames[link_idx]) + { + table->field[SPIDER_TABLES_USERNAME_POS]->set_notnull(); + table->field[SPIDER_TABLES_USERNAME_POS]->store( + alter_table->tmp_tgt_usernames[link_idx], + (uint) alter_table->tmp_tgt_usernames_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_USERNAME_POS]->set_null(); + table->field[SPIDER_TABLES_USERNAME_POS]->reset(); + } + if (alter_table->tmp_tgt_passwords[link_idx]) + { + table->field[SPIDER_TABLES_PASSWORD_POS]->set_notnull(); + table->field[SPIDER_TABLES_PASSWORD_POS]->store( + alter_table->tmp_tgt_passwords[link_idx], + (uint) alter_table->tmp_tgt_passwords_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_PASSWORD_POS]->set_null(); + table->field[SPIDER_TABLES_PASSWORD_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_cas[link_idx]) + { + table->field[SPIDER_TABLES_SSL_CA_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_CA_POS]->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[SPIDER_TABLES_SSL_CA_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_CA_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_capaths[link_idx]) + { + table->field[SPIDER_TABLES_SSL_CAPATH_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_CAPATH_POS]->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[SPIDER_TABLES_SSL_CAPATH_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_CAPATH_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_certs[link_idx]) + { + table->field[SPIDER_TABLES_SSL_CERT_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_CERT_POS]->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[SPIDER_TABLES_SSL_CERT_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_CERT_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_ciphers[link_idx]) + { + table->field[SPIDER_TABLES_SSL_CIPHER_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_CIPHER_POS]->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[SPIDER_TABLES_SSL_CIPHER_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_CIPHER_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_keys[link_idx]) + { + table->field[SPIDER_TABLES_SSL_KEY_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_KEY_POS]->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[SPIDER_TABLES_SSL_KEY_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_KEY_POS]->reset(); + } + if (alter_table->tmp_tgt_ssl_vscs[link_idx] >= 0) + { + table->field[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS]->set_notnull(); + table->field[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS]->store( + alter_table->tmp_tgt_ssl_vscs[link_idx]); + } else { + table->field[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS]->set_null(); + table->field[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS]->reset(); + } + table->field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS]-> + set_notnull(); + if (alter_table->tmp_monitoring_binlog_pos_at_failing[link_idx] >= 0) + { + table->field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS]->store( + alter_table->tmp_monitoring_binlog_pos_at_failing[link_idx]); + } else { + table->field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS]->store(0); + } + if (alter_table->tmp_tgt_default_files[link_idx]) + { + table->field[SPIDER_TABLES_DEFAULT_FILE_POS]->set_notnull(); + table->field[SPIDER_TABLES_DEFAULT_FILE_POS]->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[SPIDER_TABLES_DEFAULT_FILE_POS]->set_null(); + table->field[SPIDER_TABLES_DEFAULT_FILE_POS]->reset(); + } + if (alter_table->tmp_tgt_default_groups[link_idx]) + { + table->field[SPIDER_TABLES_DEFAULT_GROUP_POS]->set_notnull(); + table->field[SPIDER_TABLES_DEFAULT_GROUP_POS]->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[SPIDER_TABLES_DEFAULT_GROUP_POS]->set_null(); + table->field[SPIDER_TABLES_DEFAULT_GROUP_POS]->reset(); + } + if (alter_table->tmp_tgt_dsns[link_idx]) + { + table->field[SPIDER_TABLES_DSN_POS]->set_notnull(); + table->field[SPIDER_TABLES_DSN_POS]->store( + alter_table->tmp_tgt_dsns[link_idx], + (uint) alter_table->tmp_tgt_dsns_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_DSN_POS]->set_null(); + table->field[SPIDER_TABLES_DSN_POS]->reset(); + } + if (alter_table->tmp_tgt_filedsns[link_idx]) + { + table->field[SPIDER_TABLES_FILEDSN_POS]->set_notnull(); + table->field[SPIDER_TABLES_FILEDSN_POS]->store( + alter_table->tmp_tgt_filedsns[link_idx], + (uint) alter_table->tmp_tgt_filedsns_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_FILEDSN_POS]->set_null(); + table->field[SPIDER_TABLES_FILEDSN_POS]->reset(); + } + if (alter_table->tmp_tgt_drivers[link_idx]) + { + table->field[SPIDER_TABLES_DRIVER_POS]->set_notnull(); + table->field[SPIDER_TABLES_DRIVER_POS]->store( + alter_table->tmp_tgt_drivers[link_idx], + (uint) alter_table->tmp_tgt_drivers_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_DRIVER_POS]->set_null(); + table->field[SPIDER_TABLES_DRIVER_POS]->reset(); + } + if (alter_table->tmp_tgt_dbs[link_idx]) + { + table->field[SPIDER_TABLES_TGT_DB_NAME_POS]->set_notnull(); + table->field[SPIDER_TABLES_TGT_DB_NAME_POS]->store( + alter_table->tmp_tgt_dbs[link_idx], + (uint) alter_table->tmp_tgt_dbs_lengths[link_idx], + system_charset_info); + } else { + table->field[SPIDER_TABLES_TGT_DB_NAME_POS]->set_null(); + table->field[SPIDER_TABLES_TGT_DB_NAME_POS]->reset(); + } + if (alter_table->tmp_tgt_table_names[link_idx]) + { + table->field[SPIDER_TABLES_TGT_TABLE_NAME_POS]->set_notnull(); + table->field[SPIDER_TABLES_TGT_TABLE_NAME_POS]->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[SPIDER_TABLES_TGT_TABLE_NAME_POS]->set_null(); + table->field[SPIDER_TABLES_TGT_TABLE_NAME_POS]->reset(); + } + table->field[SPIDER_TABLES_BLOCK_STATUS_POS]->store((longlong) 0, FALSE); + if (alter_table->tmp_static_link_ids[link_idx]) + { + DBUG_PRINT("info",("spider static_link_id[%d] = %s", + link_idx, alter_table->tmp_static_link_ids[link_idx])); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->set_notnull(); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->store( + alter_table->tmp_static_link_ids[link_idx], + (uint) alter_table->tmp_static_link_ids_lengths[link_idx], + system_charset_info); + } else { + DBUG_PRINT("info",("spider static_link_id[%d] = NULL", link_idx)); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->set_null(); + table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->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[SPIDER_TABLES_LINK_STATUS_POS]->store(link_status, FALSE); + DBUG_VOID_RETURN; +} + +void spider_store_binlog_pos_failed_link_idx( + TABLE *table, + int failed_link_idx +) { + DBUG_ENTER("spider_store_binlog_pos_failed_link_idx"); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FAILED_LINK_ID_POS]-> + set_notnull(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FAILED_LINK_ID_POS]-> + store(failed_link_idx); + DBUG_VOID_RETURN; +} + +void spider_store_binlog_pos_source_link_idx( + TABLE *table, + int source_link_idx +) { + DBUG_ENTER("spider_store_binlog_pos_source_link_idx"); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_SOURCE_LINK_ID_POS]-> + set_notnull(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_SOURCE_LINK_ID_POS]-> + store(source_link_idx); + DBUG_VOID_RETURN; +} + +void spider_store_binlog_pos_binlog_file( + TABLE *table, + const char *file_name, + int file_name_length, + const char *position, + int position_length, + CHARSET_INFO *binlog_pos_cs +) { + DBUG_ENTER("spider_store_binlog_pos_binlog_file"); + if (!file_name) + { + DBUG_PRINT("info",("spider file_name is NULL")); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS]->set_null(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS]->reset(); + } else { + DBUG_PRINT("info",("spider file_name = %s", file_name)); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS]->set_notnull(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS]->store( + file_name, file_name_length, binlog_pos_cs); + } + if (!position) + { + DBUG_PRINT("info",("spider position is NULL")); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS]->set_null(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS]->reset(); + } else { + DBUG_PRINT("info",("spider position = %s", position)); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS]-> + set_notnull(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS]->store( + position, position_length, binlog_pos_cs); + } + DBUG_VOID_RETURN; +} + +void spider_store_binlog_pos_gtid( + TABLE *table, + const char *gtid, + int gtid_length, + CHARSET_INFO *binlog_pos_cs +) { + DBUG_ENTER("spider_store_binlog_pos_gtid"); + if (!gtid) + { + DBUG_PRINT("info",("spider gtid is NULL")); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS]->set_null(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS]->reset(); + } else { + DBUG_PRINT("info",("spider gtid = %s", gtid)); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS]->set_notnull(); + table->field[SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS]->store( + gtid, gtid_length, binlog_pos_cs); + } + DBUG_VOID_RETURN; +} + +void spider_store_table_sts_info( + TABLE *table, + ha_statistics *stat +) { + MYSQL_TIME mysql_time; + DBUG_ENTER("spider_store_table_sts_info"); + table->field[SPIDER_TABLE_STS_DATA_FILE_LENGTH_POS]->store( + (longlong) stat->data_file_length, TRUE); + table->field[SPIDER_TABLE_STS_MAX_DATA_FILE_LENGTH_POS]->store( + (longlong) stat->max_data_file_length, TRUE); + table->field[SPIDER_TABLE_STS_INDEX_FILE_LENGTH_POS]->store( + (longlong) stat->index_file_length, TRUE); + table->field[SPIDER_TABLE_STS_RECORDS_POS]->store( + (longlong) stat->records, TRUE); + table->field[SPIDER_TABLE_STS_MEAN_REC_LENGTH_POS]->store( + (longlong) stat->mean_rec_length, TRUE); + spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->check_time); + table->field[SPIDER_TABLE_STS_CHECK_TIME_POS]->store_time(&mysql_time); + spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->create_time); + table->field[SPIDER_TABLE_STS_CREATE_TIME_POS]->store_time(&mysql_time); + spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) stat->update_time); + table->field[SPIDER_TABLE_STS_UPDATE_TIME_POS]->store_time(&mysql_time); + if (stat->checksum_null) + { + table->field[SPIDER_TABLE_STS_CHECKSUM_POS]->set_null(); + table->field[SPIDER_TABLE_STS_CHECKSUM_POS]->reset(); + } else { + table->field[SPIDER_TABLE_STS_CHECKSUM_POS]->set_notnull(); + table->field[SPIDER_TABLE_STS_CHECKSUM_POS]->store( + (longlong) stat->checksum, TRUE); + } + DBUG_VOID_RETURN; +} + +void spider_store_table_crd_info( + TABLE *table, + uint *seq, + longlong *cardinality +) { + DBUG_ENTER("spider_store_table_crd_info"); + table->field[SPIDER_TABLE_CRD_KEY_SEQ_POS]->store((longlong) *seq, TRUE); + table->field[SPIDER_TABLE_CRD_CARDINALITY_POS]->store( + (longlong) *cardinality, FALSE); + 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 = spider_write_sys_table_row(table))) + { + 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 = spider_write_sys_table_row(table))) + { + 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 = spider_write_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_insert_sys_table( + TABLE *table +) { + int error_num; + DBUG_ENTER("spider_insert_sys_table"); + error_num = spider_write_sys_table_row(table); + DBUG_RETURN(error_num); +} + +int spider_insert_or_update_table_sts( + TABLE *table, + const char *name, + uint name_length, + ha_statistics *stat +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_insert_or_update_table_sts"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + spider_store_table_sts_info( + table, + stat + ); + + if ((error_num = spider_check_sys_table_for_update_all_columns(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); + } + if ((error_num = spider_write_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = spider_update_sys_table_row(table, FALSE))) + { + table->file->print_error(error_num, MYF(0)); + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_insert_or_update_table_crd( + TABLE *table, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys +) { + int error_num; + uint roop_count; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_insert_or_update_table_crd"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + + for (roop_count = 0; roop_count < number_of_keys; ++roop_count) + { + spider_store_table_crd_info(table, &roop_count, &cardinality[roop_count]); + if ((error_num = spider_check_sys_table_for_update_all_columns(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); + } + if ((error_num = spider_write_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } else { + if ((error_num = spider_update_sys_table_row(table, FALSE))) + { + 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 ((error_num = spider_write_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + DBUG_RETURN(0); +} + +int spider_log_xa_failed( + THD *thd, + TABLE *table, + XID *xid, + SPIDER_CONN *conn, + const char *status +) { + int error_num; + DBUG_ENTER("spider_log_xa_failed"); + table->use_all_columns(); + spider_store_xa_member_pk(table, xid, conn); + spider_store_xa_member_info(table, xid, conn); + if (thd) + { + table->field[SPIDER_XA_FAILED_LOG_THREAD_ID_POS]->set_notnull(); + table->field[SPIDER_XA_FAILED_LOG_THREAD_ID_POS]->store( + thd->thread_id, TRUE); + } else { + table->field[SPIDER_XA_FAILED_LOG_THREAD_ID_POS]->set_null(); + table->field[SPIDER_XA_FAILED_LOG_THREAD_ID_POS]->reset(); + } + table->field[SPIDER_XA_FAILED_LOG_STATUS_POS]->store( + status, + (uint) strlen(status), + system_charset_info); + + if ((error_num = spider_write_sys_table_row(table))) + { + 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 = spider_update_sys_table_row(table))) + { + 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 = spider_update_sys_table_row(table))) + { + 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 = spider_write_sys_table_row(table))) + { + 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 = spider_update_sys_table_row(table))) + { + 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 = spider_delete_sys_table_row(table))) + { + 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 = spider_update_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_update_sys_table( + TABLE *table +) { + int error_num; + DBUG_ENTER("spider_update_sys_table"); + error_num = spider_update_sys_table_row(table); + DBUG_RETURN(error_num); +} + +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 = spider_delete_sys_table_row(table))) + { + 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 = spider_delete_sys_table_row(table, 0, FALSE))) + { + 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 = spider_delete_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } + roop_count++; + } + + *old_link_count = roop_count; + DBUG_RETURN(0); +} + +int spider_delete_table_sts( + TABLE *table, + const char *name, + uint name_length +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_delete_table_sts"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + + 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); + } + /* no record is ok */ + DBUG_RETURN(0); + } else { + if ((error_num = spider_delete_sys_table_row(table))) + { + DBUG_RETURN(error_num); + } + } + + DBUG_RETURN(0); +} + +int spider_delete_table_crd( + TABLE *table, + const char *name, + uint name_length +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + DBUG_ENTER("spider_delete_table_crd"); + table->use_all_columns(); + spider_store_tables_name(table, name, name_length); + + if ((error_num = spider_get_sys_table_by_idx(table, table_key, 0, + SPIDER_SYS_TABLE_CRD_PK_COL_CNT - 1))) + { + 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); + } + /* no record is ok */ + DBUG_RETURN(0); + } else { + do { + if ((error_num = spider_delete_sys_table_row(table))) + { + spider_sys_index_end(table); + 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_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[SPIDER_XA_FORMAT_ID_POS]); + if (ptr) + { + xid->formatID = atoi(ptr); + } else + xid->formatID = 0; + ptr = get_field(mem_root, table->field[SPIDER_XA_GTRID_LENGTH_POS]); + if (ptr) + { + xid->gtrid_length = atoi(ptr); + } else + xid->gtrid_length = 0; + ptr = get_field(mem_root, table->field[SPIDER_XA_BQUAL_LENGTH_POS]); + if (ptr) + { + xid->bqual_length = atoi(ptr); + } else + xid->bqual_length = 0; + ptr = get_field(mem_root, table->field[SPIDER_XA_DATA_POS]); + 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[SPIDER_XA_MEMBER_SCHEME_POS]))) + { + 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[SPIDER_XA_MEMBER_HOST_POS]))) + { + 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[SPIDER_XA_MEMBER_PORT_POS]))) + { + share->tgt_ports[link_idx] = atol(ptr); + } else + share->tgt_ports[link_idx] = MYSQL_PORT; + if ((ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SOCKET_POS]))) + { + 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[SPIDER_XA_MEMBER_USERNAME_POS]))) + { + 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[SPIDER_XA_MEMBER_PASSWORD_POS]))) + { + 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[SPIDER_XA_MEMBER_SSL_CA_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SSL_CA_POS])) + ) { + 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[SPIDER_XA_MEMBER_SSL_CAPATH_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SSL_CAPATH_POS])) + ) { + 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[SPIDER_XA_MEMBER_SSL_CERT_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SSL_CERT_POS])) + ) { + 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[SPIDER_XA_MEMBER_SSL_CIPHER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SSL_CIPHER_POS])) + ) { + 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[SPIDER_XA_MEMBER_SSL_KEY_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_SSL_KEY_POS])) + ) { + 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[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS]->is_null() && + (ptr = get_field(mem_root, table-> + field[SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = 0; + if ( + !table->field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS]->is_null() && + (ptr = get_field(mem_root, table-> + field[SPIDER_XA_MEMBER_DEFAULT_FILE_POS])) + ) { + 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[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS]->is_null() && + (ptr = get_field(mem_root, table-> + field[SPIDER_XA_MEMBER_DEFAULT_GROUP_POS])) + ) { + 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[SPIDER_XA_MEMBER_DSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_DSN_POS])) + ) { + share->tgt_dsns_lengths[link_idx] = strlen(ptr); + share->tgt_dsns[link_idx] = + spider_create_string(ptr, share->tgt_dsns_lengths[link_idx]); + } else { + share->tgt_dsns_lengths[link_idx] = 0; + share->tgt_dsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_XA_MEMBER_FILEDSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_FILEDSN_POS])) + ) { + share->tgt_filedsns_lengths[link_idx] = strlen(ptr); + share->tgt_filedsns[link_idx] = + spider_create_string(ptr, share->tgt_filedsns_lengths[link_idx]); + } else { + share->tgt_filedsns_lengths[link_idx] = 0; + share->tgt_filedsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_XA_MEMBER_DRIVER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_XA_MEMBER_DRIVER_POS])) + ) { + share->tgt_drivers_lengths[link_idx] = strlen(ptr); + share->tgt_drivers[link_idx] = + spider_create_string(ptr, share->tgt_drivers_lengths[link_idx]); + } else { + share->tgt_drivers_lengths[link_idx] = 0; + share->tgt_drivers[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[SPIDER_XA_STATUS_POS]); + 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[SPIDER_TABLES_DB_NAME_POS]))) + { + *db_name = spider_create_string(ptr, strlen(ptr)); + } else { + *db_name = NULL; + } + if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_TABLE_NAME_POS]))) + { + *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"); + DBUG_PRINT("info",("spider link_idx:%d", link_idx)); + if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_PRIORITY_POS]))) + { + share->priority = my_strtoll10(ptr, (char**) NULL, &error_num); + } else + share->priority = 1000000; + DBUG_PRINT("info",("spider priority:%lld", share->priority)); + if ( + !table->field[SPIDER_TABLES_SERVER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SERVER_POS])) + ) { + share->server_names_lengths[link_idx] = strlen(ptr); + share->server_names[link_idx] = + spider_create_string(ptr, share->server_names_lengths[link_idx]); + DBUG_PRINT("info",("spider server_name:%s", + share->server_names[link_idx])); + } else { + share->server_names_lengths[link_idx] = 0; + share->server_names[link_idx] = NULL; + DBUG_PRINT("info",("spider server_name is NULL")); + } + if ( + !table->field[SPIDER_TABLES_SCHEME_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SCHEME_POS])) + ) { + share->tgt_wrappers_lengths[link_idx] = strlen(ptr); + share->tgt_wrappers[link_idx] = + spider_create_string(ptr, share->tgt_wrappers_lengths[link_idx]); + DBUG_PRINT("info",("spider tgt_wrapper:%s", + share->tgt_wrappers[link_idx])); + } else { + share->tgt_wrappers_lengths[link_idx] = 0; + share->tgt_wrappers[link_idx] = NULL; + DBUG_PRINT("info",("spider tgt_wrapper is NULL")); + } + if ( + !table->field[SPIDER_TABLES_HOST_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_HOST_POS])) + ) { + share->tgt_hosts_lengths[link_idx] = strlen(ptr); + share->tgt_hosts[link_idx] = + spider_create_string(ptr, share->tgt_hosts_lengths[link_idx]); + DBUG_PRINT("info",("spider tgt_host:%s", + share->tgt_hosts[link_idx])); + } else { + share->tgt_hosts_lengths[link_idx] = 0; + share->tgt_hosts[link_idx] = NULL; + DBUG_PRINT("info",("spider tgt_host is NULL")); + } + if ( + !table->field[SPIDER_TABLES_PORT_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_PORT_POS])) + ) { + share->tgt_ports[link_idx] = atol(ptr); + } else { + share->tgt_ports[link_idx] = -1; + } + DBUG_PRINT("info",("spider port:%ld", share->tgt_ports[link_idx])); + if ( + !table->field[SPIDER_TABLES_SOCKET_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SOCKET_POS])) + ) { + 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[SPIDER_TABLES_USERNAME_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_USERNAME_POS])) + ) { + 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[SPIDER_TABLES_PASSWORD_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_PASSWORD_POS])) + ) { + 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[SPIDER_TABLES_SSL_CA_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SSL_CA_POS])) + ) { + 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[SPIDER_TABLES_SSL_CAPATH_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SSL_CAPATH_POS])) + ) { + 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[SPIDER_TABLES_SSL_CERT_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SSL_CERT_POS])) + ) { + 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[SPIDER_TABLES_SSL_CIPHER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SSL_CIPHER_POS])) + ) { + 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[SPIDER_TABLES_SSL_KEY_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_SSL_KEY_POS])) + ) { + 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[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = -1; + if ( + !table->field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS]-> + is_null() && + (ptr = get_field(mem_root, table-> + field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS])) + ) { + share->monitoring_binlog_pos_at_failing[link_idx] = atol(ptr); + } else + share->monitoring_binlog_pos_at_failing[link_idx] = 0; + if ( + !table->field[SPIDER_TABLES_DEFAULT_FILE_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_DEFAULT_FILE_POS])) + ) { + 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[SPIDER_TABLES_DEFAULT_GROUP_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_DEFAULT_GROUP_POS])) + ) { + 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[SPIDER_TABLES_DSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_DSN_POS])) + ) { + share->tgt_dsns_lengths[link_idx] = strlen(ptr); + share->tgt_dsns[link_idx] = + spider_create_string(ptr, share->tgt_dsns_lengths[link_idx]); + } else { + share->tgt_dsns_lengths[link_idx] = 0; + share->tgt_dsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_TABLES_FILEDSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_FILEDSN_POS])) + ) { + share->tgt_filedsns_lengths[link_idx] = strlen(ptr); + share->tgt_filedsns[link_idx] = + spider_create_string(ptr, share->tgt_filedsns_lengths[link_idx]); + } else { + share->tgt_filedsns_lengths[link_idx] = 0; + share->tgt_filedsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_TABLES_DRIVER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_DRIVER_POS])) + ) { + share->tgt_drivers_lengths[link_idx] = strlen(ptr); + share->tgt_drivers[link_idx] = + spider_create_string(ptr, share->tgt_drivers_lengths[link_idx]); + } else { + share->tgt_drivers_lengths[link_idx] = 0; + share->tgt_drivers[link_idx] = NULL; + } + if ( + !table->field[SPIDER_TABLES_TGT_DB_NAME_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_TGT_DB_NAME_POS])) + ) { + 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[SPIDER_TABLES_TGT_TABLE_NAME_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_TGT_TABLE_NAME_POS])) + ) { + 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; + } + if ( + !table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_TABLES_STATIC_LINK_ID_POS])) + ) { + share->static_link_ids_lengths[link_idx] = strlen(ptr); + share->static_link_ids[link_idx] = + spider_create_string(ptr, share->static_link_ids_lengths[link_idx]); + } else { + share->static_link_ids_lengths[link_idx] = 0; + share->static_link_ids[link_idx] = NULL; + } + DBUG_RETURN(error_num); +} + +int spider_get_sys_tables_monitoring_binlog_pos_at_failing( + TABLE *table, + long *monitoring_binlog_pos_at_failing, + MEM_ROOT *mem_root +) { + char *ptr; + int error_num = 0; + DBUG_ENTER("spider_get_sys_tables_monitoring_binlog_pos_at_failing"); + if ((ptr = get_field(mem_root, table-> + field[SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS]))) + *monitoring_binlog_pos_at_failing = (long) my_strtoll10(ptr, (char**) NULL, + &error_num); + else + *monitoring_binlog_pos_at_failing = 1; + DBUG_PRINT("info",("spider monitoring_binlog_pos_at_failing=%ld", + *monitoring_binlog_pos_at_failing)); + 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[SPIDER_TABLES_LINK_STATUS_POS]))) + { + 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_status( + TABLE *table, + long *link_status, + 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[SPIDER_TABLES_LINK_STATUS_POS]))) + *link_status = (long) my_strtoll10(ptr, (char**) NULL, &error_num); + else + *link_status = 1; + DBUG_PRINT("info",("spider link_statuses=%ld", *link_status)); + 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_idx"); + if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_LINK_ID_POS]))) + *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_get_sys_tables_static_link_id( + TABLE *table, + char **static_link_id, + uint *static_link_id_length, + MEM_ROOT *mem_root +) { + int error_num = 0; + DBUG_ENTER("spider_get_sys_tables_static_link_id"); + *static_link_id = NULL; + if ( + !table->field[SPIDER_TABLES_STATIC_LINK_ID_POS]->is_null() && + (*static_link_id = get_field(mem_root, table-> + field[SPIDER_TABLES_STATIC_LINK_ID_POS])) + ) { + *static_link_id_length = strlen(*static_link_id); + } else { + *static_link_id_length = 0; + } + DBUG_PRINT("info",("spider static_link_id=%s", *static_link_id ? *static_link_id : "NULL")); + DBUG_RETURN(error_num); +} + +void spider_get_sys_table_sts_info( + TABLE *table, + ha_statistics *stat +) { + MYSQL_TIME mysql_time; + uint not_used_uint; + long not_used_long; + DBUG_ENTER("spider_get_sys_table_sts_info"); + stat->data_file_length = (ulonglong) table-> + field[SPIDER_TABLE_STS_DATA_FILE_LENGTH_POS]->val_int(); + stat->max_data_file_length = (ulonglong) table-> + field[SPIDER_TABLE_STS_MAX_DATA_FILE_LENGTH_POS]->val_int(); + stat->index_file_length = (ulonglong) table-> + field[SPIDER_TABLE_STS_INDEX_FILE_LENGTH_POS]->val_int(); + stat->records = (ha_rows) table-> + field[SPIDER_TABLE_STS_RECORDS_POS]->val_int(); + stat->mean_rec_length = (ulong) table-> + field[SPIDER_TABLE_STS_MEAN_REC_LENGTH_POS]->val_int(); + table->field[SPIDER_TABLE_STS_CHECK_TIME_POS]->get_date(&mysql_time, + SPIDER_date_mode_t(0)); + stat->check_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + table->field[SPIDER_TABLE_STS_CREATE_TIME_POS]->get_date(&mysql_time, + SPIDER_date_mode_t(0)); + stat->create_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + table->field[SPIDER_TABLE_STS_UPDATE_TIME_POS]->get_date(&mysql_time, + SPIDER_date_mode_t(0)); + stat->update_time = (time_t) my_system_gmt_sec(&mysql_time, + ¬_used_long, ¬_used_uint); + if (table->field[SPIDER_TABLE_STS_CHECKSUM_POS]->is_null()) + { + stat->checksum_null = TRUE; + stat->checksum = 0; + } else { + stat->checksum_null = FALSE; + stat->checksum = (ha_checksum) table-> + field[SPIDER_TABLE_STS_CHECKSUM_POS]->val_int(); + } + DBUG_VOID_RETURN; +} + +void spider_get_sys_table_crd_info( + TABLE *table, + longlong *cardinality, + uint number_of_keys +) { + uint seq; + DBUG_ENTER("spider_get_sys_table_crd_info"); + seq = (uint) table->field[SPIDER_TABLE_CRD_KEY_SEQ_POS]->val_int(); + if (seq < number_of_keys) + { + cardinality[seq] = (longlong) table-> + field[SPIDER_TABLE_CRD_CARDINALITY_POS]->val_int(); + } + DBUG_VOID_RETURN; +} + +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; + SPIDER_Open_tables_backup open_tables_backup; + 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)) + ) { + 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; + SPIDER_Open_tables_backup open_tables_backup; + 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)) + ) { + 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_sys_log_xa_failed( + THD *thd, + XID *xid, + SPIDER_CONN *conn, + const char *status, + bool need_lock +) { + int error_num; + TABLE *table_tables = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_log_xa_failed"); + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_XA_FAILED_TABLE_NAME_STR, + SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN, TRUE, &open_tables_backup, + need_lock, &error_num)) + ) { + goto error; + } + empty_record(table_tables); + if ((error_num = spider_log_xa_failed(thd, table_tables, xid, conn, 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_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[SPIDER_LINK_MON_SERVERS_DB_NAME_POS]->is_null() || + table->field[SPIDER_LINK_MON_SERVERS_TABLE_NAME_POS]->is_null() || + table->field[SPIDER_LINK_MON_SERVERS_LINK_ID_POS]->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[SPIDER_LINK_MON_SERVERS_DB_NAME_POS]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(table_name= + get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_TABLE_NAME_POS]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(link_id= + get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_LINK_ID_POS]))) + 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[SPIDER_LINK_MON_SERVERS_SID_POS]))) + *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[SPIDER_LINK_MON_SERVERS_SERVER_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SERVER_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SCHEME_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SCHEME_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_HOST_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_HOST_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_PORT_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_PORT_POS])) + ) { + share->tgt_ports[link_idx] = atol(ptr); + } else { + share->tgt_ports[link_idx] = -1; + } + if ( + !table->field[SPIDER_LINK_MON_SERVERS_SOCKET_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SOCKET_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_USERNAME_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_USERNAME_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_PASSWORD_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_PASSWORD_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_CA_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_CA_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_CAPATH_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_CAPATH_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_CERT_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_CERT_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_CIPHER_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_CIPHER_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_KEY_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_KEY_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_SSL_VERIFY_SERVER_CERT_POS]-> + is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_SSL_VERIFY_SERVER_CERT_POS])) + ) { + share->tgt_ssl_vscs[link_idx] = atol(ptr); + } else + share->tgt_ssl_vscs[link_idx] = -1; + if ( + !table->field[SPIDER_LINK_MON_SERVERS_DEFAULT_FILE_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_DEFAULT_FILE_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_DEFAULT_GROUP_POS]->is_null() && + (ptr = get_field(mem_root, + table->field[SPIDER_LINK_MON_SERVERS_DEFAULT_GROUP_POS])) + ) { + 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[SPIDER_LINK_MON_SERVERS_DSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_DSN_POS])) + ) { + share->tgt_dsns_lengths[link_idx] = strlen(ptr); + share->tgt_dsns[link_idx] = + spider_create_string(ptr, share->tgt_dsns_lengths[link_idx]); + } else { + share->tgt_dsns_lengths[link_idx] = 0; + share->tgt_dsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_LINK_MON_SERVERS_FILEDSN_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_FILEDSN_POS])) + ) { + share->tgt_filedsns_lengths[link_idx] = strlen(ptr); + share->tgt_filedsns[link_idx] = + spider_create_string(ptr, share->tgt_filedsns_lengths[link_idx]); + } else { + share->tgt_filedsns_lengths[link_idx] = 0; + share->tgt_filedsns[link_idx] = NULL; + } + if ( + !table->field[SPIDER_LINK_MON_SERVERS_DRIVER_POS]->is_null() && + (ptr = get_field(mem_root, table->field[SPIDER_LINK_MON_SERVERS_DRIVER_POS])) + ) { + share->tgt_drivers_lengths[link_idx] = strlen(ptr); + share->tgt_drivers[link_idx] = + spider_create_string(ptr, share->tgt_drivers_lengths[link_idx]); + } else { + share->tgt_drivers_lengths[link_idx] = 0; + share->tgt_drivers[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_insert_or_update_table_sts( + THD *thd, + const char *name, + uint name_length, + ha_statistics *stat, + bool need_lock +) { + int error_num; + TABLE *table_sts = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_insert_or_update_table_sts"); + if ( + !(table_sts = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR, + SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + if ((error_num = spider_insert_or_update_table_sts( + table_sts, + name, + name_length, + stat + ))) + goto error; + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + table_sts = NULL; + DBUG_RETURN(0); + +error: + if (table_sts) + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_insert_or_update_table_crd( + THD *thd, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys, + bool need_lock +) { + int error_num; + TABLE *table_crd = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_insert_or_update_table_crd"); + if ( + !(table_crd = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR, + SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + if ((error_num = spider_insert_or_update_table_crd( + table_crd, + name, + name_length, + cardinality, + number_of_keys + ))) + goto error; + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + table_crd = NULL; + DBUG_RETURN(0); + +error: + if (table_crd) + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_delete_table_sts( + THD *thd, + const char *name, + uint name_length, + bool need_lock +) { + int error_num; + TABLE *table_sts = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_delete_table_sts"); + if ( + !(table_sts = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR, + SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + if ((error_num = spider_delete_table_sts( + table_sts, + name, + name_length + ))) + goto error; + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + table_sts = NULL; + DBUG_RETURN(0); + +error: + if (table_sts) + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_delete_table_crd( + THD *thd, + const char *name, + uint name_length, + bool need_lock +) { + int error_num; + TABLE *table_crd = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_delete_table_crd"); + if ( + !(table_crd = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR, + SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + if ((error_num = spider_delete_table_crd( + table_crd, + name, + name_length + ))) + goto error; + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + table_crd = NULL; + DBUG_RETURN(0); + +error: + if (table_crd) + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_get_table_sts( + THD *thd, + const char *name, + uint name_length, + ha_statistics *stat, + bool need_lock +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + TABLE *table_sts = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_get_table_sts"); + if ( + !(table_sts = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR, + SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + + table_sts->use_all_columns(); + spider_store_tables_name(table_sts, name, name_length); + if ((error_num = spider_check_sys_table(table_sts, table_key))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_sts->file->print_error(error_num, MYF(0)); + } + goto error; + } else { + spider_get_sys_table_sts_info( + table_sts, + stat + ); + } + + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + table_sts = NULL; + DBUG_RETURN(0); + +error: + if (table_sts) + spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +int spider_sys_get_table_crd( + THD *thd, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys, + bool need_lock +) { + int error_num; + char table_key[MAX_KEY_LENGTH]; + bool index_inited = FALSE; + TABLE *table_crd = NULL; + SPIDER_Open_tables_backup open_tables_backup; + DBUG_ENTER("spider_sys_get_table_crd"); + + if ( + !(table_crd = spider_open_sys_table( + thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR, + SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE, + &open_tables_backup, need_lock, &error_num)) + ) { + goto error; + } + + table_crd->use_all_columns(); + spider_store_tables_name(table_crd, name, name_length); + if ((error_num = spider_get_sys_table_by_idx(table_crd, table_key, 0, + SPIDER_SYS_TABLE_CRD_PK_COL_CNT - 1))) + { + if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + { + table_crd->file->print_error(error_num, MYF(0)); + } + goto error; + } else { + index_inited = TRUE; + do { + spider_get_sys_table_crd_info( + table_crd, + cardinality, + number_of_keys + ); + error_num = spider_sys_index_next_same(table_crd, table_key); + } while (error_num == 0); + } + index_inited = FALSE; + if ((error_num = spider_sys_index_end(table_crd))) + { + table_crd->file->print_error(error_num, MYF(0)); + goto error; + } + + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + table_crd = NULL; + DBUG_RETURN(0); + +error: + if (index_inited) + spider_sys_index_end(table_crd); + + if (table_crd) + spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock); + DBUG_RETURN(error_num); +} + +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 = spider_write_sys_table_row(table, FALSE))) + { + 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) + { + error_num = table->file->ha_rnd_pos(table->record[1], + table->file->dup_ref); + 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); + 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); + 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() + ) { + if ((error_num = spider_update_sys_table_row(table))) + goto error; + DBUG_RETURN(0); + } else { + if ((error_num = spider_delete_sys_table_row(table, 1, FALSE))) + goto error; + *modified_non_trans_table = TRUE; + } + } + + DBUG_RETURN(0); + +error: + DBUG_RETURN(error_num); +} + +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const LEX_CSTRING *field_name, + CHARSET_INFO *cs +) +#else +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name, + CHARSET_INFO *cs +) +#endif +{ + Field_blob *field; + Item_field *i_field; + List i_list; + TABLE *tmp_table; + DBUG_ENTER("spider_mk_sys_tmp_table"); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(field = new (thd->mem_root) Field_blob( + 4294967295U, FALSE, field_name, cs, TRUE))) + goto error_alloc_field; +#else + if (!(field = new Field_blob( + 4294967295U, FALSE, field_name, cs, TRUE))) + goto error_alloc_field; +#endif + field->init(table); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(i_field = new (thd->mem_root) Item_field(thd, (Field *) field))) + goto error_alloc_item_field; +#else + if (!(i_field = new Item_field((Field *) field))) + goto error_alloc_item_field; +#endif + + 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 | TMP_TABLE_ALL_COLUMNS), + HA_POS_ERROR, &SPIDER_empty_string))) + 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; +} + +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor +TABLE *spider_mk_sys_tmp_table_for_result( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const LEX_CSTRING *field_name1, + const LEX_CSTRING *field_name2, + const LEX_CSTRING *field_name3, + CHARSET_INFO *cs +) +#else +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 +) +#endif +{ + 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"); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(field1 = new (thd->mem_root) Field_blob( + 4294967295U, FALSE, field_name1, cs, TRUE))) + goto error_alloc_field1; +#else + if (!(field1 = new Field_blob( + 4294967295U, FALSE, field_name1, cs, TRUE))) + goto error_alloc_field1; +#endif + field1->init(table); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(i_field1 = new (thd->mem_root) Item_field(thd, (Field *) field1))) + goto error_alloc_item_field1; +#else + if (!(i_field1 = new Item_field((Field *) field1))) + goto error_alloc_item_field1; +#endif + + if (i_list.push_back(i_field1)) + goto error_push_item1; + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(field2 = new (thd->mem_root) Field_blob( + 4294967295U, FALSE, field_name2, cs, TRUE))) + goto error_alloc_field2; +#else + if (!(field2 = new Field_blob( + 4294967295U, FALSE, field_name2, cs, TRUE))) + goto error_alloc_field2; +#endif + field2->init(table); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(i_field2 = new (thd->mem_root) Item_field(thd, (Field *) field2))) + goto error_alloc_item_field2; +#else + if (!(i_field2 = new Item_field((Field *) field2))) + goto error_alloc_item_field2; +#endif + + if (i_list.push_back(i_field2)) + goto error_push_item2; + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(field3 = new (thd->mem_root) Field_blob( + 4294967295U, FALSE, field_name3, cs, TRUE))) + goto error_alloc_field3; +#else + if (!(field3 = new Field_blob( + 4294967295U, FALSE, field_name3, cs, TRUE))) + goto error_alloc_field3; +#endif + field3->init(table); + +#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR + if (!(i_field3 = new (thd->mem_root) Item_field(thd, (Field *) field3))) + goto error_alloc_item_field3; +#else + if (!(i_field3 = new Item_field((Field *) field3))) + goto error_alloc_item_field3; +#endif + + 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 | TMP_TABLE_ALL_COLUMNS), + HA_POS_ERROR, &SPIDER_empty_string))) + 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; +} + +TABLE *spider_find_temporary_table( + THD *thd, + TABLE_LIST *table_list +) { + DBUG_ENTER("spider_find_temporary_table"); +#ifdef SPIDER_open_temporary_table + if (!thd->has_temporary_tables()) + { + DBUG_RETURN(NULL); + } + if (thd->open_temporary_table(table_list)) + { + DBUG_RETURN(NULL); + } else { + DBUG_RETURN(table_list->table); + } +#else + DBUG_RETURN(find_temporary_table(A,B)); +#endif +} diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h new file mode 100644 index 00000000..36f72375 --- /dev/null +++ b/storage/spider/spd_sys_table.h @@ -0,0 +1,644 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define SPIDER_SYS_XA_TABLE_NAME_STR "spider_xa" +#define SPIDER_SYS_XA_TABLE_NAME_LEN 9 +#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR "spider_xa_member" +#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN 16 +#define SPIDER_SYS_TABLES_TABLE_NAME_STR "spider_tables" +#define SPIDER_SYS_TABLES_TABLE_NAME_LEN 13 +#define SPIDER_SYS_LINK_MON_TABLE_NAME_STR "spider_link_mon_servers" +#define SPIDER_SYS_LINK_MON_TABLE_NAME_LEN 23 +#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR "spider_link_failed_log" +#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN 22 +#define SPIDER_SYS_XA_FAILED_TABLE_NAME_STR "spider_xa_failed_log" +#define SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN 20 +#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR "spider_table_position_for_recovery" +#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN 34 +#define SPIDER_SYS_TABLE_STS_TABLE_NAME_STR "spider_table_sts" +#define SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN 16 +#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR "spider_table_crd" +#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN 16 +#define SPIDER_SYS_RW_TBLS_TABLE_NAME_STR "spider_rewrite_tables" +#define SPIDER_SYS_RW_TBLS_TABLE_NAME_LEN 21 +#define SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR "spider_rewrite_table_tables" +#define SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_LEN 27 +#define SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR "spider_rewrite_table_partitions" +#define SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_LEN 31 +#define SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR "spider_rewrite_table_subpartitions" +#define SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_LEN 34 +#define SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR "spider_rewritten_tables" +#define SPIDER_SYS_RWN_TBLS_TABLE_NAME_LEN 23 + +#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 21 +#define SPIDER_SYS_XA_MEMBER_PK_COL_CNT 6 +#define SPIDER_SYS_TABLES_COL_CNT 28 +#define SPIDER_SYS_TABLES_PK_COL_CNT 3 +#define SPIDER_SYS_TABLES_IDX1_COL_CNT 1 +#define SPIDER_SYS_TABLES_UIDX1_COL_CNT 3 +#define SPIDER_SYS_LINK_MON_TABLE_COL_CNT 22 +#define SPIDER_SYS_LINK_FAILED_TABLE_COL_CNT 4 +#define SPIDER_SYS_XA_FAILED_TABLE_COL_CNT 24 +#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT 7 +#define SPIDER_SYS_TABLE_STS_COL_CNT 11 +#define SPIDER_SYS_TABLE_STS_PK_COL_CNT 2 +#define SPIDER_SYS_TABLE_CRD_COL_CNT 4 +#define SPIDER_SYS_TABLE_CRD_PK_COL_CNT 3 +#define SPIDER_SYS_RW_TBLS_COL_CNT 3 +#define SPIDER_SYS_RW_TBL_TBLS_COL_CNT 8 +#define SPIDER_SYS_RW_TBL_PTTS_COL_CNT 7 +#define SPIDER_SYS_RW_TBL_SPTTS_COL_CNT 8 +#define SPIDER_SYS_RWN_TBLS_COL_CNT 4 + +#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 64 + +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; +}; + +TABLE *spider_open_sys_table( + THD *thd, + const char *table_name, + int table_name_length, + bool write, + SPIDER_Open_tables_backup *open_tables_backup, + bool need_lock, + int *error_num +); + +void spider_close_sys_table( + THD *thd, + TABLE *table, + SPIDER_Open_tables_backup *open_tables_backup, + bool need_lock +); + +bool spider_sys_open_and_lock_tables( + THD *thd, + TABLE_LIST **tables, + SPIDER_Open_tables_backup *open_tables_backup +); + +TABLE *spider_sys_open_table( + THD *thd, + TABLE_LIST *tables, + SPIDER_Open_tables_backup *open_tables_backup +); + +void spider_sys_close_table( + THD *thd, + SPIDER_Open_tables_backup *open_tables_backup +); + +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_check_sys_table_for_update_all_columns( + TABLE *table, + char *table_key +); + +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_last( + 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_static_link_id( + TABLE *table, + const char *static_link_id, + const uint static_link_id_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_binlog_pos_failed_link_idx( + TABLE *table, + int failed_link_idx +); + +void spider_store_binlog_pos_source_link_idx( + TABLE *table, + int source_link_idx +); + +void spider_store_binlog_pos_binlog_file( + TABLE *table, + const char *file_name, + int file_name_length, + const char *position, + int position_length, + CHARSET_INFO *binlog_pos_cs +); + +void spider_store_binlog_pos_gtid( + TABLE *table, + const char *gtid, + int gtid_length, + CHARSET_INFO *binlog_pos_cs +); + +void spider_store_table_sts_info( + TABLE *table, + ha_statistics *stat +); + +void spider_store_table_crd_info( + TABLE *table, + uint *seq, + longlong *cardinality +); + +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_insert_sys_table( + TABLE *table +); + +int spider_insert_or_update_table_sts( + TABLE *table, + const char *name, + uint name_length, + ha_statistics *stat +); + +int spider_insert_or_update_table_crd( + TABLE *table, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys +); + +int spider_log_tables_link_failed( + TABLE *table, + char *name, + uint name_length, + int link_idx +); + +int spider_log_xa_failed( + THD *thd, + TABLE *table, + XID *xid, + SPIDER_CONN *conn, + const char *status +); + +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_update_sys_table( + TABLE *table +); + +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_delete_table_sts( + TABLE *table, + const char *name, + uint name_length +); + +int spider_delete_table_crd( + TABLE *table, + const char *name, + uint name_length +); + +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_monitoring_binlog_pos_at_failing( + TABLE *table, + long *monitoring_binlog_pos_at_failing, + 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_status( + TABLE *table, + long *link_status, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables_link_idx( + TABLE *table, + int *link_idx, + MEM_ROOT *mem_root +); + +int spider_get_sys_tables_static_link_id( + TABLE *table, + char **static_link_id, + uint *static_link_id_length, + MEM_ROOT *mem_root +); + +void spider_get_sys_table_sts_info( + TABLE *table, + ha_statistics *stat +); + +void spider_get_sys_table_crd_info( + TABLE *table, + longlong *cardinality, + uint number_of_keys +); + +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_sys_log_xa_failed( + THD *thd, + XID *xid, + SPIDER_CONN *conn, + const char *status, + 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_insert_or_update_table_sts( + THD *thd, + const char *name, + uint name_length, + ha_statistics *stat, + bool need_lock +); + +int spider_sys_insert_or_update_table_crd( + THD *thd, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys, + bool need_lock +); + +int spider_sys_delete_table_sts( + THD *thd, + const char *name, + uint name_length, + bool need_lock +); + +int spider_sys_delete_table_crd( + THD *thd, + const char *name, + uint name_length, + bool need_lock +); + +int spider_sys_get_table_sts( + THD *thd, + const char *name, + uint name_length, + ha_statistics *stat, + bool need_lock +); + +int spider_sys_get_table_crd( + THD *thd, + const char *name, + uint name_length, + longlong *cardinality, + uint number_of_keys, + bool need_lock +); + +int spider_sys_replace( + TABLE *table, + bool *modified_non_trans_table +); + +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const LEX_CSTRING *field_name, + CHARSET_INFO *cs +); +#else +TABLE *spider_mk_sys_tmp_table( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const char *field_name, + CHARSET_INFO *cs +); +#endif + +void spider_rm_sys_tmp_table( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +); + +#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor +TABLE *spider_mk_sys_tmp_table_for_result( + THD *thd, + TABLE *table, + TMP_TABLE_PARAM *tmp_tbl_prm, + const LEX_CSTRING *field_name1, + const LEX_CSTRING *field_name2, + const LEX_CSTRING *field_name3, + CHARSET_INFO *cs +); +#else +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 +); +#endif + +void spider_rm_sys_tmp_table_for_result( + THD *thd, + TABLE *tmp_table, + TMP_TABLE_PARAM *tmp_tbl_prm +); + +TABLE *spider_find_temporary_table( + THD *thd, + TABLE_LIST *table_list +); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc new file mode 100644 index 00000000..bf101858 --- /dev/null +++ b/storage/spider/spd_table.cc @@ -0,0 +1,9384 @@ +/* Copyright (C) 2008-2020 Kentoku Shiba + Copyright (C) 2019-2022 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "my_getopt.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "sql_servers.h" +#include "sql_select.h" +#include "tztime.h" +#include "sql_parse.h" +#include "create_options.h" +#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_direct_sql.h" +#include "spd_malloc.h" +#include "spd_group_by_handler.h" +#include "spd_init_query.h" + +/* Background thread management */ +#ifdef SPIDER_HAS_NEXT_THREAD_ID +#define SPIDER_set_next_thread_id(A) +MYSQL_THD create_thd(); +void destroy_thd(MYSQL_THD thd); +#else +ulong *spd_db_att_thread_id; +inline void SPIDER_set_next_thread_id(THD *A) +{ + pthread_mutex_lock(&LOCK_thread_count); + A->thread_id = (*spd_db_att_thread_id)++; + pthread_mutex_unlock(&LOCK_thread_count); +} +MYSQL_THD create_thd() +{ + THD *thd = SPIDER_new_THD(next_thread_id()); + if (thd) + { + thd->thread_stack = (char*) &thd; + thd->store_globals(); + thd->set_command(COM_DAEMON); + thd->security_ctx->host_or_ip = ""; + } + return thd; +} +void destroy_thd(MYSQL_THD thd) +{ + delete thd; +} +#endif +inline MYSQL_THD spider_create_sys_thd(SPIDER_THREAD *thread) +{ + THD *thd = create_thd(); + if (thd) + { + SPIDER_set_next_thread_id(thd); + thd->mysys_var->current_cond = &thread->cond; + thd->mysys_var->current_mutex = &thread->mutex; + } + return thd; +} +inline void spider_destroy_sys_thd(MYSQL_THD thd) +{ + destroy_thd(thd); +} +inline MYSQL_THD spider_create_thd() +{ + THD *thd; + my_thread_init(); + if (!(thd = new THD(next_thread_id()))) + my_thread_end(); + else + { +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd->thread_stack = (char *) &thd; + thd->store_globals(); + } + return thd; +} +inline void spider_destroy_thd(MYSQL_THD thd) +{ + delete thd; +} + +struct charset_info_st *spd_charset_utf8mb3_bin; +const char **spd_defaults_extra_file; +const char **spd_defaults_file; +const char **spd_mysqld_unix_port; +uint *spd_mysqld_port; +bool volatile *spd_abort_loop; +Time_zone *spd_tz_system; +extern long spider_conn_mutex_id; +handlerton *spider_hton_ptr; +SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +extern SPIDER_DBTON spider_dbton_mysql; +extern SPIDER_DBTON spider_dbton_mariadb; +SPIDER_THREAD *spider_table_sts_threads; +SPIDER_THREAD *spider_table_crd_threads; + +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key spd_key_mutex_tbl; +PSI_mutex_key spd_key_mutex_init_error_tbl; +PSI_mutex_key spd_key_mutex_wide_share; +PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share; +PSI_mutex_key spd_key_mutex_conn; +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; +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; +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; +PSI_mutex_key spd_key_mutex_wide_share_sts; +PSI_mutex_key spd_key_mutex_wide_share_crd; +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; +PSI_mutex_key spd_key_mutex_ipport_count; +PSI_mutex_key spd_key_mutex_conn_i; +PSI_mutex_key spd_key_mutex_bg_stss; +PSI_mutex_key spd_key_mutex_bg_crds; +PSI_mutex_key spd_key_mutex_conn_loop_check; + +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}, + { &spd_key_mutex_wide_share, "wide_share", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL}, + { &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_ipport_count, "ipport_count", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_bg_stss, "bg_stss", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_bg_crds, "bg_crds", PSI_FLAG_GLOBAL}, + { &spd_key_mutex_conn_i, "conn_i", 0}, + { &spd_key_mutex_mta_conn, "mta_conn", 0}, + { &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}, + { &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}, + { &spd_key_mutex_wide_share_sts, "wide_share_sts", 0}, + { &spd_key_mutex_wide_share_crd, "wide_share_crd", 0}, + { &spd_key_mutex_udf_table, "udf_table", 0}, + { &spd_key_mutex_conn_loop_check, "conn_loop_check", 0}, +}; + +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_mon_sleep; +PSI_cond_key spd_key_cond_bg_direct_sql; +PSI_cond_key spd_key_cond_udf_table_mon; +PSI_cond_key spd_key_cond_conn_i; +PSI_cond_key spd_key_cond_bg_stss; +PSI_cond_key spd_key_cond_bg_sts_syncs; +PSI_cond_key spd_key_cond_bg_crds; +PSI_cond_key spd_key_cond_bg_crd_syncs; + +static PSI_cond_info all_spider_conds[] = { + {&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_mon_sleep, "bg_mon_sleep", 0}, + {&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0}, + {&spd_key_cond_udf_table_mon, "udf_table_mon", 0}, + {&spd_key_cond_conn_i, "conn_i", 0}, + {&spd_key_cond_bg_stss, "bg_stss", 0}, + {&spd_key_cond_bg_sts_syncs, "bg_sts_syncs", 0}, + {&spd_key_cond_bg_crds, "bg_crds", 0}, + {&spd_key_cond_bg_crd_syncs, "bg_crd_syncs", 0}, +}; + +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; +PSI_thread_key spd_key_thd_bg_stss; +PSI_thread_key spd_key_thd_bg_crds; + +static PSI_thread_info all_spider_threads[] = { + {&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}, + {&spd_key_thd_bg_stss, "bg_stss", 0}, + {&spd_key_thd_bg_crds, "bg_crds", 0}, +}; +#endif + +struct ha_table_option_struct +{ + char *remote_server; + char *remote_database; + char *remote_table; +}; + +ha_create_table_option spider_table_option_list[]= { + HA_TOPTION_STRING("REMOTE_SERVER", remote_server), + HA_TOPTION_STRING("REMOTE_DATABASE", remote_database), + HA_TOPTION_STRING("REMOTE_TABLE", remote_table), HA_TOPTION_END}; + +extern HASH spider_open_connections; +extern HASH spider_ipport_conns; +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; +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; +extern pthread_mutex_t spider_ipport_conn_mutex; + +HASH spider_open_wide_share; +uint spider_open_wide_share_id; +const char *spider_open_wide_share_func_name; +const char *spider_open_wide_share_file_name; +ulong spider_open_wide_share_line_no; +pthread_mutex_t spider_wide_share_mutex; + +HASH spider_lgtm_tblhnd_share_hash; +uint spider_lgtm_tblhnd_share_hash_id; +const char *spider_lgtm_tblhnd_share_hash_func_name; +const char *spider_lgtm_tblhnd_share_hash_file_name; +ulong spider_lgtm_tblhnd_share_hash_line_no; +pthread_mutex_t spider_lgtm_tblhnd_share_mutex; + +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; + +pthread_attr_t spider_pt_attr; + +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='\\'; + +static char spider_unique_id_buf[1 + 12 + 1 + (16 * 2) + 1 + 1]; +LEX_CSTRING spider_unique_id; + +// 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); +} + +uchar *spider_wide_share_get_key( + SPIDER_WIDE_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_wide_share_get_key"); + *length = share->table_name_length; + DBUG_RETURN((uchar*) share->table_name); +} + +uchar *spider_lgtm_tblhnd_share_hash_get_key( + SPIDER_LGTM_TBLHND_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +) { + DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key"); + *length = share->table_name_length; + DBUG_RETURN((uchar*) share->table_name); +} + +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"); + 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_dsns) + { + for (roop_count = 0; roop_count < (int) share->tgt_dsns_length; + roop_count++) + { + if (share->tgt_dsns[roop_count]) + spider_free(spider_current_trx, share->tgt_dsns[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_dsns, MYF(0)); + } + if (share->tgt_filedsns) + { + for (roop_count = 0; roop_count < (int) share->tgt_filedsns_length; + roop_count++) + { + if (share->tgt_filedsns[roop_count]) + spider_free(spider_current_trx, share->tgt_filedsns[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_filedsns, MYF(0)); + } + if (share->tgt_drivers) + { + for (roop_count = 0; roop_count < (int) share->tgt_drivers_length; + roop_count++) + { + if (share->tgt_drivers[roop_count]) + spider_free(spider_current_trx, share->tgt_drivers[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->tgt_drivers, 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 (share->static_link_ids) + { + for (roop_count = 0; roop_count < (int) share->static_link_ids_length; + roop_count++) + { + if (share->static_link_ids[roop_count]) + spider_free(spider_current_trx, share->static_link_ids[roop_count], + MYF(0)); + } + spider_free(spider_current_trx, share->static_link_ids, MYF(0)); + } + 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)); + if (share->monitoring_bg_flag) + spider_free(spider_current_trx, share->monitoring_bg_flag, MYF(0)); + if (share->monitoring_bg_kind) + spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0)); + if (share->monitoring_binlog_pos_at_failing) + spider_free(spider_current_trx, share->monitoring_binlog_pos_at_failing, MYF(0)); + if (share->monitoring_flag) + spider_free(spider_current_trx, share->monitoring_flag, MYF(0)); + if (share->monitoring_kind) + spider_free(spider_current_trx, share->monitoring_kind, 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)); + if (share->bka_table_name_types) + spider_free(spider_current_trx, share->bka_table_name_types, MYF(0)); + if (share->strict_group_bys) + spider_free(spider_current_trx, share->strict_group_bys, MYF(0)); + if (share->monitoring_bg_interval) + spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0)); + 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; + } + if (share->wide_share) + spider_free_wide_share(share->wide_share); + 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_dsns && share->tgt_dsns[0]) + { + spider_free(spider_current_trx, share->tgt_dsns[0], MYF(0)); + share->tgt_dsns[0] = NULL; + } + if (share->tgt_filedsns && share->tgt_filedsns[0]) + { + spider_free(spider_current_trx, share->tgt_filedsns[0], MYF(0)); + share->tgt_filedsns[0] = NULL; + } + if (share->tgt_drivers && share->tgt_drivers[0]) + { + spider_free(spider_current_trx, share->tgt_drivers[0], MYF(0)); + share->tgt_drivers[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 (share->static_link_ids && share->static_link_ids[0]) + { + spider_free(spider_current_trx, share->static_link_ids[0], MYF(0)); + share->static_link_ids[0] = NULL; + } + 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->static_key_cardinality) + spider_free(spider_current_trx, share->static_key_cardinality, MYF(0)); + if (share->key_hint) + { + delete [] share->key_hint; + share->key_hint = NULL; + } + DBUG_VOID_RETURN; +} + +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, *tmp_ptr4, *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); + } + + bool last_esc_flg = FALSE; + while (TRUE) + { + if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) + { + find_flg = FALSE; + last_esc_flg = FALSE; + 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) + { + last_esc_flg = TRUE; + tmp_ptr = tmp_ptr2 + 1; + break; + } else { + last_esc_flg = TRUE; + 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, (uint) (sizeof(char*) * (*list_length)), + string_length_list, (uint) (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++) + { + bool esc_flg = FALSE; + find_flg = FALSE; + 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) + { + esc_flg = TRUE; + tmp_ptr = tmp_ptr2 + 1; + break; + } else { + esc_flg = TRUE; + 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); + } + + if (esc_flg) + { + esc_ptr = (*string_list)[roop_count]; + 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++; + tmp_ptr4 = esc_ptr; + do + { + *tmp_ptr4 = *(tmp_ptr4 + 1); + tmp_ptr4++; + } while (*tmp_ptr4); + (*string_length_list)[roop_count] -= 1; + } + } + 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); + } + if (last_esc_flg) + { + esc_ptr = (*string_list)[roop_count]; + 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++; + tmp_ptr4 = esc_ptr; + do + { + *tmp_ptr4 = *(tmp_ptr4 + 1); + tmp_ptr4++; + } while (*tmp_ptr4); + (*string_length_list)[roop_count] -= 1; + } + } + + 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, (uint) (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, (uint) (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, (uint) (sizeof(char*) * link_count), + &tmp_length_list, (uint) (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_null_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; + uint *tmp_length_list; + DBUG_ENTER("spider_increase_null_string_list"); + if (*list_length == link_count) + DBUG_RETURN(0); + + if (!(tmp_str_list = (char**) + spider_bulk_malloc(spider_current_trx, 247, MYF(MY_WME | MY_ZEROFILL), + &tmp_str_list, (uint) (sizeof(char*) * link_count), + &tmp_length_list, (uint) (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) *list_length; roop_count++) + { + tmp_str_list[roop_count] = (*string_list)[roop_count]; + tmp_length_list[roop_count] = (*string_length_list)[roop_count]; + } + if (*string_list) + { + spider_free(spider_current_trx, *string_list, MYF(0)); + } + *list_length = link_count; + *string_list = tmp_str_list; + *string_length_list = tmp_length_list; +#ifndef DBUG_OFF + DBUG_PRINT("info",("spider list_length=%u", *list_length)); + for (roop_count = 0; roop_count < (int) *list_length; roop_count++) + { + DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count, + (*string_list)[roop_count] ? (*string_list)[roop_count] : "NULL")); + DBUG_PRINT("info",("spider string_length_list[%d]=%u", roop_count, + (*string_length_list)[roop_count])); + } +#endif + + DBUG_RETURN(0); +} + +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, (uint) (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, (uint) (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); +} + +static int spider_set_ll_value( + longlong *value, + char *str +) { + int error_num = 0; + DBUG_ENTER("spider_set_ll_value"); + *value = my_strtoll10(str, (char**) NULL, &error_num); + DBUG_RETURN(error_num); +} + +#define SPIDER_PARAM_LEN(name) name ## _length +#define SPIDER_PARAM_LENS(name) name ## _lengths +#define SPIDER_PARAM_CHARLEN(name) name ## _charlen +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((share->param_name = spider_create_string(parse.start_value, \ + value_length))) \ + share->SPIDER_PARAM_LEN(param_name) = strlen(share->param_name); \ + else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ + DBUG_PRINT("info",("spider " title_name "=%s", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_STR_LIST(title_name, param_name) \ + SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, FALSE) +#define SPIDER_PARAM_STR_LIST_CHECK(title_name, param_name, already_set) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info", ("spider " title_name " start")); \ + if (already_set) \ + { \ + error_num= ER_SPIDER_INVALID_CONNECT_INFO_NUM; \ + goto error; \ + } \ + if (!share->param_name) \ + { \ + share->SPIDER_PARAM_CHARLEN(param_name)= value_length; \ + if ((error_num= spider_create_string_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LENS(param_name), \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + share->SPIDER_PARAM_CHARLEN(param_name)))) \ + goto error; \ + THD *thd= current_thd; \ + if (share->SPIDER_PARAM_LEN(param_name) > 1 && create_table) \ + { \ + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, \ + HA_ERR_UNSUPPORTED, \ + "The high availability feature of Spider " \ + "has been deprecated " \ + "and will be removed in a future release"); \ + } \ + } \ + break; \ + } +#define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \ + if (!strncasecmp(parse.start_title, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(parse.start_title + 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= parse.fail(true); \ + goto error; \ + } else if (share->param_name[hint_num].length() > 0) \ + break; \ + if ((error_num= append_method(&share->param_name[hint_num], \ + parse.start_value))) \ + goto error; \ + DBUG_PRINT("info",("spider " title_name "[%d]=%s", hint_num, \ + share->param_name[hint_num].ptr())); \ + } else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_NUMHINT(title_name, param_name, check_length, max_size, append_method) \ + if (!strncasecmp(parse.start_title, title_name, check_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + DBUG_PRINT("info",("spider max_size=%d", max_size)); \ + int hint_num = atoi(parse.start_title + 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= parse.fail(true); \ + goto error; \ + } else if (share->param_name[hint_num] != -1) \ + break; \ + if ((error_num = \ + append_method(&share->param_name[hint_num], parse.start_value))) \ + goto error; \ + DBUG_PRINT("info",("spider " title_name "[%d]=%lld", hint_num, \ + share->param_name[hint_num])); \ + } else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ + min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((error_num = spider_create_long_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + value_length, \ + min_val, max_val))) \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \ + min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((error_num = spider_create_longlong_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + value_length, \ + min_val, max_val))) \ + goto error; \ + } \ + break; \ + } +#define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (share->param_name == -1) \ + { \ + share->param_name = atoi(parse.start_value); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + else if (share->param_name > max_val) \ + share->param_name = max_val; \ + DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_INT(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (share->param_name == -1) \ + { \ + share->param_name = atoi(parse.start_value); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_DOUBLE(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (share->param_name == -1) \ + { \ + share->param_name = my_atof(parse.start_value); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%f", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (share->param_name == -1) \ + { \ + share->param_name = my_strtoll10(parse.start_value, (char**) NULL, \ + &error_num); \ + if (share->param_name < min_val) \ + share->param_name = min_val; \ + DBUG_PRINT("info",("spider " title_name "=%lld", share->param_name)); \ + } \ + break; \ + } +#define SPIDER_PARAM_DEPRECATED_WARNING(title_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length) && create_table) \ + { \ + THD *thd= current_thd; \ + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, \ + ER_WARN_DEPRECATED_SYNTAX, \ + "The table parameter '%s' is deprecated and will be " \ + "removed in a future release", \ + title_name); \ + } + +/* + Set a given engine-defined option, which holds a string list, to the + corresponding attribute of SPIDER_SHARE. + */ +#define SPIDER_OPTION_STR_LIST(title_name, option_name, param_name) \ + if (option_struct && option_struct->option_name) \ + { \ + DBUG_PRINT("info", ("spider " title_name " start overwrite")); \ + share->SPIDER_PARAM_CHARLEN(param_name)= \ + strlen(option_struct->option_name); \ + if ((error_num= spider_create_string_list( \ + &share->param_name, &share->SPIDER_PARAM_LENS(param_name), \ + &share->SPIDER_PARAM_LEN(param_name), \ + option_struct->option_name, \ + share->SPIDER_PARAM_CHARLEN(param_name)))) \ + goto error; \ + } + +/** + Assign -1 to some `SPIDER_SHARE' numeric fields, to indicate they + have not been specified by the user yet. +*/ +static void spider_minus_1(SPIDER_SHARE *share, TABLE_SHARE *table_share) +{ + share->sts_bg_mode = -1; + share->sts_interval = -1; + share->sts_mode = -1; + share->sts_sync = -1; + share->store_last_sts = -1; + share->load_sts_at_startup = -1; + share->crd_bg_mode = -1; + share->crd_interval = -1; + share->crd_mode = -1; + share->crd_sync = -1; + share->store_last_crd = -1; + share->load_crd_at_startup = -1; + 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->query_cache_sync = -1; + share->bulk_size = -1; + share->bulk_update_mode = -1; + share->bulk_update_size = -1; + share->buffer_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->quick_page_byte = -1; + share->low_mem_read = -1; + share->table_count_mode = -1; + share->select_column_mode = -1; + share->bgs_mode = -1; + share->bgs_first_read = -1; + share->bgs_second_read = -1; + 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->skip_parallel_search = -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; +#ifdef HA_CAN_FORCE_BULK_UPDATE + share->force_bulk_update = -1; +#endif +#ifdef HA_CAN_FORCE_BULK_DELETE + share->force_bulk_delete = -1; +#endif + share->casual_read = -1; + share->delete_all_rows_type = -1; + share->static_records_for_status = -1; + share->static_mean_rec_length = -1; + for (uint i = 0; i < table_share->keys; i++) + { + share->static_key_cardinality[i] = -1; + } +} + +/** + Get the connect info of a certain type. + + @param type The type of the connect info. + 4: partition; 3: subpartition; 2: comment; + 1: connect_string + @retval 0 Success + @retval 1 Not applicable. That is, the info with the + type is missing + @retval HA_ERR_OUT_OF_MEM Failure +*/ +static int spider_get_connect_info(const int type, + const partition_element *part_elem, + const partition_element *sub_elem, + const TABLE_SHARE* table_share, + char*& out) +{ + switch (type) + { + case 4: + if (!sub_elem || !sub_elem->part_comment) + return 1; + if (!(out = spider_create_string( + sub_elem->part_comment, strlen(sub_elem->part_comment)))) + return HA_ERR_OUT_OF_MEM; + break; + case 3: + if (!part_elem || !part_elem->part_comment) + return 1; + if (!(out = spider_create_string( + part_elem->part_comment, strlen(part_elem->part_comment)))) + return HA_ERR_OUT_OF_MEM; + break; + case 2: + if (table_share->comment.length == 0) + return 1; + if (!(out = spider_create_string( + table_share->comment.str, table_share->comment.length))) + return HA_ERR_OUT_OF_MEM; + break; + default: + if (table_share->connect_string.length == 0) + return 1; + DBUG_PRINT("info",("spider create out string")); + if (!(out = spider_create_string( + table_share->connect_string.str, table_share->connect_string.length))) + return HA_ERR_OUT_OF_MEM; + break; + } + return 0; +} + +/** + Find the beginning and end of a parameter title + + Skip over whitespace to find the beginning of the parameter + title. Then skip over non-whitespace/quote/nul chars to find the end + of the parameter title + + @param start_title The start of the param definition. Will be + moved to the start of the param title + @param end_title Will be moved to the end of the param title + @retval false Success + @retval true Failure +*/ +static bool spider_parse_find_title(char*& start_title, char*& end_title) +{ + /* Skip leading whitespaces. */ + while (*start_title == ' ' || *start_title == '\r' || + *start_title == '\n' || *start_title == '\t') + start_title++; + + if (*start_title == '\0') + return true; + + end_title = start_title; + /* Move over non-whitespace/comma/nul/quote chars (parameter title). */ + while (*end_title != ' ' && *end_title != '\r' && + *end_title != '\n' && *end_title != '\t' && + *end_title != '\0' && *end_title != ',' && + *end_title != '\'' && *end_title != '"') + end_title++; + + /* Fail on invalid end: there should be at least one space between + title and value, and the value should be non-empty. */ + if (*end_title == '\'' || *end_title == '"' || + *end_title == '\0' || *end_title == ',') + return true; + + return false; +} + +/** + Find the beginning and the end of a paramter value, and the value + delimiter + + Skip over whitespaces to find the start delimiter, then skip over + the param value to find the end delimiter + + @param start_value The end of the param title. Will be moved to + the start of the param value, just after the + delimiter + @param end_value Will be moved to the end of the param value, at + the delimiter + @param delim Will be assigned the param value delimiter, + either the single or double quote + @retval false Success + @retval true Failure +*/ +static bool spider_parse_find_value(char*& start_value, char*& end_value, + char& delim) +{ + /* Skip over whitespaces */ + while (*start_value == ' ' || *start_value == '\r' || + *start_value == '\n' || *start_value == '\t') + start_value++; + if (*start_value != '"' && *start_value != '\'') + return true; + delim= *start_value; + end_value= start_value++; + + while (1) + { + end_value++; + /* Escaping */ + if (*end_value == '\\') + { + end_value++; + /* The backslash cannot be at the end */ + if (*end_value == '\0') + return true; + } + else if (*end_value == delim) + return false; + else if (*end_value == '\0') + return true; + } +} + +/** + Find the beginning of the next parameter + + Skip over whitespaces, then check that the first non-whitespace char + is a comma or the end of string + + @param start_param The end of the param value. Will be moved to + the start of the next param definition, just + after the comma, if there's one; otherwise will + be moved to the end of the string + @retval false Success + @retval true Failure +*/ +static bool spider_parse_find_next(char*& start_param) +{ + /* Skip over whitespaces */ + while (*start_param == ' ' || *start_param == '\r' || + *start_param == '\n' || *start_param == '\t') + start_param++; + /* No more param definitions */ + if (*start_param == '\0') + return false; + else if (*start_param == ',') + { + start_param++; + return false; + } + else + return true; +} + +/** + Find the start and end of the current param title and value and the + value deliminator. + + @param start_param The beginning of the current param + definition. Will be mutated to the beginning + of the next param definition. + @retval false success + @retval true failure +*/ +bool st_spider_param_string_parse::locate_param_def(char*& start_param) +{ + DBUG_ENTER("parse::locate_param_def"); + start_title= start_param; + if (spider_parse_find_title(start_title, end_title)) + DBUG_RETURN(TRUE); + start_value= end_title; + if (spider_parse_find_value(start_value, end_value, delim_value)) + DBUG_RETURN(TRUE); + /* skip the delim */ + start_param= end_value + 1; + if (spider_parse_find_next(start_param)) + DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); +} + +/** + Handle parsing failure. + + Print error and optionally restore param value end delimiter that + has been nulled before. + + @param restore_delim If true, restore the end value delimiter + @return The error number +*/ +int st_spider_param_string_parse::fail(bool restore_delim) +{ + DBUG_ENTER("spider_parse_print_param_error"); + DBUG_ASSERT(error_num != 0); + /* Print the error message */ + switch (error_num) + { + case ER_SPIDER_INVALID_UDF_PARAM_NUM: + my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, + MYF(0), start_title); + break; + case ER_SPIDER_INVALID_CONNECT_INFO_NUM: + default: + my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, + MYF(0), start_title); + } + if (restore_delim) + *end_value = delim_value; + DBUG_RETURN(error_num); +} + + +/* + Parse connection information specified by COMMENT, CONNECT, or engine-defined + options. + + TODO: Deprecate the connection specification by COMMENT and CONNECT, + and then solely utilize engine-defined options. +*/ +int spider_parse_connect_info( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, + partition_info *part_info, + uint create_table) +{ + int error_num = 0; + char *connect_string = NULL; + char *start_param; + int title_length, value_length; + SPIDER_PARAM_STRING_PARSE parse; + SPIDER_ALTER_TABLE *share_alter; + ha_table_option_struct *option_struct; + partition_element *part_elem; + partition_element *sub_elem; + DBUG_ENTER("spider_parse_connect_info"); + DBUG_PRINT("info",("spider partition_info=%s", + table_share->partition_info_str)); + DBUG_PRINT("info",("spider part_info=%p", part_info)); + 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)); + spider_get_partition_info(share->table_name, share->table_name_length, + table_share, part_info, &part_elem, &sub_elem); + /* Find the correct table options, depending on if we are parsing a + table, a partition, or a sub-partition. */ + if (part_info) + if (part_info->is_sub_partitioned()) + option_struct= sub_elem->option_struct; + else + option_struct= part_elem->option_struct; + else + option_struct= table_share->option_struct; + + spider_minus_1(share, table_share); + for (int i = 4; i > 0; i--) + { + if (connect_string) + { + spider_free(spider_current_trx, connect_string, MYF(0)); + connect_string = NULL; + } + + /* Get the correct connect info for the current level. */ + int error_num_1 = spider_get_connect_info(i, part_elem, sub_elem, + table_share, connect_string); + if (error_num_1 == 1) + continue; + if (error_num_1 == HA_ERR_OUT_OF_MEM) + { + error_num= HA_ERR_OUT_OF_MEM; + goto error_alloc_conn_string; + } + DBUG_ASSERT(error_num_1 == 0); + + start_param = connect_string; + parse.error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; + while (*start_param != '\0') + { + if (parse.locate_param_def(start_param)) + { + error_num= parse.fail(false); + goto error; + } + /* Null the end of the parameter value. */ + *parse.end_value= '\0'; + value_length= (int) (parse.end_value - parse.start_value); + switch (title_length = (int) (parse.end_title - parse.start_title)) + { + case 0: + error_num= parse.fail(true); + goto error; + 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); + SPIDER_PARAM_DEPRECATED_WARNING("bfz"); + SPIDER_PARAM_INT("bfz", buffer_size, 0); + SPIDER_PARAM_LONGLONG("bfr", bgs_first_read, 0); + SPIDER_PARAM_INT("bmd", bgs_mode, 0); + SPIDER_PARAM_LONGLONG("bsr", bgs_second_read, 0); + SPIDER_PARAM_STR("bke", bka_engine); + SPIDER_PARAM_INT_WITH_MAX("bkm", bka_mode, 0, 2); + SPIDER_PARAM_INT("bsz", bulk_size, 0); + SPIDER_PARAM_DEPRECATED_WARNING("btt"); + SPIDER_PARAM_LONG_LIST_WITH_MAX("btt", bka_table_name_types, + 0, 1); + SPIDER_PARAM_INT_WITH_MAX("bum", bulk_update_mode, 0, 2); + SPIDER_PARAM_INT("bus", bulk_update_size, 0); + SPIDER_PARAM_INT_WITH_MAX("cbm", crd_bg_mode, 0, 2); + SPIDER_PARAM_DOUBLE("civ", crd_interval, 0); + SPIDER_PARAM_DEPRECATED_WARNING("cmd"); + SPIDER_PARAM_INT_WITH_MAX("cmd", crd_mode, 0, 3); + SPIDER_PARAM_INT_WITH_MAX("csr", casual_read, 0, 63); + SPIDER_PARAM_INT_WITH_MAX("csy", crd_sync, 0, 2); + SPIDER_PARAM_LONG_LIST_WITH_MAX("cto", connect_timeouts, 0, + 2147483647); + SPIDER_PARAM_DEPRECATED_WARNING("ctp"); + SPIDER_PARAM_INT_WITH_MAX("ctp", crd_type, 0, 2); + SPIDER_PARAM_DEPRECATED_WARNING("cwg"); + SPIDER_PARAM_DOUBLE("cwg", crd_weight, 1); + SPIDER_PARAM_INT_WITH_MAX("dat", delete_all_rows_type, 0, 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_STR_LIST("drv", tgt_drivers); + SPIDER_PARAM_STR_LIST("dsn", tgt_dsns); + SPIDER_PARAM_INT_WITH_MAX("erm", error_read_mode, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("ewm", error_write_mode, 0, 1); +#ifdef HA_CAN_FORCE_BULK_DELETE + SPIDER_PARAM_INT_WITH_MAX("fbd", force_bulk_delete, 0, 1); +#endif +#ifdef HA_CAN_FORCE_BULK_UPDATE + SPIDER_PARAM_INT_WITH_MAX("fbu", force_bulk_update, 0, 1); +#endif + SPIDER_PARAM_STR_LIST("fds", tgt_filedsns); + SPIDER_PARAM_LONGLONG("frd", first_read, 0); + SPIDER_PARAM_DEPRECATED_WARNING("isa"); + SPIDER_PARAM_INT("isa", init_sql_alloc_size, 0); + SPIDER_PARAM_DEPRECATED_WARNING("ilm"); + SPIDER_PARAM_LONGLONG("ilm", internal_limit, 0); + SPIDER_PARAM_DEPRECATED_WARNING("ios"); + 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_INT_WITH_MAX("lcs", load_crd_at_startup, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("lss", load_sts_at_startup, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("lst", link_statuses, 0, 3); + SPIDER_PARAM_LONG_LIST_WITH_MAX("mbf", monitoring_bg_flag, 0, 1); + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "mbi", monitoring_bg_interval, 0, 4294967295LL); + SPIDER_PARAM_LONG_LIST_WITH_MAX("mbk", monitoring_bg_kind, 0, 3); + SPIDER_PARAM_LONG_LIST_WITH_MAX("mbp", monitoring_binlog_pos_at_failing, 0, 2); + SPIDER_PARAM_LONG_LIST_WITH_MAX("mfg", monitoring_flag, 0, 1); + 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("qcs", query_cache_sync, 0, 3); + SPIDER_PARAM_INT_WITH_MAX("qmd", quick_mode, 0, 3); + SPIDER_PARAM_LONGLONG("qpb", quick_page_byte, 0); + 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); + SPIDER_PARAM_INT_WITH_MAX("sbm", sts_bg_mode, 0, 2); + 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_LONG_LIST_WITH_MAX("sgb", strict_group_bys, 0, 1); + SPIDER_PARAM_DOUBLE("siv", sts_interval, 0); + SPIDER_PARAM_STR_LIST("sky", tgt_ssl_keys); + SPIDER_PARAM_STR_LIST("sli", static_link_ids); + SPIDER_PARAM_INT_WITH_MAX("slc", store_last_crd, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("slm", selupd_lock_mode, 0, 2); + SPIDER_PARAM_INT_WITH_MAX("sls", store_last_sts, 0, 1); + SPIDER_PARAM_DEPRECATED_WARNING("smd"); + SPIDER_PARAM_INT_WITH_MAX("smd", sts_mode, 1, 2); + SPIDER_PARAM_LONGLONG("smr", static_mean_rec_length, 0); + SPIDER_PARAM_LONGLONG("spr", split_read, 0); + SPIDER_PARAM_INT_WITH_MAX("sps", skip_parallel_search, 0, 3); + 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_CHECK("srv", server_names, + option_struct && + option_struct->remote_server); + SPIDER_PARAM_DOUBLE("ssr", semi_split_read, 0); + SPIDER_PARAM_LONGLONG("ssl", semi_split_read_limit, 0); + SPIDER_PARAM_INT_WITH_MAX("ssy", sts_sync, 0, 2); + SPIDER_PARAM_DEPRECATED_WARNING("stc"); + SPIDER_PARAM_INT_WITH_MAX("stc", semi_table_lock_conn, 0, 1); + SPIDER_PARAM_DEPRECATED_WARNING("stl"); + SPIDER_PARAM_INT_WITH_MAX("stl", semi_table_lock, 0, 1); + SPIDER_PARAM_LONGLONG("srs", static_records_for_status, 0); + SPIDER_PARAM_LONG_LIST_WITH_MAX("svc", tgt_ssl_vscs, 0, 1); + SPIDER_PARAM_STR_LIST_CHECK("tbl", tgt_table_names, + option_struct && + option_struct->remote_table); + SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 3); + SPIDER_PARAM_INT_WITH_MAX("upu", use_pushdown_udf, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("utc", use_table_charset, 0, 1); + error_num = parse.fail(true); + 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 = parse.fail(true); + goto error; + case 5: + SPIDER_PARAM_STR_LIST_CHECK("table", tgt_table_names, + option_struct && + option_struct->remote_table); + error_num = parse.fail(true); + goto error; + case 6: + SPIDER_PARAM_STR_LIST("driver", tgt_drivers); + SPIDER_PARAM_STR_LIST_CHECK("server", server_names, + option_struct && + option_struct->remote_server); + 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); + SPIDER_PARAM_NUMHINT("skc", static_key_cardinality, 3, + (int) table_share->keys, spider_set_ll_value); + error_num = parse.fail(true); + goto error; + case 7: + SPIDER_PARAM_STR_LIST("filedsn", tgt_filedsns); + 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 = parse.fail(true); + goto error; + case 8: + SPIDER_PARAM_STR_LIST_CHECK("database", tgt_dbs, + option_struct && + option_struct->remote_database); + SPIDER_PARAM_STR_LIST("password", tgt_passwords); + SPIDER_PARAM_DEPRECATED_WARNING("sts_mode"); + SPIDER_PARAM_INT_WITH_MAX("sts_mode", sts_mode, 1, 2); + SPIDER_PARAM_INT_WITH_MAX("sts_sync", sts_sync, 0, 2); + SPIDER_PARAM_DEPRECATED_WARNING("crd_mode"); + SPIDER_PARAM_INT_WITH_MAX("crd_mode", crd_mode, 0, 3); + SPIDER_PARAM_INT_WITH_MAX("crd_sync", crd_sync, 0, 2); + SPIDER_PARAM_DEPRECATED_WARNING("crd_type"); + SPIDER_PARAM_INT_WITH_MAX("crd_type", crd_type, 0, 2); + SPIDER_PARAM_LONGLONG("priority", priority, 0); + SPIDER_PARAM_INT("bgs_mode", bgs_mode, 0); + SPIDER_PARAM_STR_LIST("ssl_cert", tgt_ssl_certs); + SPIDER_PARAM_INT_WITH_MAX("bka_mode", bka_mode, 0, 2); + error_num = parse.fail(true); + 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 = parse.fail(true); + goto error; + case 10: + SPIDER_PARAM_DEPRECATED_WARNING("crd_weight"); + 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 = parse.fail(true); + goto error; + case 11: + SPIDER_PARAM_INT_WITH_MAX("query_cache", query_cache, 0, 2); + SPIDER_PARAM_INT_WITH_MAX("crd_bg_mode", crd_bg_mode, 0, 2); + SPIDER_PARAM_INT_WITH_MAX("sts_bg_mode", sts_bg_mode, 0, 2); + SPIDER_PARAM_LONG_LIST_WITH_MAX("link_status", link_statuses, 0, 3); + SPIDER_PARAM_INT_WITH_MAX("casual_read", casual_read, 0, 63); + SPIDER_PARAM_DEPRECATED_WARNING("buffer_size"); + SPIDER_PARAM_INT("buffer_size", buffer_size, 0); + error_num = parse.fail(true); + 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); + error_num = parse.fail(true); + goto error; + case 13: + SPIDER_PARAM_STR_LIST("default_group", tgt_default_groups); + SPIDER_PARAM_STR_LIST("sequence_name", tgt_sequence_names); + error_num = parse.fail(true); + goto error; + case 14: + SPIDER_PARAM_DEPRECATED_WARNING("internal_limit"); + SPIDER_PARAM_LONGLONG("internal_limit", internal_limit, 0); + SPIDER_PARAM_LONGLONG("bgs_first_read", bgs_first_read, 0); + 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); + SPIDER_PARAM_STR_LIST("static_link_id", static_link_ids); + SPIDER_PARAM_INT_WITH_MAX("store_last_crd", store_last_crd, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("store_last_sts", store_last_sts, 0, 1); + error_num = parse.fail(true); + goto error; + case 15: + SPIDER_PARAM_DEPRECATED_WARNING("internal_offset"); + SPIDER_PARAM_LONGLONG("internal_offset", internal_offset, 0); + SPIDER_PARAM_INT_WITH_MAX("reset_sql_alloc", reset_sql_alloc, 0, 1); + SPIDER_PARAM_DEPRECATED_WARNING("semi_table_lock"); + SPIDER_PARAM_INT_WITH_MAX("semi_table_lock", semi_table_lock, 0, 1); + SPIDER_PARAM_LONGLONG("quick_page_byte", quick_page_byte, 0); + SPIDER_PARAM_LONGLONG("quick_page_size", quick_page_size, 0); + SPIDER_PARAM_LONGLONG("bgs_second_read", bgs_second_read, 0); + SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_flag", monitoring_flag, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_kind", monitoring_kind, 0, 3); + SPIDER_PARAM_DOUBLE("semi_split_read", semi_split_read, 0); + SPIDER_PARAM_LONG_LIST_WITH_MAX("connect_timeout", connect_timeouts, + 0, 2147483647); + SPIDER_PARAM_LONG_LIST_WITH_MAX("strict_group_by", + strict_group_bys, 0, 1); + SPIDER_PARAM_INT_WITH_MAX("error_read_mode", error_read_mode, 0, 1); + error_num = parse.fail(true); + 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( + "table_count_mode", table_count_mode, 0, 3); + 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); + SPIDER_PARAM_INT_WITH_MAX( + "error_write_mode", error_write_mode, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "query_cache_sync", query_cache_sync, 0, 3); + error_num = parse.fail(true); + 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); +#ifdef HA_CAN_FORCE_BULK_DELETE + SPIDER_PARAM_INT_WITH_MAX( + "force_bulk_delete", force_bulk_delete, 0, 1); +#endif +#ifdef HA_CAN_FORCE_BULK_UPDATE + SPIDER_PARAM_INT_WITH_MAX( + "force_bulk_update", force_bulk_update, 0, 1); +#endif + error_num = parse.fail(true); + goto error; + case 18: + SPIDER_PARAM_INT_WITH_MAX( + "select_column_mode", select_column_mode, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "monitoring_bg_flag", monitoring_bg_flag, 0, 1); + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "monitoring_bg_kind", monitoring_bg_kind, 0, 3); + SPIDER_PARAM_LONGLONG( + "direct_order_limit", direct_order_limit, 0); + error_num = parse.fail(true); + goto error; + case 19: + SPIDER_PARAM_DEPRECATED_WARNING("init_sql_alloc_size"); + 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); + SPIDER_PARAM_DEPRECATED_WARNING("bka_table_name_type"); + SPIDER_PARAM_LONG_LIST_WITH_MAX("bka_table_name_type", + bka_table_name_types, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "load_crd_at_startup", load_crd_at_startup, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "load_sts_at_startup", load_sts_at_startup, 0, 1); + error_num = parse.fail(true); + goto error; + case 20: + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "monitoring_server_id", monitoring_sid, 0, 4294967295LL); + SPIDER_PARAM_INT_WITH_MAX( + "delete_all_rows_type", delete_all_rows_type, 0, 1); + SPIDER_PARAM_INT_WITH_MAX( + "skip_parallel_search", skip_parallel_search, 0, 3); + error_num = parse.fail(true); + goto error; + case 21: + SPIDER_PARAM_LONGLONG( + "semi_split_read_limit", semi_split_read_limit, 0); + error_num = parse.fail(true); + goto error; + case 22: + SPIDER_PARAM_LONG_LIST_WITH_MAX( + "ssl_verify_server_cert", tgt_ssl_vscs, 0, 1); + SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( + "monitoring_bg_interval", monitoring_bg_interval, 0, 4294967295LL); + SPIDER_PARAM_INT_WITH_MAX( + "skip_default_condition", skip_default_condition, 0, 1); + SPIDER_PARAM_LONGLONG( + "static_mean_rec_length", static_mean_rec_length, 0); + error_num = parse.fail(true); + goto error; + case 23: + SPIDER_PARAM_INT_WITH_MAX( + "internal_optimize_local", internal_optimize_local, 0, 1); + error_num = parse.fail(true); + goto error; + case 25: + SPIDER_PARAM_LONGLONG("static_records_for_status", + static_records_for_status, 0); + SPIDER_PARAM_NUMHINT("static_key_cardinality", static_key_cardinality, + 3, (int) table_share->keys, spider_set_ll_value); + error_num = parse.fail(true); + goto error; + case 26: + SPIDER_PARAM_DEPRECATED_WARNING("semi_table_lock_connection"); + SPIDER_PARAM_INT_WITH_MAX( + "semi_table_lock_connection", semi_table_lock_conn, 0, 1); + error_num = parse.fail(true); + goto error; + case 32: + SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_binlog_pos_at_failing", + monitoring_binlog_pos_at_failing, 0, 2); + error_num = parse.fail(true); + goto error; + default: + error_num = parse.fail(true); + goto error; + } + /* Restore delim */ + *parse.end_value= parse.delim_value; + } + } + + SPIDER_OPTION_STR_LIST("server", remote_server, server_names); + SPIDER_OPTION_STR_LIST("database", remote_database, tgt_dbs); + SPIDER_OPTION_STR_LIST("table", remote_table, tgt_table_names); + + /* 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_dsns_length) + share->all_link_count = share->tgt_dsns_length; + if (share->all_link_count < share->tgt_filedsns_length) + share->all_link_count = share->tgt_filedsns_length; + if (share->all_link_count < share->tgt_drivers_length) + share->all_link_count = share->tgt_drivers_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->static_link_ids_length) + share->all_link_count = share->static_link_ids_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_binlog_pos_at_failing_length) + share->all_link_count = share->monitoring_binlog_pos_at_failing_length; + if (share->all_link_count < share->monitoring_flag_length) + share->all_link_count = share->monitoring_flag_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; + if (share->all_link_count < share->monitoring_bg_flag_length) + share->all_link_count = share->monitoring_bg_flag_length; + 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; + 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 (share->all_link_count < share->bka_table_name_types_length) + share->all_link_count = share->bka_table_name_types_length; + if (share->all_link_count < share->strict_group_bys_length) + share->all_link_count = share->strict_group_bys_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_dsns, + &share->tgt_dsns_lengths, + &share->tgt_dsns_length, + &share->tgt_dsns_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_filedsns, + &share->tgt_filedsns_lengths, + &share->tgt_filedsns_length, + &share->tgt_filedsns_charlen, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_string_list( + &share->tgt_drivers, + &share->tgt_drivers_lengths, + &share->tgt_drivers_length, + &share->tgt_drivers_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_null_string_list( + &share->static_link_ids, + &share->static_link_ids_lengths, + &share->static_link_ids_length, + &share->static_link_ids_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; + if ((error_num = spider_increase_long_list( + &share->monitoring_bg_flag, + &share->monitoring_bg_flag_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->monitoring_bg_kind, + &share->monitoring_bg_kind_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->monitoring_binlog_pos_at_failing, + &share->monitoring_binlog_pos_at_failing_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->monitoring_flag, + &share->monitoring_flag_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->monitoring_kind, + &share->monitoring_kind_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_longlong_list( + &share->monitoring_bg_interval, + &share->monitoring_bg_interval_length, + share->all_link_count))) + goto error; + 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 ((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; + if ((error_num = spider_increase_long_list( + &share->bka_table_name_types, + &share->bka_table_name_types_length, + share->all_link_count))) + goto error; + if ((error_num = spider_increase_long_list( + &share->strict_group_bys, + &share->strict_group_bys_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, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_table_names, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_dbs, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_hosts, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_usernames, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_passwords, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_sockets, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_wrappers, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_cas, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_capaths, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_certs, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_ciphers, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_keys, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_default_files, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_default_groups, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_dsns, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_filedsns, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_tgt_drivers, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_static_link_ids, + (uint) (sizeof(char *) * share->all_link_count), + &share_alter->tmp_server_names_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_table_names_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_dbs_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_hosts_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_usernames_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_passwords_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_sockets_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_wrappers_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_cas_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_capaths_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_certs_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_ciphers_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ssl_keys_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_default_files_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_default_groups_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_dsns_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_filedsns_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_drivers_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_static_link_ids_lengths, + (uint) (sizeof(uint *) * share->all_link_count), + &share_alter->tmp_tgt_ports, + (uint) (sizeof(long) * share->all_link_count), + &share_alter->tmp_tgt_ssl_vscs, + (uint) (sizeof(long) * share->all_link_count), + &share_alter->tmp_monitoring_binlog_pos_at_failing, + (uint) (sizeof(long) * share->all_link_count), + &share_alter->tmp_link_statuses, + (uint) (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); + memcpy(share_alter->tmp_tgt_table_names, share->tgt_table_names, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_dbs, share->tgt_dbs, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_hosts, share->tgt_hosts, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_usernames, share->tgt_usernames, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_passwords, share->tgt_passwords, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_sockets, share->tgt_sockets, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_wrappers, share->tgt_wrappers, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_cas, share->tgt_ssl_cas, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_capaths, share->tgt_ssl_capaths, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_certs, share->tgt_ssl_certs, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_ciphers, share->tgt_ssl_ciphers, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_keys, share->tgt_ssl_keys, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_default_files, share->tgt_default_files, + sizeof(char *) * 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_dsns, share->tgt_dsns, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_filedsns, share->tgt_filedsns, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_tgt_drivers, share->tgt_drivers, + sizeof(char *) * share->all_link_count); + memcpy(share_alter->tmp_static_link_ids, share->static_link_ids, + 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_monitoring_binlog_pos_at_failing, + share->monitoring_binlog_pos_at_failing, + 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); + memcpy(share_alter->tmp_tgt_table_names_lengths, + share->tgt_table_names_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_dbs_lengths, share->tgt_dbs_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_hosts_lengths, share->tgt_hosts_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_usernames_lengths, + share->tgt_usernames_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_passwords_lengths, + share->tgt_passwords_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_sockets_lengths, share->tgt_sockets_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_wrappers_lengths, + share->tgt_wrappers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_cas_lengths, + share->tgt_ssl_cas_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_capaths_lengths, + share->tgt_ssl_capaths_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_certs_lengths, + share->tgt_ssl_certs_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_ciphers_lengths, + share->tgt_ssl_ciphers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_ssl_keys_lengths, + share->tgt_ssl_keys_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_default_files_lengths, + share->tgt_default_files_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_default_groups_lengths, + share->tgt_default_groups_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_dsns_lengths, + share->tgt_dsns_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_filedsns_lengths, + share->tgt_filedsns_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_tgt_drivers_lengths, + share->tgt_drivers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(share_alter->tmp_static_link_ids_lengths, + share->static_link_ids_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_tgt_dsns_charlen = + share->tgt_dsns_charlen; + share_alter->tmp_tgt_filedsns_charlen = + share->tgt_filedsns_charlen; + share_alter->tmp_tgt_drivers_charlen = + share->tgt_drivers_charlen; + share_alter->tmp_static_link_ids_charlen = + share->static_link_ids_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_dsns_length = + share->tgt_dsns_length; + share_alter->tmp_tgt_filedsns_length = + share->tgt_filedsns_length; + share_alter->tmp_tgt_drivers_length = + share->tgt_drivers_length; + share_alter->tmp_static_link_ids_length = + share->static_link_ids_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_monitoring_binlog_pos_at_failing_length = + share->monitoring_binlog_pos_at_failing_length; + share_alter->tmp_link_statuses_length = share->link_statuses_length; + /* copy for tables end */ + + if ((error_num = spider_set_connect_info_default( + share, + part_elem, + sub_elem, + table_share + ))) + goto error; + + if (create_table) + { + for (int 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 && + !strcasecmp(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_dsns_lengths[%d] = %u", roop_count, + share->tgt_dsns_lengths[roop_count])); + if (share->tgt_dsns_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_dsns[roop_count], "dsn"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_filedsns_lengths[%d] = %u", roop_count, + share->tgt_filedsns_lengths[roop_count])); + if (share->tgt_filedsns_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_filedsns[roop_count], "filedsn"); + goto error; + } + + DBUG_PRINT("info", + ("spider tgt_drivers_lengths[%d] = %u", roop_count, + share->tgt_drivers_lengths[roop_count])); + if (share->tgt_drivers_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_drivers[roop_count], "driver"); + 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 static_link_ids_lengths[%d] = %u", roop_count, + share->static_link_ids_lengths[roop_count])); + if (share->static_link_ids_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->static_link_ids[roop_count], "static_link_id"); + goto error; + } + if (share->static_link_ids[roop_count]) + { + if ( + share->static_link_ids_lengths[roop_count] > 0 && + share->static_link_ids[roop_count][0] >= '0' && + share->static_link_ids[roop_count][0] <= '9' + ) { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_NUM; + my_printf_error(error_num, + ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_STR, + MYF(0), share->static_link_ids[roop_count], "static_link_id"); + goto error; + } + for (roop_count2 = roop_count + 1; + roop_count2 < (int) share->all_link_count; + roop_count2++) + { + if ( + share->static_link_ids_lengths[roop_count] == + share->static_link_ids_lengths[roop_count2] && + !memcmp(share->static_link_ids[roop_count], + share->static_link_ids[roop_count2], + share->static_link_ids_lengths[roop_count]) + ) { + error_num = ER_SPIDER_INVALID_CONNECT_INFO_SAME_NUM; + my_printf_error(error_num, + ER_SPIDER_INVALID_CONNECT_INFO_SAME_STR, + MYF(0), share->static_link_ids[roop_count], + "static_link_id"); + 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, + partition_element *part_elem, + partition_element *sub_elem, + TABLE_SHARE *table_share +) { + bool check_socket; + bool check_database; + bool check_default_file; + bool check_host; + bool check_port; + bool socket_has_default_value; + bool database_has_default_value; + bool default_file_has_default_value; + bool host_has_default_value; + bool port_has_default_value; + int error_num, roop_count, roop_count2; + 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_sockets[roop_count] && + ( + !share->tgt_hosts[roop_count] || + !strcmp(share->tgt_hosts[roop_count], my_localhost) + ) + ) { + check_socket = TRUE; + } else { + check_socket = FALSE; + } + if (!share->tgt_dbs[roop_count] && table_share) + { + check_database = TRUE; + } else { + check_database = FALSE; + } + if ( + !share->tgt_default_files[roop_count] && + share->tgt_default_groups[roop_count] && + (*spd_defaults_file || *spd_defaults_extra_file) + ) { + check_default_file = TRUE; + } else { + check_default_file = FALSE; + } + if (!share->tgt_hosts[roop_count]) + { + check_host = TRUE; + } else { + check_host = FALSE; + } + if (share->tgt_ports[roop_count] == -1) + { + check_port = TRUE; + } else { + check_port = FALSE; + } + if (check_socket || check_database || check_default_file || check_host || + check_port) + { + socket_has_default_value = check_socket; + database_has_default_value = check_database; + default_file_has_default_value = check_default_file; + host_has_default_value = check_host; + port_has_default_value = check_port; + if (share->tgt_wrappers[roop_count]) + { + 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) + ) { + if (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { + if (check_socket) + { + socket_has_default_value = spider_dbton[roop_count2]. + db_util->socket_has_default_value(); + } + if (check_database) + { + database_has_default_value = spider_dbton[roop_count2]. + db_util->database_has_default_value(); + } + if (check_default_file) + { + default_file_has_default_value = spider_dbton[roop_count2]. + db_util->default_file_has_default_value(); + } + if (check_host) + { + host_has_default_value = spider_dbton[roop_count2]. + db_util->host_has_default_value(); + } + if (check_port) + { + port_has_default_value = spider_dbton[roop_count2]. + db_util->port_has_default_value(); + } + break; + } + } + } + } + } else { + socket_has_default_value = FALSE; + database_has_default_value = FALSE; + default_file_has_default_value = FALSE; + host_has_default_value = FALSE; + port_has_default_value = FALSE; + } + + 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 (host_has_default_value) + { + 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 (database_has_default_value) + { + 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] = + table_share->table_name.length; + if ( + !(share->tgt_table_names[roop_count] = spider_create_table_name_string( + table_share->table_name.str, + (part_elem ? part_elem->partition_name : NULL), + (sub_elem ? sub_elem->partition_name : NULL) + )) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } + + if (default_file_has_default_value) + { + 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->static_link_ids[roop_count]) + { + DBUG_PRINT("info",("spider create default static_link_ids")); + share->static_link_ids_lengths[roop_count] = + SPIDER_DB_STATIC_LINK_ID_LEN; + if ( + !(share->static_link_ids[roop_count] = spider_create_string( + SPIDER_DB_STATIC_LINK_ID_STR, + share->static_link_ids_lengths[roop_count])) + ) { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + } +*/ + + if (port_has_default_value) + { + 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 (socket_has_default_value) + { + 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; + + if (share->monitoring_bg_flag[roop_count] == -1) + share->monitoring_bg_flag[roop_count] = 0; + if (share->monitoring_bg_kind[roop_count] == -1) + share->monitoring_bg_kind[roop_count] = 0; + if (share->monitoring_binlog_pos_at_failing[roop_count] == -1) + share->monitoring_binlog_pos_at_failing[roop_count] = 0; + if (share->monitoring_flag[roop_count] == -1) + share->monitoring_flag[roop_count] = 0; + if (share->monitoring_kind[roop_count] == -1) + share->monitoring_kind[roop_count] = 0; + if (share->monitoring_bg_interval[roop_count] == -1) + share->monitoring_bg_interval[roop_count] = 10000000; + if (share->monitoring_limit[roop_count] == -1) + share->monitoring_limit[roop_count] = 1; + if (share->monitoring_sid[roop_count] == -1) + share->monitoring_sid[roop_count] = global_system_variables.server_id; + + if (share->access_balances[roop_count] == -1) + share->access_balances[roop_count] = 100; + } + + if (share->query_cache == -1) + share->query_cache = 0; + if (share->query_cache_sync == -1) + share->query_cache_sync = 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->table_count_mode == -1) + share->table_count_mode = 0; + if (share->active_link_count == -1) + share->active_link_count = share->all_link_count; +#ifdef HA_CAN_FORCE_BULK_UPDATE + if (share->force_bulk_update == -1) + share->force_bulk_update = 0; +#endif +#ifdef HA_CAN_FORCE_BULK_DELETE + if (share->force_bulk_delete == -1) + share->force_bulk_delete = 0; +#endif + 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 +) { + uint roop_count, roop_count2; + bool check_database; + bool database_has_default_value; + DBUG_ENTER("spider_set_connect_info_default_db_table"); + for (roop_count = 0; roop_count < share->link_count; roop_count++) + { + if (!share->tgt_dbs[roop_count] && db_name) + { + check_database = TRUE; + } else { + check_database = FALSE; + } + if (check_database) + { + database_has_default_value = check_database; + if (share->tgt_wrappers[roop_count]) + { + 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) + ) { + if (spider_dbton[roop_count2].db_access_type == + SPIDER_DB_ACCESS_TYPE_SQL) + { + if (check_database) + { + database_has_default_value = spider_dbton[roop_count2]. + db_util->database_has_default_value(); + } + break; + } + } + } + } + } else { + database_has_default_value = FALSE; + } + + if (database_has_default_value) + { + 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) + )); +} + +#ifdef DBUG_TRACE +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]; + uint length_base = sizeof(uint) * share->all_link_count; + uint *conn_keys_lengths; + uint *sql_dbton_ids; + DBUG_ENTER("spider_create_conn_keys"); + char *ptr; + uint length = length_base * 2; + ptr = (char *) my_alloca(length); + if (!ptr) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + conn_keys_lengths = (uint *) ptr; + ptr += length_base; + sql_dbton_ids = (uint *) ptr; + + share->conn_keys_charlen = 0; + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + bool get_sql_id = FALSE; + 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 && + !strcasecmp(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 + ) { + sql_dbton_ids[roop_count] = roop_count2; + get_sql_id = TRUE; + break; + } + } + } + if (!get_sql_id) + sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE; + + bool tables_on_different_db_are_joinable; + if (get_sql_id) + { + tables_on_different_db_are_joinable = + spider_dbton[sql_dbton_ids[roop_count]].db_util-> + tables_on_different_db_are_joinable(); + } else { + tables_on_different_db_are_joinable = TRUE; + } + 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 + + (tables_on_different_db_are_joinable ? + 0 : share->tgt_dbs_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] + 1 + + share->tgt_dsns_lengths[roop_count] + 1 + + share->tgt_filedsns_lengths[roop_count] + 1 + + share->tgt_drivers_lengths[roop_count]; + share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2; + } + 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, length_base, + &share->conn_keys_hash_value, + sizeof(my_hash_value_type) * share->all_link_count, + &tmp_name, sizeof(char) * share->conn_keys_charlen, + &share->sql_dbton_ids, length_base, + NullS)) + ) { + my_afree(conn_keys_lengths); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + share->conn_keys_length = share->all_link_count; + memcpy(share->conn_keys_lengths, conn_keys_lengths, + length_base); + memcpy(share->sql_dbton_ids, sql_dbton_ids, length_base); + + my_afree(conn_keys_lengths); + + for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) + { + bool tables_on_different_db_are_joinable; + if (share->sql_dbton_ids[roop_count] != SPIDER_DBTON_SIZE) + { + tables_on_different_db_are_joinable = + spider_dbton[share->sql_dbton_ids[roop_count]].db_util-> + tables_on_different_db_are_joinable(); + } else { + tables_on_different_db_are_joinable = TRUE; + } + + 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]); + if (share->tgt_hosts[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]); + } else { + tmp_name++; + } + 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 (!tables_on_different_db_are_joinable) + { + if (share->tgt_dbs[roop_count]) + { + DBUG_PRINT("info",("spider tgt_dbs[%d]=%s", roop_count, + share->tgt_dbs[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_dbs[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++; + if (share->tgt_dsns[roop_count]) + { + DBUG_PRINT("info",("spider tgt_dsns[%d]=%s", roop_count, + share->tgt_dsns[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_dsns[roop_count]); + } else + tmp_name++; + if (share->tgt_filedsns[roop_count]) + { + DBUG_PRINT("info",("spider tgt_filedsns[%d]=%s", roop_count, + share->tgt_filedsns[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_filedsns[roop_count]); + } else + tmp_name++; + if (share->tgt_drivers[roop_count]) + { + DBUG_PRINT("info",("spider tgt_drivers[%d]=%s", roop_count, + share->tgt_drivers[roop_count])); + tmp_name = strmov(tmp_name + 1, share->tgt_drivers[roop_count]); + } else + tmp_name++; + tmp_name++; + tmp_name++; + 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]); + } + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) + { + if (spider_bit_is_set(share->dbton_bitmap, roop_count2)) + { + 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++; + 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, + partition_info *part_info, + my_hash_value_type hash_value, + int *error_num +) { + int bitmap_size, roop_count; + uint length; + int use_table_charset; + SPIDER_SHARE *share; + char *tmp_name; + longlong *tmp_cardinality, *tmp_static_key_cardinality; + uchar *tmp_cardinality_upd, *tmp_table_mon_mutex_bitmap; + char buf[MAX_FIELD_WIDTH], *buf_pos; + char link_idx_str[SPIDER_SQL_INT_LEN]; + bool checksum_support = TRUE; + 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, (uint) (sizeof(*share)), + &tmp_name, (uint) (length + 1), + &tmp_static_key_cardinality, + (uint) (sizeof(*tmp_static_key_cardinality) * table_share->keys), + &tmp_cardinality, + (uint) (sizeof(*tmp_cardinality) * table_share->fields), + &tmp_cardinality_upd, + (uint) (sizeof(*tmp_cardinality_upd) * bitmap_size), + &tmp_table_mon_mutex_bitmap, + (uint) (sizeof(*tmp_table_mon_mutex_bitmap) * + ((spider_udf_table_mon_mutex_count + 7) / 8)), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_share; + } + + SPD_INIT_ALLOC_ROOT(&share->mem_root, 4096, 0, MYF(MY_WME)); + share->use_count = 0; + share->use_dbton_count = 0; + share->table_name_length = length; + share->table_name = tmp_name; + strmov(share->table_name, table_name); + share->static_key_cardinality = tmp_static_key_cardinality; + share->cardinality = tmp_cardinality; + share->cardinality_upd = tmp_cardinality_upd; + share->table_mon_mutex_bitmap = tmp_table_mon_mutex_bitmap; + share->bitmap_size = bitmap_size; + share->table_share = table_share; + share->table_name_hash_value = hash_value; + share->table_path_hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_share->path.str, table_share->path.length); + share->table.s = table_share; + share->table.field = table_share->field; + share->table.key_info = table_share->key_info; + share->table.read_set = &table_share->all_set; + + 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, + part_info, + 0))) + goto error_parse_connect_string; + + for (roop_count = 0; roop_count < (int) share->all_link_count; + roop_count++) + { + my_sprintf(link_idx_str, (link_idx_str, "%010d", roop_count)); + buf_pos = strmov(buf, share->table_name); + buf_pos = strmov(buf_pos, link_idx_str); + *buf_pos = '\0'; + spider_set_bit(tmp_table_mon_mutex_bitmap, + spider_udf_calc_hash(buf, spider_udf_table_mon_mutex_count) + ); + } + + use_table_charset = spider_param_use_table_charset( + share->use_table_charset); + if (table_share->table_charset && 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 & 1) + share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT; + if (share->table_count_mode & 2) + share->additional_table_flags |= HA_HAS_RECORDS; + + if (mysql_mutex_init(spd_key_mutex_share, + &share->mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_mutex; + } + + if (mysql_mutex_init(spd_key_mutex_share_sts, + &share->sts_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_sts_mutex; + } + + if (mysql_mutex_init(spd_key_mutex_share_crd, + &share->crd_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_crd_mutex; + } + + if (!(share->lgtm_tblhnd_share = + spider_get_lgtm_tblhnd_share(tmp_name, length, hash_value, FALSE, TRUE, + error_num))) + { + goto error_get_lgtm_tblhnd_share; + } + + if (!(share->wide_share = + spider_get_wide_share(share, table_share, error_num))) + goto error_get_wide_share; + + 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; + } + if ( + spider_dbton[roop_count].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL && + !share->dbton_share[roop_count]->checksum_support() + ) { + checksum_support = FALSE; + } + } + } + if (checksum_support) + { + share->additional_table_flags |= + HA_HAS_OLD_CHECKSUM | + HA_HAS_NEW_CHECKSUM; + } + 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; + } + } + spider_free_wide_share(share->wide_share); +error_get_wide_share: +error_get_lgtm_tblhnd_share: + 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, buf_sz; + char *tmp_name; + int roop_count; + double sts_interval; + int sts_mode; + int sts_sync; + int auto_increment_mode; + double crd_interval; + int crd_mode; + int crd_sync; + char first_byte; + int semi_table_lock_conn; + int search_link_idx; + uint sql_command = thd_sql_command(thd); + SPIDER_Open_tables_backup open_tables_backup; + MEM_ROOT mem_root; + TABLE *table_tables = NULL; + bool init_mem_root = FALSE; + bool same_server_link; + int load_sts_at_startup; + int load_crd_at_startup; + user_var_entry *loop_check; + char *loop_check_buf; + TABLE_SHARE *top_share; + LEX_CSTRING lex_str; + DBUG_ENTER("spider_get_share"); + top_share = spider->wide_handler->top_share; + length = (uint) strlen(table_name); + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_name, length); + if (top_share) + { + lex_str.length = top_share->path.length + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN; + buf_sz = spider_unique_id.length > SPIDER_SQL_LOP_CHK_PRM_PRF_LEN ? + top_share->path.length + spider_unique_id.length + 2 : + lex_str.length + 2; + loop_check_buf = (char *) my_alloca(buf_sz); + if (unlikely(!loop_check_buf)) + { + *error_num = HA_ERR_OUT_OF_MEM; + DBUG_RETURN(NULL); + } + lex_str.str = loop_check_buf + buf_sz - lex_str.length - 2; + memcpy((void *) lex_str.str, + SPIDER_SQL_LOP_CHK_PRM_PRF_STR, SPIDER_SQL_LOP_CHK_PRM_PRF_LEN); + memcpy((void *) (lex_str.str + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN), + top_share->path.str, top_share->path.length); + ((char *) lex_str.str)[lex_str.length] = '\0'; + DBUG_PRINT("info",("spider loop check param name=%s", lex_str.str)); + loop_check = get_variable(&thd->user_vars, &lex_str, FALSE); + if (loop_check && loop_check->type == STRING_RESULT) + { + lex_str.length = top_share->path.length + spider_unique_id.length + 1; + lex_str.str = loop_check_buf + buf_sz - top_share->path.length - + spider_unique_id.length - 2; + memcpy((void *) lex_str.str, spider_unique_id.str, + spider_unique_id.length); + ((char *) lex_str.str)[lex_str.length - 1] = '-'; + ((char *) lex_str.str)[lex_str.length] = '\0'; + DBUG_PRINT("info",("spider loop check key=%s", lex_str.str)); + DBUG_PRINT("info",("spider loop check param value=%s", + loop_check->value)); + if (unlikely(strstr(loop_check->value, lex_str.str))) + { + *error_num = ER_SPIDER_INFINITE_LOOP_NUM; + my_printf_error(*error_num, ER_SPIDER_INFINITE_LOOP_STR, MYF(0), + top_share->db.str, top_share->table_name.str); + my_afree(loop_check_buf); + DBUG_RETURN(NULL); + } + } + my_afree(loop_check_buf); + } + pthread_mutex_lock(&spider_tbl_mutex); + if (!(share = (SPIDER_SHARE*) my_hash_search_using_hash_value( + &spider_open_tables, hash_value, (uchar*) table_name, length))) + { + if (!(share = spider_create_share( + table_name, table_share, + table->part_info, + hash_value, + error_num + ))) { + goto error_alloc_share; + } + + uint old_elements = spider_open_tables.array.max_element; + if (my_hash_insert(&spider_open_tables, (uchar*) share)) + { + *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); + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]); + } + if (!share->link_status_init) + { + /* + The link statuses need to be refreshed from the spider_tables table + if the operation: + - Is not a DROP TABLE on a permanent table; or + - Is an ALTER TABLE. + + Note that SHOW CREATE TABLE is not excluded, because the commands + that follow it require up-to-date link statuses. + */ + if ((table_share->tmp_table == NO_TMP_TABLE && + sql_command != SQLCOM_DROP_TABLE) || + /* for alter change link status */ + sql_command == SQLCOM_ALTER_TABLE) + { + 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)) + ) { + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + pthread_mutex_unlock(&share->mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_open_sys_table; + } + *error_num = spider_get_link_statuses(table_tables, share, + &mem_root); + if (*error_num) + { + if ( + *error_num != HA_ERR_KEY_NOT_FOUND && + *error_num != HA_ERR_END_OF_FILE + ) { + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + pthread_mutex_unlock(&share->mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + goto error_open_sys_table; + } + } else { + memcpy(share->alter_table.tmp_link_statuses, share->link_statuses, + sizeof(long) * share->all_link_count); + share->link_status_init = TRUE; + } + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } + share->have_recovery_link = spider_conn_check_recovery_link(share); + if (init_mem_root) + { + free_root(&mem_root, MYF(0)); + init_mem_root = FALSE; + } + } + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + 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->wide_handler->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(); + + if (!share->sts_spider_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->sts_spider_init) + { + if ((*error_num = spider_create_spider_object_for_share( + spider->wide_handler->trx, share, &share->sts_spider))) + { + pthread_mutex_unlock(&share->mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_sts_spider_init; + } + share->sts_thread = &spider_table_sts_threads[ + my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % + spider_param_table_sts_thread_count()]; + share->sts_spider_init = TRUE; + } + pthread_mutex_unlock(&share->mutex); + } + + if (!share->crd_spider_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->crd_spider_init) + { + if ((*error_num = spider_create_spider_object_for_share( + spider->wide_handler->trx, share, &share->crd_spider))) + { + pthread_mutex_unlock(&share->mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + spider_free_share(share); + goto error_crd_spider_init; + } + share->crd_thread = &spider_table_crd_threads[ + my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % + spider_param_table_crd_thread_count()]; + share->crd_spider_init = TRUE; + } + pthread_mutex_unlock(&share->mutex); + } + + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + (*error_num = spider_create_mon_threads(spider->wide_handler->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; + } + + 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, + &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->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, + &result_list->casual_read, sizeof(int) * 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); + + 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; + 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; + } + } + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_conn_keys; + } + + 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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + FALSE + ); + } + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_dbton_handler; + } + 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) + { + char *db = (char *) my_alloca( + table_share->db.length + 1 + table_share->table_name.length + 1); + if (!db) + { + *error_num = HA_ERR_OUT_OF_MEM; + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_dbton_handler; + } + char *table_name = db + table_share->db.length + 1; + 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); + my_afree(db); + *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; + goto error_after_alloc_dbton_handler; + } else if (search_link_idx == -2) + { + *error_num = HA_ERR_OUT_OF_MEM; + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_dbton_handler; + } + spider->search_link_idx = search_link_idx; + + same_server_link = spider_param_same_server_link(thd); + load_sts_at_startup = + spider_param_load_sts_at_startup(share->load_sts_at_startup); + load_crd_at_startup = + spider_param_load_crd_at_startup(share->load_crd_at_startup); + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + !spider->error_mode && + ( + !same_server_link || + load_sts_at_startup || + load_crd_at_startup + ) + ) { + 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); + 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; + 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; + crd_sync = spider_param_crd_sync(thd, share->crd_sync); + 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->wide_handler->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); + goto error_after_alloc_dbton_handler; + } + } + + if ( + ( + !same_server_link || + load_sts_at_startup + ) && + (*error_num = spider_get_sts(share, spider->search_link_idx, tmp_time, + spider, sts_interval, sts_mode, + sts_sync, + 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO)) + ) { + if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM) + { + thd->clear_error(); + } else { + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_dbton_handler; + } + } + if ( + ( + !same_server_link || + load_crd_at_startup + ) && + (*error_num = spider_get_crd(share, spider->search_link_idx, tmp_time, + spider, table, crd_interval, crd_mode, + crd_sync, + 1)) + ) { + if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM) + { + thd->clear_error(); + } else { + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + share->init_error = TRUE; + share->init_error_time = (time_t) time((time_t*) 0); + share->init = TRUE; + goto error_after_alloc_dbton_handler; + } + } + 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); + + int sleep_cnt = 0; + while (!share->init) + { + // avoid for dead loop + if (sleep_cnt++ > 1000) + { + fprintf(stderr, " [WARN SPIDER RESULT] " + "Wait share->init too long, table_name %s %s %ld\n", + share->table_name, share->tgt_hosts[0], share->tgt_ports[0]); + *error_num = ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM; + my_printf_error(ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM, + ER_SPIDER_TABLE_OPEN_TIMEOUT_STR, MYF(0), + table_share->db.str, table_share->table_name.str); + spider_free_share(share); + goto error_but_no_delete; + } + my_sleep(10000); // wait 10 ms + } + + if (!share->link_status_init) + { + pthread_mutex_lock(&share->mutex); + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]); + } + if (!share->link_status_init) + { + DBUG_ASSERT(!table_tables); + /* + The link statuses need to be refreshed from the spider_tables table + if the operation: + - Is not a DROP TABLE on a permanent table; or + - Is an ALTER TABLE. + + Note that SHOW CREATE TABLE is not excluded, because the commands + that follow it require up-to-date link statuses. + */ + if ((table_share->tmp_table == NO_TMP_TABLE && + sql_command != SQLCOM_DROP_TABLE) || + /* for alter change link status */ + sql_command == SQLCOM_ALTER_TABLE) + { + 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)) + ) { + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + 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) + { + if ( + *error_num != HA_ERR_KEY_NOT_FOUND && + *error_num != HA_ERR_END_OF_FILE + ) { + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + goto error_open_sys_table; + } + } else { + memcpy(share->alter_table.tmp_link_statuses, share->link_statuses, + sizeof(long) * share->all_link_count); + share->link_status_init = TRUE; + } + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + table_tables = NULL; + } + share->have_recovery_link = spider_conn_check_recovery_link(share); + if (init_mem_root) + { + free_root(&mem_root, MYF(0)); + init_mem_root = FALSE; + } + } + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++ + ) { + if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) + pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); + } + 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->wide_handler->trx = spider_get_trx(thd, TRUE, error_num))) + { + spider_free_share(share); + goto error_but_no_delete; + } + spider->set_error_mode(); + + if (!share->sts_spider_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->sts_spider_init) + { + if ((*error_num = spider_create_spider_object_for_share( + spider->wide_handler->trx, share, &share->sts_spider))) + { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_sts_spider_init; + } + share->sts_thread = &spider_table_sts_threads[ + my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % + spider_param_table_sts_thread_count()]; + share->sts_spider_init = TRUE; + } + pthread_mutex_unlock(&share->mutex); + } + + if (!share->crd_spider_init) + { + pthread_mutex_lock(&share->mutex); + if (!share->crd_spider_init) + { + if ((*error_num = spider_create_spider_object_for_share( + spider->wide_handler->trx, share, &share->crd_spider))) + { + pthread_mutex_unlock(&share->mutex); + spider_free_share(share); + goto error_crd_spider_init; + } + share->crd_thread = &spider_table_crd_threads[ + my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % + spider_param_table_crd_thread_count()]; + share->crd_spider_init = TRUE; + } + pthread_mutex_unlock(&share->mutex); + } + + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + (*error_num = spider_create_mon_threads(spider->wide_handler->trx, + share)) + ) { + spider_free_share(share); + goto error_but_no_delete; + } + + 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, + &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->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, + &result_list->casual_read, sizeof(int) * 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); + + 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; + 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_after_alloc_conn_keys; + } + + 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->wide_handler->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->wide_handler->trx, + spider->wide_handler->trx->thd, + share, + roop_count, + (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], + share->monitoring_flag[roop_count], + FALSE + ); + } + goto error_after_alloc_dbton_handler; + } + 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) + { + char *db = (char *) my_alloca( + table_share->db.length + 1 + table_share->table_name.length + 1); + if (!db) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_after_alloc_dbton_handler; + } + char *table_name = db + table_share->db.length + 1; + 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); + my_afree(db); + *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM; + goto error_after_alloc_dbton_handler; + } else if (search_link_idx == -2) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_after_alloc_dbton_handler; + } + 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) + { + same_server_link = spider_param_same_server_link(thd); + load_sts_at_startup = + spider_param_load_sts_at_startup(share->load_sts_at_startup); + load_crd_at_startup = + spider_param_load_crd_at_startup(share->load_crd_at_startup); + if ( + sql_command != SQLCOM_DROP_TABLE && + sql_command != SQLCOM_ALTER_TABLE && + sql_command != SQLCOM_SHOW_CREATE && + !spider->error_mode && + ( + !same_server_link || + load_sts_at_startup || + load_crd_at_startup + ) + ) { + 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); + 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; + 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; + crd_sync = spider_param_crd_sync(thd, share->crd_sync); + time_t tmp_time = (time_t) time((time_t*) 0); + if ((spider_init_error_table = + spider_get_init_error_table(spider->wide_handler->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); + goto error_after_alloc_dbton_handler; + } + } + + if ( + ( + !same_server_link || + load_sts_at_startup + ) && + (*error_num = spider_get_sts(share, spider->search_link_idx, + tmp_time, spider, sts_interval, sts_mode, + sts_sync, + 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO)) + ) { + if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM) + { + thd->clear_error(); + } else { + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + goto error_after_alloc_dbton_handler; + } + } + if ( + ( + !same_server_link || + load_crd_at_startup + ) && + (*error_num = spider_get_crd(share, spider->search_link_idx, + tmp_time, spider, table, crd_interval, crd_mode, + crd_sync, + 1)) + ) { + if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM) + { + thd->clear_error(); + } else { + pthread_mutex_unlock(&share->crd_mutex); + pthread_mutex_unlock(&share->sts_mutex); + goto error_after_alloc_dbton_handler; + } + } + } + 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_after_alloc_dbton_handler: + 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]) + { + delete spider->dbton_handler[dbton_id]; + spider->dbton_handler[dbton_id] = NULL; + } + } +error_after_alloc_conn_keys: + spider_free(spider_current_trx, spider->conn_keys, MYF(0)); + spider->conn_keys = NULL; + spider_free_share(share); + goto error_but_no_delete; + +error_hash_insert: + spider_free_share_resource_only(share); +error_alloc_share: + pthread_mutex_unlock(&spider_tbl_mutex); +error_open_sys_table: +error_crd_spider_init: +error_sts_spider_init: + 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); + 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); + bool do_delete_thd = false; + THD *thd = current_thd; + if (!--share->use_count) + { + spider_free_sts_thread(share); + spider_free_crd_thread(share); + spider_free_mon_threads(share); + if (share->sts_spider_init) + { + spider_table_remove_share_from_sts_thread(share); + spider_free_spider_object_for_share(&share->sts_spider); + } + if (share->crd_spider_init) + { + spider_table_remove_share_from_crd_thread(share); + spider_free_spider_object_for_share(&share->crd_spider); + } + if ( + share->sts_init && + share->table_share->tmp_table == NO_TMP_TABLE && + spider_param_store_last_sts(share->store_last_sts) + ) { + if (!thd) + { + /* Create a thread for Spider system table update */ + thd = spider_create_thd(); + if (!thd) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + do_delete_thd = TRUE; + } + spider_sys_insert_or_update_table_sts( + thd, + share->lgtm_tblhnd_share->table_name, + share->lgtm_tblhnd_share->table_name_length, + &share->stat, + FALSE + ); + } + if ( + share->crd_init && + share->table_share->tmp_table == NO_TMP_TABLE && + spider_param_store_last_crd(share->store_last_crd) + ) { + if (!thd) + { + /* Create a thread for Spider system table update */ + thd = spider_create_thd(); + if (!thd) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + do_delete_thd = TRUE; + } + spider_sys_insert_or_update_table_crd( + thd, + share->lgtm_tblhnd_share->table_name, + share->lgtm_tblhnd_share->table_name_length, + share->cardinality, + share->table_share->fields, + FALSE + ); + } + spider_free_share_alloc(share); + my_hash_delete(&spider_open_tables, (uchar*) share); + pthread_mutex_destroy(&share->crd_mutex); + pthread_mutex_destroy(&share->sts_mutex); + pthread_mutex_destroy(&share->mutex); + free_root(&share->mem_root, MYF(0)); + spider_free(spider_current_trx, share, MYF(0)); + } + if (do_delete_thd) + spider_destroy_thd(thd); + pthread_mutex_unlock(&spider_tbl_mutex); + DBUG_RETURN(0); +} + +void spider_update_link_status_for_share( + const char *table_name, + uint table_name_length, + int link_idx, + long link_status +) { + SPIDER_SHARE *share; + DBUG_ENTER("spider_update_link_status_for_share"); + + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_name, table_name_length); + pthread_mutex_lock(&spider_tbl_mutex); + if ((share = (SPIDER_SHARE*) my_hash_search_using_hash_value( + &spider_open_tables, hash_value, (uchar*) table_name, + table_name_length))) + { + DBUG_PRINT("info", ("spider share->link_status_init=%s", + share->link_status_init ? "TRUE" : "FALSE")); + if (share->link_status_init) + { + DBUG_PRINT("info", ("spider share->link_statuses[%d]=%ld", + link_idx, link_status)); + share->link_statuses[link_idx] = link_status; + } + } + pthread_mutex_unlock(&spider_tbl_mutex); + DBUG_VOID_RETURN; +} + +SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( + const char *table_name, + uint table_name_length, + my_hash_value_type hash_value, + bool locked, + bool need_to_create, + int *error_num +) +{ + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; + char *tmp_name; + DBUG_ENTER("spider_get_lgtm_tblhnd_share"); + + if (!locked) + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) + my_hash_search_using_hash_value( + &spider_lgtm_tblhnd_share_hash, hash_value, + (uchar*) table_name, table_name_length))) + { + DBUG_PRINT("info",("spider create new lgtm tblhnd share")); + if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE *) + spider_bulk_malloc(spider_current_trx, 244, MYF(MY_WME | MY_ZEROFILL), + &lgtm_tblhnd_share, (uint) (sizeof(*lgtm_tblhnd_share)), + &tmp_name, (uint) (table_name_length + 1), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_share; + } + + lgtm_tblhnd_share->table_name_length = table_name_length; + lgtm_tblhnd_share->table_name = tmp_name; + memcpy(lgtm_tblhnd_share->table_name, table_name, + lgtm_tblhnd_share->table_name_length); + lgtm_tblhnd_share->table_path_hash_value = hash_value; + + if (mysql_mutex_init(spd_key_mutex_share_auto_increment, + &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_auto_increment_mutex; + } + + uint old_elements = spider_lgtm_tblhnd_share_hash.array.max_element; + if (my_hash_insert(&spider_lgtm_tblhnd_share_hash, + (uchar*) lgtm_tblhnd_share)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_hash_insert; + } + if (spider_lgtm_tblhnd_share_hash.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_lgtm_tblhnd_share_hash, + (spider_lgtm_tblhnd_share_hash.array.max_element - old_elements) * + spider_lgtm_tblhnd_share_hash.array.size_of_element); + } + } + if (!locked) + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + + DBUG_PRINT("info",("spider lgtm_tblhnd_share=%p", lgtm_tblhnd_share)); + DBUG_RETURN(lgtm_tblhnd_share); + +error_hash_insert: + pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex); +error_init_auto_increment_mutex: + spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0)); +error_alloc_share: + if (!locked) + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + DBUG_RETURN(NULL); +} + +void spider_free_lgtm_tblhnd_share_alloc( + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share, + bool locked +) { + DBUG_ENTER("spider_free_lgtm_tblhnd_share"); + if (!locked) + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + my_hash_delete(&spider_lgtm_tblhnd_share_hash, (uchar*) lgtm_tblhnd_share); + pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex); + spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0)); + if (!locked) + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); + DBUG_VOID_RETURN; +} + +SPIDER_WIDE_SHARE *spider_get_wide_share( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, + int *error_num +) { + SPIDER_WIDE_SHARE *wide_share; + char *tmp_name; + longlong *tmp_cardinality; + DBUG_ENTER("spider_get_wide_share"); + + pthread_mutex_lock(&spider_wide_share_mutex); + if (!(wide_share = (SPIDER_WIDE_SHARE*) + my_hash_search_using_hash_value( + &spider_open_wide_share, share->table_path_hash_value, + (uchar*) table_share->path.str, table_share->path.length))) + { + DBUG_PRINT("info",("spider create new wide share")); + if (!(wide_share = (SPIDER_WIDE_SHARE *) + spider_bulk_malloc(spider_current_trx, 51, MYF(MY_WME | MY_ZEROFILL), + &wide_share, sizeof(SPIDER_WIDE_SHARE), + &tmp_name, (uint) (table_share->path.length + 1), + &tmp_cardinality, + (uint) (sizeof(*tmp_cardinality) * table_share->fields), + NullS)) + ) { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_alloc_share; + } + + wide_share->use_count = 0; + wide_share->table_name_length = table_share->path.length; + wide_share->table_name = tmp_name; + memcpy(wide_share->table_name, table_share->path.str, + wide_share->table_name_length); + wide_share->table_path_hash_value = share->table_path_hash_value; + wide_share->cardinality = tmp_cardinality; + + wide_share->crd_get_time = wide_share->sts_get_time = + share->crd_get_time; + + if (mysql_mutex_init(spd_key_mutex_wide_share_sts, + &wide_share->sts_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_sts_mutex; + } + + if (mysql_mutex_init(spd_key_mutex_wide_share_crd, + &wide_share->crd_mutex, MY_MUTEX_INIT_FAST)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_init_crd_mutex; + } + + thr_lock_init(&wide_share->lock); + + uint old_elements = spider_open_wide_share.array.max_element; + if (my_hash_insert(&spider_open_wide_share, (uchar*) wide_share)) + { + *error_num = HA_ERR_OUT_OF_MEM; + goto error_hash_insert; + } + if (spider_open_wide_share.array.max_element > old_elements) + { + spider_alloc_calc_mem(spider_current_trx, + spider_open_wide_share, + (spider_open_wide_share.array.max_element - old_elements) * + spider_open_wide_share.array.size_of_element); + } + } + wide_share->use_count++; + pthread_mutex_unlock(&spider_wide_share_mutex); + + DBUG_PRINT("info",("spider wide_share=%p", wide_share)); + DBUG_RETURN(wide_share); + +error_hash_insert: + pthread_mutex_destroy(&wide_share->crd_mutex); +error_init_crd_mutex: + pthread_mutex_destroy(&wide_share->sts_mutex); +error_init_sts_mutex: + spider_free(spider_current_trx, wide_share, MYF(0)); +error_alloc_share: + pthread_mutex_unlock(&spider_wide_share_mutex); + DBUG_RETURN(NULL); +} + +int spider_free_wide_share( + SPIDER_WIDE_SHARE *wide_share +) { + DBUG_ENTER("spider_free_wide_share"); + pthread_mutex_lock(&spider_wide_share_mutex); + if (!--wide_share->use_count) + { + thr_lock_delete(&wide_share->lock); + my_hash_delete(&spider_open_wide_share, (uchar*) wide_share); + pthread_mutex_destroy(&wide_share->crd_mutex); + pthread_mutex_destroy(&wide_share->sts_mutex); + spider_free(spider_current_trx, wide_share, MYF(0)); + } + pthread_mutex_unlock(&spider_wide_share_mutex); + DBUG_RETURN(0); +} + +void spider_copy_sts_to_wide_share( + SPIDER_WIDE_SHARE *wide_share, + SPIDER_SHARE *share +) { + DBUG_ENTER("spider_copy_sts_to_pt_share"); + wide_share->stat = share->stat; + DBUG_VOID_RETURN; +} + +void spider_copy_sts_to_share( + SPIDER_SHARE *share, + SPIDER_WIDE_SHARE *wide_share +) { + DBUG_ENTER("spider_copy_sts_to_share"); + share->stat = wide_share->stat; + DBUG_VOID_RETURN; +} + +void spider_copy_crd_to_wide_share( + SPIDER_WIDE_SHARE *wide_share, + SPIDER_SHARE *share, + int fields +) { + DBUG_ENTER("spider_copy_crd_to_wide_share"); + memcpy(wide_share->cardinality, share->cardinality, + sizeof(longlong) * fields); + DBUG_VOID_RETURN; +} + +void spider_copy_crd_to_share( + SPIDER_SHARE *share, + SPIDER_WIDE_SHARE *wide_share, + int fields +) { + DBUG_ENTER("spider_copy_crd_to_share"); + memcpy(share->cardinality, wide_share->cardinality, + sizeof(longlong) * fields); + DBUG_VOID_RETURN; +} + +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; + SPIDER_Open_tables_backup open_tables_backup; + 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((void*)&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, + NULL, + NULL, + 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_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &mon_val; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; + if ((error_num = spider_db_before_query(conn, &mon_val))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + 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->wide_handler->lock_type = TL_READ_NO_INSERT; + + if (!(share = (SPIDER_SHARE *) + spider_bulk_malloc(spider_current_trx, 52, MYF(MY_WME | MY_ZEROFILL), + &share, (uint) (sizeof(*share)), + &connect_info, + (uint) (sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT), + &connect_info_length, + (uint) (sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT), + &long_info, (uint) (sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT), + &longlong_info, + (uint) (sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT), + &conns, (uint) (sizeof(SPIDER_CONN *)), + &need_mon, (uint) (sizeof(int)), + &spider->conn_link_idx, (uint) (sizeof(uint)), + &spider->conn_can_fo, (uint) (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((void*)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->wide_handler->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; + SPIDER_CONN *conn; + SPIDER_TRX *trx; + DBUG_ENTER("spider_close_connection"); + if (!(trx = (SPIDER_TRX*) thd_get_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + + trx->tmp_spider->conns = &conn; + 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(trx->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, false); + + 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; + bool do_delete_thd; + THD *thd = current_thd, *tmp_thd; + SPIDER_CONN *conn; + SPIDER_INIT_ERROR_TABLE *spider_init_error_table; + SPIDER_TABLE_MON_LIST *table_mon_list; + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; + DBUG_ENTER("spider_db_done"); + + /* Begin Spider plugin deinit */ + if (thd) + do_delete_thd = FALSE; + else + { + /* Create a thread for Spider plugin deinit */ + thd = spider_create_thd(); + if (!thd) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + do_delete_thd = TRUE; + } + + 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_table_crd_thread_count() - 1; + roop_count >= 0; roop_count--) + { + spider_free_crd_threads(&spider_table_crd_threads[roop_count]); + } + for (roop_count = spider_param_table_sts_thread_count() - 1; + roop_count >= 0; roop_count--) + { + spider_free_sts_threads(&spider_table_sts_threads[roop_count]); + } + spider_free(NULL, spider_table_sts_threads, MYF(0)); + + for (roop_count= spider_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))) + { + my_hash_delete(&spider_udf_table_mon_list_hash[roop_count], + (uchar*) table_mon_list); + 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_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_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)); + + pthread_mutex_lock(&spider_allocated_thds_mutex); + while ((tmp_thd = (THD *) my_hash_element(&spider_allocated_thds, 0))) + { + SPIDER_TRX *trx = (SPIDER_TRX *) + thd_get_ha_data(tmp_thd, spider_hton_ptr); + if (trx) + { + DBUG_ASSERT(tmp_thd == trx->thd); + spider_free_trx(trx, FALSE); + thd_set_ha_data(tmp_thd, spider_hton_ptr, NULL); + } + else + my_hash_delete(&spider_allocated_thds, (uchar *) tmp_thd); + } + pthread_mutex_unlock(&spider_allocated_thds_mutex); + + pthread_mutex_lock(&spider_conn_mutex); + while ((conn = (SPIDER_CONN*) my_hash_element(&spider_open_connections, 0))) + { + my_hash_delete(&spider_open_connections, (uchar*) conn); + spider_free_conn(conn); + } + pthread_mutex_unlock(&spider_conn_mutex); + pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); + while ((lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_element( + &spider_lgtm_tblhnd_share_hash, 0))) + { + spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE); + } + pthread_mutex_unlock(&spider_lgtm_tblhnd_share_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); + 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); + my_hash_free(&spider_ipport_conns); + spider_free_mem_calc(spider_current_trx, + spider_lgtm_tblhnd_share_hash_id, + spider_lgtm_tblhnd_share_hash.array.max_element * + spider_lgtm_tblhnd_share_hash.array.size_of_element); + my_hash_free(&spider_lgtm_tblhnd_share_hash); + spider_free_mem_calc(spider_current_trx, + spider_open_wide_share_id, + spider_open_wide_share.array.max_element * + spider_open_wide_share.array.size_of_element); + my_hash_free(&spider_open_wide_share); + 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))) + { + my_hash_delete(&spider_init_error_tables, + (uchar*) spider_init_error_table); + 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); + pthread_mutex_destroy(&spider_conn_mutex); + pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex); + pthread_mutex_destroy(&spider_wide_share_mutex); + pthread_mutex_destroy(&spider_init_error_tbl_mutex); + pthread_mutex_destroy(&spider_conn_id_mutex); + pthread_mutex_destroy(&spider_ipport_conn_mutex); + pthread_mutex_destroy(&spider_thread_id_mutex); + pthread_mutex_destroy(&spider_tbl_mutex); + pthread_attr_destroy(&spider_pt_attr); + + 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" + )); + } + + /* End Spider plugin deinit */ + if (do_delete_thd) + spider_destroy_thd(thd); + +/* +DBUG_ASSERT(0); +*/ + DBUG_RETURN(0); +} + +int spider_panic( + handlerton *hton, + ha_panic_function type +) { + DBUG_ENTER("spider_panic"); + DBUG_RETURN(0); +} + +/* + Create or fix the system tables. See spd_init_query.h for the details. +*/ +bool spider_init_system_tables() +{ + DBUG_ENTER("spider_init_system_tables"); + + MYSQL *mysql= mysql_init(NULL); + if (!mysql) + { + DBUG_RETURN(TRUE); + } + + if (!mysql_real_connect_local(mysql)) + { + mysql_close(mysql); + DBUG_RETURN(TRUE); + } + + const int size= sizeof(spider_init_queries) / sizeof(spider_init_queries[0]); + for (int i= 0; i < size; i++) + { + const LEX_STRING *query= &spider_init_queries[i]; + if (mysql_real_query(mysql, query->str, query->length)) + { + fprintf(stderr, + "[ERROR] SPIDER plugin initialization failed at '%s' by '%s'\n", + query->str, mysql_error(mysql)); + + mysql_close(mysql); + DBUG_RETURN(TRUE); + } + + if (MYSQL_RES *res= mysql_store_result(mysql)) + { + mysql_free_result(res); + } + } + + mysql_close(mysql); + + DBUG_RETURN(FALSE); +} + +int spider_db_init( + void *p +) { + int error_num = HA_ERR_OUT_OF_MEM, roop_count; + uint dbton_id = 0; + uchar addr[6]; + handlerton *spider_hton = (handlerton *)p; + DBUG_ENTER("spider_db_init"); + + const LEX_CSTRING aria_name={STRING_WITH_LEN("Aria")}; + if (!plugin_is_ready(&aria_name, MYSQL_STORAGE_ENGINE_PLUGIN)) + DBUG_RETURN(HA_ERR_RETRY_INIT); + + spider_hton_ptr = spider_hton; + + spider_hton->flags = HTON_TEMPORARY_NOT_SUPPORTED; +#ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION + spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION; +#endif + /* 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; + spider_hton->discover_table_structure = spider_discover_table_structure; + 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; + spider_hton->create_group_by = spider_create_group_by_handler; + spider_hton->table_options= spider_table_option_list; + + if (my_gethwaddr((uchar *) addr)) + { + my_printf_error(ER_SPIDER_CANT_NUM, ER_SPIDER_CANT_STR1, MYF(ME_WARNING), + "get hardware address with error ", errno); + bzero(addr,6); + } + spider_unique_id.str = spider_unique_id_buf; + spider_unique_id.length = my_sprintf(spider_unique_id_buf, + (spider_unique_id_buf, "-%02x%02x%02x%02x%02x%02x-%lx-", + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], (ulong) getpid())); + + 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)); + +#ifndef SPIDER_HAS_NEXT_THREAD_ID + spd_db_att_thread_id = &thread_id; +#endif + spd_charset_utf8mb3_bin = &my_charset_utf8mb3_bin; + spd_defaults_extra_file = &my_defaults_extra_file; + spd_defaults_file = &my_defaults_file; + spd_mysqld_unix_port = (const char **) &mysqld_unix_port; + spd_mysqld_port = &mysqld_port; + spd_abort_loop = &abort_loop; + spd_tz_system = my_tz_SYSTEM; + +#ifdef HAVE_PSI_INTERFACE + init_spider_psi_keys(); +#endif + + if (pthread_attr_init(&spider_pt_attr)) + goto error_pt_attr_init; +/* + if (pthread_attr_setdetachstate(&spider_pt_attr, PTHREAD_CREATE_DETACHED)) + goto error_pt_attr_setstate; +*/ + + if (mysql_mutex_init(spd_key_mutex_tbl, + &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) + goto error_tbl_mutex_init; + + if (mysql_mutex_init(spd_key_thread_id, + &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) + goto error_thread_id_mutex_init; + + if (mysql_mutex_init(spd_key_conn_id, + &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) + goto error_conn_id_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_ipport_count, + &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) + goto error_ipport_count_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_init_error_tbl, + &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) + goto error_init_error_tbl_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_wide_share, + &spider_wide_share_mutex, MY_MUTEX_INIT_FAST)) + goto error_wide_share_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share, + &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) + goto error_lgtm_tblhnd_share_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_conn, + &spider_conn_mutex, MY_MUTEX_INIT_FAST)) + goto error_conn_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_open_conn, + &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) + goto error_open_conn_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_allocated_thds, + &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) + goto error_allocated_thds_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_mon_table_cache, + &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) + goto error_mon_table_cache_mutex_init; + + if (mysql_mutex_init(spd_key_mutex_mem_calc, + &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) + goto error_mem_calc_mutex_init; + + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_tables, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_tbl_get_key, 0, 0)) + 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(PSI_INSTRUMENT_ME, &spider_init_error_tables, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_tbl_get_key, 0, 0)) + 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); + if( + my_hash_init(PSI_INSTRUMENT_ME, &spider_open_wide_share, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_wide_share_get_key, 0, 0) + ) + goto error_open_wide_share_hash_init; + + spider_alloc_calc_mem_init(spider_open_wide_share, 145); + spider_alloc_calc_mem(NULL, + spider_open_wide_share, + spider_open_wide_share.array.max_element * + spider_open_wide_share.array.size_of_element); + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_lgtm_tblhnd_share_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0)) + goto error_lgtm_tblhnd_share_hash_init; + + spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, 245); + spider_alloc_calc_mem(NULL, + spider_lgtm_tblhnd_share_hash, + spider_lgtm_tblhnd_share_hash.array.max_element * + spider_lgtm_tblhnd_share_hash.array.size_of_element); + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_connections, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_conn_get_key, 0, 0)) + goto error_open_connections_hash_init; + + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_ipport_conns, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_ipport_conn_get_key, + spider_free_ipport_conn, 0)) + goto error_ipport_conn__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 (my_hash_init(PSI_INSTRUMENT_ME, &spider_allocated_thds, spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_allocated_thds_get_key, 0, 0)) + 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))) + 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, (uint) (sizeof(pthread_mutex_t) * + spider_udf_table_mon_mutex_count), + &spider_udf_table_mon_conds, (uint) (sizeof(pthread_cond_t) * + spider_udf_table_mon_mutex_count), + &spider_udf_table_mon_list_hash, (uint) (sizeof(HASH) * + spider_udf_table_mon_mutex_count), + NullS)) + ) + goto error_alloc_mon_mutxes; + + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++) + { + if (mysql_mutex_init(spd_key_mutex_udf_table_mon, + &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) + goto error_init_udf_table_mon_mutex; + } + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++) + { + if (mysql_cond_init(spd_key_cond_udf_table_mon, + &spider_udf_table_mon_conds[roop_count], NULL)) + goto error_init_udf_table_mon_cond; + } + for (roop_count = 0; + roop_count < (int) spider_udf_table_mon_mutex_count; + roop_count++) + { + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_udf_table_mon_list_hash[roop_count], + spd_charset_utf8mb3_bin, 32, 0, 0, + (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0)) + 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); + } + + if (spider_init_system_tables()) + { + goto error_system_table_creation; + } + + if (!(spider_table_sts_threads = (SPIDER_THREAD *) + spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL), + &spider_table_sts_threads, (uint) (sizeof(SPIDER_THREAD) * + spider_param_table_sts_thread_count()), + &spider_table_crd_threads, (uint) (sizeof(SPIDER_THREAD) * + spider_param_table_crd_thread_count()), + NullS)) + ) + goto error_alloc_mon_mutxes; + + for (roop_count = 0; + roop_count < (int) spider_param_table_sts_thread_count(); + roop_count++) + { + if ((error_num = spider_create_sts_threads(&spider_table_sts_threads[roop_count]))) + { + goto error_init_table_sts_threads; + } + } + for (roop_count = 0; + roop_count < (int) spider_param_table_crd_thread_count(); + roop_count++) + { + if ((error_num = spider_create_crd_threads(&spider_table_crd_threads[roop_count]))) + { + goto error_init_table_crd_threads; + } + } + + spider_dbton_mysql.dbton_id = dbton_id; + spider_dbton_mysql.db_util->dbton_id = dbton_id; + spider_dbton[dbton_id] = spider_dbton_mysql; + ++dbton_id; + spider_dbton_mariadb.dbton_id = dbton_id; + spider_dbton_mariadb.db_util->dbton_id = dbton_id; + spider_dbton[dbton_id] = spider_dbton_mariadb; + ++dbton_id; + 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; + } + } + } + DBUG_RETURN(0); + +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_table_crd_thread_count() - 1; +error_init_table_crd_threads: + for (; roop_count >= 0; roop_count--) + { + spider_free_crd_threads(&spider_table_crd_threads[roop_count]); + } + roop_count = spider_param_table_sts_thread_count() - 1; +error_init_table_sts_threads: + for (; roop_count >= 0; roop_count--) + { + spider_free_sts_threads(&spider_table_sts_threads[roop_count]); + } + spider_free(NULL, spider_table_sts_threads, MYF(0)); + roop_count= spider_udf_table_mon_mutex_count - 1; +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_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]); +error_system_table_creation: + roop_count= spider_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: + my_hash_free(&spider_ipport_conns); +error_ipport_conn__hash_init: + 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: + spider_free_mem_calc(NULL, + spider_lgtm_tblhnd_share_hash_id, + spider_lgtm_tblhnd_share_hash.array.max_element * + spider_lgtm_tblhnd_share_hash.array.size_of_element); + my_hash_free(&spider_lgtm_tblhnd_share_hash); +error_lgtm_tblhnd_share_hash_init: + spider_free_mem_calc(NULL, + spider_open_wide_share_id, + spider_open_wide_share.array.max_element * + spider_open_wide_share.array.size_of_element); + my_hash_free(&spider_open_wide_share); +error_open_wide_share_hash_init: + 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: + pthread_mutex_destroy(&spider_open_conn_mutex); +error_open_conn_mutex_init: + pthread_mutex_destroy(&spider_conn_mutex); +error_conn_mutex_init: + pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex); +error_lgtm_tblhnd_share_mutex_init: + pthread_mutex_destroy(&spider_wide_share_mutex); +error_wide_share_mutex_init: + pthread_mutex_destroy(&spider_init_error_tbl_mutex); +error_init_error_tbl_mutex_init: + pthread_mutex_destroy(&spider_ipport_conn_mutex); +error_ipport_count_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: +/* +error_pt_attr_setstate: +*/ + pthread_attr_destroy(&spider_pt_attr); +error_pt_attr_init: + 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); +} + +/* + Get the target partition_elements. + + The target partition and subpartition are detected by the table name, + which is in the form like "t1#P#pt1". +*/ +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_REFLEN + 1]; + 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++)) + { + if (SPIDER_create_subpartition_name( + tmp_name, FN_REFLEN + 1, table_share->path.str, + (*part_elem)->partition_name, (*sub_elem)->partition_name, + NORMAL_PART_NAME)) + { + DBUG_VOID_RETURN; + } + 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 { + if (SPIDER_create_partition_name( + tmp_name, FN_REFLEN + 1, table_share->path.str, + (*part_elem)->partition_name, NORMAL_PART_NAME, TRUE)) + { + DBUG_VOID_RETURN; + } + 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; +} + +int spider_get_sts( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + double sts_interval, + int sts_mode, + int sts_sync, + int sts_sync_level, + uint flag +) { + int get_type; + int error_num = 0; + bool need_to_get = TRUE; + DBUG_ENTER("spider_get_sts"); + + if ( + sts_sync == 0 + ) { + /* get */ + get_type = 1; + } else if ( + !share->wide_share->sts_init + ) { + pthread_mutex_lock(&share->wide_share->sts_mutex); + if (!share->wide_share->sts_init) + { + /* get after mutex_lock */ + get_type = 2; + } else { + pthread_mutex_unlock(&share->wide_share->sts_mutex); + /* copy */ + get_type = 0; + } + } else if ( + difftime(share->sts_get_time, share->wide_share->sts_get_time) < + sts_interval + ) { + /* copy */ + get_type = 0; + } else if ( + !pthread_mutex_trylock(&share->wide_share->sts_mutex) + ) { + /* get after mutex_trylock */ + get_type = 3; + } else { + /* copy */ + get_type = 0; + } + if ( + !share->sts_init && + share->table_share->tmp_table == NO_TMP_TABLE && + spider_param_load_sts_at_startup(share->load_sts_at_startup) && + (!share->init || share->init_error) + ) { + error_num = spider_sys_get_table_sts( + current_thd, + share->lgtm_tblhnd_share->table_name, + share->lgtm_tblhnd_share->table_name_length, + &share->stat, + FALSE + ); + if ( + !error_num || + (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + ) + need_to_get = FALSE; + } + + if (need_to_get) + { + if (get_type == 0) + spider_copy_sts_to_share(share, share->wide_share); + else { + error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag); + } + } + if (get_type >= 2) + pthread_mutex_unlock(&share->wide_share->sts_mutex); + if (error_num) + { + SPIDER_PARTITION_HANDLER *partition_handler = + spider->partition_handler; + if ( + !share->wide_share->sts_init && + sts_sync >= sts_sync_level && + get_type > 1 && + partition_handler && + partition_handler->handlers && + partition_handler->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->wide_handler->trx->thd; + for (roop_count = 1; + roop_count < (int) partition_handler->no_parts; + roop_count++) + { + tmp_spider = + (ha_spider *) partition_handler->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->wide_share->sts_init) + { + error_num = 0; + thd->clear_error(); + get_type = 0; + spider_copy_sts_to_share(share, share->wide_share); + break; + } + } + } + if (error_num) + DBUG_RETURN(error_num); + } + if (sts_sync >= sts_sync_level && get_type > 0) + { + spider_copy_sts_to_wide_share(share->wide_share, share); + share->wide_share->sts_get_time = tmp_time; + share->wide_share->sts_init = TRUE; + } + 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, + int crd_sync, + int crd_sync_level +) { + int get_type; + int error_num = 0; + bool need_to_get = TRUE; + DBUG_ENTER("spider_get_crd"); + + if ( + crd_sync == 0 + ) { + /* get */ + get_type = 1; + } else if ( + !share->wide_share->crd_init + ) { + pthread_mutex_lock(&share->wide_share->crd_mutex); + if (!share->wide_share->crd_init) + { + /* get after mutex_lock */ + get_type = 2; + } else { + pthread_mutex_unlock(&share->wide_share->crd_mutex); + /* copy */ + get_type = 0; + } + } else if ( + difftime(share->crd_get_time, share->wide_share->crd_get_time) < + crd_interval + ) { + /* copy */ + get_type = 0; + } else if ( + !pthread_mutex_trylock(&share->wide_share->crd_mutex) + ) { + /* get after mutex_trylock */ + get_type = 3; + } else { + /* copy */ + get_type = 0; + } + if ( + !share->crd_init && + share->table_share->tmp_table == NO_TMP_TABLE && + spider_param_load_sts_at_startup(share->load_crd_at_startup) + ) { + error_num = spider_sys_get_table_crd( + current_thd, + share->lgtm_tblhnd_share->table_name, + share->lgtm_tblhnd_share->table_name_length, + share->cardinality, + table->s->fields, + FALSE + ); + if ( + !error_num || + (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) + ) + need_to_get = FALSE; + } + + if (need_to_get) + { + if (get_type == 0) + spider_copy_crd_to_share(share, share->wide_share, + table->s->fields); + else { + error_num = spider_db_show_index(spider, link_idx, table, crd_mode); + } + } + if (get_type >= 2) + pthread_mutex_unlock(&share->wide_share->crd_mutex); + if (error_num) + { + SPIDER_PARTITION_HANDLER *partition_handler = + spider->partition_handler; + if ( + !share->wide_share->crd_init && + crd_sync >= crd_sync_level && + get_type > 1 && + partition_handler && + partition_handler->handlers && + partition_handler->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->wide_handler->trx->thd; + for (roop_count = 1; + roop_count < (int) partition_handler->no_parts; + roop_count++) + { + tmp_spider = + (ha_spider *) partition_handler->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->wide_share->crd_init) + { + error_num = 0; + thd->clear_error(); + get_type = 0; + spider_copy_crd_to_share(share, share->wide_share, + table->s->fields); + break; + } + } + } + if (error_num) + DBUG_RETURN(error_num); + } + if (crd_sync >= crd_sync_level && get_type > 0) + { + spider_copy_crd_to_wide_share(share->wide_share, share, + table->s->fields); + share->wide_share->crd_get_time = tmp_time; + share->wide_share->crd_init = TRUE; + } + 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->wide_handler->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->wide_handler->info_limit < 9223372036854775807LL ? + spider->wide_handler->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->quick_page_byte = + spider_param_quick_page_byte(thd, share->quick_page_byte); + 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); + 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))) + { + 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, (uint) (sizeof(*spider_init_error_table)), + &tmp_name, (uint) (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; + spider_init_error_table->table_name_hash_value = + share->table_name_hash_value; + uint old_elements = spider_init_error_tables.array.max_element; + if (my_hash_insert(&spider_init_error_tables, + (uchar*) spider_init_error_table)) + { + 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); + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) name, length); + DBUG_ENTER("spider_delete_init_error_table"); + pthread_mutex_lock(&spider_init_error_tbl_mutex); + if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) + my_hash_search_using_hash_value(&spider_init_error_tables, hash_value, + (uchar*) name, length))) + { + my_hash_delete(&spider_init_error_tables, + (uchar*) spider_init_error_table); + 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) spider_user_defined_key_parts(key_info); roop_count++) + { + if (bitmap_is_set(table->write_set, + key_part[roop_count].field->field_index)) + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} + +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_dsns = &tmp_connect_info[15]; + tmp_share->tgt_filedsns = &tmp_connect_info[16]; + tmp_share->tgt_drivers = &tmp_connect_info[17]; + tmp_share->tgt_pk_names = &tmp_connect_info[18]; + tmp_share->tgt_sequence_names = &tmp_connect_info[19]; + tmp_share->static_link_ids = &tmp_connect_info[20]; + 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_binlog_pos_at_failing = &tmp_long[3]; + tmp_share->monitoring_flag = &tmp_long[4]; + tmp_share->monitoring_kind = &tmp_long[5]; + tmp_share->monitoring_bg_flag = &tmp_long[6]; + tmp_share->monitoring_bg_kind = &tmp_long[7]; + tmp_share->connect_timeouts = &tmp_long[13]; + tmp_share->net_read_timeouts = &tmp_long[14]; + tmp_long[13] = -1; + tmp_share->net_write_timeouts = &tmp_long[15]; + tmp_long[14] = -1; + tmp_share->access_balances = &tmp_long[16]; + tmp_share->bka_table_name_types = &tmp_long[17]; + tmp_share->strict_group_bys = &tmp_long[18]; + tmp_share->monitoring_limit = &tmp_longlong[0]; + tmp_share->monitoring_sid = &tmp_longlong[1]; + tmp_share->monitoring_bg_interval = &tmp_longlong[2]; + 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_dsns_lengths = &tmp_connect_info_length[15]; + tmp_share->tgt_filedsns_lengths = &tmp_connect_info_length[16]; + tmp_share->tgt_drivers_lengths = &tmp_connect_info_length[17]; + tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[18]; + tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[19]; + tmp_share->static_link_ids_lengths = &tmp_connect_info_length[20]; + 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_dsns_length = 1; + tmp_share->tgt_filedsns_length = 1; + tmp_share->tgt_drivers_length = 1; + tmp_share->tgt_pk_names_length = 1; + tmp_share->tgt_sequence_names_length = 1; + tmp_share->static_link_ids_length = 1; + tmp_share->tgt_ports_length = 1; + tmp_share->tgt_ssl_vscs_length = 1; + tmp_share->link_statuses_length = 1; + tmp_share->monitoring_binlog_pos_at_failing_length = 1; + tmp_share->monitoring_flag_length = 1; + tmp_share->monitoring_kind_length = 1; + tmp_share->monitoring_bg_flag_length = 1; + tmp_share->monitoring_bg_kind_length = 1; + tmp_share->monitoring_limit_length = 1; + tmp_share->monitoring_sid_length = 1; + tmp_share->monitoring_bg_interval_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; + tmp_share->bka_table_name_types_length = 1; + tmp_share->strict_group_bys_length = 1; + + tmp_share->monitoring_bg_flag[0] = -1; + tmp_share->monitoring_bg_kind[0] = -1; + tmp_share->monitoring_binlog_pos_at_failing[0] = -1; + tmp_share->monitoring_flag[0] = -1; + tmp_share->monitoring_kind[0] = -1; + tmp_share->monitoring_bg_interval[0] = -1; + tmp_share->monitoring_limit[0] = -1; + tmp_share->monitoring_sid[0] = -1; + tmp_share->bka_engine = NULL; + tmp_share->use_dbton_count = 0; + 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; +} + +TABLE_LIST *spider_get_parent_table_list( + ha_spider *spider +) { + TABLE *table = spider->get_table(); + DBUG_ENTER("spider_get_parent_table_list"); + DBUG_RETURN(table->pos_in_table_list); +} + +List *spider_get_index_hints( + ha_spider *spider + ) { + TABLE_LIST *table_list = spider_get_parent_table_list(spider); + DBUG_ENTER("spider_get_index_hint"); + if (table_list) + { + DBUG_RETURN(table_list->index_hints); + } + DBUG_RETURN(NULL); +} + + +st_select_lex *spider_get_select_lex( + ha_spider *spider +) { + TABLE_LIST *table_list = spider_get_parent_table_list(spider); + DBUG_ENTER("spider_get_select_lex"); + if (table_list) + { + DBUG_RETURN(table_list->select_lex); + } + DBUG_RETURN(NULL); +} + +void spider_get_select_limit_from_select_lex( + st_select_lex *select_lex, + longlong *select_limit, + longlong *offset_limit +) { + DBUG_ENTER("spider_get_select_limit_from_select_lex"); + *select_limit = 9223372036854775807LL; + *offset_limit = 0; + if (select_lex && select_lex->limit_params.explicit_limit) + { + *select_limit = select_lex->limit_params.select_limit ? + select_lex->limit_params.select_limit->val_int() : 0; + *offset_limit = select_lex->limit_params.offset_limit ? + select_lex->limit_params.offset_limit->val_int() : 0; + } + DBUG_VOID_RETURN; +} + +void spider_get_select_limit( + ha_spider *spider, + st_select_lex **select_lex, + longlong *select_limit, + longlong *offset_limit +) { + DBUG_ENTER("spider_get_select_limit"); + *select_lex = spider_get_select_lex(spider); + spider_get_select_limit_from_select_lex( + *select_lex, select_limit, offset_limit); + 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->wide_handler->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->wide_handler->info_limit < 9223372036854775807LL) + { + DBUG_PRINT("info",("spider info_limit=%lld", + spider->wide_handler->info_limit)); + longlong info_limit = spider->wide_handler->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 + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + DBUG_PRINT("info",("spider result_list->set_split_read=%s", result_list->set_split_read ? "TRUE" : "FALSE")); + if (!result_list->set_split_read) + { + int bulk_update_mode = spider_param_bulk_update_mode(thd, + share->bulk_update_mode); + DBUG_PRINT("info",("spider sql_command=%u", + spider->wide_handler->sql_command)); + DBUG_PRINT("info",("spider bulk_update_mode=%d", bulk_update_mode)); + DBUG_PRINT("info",("spider support_bulk_update_sql=%s", + spider->support_bulk_update_sql() ? "TRUE" : "FALSE")); + bool inserting = + ( + spider->wide_handler->sql_command == SQLCOM_INSERT || + spider->wide_handler->sql_command == SQLCOM_INSERT_SELECT + ); + bool updating = + ( + spider->wide_handler->sql_command == SQLCOM_UPDATE || + spider->wide_handler->sql_command == SQLCOM_UPDATE_MULTI + ); + bool deleting = + ( + spider->wide_handler->sql_command == SQLCOM_DELETE || + spider->wide_handler->sql_command == SQLCOM_DELETE_MULTI + ); + bool replacing = + ( + spider->wide_handler->sql_command == SQLCOM_REPLACE || + spider->wide_handler->sql_command == SQLCOM_REPLACE_SELECT + ); + DBUG_PRINT("info",("spider updating=%s", updating ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider deleting=%s", deleting ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider replacing=%s", replacing ? "TRUE" : "FALSE")); + TABLE *table = spider->get_table(); + if ( + ( + inserting && + spider->use_fields + ) || + replacing || + ( + ( + updating || + deleting + ) && + ( + bulk_update_mode != 2 || + !spider->support_bulk_update_sql() || + ( + updating && + table->triggers && +#ifdef HA_CAN_FORCE_BULK_UPDATE + !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_UPDATE) && +#endif + table->triggers->has_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER) + ) || + ( + deleting && + table->triggers && +#ifdef HA_CAN_FORCE_BULK_DELETE + !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_DELETE) && +#endif + table->triggers->has_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER) + ) + ) + ) + ) { + /* This case must select by one shot */ + DBUG_PRINT("info",("spider cancel split read")); + result_list->split_read_base = 9223372036854775807LL; + result_list->semi_split_read = 0; + result_list->semi_split_read_limit = 9223372036854775807LL; + result_list->first_read = 9223372036854775807LL; + result_list->second_read = 9223372036854775807LL; + result_list->semi_split_read_base = 0; + result_list->set_split_read = TRUE; + DBUG_RETURN(9223372036854775807LL); + } +#ifdef SPIDER_HAS_EXPLAIN_QUERY + Explain_query *explain = thd->lex->explain; + bool filesort = FALSE; + if (explain) + { + DBUG_PRINT("info",("spider explain=%p", explain)); + Explain_select *explain_select = NULL; + if (select_lex) + { + DBUG_PRINT("info",("spider select_lex=%p", select_lex)); + DBUG_PRINT("info",("spider select_number=%u", + select_lex->select_number)); + explain_select = + explain->get_select(select_lex->select_number); + } + if (explain_select) + { + DBUG_PRINT("info",("spider explain_select=%p", explain_select)); + if (explain_select->using_filesort) + { + DBUG_PRINT("info",("spider using filesort")); + filesort = TRUE; + } + } + } +#endif + result_list->split_read_base = + spider_param_split_read(thd, share->split_read); +#ifdef SPIDER_HAS_EXPLAIN_QUERY + if (filesort) + { + result_list->semi_split_read = 0; + result_list->semi_split_read_limit = 9223372036854775807LL; + } else { +#endif + 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); +#ifdef SPIDER_HAS_EXPLAIN_QUERY + } +#endif + 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; + } + DBUG_PRINT("info",("spider result_list->semi_split_read=%f", result_list->semi_split_read)); + DBUG_PRINT("info",("spider select_lex->explicit_limit=%d", select_lex ? select_lex->limit_params.explicit_limit : 0)); + DBUG_PRINT("info",("spider OPTION_FOUND_ROWS=%s", select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider select_lex->group_list.elements=%u", select_lex ? select_lex->group_list.elements : 0)); + DBUG_PRINT("info",("spider select_lex->with_sum_func=%s", select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE")); + if ( + result_list->semi_split_read > 0 && + select_lex && select_lex->limit_params.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->wide_handler->trx->thd; + SPIDER_SHARE *share = spider->share; + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + DBUG_ENTER("spider_check_direct_order_limit"); + if (spider_check_index_merge(spider->get_table(), + spider_get_select_lex(spider))) + { + DBUG_PRINT("info",("spider set use_index_merge")); + spider->use_index_merge = TRUE; + } + DBUG_PRINT("info",("spider SQLCOM_HA_READ=%s", + (spider->wide_handler->sql_command == SQLCOM_HA_READ) ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider use_index_merge=%s", + spider->use_index_merge ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider is_clone=%s", + spider->is_clone ? "TRUE" : "FALSE")); + if ( + spider->wide_handler->sql_command != SQLCOM_HA_READ && + !spider->use_index_merge && + !spider->is_clone + ) { + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + bool first_check = TRUE; + DBUG_PRINT("info",("spider select_lex=%p", select_lex)); + DBUG_PRINT("info",("spider leaf_tables.elements=%u", + select_lex ? select_lex->leaf_tables.elements : 0)); + + if (select_lex && (select_lex->options & SELECT_DISTINCT)) + { + DBUG_PRINT("info",("spider with distinct")); + spider->result_list.direct_distinct = TRUE; + } + spider->result_list.direct_aggregate = spider_param_direct_aggregate(thd); + DBUG_PRINT("info",("spider select_limit=%lld", select_limit)); + DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit)); + if ( +#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif +#ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT + !spider->condition || +#endif + !select_lex || + select_lex->leaf_tables.elements != 1 || + select_lex->table_list.elements != 1 + ) { + DBUG_PRINT("info",("spider first_check is FALSE")); + first_check = FALSE; + spider->result_list.direct_distinct = FALSE; + spider->result_list.direct_aggregate = FALSE; + } else if (spider_db_append_condition(spider, NULL, 0, TRUE)) + { + DBUG_PRINT("info",("spider FALSE by condition")); + first_check = FALSE; + spider->result_list.direct_distinct = FALSE; + spider->result_list.direct_aggregate = FALSE; + } else if ( + !select_lex->group_list.elements && + !select_lex->with_sum_func + ) { + DBUG_PRINT("info",("spider this SQL is not aggregate SQL")); + spider->result_list.direct_aggregate = FALSE; + } else { + ORDER *group; + for (group = (ORDER *) select_lex->group_list.first; group; + group = group->next) + { + if (spider->print_item_type((*group->item), NULL, NULL, 0)) + { + DBUG_PRINT("info",("spider aggregate FALSE by group")); + spider->result_list.direct_aggregate = FALSE; + break; + } + } + JOIN *join = select_lex->join; + Item_sum **item_sum_ptr; + for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr) + { + if (spider->print_item_type(*item_sum_ptr, NULL, NULL, 0)) + { + DBUG_PRINT("info",("spider aggregate FALSE by not supported")); + spider->result_list.direct_aggregate = FALSE; + break; + } + } + if (!spider_all_part_in_order((ORDER *) select_lex->group_list.first, + spider->get_table())) + { + DBUG_PRINT("info",("spider FALSE by group condition")); + first_check = FALSE; + spider->result_list.direct_distinct = FALSE; + } + } + + longlong direct_order_limit = spider_param_direct_order_limit(thd, + share->direct_order_limit); + DBUG_PRINT("info",("spider direct_order_limit=%lld", direct_order_limit)); + if (direct_order_limit) + { + DBUG_PRINT("info",("spider first_check=%s", + first_check ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider (select_lex->options & OPTION_FOUND_ROWS)=%s", + select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider direct_aggregate=%s", + spider->result_list.direct_aggregate ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider select_lex->group_list.elements=%u", + select_lex ? select_lex->group_list.elements : 0)); + DBUG_PRINT("info",("spider select_lex->with_sum_func=%s", + select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider select_lex->having=%s", + select_lex && select_lex->having ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider select_lex->order_list.elements=%u", + select_lex ? select_lex->order_list.elements : 0)); + if ( + !first_check || + !select_lex->limit_params.explicit_limit || + (select_lex->options & OPTION_FOUND_ROWS) || + ( + !spider->result_list.direct_aggregate && + ( + select_lex->group_list.elements || + select_lex->with_sum_func + ) + ) || + select_lex->having || + !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); + } + } + DBUG_PRINT("info",("spider TRUE")); + spider->result_list.internal_limit = select_limit + offset_limit; + spider->result_list.split_read = select_limit + offset_limit; + spider->wide_handler->trx->direct_order_limit_count++; + DBUG_RETURN(TRUE); + } + } + DBUG_PRINT("info",("spider FALSE by parameter")); + DBUG_RETURN(FALSE); +} + +bool spider_all_part_in_order( + ORDER *order, + TABLE *table +) { + TABLE_LIST *parent; + partition_info *part_info; + Field **part_fields; + ORDER *ptr; + Item *item; + Item_field *item_field; + DBUG_ENTER("spider_all_part_in_order"); + while (TRUE) + { + DBUG_PRINT("info", ("spider table_name = %s", table->s->db.str)); + DBUG_PRINT("info",("spider part_info=%p", table->part_info)); + if ((part_info = table->part_info)) + { + for (part_fields = part_info->full_part_field_array; + *part_fields; ++part_fields) + { + DBUG_PRINT("info", ("spider part_field = %s", + SPIDER_field_name_str(*part_fields))); + for (ptr = order; ptr; ptr = ptr->next) + { + item = *ptr->item; + if (item->type() != Item::FIELD_ITEM) + { + continue; + } + item_field = (Item_field *) item; + Field *field = item_field->field; + if (!field) + { + continue; + } + DBUG_PRINT("info", ("spider field_name = %s.%s", + field->table->s->db.str, SPIDER_field_name_str(field))); + if (*part_fields == spider_field_exchange(table->file, field)) + { + break; + } + } + if (!ptr) + { + DBUG_RETURN(FALSE); + } + } + } + if (!(parent = table->pos_in_table_list->parent_l)) + { + break; + } + table = parent->table; + } + DBUG_RETURN(TRUE); +} + +Field *spider_field_exchange( + handler *handler, + Field *field +) { + DBUG_ENTER("spider_field_exchange"); + DBUG_PRINT("info",("spider in field=%p", field)); + DBUG_PRINT("info",("spider in field->table=%p", field->table)); + DBUG_PRINT("info",("spider table=%p", handler->get_table())); + if (field->table != handler->get_table()) + DBUG_RETURN(NULL); + DBUG_PRINT("info",("spider out field=%p", field)); + DBUG_RETURN(field); +} + +int spider_set_direct_limit_offset( + ha_spider *spider +) { +#ifndef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON + THD *thd = spider->wide_handler->trx->thd; +#endif + st_select_lex *select_lex; + longlong select_limit; + longlong offset_limit; + TABLE_LIST *table_list; + DBUG_ENTER("spider_set_direct_limit_offset"); + + if (spider->result_list.direct_limit_offset) + DBUG_RETURN(TRUE); + + if ( + spider->partition_handler && + !spider->wide_handler_owner + ) { + if (spider->partition_handler->owner-> + result_list.direct_limit_offset == TRUE) + { + spider->result_list.direct_limit_offset = TRUE; + DBUG_RETURN(TRUE); + } else { + DBUG_RETURN(FALSE); + } + } + + if ( + spider->wide_handler->sql_command != SQLCOM_SELECT || + spider->result_list.direct_aggregate || + spider->result_list.direct_order_limit || + spider->prev_index_rnd_init != SPD_RND // must be RND_INIT and not be INDEX_INIT + ) + DBUG_RETURN(FALSE); + + spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); + + // limit and offset is non-zero + if (!(select_limit && offset_limit)) + DBUG_RETURN(FALSE); + + // more than one table + if ( + !select_lex || + select_lex->table_list.elements != 1 + ) + DBUG_RETURN(FALSE); + + table_list = (TABLE_LIST *) select_lex->table_list.first; + if (table_list->table->file->partition_ht() != spider_hton_ptr) + { + DBUG_PRINT("info",("spider ht1=%u ht2=%u", + table_list->table->file->partition_ht()->slot, + spider_hton_ptr->slot + )); + DBUG_RETURN(FALSE); + } + + // contain where + if ( +#ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON +#else + !(thd->variables.optimizer_switch & + OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || +#endif + // conditions is null may be no where condition in rand_init + spider->wide_handler->condition + ) + DBUG_RETURN(FALSE); + + // ignore condition like 1=1 +#ifdef SPIDER_has_Item_has_subquery + if (select_lex->where && select_lex->where->has_subquery()) +#else + if (select_lex->where && select_lex->where->with_subquery()) +#endif + DBUG_RETURN(FALSE); + + if ( + select_lex->group_list.elements || + select_lex->with_sum_func || + select_lex->having || + select_lex->order_list.elements + ) + DBUG_RETURN(FALSE); + + // must not be derived table + if (SPIDER_get_linkage(select_lex) == DERIVED_TABLE_TYPE) + DBUG_RETURN(FALSE); + + spider->direct_select_offset = offset_limit; + spider->direct_current_offset = offset_limit; + spider->direct_select_limit = select_limit; + spider->result_list.direct_limit_offset = TRUE; + DBUG_RETURN(TRUE); +} + + +bool spider_check_index_merge( + TABLE *table, + st_select_lex *select_lex +) { + uint roop_count; + JOIN *join; + DBUG_ENTER("spider_check_index_merge"); + if (!select_lex) + { + DBUG_PRINT("info",("spider select_lex is null")); + DBUG_RETURN(FALSE); + } + join = select_lex->join; + if (!join) + { + DBUG_PRINT("info",("spider join is null")); + DBUG_RETURN(FALSE); + } + if (!join->join_tab) + { + DBUG_PRINT("info",("spider join->join_tab is null")); + DBUG_RETURN(FALSE); + } + for (roop_count = 0; roop_count < spider_join_table_count(join); ++roop_count) + { + JOIN_TAB *join_tab = &join->join_tab[roop_count]; + if (join_tab->table == table) + { + DBUG_PRINT("info",("spider join_tab->type=%u", join_tab->type)); + if ( +#ifdef SPIDER_HAS_JT_HASH_INDEX_MERGE + join_tab->type == JT_HASH_INDEX_MERGE || +#endif + join_tab->type == JT_INDEX_MERGE + ) { + DBUG_RETURN(TRUE); + } +/* + DBUG_PRINT("info",("spider join_tab->quick->get_type()=%u", + join_tab->quick ? join_tab->quick->get_type() : 0)); + if ( + join_tab->quick && + join_tab->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE + ) { + DBUG_RETURN(TRUE); + } +*/ + DBUG_PRINT("info",("spider join_tab->select->quick->get_type()=%u", + join_tab->select && join_tab->select->quick ? join_tab->select->quick->get_type() : 0)); + if ( + join_tab->select && + join_tab->select->quick && + join_tab->select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE + ) { + DBUG_RETURN(TRUE); + } + break; + } + } + 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 +) { + struct my_rnd_struct rand; + DBUG_ENTER("spider_rand"); + /* generate same as rand function for applications */ + my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), + (uint32) (rand_source * 268435457L)); + DBUG_RETURN(my_rnd(&rand)); +} + +int spider_discover_table_structure_internal( + SPIDER_TRX *trx, + SPIDER_SHARE *spider_share, + spider_string *str +) { + int error_num = 0, roop_count; + DBUG_ENTER("spider_discover_table_structure_internal"); + 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))) + { + continue; + } + break; + } + } + DBUG_RETURN(error_num); +} + +int spider_discover_table_structure( + handlerton *hton, + THD* thd, + TABLE_SHARE *share, + HA_CREATE_INFO *info +) { + int error_num = HA_ERR_WRONG_COMMAND, dummy; + SPIDER_SHARE *spider_share; + const char *table_name = share->path.str; + uint table_name_length = (uint) strlen(table_name); + SPIDER_TRX *trx; + partition_info *part_info = thd->work_part_info; + SPIDER_Open_tables_backup open_tables_backup; + TABLE *table_tables; + 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(); + my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, + (uchar*) table_name, table_name_length); + 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; + if (!part_info) + { + if (!(spider_share = spider_create_share(table_name, share, + NULL, + hash_value, + &error_num + ))) { + DBUG_RETURN(error_num); + } + + error_num = spider_discover_table_structure_internal(trx, spider_share, &str); + + if (!error_num) + { + if ( + (table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, + &error_num)) + ) { + if (thd->lex->create_info.or_replace()) + { + error_num = spider_delete_tables(table_tables, + spider_share->table_name, &dummy); + } + if (!error_num) + { + error_num = spider_insert_tables(table_tables, spider_share); + } + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + } + } + + spider_free_share_resource_only(spider_share); + } else { + char tmp_name[FN_REFLEN + 1]; + List_iterator part_it(part_info->partitions); + List_iterator part_it2(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); + if ((error_num = SPIDER_create_subpartition_name( + tmp_name, FN_REFLEN + 1, table_name, + (part_elem)->partition_name, (sub_elem)->partition_name, + NORMAL_PART_NAME))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(tmp_name, share, + part_info, + hash_value, + &error_num + ))) { + DBUG_RETURN(error_num); + } + + 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); + if ((error_num = SPIDER_create_partition_name( + tmp_name, FN_REFLEN + 1, table_name, + (part_elem)->partition_name, NORMAL_PART_NAME, TRUE))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(tmp_name, share, + part_info, + hash_value, + &error_num + ))) { + DBUG_RETURN(error_num); + } + + 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) + { + if ( + !(table_tables = spider_open_sys_table( + thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, + SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, + &error_num)) + ) { + DBUG_RETURN(error_num); + } + while ((part_elem = part_it2++)) + { + if ((part_elem)->subpartitions.elements) + { + List_iterator sub_it((part_elem)->subpartitions); + while ((sub_elem = sub_it++)) + { + if ((error_num = SPIDER_create_subpartition_name( + tmp_name, FN_REFLEN + 1, table_name, + (part_elem)->partition_name, (sub_elem)->partition_name, + NORMAL_PART_NAME))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(tmp_name, share, + part_info, + hash_value, + &error_num + ))) { + DBUG_RETURN(error_num); + } + + if (thd->lex->create_info.or_replace()) + { + error_num = spider_delete_tables(table_tables, + spider_share->table_name, &dummy); + } + if (!error_num) + { + error_num = spider_insert_tables(table_tables, spider_share); + } + + spider_free_share_resource_only(spider_share); + if (error_num) + break; + } + if (error_num) + break; + } else { + if ((error_num = SPIDER_create_partition_name( + tmp_name, FN_REFLEN + 1, table_name, + (part_elem)->partition_name, NORMAL_PART_NAME, TRUE))) + { + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + DBUG_PRINT("info",("spider tmp_name=%s", tmp_name)); + if (!(spider_share = spider_create_share(tmp_name, share, + part_info, + hash_value, + &error_num + ))) { + DBUG_RETURN(error_num); + } + + if (thd->lex->create_info.or_replace()) + { + error_num = spider_delete_tables(table_tables, + spider_share->table_name, &dummy); + } + if (!error_num) + { + error_num = spider_insert_tables(table_tables, spider_share); + } + + spider_free_share_resource_only(spider_share); + if (error_num) + break; + } + } + spider_close_sys_table(thd, table_tables, + &open_tables_backup, FALSE); + } + } + + if (!error_num) + thd->clear_error(); + else + DBUG_RETURN(error_num); + + str.length(str.length() - SPIDER_SQL_COMMA_LEN); + CHARSET_INFO *table_charset; + if (share->table_charset) + { + table_charset = share->table_charset; + } else { + table_charset = system_charset_info; + } + uint csnamelen = table_charset->cs_name.length; + uint collatelen = table_charset->coll_name.length; + 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 + + (share->comment.length * 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_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN); + str.q_append(table_charset->cs_name.str, csnamelen); + str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); + str.q_append(table_charset->coll_name.str, 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); + str.append_escape_string(share->comment.str, share->comment.length); + if (str.reserve(SPIDER_SQL_CONNECTION_LEN + + (SPIDER_SQL_VALUE_QUOTE_LEN * 2) + + (share->connect_string.length * 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); + str.append_escape_string(share->connect_string.str, + share->connect_string.length); + 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); + 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); + } + if (!(part_syntax = SPIDER_generate_partition_syntax(thd, part_info, + &part_syntax_len, FALSE, TRUE, info, NULL, NULL))) + { + 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); + SPIDER_free_part_syntax(part_syntax, MYF(0)); + } + 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); +} + +int spider_create_spider_object_for_share( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + ha_spider **spider +) { + int error_num, roop_count, *need_mons; + SPIDER_CONN **conns; + uint *conn_link_idx; + uchar *conn_can_fo; + char **conn_keys; + spider_db_handler **dbton_hdl; + SPIDER_WIDE_HANDLER *wide_handler; + DBUG_ENTER("spider_create_spider_object_for_share"); + DBUG_PRINT("info",("spider trx=%p", trx)); + DBUG_PRINT("info",("spider share=%p", share)); + DBUG_PRINT("info",("spider spider_ptr=%p", spider)); + DBUG_PRINT("info",("spider spider=%p", (*spider))); + + if (*spider) + { + /* already exists */ + DBUG_RETURN(0); + } + (*spider) = new (&share->mem_root) ha_spider(); + if (!(*spider)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_spider_alloc; + } + DBUG_PRINT("info",("spider spider=%p", (*spider))); + if (!(need_mons = (int *) + spider_bulk_malloc(spider_current_trx, 255, MYF(MY_WME | MY_ZEROFILL), + &need_mons, (uint) (sizeof(int) * share->link_count), + &conns, (uint) (sizeof(SPIDER_CONN *) * share->link_count), + &conn_link_idx, (uint) (sizeof(uint) * share->link_count), + &conn_can_fo, (uint) (sizeof(uchar) * share->link_bitmap_size), + &conn_keys, (uint) (sizeof(char *) * share->link_count), + &dbton_hdl, (uint) (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE), + &wide_handler, (uint) sizeof(SPIDER_WIDE_HANDLER), + NullS)) + ) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_need_mons_alloc; + } + DBUG_PRINT("info",("spider need_mons=%p", need_mons)); + (*spider)->wide_handler = wide_handler; + wide_handler->trx = trx; + (*spider)->change_table_ptr(&share->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; + (*spider)->dbton_handler = dbton_hdl; + (*spider)->search_link_idx = -1; + 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]))) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_init_db_handler; + } + if ((error_num = dbton_hdl[roop_count]->init())) + goto error_init_db_handler; + } + } + DBUG_PRINT("info",("spider share=%p", (*spider)->share)); + DBUG_PRINT("info",("spider need_mons=%p", (*spider)->need_mons)); + DBUG_RETURN(0); + +error_init_db_handler: + for (; 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(spider_current_trx, (*spider)->need_mons, MYF(0)); +error_need_mons_alloc: + delete (*spider); + (*spider) = NULL; +error_spider_alloc: + DBUG_RETURN(error_num); +} + +void spider_free_spider_object_for_share( + ha_spider **spider +) { + int roop_count; + SPIDER_SHARE *share = (*spider)->share; + spider_db_handler **dbton_hdl = (*spider)->dbton_handler; + DBUG_ENTER("spider_free_spider_object_for_share"); + DBUG_PRINT("info",("spider share=%p", share)); + DBUG_PRINT("info",("spider spider_ptr=%p", spider)); + DBUG_PRINT("info",("spider spider=%p", (*spider))); + 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(spider_current_trx, (*spider)->need_mons, MYF(0)); + delete (*spider); + (*spider) = NULL; + DBUG_VOID_RETURN; +} + +int spider_create_sts_threads( + SPIDER_THREAD *spider_thread +) { + int error_num; + DBUG_ENTER("spider_create_sts_threads"); + if (mysql_mutex_init(spd_key_mutex_bg_stss, + &spider_thread->mutex, MY_MUTEX_INIT_FAST)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mutex_init; + } + if (mysql_cond_init(spd_key_cond_bg_stss, + &spider_thread->cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + if (mysql_cond_init(spd_key_cond_bg_sts_syncs, + &spider_thread->sync_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } + if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread, + &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread) + ) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + DBUG_RETURN(0); + +error_thread_create: + pthread_cond_destroy(&spider_thread->sync_cond); +error_sync_cond_init: + pthread_cond_destroy(&spider_thread->cond); +error_cond_init: + pthread_mutex_destroy(&spider_thread->mutex); +error_mutex_init: + DBUG_RETURN(error_num); +} + +void spider_free_sts_threads( + SPIDER_THREAD *spider_thread +) { + bool thread_killed; + DBUG_ENTER("spider_free_sts_threads"); + pthread_mutex_lock(&spider_thread->mutex); + thread_killed = spider_thread->killed; + spider_thread->killed = TRUE; + if (!thread_killed) + { + if (spider_thread->thd_wait) + { + pthread_cond_signal(&spider_thread->cond); + } + pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); + } + pthread_mutex_unlock(&spider_thread->mutex); + pthread_join(spider_thread->thread, NULL); + pthread_cond_destroy(&spider_thread->sync_cond); + pthread_cond_destroy(&spider_thread->cond); + pthread_mutex_destroy(&spider_thread->mutex); + spider_thread->thd_wait = FALSE; + spider_thread->killed = FALSE; + DBUG_VOID_RETURN; +} + +int spider_create_crd_threads( + SPIDER_THREAD *spider_thread +) { + int error_num; + DBUG_ENTER("spider_create_crd_threads"); + if (mysql_mutex_init(spd_key_mutex_bg_crds, + &spider_thread->mutex, MY_MUTEX_INIT_FAST)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_mutex_init; + } + if (mysql_cond_init(spd_key_cond_bg_crds, + &spider_thread->cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_cond_init; + } + if (mysql_cond_init(spd_key_cond_bg_crd_syncs, + &spider_thread->sync_cond, NULL)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_sync_cond_init; + } + if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread, + &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread) + ) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_thread_create; + } + DBUG_RETURN(0); + +error_thread_create: + pthread_cond_destroy(&spider_thread->sync_cond); +error_sync_cond_init: + pthread_cond_destroy(&spider_thread->cond); +error_cond_init: + pthread_mutex_destroy(&spider_thread->mutex); +error_mutex_init: + DBUG_RETURN(error_num); +} + +void spider_free_crd_threads( + SPIDER_THREAD *spider_thread +) { + bool thread_killed; + DBUG_ENTER("spider_free_crd_threads"); + pthread_mutex_lock(&spider_thread->mutex); + thread_killed = spider_thread->killed; + spider_thread->killed = TRUE; + if (!thread_killed) + { + if (spider_thread->thd_wait) + { + pthread_cond_signal(&spider_thread->cond); + } + pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); + } + pthread_mutex_unlock(&spider_thread->mutex); + pthread_join(spider_thread->thread, NULL); + pthread_cond_destroy(&spider_thread->sync_cond); + pthread_cond_destroy(&spider_thread->cond); + pthread_mutex_destroy(&spider_thread->mutex); + spider_thread->thd_wait = FALSE; + spider_thread->killed = FALSE; + DBUG_VOID_RETURN; +} + +void *spider_table_bg_sts_action( + void *arg +) { + SPIDER_THREAD *thread = (SPIDER_THREAD *) arg; + SPIDER_SHARE *share; + SPIDER_TRX *trx; + int error_num; + ha_spider *spider; + SPIDER_CONN **conns; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_table_bg_sts_action"); + /* init start */ + pthread_mutex_lock(&thread->mutex); + if (!(thd = spider_create_sys_thd(thread))) + { + thread->thd_wait = FALSE; + thread->killed = FALSE; + pthread_mutex_unlock(&thread->mutex); + my_thread_end(); + DBUG_RETURN(NULL); + } + SPIDER_set_next_thread_id(thd); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd_proc_info(thd, "Spider table background statistics action handler"); + if (!(trx = spider_get_trx(NULL, FALSE, &error_num))) + { + spider_destroy_sys_thd(thd); + thread->thd_wait = FALSE; + thread->killed = FALSE; + pthread_mutex_unlock(&thread->mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + trx->thd = thd; + /* init end */ + + if (thd->killed) + { + thread->killed = TRUE; + } + if (thd->killed) + { + thread->killed = TRUE; + } + + while (TRUE) + { + DBUG_PRINT("info",("spider bg sts loop start")); + if (thread->killed) + { + DBUG_PRINT("info",("spider bg sts kill start")); + trx->thd = NULL; + spider_free_trx(trx, TRUE); + spider_destroy_sys_thd(thd); + pthread_cond_signal(&thread->sync_cond); + pthread_mutex_unlock(&thread->mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + if (!thread->queue_first) + { + DBUG_PRINT("info",("spider bg sts has no job")); + thread->thd_wait = TRUE; + pthread_cond_wait(&thread->cond, &thread->mutex); + thread->thd_wait = FALSE; + if (thd->killed) + thread->killed = TRUE; + continue; + } + share = (SPIDER_SHARE *) thread->queue_first; + share->sts_working = TRUE; + pthread_mutex_unlock(&thread->mutex); + + spider = share->sts_spider; + conns = spider->conns; + if (spider->search_link_idx < 0) + { + spider->wide_handler->trx = trx; + 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); + } + if (spider->search_link_idx >= 0) + { + DBUG_PRINT("info", + ("spider difftime=%f", + difftime(share->bg_sts_try_time, share->sts_get_time))); + DBUG_PRINT("info", + ("spider bg_sts_interval=%f", share->bg_sts_interval)); + if (difftime(share->bg_sts_try_time, share->sts_get_time) >= + share->bg_sts_interval) + { + if (!conns[spider->search_link_idx]) + { + spider_get_conn(share, spider->search_link_idx, + share->conn_keys[spider->search_link_idx], + trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + if (conns[spider->search_link_idx]) + { + conns[spider->search_link_idx]->error_mode = 0; + } else { + spider->search_link_idx = -1; + } + } + DBUG_PRINT("info", + ("spider search_link_idx=%d", spider->search_link_idx)); + if (spider->search_link_idx >= 0 && conns[spider->search_link_idx]) + { + 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)) + { + spider->search_link_idx = -1; + } + } + } + } + memset(spider->need_mons, 0, sizeof(int) * share->link_count); + pthread_mutex_lock(&thread->mutex); + if (thread->queue_first == thread->queue_last) + { + thread->queue_first = NULL; + thread->queue_last = NULL; + } else { + thread->queue_first = share->sts_next; + share->sts_next->sts_prev = NULL; + share->sts_next = NULL; + } + share->sts_working = FALSE; + share->sts_wait = FALSE; + if (thread->first_free_wait) + { + pthread_cond_signal(&thread->sync_cond); + pthread_cond_wait(&thread->cond, &thread->mutex); + if (thd->killed) + thread->killed = TRUE; + } + } +} + +void *spider_table_bg_crd_action( + void *arg +) { + SPIDER_THREAD *thread = (SPIDER_THREAD *) arg; + SPIDER_SHARE *share; + SPIDER_TRX *trx; + int error_num; + ha_spider *spider; + TABLE *table; + SPIDER_CONN **conns; + THD *thd; + my_thread_init(); + DBUG_ENTER("spider_table_bg_crd_action"); + /* init start */ + pthread_mutex_lock(&thread->mutex); + if (!(thd = spider_create_sys_thd(thread))) + { + thread->thd_wait = FALSE; + thread->killed = FALSE; + pthread_mutex_unlock(&thread->mutex); + my_thread_end(); + DBUG_RETURN(NULL); + } + SPIDER_set_next_thread_id(thd); +#ifdef HAVE_PSI_INTERFACE + mysql_thread_set_psi_id(thd->thread_id); +#endif + thd_proc_info(thd, "Spider table background cardinality action handler"); + if (!(trx = spider_get_trx(NULL, FALSE, &error_num))) + { + spider_destroy_sys_thd(thd); + thread->thd_wait = FALSE; + thread->killed = FALSE; + pthread_mutex_unlock(&thread->mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + trx->thd = thd; + /* init end */ + + while (TRUE) + { + DBUG_PRINT("info",("spider bg crd loop start")); + if (thread->killed) + { + DBUG_PRINT("info",("spider bg crd kill start")); + trx->thd = NULL; + spider_free_trx(trx, TRUE); + spider_destroy_sys_thd(thd); + pthread_cond_signal(&thread->sync_cond); + pthread_mutex_unlock(&thread->mutex); +#if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) + set_current_thd(nullptr); +#endif + my_thread_end(); + DBUG_RETURN(NULL); + } + if (!thread->queue_first) + { + DBUG_PRINT("info",("spider bg crd has no job")); + thread->thd_wait = TRUE; + pthread_cond_wait(&thread->cond, &thread->mutex); + thread->thd_wait = FALSE; + if (thd->killed) + thread->killed = TRUE; + continue; + } + share = (SPIDER_SHARE *) thread->queue_first; + share->crd_working = TRUE; + pthread_mutex_unlock(&thread->mutex); + + table = &share->table; + spider = share->crd_spider; + conns = spider->conns; + if (spider->search_link_idx < 0) + { + spider->wide_handler->trx = trx; + 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); + } + if (spider->search_link_idx >= 0) + { + DBUG_PRINT("info", + ("spider difftime=%f", + difftime(share->bg_crd_try_time, share->crd_get_time))); + DBUG_PRINT("info", + ("spider bg_crd_interval=%f", share->bg_crd_interval)); + if (difftime(share->bg_crd_try_time, share->crd_get_time) >= + share->bg_crd_interval) + { + if (!conns[spider->search_link_idx]) + { + spider_get_conn(share, spider->search_link_idx, + share->conn_keys[spider->search_link_idx], + trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, + &error_num); + if (conns[spider->search_link_idx]) + { + conns[spider->search_link_idx]->error_mode = 0; + } else { + spider->search_link_idx = -1; + } + } + DBUG_PRINT("info", + ("spider search_link_idx=%d", spider->search_link_idx)); + if (spider->search_link_idx >= 0 && conns[spider->search_link_idx]) + { + 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)) + { + spider->search_link_idx = -1; + } + } + } + } + memset(spider->need_mons, 0, sizeof(int) * share->link_count); + pthread_mutex_lock(&thread->mutex); + if (thread->queue_first == thread->queue_last) + { + thread->queue_first = NULL; + thread->queue_last = NULL; + } else { + thread->queue_first = share->crd_next; + share->crd_next->crd_prev = NULL; + share->crd_next = NULL; + } + share->crd_working = FALSE; + share->crd_wait = FALSE; + if (thread->first_free_wait) + { + pthread_cond_signal(&thread->sync_cond); + pthread_cond_wait(&thread->cond, &thread->mutex); + if (thd->killed) + thread->killed = TRUE; + } + } +} + +void spider_table_add_share_to_sts_thread( + SPIDER_SHARE *share +) { + SPIDER_THREAD *spider_thread = share->sts_thread; + DBUG_ENTER("spider_table_add_share_to_sts_thread"); + if ( + !share->sts_wait && + !pthread_mutex_trylock(&spider_thread->mutex) + ) { + if (!share->sts_wait) + { + if (spider_thread->queue_last) + { + DBUG_PRINT("info",("spider add to last")); + share->sts_prev = spider_thread->queue_last; + spider_thread->queue_last->sts_next = share; + } else { + spider_thread->queue_first = share; + } + spider_thread->queue_last = share; + share->sts_wait = TRUE; + + if (spider_thread->thd_wait) + { + pthread_cond_signal(&spider_thread->cond); + } + } + pthread_mutex_unlock(&spider_thread->mutex); + } + DBUG_VOID_RETURN; +} + +void spider_table_add_share_to_crd_thread( + SPIDER_SHARE *share +) { + SPIDER_THREAD *spider_thread = share->crd_thread; + DBUG_ENTER("spider_table_add_share_to_crd_thread"); + if ( + !share->crd_wait && + !pthread_mutex_trylock(&spider_thread->mutex) + ) { + if (!share->crd_wait) + { + if (spider_thread->queue_last) + { + DBUG_PRINT("info",("spider add to last")); + share->crd_prev = spider_thread->queue_last; + spider_thread->queue_last->crd_next = share; + } else { + spider_thread->queue_first = share; + } + spider_thread->queue_last = share; + share->crd_wait = TRUE; + + if (spider_thread->thd_wait) + { + pthread_cond_signal(&spider_thread->cond); + } + } + pthread_mutex_unlock(&spider_thread->mutex); + } + DBUG_VOID_RETURN; +} + +void spider_table_remove_share_from_sts_thread( + SPIDER_SHARE *share +) { + SPIDER_THREAD *spider_thread = share->sts_thread; + DBUG_ENTER("spider_table_remove_share_from_sts_thread"); + if (share->sts_wait) + { + pthread_mutex_lock(&spider_thread->mutex); + if (share->sts_wait) + { + if (share->sts_working) + { + DBUG_PRINT("info",("spider waiting bg sts start")); + spider_thread->first_free_wait = TRUE; + pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); + spider_thread->first_free_wait = FALSE; + pthread_cond_signal(&spider_thread->cond); + DBUG_PRINT("info",("spider waiting bg sts end")); + } + + if (share->sts_prev) + { + if (share->sts_next) + { + DBUG_PRINT("info",("spider remove middle one")); + share->sts_prev->sts_next = share->sts_next; + share->sts_next->sts_prev = share->sts_prev; + } else { + DBUG_PRINT("info",("spider remove last one")); + share->sts_prev->sts_next = NULL; + spider_thread->queue_last = share->sts_prev; + } + } else if (share->sts_next) { + DBUG_PRINT("info",("spider remove first one")); + share->sts_next->sts_prev = NULL; + spider_thread->queue_first = share->sts_next; + } else { + DBUG_PRINT("info",("spider empty")); + spider_thread->queue_first = NULL; + spider_thread->queue_last = NULL; + } + } + pthread_mutex_unlock(&spider_thread->mutex); + } + DBUG_VOID_RETURN; +} + +void spider_table_remove_share_from_crd_thread( + SPIDER_SHARE *share +) { + SPIDER_THREAD *spider_thread = share->crd_thread; + DBUG_ENTER("spider_table_remove_share_from_crd_thread"); + if (share->crd_wait) + { + pthread_mutex_lock(&spider_thread->mutex); + if (share->crd_wait) + { + if (share->crd_working) + { + DBUG_PRINT("info",("spider waiting bg crd start")); + spider_thread->first_free_wait = TRUE; + pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); + spider_thread->first_free_wait = FALSE; + pthread_cond_signal(&spider_thread->cond); + DBUG_PRINT("info",("spider waiting bg crd end")); + } + + if (share->crd_prev) + { + if (share->crd_next) + { + DBUG_PRINT("info",("spider remove middle one")); + share->crd_prev->crd_next = share->crd_next; + share->crd_next->crd_prev = share->crd_prev; + } else { + DBUG_PRINT("info",("spider remove last one")); + share->crd_prev->crd_next = NULL; + spider_thread->queue_last = share->crd_prev; + } + } else if (share->crd_next) { + DBUG_PRINT("info",("spider remove first one")); + share->crd_next->crd_prev = NULL; + spider_thread->queue_first = share->crd_next; + } else { + DBUG_PRINT("info",("spider empty")); + spider_thread->queue_first = NULL; + spider_thread->queue_last = NULL; + } + } + pthread_mutex_unlock(&spider_thread->mutex); + } + DBUG_VOID_RETURN; +} + +uchar *spider_duplicate_char( + uchar *dst, + uchar esc, + uchar *src, + uint src_lgt +) { + uchar *ed = src + src_lgt; + DBUG_ENTER("spider_duplicate_char"); + while (src < ed) + { + *dst = *src; + if (*src == esc) + { + ++dst; + *dst = esc; + } + ++dst; + ++src; + } + DBUG_RETURN(dst); +} diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h new file mode 100644 index 00000000..2bc123ab --- /dev/null +++ b/storage/spider/spd_table.h @@ -0,0 +1,519 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019-2022 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +/* + Structure used to manage Spider parameter string parsing. Types of + parameters include: + - connection strings + - UDF parameters + + A parameter string consists of one or more parameter definitions using + the following syntax: + + A comma is the separator character between multiple parameter definitions. + Parameter titles must not be quoted. Parameter values must be quoted with + single or double quotes. +*/ + +typedef struct st_spider_param_string_parse +{ + char *start_title; /* Pointer to the start of the current parameter + title */ + char *end_title; /* Pointer to the end of the current + parameter value */ + char *start_value; /* Pointer to the start of the current parameter + value */ + char *end_value; /* Pointer to the end of the current parameter + value */ + char delim_value; /* Current parameter value's delimiter + character, either a single or a double quote */ + int error_num; /* Error code of the error message to print when + an error is detected */ + + int fail(bool restore_delim); + bool locate_param_def(char*& start_param); +} SPIDER_PARAM_STRING_PARSE; + +uchar *spider_tbl_get_key( + SPIDER_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +uchar *spider_wide_share_get_key( + SPIDER_WIDE_SHARE *share, + size_t *length, + my_bool not_used __attribute__ ((unused)) +); + +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 +); + +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, + partition_info *part_info, + uint create_table +); + +int spider_set_connect_info_default( + SPIDER_SHARE *share, + partition_element *part_elem, + partition_element *sub_elem, + 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 +); + +#ifdef DBUG_TRACE +void spider_print_keys( + const char *key, + uint length +); +#endif + +int spider_create_conn_keys( + SPIDER_SHARE *share +); + +SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( + const char *table_name, + uint table_name_length, + my_hash_value_type hash_value, + bool locked, + bool need_to_create, + int *error_num +); + +void spider_free_lgtm_tblhnd_share_alloc( + SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share, + bool locked +); + +SPIDER_SHARE *spider_create_share( + const char *table_name, + TABLE_SHARE *table_share, + partition_info *part_info, + my_hash_value_type hash_value, + 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 +); + +void spider_update_link_status_for_share( + const char *table_name, + uint table_name_length, + int link_idx, + long link_status +); + +SPIDER_WIDE_SHARE *spider_get_wide_share( + SPIDER_SHARE *share, + TABLE_SHARE *table_share, + int *error_num +); + +int spider_free_wide_share( + SPIDER_WIDE_SHARE *wide_share +); + +void spider_copy_sts_to_wide_share( + SPIDER_WIDE_SHARE *wide_share, + SPIDER_SHARE *share +); + +void spider_copy_sts_to_share( + SPIDER_SHARE *share, + SPIDER_WIDE_SHARE *wide_share +); + +void spider_copy_crd_to_wide_share( + SPIDER_WIDE_SHARE *wide_share, + SPIDER_SHARE *share, + int fields +); + +void spider_copy_crd_to_share( + SPIDER_SHARE *share, + SPIDER_WIDE_SHARE *wide_share, + int fields +); + +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 +); + +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 +); + +int spider_get_sts( + SPIDER_SHARE *share, + int link_idx, + time_t tmp_time, + ha_spider *spider, + double sts_interval, + int sts_mode, + int sts_sync, + 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, + int crd_sync, + 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 +); + +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 +); + +TABLE_LIST *spider_get_parent_table_list( + ha_spider *spider +); +List *spider_get_index_hints( + ha_spider *spider + ); + +st_select_lex *spider_get_select_lex( + ha_spider *spider +); + +void spider_get_select_limit_from_select_lex( + st_select_lex *select_lex, + longlong *select_limit, + longlong *offset_limit +); + +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 +); + +bool spider_all_part_in_order( + ORDER *order, + TABLE *table +); + +Field *spider_field_exchange( + handler *handler, + Field *field +); + +int spider_set_direct_limit_offset( + ha_spider *spider +); + +bool spider_check_index_merge( + TABLE *table, + st_select_lex *select_lex +); + +int spider_compare_for_sort( + SPIDER_SORT *a, + SPIDER_SORT *b +); + +ulong spider_calc_for_sort( + uint count, + ... +); + +double spider_rand( + uint32 rand_source +); + +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 +); + +int spider_create_spider_object_for_share( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + ha_spider **spider +); + +void spider_free_spider_object_for_share( + ha_spider **spider +); + +int spider_create_sts_threads( + SPIDER_THREAD *spider_thread +); + +void spider_free_sts_threads( + SPIDER_THREAD *spider_thread +); + +int spider_create_crd_threads( + SPIDER_THREAD *spider_thread +); + +void spider_free_crd_threads( + SPIDER_THREAD *spider_thread +); + +void *spider_table_bg_sts_action( + void *arg +); + +void *spider_table_bg_crd_action( + void *arg +); + +void spider_table_add_share_to_sts_thread( + SPIDER_SHARE *share +); + +void spider_table_add_share_to_crd_thread( + SPIDER_SHARE *share +); + +void spider_table_remove_share_from_sts_thread( + SPIDER_SHARE *share +); + +void spider_table_remove_share_from_crd_thread( + SPIDER_SHARE *share +); +uchar *spider_duplicate_char( + uchar *dst, + uchar esc, + uchar *src, + uint src_lgt +); diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc new file mode 100644 index 00000000..c689e40d --- /dev/null +++ b/storage/spider/spd_trx.cc @@ -0,0 +1,3863 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "mysql_version.h" +#include "spd_environ.h" +#include "sql_priv.h" +#include "probes_mysql.h" +#include "sql_class.h" +#include "sql_partition.h" +#include "records.h" +#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 struct charset_info_st *spd_charset_utf8mb3_bin; + +extern handlerton *spider_hton_ptr; +extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; +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); +} + +/* + Try to free the connections held by the given transaction. +*/ +int spider_free_trx_conn(SPIDER_TRX *trx, bool trx_free) +{ + int loop_count= 0; + SPIDER_CONN *conn; + HASH *conn_hash= &trx->trx_conn_hash; + + DBUG_ENTER("spider_free_trx_conn"); + + /* Clear the connection queues in any case. */ + while ((conn= (SPIDER_CONN *) my_hash_element(conn_hash, loop_count))) + { + spider_conn_clear_queue_at_commit(conn); + loop_count++; + } + + if (trx_free || spider_param_conn_recycle_mode(trx->thd) != 2) + { + loop_count= 0; + while ((conn= (SPIDER_CONN *) my_hash_element(&trx->trx_conn_hash, + loop_count))) + { + if (conn->table_lock) + { + DBUG_ASSERT(!trx_free); + loop_count++; + } + else + { + spider_free_conn_from_trx(trx, conn, FALSE, trx_free, &loop_count); + } + } + trx->trx_conn_adjustment++; + + DBUG_RETURN(0); + } + + loop_count= 0; + while ((conn= (SPIDER_CONN *) my_hash_element(conn_hash, loop_count))) + { + if (!conn->table_lock) + { + conn->error_mode= 1; + } + loop_count++; + } + + DBUG_RETURN(0); +} + +int spider_free_trx_another_conn( + SPIDER_TRX *trx, + bool lock +) { + int error_num, tmp_error_num; + int roop_count = 0; + SPIDER_CONN *conn; + DBUG_ENTER("spider_free_trx_another_conn"); + trx->tmp_spider->conns = &conn; + error_num = 0; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_another_conn_hash, + roop_count))) + { + if (lock && (tmp_error_num = spider_db_unlock_tables(trx->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; + SPIDER_WIDE_HANDLER tmp_wide_handler; + 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((void*)&tmp_spider, 0, sizeof(ha_spider)); + memset((void*)&tmp_share, 0, sizeof(SPIDER_SHARE)); + memset((void*)&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER)); + tmp_spider.share = &tmp_share; + tmp_spider.wide_handler = &tmp_wide_handler; + tmp_wide_handler.trx = trx; + tmp_share.access_charset = system_charset_info; + 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) + { + DBUG_RETURN(error_num); + } + } + roop_count++; + } + 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((void*)&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((void*)&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; + THD *thd = trx->thd; + SPIDER_CONN *conn; + DBUG_ENTER("spider_trx_all_unlock_tables"); + SPIDER_BACKUP_DASTATUS; + trx->tmp_spider->conns = &conn; + while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, + roop_count))) + { + if ((error_num = spider_db_unlock_tables(trx->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; + SPIDER_WIDE_HANDLER tmp_wide_handler; + DBUG_ENTER("spider_trx_all_start_trx"); + SPIDER_BACKUP_DASTATUS; + memset((void*)&tmp_spider, 0, sizeof(ha_spider)); + memset(&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER)); + tmp_spider.wide_handler = &tmp_wide_handler; + tmp_wide_handler.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_for_connection(&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; + SPIDER_WIDE_HANDLER tmp_wide_handler; + 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((void*)&tmp_spider, 0, sizeof(ha_spider)); + memset(&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER)); + 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.wide_handler = &tmp_wide_handler; + tmp_wide_handler.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"); + my_hash_delete(&trx->trx_alter_table_hash, (uchar*) alter_table); + 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); +} + +/** Copy a string from one array to another */ +static inline void spider_maybe_memcpy_indexed_string( + char **dests, + char **srcs, + const uint* lengths, + const int idx, + char *&ptr) +{ + if (size_t len= sizeof(char) * lengths[idx]) + { + dests[idx]= ptr; + memcpy(ptr, srcs[idx], len); + ptr+= len + 1; + } +} + +int spider_create_trx_alter_table( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + bool now_create +) { + int error_num, link_idx; + 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; + char **tmp_tgt_dsns; + char **tmp_tgt_filedsns; + char **tmp_tgt_drivers; + char **tmp_static_link_ids; + 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_tgt_dsns_lengths; + uint *tmp_tgt_filedsns_lengths; + uint *tmp_tgt_drivers_lengths; + uint *tmp_static_link_ids_lengths; + long *tmp_tgt_ports; + long *tmp_tgt_ssl_vscs; + long *tmp_monitoring_binlog_pos_at_failing; + 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; + char *tmp_tgt_dsns_char; + char *tmp_tgt_filedsns_char; + char *tmp_tgt_drivers_char; + char *tmp_static_link_ids_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, (uint) (sizeof(*alter_table)), + &tmp_name, (uint) (sizeof(char) * (share->table_name_length + 1)), + + &tmp_server_names, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_table_names, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_dbs, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_hosts, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_usernames, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_passwords, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_sockets, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_wrappers, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_ssl_cas, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_ssl_capaths, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_ssl_certs, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_ssl_ciphers, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_ssl_keys, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_default_files, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_default_groups, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_dsns, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_filedsns, (uint) (sizeof(char *) * share->all_link_count), + &tmp_tgt_drivers, (uint) (sizeof(char *) * share->all_link_count), + &tmp_static_link_ids, (uint) (sizeof(char *) * share->all_link_count), + + &tmp_server_names_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_table_names_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_dbs_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_hosts_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_usernames_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_passwords_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_sockets_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_wrappers_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_ssl_cas_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_ssl_capaths_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_ssl_certs_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_ssl_ciphers_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_ssl_keys_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_default_files_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_default_groups_lengths, + (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_dsns_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_filedsns_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_tgt_drivers_lengths, (uint) (sizeof(uint) * share->all_link_count), + &tmp_static_link_ids_lengths, + (uint) (sizeof(uint) * share->all_link_count), + + &tmp_tgt_ports, (uint) (sizeof(long) * share->all_link_count), + &tmp_tgt_ssl_vscs, (uint) (sizeof(long) * share->all_link_count), + &tmp_monitoring_binlog_pos_at_failing, + (uint) (sizeof(long) * share->all_link_count), + &tmp_link_statuses, (uint) (sizeof(long) * share->all_link_count), + + &tmp_server_names_char, (uint) (sizeof(char) * + (share_alter->tmp_server_names_charlen + 1)), + &tmp_tgt_table_names_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_table_names_charlen + 1)), + &tmp_tgt_dbs_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_dbs_charlen + 1)), + &tmp_tgt_hosts_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_hosts_charlen + 1)), + &tmp_tgt_usernames_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_usernames_charlen + 1)), + &tmp_tgt_passwords_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_passwords_charlen + 1)), + &tmp_tgt_sockets_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_sockets_charlen + 1)), + &tmp_tgt_wrappers_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_wrappers_charlen + 1)), + &tmp_tgt_ssl_cas_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_ssl_cas_charlen + 1)), + &tmp_tgt_ssl_capaths_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_ssl_capaths_charlen + 1)), + &tmp_tgt_ssl_certs_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_ssl_certs_charlen + 1)), + &tmp_tgt_ssl_ciphers_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_ssl_ciphers_charlen + 1)), + &tmp_tgt_ssl_keys_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_ssl_keys_charlen + 1)), + &tmp_tgt_default_files_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_default_files_charlen + 1)), + &tmp_tgt_default_groups_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_default_groups_charlen + 1)), + &tmp_tgt_dsns_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_dsns_charlen + 1)), + &tmp_tgt_filedsns_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_filedsns_charlen + 1)), + &tmp_tgt_drivers_char, (uint) (sizeof(char) * + (share_alter->tmp_tgt_drivers_charlen + 1)), + &tmp_static_link_ids_char, (uint) (sizeof(char) * + (share_alter->tmp_static_link_ids_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; + 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; + 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_dsns = tmp_tgt_dsns; + alter_table->tmp_tgt_filedsns = tmp_tgt_filedsns; + alter_table->tmp_tgt_drivers = tmp_tgt_drivers; + alter_table->tmp_static_link_ids = tmp_static_link_ids; + + alter_table->tmp_tgt_ports = tmp_tgt_ports; + alter_table->tmp_tgt_ssl_vscs = tmp_tgt_ssl_vscs; + alter_table->tmp_monitoring_binlog_pos_at_failing = + tmp_monitoring_binlog_pos_at_failing; + 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; + alter_table->tmp_tgt_dsns_lengths = tmp_tgt_dsns_lengths; + alter_table->tmp_tgt_filedsns_lengths = tmp_tgt_filedsns_lengths; + alter_table->tmp_tgt_drivers_lengths = tmp_tgt_drivers_lengths; + alter_table->tmp_static_link_ids_lengths = tmp_static_link_ids_lengths; + + for(link_idx = 0; link_idx < (int) share->all_link_count; link_idx++) + { + spider_maybe_memcpy_indexed_string( + tmp_server_names, share_alter->tmp_server_names, + share_alter->tmp_server_names_lengths, link_idx, tmp_server_names_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_table_names, share_alter->tmp_tgt_table_names, + share_alter->tmp_tgt_table_names_lengths, link_idx, tmp_tgt_table_names_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_dbs, share_alter->tmp_tgt_dbs, + share_alter->tmp_tgt_dbs_lengths, link_idx, tmp_tgt_dbs_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_hosts, share_alter->tmp_tgt_hosts, + share_alter->tmp_tgt_hosts_lengths, link_idx, tmp_tgt_hosts_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_usernames, share_alter->tmp_tgt_usernames, + share_alter->tmp_tgt_usernames_lengths, link_idx, tmp_tgt_usernames_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_passwords, share_alter->tmp_tgt_passwords, + share_alter->tmp_tgt_passwords_lengths, link_idx, tmp_tgt_passwords_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_sockets, share_alter->tmp_tgt_sockets, + share_alter->tmp_tgt_sockets_lengths, link_idx, tmp_tgt_sockets_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_wrappers, share_alter->tmp_tgt_wrappers, + share_alter->tmp_tgt_wrappers_lengths, link_idx, tmp_tgt_wrappers_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_ssl_cas, share_alter->tmp_tgt_ssl_cas, + share_alter->tmp_tgt_ssl_cas_lengths, link_idx, tmp_tgt_ssl_cas_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_ssl_capaths, share_alter->tmp_tgt_ssl_capaths, + share_alter->tmp_tgt_ssl_capaths_lengths, link_idx, tmp_tgt_ssl_capaths_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_ssl_certs, share_alter->tmp_tgt_ssl_certs, + share_alter->tmp_tgt_ssl_certs_lengths, link_idx, tmp_tgt_ssl_certs_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_ssl_ciphers, share_alter->tmp_tgt_ssl_ciphers, + share_alter->tmp_tgt_ssl_ciphers_lengths, link_idx, tmp_tgt_ssl_ciphers_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_ssl_keys, share_alter->tmp_tgt_ssl_keys, + share_alter->tmp_tgt_ssl_keys_lengths, link_idx, tmp_tgt_ssl_keys_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_default_files, share_alter->tmp_tgt_default_files, + share_alter->tmp_tgt_default_files_lengths, link_idx, tmp_tgt_default_files_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_default_groups, share_alter->tmp_tgt_default_groups, + share_alter->tmp_tgt_default_groups_lengths, link_idx, tmp_tgt_default_groups_char); + spider_maybe_memcpy_indexed_string( + tmp_tgt_dsns, share_alter->tmp_tgt_dsns, + share_alter->tmp_tgt_dsns_lengths, link_idx, tmp_tgt_dsns_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_filedsns, share_alter->tmp_tgt_filedsns, + share_alter->tmp_tgt_filedsns_lengths, link_idx, tmp_tgt_filedsns_char); + + spider_maybe_memcpy_indexed_string( + tmp_tgt_drivers, share_alter->tmp_tgt_drivers, + share_alter->tmp_tgt_drivers_lengths, link_idx, tmp_tgt_drivers_char); + + spider_maybe_memcpy_indexed_string( + tmp_static_link_ids, share_alter->tmp_static_link_ids, + share_alter->tmp_static_link_ids_lengths, link_idx, tmp_static_link_ids_char); + } + + 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_monitoring_binlog_pos_at_failing, + share_alter->tmp_monitoring_binlog_pos_at_failing, + 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); + memcpy(tmp_tgt_dsns_lengths, share_alter->tmp_tgt_dsns_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_filedsns_lengths, share_alter->tmp_tgt_filedsns_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_tgt_drivers_lengths, share_alter->tmp_tgt_drivers_lengths, + sizeof(uint) * share->all_link_count); + memcpy(tmp_static_link_ids_lengths, + share_alter->tmp_static_link_ids_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_dsns_length = + share_alter->tmp_tgt_dsns_length; + alter_table->tmp_tgt_filedsns_length = + share_alter->tmp_tgt_filedsns_length; + alter_table->tmp_tgt_drivers_length = + share_alter->tmp_tgt_drivers_length; + alter_table->tmp_static_link_ids_length = + share_alter->tmp_static_link_ids_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_monitoring_binlog_pos_at_failing_length = + share_alter->tmp_monitoring_binlog_pos_at_failing_length; + alter_table->tmp_link_statuses_length = + share_alter->tmp_link_statuses_length; + + old_elements = trx->trx_alter_table_hash.array.max_element; + if (my_hash_insert(&trx->trx_alter_table_hash, (uchar*) alter_table)) + { + 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_dsns[roop_count] != + cmp2->tmp_tgt_dsns[roop_count] && + ( + !cmp1->tmp_tgt_dsns[roop_count] || + !cmp2->tmp_tgt_dsns[roop_count] || + strcmp(cmp1->tmp_tgt_dsns[roop_count], + cmp2->tmp_tgt_dsns[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_filedsns[roop_count] != + cmp2->tmp_tgt_filedsns[roop_count] && + ( + !cmp1->tmp_tgt_filedsns[roop_count] || + !cmp2->tmp_tgt_filedsns[roop_count] || + strcmp(cmp1->tmp_tgt_filedsns[roop_count], + cmp2->tmp_tgt_filedsns[roop_count]) + ) + ) || + ( + cmp1->tmp_tgt_drivers[roop_count] != + cmp2->tmp_tgt_drivers[roop_count] && + ( + !cmp1->tmp_tgt_drivers[roop_count] || + !cmp2->tmp_tgt_drivers[roop_count] || + strcmp(cmp1->tmp_tgt_drivers[roop_count], + cmp2->tmp_tgt_drivers[roop_count]) + ) + ) || + ( + cmp1->tmp_static_link_ids[roop_count] != + cmp2->tmp_static_link_ids[roop_count] && + ( + !cmp1->tmp_static_link_ids[roop_count] || + !cmp2->tmp_static_link_ids[roop_count] || + strcmp(cmp1->tmp_static_link_ids[roop_count], + cmp2->tmp_static_link_ids[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_monitoring_binlog_pos_at_failing[roop_count] != + cmp2->tmp_monitoring_binlog_pos_at_failing[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"); + if (trx->tmp_spider) + { + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; ++roop_count) + { + if (trx->tmp_spider->dbton_handler[roop_count]) + { + delete trx->tmp_spider->dbton_handler[roop_count]; + trx->tmp_spider->dbton_handler[roop_count] = NULL; + } + } + if (trx->tmp_spider->result_list.sqls) + { + delete [] trx->tmp_spider->result_list.sqls; + trx->tmp_spider->result_list.sqls = NULL; + } + delete trx->tmp_spider; + trx->tmp_spider = NULL; + } + if (trx->tmp_share) + { + for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; ++roop_count) + { + if (trx->tmp_share->dbton_share[roop_count]) + { + delete trx->tmp_share->dbton_share[roop_count]; + trx->tmp_share->dbton_share[roop_count] = NULL; + } + } + spider_free_tmp_share_alloc(trx->tmp_share); + } + spider_db_udf_free_set_names(trx); + for (roop_count = spider_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); + 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); + free_root(&trx->mem_root, MYF(0)); + DBUG_RETURN(0); +} + +SPIDER_TRX *spider_get_trx( + THD *thd, + bool regist_allocated_thds, + int *error_num +) { + int roop_count = 0, roop_count2; + SPIDER_TRX *trx; + SPIDER_SHARE *tmp_share; + SPIDER_WIDE_HANDLER *tmp_wide_handler; + pthread_mutex_t *udf_table_mutexes; + DBUG_ENTER("spider_get_trx"); + + if ( + !thd || + !(trx = (SPIDER_TRX*) thd_get_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, (uint) (sizeof(*trx)), + &tmp_share, (uint) (sizeof(SPIDER_SHARE)), + &tmp_wide_handler, (uint) sizeof(SPIDER_WIDE_HANDLER), + &udf_table_mutexes, (uint) (sizeof(pthread_mutex_t) * + spider_udf_table_lock_mutex_count), + NullS)) + ) + goto error_alloc_trx; + + SPD_INIT_ALLOC_ROOT(&trx->mem_root, 4096, 0, MYF(MY_WME)); + trx->tmp_share = tmp_share; + trx->udf_table_mutexes = udf_table_mutexes; + + for (roop_count = 0; + roop_count < (int) spider_udf_table_lock_mutex_count; + roop_count++) + { + if (mysql_mutex_init(spd_key_mutex_udf_table, + &trx->udf_table_mutexes[roop_count], MY_MUTEX_INIT_FAST)) + goto error_init_udf_table_mutex; + } + + if ( + my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_conn_hash, + spd_charset_utf8mb3_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_get_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(PSI_INSTRUMENT_ME, &trx->trx_another_conn_hash, + spd_charset_utf8mb3_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_get_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 ( + my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_alter_table_hash, + spd_charset_utf8mb3_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_get_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(PSI_INSTRUMENT_ME, &trx->trx_ha_hash, + spd_charset_utf8mb3_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_get_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; + 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 (thd) + { + spider_set_tmp_share_pointer(trx->tmp_share, trx->tmp_connect_info, + trx->tmp_connect_info_length, trx->tmp_long, trx->tmp_longlong); + if ( + spider_set_connect_info_default( + trx->tmp_share, + NULL, + NULL, + NULL + ) || + spider_set_connect_info_default_db_table( + trx->tmp_share, + "", 0, + "", 0 + ) || + spider_create_conn_keys(trx->tmp_share) + ) { + goto error_set_connect_info_default; + } + + if (!(trx->tmp_spider = new (&trx->mem_root) ha_spider())) + { + goto error_alloc_spider; + } + trx->tmp_spider->need_mons = &trx->tmp_need_mon; + trx->tmp_spider->share = trx->tmp_share; + trx->tmp_spider->wide_handler = tmp_wide_handler; + tmp_wide_handler->trx = trx; + trx->tmp_spider->dbton_handler = trx->tmp_dbton_handler; + if (!(trx->tmp_spider->result_list.sqls = + new spider_string[trx->tmp_share->link_count])) + { + goto error_init_result_list_sql; + } + for (roop_count2 = 0; roop_count2 < (int) trx->tmp_share->link_count; + ++roop_count2) + { + trx->tmp_spider->result_list.sqls[roop_count2].init_calc_mem(121); + trx->tmp_spider->result_list.sqls[roop_count2].set_charset( + trx->tmp_share->access_charset); + } + + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; ++roop_count2) + { + if (!spider_dbton[roop_count2].init) + continue; + + if (!(trx->tmp_share->dbton_share[roop_count2] = + spider_dbton[roop_count2].create_db_share(trx->tmp_share))) + { + goto error_create_db_share; + } + if (trx->tmp_share->dbton_share[roop_count2]->init()) + { + delete trx->tmp_share->dbton_share[roop_count2]; + trx->tmp_share->dbton_share[roop_count2] = NULL; + goto error_create_db_share; + } + + if (!(trx->tmp_spider->dbton_handler[roop_count2] = + spider_dbton[roop_count2].create_db_handler(trx->tmp_spider, + trx->tmp_share->dbton_share[roop_count2]))) + { + goto error_create_db_share; + } + if (trx->tmp_spider->dbton_handler[roop_count2]->init()) + { + delete trx->tmp_spider->dbton_handler[roop_count2]; + trx->tmp_spider->dbton_handler[roop_count2] = NULL; + goto error_create_db_share; + } + } + + if (regist_allocated_thds) + { + pthread_mutex_lock(&spider_allocated_thds_mutex); + uint old_elements = spider_allocated_thds.array.max_element; + if (my_hash_insert(&spider_allocated_thds, (uchar*) thd)) + { + 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_set_ha_data(thd, spider_hton_ptr, trx); + } + } + + DBUG_PRINT("info",("spider trx=%p", trx)); + DBUG_RETURN(trx); + +error_allocated_thds_insert: +error_alloc_spider: +error_create_db_share: + if (thd) + { + delete [] trx->tmp_spider->result_list.sqls; + trx->tmp_spider->result_list.sqls = NULL; + } +error_init_result_list_sql: + if (thd) + { + delete trx->tmp_spider; + trx->tmp_spider = NULL; + for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; ++roop_count2) + { + if (trx->tmp_spider->dbton_handler[roop_count2]) + { + delete trx->tmp_spider->dbton_handler[roop_count2]; + trx->tmp_spider->dbton_handler[roop_count2] = NULL; + } + if (trx->tmp_share->dbton_share[roop_count2]) + { + delete trx->tmp_share->dbton_share[roop_count2]; + trx->tmp_share->dbton_share[roop_count2] = NULL; + } + } + } +error_set_connect_info_default: + if (thd) + { + spider_free_tmp_share_alloc(trx->tmp_share); + } + 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_get_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: + spider_free_mem_calc( + thd ? ((SPIDER_TRX *) thd_get_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_get_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: + free_root(&trx->mem_root, MYF(0)); + 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, + bool reset_ha_data +) { + DBUG_ENTER("spider_free_trx"); + if (trx->thd) + { + if (trx->registed_allocated_thds) + { + if (need_lock) + pthread_mutex_lock(&spider_allocated_thds_mutex); + my_hash_delete(&spider_allocated_thds, (uchar*) trx->thd); + if (need_lock) + pthread_mutex_unlock(&spider_allocated_thds_mutex); + } + if (reset_ha_data) + thd_set_ha_data(trx->thd, spider_hton_ptr, 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 +) { + THD *thd = conn->thd; + int trx_isolation; + DBUG_ENTER("spider_check_and_set_trx_isolation"); + if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL) + { + if ((trx_isolation = spider_param_slave_trx_isolation()) == -1) + { + trx_isolation = thd_tx_isolation(thd); + DBUG_PRINT("info",("spider local trx_isolation=%d", trx_isolation)); + } else { + DBUG_PRINT("info",("spider slave trx_isolation=%d", trx_isolation)); + } + } else { + trx_isolation = thd_tx_isolation(thd); + DBUG_PRINT("info",("spider local trx_isolation=%d", trx_isolation)); + } + spider_conn_queue_trx_isolation(conn, trx_isolation); + DBUG_RETURN(0); +} + +int spider_check_and_set_autocommit( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + DBUG_ENTER("spider_check_and_set_autocommit"); + spider_conn_queue_autocommit( + conn, !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)); + DBUG_RETURN(0); +} + +int spider_check_and_set_sql_log_off( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + int 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 != -1) + { + if (internal_sql_log_off) + { + spider_conn_queue_sql_log_off(conn, TRUE); + } else { + spider_conn_queue_sql_log_off(conn, FALSE); + } + } + DBUG_RETURN(0); +} + +int spider_check_and_set_wait_timeout( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + int wait_timeout; + DBUG_ENTER("spider_check_and_set_wait_timeout"); + + wait_timeout = spider_param_wait_timeout(thd); + if (wait_timeout > 0) + { + spider_conn_queue_wait_timeout(conn, wait_timeout); + } + DBUG_RETURN(0); +} + +int spider_check_and_set_sql_mode( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +) { + DBUG_ENTER("spider_check_and_set_sql_mode"); + spider_conn_queue_sql_mode(conn, thd->variables.sql_mode); + 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); +} + +static int spider_xa_lock( + XID_STATE *xid_state, + XID *xid +) { + THD *thd = current_thd; + int error_num; + const char *old_proc_info; + DBUG_ENTER("spider_xa_lock"); + old_proc_info = thd_proc_info(thd, "Locking xid by Spider"); + if (xid_cache_insert(thd, xid_state, xid)) + { + error_num = (spider_stmt_da_sql_errno(thd) == ER_XAER_DUPID ? + ER_SPIDER_XA_LOCKED_NUM : HA_ERR_OUT_OF_MEM); + goto error; + } + thd_proc_info(thd, old_proc_info); + DBUG_RETURN(0); + +error: + thd_proc_info(thd, old_proc_info); + DBUG_RETURN(error_num); +} + +static int spider_xa_unlock( + XID_STATE *xid_state +) { + THD *thd = current_thd; + const char *old_proc_info; + DBUG_ENTER("spider_xa_unlock"); + old_proc_info = thd_proc_info(thd, "Unlocking xid by Spider"); + xid_cache_delete(thd, xid_state); + thd_proc_info(thd, old_proc_info); + 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 +) { + int error_num; + SPIDER_TRX *trx = spider->wide_handler->trx; + THD *thd = trx->thd; + bool xa_lock = FALSE; + DBUG_ENTER("spider_internal_start_trx"); + + if (!trx->trx_start) + { + if (!trx->trx_consistent_snapshot) + { + trx->use_consistent_snapshot = + spider_param_use_consistent_snapshot(thd); + trx->internal_xa = spider_param_internal_xa(thd); + trx->internal_xa_snapshot = spider_param_internal_xa_snapshot(thd); + } + } + spider->wide_handler->consistent_snapshot = FALSE; + 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) + { + spider->wide_handler->consistent_snapshot = TRUE; + } + } + DBUG_PRINT("info",("spider trx->trx_start= %s", + trx->trx_start ? "TRUE" : "FALSE")); + if (!trx->trx_start) + { + if ( + thd->transaction->xid_state.is_explicit_XA() && + spider_param_support_xa() + ) { + trx->trx_xa = TRUE; + thd_get_xid(thd, (MYSQL_XID*) &trx->xid); + } + + if ( + !trx->trx_xa && + trx->internal_xa && + (!trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3) && + spider->wide_handler->sql_command != SQLCOM_LOCK_TABLES + ) { + trx->trx_xa = TRUE; + trx->xid.formatID = 1; + if (spider_param_internal_xa_id_type(thd) == 0) + { + trx->xid.gtrid_length + = my_sprintf(trx->xid.data, + (trx->xid.data, "%lx", thd_get_thread_id(thd))); + } else { + trx->xid.gtrid_length + = my_sprintf(trx->xid.data, + (trx->xid.data, "%lx%016llx", thd_get_thread_id(thd), + thd->query_id)); + } + trx->xid.bqual_length + = my_sprintf(trx->xid.data + trx->xid.gtrid_length, + (trx->xid.data + trx->xid.gtrid_length, "%lx", + thd->variables.server_id)); + +#ifdef SPIDER_XID_STATE_HAS_in_thd + trx->internal_xid_state.in_thd = 1; +#endif + if ((error_num = spider_xa_lock(&trx->internal_xid_state, &trx->xid))) + { + if (error_num == ER_SPIDER_XA_LOCKED_NUM) + my_message(error_num, ER_SPIDER_XA_LOCKED_STR, MYF(0)); + goto error; + } + xa_lock = TRUE; + } else + trx->internal_xa = FALSE; + + DBUG_PRINT("info",("spider trx->trx_consistent_snapshot= %s", + trx->trx_consistent_snapshot ? "TRUE" : "FALSE")); + if (!trx->trx_consistent_snapshot) + { + trans_register_ha(thd, FALSE, spider_hton_ptr, 0); + if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) + trans_register_ha(thd, TRUE, spider_hton_ptr, 0); + } + trx->trx_start = TRUE; + trx->trx_xa_prepared = FALSE; + trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); + } + DBUG_RETURN(0); + +error: + if (xa_lock) + spider_xa_unlock(&trx->internal_xid_state); + DBUG_RETURN(error_num); +} + +int spider_internal_start_trx_for_connection( + ha_spider *spider, + SPIDER_CONN *conn, + int link_idx +) { + int error_num; + SPIDER_TRX *trx = spider->wide_handler->trx; + THD *thd = trx->thd; + bool sync_autocommit = spider_param_sync_autocommit(thd); + double ping_interval_at_trx_start = + spider_param_ping_interval_at_trx_start(thd); + time_t tmp_time = (time_t) time((time_t*) 0); + DBUG_ENTER("spider_internal_start_trx_for_connection"); + 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 ( + (error_num = spider_check_and_set_sql_log_off(thd, conn, + &spider->need_mons[link_idx])) || + (error_num = spider_check_and_set_wait_timeout(thd, conn, + &spider->need_mons[link_idx])) || + (spider_param_sync_sql_mode(thd) && + (error_num = spider_check_and_set_sql_mode(thd, conn, + &spider->need_mons[link_idx]))) || + (sync_autocommit && + (error_num = spider_check_and_set_autocommit(thd, conn, + &spider->need_mons[link_idx]))) + ) + goto error; + + if (spider->wide_handler->consistent_snapshot) + { + if ((error_num = spider_start_internal_consistent_snapshot(trx, conn, + &spider->need_mons[link_idx]))) + goto error; + } + + 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(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(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(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(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(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: + 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 = 0, tmp_error_num; + char xa_key[MAX_KEY_LENGTH]; + SPIDER_CONN *conn; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; + SPIDER_Open_tables_backup open_tables_backup; + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_commit"); + + if (trx->updated_in_this_trx || spider_param_xa_register_mode(thd) == 0) + { + /* + 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->bg_search) + spider_bg_conn_break(conn, NULL); + DBUG_PRINT("info",("spider conn=%p", conn)); + DBUG_PRINT("info",("spider conn->join_trx=%u", conn->join_trx)); + 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; + } + spider_sys_log_xa_failed(thd, &trx->xid, conn, + SPIDER_SYS_XA_COMMIT_STR, TRUE); + } + 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; + + if (trx->updated_in_this_trx || spider_param_xa_register_mode(thd) == 0) + { + /* + 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; + } + if (trx->internal_xa) + { + spider_xa_unlock(&trx->internal_xid_state); + } + 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: + if (trx->internal_xa) + { + spider_xa_unlock(&trx->internal_xid_state); + } + 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; + SPIDER_Open_tables_backup open_tables_backup; + bool server_lost = FALSE; + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_rollback"); + + if ( + trx->trx_xa_prepared && + ( + trx->updated_in_this_trx || + spider_param_xa_register_mode(thd) == 0 + ) + ) { + /* + 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->bg_search) + spider_bg_conn_break(conn, NULL); + if (conn->join_trx) + { + if (conn->disable_xa) + { + if (conn->table_lock != 3 && !trx->trx_xa_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 ( + !trx->trx_xa_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 ( + trx->trx_xa_prepared && + !server_lost && + ( + trx->updated_in_this_trx || + spider_param_xa_register_mode(thd) == 0 + ) + ) { + /* + 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; + } + if (trx->internal_xa) + { + spider_xa_unlock(&trx->internal_xid_state); + } + 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: + if (trx->internal_xa) + { + spider_xa_unlock(&trx->internal_xid_state); + } + 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); + SPIDER_Open_tables_backup open_tables_backup; + bool table_xa_opened = FALSE; + bool table_xa_member_opened = FALSE; + DBUG_ENTER("spider_internal_xa_prepare"); + if (trx->updated_in_this_trx || spider_param_xa_register_mode(thd) == 0) + { + /* + 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->bg_search) + spider_bg_conn_break(conn, NULL); + 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 { + if (trx->updated_in_this_trx || spider_param_xa_register_mode(thd) == 0) + { + /* + 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; +*/ + } + if (trx->updated_in_this_trx || spider_param_xa_register_mode(thd) == 0) + { + 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; + } + 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; + SPIDER_Open_tables_backup open_tables_backup; + 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; + THD *thd; + TABLE *table_xa; + READ_RECORD *read_record; + SPIDER_Open_tables_backup open_tables_backup; + int cnt = 0; + MEM_ROOT mem_root; + DBUG_ENTER("spider_initinal_xa_recover"); + if (!(read_record = new READ_RECORD)) + { + error_num = HA_ERR_OUT_OF_MEM; + goto error_create_read_record; + } + + 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 = 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; + SPIDER_init_read_record(read_record, thd, table_xa, NULL, NULL, TRUE, + FALSE, FALSE); + SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); + while ((!(read_record->SPIDER_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)); + + 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; + DBUG_RETURN(cnt); + +error_open_table: + spider_free_tmp_thd(thd); + thd = NULL; +error_create_thd: + delete read_record; + read_record = NULL; +error_create_read_record: + DBUG_RETURN(0); +} + +int spider_internal_xa_commit_by_xid( + THD* thd, + SPIDER_TRX *trx, + XID* xid +) { + TABLE *table_xa, *table_xa_member = 0; + int error_num; + char xa_key[MAX_KEY_LENGTH]; + char xa_member_key[MAX_KEY_LENGTH]; + SPIDER_SHARE tmp_share; + 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; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; + SPIDER_Open_tables_backup open_tables_backup; + 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((void*)&tmp_share, 0, sizeof(SPIDER_SHARE)); + memset(&tmp_connect_info, 0, + sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT); + spider_set_tmp_share_pointer(&tmp_share, tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + 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 = 0; + int error_num; + char xa_key[MAX_KEY_LENGTH]; + char xa_member_key[MAX_KEY_LENGTH]; + SPIDER_SHARE tmp_share; + 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; + uint force_commit = spider_param_force_commit(thd); + MEM_ROOT mem_root; + SPIDER_Open_tables_backup open_tables_backup; + 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((void*)&tmp_share, 0, sizeof(SPIDER_SHARE)); + memset(&tmp_connect_info, 0, + sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT); + spider_set_tmp_share_pointer(&tmp_share, tmp_connect_info, + tmp_connect_info_length, tmp_long, tmp_longlong); + 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, 0); + trans_register_ha(trx->thd, TRUE, spider_hton_ptr, 0); + 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_get_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + + + /* + We do (almost) nothing if the following two conditions are both met: + + * This is just the end of a statement, not an explicit commit. + * The autocommit is OFF or we are in an explicit transaction. + */ + if (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) + { + if (trx->trx_start) + { + if (trx->trx_xa) + { + if (trx->internal_xa && !trx->trx_xa_prepared) + { + if ( + (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); + } + trx->trx_xa_prepared = TRUE; + } + int tmp_error_num; + if ( + (tmp_error_num = spider_internal_xa_commit( + thd, trx, &trx->xid, table_xa, table_xa_member)) + ) { + if (tmp_error_num) + error_num = tmp_error_num; + } + trx->trx_xa = FALSE; + trx->join_trx_top = NULL; + } 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; + trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->trx_start=FALSE")); + DBUG_PRINT("info",("spider trx->updated_in_this_trx=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_get_ha_data(thd, spider_hton_ptr))) + DBUG_RETURN(0); /* transaction is not started */ + + + if (all || (!thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) + { + if (trx->trx_start) + { + if (trx->trx_xa) + { + int tmp_error_num; + if ( + (tmp_error_num = spider_internal_xa_rollback(thd, trx)) + ) { + if (tmp_error_num) + error_num = tmp_error_num; + } + trx->trx_xa = FALSE; + trx->join_trx_top = NULL; + } 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; + trx->updated_in_this_trx = FALSE; + DBUG_PRINT("info",("spider trx->trx_start=FALSE")); + DBUG_PRINT("info",("spider trx->updated_in_this_trx=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_get_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; + trx->trx_xa_prepared = TRUE; + } + } + + 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); +} + +void spider_copy_table_free_trx_conn( + SPIDER_TRX *trx +) { + SPIDER_CONN *conn; + DBUG_ENTER("spider_copy_table_free_trx_conn"); + if ((conn = spider_tree_first(trx->join_trx_top))) + { + do { + spider_end_trx(trx, conn); + conn->join_trx = 0; + } while ((conn = spider_tree_next(conn))); + trx->join_trx_top = NULL; + } + spider_reuse_trx_ha(trx); + spider_free_trx_conn(trx, FALSE); + trx->trx_consistent_snapshot = FALSE; + spider_merge_mem_calc(trx, FALSE); + DBUG_VOID_RETURN; +} + +int spider_end_trx( + SPIDER_TRX *trx, + SPIDER_CONN *conn +) { + int error_num = 0, need_mon = 0; + DBUG_ENTER("spider_end_trx"); + if (conn->table_lock == 3) + { + trx->tmp_spider->conns = &conn; + conn->table_lock = 0; + conn->disable_reconnect = FALSE; + if ( + !conn->server_lost && + (error_num = spider_db_unlock_tables(trx->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->wide_handler->trx = trx; + spider->set_error_mode(); + if (spider->wide_handler->sql_command != SQLCOM_DROP_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 (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 ( + !trx_ha || + trx_ha->wait_for_reusing || + trx->spider_thread_id != spider->spider_thread_id || + trx->trx_conn_adjustment != spider->trx_conn_adjustment || + 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->wide_handler->trx ? + "spider change thd" : "spider next trx")); + spider->wide_handler->trx = trx; + spider->trx_conn_adjustment = trx->trx_conn_adjustment; + 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; + char *db = (char *) my_alloca( + table_share->db.length + 1 + table_share->table_name.length + 1); + if (!db) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + char *table_name = db + table_share->db.length + 1; + 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); + my_afree(db); + DBUG_RETURN(ER_SPIDER_ALL_LINKS_FAILED_NUM); + } else if (search_link_idx == -2) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + 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++) + { + spider->conns[roop_count]= NULL; + } + bool search_link_idx_is_checked = FALSE; + 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 (roop_count == spider->search_link_idx) + search_link_idx_is_checked = TRUE; + if ( + tgt_conn_kind == SPIDER_CONN_KIND_MYSQL && + !spider->conns[roop_count] + ) { + *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, + roop_count, + (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], + share->monitoring_flag[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 (!search_link_idx_is_checked) + { + TABLE *table = spider->get_table(); + TABLE_SHARE *table_share = table->s; + char *db = (char *) my_alloca( + table_share->db.length + 1 + table_share->table_name.length + 1); + if (!db) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + char *table_name = db + table_share->db.length + 1; + 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_LINK_MON_JUST_NG_NUM, + ER_SPIDER_LINK_MON_JUST_NG_STR, MYF(0), db, table_name); + my_afree(db); + DBUG_RETURN(ER_SPIDER_LINK_MON_JUST_NG_NUM); + } + } else { + DBUG_PRINT("info",("spider link_status = %ld", + share->link_statuses[spider->conn_link_idx[spider->search_link_idx]])); + bool search_link_idx_is_checked = FALSE; + 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 (roop_count == spider->search_link_idx) + search_link_idx_is_checked = TRUE; + + conn= spider->conns[roop_count]; + + 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, + roop_count, + (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], + share->monitoring_flag[roop_count], + TRUE + ); + } + DBUG_PRINT("info",("spider get conn error")); + DBUG_RETURN(error_num); + } + } + conn->error_mode &= spider->error_mode; + } + if (!search_link_idx_is_checked) + { + TABLE *table = spider->get_table(); + TABLE_SHARE *table_share = table->s; + char *db = (char *) my_alloca( + table_share->db.length + 1 + table_share->table_name.length + 1); + if (!db) + { + my_error(HA_ERR_OUT_OF_MEM, MYF(0)); + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + } + char *table_name = db + table_share->db.length + 1; + 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_LINK_MON_JUST_NG_NUM, + ER_SPIDER_LINK_MON_JUST_NG_STR, MYF(0), db, table_name); + my_afree(db); + DBUG_RETURN(ER_SPIDER_LINK_MON_JUST_NG_NUM); + } + } + 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 = SPIDER_new_THD((my_thread_id) 0))) + DBUG_RETURN(NULL); + thd->killed = NOT_KILLED; + thd->proc_info = ""; + thd->thread_stack = (char*) &thd; + thd->store_globals(); + lex_start(thd); + DBUG_RETURN(thd); +} + +void spider_free_tmp_thd( + THD *thd +) { + DBUG_ENTER("spider_free_tmp_thd"); + thd->cleanup(); + thd->reset_globals(); + 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; + my_hash_delete(&trx->trx_ha_hash, (uchar*) trx_ha); + 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, (uint) (sizeof(SPIDER_TRX_HA)), + &tmp_name, (uint) (sizeof(char *) * (share->table_name_length + 1)), + &conn_link_idx, (uint) (sizeof(uint) * share->link_count), + &conn_can_fo, (uint) (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; + if (my_hash_insert(&trx->trx_ha_hash, (uchar*) trx_ha)) + { + 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"); + 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))) + { + 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])); + } + 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_check_link_idx_failed"); + 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); +} + diff --git a/storage/spider/spd_trx.h b/storage/spider/spd_trx.h new file mode 100644 index 00000000..2055a497 --- /dev/null +++ b/storage/spider/spd_trx.h @@ -0,0 +1,268 @@ +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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, + bool reset_ha_data= true +); + +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_wait_timeout( + THD *thd, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_check_and_set_sql_mode( + 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_start_internal_consistent_snapshot( + SPIDER_TRX *trx, + SPIDER_CONN *conn, + int *need_mon +); + +int spider_internal_start_trx( + ha_spider *spider +); + +int spider_internal_start_trx_for_connection( + 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 +); + +void spider_copy_table_free_trx_conn( + SPIDER_TRX *trx +); + +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 +); + diff --git a/storage/spider/spd_udf.cc b/storage/spider/spd_udf.cc new file mode 100644 index 00000000..13a9b41f --- /dev/null +++ b/storage/spider/spd_udf.cc @@ -0,0 +1,153 @@ +/* Copyright (C) 2009-2014 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#define MYSQL_SERVER 1 +#include +#include "spd_environ.h" +#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); +} + +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); +} + +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 00000000..d0d7d53e --- /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 00000000..bb9f1ce2 --- /dev/null +++ b/storage/spider/spd_udf.h @@ -0,0 +1,77 @@ +/* Copyright (C) 2009-2014 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 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 +); + +void spider_direct_sql_bg_start( + UDF_INIT *initid +); + +long long spider_direct_sql_bg_end( + UDF_INIT *initid +); + +long long spider_ping_table_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +); + +my_bool spider_ping_table_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +); + +void spider_ping_table_deinit_body( + UDF_INIT *initid +); + +long long spider_flush_table_mon_cache_body(); + +long long spider_copy_tables_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *is_null, + char *error +); + +my_bool spider_copy_tables_init_body( + UDF_INIT *initid, + UDF_ARGS *args, + char *message +); + +void spider_copy_tables_deinit_body( + UDF_INIT *initid +); diff --git a/storage/spider/spider.cnf b/storage/spider/spider.cnf new file mode 100644 index 00000000..ebc9968b --- /dev/null +++ b/storage/spider/spider.cnf @@ -0,0 +1,7 @@ +[mariadb] +# +# Uncomment line to enable +# +#plugin-load-add = ha_spider + +# Read more at https://mariadb.com/kb/en/spider/ -- cgit v1.2.3