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.
- The grammar erroneously accepts these weird query:
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:
- Introduce a new class:
- 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:
- 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.