diff --git a/mysql-test/suite/compat/oracle/r/win.result b/mysql-test/suite/compat/oracle/r/win.result new file mode 100644 index 0000000000000..a35e2c79b28d8 --- /dev/null +++ b/mysql-test/suite/compat/oracle/r/win.result @@ -0,0 +1,16 @@ +# +# MDEV-13384: "window" seems like a reserved column name but it's not listed as one +# +# Currently we allow window as an identifier, except for table aliases. +# +CREATE TABLE door (id INT, window VARCHAR(10)); +SELECT id +FROM door as window; +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 'window' at line 2 +SELECT id, window +FROM door; +id window +SELECT id, window +FROM door as window; +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 'window' at line 2 +DROP TABLE door; diff --git a/mysql-test/suite/compat/oracle/t/win.test b/mysql-test/suite/compat/oracle/t/win.test new file mode 100644 index 0000000000000..d38b92e0a176a --- /dev/null +++ b/mysql-test/suite/compat/oracle/t/win.test @@ -0,0 +1,20 @@ +--echo # +--echo # MDEV-13384: "window" seems like a reserved column name but it's not listed as one +--echo # +--echo # Currently we allow window as an identifier, except for table aliases. +--echo # + +CREATE TABLE door (id INT, window VARCHAR(10)); + +--error ER_PARSE_ERROR +SELECT id +FROM door as window; + +SELECT id, window +FROM door; + +--error ER_PARSE_ERROR +SELECT id, window +FROM door as window; + +DROP TABLE door; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 14264924eed64..e9b5d3b5f8f0f 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1224,7 +1224,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token PACKAGE_SYM /* Oracle-R */ %token RAISE_SYM /* Oracle-PLSQL-R */ %token ROWTYPE_SYM /* Oracle-PLSQL-R */ -%token WINDOW_SYM /* Non-reserved keywords @@ -1640,6 +1639,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token WARNINGS %token WEEK_SYM %token WEIGHT_STRING_SYM +%token WINDOW_SYM /* SQL-2003-R */ %token WITHIN %token WITHOUT /* SQL-2003-R */ %token WORK_SYM /* SQL-2003-N */ @@ -15318,10 +15318,8 @@ ident_table_alias: IDENT_sys | keyword_alias { - $$.str= thd->strmake($1.str, $1.length); - if (unlikely($$.str == NULL)) + if (unlikely($$.copy_keyword(thd, &$1))) MYSQL_YYABORT; - $$.length= $1.length; } ; diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 8992e9ce9ad92..a4491258906fc 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -610,7 +610,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token PACKAGE_SYM /* Oracle-R */ %token RAISE_SYM /* Oracle-PLSQL-R */ %token ROWTYPE_SYM /* Oracle-PLSQL-R */ -%token WINDOW_SYM /* Non-reserved keywords @@ -1026,6 +1025,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %token WARNINGS %token WEEK_SYM %token WEIGHT_STRING_SYM +%token WINDOW_SYM /* SQL-2003-R */ %token WITHIN %token WITHOUT /* SQL-2003-R */ %token WORK_SYM /* SQL-2003-N */ @@ -1101,8 +1101,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); IDENT_sys ident label_ident - ident_or_empty sp_decl_ident + ident_or_empty + ident_table_alias ident_directly_assignable %type @@ -1120,6 +1121,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type keyword keyword_sp + keyword_alias keyword_directly_assignable keyword_directly_not_assignable keyword_sp_data_type @@ -12019,7 +12021,7 @@ table_alias: opt_table_alias: /* empty */ { $$=0; } - | table_alias ident + | table_alias ident_table_alias { $$= (LEX_CSTRING*) thd->memdup(&$2,sizeof(LEX_STRING)); if (unlikely($$ == NULL)) @@ -14997,6 +14999,15 @@ TEXT_STRING_filesystem: } ; +ident_table_alias: + IDENT_sys + | keyword_alias + { + if (unlikely($$.copy_keyword(thd, &$1))) + MYSQL_YYABORT; + } + ; + ident: IDENT_sys | keyword @@ -15114,14 +15125,17 @@ user: user_maybe_role } ; -/* Keyword that we allow for identifiers (except SP labels) */ -keyword: +/* Keywords which we allow as table aliases. */ +keyword_alias: keyword_sp | keyword_directly_assignable | keyword_directly_not_assignable ; +/* Keyword that we allow for identifiers (except SP labels) */ +keyword: keyword_alias | WINDOW_SYM; + /* Keywords that we allow in Oracle-style direct assignments: xxx := 10;