Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-10142 PL/SQL parser
  3. MDEV-13197

Parser refactoring for CREATE VIEW,TRIGGER,SP,UDF,EVENT

Details

    • 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

    Description

      This task is intended to simplify the work for CREATE PACKAGE (see MDEV-10591), as well as to fix minor known problems in the underlying parser grammar.

      There are a few difficulties in the grammar for CREATE for VIEW, TRIGGER, EVENT, PROCEDURE, FUNCTION.

      • The grammar for the mentioned objects is implemented with help of the rule view_or_trigger_or_sp_or_event. The grammar for all other object types is implemented directly in the create: rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.
      • We'll add CREATE PACKAGE soon. It will require the DEFINER clause. In the current grammar, it will have to go to view_or_trigger_or_sp_or_event again, and make the things even more complex.
      • LEX::create_view_mode, LEX::create_view_algorithm, LEX::create_view_suid are initialized for all objects described in view_or_trigger_or_sp_or_event. For non-VIEW objects this initialization is redundant.

                | create_or_replace
                  {
                    Lex->create_info.set($1);
                    Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                              VIEW_CREATE_NEW);
                    Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                    Lex->create_view_suid= TRUE;
                  }
                  view_or_trigger_or_sp_or_event { }
        

      • The grammar erroneously accepts these weird query:

        ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
        

        It's really senseless to ALTER something that NOT EXISTS.
        The IF NOT EXISTS clause is accepted because both CREATE VIEW and ALTER VIEW grammar reuses the view_tail rule.

      Under terms of this task we'll do the following:

      • For stricter data type control: introduce a new enum instead of pre-processor constants:

      enum enum_view_suid
      {
        VIEW_SUID_INVOKER= 0,
        VIEW_SUID_DEFINER= 1,
        VIEW_SUID_DEFAULT= 2
      };
      

      • Introduce a new class:

      class Create_view_info: public Sql_alloc
      {
      public:
        LEX_CSTRING select;              // The SELECT statement of CREATE VIEW
        enum enum_view_create_mode mode;
        uint16 algorithm;
        uint8 check;
        enum enum_view_suid suid;
        Create_view_info(enum_view_create_mode mode_arg,
                         uint16 algorithm_arg,
                         enum_view_suid suid_arg)
         :select(null_clex_str),
          mode(mode_arg),
          algorithm(algorithm_arg),
          check(VIEW_CHECK_NONE),  
          suid(suid_arg)
        { }
      }; 
      

      • Remove the same members from LEX and add a pointer to Create_view_info instead. Create_view_info will be allocated on THD memory root only for CREATE VIEW or ALTER VIEW queries.
      • Reduce the amount of duplicate C++ code used in .yy files by adding new methods in LEX:

        bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                            Table_ident *table_ident);
        bool add_create_view(THD *thd, DDL_options_st ddl,
                             uint16 algorithm, enum_view_suid suid,
                             Table_ident *table_ident);
      

      • In sql_yacc.yy: remove grammar rules view_or_trigger_or_sp_or_event, definer_tail, no_definer_tail, view_tail
      • In sql_yacc.yy: add new grammar branches directly into the create: rules, for VIEW, TRIGGER, PROCEDURE, FUNCTION, EVENT.
        Note, when we add the CREATE PACKAGE statement later (see MDEV-10591), it will also be added directly to create:, together with its optional DEFINER clause.
      • In sql_yacc.yy: fix the rules view_algorithm, view_suid, view_check_options to return values in $$, instead of setting thd->lex members directly. This is needed to pass these values to the new methods LEX::add_alter_view() and LEX::add_create_view().
      • Do corresponding changes in sql_yacc_ora.yy.

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            bar Alexander Barkov made changes -
            Description There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            bar Alexander Barkov made changes -
            Description There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            This task is intended to simplify the work for {{CREATE PACKAGE}} (see MDEV-10591), as well as to fix minor known problems.

            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            bar Alexander Barkov made changes -
            Description This task is intended to simplify the work for {{CREATE PACKAGE}} (see MDEV-10591), as well as to fix minor known problems.

            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            This task is intended to simplify the work for {{CREATE PACKAGE}} (see MDEV-10591), as well as to fix minor known problems in the underlying parser grammar.

            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            bar Alexander Barkov made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            bar Alexander Barkov made changes -
            Assignee Alexander Barkov [ bar ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Description This task is intended to simplify the work for {{CREATE PACKAGE}} (see MDEV-10591), as well as to fix minor known problems in the underlying parser grammar.

            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591}}, it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            This task is intended to simplify the work for {{CREATE PACKAGE}} (see MDEV-10591), as well as to fix minor known problems in the underlying parser grammar.

            There are a few difficulties in the grammar for {{CREATE}} for {{VIEW}}, {{TRIGGER}}, {{EVENT}}, {{PROCEDURE}}, {{FUNCTION}}.

            - The grammar for the mentioned objects is implemented with help of the rule {{view_or_trigger_or_sp_or_event}}. The grammar for all other object types is implemented directly in the {{create:}} rule. This makes the grammar non-symmetric for various object types, which is hard to read and understand.

            - We'll add {{CREATE PACKAGE}} soon. It will require the {{DEFINER}} clause. In the current grammar, it will have to go to {{view_or_trigger_or_sp_or_event}} again, and make the things even more complex.

            - {{LEX::create_view_mode}}, {{LEX::create_view_algorithm}}, {{LEX::create_view_suid}} are initialized for all objects described in {{view_or_trigger_or_sp_or_event}}. For non-{{VIEW}} objects this initialization is redundant.
            {code:sql}
                    | create_or_replace
                      {
                        Lex->create_info.set($1);
                        Lex->create_view_mode= ($1.or_replace() ? VIEW_CREATE_OR_REPLACE :
                                                                  VIEW_CREATE_NEW);
                        Lex->create_view_algorithm= DTYPE_ALGORITHM_UNDEFINED;
                        Lex->create_view_suid= TRUE;
                      }
                      view_or_trigger_or_sp_or_event { }
            {code}

            - The grammar erroneously accepts these weird query:
            {code:sql}
            ALTER VIEW IF NOT EXISTS v1 AS SELECT 1;
            {code}
            It's really senseless to {{ALTER}} something that {{NOT EXISTS}}.
            The {{IF NOT EXISTS}} clause is accepted because both {{CREATE VIEW}} and {{ALTER VIEW}} grammar reuses the {{view_tail}} rule.


            Under terms of this task we'll do the following:

            - For stricter data type control: introduce a new {{enum}} instead of pre-processor constants:

            {code:sql}
            enum enum_view_suid
            {
              VIEW_SUID_INVOKER= 0,
              VIEW_SUID_DEFINER= 1,
              VIEW_SUID_DEFAULT= 2
            };
            {code}


            - Introduce a new class:

            {code:cpp}
            class Create_view_info: public Sql_alloc
            {
            public:
              LEX_CSTRING select; // The SELECT statement of CREATE VIEW
              enum enum_view_create_mode mode;
              uint16 algorithm;
              uint8 check;
              enum enum_view_suid suid;
              Create_view_info(enum_view_create_mode mode_arg,
                               uint16 algorithm_arg,
                               enum_view_suid suid_arg)
               :select(null_clex_str),
                mode(mode_arg),
                algorithm(algorithm_arg),
                check(VIEW_CHECK_NONE),
                suid(suid_arg)
              { }
            };
            {code}

            - Remove the same members from {{LEX}} and add a pointer to {{Create_view_info}} instead. {{Create_view_info}} will be allocated on {{THD}} memory root only for {{CREATE VIEW}} or {{ALTER VIEW}} queries.


            - Reduce the amount of duplicate {{C++}} code used in {{.yy}} files by adding new methods in {{LEX}}:

            {code:sql}
              bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid,
                                  Table_ident *table_ident);
              bool add_create_view(THD *thd, DDL_options_st ddl,
                                   uint16 algorithm, enum_view_suid suid,
                                   Table_ident *table_ident);
            {code}

            - In {{sql_yacc.yy}}: remove grammar rules {{view_or_trigger_or_sp_or_event}}, {{definer_tail}}, {{no_definer_tail}}, {{view_tail}}

            - In {{sql_yacc.yy}}: add new grammar branches directly into the {{create:}} rules, for {{VIEW}}, {{TRIGGER}}, {{PROCEDURE}}, {{FUNCTION}}, {{EVENT}}.
            Note, when we add the {{CREATE PACKAGE}} statement later (see MDEV-10591), it will also be added directly to {{create:}}, together with its optional {{DEFINER}} clause.

            - In {{sql_yacc.yy}}: fix the rules {{view_algorithm}}, {{view_suid}}, {{view_check_options}} to return values in {{$$}}, instead of setting {{thd->lex}} members directly. This is needed to pass these values to the new methods {{LEX::add_alter_view()}} and {{LEX::add_create_view()}}.

            - Do corresponding changes in {{sql_yacc_ora.yy}}.
            bar Alexander Barkov made changes -
            Assignee Oleksandr Byelkin [ sanja ] Alexander Barkov [ bar ]
            bar Alexander Barkov made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            bar Alexander Barkov made changes -
            Fix Version/s 10.3.1 [ 22532 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            bar Alexander Barkov made changes -
            Labels refactoring
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 81408 ] MariaDB v4 [ 152396 ]

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.