Commit 64569fa8 authored by Sergei Golubchik's avatar Sergei Golubchik

parser: better error messages for CHECK/REPAIR VIEW

remove the code that checks for correct options for
for CHECK/REPAIR VIEW. Rewrite the grammar for the parser
to check that. This changes error messages as

-ERROR 42000: You have an error ... near '' at line 1
+ERROR 42000: You have an error ... near 'quick' at line 1
parent 0ffef5d2
...@@ -3,6 +3,41 @@ drop table if exists t1,v1,v2,v3,v4,v1badcheck; ...@@ -3,6 +3,41 @@ drop table if exists t1,v1,v2,v3,v4,v1badcheck;
drop view if exists t1,v1,v2,v3,v4,v1badcheck; drop view if exists t1,v1,v2,v3,v4,v1badcheck;
create table t1(a int); create table t1(a int);
create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50)); create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50));
create view v1 as select 1;
repair table t1 quick;
Table Op Msg_type Msg_text
test.t1 repair status OK
repair table t1 extended;
Table Op Msg_type Msg_text
test.t1 repair status OK
repair table t1 use_frm;
Table Op Msg_type Msg_text
test.t1 repair status OK
repair table t1 from mysql;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from mysql' at line 1
repair view v1 quick;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'quick' at line 1
repair view v1 extended;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'extended' at line 1
repair view v1 use_frm;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'use_frm' at line 1
repair view v1 from mysql;
Table Op Msg_type Msg_text
test.v1 repair status OK
check view v1 quick;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'quick' at line 1
check view v1 fast;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'fast' at line 1
check view v1 medium;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'medium' at line 1
check view v1 extended;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'extended' at line 1
check view v1 changed;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'changed' at line 1
check view v1 for upgrade;
Table Op Msg_type Msg_text
test.v1 check status OK
drop view v1;
flush tables; flush tables;
check view v1; check view v1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
......
...@@ -8,6 +8,35 @@ drop view if exists t1,v1,v2,v3,v4,v1badcheck; ...@@ -8,6 +8,35 @@ drop view if exists t1,v1,v2,v3,v4,v1badcheck;
create table t1(a int); create table t1(a int);
create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50)); create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50));
create view v1 as select 1;
repair table t1 quick;
repair table t1 extended;
repair table t1 use_frm;
--error ER_PARSE_ERROR
repair table t1 from mysql;
--error ER_PARSE_ERROR
repair view v1 quick;
--error ER_PARSE_ERROR
repair view v1 extended;
--error ER_PARSE_ERROR
repair view v1 use_frm;
repair view v1 from mysql;
--error ER_PARSE_ERROR
check view v1 quick;
--error ER_PARSE_ERROR
check view v1 fast;
--error ER_PARSE_ERROR
check view v1 medium;
--error ER_PARSE_ERROR
check view v1 extended;
--error ER_PARSE_ERROR
check view v1 changed;
check view v1 for upgrade;
drop view v1;
let $MYSQLD_DATADIR= `select @@datadir`; let $MYSQLD_DATADIR= `select @@datadir`;
......
...@@ -533,6 +533,7 @@ void lex_start(THD *thd) ...@@ -533,6 +533,7 @@ void lex_start(THD *thd)
lex->is_lex_started= TRUE; lex->is_lex_started= TRUE;
lex->used_tables= 0; lex->used_tables= 0;
lex->only_view= FALSE;
lex->reset_slave_info.all= false; lex->reset_slave_info.all= false;
lex->limit_rows_examined= 0; lex->limit_rows_examined= 0;
lex->limit_rows_examined_cnt= ULONGLONG_MAX; lex->limit_rows_examined_cnt= ULONGLONG_MAX;
......
...@@ -7191,8 +7191,13 @@ opt_checksum_type: ...@@ -7191,8 +7191,13 @@ opt_checksum_type:
| EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; } | EXTENDED_SYM { Lex->check_opt.flags= T_EXTEND; }
; ;
repair_table_or_view:
table_or_tables table_list opt_mi_repair_type
| VIEW_SYM { Lex->only_view= TRUE; } table_list opt_view_repair_type
;
repair: repair:
REPAIR opt_no_write_to_binlog table_or_view REPAIR opt_no_write_to_binlog
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command = SQLCOM_REPAIR; lex->sql_command = SQLCOM_REPAIR;
...@@ -7202,18 +7207,9 @@ repair: ...@@ -7202,18 +7207,9 @@ repair:
/* Will be overriden during execution. */ /* Will be overriden during execution. */
YYPS->m_lock_type= TL_UNLOCK; YYPS->m_lock_type= TL_UNLOCK;
} }
table_list opt_mi_repair_type repair_table_or_view
{ {
LEX* lex= thd->lex; LEX* lex= thd->lex;
if ((lex->only_view &&
((lex->check_opt.flags & (T_QUICK | T_EXTEND)) ||
(lex->check_opt.sql_flags & TT_USEFRM))) ||
(!lex->only_view &&
(lex->check_opt.sql_flags & TT_FROM_MYSQL)))
{
my_parse_error(ER(ER_SYNTAX_ERROR));
MYSQL_YYABORT;
}
DBUG_ASSERT(!lex->m_stmt); DBUG_ASSERT(!lex->m_stmt);
lex->m_stmt= new (thd->mem_root) Repair_table_statement(lex); lex->m_stmt= new (thd->mem_root) Repair_table_statement(lex);
if (lex->m_stmt == NULL) if (lex->m_stmt == NULL)
...@@ -7235,6 +7231,10 @@ mi_repair_type: ...@@ -7235,6 +7231,10 @@ mi_repair_type:
QUICK { Lex->check_opt.flags|= T_QUICK; } QUICK { Lex->check_opt.flags|= T_QUICK; }
| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; } | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
| USE_FRM { Lex->check_opt.sql_flags|= TT_USEFRM; } | USE_FRM { Lex->check_opt.sql_flags|= TT_USEFRM; }
;
opt_view_repair_type:
/* empty */ { }
| FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; } | FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; }
; ;
...@@ -7267,30 +7267,27 @@ binlog_base64_event: ...@@ -7267,30 +7267,27 @@ binlog_base64_event:
} }
; ;
check: check_view_or_table:
CHECK_SYM table_or_view table_or_tables table_list opt_mi_check_type
| VIEW_SYM { Lex->only_view= TRUE; } table_list opt_view_check_type
;
check: CHECK_SYM
{ {
LEX *lex=Lex; LEX *lex=Lex;
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "CHECK");
MYSQL_YYABORT;
}
lex->sql_command = SQLCOM_CHECK; lex->sql_command = SQLCOM_CHECK;
lex->check_opt.init(); lex->check_opt.init();
lex->alter_info.reset(); lex->alter_info.reset();
/* Will be overriden during execution. */ /* Will be overriden during execution. */
YYPS->m_lock_type= TL_UNLOCK; YYPS->m_lock_type= TL_UNLOCK;
} }
table_list opt_mi_check_type check_view_or_table
{ {
LEX* lex= thd->lex; LEX* lex= thd->lex;
if (lex->only_view && if (lex->sphead)
(lex->check_opt.flags & (T_QUICK | T_FAST | T_EXTEND |
T_CHECK_ONLY_CHANGED)))
{ {
my_parse_error(ER(ER_SYNTAX_ERROR)); my_error(ER_SP_BADSTATEMENT, MYF(0), "CHECK");
MYSQL_YYABORT; MYSQL_YYABORT;
} }
DBUG_ASSERT(!lex->m_stmt); DBUG_ASSERT(!lex->m_stmt);
...@@ -7319,6 +7316,11 @@ mi_check_type: ...@@ -7319,6 +7316,11 @@ mi_check_type:
| FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; } | FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
; ;
opt_view_check_type:
/* empty */ { }
| FOR_SYM UPGRADE_SYM { Lex->check_opt.sql_flags|= TT_FOR_UPGRADE; }
;
optimize: optimize:
OPTIMIZE opt_no_write_to_binlog table_or_tables OPTIMIZE opt_no_write_to_binlog table_or_tables
{ {
...@@ -7400,7 +7402,6 @@ keycache: ...@@ -7400,7 +7402,6 @@ keycache:
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE; lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
lex->ident= $6; lex->ident= $6;
lex->only_view= FALSE;
} }
; ;
...@@ -7445,7 +7446,6 @@ preload: ...@@ -7445,7 +7446,6 @@ 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();
lex->only_view= FALSE;
} }
preload_list_or_parts preload_list_or_parts
{} {}
...@@ -11610,7 +11610,6 @@ show_param: ...@@ -11610,7 +11610,6 @@ show_param:
lex->sql_command = SQLCOM_SHOW_CREATE; lex->sql_command = SQLCOM_SHOW_CREATE;
if (!lex->select_lex.add_table_to_list(thd, $3, NULL,0)) if (!lex->select_lex.add_table_to_list(thd, $3, NULL,0))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->only_view= 0;
lex->create_info.storage_media= HA_SM_DEFAULT; lex->create_info.storage_media= HA_SM_DEFAULT;
} }
| CREATE VIEW_SYM table_ident | CREATE VIEW_SYM table_ident
...@@ -13806,13 +13805,8 @@ lock: ...@@ -13806,13 +13805,8 @@ lock:
; ;
table_or_tables: table_or_tables:
TABLE_SYM { Lex->only_view= FALSE; } TABLE_SYM { }
| TABLES { Lex->only_view= FALSE; } | TABLES { }
;
table_or_view:
table_or_tables
| VIEW_SYM { Lex->only_view= TRUE; }
; ;
table_lock_list: table_lock_list:
......
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