Commit a4666509 authored by Kentoku SHIBA's avatar Kentoku SHIBA Committed by Nayuta Yanagisawa

MDEV-19866 With a Spider table, a SELECT with WHERE involving primary key...

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
parent 4a7dfda3
--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
--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 %';
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
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
!include ../my_2_2.cnf
--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
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment