[MDEV-19533] Add methods make() and append_uniq() to Row_definition_list Created: 2019-05-21  Updated: 2019-05-21  Resolved: 2019-05-21

Status: Closed
Project: MariaDB Server
Component/s: Parser
Fix Version/s: 10.4.6

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-12518 Unify sql_yacc.yy and sql_yacc_ora.yy Closed

 Description   

There is a duplicate code in sql_yacc.yy and sql_yacc_ora.yy related to ROW variable defintion:

row_field_name:
          ident // or ident_directly_assignable
          {
            if (unlikely(check_string_char_length(&$1, 0, NAME_CHAR_LEN,
                                                  system_charset_info, 1)))
              my_yyabort_error((ER_TOO_LONG_IDENT, MYF(0), $1.str));
            if (unlikely(!($$= new (thd->mem_root) Spvar_definition())))
              MYSQL_YYABORT;
            Lex->init_last_field($$, &$1, thd->variables.collation_database);
          }
        ;
 
row_field_definition_list:
          row_field_definition
          {
            if (unlikely(!($$= new (thd->mem_root) Row_definition_list())) ||
                unlikely($$->push_back($1, thd->mem_root)))
              MYSQL_YYABORT;
          }
        | row_field_definition_list ',' row_field_definition
          {
            uint unused;
            if (unlikely($1->find_row_field_by_name(&$3->field_name, &unused)))
              my_yyabort_error((ER_DUP_FIELDNAME, MYF(0), $3->field_name.str));
            $$= $1;
            if (unlikely($$->push_back($3, thd->mem_root)))
              MYSQL_YYABORT;
          }
        ;

There is a difference though:

  • in sql_yacc.yy row_field_name is defined as ident
  • in sql_yacc_ora.yy row_field_name is defined as ident_directly_assignable

In order to join the two *.yy files easier, let's move the C++ code into new Row_definition_list methods and simplify the grammar as follows:

row_field_name:
          ident  // or ident_directly_assignable
          {
            if (!($$= Lex->row_field_name(thd, $1)))
              MYSQL_YYABORT;
          }
        ;
 
row_field_definition_list:
          row_field_definition
          {
            if (!($$= Row_definition_list::make(thd->mem_root, $1)))
              MYSQL_YYABORT;
          }
        | row_field_definition_list ',' row_field_definition
          {
            if (($$= $1)->append_uniq(thd->mem_root, $3))
              MYSQL_YYABORT;
          }
        ;


Generated at Thu Feb 08 08:52:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.