Commit a17a327f authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-21684: mysqld crash with signal 11 when renaming table+max_statement_time

Main select should be pushed first in case of SET STATEMENT.
parent e6373551
...@@ -1807,4 +1807,40 @@ Field Type Null Key Default Extra ...@@ -1807,4 +1807,40 @@ Field Type Null Key Default Extra
a int(11) YES NULL a int(11) YES NULL
drop table t1; drop table t1;
SET STATEMENT max_statement_time=0 FOR do 1; SET STATEMENT max_statement_time=0 FOR do 1;
set @save_sql_mode=@@SQL_MODE;
set SQL_MODE=ORACLE;
create table t1 (a int);
SET STATEMENT max_statement_time=0 FOR desc t1;
Field Type Null Key Default Extra
a int(11) YES NULL
drop table t1;
SET STATEMENT max_statement_time=0 FOR do 1;
set SQL_MODE=@save_sql_mode;
#
# MDEV-21684: mysqld crash with signal 11 when renaming
# table+max_statement_time
#
SET STATEMENT max_statement_time=180 FOR RENAME TABLE bleh TO blah;
ERROR 42S02: Table 'test.bleh' doesn't exist
SET STATEMENT max_statement_time=180 FOR load index into cache t1_base;
Table Op Msg_type Msg_text
test.t1_base preload_keys Error Table 'test.t1_base' doesn't exist
test.t1_base preload_keys status Operation failed
SET STATEMENT max_statement_time=180 FOR DROP INDEX i1 ON t1;
ERROR 42S02: Table 'test.t1' doesn't exist
SET STATEMENT max_statement_time=180 FOR BACKUP LOCK test.t1;
SET STATEMENT max_statement_time=180 FOR BACKUP UNLOCK;
set @save_sql_mode=@@SQL_MODE;
set SQL_MODE=ORACLE;
SET STATEMENT max_statement_time=180 FOR RENAME TABLE bleh TO blah;
ERROR 42S02: Table 'test.bleh' doesn't exist
SET STATEMENT max_statement_time=180 FOR load index into cache t1_base;
Table Op Msg_type Msg_text
test.t1_base preload_keys Error Table 'test.t1_base' doesn't exist
test.t1_base preload_keys status Operation failed
SET STATEMENT max_statement_time=180 FOR DROP INDEX i1 ON t1;
ERROR 42S02: Table 'test.t1' doesn't exist
SET STATEMENT max_statement_time=180 FOR BACKUP LOCK test.t1;
SET STATEMENT max_statement_time=180 FOR BACKUP UNLOCK;
set SQL_MODE=@save_sql_mode;
# End of 10.4 tests # End of 10.4 tests
...@@ -1575,4 +1575,37 @@ SET STATEMENT max_statement_time=0 FOR desc t1; ...@@ -1575,4 +1575,37 @@ SET STATEMENT max_statement_time=0 FOR desc t1;
drop table t1; drop table t1;
SET STATEMENT max_statement_time=0 FOR do 1; SET STATEMENT max_statement_time=0 FOR do 1;
set @save_sql_mode=@@SQL_MODE;
set SQL_MODE=ORACLE;
create table t1 (a int);
SET STATEMENT max_statement_time=0 FOR desc t1;
drop table t1;
SET STATEMENT max_statement_time=0 FOR do 1;
set SQL_MODE=@save_sql_mode;
--echo #
--echo # MDEV-21684: mysqld crash with signal 11 when renaming
--echo # table+max_statement_time
--echo #
--error ER_NO_SUCH_TABLE
SET STATEMENT max_statement_time=180 FOR RENAME TABLE bleh TO blah;
SET STATEMENT max_statement_time=180 FOR load index into cache t1_base;
--error ER_NO_SUCH_TABLE
SET STATEMENT max_statement_time=180 FOR DROP INDEX i1 ON t1;
SET STATEMENT max_statement_time=180 FOR BACKUP LOCK test.t1;
SET STATEMENT max_statement_time=180 FOR BACKUP UNLOCK;
set @save_sql_mode=@@SQL_MODE;
set SQL_MODE=ORACLE;
--error ER_NO_SUCH_TABLE
SET STATEMENT max_statement_time=180 FOR RENAME TABLE bleh TO blah;
SET STATEMENT max_statement_time=180 FOR load index into cache t1_base;
--error ER_NO_SUCH_TABLE
SET STATEMENT max_statement_time=180 FOR DROP INDEX i1 ON t1;
SET STATEMENT max_statement_time=180 FOR BACKUP LOCK test.t1;
SET STATEMENT max_statement_time=180 FOR BACKUP UNLOCK;
set SQL_MODE=@save_sql_mode;
--echo # End of 10.4 tests --echo # End of 10.4 tests
...@@ -8996,9 +8996,13 @@ rename: ...@@ -8996,9 +8996,13 @@ rename:
RENAME table_or_tables RENAME table_or_tables
{ {
Lex->sql_command= SQLCOM_RENAME_TABLE; Lex->sql_command= SQLCOM_RENAME_TABLE;
if (Lex->main_select_push())
MYSQL_YYABORT;
} }
table_to_table_list table_to_table_list
{} {
Lex->pop_select(); //main select
}
| RENAME USER_SYM clear_privileges rename_list | RENAME USER_SYM clear_privileges rename_list
{ {
Lex->sql_command = SQLCOM_RENAME_USER; Lex->sql_command = SQLCOM_RENAME_USER;
...@@ -9096,9 +9100,13 @@ preload: ...@@ -9096,9 +9100,13 @@ preload:
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command=SQLCOM_PRELOAD_KEYS; lex->sql_command=SQLCOM_PRELOAD_KEYS;
lex->alter_info.reset(); lex->alter_info.reset();
if (lex->main_select_push())
MYSQL_YYABORT;
} }
preload_list_or_parts preload_list_or_parts
{} {
Lex->pop_select(); //main select
}
; ;
preload_list_or_parts: preload_list_or_parts:
...@@ -13278,11 +13286,16 @@ drop: ...@@ -13278,11 +13286,16 @@ drop:
} }
table_list opt_lock_wait_timeout opt_restrict table_list opt_lock_wait_timeout opt_restrict
{} {}
| DROP INDEX_SYM opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout | DROP INDEX_SYM
{
if (Lex->main_select_push())
MYSQL_YYABORT;
}
opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout
{ {
LEX *lex=Lex; LEX *lex=Lex;
Alter_drop *ad= (new (thd->mem_root) Alter_drop *ad= (new (thd->mem_root)
Alter_drop(Alter_drop::KEY, $4.str, $3)); Alter_drop(Alter_drop::KEY, $5.str, $4));
if (unlikely(ad == NULL)) if (unlikely(ad == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->sql_command= SQLCOM_DROP_INDEX; lex->sql_command= SQLCOM_DROP_INDEX;
...@@ -13290,10 +13303,11 @@ drop: ...@@ -13290,10 +13303,11 @@ drop:
lex->alter_info.flags= ALTER_DROP_INDEX; lex->alter_info.flags= ALTER_DROP_INDEX;
lex->alter_info.drop_list.push_back(ad, thd->mem_root); lex->alter_info.drop_list.push_back(ad, thd->mem_root);
if (unlikely(!lex->current_select-> if (unlikely(!lex->current_select->
add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING, add_table_to_list(thd, $7, NULL, TL_OPTION_UPDATING,
TL_READ_NO_INSERT, TL_READ_NO_INSERT,
MDL_SHARED_UPGRADABLE))) MDL_SHARED_UPGRADABLE)))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->pop_select(); //main select
} }
| DROP DATABASE opt_if_exists ident | DROP DATABASE opt_if_exists ident
{ {
...@@ -14789,12 +14803,18 @@ backup_statements: ...@@ -14789,12 +14803,18 @@ backup_statements:
Lex->backup_stage= (backup_stages) (type-1); Lex->backup_stage= (backup_stages) (type-1);
break; break;
} }
| LOCK_SYM table_ident | LOCK_SYM
{ {
if (unlikely(!Select->add_table_to_list(thd, $2, NULL, 0, if (Lex->main_select_push())
MYSQL_YYABORT;
}
table_ident
{
if (unlikely(!Select->add_table_to_list(thd, $3, NULL, 0,
TL_READ, MDL_SHARED_HIGH_PRIO))) TL_READ, MDL_SHARED_HIGH_PRIO)))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->sql_command= SQLCOM_BACKUP_LOCK; Lex->sql_command= SQLCOM_BACKUP_LOCK;
Lex->pop_select(); //main select
} }
| UNLOCK_SYM | UNLOCK_SYM
{ {
......
...@@ -9097,9 +9097,13 @@ rename: ...@@ -9097,9 +9097,13 @@ rename:
RENAME table_or_tables RENAME table_or_tables
{ {
Lex->sql_command= SQLCOM_RENAME_TABLE; Lex->sql_command= SQLCOM_RENAME_TABLE;
if (Lex->main_select_push())
MYSQL_YYABORT;
} }
table_to_table_list table_to_table_list
{} {
Lex->pop_select(); //main select
}
| RENAME USER_SYM clear_privileges rename_list | RENAME USER_SYM clear_privileges rename_list
{ {
Lex->sql_command = SQLCOM_RENAME_USER; Lex->sql_command = SQLCOM_RENAME_USER;
...@@ -9197,9 +9201,13 @@ preload: ...@@ -9197,9 +9201,13 @@ preload:
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command=SQLCOM_PRELOAD_KEYS; lex->sql_command=SQLCOM_PRELOAD_KEYS;
lex->alter_info.reset(); lex->alter_info.reset();
if (lex->main_select_push())
MYSQL_YYABORT;
} }
preload_list_or_parts preload_list_or_parts
{} {
Lex->pop_select(); //main select
}
; ;
preload_list_or_parts: preload_list_or_parts:
...@@ -13363,11 +13371,14 @@ do: ...@@ -13363,11 +13371,14 @@ do:
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command = SQLCOM_DO; lex->sql_command = SQLCOM_DO;
if (lex->main_select_push())
MYSQL_YYABORT;
mysql_init_select(lex); mysql_init_select(lex);
} }
expr_list expr_list
{ {
Lex->insert_list= $3; Lex->insert_list= $3;
Lex->pop_select(); //main select
} }
; ;
...@@ -13385,11 +13396,16 @@ drop: ...@@ -13385,11 +13396,16 @@ drop:
} }
table_list opt_lock_wait_timeout opt_restrict table_list opt_lock_wait_timeout opt_restrict
{} {}
| DROP INDEX_SYM opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout | DROP INDEX_SYM
{
if (Lex->main_select_push())
MYSQL_YYABORT;
}
opt_if_exists_table_element ident ON table_ident opt_lock_wait_timeout
{ {
LEX *lex=Lex; LEX *lex=Lex;
Alter_drop *ad= (new (thd->mem_root) Alter_drop *ad= (new (thd->mem_root)
Alter_drop(Alter_drop::KEY, $4.str, $3)); Alter_drop(Alter_drop::KEY, $5.str, $4));
if (unlikely(ad == NULL)) if (unlikely(ad == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->sql_command= SQLCOM_DROP_INDEX; lex->sql_command= SQLCOM_DROP_INDEX;
...@@ -13397,10 +13413,11 @@ drop: ...@@ -13397,10 +13413,11 @@ drop:
lex->alter_info.flags= ALTER_DROP_INDEX; lex->alter_info.flags= ALTER_DROP_INDEX;
lex->alter_info.drop_list.push_back(ad, thd->mem_root); lex->alter_info.drop_list.push_back(ad, thd->mem_root);
if (unlikely(!lex->current_select-> if (unlikely(!lex->current_select->
add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING, add_table_to_list(thd, $7, NULL, TL_OPTION_UPDATING,
TL_READ_NO_INSERT, TL_READ_NO_INSERT,
MDL_SHARED_UPGRADABLE))) MDL_SHARED_UPGRADABLE)))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->pop_select(); //main select
} }
| DROP DATABASE opt_if_exists ident | DROP DATABASE opt_if_exists ident
{ {
...@@ -14685,6 +14702,8 @@ describe: ...@@ -14685,6 +14702,8 @@ describe:
describe_command table_ident describe_command table_ident
{ {
LEX *lex= Lex; LEX *lex= Lex;
if (lex->main_select_push())
MYSQL_YYABORT;
mysql_init_select(lex); mysql_init_select(lex);
lex->current_select->parsing_place= SELECT_LIST; lex->current_select->parsing_place= SELECT_LIST;
lex->sql_command= SQLCOM_SHOW_FIELDS; lex->sql_command= SQLCOM_SHOW_FIELDS;
...@@ -14696,6 +14715,7 @@ describe: ...@@ -14696,6 +14715,7 @@ describe:
opt_describe_column opt_describe_column
{ {
Select->parsing_place= NO_MATTER; Select->parsing_place= NO_MATTER;
Lex->pop_select(); //main select
} }
| describe_command opt_extended_describe | describe_command opt_extended_describe
{ Lex->describe|= DESCRIBE_NORMAL; } { Lex->describe|= DESCRIBE_NORMAL; }
...@@ -14916,12 +14936,18 @@ backup_statements: ...@@ -14916,12 +14936,18 @@ backup_statements:
Lex->backup_stage= (backup_stages) (type-1); Lex->backup_stage= (backup_stages) (type-1);
break; break;
} }
| LOCK_SYM table_ident | LOCK_SYM
{ {
if (unlikely(!Select->add_table_to_list(thd, $2, NULL, 0, if (Lex->main_select_push())
MYSQL_YYABORT;
}
table_ident
{
if (unlikely(!Select->add_table_to_list(thd, $3, NULL, 0,
TL_READ, MDL_SHARED_HIGH_PRIO))) TL_READ, MDL_SHARED_HIGH_PRIO)))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->sql_command= SQLCOM_BACKUP_LOCK; Lex->sql_command= SQLCOM_BACKUP_LOCK;
Lex->pop_select(); //main select
} }
| UNLOCK_SYM | UNLOCK_SYM
{ {
......
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