-
Roy Lyseng authored
The problem is caused because a DO statement is not following the same handling procedure as a regular DML statement. Among other things, we open and lock tables in the same operation, whereas for regular DML statements, we open tables first, then resolve the statement, then lock the statement. For DO statements containing more than one expression, in particular those with subqueries, it is a big problem that we do not follow the same phases as for regular DML statements. This particular problem is caused because closing a DO statement is irregular. The problem is solved by refactoring DO statement handling to execute it like a SELECT statement. Thus, the following statement: DO expr1, expr2, ... exprN; is executed as SELECT expr1, expr2, ... exprN FROM DUAL INTO /dev/null; Instead of generating a list of expressions and evaluating them one by one, we generate a SELECT statement where the expressions are each evaluated exactly once. The difference compared to a regular SELECT statement is that a specific Query_result object that does not send back any results are generated. There is one semantic change in this patch: DO statements do not normally cause errors; they are instead converted to warnings. In this patch, errors are generated as for regular SELECT statements and returned to the client. Because of this, a few test results have been changed to report errors. Summary of changes: - The function Item::evaluate() that evaluates an Item tree with type as given by field_type() is implemented. - A new constructor for parse tree class PT_select_part2 is called when parsing a DO statement. - PT_select constructor now takes an sql_command argument (for distinguishing between SELECT and DO). - Preparing a DO statement is handled by mysql_test_select(), the same function as used for preparing SELECT. - mysql_do() now creates a Query result subclass object and calls handle_query(). - The subclass Query_result_do has the following important functions: # ::send_data() calls Item::evaluate() but does not send any values. # ::send_eof() calls ::my_ok() in case of success in execution. # ::send_result_set_metadata() does nothing.
Roy Lyseng authoredThe problem is caused because a DO statement is not following the same handling procedure as a regular DML statement. Among other things, we open and lock tables in the same operation, whereas for regular DML statements, we open tables first, then resolve the statement, then lock the statement. For DO statements containing more than one expression, in particular those with subqueries, it is a big problem that we do not follow the same phases as for regular DML statements. This particular problem is caused because closing a DO statement is irregular. The problem is solved by refactoring DO statement handling to execute it like a SELECT statement. Thus, the following statement: DO expr1, expr2, ... exprN; is executed as SELECT expr1, expr2, ... exprN FROM DUAL INTO /dev/null; Instead of generating a list of expressions and evaluating them one by one, we generate a SELECT statement where the expressions are each evaluated exactly once. The difference compared to a regular SELECT statement is that a specific Query_result object that does not send back any results are generated. There is one semantic change in this patch: DO statements do not normally cause errors; they are instead converted to warnings. In this patch, errors are generated as for regular SELECT statements and returned to the client. Because of this, a few test results have been changed to report errors. Summary of changes: - The function Item::evaluate() that evaluates an Item tree with type as given by field_type() is implemented. - A new constructor for parse tree class PT_select_part2 is called when parsing a DO statement. - PT_select constructor now takes an sql_command argument (for distinguishing between SELECT and DO). - Preparing a DO statement is handled by mysql_test_select(), the same function as used for preparing SELECT. - mysql_do() now creates a Query result subclass object and calls handle_query(). - The subclass Query_result_do has the following important functions: # ::send_data() calls Item::evaluate() but does not send any values. # ::send_eof() calls ::my_ok() in case of success in execution. # ::send_result_set_metadata() does nothing.
Loading