summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKentoku SHIBA <kentokushiba@gmail.com>2019-07-06 23:54:53 +0900
committerNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2021-10-18 13:19:03 +0900
commita46665090b96f5598b534d31524af830dfc225b0 (patch)
treeaa6d214f44467fdaf96fe7e20fdbdb2994627f1d
parent4a7dfda373ff9e28e4f4f35bad76cbfc20934a9a (diff)
downloadmariadb-git-a46665090b96f5598b534d31524af830dfc225b0.tar.gz
MDEV-19866 With a Spider table, a SELECT with WHERE involving primary key breaks following SELECTs (#1356)
Change checking scanning partitions from part_spec to part_info->read_partitions
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/mdev_19866_deinit.inc14
-rw-r--r--storage/spider/mysql-test/spider/bugfix/include/mdev_19866_init.inc52
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result111
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test97
-rw-r--r--storage/spider/spd_group_by_handler.cc62
6 files changed, 310 insertions, 30 deletions
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 00000000000..9d255152dd8
--- /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 00000000000..dceae8226b0
--- /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 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 argument LIKE '%select %';
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 00000000000..5d483481edd
--- /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 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 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 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 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/t/mdev_19866.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.cnf
new file mode 100644
index 00000000000..e0ffb99c38e
--- /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 00000000000..05b753ae8bb
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_19866.test
@@ -0,0 +1,97 @@
+--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
+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;
+
+--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/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc
index 8bd0eca507f..de041897239 100644
--- a/storage/spider/spd_group_by_handler.cc
+++ b/storage/spider/spd_group_by_handler.cc
@@ -1654,21 +1654,18 @@ group_by_handler *spider_create_group_by_handler(
if (from->table->part_info)
{
DBUG_PRINT("info",("spider partition handler"));
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
- ha_partition *partition = (ha_partition *) from->table->file;
- part_id_range *part_spec = partition->get_part_spec();
- DBUG_PRINT("info",("spider part_spec->start_part=%u", part_spec->start_part));
- DBUG_PRINT("info",("spider part_spec->end_part=%u", part_spec->end_part));
- if (
- part_spec->start_part == partition->get_no_current_part_id() ||
- part_spec->start_part != part_spec->end_part
- ) {
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
+ 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"));
#else
DBUG_PRINT("info",("spider partition is not supported by this feature yet"));
#endif
DBUG_RETURN(NULL);
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
}
@@ -1686,17 +1683,18 @@ group_by_handler *spider_create_group_by_handler(
/* all tables are const_table */
DBUG_RETURN(NULL);
}
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
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;
- part_id_range *part_spec = partition->get_part_spec();
handler **handlers = partition->get_child_handlers();
- spider = (ha_spider *) handlers[part_spec->start_part];
+ spider = (ha_spider *) handlers[part];
} else {
#endif
spider = (ha_spider *) from->table->file;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
share = spider->share;
@@ -1717,17 +1715,18 @@ group_by_handler *spider_create_group_by_handler(
{
if (from->table->const_table)
continue;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
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;
- part_id_range *part_spec = partition->get_part_spec();
handler **handlers = partition->get_child_handlers();
- spider = (ha_spider *) handlers[part_spec->start_part];
+ spider = (ha_spider *) handlers[part];
} else {
#endif
spider = (ha_spider *) from->table->file;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
share = spider->share;
@@ -1755,17 +1754,18 @@ group_by_handler *spider_create_group_by_handler(
do {
if (from->table->const_table)
continue;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
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;
- part_id_range *part_spec = partition->get_part_spec();
handler **handlers = partition->get_child_handlers();
- spider = (ha_spider *) handlers[part_spec->start_part];
+ spider = (ha_spider *) handlers[part];
} else {
#endif
spider = (ha_spider *) from->table->file;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
share = spider->share;
@@ -1908,17 +1908,18 @@ group_by_handler *spider_create_group_by_handler(
{
from = from->next_local;
}
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
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;
- part_id_range *part_spec = partition->get_part_spec();
handler **handlers = partition->get_child_handlers();
- spider = (ha_spider *) handlers[part_spec->start_part];
+ spider = (ha_spider *) handlers[part];
} else {
#endif
spider = (ha_spider *) from->table->file;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
share = spider->share;
@@ -1996,17 +1997,18 @@ group_by_handler *spider_create_group_by_handler(
continue;
fields->clear_conn_holder_from_conn();
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
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;
- part_id_range *part_spec = partition->get_part_spec();
handler **handlers = partition->get_child_handlers();
- spider = (ha_spider *) handlers[part_spec->start_part];
+ spider = (ha_spider *) handlers[part];
} else {
#endif
spider = (ha_spider *) from->table->file;
-#if defined(PARTITION_HAS_GET_CHILD_HANDLERS) && defined(PARTITION_HAS_GET_PART_SPEC)
+#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
}
#endif
share = spider->share;