| 912 | |
| 913 | |
| 914 | LEX* sp_lex_instr::parse_expr(THD *thd, sp_head *sp, LEX *sp_instr_lex) |
| 915 | { |
| 916 | sql_query_cache.free(); |
| 917 | get_query(&sql_query_cache); |
| 918 | |
| 919 | if (sql_query_cache.length() == 0) |
| 920 | { |
| 921 | /** |
| 922 | The instruction has returned zero-length query string. That means, the |
| 923 | re-preparation of the instruction is not possible. We should not come |
| 924 | here in the normal case. |
| 925 | */ |
| 926 | assert(false); |
| 927 | my_error(ER_UNKNOWN_ERROR, MYF(0)); |
| 928 | return nullptr; |
| 929 | } |
| 930 | |
| 931 | /* |
| 932 | Remember a pointer to the next list of Item_trigger_field objects. |
| 933 | The current list of Item_trigger_field objects is cleared up in the |
| 934 | method cleanup_before_parsing(). |
| 935 | */ |
| 936 | SQL_I_List<Item_trigger_field> *saved_ptr_to_next_trg_items_list= nullptr; |
| 937 | |
| 938 | if (m_cur_trigger_stmt_items.elements) |
| 939 | saved_ptr_to_next_trg_items_list= |
| 940 | m_cur_trigger_stmt_items.first->next_trig_field_list; |
| 941 | |
| 942 | /* |
| 943 | Clean up items owned by this SP instruction except instances of Item_param. |
| 944 | `sp_statement_param_values` stores instances of the class Item_param |
| 945 | associated with the SP instruction's statement before the statement |
| 946 | has been re-parsed. |
| 947 | */ |
| 948 | List<Item_param> sp_statement_param_values= |
| 949 | cleanup_before_parsing(sp->m_handler->type()); |
| 950 | DBUG_ASSERT(mem_root != thd->mem_root); |
| 951 | /* |
| 952 | Back up the current free_list pointer and reset it to nullptr. |
| 953 | Set thd->mem_root pointing to a mem_root of SP instruction being re-parsed. |
| 954 | In that way any items created on parsing a statement of the current |
| 955 | instruction is allocated on SP instruction's mem_root and placed on its own |
| 956 | free_list that later assigned to the current sp_instr. We use the separate |
| 957 | free list for every instruction since at least at one place in the source |
| 958 | code (the function subst_spvars() to be accurate) we iterate along the |
| 959 | list sp_instr->free_list on executing of every SP instruction. |
| 960 | */ |
| 961 | Query_arena backup; |
| 962 | /* |
| 963 | A statement of SP instruction is going to be re-parsed, so reset |
| 964 | SP arena's state to STMT_INITIALIZED_FOR_SP as its initial state. |
| 965 | */ |
| 966 | state= STMT_INITIALIZED_FOR_SP; |
| 967 | |
| 968 | /* |
| 969 | First, set up a mem_root for the statement is going to re-compile. |
| 970 | */ |
| 971 | bool mem_root_allocated; |
no test coverage detected