maria:10.11-MDEV-5816

Last commit made on 2022-09-01
Get this branch:
git clone -b 10.11-MDEV-5816 https://git.launchpad.net/maria

Branch merges

Branch information

Name:
10.11-MDEV-5816
Repository:
lp:maria

Recent commits

dfb138c... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

Follow-up patch that fixes existing mtr tests.

7fc2028... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

Added re-parsing of failed statements inside a stored routine.

General idea of the patch is to install an instance of the class
Reprepare_observer before executing a next SP instruction and
re-parse a statement of this SP instruction in case of
its execution failure.

To implement the described approach the class sp_lex_keeper
has been extended with the method validate_lex_and_exec_core()
that is just a wrapper around the method reset_lex_and_exec_core()
with additional setting/resetting an instance of the class
Reprepare_observer on each iteration of SP instruction
execution.

If reset_lex_and_exec_core() returns error and an instance
of the class Reprepare_observer is installed before running
an SP instruction then a number of attempts to re-run the SP
instruction is checked against a max. limit and in case it doesn't
reach the limit a statement for the failed SP instruction is re-parsed.

Re-parsing of a statement for the failed SP instruction is implemented
by the new method sp_le_inst::parse_expr() that prepends
an SP instruction's statement with the clause 'SELECT' and parse it.
Own SP instruction MEM_ROOT and a separate free_list is used for
parsing of a SP statement. On successful re-parsing of SP instruction's
statement the virtual methods adjust_sql_command() and
on_after_expr_parsing() of the class sp_lex_instr is called
to update the SP instruction state with a new data created
on parsing the statement.

Few words about reason for prepending a SP instruction's statement
with the clause 'SELECT' - this is required step to produce a valid
SQL statement, since for some SP instructions, such as SET var=func(),
the instructions statement (in the above case it is the text 'var=func()')
is not a valid SQL statement. Wrapping such text inside 'SELECT ( )'
produces a correct operator from SQL syntax point of view.

4681749... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

For those SP instructions that need to get access to LEX object on execution,
added storing of their original sql expressions inside classes derived
from the class sp_lex_instr.

Stored sql expression is returned by the abstract method
  sp_lex_instr::get_expr_query
redefined in derived classes.

Since an expression constituting a SP instruction could be non valid
SQL statement in general case (not parseable statement), the virtual method
sp_lex_instr::get_query() has been introduced to return a valid string
for a statement that corresponds to the given instruction.

474c79f... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch introducing the class sp_lex_instr
that encapsulates access to an instance of the class sp_lex_keeper.
Every SP instruction that need to get access to a LEX object on its
processing should inherit this class and implement two abstract methods:
  is_invalid(),
  invalidate().

These methods will be used in subsequent patches to implement recompilation of
SP instructions on failure.

Currently, the following instructions are derived from the class sp_lex_instr:
  sp_instr_stmt,
  sp_instr_set,
  sp_instr_set_trigger_field,
  sp_instr_jump_if_not,
  sp_instr_freturn,
  sp_instr_cpush,
  sp_instr_cursor_copy_struct,
  sp_instr_set_case_expr

Additionally, this patch converts the class sp_instr_opt_meta
to base abstract class (that is, not inherited from the class
sp_instr). Since this class originally was designed to provide a way
for opimizer to update a destination address for jump SP-instructions,
the only useful method at interface of this class is set_destination
and therefore inheritance from the class sp_instr is meaningless.

Every jump SP instruction now must be inhereted directly from
the class sp_instr_opt_meta and additionally from either the class
sp_lex_instr or sp_instr depending on whether this SP instruction
need to get access to a LEX object or not.

Moreover, the class sp_cursor doesn't own a data member of
the class sp_lex_keeper any more. Instead, the virtual method
get_lex_keeper() has been added to the class sp_cursor() that
returns nullptr and this method is overridden in the derived class
sp_instr_cpush to provide a pointer to a real instance of
the class sp_lex_keeper. Doing this way we exclude duplication
of a data member of the type sp_lex_keeper at the class sp_instr_cpush
since it is derived both from sp_lex_instr and sp_cursor, and sp_lex_instr
already encapsulates a data member of the class sp_lex_keeper.

32c348d... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to change a signature of the virtual
method opt_move() in the base class sp_instr and its derived classes.
The parameterized type of the instuctions list returned in the second
argument is changed from sp_instr to sp_instr_opt_meta since only
jump instructions are placed in this list on returning from
the method call.

30cd2c2... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to move the data member
LEX::trg_table_fields to the class sp_head and rename it as
m_trg_table_fields.

This data member is used for handling OLD/NEW pseudo-rows inside
a trigger body and in order to be able to reparse a trigger body
this must be moved from the struct LEX to the class sp_head.

6d7fe24... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to remove the data member
sp_head::m_trg_table_fields and some methods that use it but is not called
anywhere in the source code.

The commit 5f1f2fc0e443f098af24d21f7d1ec1a8166a4030 introduced the
data member sp_head::m_trg_table_fields and the method
Table_triggers_list::is_fields_updated_in_trigger that used this data member.

The method Table_triggers_list::is_fields_updated_in_trigger() is invoked
by the method partition_info::can_prune_insert() also introduced by
the same commit 5f1f2fc0e443f098af24d21f7d1ec1a8166a4030

But the method partition_info::can_prune_insert() is not called anywhere
in the code. Later, the aforementioned methods were removed from
the source code but the data member sp_head::m_trg_table_fields wasn't.
So, remove the data member sp_head::m_trg_table_fields and declaration of
the method is_fields_updated_in_trigger() for purpose of code cleaning up.

0a87fa5... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to move the sp_instr class and classes derived
from it into the files sp_instr.cc/sp_instr.h

Additionally,
  * all occurrences of macroses NULL, FALSE, TRUE have been replaced
    with the corresponding C++ keywords nullptr, false, true.
  * the keyword 'override' has been added in and the keyword 'virtual' removed
    from signatures of every virtual method implemented in classes derived
    from the base class sp_instr.
  * trivial destructors like
     virtual ~sp_instr_stmt() {}
    have been removed for every class derived from the base class sp_instr
    since they are meaningless.
  * added the keyword 'final' into declaration of the class sp_lex_keeper
    since this class shouldn't have a derived class by design.
  * made the function cmp_rqp_locations as static since it is not called
    outside the file sp_instr.cc.
  * moved the function subst_spvars() into the file sp_instr.cc since this
    function is used only by the class sp_instr_stmt that is located
    in the file sp_instr.cc.

ecead40... by Dmitry Shulga <email address hidden>

MDEV-5816: Stored programs: validation of stored program statements

This is the prerequisite patch to make interface of the class
Reprepare_observer more like the one used by MySQL.

This patch adds the method can_retry() to the class Reprepare_observer
that returns true in case max. number of attempts to re-run a failing
statement is not yet reached. To control a number of re-run attempts
already done the data member m_attempt has been introduced. Doing this way,
we encapsulate activity with incrementing a counter on every statement
run and checking whether it reaches a limit or not inside implementation
of the class Reprepare_observer instead duplicating such boiler plate code
in every place where controlling for reaching a limit of max. number attempts
for re-running failed statement is required.

7253cdf... by Oleksandr "Sanja" Byelkin

Merge branch '10.10' into 10.11