Skip to content

Commit

Permalink
MDEV-6268 SPIDER table with no COMMENT clause causes queries to wait …
Browse files Browse the repository at this point in the history
…forever

Add looping check

Conflicts:
	sql/table.h
  • Loading branch information
Kentoku committed Jun 5, 2020
1 parent 272625d commit 23c8add
Show file tree
Hide file tree
Showing 31 changed files with 1,146 additions and 35 deletions.
4 changes: 3 additions & 1 deletion sql/sql_base.cc
Expand Up @@ -1977,11 +1977,13 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
MYF(MY_WME))))
goto err_lock;

table_list->intention_table= table;
error= open_table_from_share(thd, share, &table_list->alias,
HA_OPEN_KEYFILE | HA_TRY_READ_ONLY,
EXTRA_RECORD,
thd->open_options, table, FALSE,
IF_PARTITIONING(table_list->partition_names,0));
IF_PARTITIONING(table_list->partition_names,0),
table_list);

if (unlikely(error))
{
Expand Down
4 changes: 3 additions & 1 deletion sql/table.cc
Expand Up @@ -3868,7 +3868,8 @@ bool copy_keys_from_share(TABLE *outparam, MEM_ROOT *root)
enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
const LEX_CSTRING *alias, uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam,
bool is_create_table, List<String> *partitions_to_open)
bool is_create_table, List<String> *partitions_to_open,
TABLE_LIST *table_list)
{
enum open_frm_error error;
uint records, i, bitmap_size, bitmap_count;
Expand All @@ -3890,6 +3891,7 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
outparam->s= share;
outparam->db_stat= db_stat;
outparam->write_row_record= NULL;
outparam->intention_pos_in_table_list= table_list;

if (share->incompatible_version &&
!(ha_open_flags & (HA_OPEN_FOR_ALTER | HA_OPEN_FOR_REPAIR)))
Expand Down
9 changes: 8 additions & 1 deletion sql/table.h
Expand Up @@ -1289,6 +1289,9 @@ struct TABLE
/* Table's triggers, 0 if there are no of them */
Table_triggers_list *triggers;
TABLE_LIST *pos_in_table_list;/* Element referring to this table */
/* This is same as pos_in_table_list, but it is set as soon as possible when
TABLE is allocated */
TABLE_LIST *intention_pos_in_table_list;
/* Position in thd->locked_table_list under LOCK TABLES */
TABLE_LIST *pos_in_locked_tables;
/* Tables used in DEFAULT and CHECK CONSTRAINT (normally sequence tables) */
Expand Down Expand Up @@ -2262,6 +2265,9 @@ struct TABLE_LIST
/* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
List<Index_hint> *index_hints;
TABLE *table; /* opened table */
/* This is same as table, but it is set as soon as possible when
TABLE is allocated */
TABLE *intention_table;
ulonglong table_id; /* table id (from binlog) for opened table */
/*
select_result for derived table to pass it from table creation to table
Expand Down Expand Up @@ -3107,7 +3113,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
const LEX_CSTRING *alias, uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam,
bool is_create_table,
List<String> *partitions_to_open= NULL);
List<String> *partitions_to_open= NULL,
TABLE_LIST *table_list= NULL);
bool copy_keys_from_share(TABLE *outparam, MEM_ROOT *root);
bool fix_session_vcol_expr(THD *thd, Virtual_column_info *vcol);
bool fix_session_vcol_expr_for_read(THD *thd, Field *field,
Expand Down
10 changes: 10 additions & 0 deletions storage/spider/ha_spider.cc
Expand Up @@ -423,6 +423,16 @@ int ha_spider::open(
wide_handler->rnd_read_bitmap = rnd_read_bitmap;
wide_handler->rnd_write_bitmap = rnd_write_bitmap;
wide_handler->owner = owner;
if (table_share->tmp_table == NO_TMP_TABLE)
{
TABLE_LIST *top = spider_get_parent_table_list(this);
if (top->intention_table)
{
wide_handler->top_share = top->intention_table->s;
} else {
wide_handler->top_share = top->table->s;
}
}
owner->wide_handler_owner = TRUE;
memset(wide_handler->ft_discard_bitmap, 0xFF,
no_bytes_in_map(table->read_set));
Expand Down
@@ -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
@@ -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;
36 changes: 36 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/r/self_reference.result
@@ -0,0 +1,36 @@
for master_1
for child2
for child3
connection master_1;
set @old_spider_same_server_link= @@spider_same_server_link;
set spider_same_server_link= ON;

this test is for MDEV-6268

drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;

create table
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

select test 1
connection master_1;
SELECT pkey FROM tbl_a;
ERROR HY000: An infinite loop is detected when opening table auto_test_local.tbl_a

deinit
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection master_1;
set spider_same_server_link= @old_spider_same_server_link;
for master_1
for child2
for child3

end of test
Expand Up @@ -48,7 +48,7 @@ SET SESSION sql_log_bin= 0;
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %';
argument
set session time_zone = '+00:00'
set session time_zone = '+00:00';set @`spider_lc_./auto_test_remote/tbl_a` = '-xxxxxxxxxxxx-xxxxx-./auto_test_local/tbl_a-'
SET NAMES utf8
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 argument LIKE '%set %'
Expand Down
Expand Up @@ -50,7 +50,7 @@ pkey
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%sql_mode%';
argument
set session transaction isolation level repeatable read;set session autocommit = 1;set session sql_log_off = 0;set session wait_timeout = 604800;set session sql_mode = 'real_as_float,ignore_bad_table_options,no_unsigned_subtraction,no_dir_in_create,no_auto_value_on_zero,strict_trans_tables,strict_all_tables,no_zero_in_date,no_zero_date,allow_invalid_dates,error_for_division_by_zero,no_auto_create_user,high_not_precedence,no_engine_substitution,pad_char_to_full_length,empty_string_is_null,simultaneous_assignment,time_round_fractional';set session time_zone = '+00:00';start transaction
set session transaction isolation level repeatable read;set session autocommit = 1;set session sql_log_off = 0;set session wait_timeout = 604800;set session sql_mode = 'real_as_float,ignore_bad_table_options,no_unsigned_subtraction,no_dir_in_create,no_auto_value_on_zero,strict_trans_tables,strict_all_tables,no_zero_in_date,no_zero_date,allow_invalid_dates,error_for_division_by_zero,no_auto_create_user,high_not_precedence,no_engine_substitution,pad_char_to_full_length,empty_string_is_null,simultaneous_assignment,time_round_fractional';set session time_zone = '+00:00';set @`spider_lc_./auto_test_remote/tbl_a` = '-xxxxxxxxxxxx-xxxxx-./auto_test_local/tbl_a-';start transaction
SELECT argument FROM mysql.general_log WHERE argument LIKE '%sql_mode%'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
Expand Down
Expand Up @@ -50,7 +50,7 @@ pkey
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%sql_mode%';
argument
set session transaction isolation level repeatable read;set session autocommit = 1;set session sql_log_off = 0;set session wait_timeout = 604800;set session sql_mode = 'real_as_float,ignore_bad_table_options,no_unsigned_subtraction,no_dir_in_create,no_auto_value_on_zero,strict_trans_tables,strict_all_tables,no_zero_in_date,no_zero_date,allow_invalid_dates,error_for_division_by_zero,no_auto_create_user,high_not_precedence,no_engine_substitution,pad_char_to_full_length';set session time_zone = '+00:00';start transaction
set session transaction isolation level repeatable read;set session autocommit = 1;set session sql_log_off = 0;set session wait_timeout = 604800;set session sql_mode = 'real_as_float,ignore_bad_table_options,no_unsigned_subtraction,no_dir_in_create,no_auto_value_on_zero,strict_trans_tables,strict_all_tables,no_zero_in_date,no_zero_date,allow_invalid_dates,error_for_division_by_zero,no_auto_create_user,high_not_precedence,no_engine_substitution,pad_char_to_full_length';set session time_zone = '+00:00';set @`spider_lc_./auto_test_remote/tbl_a` = '-xxxxxxxxxxxx-xxxxx-./auto_test_local/tbl_a-';start transaction
SELECT argument FROM mysql.general_log WHERE argument LIKE '%sql_mode%'
SELECT pkey FROM tbl_a ORDER BY pkey;
pkey
Expand Down
2 changes: 2 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/self_reference.cnf
@@ -0,0 +1,2 @@
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
45 changes: 45 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/self_reference.test
@@ -0,0 +1,45 @@
--source ../include/self_reference_init.inc
--echo
--echo this test is for MDEV-6268
--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
--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

--echo
--echo select test 1

--connection master_1
--error 12719
SELECT pkey FROM tbl_a;

--echo
--echo deinit
--disable_warnings

--connection master_1
DROP DATABASE IF EXISTS auto_test_local;

--enable_warnings
--source ../include/self_reference_deinit.inc
--echo
--echo end of test
Expand Up @@ -70,6 +70,7 @@ sync_with_master;
SET SESSION sql_log_bin= 0;

--connection child2_1
--replace_regex /-[0-9a-f]{12}-[0-9a-f]+-/-xxxxxxxxxxxx-xxxxx-/
eval $CHILD2_1_SELECT_ARGUMENT1;
eval $CHILD2_1_SELECT_TABLES;

Expand Down
1 change: 1 addition & 0 deletions storage/spider/mysql-test/spider/bugfix/t/sql_mode.inc
Expand Up @@ -48,6 +48,7 @@ TRUNCATE TABLE mysql.general_log;
SELECT * FROM tbl_a ORDER BY pkey;

--connection child2_1
--replace_regex /-[0-9a-f]{12}-[0-9a-f]+-/-xxxxxxxxxxxx-xxxxx-/
eval $CHILD2_1_SELECT_ARGUMENT1;
eval $CHILD2_1_SELECT_TABLES;

Expand Down
8 changes: 8 additions & 0 deletions storage/spider/mysql-test/spider/include/deinit_spider.inc
Expand Up @@ -46,6 +46,10 @@ DROP TABLE IF EXISTS mysql.spider_table_sts;
DROP TABLE IF EXISTS mysql.spider_table_crd;
if ($VERSION_COMPILE_OS_WIN)
{
if ($MASTER_1_MYPORT)
{
DROP SERVER s_1;
}
if ($CHILD2_1_MYPORT)
{
DROP SERVER s_2_1;
Expand Down Expand Up @@ -73,6 +77,10 @@ if ($VERSION_COMPILE_OS_WIN)
}
if (!$VERSION_COMPILE_OS_WIN)
{
if ($MASTER_1_MYSOCK)
{
DROP SERVER s_1;
}
if ($CHILD2_1_MYSOCK)
{
DROP SERVER s_2_1;
Expand Down
20 changes: 20 additions & 0 deletions storage/spider/mysql-test/spider/include/init_spider.inc
Expand Up @@ -3,6 +3,16 @@ let $VERSION_COMPILE_OS_WIN=
if ($VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.dll';
if ($MASTER_1_MYPORT)
{
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
PASSWORD '',
PORT $MASTER_1_MYPORT
);
}
if ($CHILD2_1_MYPORT)
{
eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
Expand Down Expand Up @@ -67,6 +77,16 @@ if ($VERSION_COMPILE_OS_WIN)
if (!$VERSION_COMPILE_OS_WIN)
{
INSTALL PLUGIN spider SONAME 'ha_spider.so';
if ($MASTER_1_MYSOCK)
{
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
HOST 'localhost',
DATABASE 'auto_test_local',
USER 'root',
PASSWORD '',
SOCKET '$MASTER_1_MYSOCK'
);
}
if ($CHILD2_1_MYSOCK)
{
eval CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
Expand Down
Expand Up @@ -51,7 +51,7 @@ SET SESSION sql_log_bin= 0;
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%set %';
argument
set session time_zone = '+00:00'
set session time_zone = '+00:00';set @`spider_lc_./auto_test_remote/tbl_a` = '-xxxxxxxxxxxx-xxxxx-./auto_test_local/tbl_a-'
SET NAMES utf8
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 argument LIKE '%set %'
Expand Down
Expand Up @@ -108,6 +108,7 @@ if ($USE_CHILD_GROUP2)
--connection child2_1
if ($USE_GENERAL_LOG)
{
--replace_regex /-[0-9a-f]{12}-[0-9a-f]+-/-xxxxxxxxxxxx-xxxxx-/
eval $CHILD2_1_SELECT_ARGUMENT1;
}
eval $CHILD2_1_SELECT_TABLES;
Expand Down

0 comments on commit 23c8add

Please sign in to comment.