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 a 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 a 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 the instructions statement is not a valid SQL statement. Wrapping such text into 'SELECT ( )' produces a correct operator from SQL syntax point of view.
Showing
This diff is collapsed.
Please register or sign in to comment