[MDEV-32220] sql_yacc.yy: unify the drop_routine rule Created: 2023-09-21  Updated: 2023-09-21  Resolved: 2023-09-21

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

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

Issue Links:
Blocks
blocks MDEV-32101 CREATE PACKAGE [BODY] for sql_mode=DE... Closed

 Description   

The drop_routine has two copies in sql_yacc.yy:

  • for sql_mode=DEFAULT
  • for sql_mode=ORACLE

drop_routine:
          DROP FUNCTION_SYM opt_if_exists ident '.' ident
          {
            if (Lex->stmt_drop_function($3, $4, $6))
              MYSQL_YYABORT;
          }
        | DROP FUNCTION_SYM opt_if_exists ident
          {
            if (Lex->stmt_drop_function($3, $4))
              MYSQL_YYABORT;
          }
        | DROP PROCEDURE_SYM opt_if_exists sp_name
          {
            if (Lex->stmt_drop_procedure($3, $4))
              MYSQL_YYABORT;
          }
        ;

drop_routine:
          DROP FUNCTION_SYM opt_if_exists ident '.' ident
          {
            if (Lex->stmt_drop_function($3, $4, $6))
              MYSQL_YYABORT;
          }
        | DROP FUNCTION_SYM opt_if_exists ident
          {
            if (Lex->stmt_drop_function($3, $4))
              MYSQL_YYABORT;
          }
        | DROP PROCEDURE_SYM opt_if_exists sp_name
          {
            if (Lex->stmt_drop_procedure($3, $4))
              MYSQL_YYABORT;
          }
        | DROP PACKAGE_ORACLE_SYM opt_if_exists sp_name
          {
            LEX *lex= Lex;
            lex->set_command(SQLCOM_DROP_PACKAGE, $3);
            if (unlikely(lex->sphead))
              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE"));
            lex->spname= $4;
          }
        | DROP PACKAGE_ORACLE_SYM BODY_ORACLE_SYM opt_if_exists sp_name
          {
            LEX *lex= Lex;
            lex->set_command(SQLCOM_DROP_PACKAGE_BODY, $4);
            if (unlikely(lex->sphead))
              my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PACKAGE BODY"));
            lex->spname= $5;
          }
        ;

It's not necessary two have two copies. The grammar can be unified to a simple rule used for both sql_mode=DEFAULT and sql_mode=ORACLE:

drop_routine:
          DROP sp_handler opt_if_exists ident '.' ident
          {
            if (Lex->stmt_drop_routine($2, $3, $4, $6))
              MYSQL_YYABORT;
          }
        | DROP sp_handler opt_if_exists ident
          {
            if (Lex->stmt_drop_routine($2, $3, Lex_ident_sys(), $4))
              MYSQL_YYABORT;
          }
        ;

where LEX::stmt_drop_routine() is a new method in LEX replacing these three methods:

  bool stmt_drop_function(const DDL_options_st &options,
                          const Lex_ident_sys_st &db,
                          const Lex_ident_sys_st &name);
 
  bool stmt_drop_function(const DDL_options_st &options,
                          const Lex_ident_sys_st &name);
 
  bool stmt_drop_procedure(const DDL_options_st &options,
                           sp_name *name);

Unification can done with help of a new method in Sp_handler:

virtual enum_sql_command sqlcom_drop() const= 0;

which will have the following overrides for Sp_handler descendants:

  enum_sql_command sqlcom_drop() const { return SQLCOM_DROP_PROCEDURE; }
  enum_sql_command sqlcom_drop() const { return SQLCOM_DROP_FUNCTION; }
  enum_sql_command sqlcom_drop() const { return SQLCOM_DROP_PACKAGE; }
  enum_sql_command sqlcom_drop() const { return SQLCOM_DROP_PACKAGE_BODY; }


Generated at Thu Feb 08 10:29:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.