Commit 78a891c8 authored by Alexander Barkov's avatar Alexander Barkov

A partial patch for MDEV-12518 Unify sql_yacc.yy and sql_yacc_ora.yy

Making sql_yacc.yy close to sql_yacc_ora.yy:

1. Adding struct sp_cursor_name_and_offset into %union
2. Adding field_type_numeric, field_type_string,  field_type_lob,
   field_type_temporal, field_type_misc
3. Adding keyword_sp_data_type and keyword_sp_not_data_type
4. Removing "opt_savepoint". Moving this grammar to "rollback" instead.
   This fixes one shift/reduce conflict.
5. Minor indentation cleanup.
parent 7a70641f
...@@ -772,6 +772,11 @@ Virtual_column_info *add_virtual_expression(THD *thd, Item *expr) ...@@ -772,6 +772,11 @@ Virtual_column_info *add_virtual_expression(THD *thd, Item *expr)
Lex_dyncol_type_st Lex_dyncol_type; Lex_dyncol_type_st Lex_dyncol_type;
Lex_for_loop_st for_loop; Lex_for_loop_st for_loop;
Lex_for_loop_bounds_st for_loop_bounds; Lex_for_loop_bounds_st for_loop_bounds;
struct
{
LEX_CSTRING name;
uint offset;
} sp_cursor_name_and_offset;
/* pointers */ /* pointers */
Create_field *create_field; Create_field *create_field;
...@@ -860,10 +865,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); ...@@ -860,10 +865,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%parse-param { THD *thd } %parse-param { THD *thd }
%lex-param { THD *thd } %lex-param { THD *thd }
/* /*
Currently there are 103 shift/reduce conflicts. Currently there are 102 shift/reduce conflicts.
We should not introduce new conflicts any more. We should not introduce new conflicts any more.
*/ */
%expect 103 %expect 102
/* /*
Comments for TOKENS. Comments for TOKENS.
...@@ -1641,6 +1646,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); ...@@ -1641,6 +1646,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <field_type> int_type real_type %type <field_type> int_type real_type
%type <Lex_field_type> type_with_opt_collate field_type %type <Lex_field_type> type_with_opt_collate field_type
field_type_numeric
field_type_string
field_type_lob
field_type_temporal
field_type_misc
%type <Lex_dyncol_type> opt_dyncol_type dyncol_type %type <Lex_dyncol_type> opt_dyncol_type dyncol_type
numeric_dyncol_type temporal_dyncol_type string_dyncol_type numeric_dyncol_type temporal_dyncol_type string_dyncol_type
...@@ -1787,6 +1797,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); ...@@ -1787,6 +1797,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <Lex_length_and_dec> precision opt_precision float_options %type <Lex_length_and_dec> precision opt_precision float_options
%type <symbol> keyword keyword_sp %type <symbol> keyword keyword_sp
keyword_sp_data_type
keyword_sp_not_data_type
%type <lex_user> user grant_user grant_role user_or_role current_role %type <lex_user> user grant_user grant_role user_or_role current_role
admin_option_for_role user_maybe_role admin_option_for_role user_maybe_role
...@@ -6243,6 +6255,14 @@ column_default_expr: ...@@ -6243,6 +6255,14 @@ column_default_expr:
; ;
field_type: field_type:
field_type_numeric
| field_type_temporal
| field_type_string
| field_type_lob
| field_type_misc
;
field_type_numeric:
int_type opt_field_length field_options { $$.set($1, $2); } int_type opt_field_length field_options { $$.set($1, $2); }
| real_type opt_precision field_options { $$.set($1, $2); } | real_type opt_precision field_options { $$.set($1, $2); }
| FLOAT_SYM float_options field_options | FLOAT_SYM float_options field_options
...@@ -6273,7 +6293,17 @@ field_type: ...@@ -6273,7 +6293,17 @@ field_type:
{ {
$$.set(MYSQL_TYPE_TINY, "1"); $$.set(MYSQL_TYPE_TINY, "1");
} }
| char opt_field_length_default_1 opt_binary | DECIMAL_SYM float_options field_options
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);}
| NUMERIC_SYM float_options field_options
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);}
| FIXED_SYM float_options field_options
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);}
;
field_type_string:
char opt_field_length_default_1 opt_binary
{ {
$$.set(MYSQL_TYPE_STRING, $2); $$.set(MYSQL_TYPE_STRING, $2);
} }
...@@ -6301,7 +6331,10 @@ field_type: ...@@ -6301,7 +6331,10 @@ field_type:
Lex->charset=&my_charset_bin; Lex->charset=&my_charset_bin;
$$.set(MYSQL_TYPE_VARCHAR, $2); $$.set(MYSQL_TYPE_VARCHAR, $2);
} }
| YEAR_SYM opt_field_length field_options ;
field_type_temporal:
YEAR_SYM opt_field_length field_options
{ {
if ($2) if ($2)
{ {
...@@ -6344,7 +6377,11 @@ field_type: ...@@ -6344,7 +6377,11 @@ field_type:
| DATETIME opt_field_length | DATETIME opt_field_length
{ $$.set(opt_mysql56_temporal_format ? { $$.set(opt_mysql56_temporal_format ?
MYSQL_TYPE_DATETIME2 : MYSQL_TYPE_DATETIME, $2); } MYSQL_TYPE_DATETIME2 : MYSQL_TYPE_DATETIME, $2); }
| TINYBLOB ;
field_type_lob:
TINYBLOB
{ {
Lex->charset=&my_charset_bin; Lex->charset=&my_charset_bin;
$$.set(MYSQL_TYPE_TINY_BLOB); $$.set(MYSQL_TYPE_TINY_BLOB);
...@@ -6390,18 +6427,16 @@ field_type: ...@@ -6390,18 +6427,16 @@ field_type:
{ $$.set(MYSQL_TYPE_MEDIUM_BLOB); } { $$.set(MYSQL_TYPE_MEDIUM_BLOB); }
| LONGTEXT opt_binary | LONGTEXT opt_binary
{ $$.set(MYSQL_TYPE_LONG_BLOB); } { $$.set(MYSQL_TYPE_LONG_BLOB); }
| DECIMAL_SYM float_options field_options | LONG_SYM opt_binary
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);} { $$.set(MYSQL_TYPE_MEDIUM_BLOB); }
| NUMERIC_SYM float_options field_options ;
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);}
| FIXED_SYM float_options field_options
{ $$.set(MYSQL_TYPE_NEWDECIMAL, $2);} field_type_misc:
| ENUM '(' string_list ')' opt_binary ENUM '(' string_list ')' opt_binary
{ $$.set(MYSQL_TYPE_ENUM); } { $$.set(MYSQL_TYPE_ENUM); }
| SET '(' string_list ')' opt_binary | SET '(' string_list ')' opt_binary
{ $$.set(MYSQL_TYPE_SET); } { $$.set(MYSQL_TYPE_SET); }
| LONG_SYM opt_binary
{ $$.set(MYSQL_TYPE_MEDIUM_BLOB); }
; ;
spatial_type: spatial_type:
...@@ -14093,7 +14128,7 @@ simple_ident: ...@@ -14093,7 +14128,7 @@ simple_ident:
lip->get_tok_end()))) lip->get_tok_end())))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| simple_ident_q2 { $$= $1; } | simple_ident_q2
| ident '.' ident | ident '.' ident
{ {
LEX *lex= thd->lex; LEX *lex= thd->lex;
...@@ -14480,6 +14515,49 @@ keyword: ...@@ -14480,6 +14515,49 @@ keyword:
* conflicts. * conflicts.
*/ */
keyword_sp: keyword_sp:
keyword_sp_data_type
| keyword_sp_not_data_type
;
/*
These keywords are generally allowed as identifiers,
but not allowed as non-delimited SP variable names in sql_mode=ORACLE.
*/
keyword_sp_data_type:
BIT_SYM {}
| BOOLEAN_SYM {} /* PLSQL-R */
| BOOL_SYM {}
| CLOB {}
| DATE_SYM {} /* Oracle-R, PLSQL-R */
| DATETIME {}
| ENUM {}
| FIXED_SYM {}
| GEOMETRYCOLLECTION {}
| GEOMETRY_SYM {}
| LINESTRING {}
| MEDIUM_SYM {}
| MULTILINESTRING {}
| MULTIPOINT {}
| MULTIPOLYGON {}
| NATIONAL_SYM {}
| NCHAR_SYM {}
| NUMBER_SYM {} /* Oracle-R, PLSQL-R */
| NVARCHAR_SYM {}
| POINT_SYM {}
| POLYGON {}
| RAW {} /* Oracle-R */
| ROW_SYM {}
| SERIAL_SYM {}
| TEXT_SYM {}
| TIMESTAMP {}
| TIME_SYM {} /* Oracle-R */
| VARCHAR2 {} /* Oracle-R, PLSQL-R */
| YEAR_SYM {}
;
keyword_sp_not_data_type:
ACTION {} ACTION {}
| ADDDATE_SYM {} | ADDDATE_SYM {}
| ADMIN_SYM {} | ADMIN_SYM {}
...@@ -14497,10 +14575,7 @@ keyword_sp: ...@@ -14497,10 +14575,7 @@ keyword_sp:
| AUTO_SYM {} | AUTO_SYM {}
| AVG_ROW_LENGTH {} | AVG_ROW_LENGTH {}
| AVG_SYM {} | AVG_SYM {}
| BIT_SYM {}
| BLOCK_SYM {} | BLOCK_SYM {}
| BOOL_SYM {}
| BOOLEAN_SYM {}
| BTREE_SYM {} | BTREE_SYM {}
| CASCADED {} | CASCADED {}
| CATALOG_NAME_SYM {} | CATALOG_NAME_SYM {}
...@@ -14509,7 +14584,6 @@ keyword_sp: ...@@ -14509,7 +14584,6 @@ keyword_sp:
| CIPHER_SYM {} | CIPHER_SYM {}
| CLIENT_SYM {} | CLIENT_SYM {}
| CLASS_ORIGIN_SYM {} | CLASS_ORIGIN_SYM {}
| CLOB {}
| COALESCE {} | COALESCE {}
| CODE_SYM {} | CODE_SYM {}
| COLLATION_SYM {} | COLLATION_SYM {}
...@@ -14539,8 +14613,6 @@ keyword_sp: ...@@ -14539,8 +14613,6 @@ keyword_sp:
| CYCLE_SYM {} | CYCLE_SYM {}
| DATA_SYM {} | DATA_SYM {}
| DATAFILE_SYM {} | DATAFILE_SYM {}
| DATETIME {}
| DATE_SYM {}
| DAY_SYM {} | DAY_SYM {}
| DECODE_SYM {} | DECODE_SYM {}
| DEFINER_SYM {} | DEFINER_SYM {}
...@@ -14556,7 +14628,6 @@ keyword_sp: ...@@ -14556,7 +14628,6 @@ keyword_sp:
| DYNAMIC_SYM {} | DYNAMIC_SYM {}
| ELSIF_SYM {} | ELSIF_SYM {}
| ENDS_SYM {} | ENDS_SYM {}
| ENUM {}
| ENGINE_SYM {} | ENGINE_SYM {}
| ENGINES_SYM {} | ENGINES_SYM {}
| ERROR_SYM {} | ERROR_SYM {}
...@@ -14578,11 +14649,8 @@ keyword_sp: ...@@ -14578,11 +14649,8 @@ keyword_sp:
| FULL {} | FULL {}
| FILE_SYM {} | FILE_SYM {}
| FIRST_SYM {} | FIRST_SYM {}
| FIXED_SYM {}
| GENERAL {} | GENERAL {}
| GENERATED_SYM {} | GENERATED_SYM {}
| GEOMETRY_SYM {}
| GEOMETRYCOLLECTION {}
| GET_FORMAT {} | GET_FORMAT {}
| GRANTS {} | GRANTS {}
| GLOBAL_SYM {} | GLOBAL_SYM {}
...@@ -14614,7 +14682,6 @@ keyword_sp: ...@@ -14614,7 +14682,6 @@ keyword_sp:
| LEAVES {} | LEAVES {}
| LESS_SYM {} | LESS_SYM {}
| LEVEL_SYM {} | LEVEL_SYM {}
| LINESTRING {}
| LIST_SYM {} | LIST_SYM {}
| LOCAL_SYM {} | LOCAL_SYM {}
| LOCKS_SYM {} | LOCKS_SYM {}
...@@ -14648,7 +14715,6 @@ keyword_sp: ...@@ -14648,7 +14715,6 @@ keyword_sp:
| MAX_STATEMENT_TIME_SYM {} | MAX_STATEMENT_TIME_SYM {}
| MAX_UPDATES_PER_HOUR {} | MAX_UPDATES_PER_HOUR {}
| MAX_USER_CONNECTIONS_SYM {} | MAX_USER_CONNECTIONS_SYM {}
| MEDIUM_SYM {}
| MEMORY_SYM {} | MEMORY_SYM {}
| MERGE_SYM {} | MERGE_SYM {}
| MESSAGE_TEXT_SYM {} | MESSAGE_TEXT_SYM {}
...@@ -14660,16 +14726,11 @@ keyword_sp: ...@@ -14660,16 +14726,11 @@ keyword_sp:
| MODIFY_SYM {} | MODIFY_SYM {}
| MODE_SYM {} | MODE_SYM {}
| MONTH_SYM {} | MONTH_SYM {}
| MULTILINESTRING {}
| MULTIPOINT {}
| MULTIPOLYGON {}
| MUTEX_SYM {} | MUTEX_SYM {}
| MYSQL_SYM {} | MYSQL_SYM {}
| MYSQL_ERRNO_SYM {} | MYSQL_ERRNO_SYM {}
| NAME_SYM {} | NAME_SYM {}
| NAMES_SYM {} | NAMES_SYM {}
| NATIONAL_SYM {}
| NCHAR_SYM {}
| NEXT_SYM {} | NEXT_SYM {}
| NEXTVAL_SYM {} | NEXTVAL_SYM {}
| NEW_SYM {} | NEW_SYM {}
...@@ -14681,8 +14742,6 @@ keyword_sp: ...@@ -14681,8 +14742,6 @@ keyword_sp:
| NODEGROUP_SYM {} | NODEGROUP_SYM {}
| NONE_SYM {} | NONE_SYM {}
| NOTFOUND_SYM {} | NOTFOUND_SYM {}
| NUMBER_SYM {}
| NVARCHAR_SYM {}
| OF_SYM {} /* SQL-1999-R, Oracle-R */ | OF_SYM {} /* SQL-1999-R, Oracle-R */
| OFFSET_SYM {} | OFFSET_SYM {}
| OLD_PASSWORD_SYM {} | OLD_PASSWORD_SYM {}
...@@ -14699,8 +14758,6 @@ keyword_sp: ...@@ -14699,8 +14758,6 @@ keyword_sp:
| PHASE_SYM {} | PHASE_SYM {}
| PLUGIN_SYM {} | PLUGIN_SYM {}
| PLUGINS_SYM {} | PLUGINS_SYM {}
| POINT_SYM {}
| POLYGON {}
| PRESERVE_SYM {} | PRESERVE_SYM {}
| PREV_SYM {} | PREV_SYM {}
| PREVIOUS_SYM {} | PREVIOUS_SYM {}
...@@ -14714,7 +14771,6 @@ keyword_sp: ...@@ -14714,7 +14771,6 @@ keyword_sp:
| QUERY_SYM {} | QUERY_SYM {}
| QUICK {} | QUICK {}
| RAISE_SYM {} | RAISE_SYM {}
| RAW {}
| READ_ONLY_SYM {} | READ_ONLY_SYM {}
| REBUILD_SYM {} | REBUILD_SYM {}
| RECOVER_SYM {} | RECOVER_SYM {}
...@@ -14734,7 +14790,7 @@ keyword_sp: ...@@ -14734,7 +14790,7 @@ keyword_sp:
| RESUME_SYM {} | RESUME_SYM {}
| RETURNED_SQLSTATE_SYM {} | RETURNED_SQLSTATE_SYM {}
| RETURNS_SYM {} | RETURNS_SYM {}
| REUSE_SYM {} | REUSE_SYM {} /* Oracle-R */
| REVERSE_SYM {} | REVERSE_SYM {}
| ROLE_SYM {} | ROLE_SYM {}
| ROLLUP_SYM {} | ROLLUP_SYM {}
...@@ -14743,13 +14799,11 @@ keyword_sp: ...@@ -14743,13 +14799,11 @@ keyword_sp:
| ROWTYPE_SYM {} | ROWTYPE_SYM {}
| ROW_COUNT_SYM {} | ROW_COUNT_SYM {}
| ROW_FORMAT_SYM {} | ROW_FORMAT_SYM {}
| ROW_SYM {}
| RTREE_SYM {} | RTREE_SYM {}
| SCHEDULE_SYM {} | SCHEDULE_SYM {}
| SCHEMA_NAME_SYM {} | SCHEMA_NAME_SYM {}
| SECOND_SYM {} | SECOND_SYM {}
| SEQUENCE_SYM {} | SEQUENCE_SYM {}
| SERIAL_SYM {}
| SERIALIZABLE_SYM {} | SERIALIZABLE_SYM {}
| SESSION_SYM {} | SESSION_SYM {}
| SIMPLE_SYM {} | SIMPLE_SYM {}
...@@ -14784,15 +14838,12 @@ keyword_sp: ...@@ -14784,15 +14838,12 @@ keyword_sp:
| TABLESPACE {} | TABLESPACE {}
| TEMPORARY {} | TEMPORARY {}
| TEMPTABLE_SYM {} | TEMPTABLE_SYM {}
| TEXT_SYM {}
| THAN_SYM {} | THAN_SYM {}
| TRANSACTION_SYM {} | TRANSACTION_SYM {}
| TRANSACTIONAL_SYM {} | TRANSACTIONAL_SYM {}
| TRIGGERS_SYM {} | TRIGGERS_SYM {}
| TIMESTAMP {}
| TIMESTAMP_ADD {} | TIMESTAMP_ADD {}
| TIMESTAMP_DIFF {} | TIMESTAMP_DIFF {}
| TIME_SYM {}
| TYPES_SYM {} | TYPES_SYM {}
| TYPE_SYM {} | TYPE_SYM {}
| UDF_RETURNS_SYM {} | UDF_RETURNS_SYM {}
...@@ -14805,7 +14856,6 @@ keyword_sp: ...@@ -14805,7 +14856,6 @@ keyword_sp:
| UNTIL_SYM {} | UNTIL_SYM {}
| USER_SYM {} | USER_SYM {}
| USE_FRM {} | USE_FRM {}
| VARCHAR2 {}
| VARIABLES {} | VARIABLES {}
| VIEW_SYM {} | VIEW_SYM {}
| VIRTUAL_SYM {} | VIRTUAL_SYM {}
...@@ -14817,7 +14867,6 @@ keyword_sp: ...@@ -14817,7 +14867,6 @@ keyword_sp:
| WORK_SYM {} | WORK_SYM {}
| X509_SYM {} | X509_SYM {}
| XML_SYM {} | XML_SYM {}
| YEAR_SYM {}
| VIA_SYM {} | VIA_SYM {}
; ;
...@@ -15956,11 +16005,6 @@ opt_release: ...@@ -15956,11 +16005,6 @@ opt_release:
| NO_SYM RELEASE_SYM { $$= TVL_NO; } | NO_SYM RELEASE_SYM { $$= TVL_NO; }
; ;
opt_savepoint:
/* empty */ {}
| SAVEPOINT_SYM {}
;
commit: commit:
COMMIT_SYM opt_work opt_chain opt_release COMMIT_SYM opt_work opt_chain opt_release
{ {
...@@ -15983,13 +16027,18 @@ rollback: ...@@ -15983,13 +16027,18 @@ rollback:
lex->tx_chain= $3; lex->tx_chain= $3;
lex->tx_release= $4; lex->tx_release= $4;
} }
| ROLLBACK_SYM opt_work | ROLLBACK_SYM opt_work TO_SYM SAVEPOINT_SYM ident
TO_SYM opt_savepoint ident
{ {
LEX *lex=Lex; LEX *lex=Lex;
lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT; lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
lex->ident= $5; lex->ident= $5;
} }
| ROLLBACK_SYM opt_work TO_SYM ident
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_ROLLBACK_TO_SAVEPOINT;
lex->ident= $4;
}
; ;
savepoint: savepoint:
......
...@@ -14720,7 +14720,7 @@ keyword_sp: ...@@ -14720,7 +14720,7 @@ keyword_sp:
/* /*
These keywords are generally allowed as identifiers, These keywords are generally allowed as identifiers,
but not allowed as non-delimited SP variable names. but not allowed as non-delimited SP variable names in sql_mode=ORACLE.
*/ */
keyword_sp_data_type: keyword_sp_data_type:
BIT_SYM {} BIT_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