MySQL 9.5.0
Source Code Documentation
sp_instr.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef _SP_INSTR_H_
25#define _SP_INSTR_H_
26
27#include <assert.h>
28#include <limits.h>
29#include <string.h>
30#include <sys/types.h>
31
32#include "field_types.h"
33#include "lex_string.h"
34#include "my_alloc.h"
35#include "my_compiler.h"
36
37#include "my_inttypes.h"
38#include "my_psi_config.h"
39#include "my_sys.h"
41#include "sql/sql_class.h" // Query_arena
42#include "sql/sql_const.h"
43#include "sql/sql_error.h"
44#include "sql/sql_lex.h"
45#include "sql/sql_list.h"
46#include "sql_string.h"
47#include "string_with_len.h"
48
49class Item;
50class Item_case_expr;
53class sp_handler;
54class sp_head;
55class sp_pcontext;
56class sp_variable;
57class Table_ref;
58
59///////////////////////////////////////////////////////////////////////////
60// This file contains SP-instruction classes.
61///////////////////////////////////////////////////////////////////////////
62
63/**
64 sp_printable defines an interface which should be implemented if a class wants
65 report some internal information about its state.
66*/
68 public:
69 virtual void print(const THD *thd, String *str) = 0;
70
71 virtual ~sp_printable() = default;
72};
73
74/**
75 An interface for all SP-instructions with destinations that
76 need to be updated by the SP-optimizer.
77*/
79 public:
80 /**
81 Update the destination; used by the SP-instruction-optimizer.
82
83 @param old_dest current (old) destination (instruction pointer).
84 @param new_dest new destination (instruction pointer).
85 */
86 virtual void set_destination(uint old_dest, uint new_dest) = 0;
87
88 /**
89 Update all instruction with the given label in the backpatch list to
90 the specified instruction pointer.
91
92 @param dest destination instruction pointer.
93 */
94 virtual void backpatch(uint dest) = 0;
95
96 virtual ~sp_branch_instr() = default;
97};
98
99///////////////////////////////////////////////////////////////////////////
100
101/**
102 Base class for every SP-instruction. sp_instr defines interface and provides
103 base implementation.
104*/
105class sp_instr : public sp_printable {
106 public:
107 sp_instr(uint ip, sp_pcontext *ctx)
108 : m_arena(nullptr, Query_arena::STMT_INITIALIZED_FOR_SP),
109 m_marked(false),
110 m_ip(ip),
111 m_parsing_ctx(ctx) {}
112
113 ~sp_instr() override { m_arena.free_items(); }
114
134 };
135
136 /**
137 Execute this instruction
138
139 @param thd Thread context
140 @param[out] nextp index of the next instruction to execute. (For most
141 instructions this will be the instruction following this
142 one). Note that this parameter is undefined in case of
143 errors, use get_cont_dest() to find the continuation
144 instruction for CONTINUE error handlers.
145
146 @return Error status.
147 */
148 virtual bool execute(THD *thd, uint *nextp) = 0;
149
150 /**
151 Get the instruction type of this instruction.
152 @return the instruction type
153 */
154 virtual enum Instr_type type() = 0;
155
156#ifdef HAVE_PSI_INTERFACE
158#endif
159
160 uint get_ip() const { return m_ip; }
161
162 /**
163 Get the continuation destination (instruction pointer for the CONTINUE
164 HANDLER) of this instruction.
165 @return the continuation destination
166 */
167 virtual uint get_cont_dest() const { return get_ip() + 1; }
168
170
171 protected:
172 /**
173 Clear diagnostics area.
174 @param thd Thread context
175 */
176 void clear_da(THD *thd) const {
179 }
180
181 ///////////////////////////////////////////////////////////////////////////
182 // The following operations are used solely for SP-code-optimizer.
183 ///////////////////////////////////////////////////////////////////////////
184
185 public:
186 /**
187 Mark this instruction as reachable during optimization and return the
188 index to the next instruction. Jump instruction will add their
189 destination to the leads list.
190 */
191 virtual uint opt_mark(sp_head *, List<sp_instr> *leads [[maybe_unused]]) {
192 m_marked = true;
193 return get_ip() + 1;
194 }
195
196 /**
197 Short-cut jumps to jumps during optimization. This is used by the
198 jump instructions' opt_mark() methods. 'start' is the starting point,
199 used to prevent the mark sweep from looping for ever. Return the
200 end destination.
201 */
202 virtual uint opt_shortcut_jump(sp_head *, sp_instr *start [[maybe_unused]]) {
203 return get_ip();
204 }
205
206 /**
207 Inform the instruction that it has been moved during optimization.
208 Most instructions will simply update its index, but jump instructions
209 must also take care of their destination pointers. Forward jumps get
210 pushed to the backpatch list 'ibp'.
211 */
212 virtual void opt_move(uint dst, List<sp_branch_instr> *ibp [[maybe_unused]]) {
213 m_ip = dst;
214 }
215
216 bool opt_is_marked() const { return m_marked; }
217
219 return nullptr;
220 }
221
223
224 protected:
225 /// Show if this instruction is reachable within the SP
226 /// (used by SP-optimizer).
228
229 /// Instruction pointer.
230 uint m_ip;
231
232 /// Instruction parsing context.
234
235 private:
236 // Prevent use of copy constructor and assignment operator.
239};
240
241///////////////////////////////////////////////////////////////////////////
242
243/**
244 sp_lex_instr is a class providing the interface and base implementation
245 for SP-instructions, whose execution is based on expression evaluation.
246
247 sp_lex_instr keeps LEX-object to be able to evaluate the expression.
248
249 sp_lex_instr also provides possibility to re-parse the original query
250 string if for some reason the LEX-object is not valid any longer.
251*/
252class sp_lex_instr : public sp_instr {
253 public:
254 sp_lex_instr(uint ip, sp_pcontext *ctx, LEX *lex, bool is_lex_owner)
255 : sp_instr(ip, ctx),
256 m_lex(nullptr),
257 m_is_lex_owner(false),
258 m_first_execution(true),
261 set_lex(lex, is_lex_owner);
262 }
263
264 ~sp_lex_instr() override {
265 free_lex();
266 /*
267 If the instruction is reparsed, m_lex_mem_root was used to allocate
268 the items, then freeing the memroot, frees the items. Also free the
269 items allocated on heap as well.
270 */
272 }
273
274 /**
275 Make a few attempts to execute the instruction.
276
277 Basically, this operation does the following things:
278 - install Reprepare_observer to catch metadata changes (if any);
279 - calls reset_lex_and_exec_core() to execute the instruction;
280 - if the execution fails due to a change in metadata, re-parse the
281 instruction's SQL-statement and repeat execution.
282
283 @param thd Thread context.
284 @param[out] nextp Next instruction pointer
285 @param open_tables Flag to specify if the function should check read
286 access to tables in LEX's table list and open and
287 lock them (used in instructions which need to
288 calculate some expression and don't execute
289 complete statement).
290
291 @return Error status.
292 */
293 bool validate_lex_and_execute_core(THD *thd, uint *nextp, bool open_tables);
294
296 return &m_trig_field_list;
297 }
298
299 private:
300 /**
301 Prepare LEX and thread for execution of instruction, if requested open
302 and lock LEX's tables, execute instruction's core function, perform
303 cleanup afterwards.
304
305 @param thd thread context
306 @param [out] nextp next instruction pointer
307 @param open_tables if true then check read access to tables in LEX's table
308 list and open and lock them (used in instructions which
309 need to calculate some expression and don't execute
310 complete statement).
311
312 @note
313 We are not saving/restoring some parts of THD which may need this because
314 we do this once for whole routine execution in sp_head::execute().
315
316 @return Error status.
317 */
318 bool reset_lex_and_exec_core(THD *thd, uint *nextp, bool open_tables);
319
320 bool execute_expression(THD *thd, uint *nextp);
321
322 /**
323 Parse statement corresponding to this instruction and return a new LEX.
324
325 @param thd Thread context.
326 @param sp The stored program.
327
328 @return new LEX-object or NULL in case of failure.
329 */
330 LEX *parse_statement(THD *thd, sp_head *sp);
331
332 /**
333 Set LEX-object.
334
335 Previously assigned LEX-object (if any) will be properly cleaned up
336 and destroyed.
337
338 @param lex LEX-object to be used by this instance of sp_lex_instr.
339 @param is_lex_owner the flag specifying if this instance sp_lex_instr
340 owns (and thus deletes when needed) passed LEX-object.
341 */
342 void set_lex(LEX *lex, bool is_lex_owner);
343
344 /**
345 Cleanup and destroy assigned LEX-object if needed.
346 */
347 void free_lex();
348
349 public:
350 /////////////////////////////////////////////////////////////////////////
351 // sp_instr implementation.
352 /////////////////////////////////////////////////////////////////////////
353
354 bool execute(THD *thd, uint *nextp) override {
355 /*
356 SP instructions with expressions should clear DA before execution.
357 Note that sp_instr_stmt will override execute(), but it clears DA
358 during normal mysql_execute_command().
359 */
360 clear_da(thd);
361 return validate_lex_and_execute_core(thd, nextp, true);
362 }
363
364 enum Instr_type type() override = 0;
365
366 /////////////////////////////////////////////////////////////////////////
367 // sp_instr methods.
368 /////////////////////////////////////////////////////////////////////////
369
370 /**
371 Return the query string, which can be passed to the parser. I.e. the
372 operation should return a valid SQL-statement query string.
373
374 @param[out] sql_query SQL-statement query string.
375 */
376 virtual void get_query(String *sql_query) const;
377
378 const LEX *get_lex() { return m_lex; }
379
380 protected:
381 /////////////////////////////////////////////////////////////////////////
382 // Interface (virtual) methods.
383 /////////////////////////////////////////////////////////////////////////
384
385 /**
386 Execute core function of instruction after all preparations
387 (e.g. setting of proper LEX, saving part of the thread context).
388
389 @param thd Thread context.
390 @param [out] nextp next instruction pointer
391
392 @return Error flag.
393 */
394 virtual bool exec_core(THD *thd, uint *nextp) = 0;
395
396 /**
397 @retval false if the object (i.e. LEX-object) is valid and exec_core() can
398 be just called.
399
400 @retval true if the object is not valid any longer, exec_core() can not be
401 called. The original query string should be re-parsed and a new LEX-object
402 should be used.
403 */
404 virtual bool is_invalid() const = 0;
405
406 /**
407 Invalidate the object.
408 */
409 virtual void invalidate() = 0;
410
411 /**
412 Some expressions may be re-parsed as SELECT statements, but need to be
413 adjusted to another SQL command. This function facilitates that change.
414 */
415 virtual void adjust_sql_command(LEX *) {}
416
417 /**
418 @return the expression query string. This string can not be passed directly
419 to the parser as it is most likely not a valid SQL-statement.
420
421 @note as it can be seen in the get_query() implementation, get_expr_query()
422 might return EMPTY_CSTR. EMPTY_CSTR means that no query-expression is
423 available. That happens when class provides different implementation of
424 get_query(). Strictly speaking, this is a drawback of the current class
425 hierarchy.
426 */
427 virtual LEX_CSTRING get_expr_query() const { return EMPTY_CSTR; }
428
429 /**
430 Callback function which is called after the statement query string is
431 successfully parsed, and the thread context has not been switched to the
432 outer context. The thread context contains new LEX-object corresponding to
433 the parsed query string.
434
435 @param thd Thread context.
436
437 @return Error flag.
438 */
439 virtual bool on_after_expr_parsing(THD *thd [[maybe_unused]]) {
440 return false;
441 }
442
443 /**
444 Destroy items in the free list before re-parsing the statement query
445 string (and thus, creating new items).
446
447 @param thd Thread context.
448 */
449 virtual void cleanup_before_parsing(THD *thd);
450
451 /// LEX-object.
453
454 private:
455 /**
456 Mem-root for storing the LEX-tree during reparse. This
457 mem-root is freed when a reparse is triggered or the stored
458 routine is dropped.
459 */
461
462 /**
463 Indicates whether this sp_lex_instr instance is responsible for
464 LEX-object deletion.
465 */
467
468 /**
469 Indicates whether exec_core() has not been already called on the current
470 LEX-object.
471 */
473
474 /*****************************************************************************
475 Support for being able to execute this statement in two modes:
476 a) inside prelocked mode set by the calling procedure or its ancestor.
477 b) outside of prelocked mode, when this statement enters/leaves
478 prelocked mode itself.
479 *****************************************************************************/
480
481 /**
482 List of additional tables this statement needs to lock when it
483 enters/leaves prelocked mode on its own.
484 */
486
487 /**
488 The value m_lex->query_tables_own_last should be set to this when the
489 statement enters/leaves prelocked mode on its own.
490 */
492
493 /**
494 List of all the Item_trigger_field's of instruction.
495 */
497};
498
499///////////////////////////////////////////////////////////////////////////
500
501/**
502 sp_instr_stmt represents almost all conventional SQL-statements, which are
503 supported outside stored programs.
504
505 SET-statements, which deal with SP-variable or NEW/OLD trigger pseudo-rows are
506 not represented by this instruction.
507*/
509 public:
511 : sp_lex_instr(ip, lex->get_sp_current_parsing_ctx(), lex, true),
512 m_query(query),
513 m_valid(true) {}
514
515 /////////////////////////////////////////////////////////////////////////
516 // sp_instr implementation.
517 /////////////////////////////////////////////////////////////////////////
518
519 bool execute(THD *thd, uint *nextp) override;
520
521 enum Instr_type type() override { return Instr_type::INSTR_LEX_STMT; }
522
523 /////////////////////////////////////////////////////////////////////////
524 // sp_printable implementation.
525 /////////////////////////////////////////////////////////////////////////
526
527 void print(const THD *thd, String *str) override;
528
529 /////////////////////////////////////////////////////////////////////////
530 // sp_lex_instr implementation.
531 /////////////////////////////////////////////////////////////////////////
532
533 bool exec_core(THD *thd, uint *nextp) override;
534
535 bool is_invalid() const override { return !m_valid; }
536
537 void invalidate() override { m_valid = false; }
538
539 void get_query(String *sql_query) const override {
540 sql_query->append(m_query.str, m_query.length);
541 }
542
543 bool on_after_expr_parsing(THD *) override {
544 m_valid = true;
545 return false;
546 }
547
548 private:
549 /// Complete query of the SQL-statement.
551
552 /// Specify if the stored LEX-object is up-to-date.
554
555#ifdef HAVE_PSI_INTERFACE
556 public:
557 PSI_statement_info *get_psi_info() override { return &psi_info; }
558
560#endif
561};
562
563///////////////////////////////////////////////////////////////////////////
564
565/**
566 sp_instr_set represents SET-statements, which deal with SP-variables.
567*/
569 public:
570 sp_instr_set(uint ip, LEX *lex, uint offset, Item *value_item,
571 LEX_CSTRING value_query, bool is_lex_owner)
572 : sp_lex_instr(ip, lex->get_sp_current_parsing_ctx(), lex, is_lex_owner),
573 m_offset(offset),
574 m_value_item(value_item),
575 m_value_query(value_query) {}
576
577 /////////////////////////////////////////////////////////////////////////
578 // sp_printable implementation.
579 /////////////////////////////////////////////////////////////////////////
580
581 void print(const THD *thd, String *str) override;
582
583 /////////////////////////////////////////////////////////////////////////
584 // sp_instr implementation.
585 /////////////////////////////////////////////////////////////////////////
586
587 enum Instr_type type() override { return Instr_type::INSTR_LEX_SET; }
588
589 /////////////////////////////////////////////////////////////////////////
590 // sp_lex_instr implementation.
591 /////////////////////////////////////////////////////////////////////////
592
593 bool exec_core(THD *thd, uint *nextp) override;
594
595 bool is_invalid() const override { return m_value_item == nullptr; }
596
597 void invalidate() override { m_value_item = nullptr; }
598
599 bool on_after_expr_parsing(THD *thd) override {
601 assert(m_value_item != nullptr);
602
603 return false;
604 }
605
606 LEX_CSTRING get_expr_query() const override { return m_value_query; }
607
608 void adjust_sql_command(LEX *lex) override {
609 assert(lex->sql_command == SQLCOM_SELECT);
611 }
612
613 /////////////////////////////////////////////////////////////////////////
614 // sp_instr_set methods.
615 /////////////////////////////////////////////////////////////////////////
616
618
619 uint get_offset() { return m_offset; }
620
621 private:
622 /// Frame offset.
624
625 /// Value expression item of the SET-statement.
627
628 /// SQL-query corresponding to the value expression.
630
631#ifdef HAVE_PSI_INTERFACE
632 public:
634 PSI_statement_info *get_psi_info() override { return &psi_info; }
635#endif
636};
637
638///////////////////////////////////////////////////////////////////////////
639
640/**
641 sp_instr_set_trigger_field represents SET-statements, which deal with NEW/OLD
642 trigger pseudo-rows.
643*/
645 public:
646 sp_instr_set_trigger_field(uint ip, LEX *lex, LEX_CSTRING trigger_field_name,
647 Item_trigger_field *trigger_field,
648 Item *value_item, LEX_CSTRING value_query)
649 : sp_lex_instr(ip, lex->get_sp_current_parsing_ctx(), lex, true),
650 m_trigger_field_name(trigger_field_name),
651 m_trigger_field(trigger_field),
652 m_value_item(value_item),
653 m_value_query(value_query) {}
654
655 /////////////////////////////////////////////////////////////////////////
656 // sp_printable implementation.
657 /////////////////////////////////////////////////////////////////////////
658
659 void print(const THD *thd, String *str) override;
660
661 /////////////////////////////////////////////////////////////////////////
662 // sp_instr implementation.
663 /////////////////////////////////////////////////////////////////////////
664
665 enum Instr_type type() override {
666 return Instr_type::INSTR_LEX_SET_TRIGGER_FIELD;
667 }
668
669 /////////////////////////////////////////////////////////////////////////
670 // sp_lex_instr implementation.
671 /////////////////////////////////////////////////////////////////////////
672
673 bool exec_core(THD *thd, uint *nextp) override;
674
675 bool is_invalid() const override { return m_value_item == nullptr; }
676
677 void invalidate() override { m_value_item = nullptr; }
678
679 bool on_after_expr_parsing(THD *thd) override;
680
681 void cleanup_before_parsing(THD *thd) override;
682
683 LEX_CSTRING get_expr_query() const override { return m_value_query; }
684
685 private:
686 /// Trigger field name ("field_name" of the "NEW.field_name").
688
689 /// Item corresponding to the NEW/OLD trigger field.
691
692 /// Value expression item of the SET-statement.
694
695 /// SQL-query corresponding to the value expression.
697
698#ifdef HAVE_PSI_INTERFACE
699 public:
700 PSI_statement_info *get_psi_info() override { return &psi_info; }
701
703#endif
704};
705
706///////////////////////////////////////////////////////////////////////////
707
708/**
709 sp_instr_freturn represents RETURN statement in stored functions.
710*/
712 public:
713 sp_instr_freturn(uint ip, LEX *lex, Item *expr_item, LEX_CSTRING expr_query,
714 enum enum_field_types return_field_type)
715 : sp_lex_instr(ip, lex->get_sp_current_parsing_ctx(), lex, true),
716 m_expr_item(expr_item),
717 m_expr_query(expr_query),
718 m_return_field_type(return_field_type) {}
719
720 /////////////////////////////////////////////////////////////////////////
721 // sp_printable implementation.
722 /////////////////////////////////////////////////////////////////////////
723
724 void print(const THD *thd, String *str) override;
725
726 /////////////////////////////////////////////////////////////////////////
727 // sp_instr implementation.
728 /////////////////////////////////////////////////////////////////////////
729
730 uint opt_mark(sp_head *, List<sp_instr> *) override {
731 m_marked = true;
732 return UINT_MAX;
733 }
734
735 enum Instr_type type() override { return Instr_type::INSTR_LEX_FRETURN; }
736
737 /////////////////////////////////////////////////////////////////////////
738 // sp_lex_instr implementation.
739 /////////////////////////////////////////////////////////////////////////
740
741 bool exec_core(THD *thd, uint *nextp) override;
742
743 bool is_invalid() const override { return m_expr_item == nullptr; }
744
745 void invalidate() override {
746 // it's already deleted.
747 m_expr_item = nullptr;
748 }
749
750 bool on_after_expr_parsing(THD *thd) override {
752 assert(m_expr_item != nullptr);
753 return false;
754 }
755
756 LEX_CSTRING get_expr_query() const override { return m_expr_query; }
757
758 void adjust_sql_command(LEX *lex) override {
759 assert(lex->sql_command == SQLCOM_SELECT);
760 lex->sql_command = SQLCOM_END;
761 }
762
763 /////////////////////////////////////////////////////////////////////////
764 // sp_instr_freturn methods.
765 /////////////////////////////////////////////////////////////////////////
766
767 Item *get_expr_item() const { return m_expr_item; }
768
769 private:
770 /// RETURN-expression item.
772
773 /// SQL-query corresponding to the RETURN-expression.
775
776 /// RETURN-field type code.
778
779#ifdef HAVE_PSI_INTERFACE
780 public:
781 PSI_statement_info *get_psi_info() override { return &psi_info; }
782
784#endif
785};
786
787///////////////////////////////////////////////////////////////////////////
788
789/**
790 This is base class for all kinds of jump instructions.
791
792 @note this is the only class, we directly construct instances of, that has
793 subclasses. We also redefine sp_instr_jump behavior in those subclasses.
794
795 @todo later we will consider introducing a new class, which will be the base
796 for sp_instr_jump, sp_instr_set_case_expr and sp_instr_jump_case_when.
797 Something like sp_regular_branch_instr (similar to sp_lex_branch_instr).
798*/
799class sp_instr_jump : public sp_instr, public sp_branch_instr {
800 public:
802 : sp_instr(ip, ctx), m_dest(0), m_optdest(nullptr) {}
803
804 sp_instr_jump(uint ip, sp_pcontext *ctx, uint dest)
805 : sp_instr(ip, ctx), m_dest(dest), m_optdest(nullptr) {}
806
807 /////////////////////////////////////////////////////////////////////////
808 // sp_printable implementation.
809 /////////////////////////////////////////////////////////////////////////
810
811 void print(const THD *thd, String *str) override;
812
813 /////////////////////////////////////////////////////////////////////////
814 // sp_instr implementation.
815 /////////////////////////////////////////////////////////////////////////
816
817 bool execute(THD *, uint *nextp) override {
818 *nextp = m_dest;
819 return false;
820 }
821
822 enum Instr_type type() override { return Instr_type::INSTR_JUMP; }
823
824 uint opt_mark(sp_head *sp, List<sp_instr> *leads) override;
825
826 uint opt_shortcut_jump(sp_head *sp, sp_instr *start) override;
827
828 void opt_move(uint dst, List<sp_branch_instr> *ibp) override;
829
830 /////////////////////////////////////////////////////////////////////////
831 // sp_branch_instr implementation.
832 /////////////////////////////////////////////////////////////////////////
833
834 void set_destination(uint old_dest, uint new_dest) override {
835 if (m_dest == old_dest) m_dest = new_dest;
836 }
837
838 void backpatch(uint dest) override {
839 /* Calling backpatch twice is a logic flaw in jump resolution. */
840 assert(m_dest == 0);
841 m_dest = dest;
842 }
843
844 protected:
845 /// Where we will go.
846 uint m_dest;
847
848 // The following attribute is used by SP-optimizer.
850
851#ifdef HAVE_PSI_INTERFACE
852 public:
853 PSI_statement_info *get_psi_info() override { return &psi_info; }
854
856#endif
857};
858
859///////////////////////////////////////////////////////////////////////////
860
861/**
862 sp_lex_branch_instr is a base class for SP-instructions, which might perform
863 conditional jump depending on the value of an SQL-expression.
864*/
866 protected:
867 sp_lex_branch_instr(uint ip, sp_pcontext *ctx, LEX *lex, Item *expr_item,
868 LEX_CSTRING expr_query)
869 : sp_lex_instr(ip, ctx, lex, true),
870 m_dest(0),
871 m_cont_dest(0),
874 m_expr_item(expr_item),
875 m_expr_query(expr_query) {}
876
877 sp_lex_branch_instr(uint ip, sp_pcontext *ctx, LEX *lex, Item *expr_item,
878 LEX_CSTRING expr_query, uint dest)
879 : sp_lex_instr(ip, ctx, lex, true),
880 m_dest(dest),
881 m_cont_dest(0),
884 m_expr_item(expr_item),
885 m_expr_query(expr_query) {}
886
887 public:
888 void set_cont_dest(uint cont_dest) { m_cont_dest = cont_dest; }
889
890 /////////////////////////////////////////////////////////////////////////
891 // sp_instr implementation.
892 /////////////////////////////////////////////////////////////////////////
893
894 uint opt_mark(sp_head *sp, List<sp_instr> *leads) override;
895
896 void opt_move(uint dst, List<sp_branch_instr> *ibp) override;
897
898 uint get_cont_dest() const override { return m_cont_dest; }
899
900 enum Instr_type type() override = 0;
901
902 /////////////////////////////////////////////////////////////////////////
903 // sp_lex_instr implementation.
904 /////////////////////////////////////////////////////////////////////////
905
906 bool is_invalid() const override { return m_expr_item == nullptr; }
907
908 void invalidate() override {
909 m_expr_item = nullptr; /* it's already deleted. */
910 }
911
912 LEX_CSTRING get_expr_query() const override { return m_expr_query; }
913
914 /////////////////////////////////////////////////////////////////////////
915 // sp_branch_instr implementation.
916 /////////////////////////////////////////////////////////////////////////
917
918 void set_destination(uint old_dest, uint new_dest) override {
919 if (m_dest == old_dest) m_dest = new_dest;
920
921 if (m_cont_dest == old_dest) m_cont_dest = new_dest;
922 }
923
924 void backpatch(uint dest) override {
925 /* Calling backpatch twice is a logic flaw in jump resolution. */
926 assert(m_dest == 0);
927 m_dest = dest;
928 }
929
930 void adjust_sql_command(LEX *lex) override {
931 assert(lex->sql_command == SQLCOM_SELECT);
932 lex->sql_command = SQLCOM_END;
933 }
934
935 protected:
936 /// Where we will go.
937 uint m_dest;
938
939 /// Where continue handlers will go.
941
942 // The following attributes are used by SP-optimizer.
945
946 /// Expression item.
948
949 /// SQL-query corresponding to the expression.
951};
952
953///////////////////////////////////////////////////////////////////////////
954
955/**
956 sp_instr_jump_if_not implements SP-instruction, which does the jump if its
957 SQL-expression is false.
958*/
960 public:
961 sp_instr_jump_if_not(uint ip, LEX *lex, Item *expr_item,
962 LEX_CSTRING expr_query)
963 : sp_lex_branch_instr(ip, lex->get_sp_current_parsing_ctx(), lex,
964 expr_item, expr_query) {}
965
966 sp_instr_jump_if_not(uint ip, LEX *lex, Item *expr_item,
967 LEX_CSTRING expr_query, uint dest)
968 : sp_lex_branch_instr(ip, lex->get_sp_current_parsing_ctx(), lex,
969 expr_item, expr_query, dest) {}
970
971 /////////////////////////////////////////////////////////////////////////
972 // sp_printable implementation.
973 /////////////////////////////////////////////////////////////////////////
974
975 void print(const THD *thd, String *str) override;
976
977 /////////////////////////////////////////////////////////////////////////
978 // sp_instr implementation.
979 /////////////////////////////////////////////////////////////////////////
980
981 enum Instr_type type() override {
982 return Instr_type::INSTR_LEX_BRANCH_IF_NOT;
983 }
984
985 /////////////////////////////////////////////////////////////////////////
986 // sp_lex_instr implementation.
987 /////////////////////////////////////////////////////////////////////////
988
989 bool exec_core(THD *thd, uint *nextp) override;
990
991 bool on_after_expr_parsing(THD *thd) override {
993 assert(m_expr_item != nullptr);
994 return false;
995 }
996
997#ifdef HAVE_PSI_INTERFACE
998 public:
999 PSI_statement_info *get_psi_info() override { return &psi_info; }
1000
1002#endif
1003};
1004
1005///////////////////////////////////////////////////////////////////////////
1006// Instructions used for the "simple CASE" implementation.
1007///////////////////////////////////////////////////////////////////////////
1008
1009/**
1010 sp_instr_set_case_expr is used in the "simple CASE" implementation to evaluate
1011 and store the CASE-expression in the runtime context.
1012*/
1014 public:
1015 sp_instr_set_case_expr(uint ip, LEX *lex, uint case_expr_id,
1016 Item *case_expr_item, LEX_CSTRING case_expr_query)
1017 : sp_lex_branch_instr(ip, lex->get_sp_current_parsing_ctx(), lex,
1018 case_expr_item, case_expr_query),
1019 m_case_expr_id(case_expr_id) {}
1020
1021 /////////////////////////////////////////////////////////////////////////
1022 // sp_printable implementation.
1023 /////////////////////////////////////////////////////////////////////////
1024
1025 void print(const THD *thd, String *str) override;
1026
1027 /////////////////////////////////////////////////////////////////////////
1028 // sp_instr implementation.
1029 /////////////////////////////////////////////////////////////////////////
1030
1031 uint opt_mark(sp_head *sp, List<sp_instr> *leads) override;
1032
1033 void opt_move(uint dst, List<sp_branch_instr> *ibp) override;
1034
1035 enum Instr_type type() override {
1036 return Instr_type::INSTR_LEX_BRANCH_SET_CASE_EXPR;
1037 }
1038
1039 /////////////////////////////////////////////////////////////////////////
1040 // sp_branch_instr implementation.
1041 /////////////////////////////////////////////////////////////////////////
1042
1043 /*
1044 NOTE: set_destination() and backpatch() are overridden here just because the
1045 m_dest attribute is not used by this class, so there is no need to do
1046 anything about it.
1047
1048 @todo These operations probably should be left as they are (i.e. do not
1049 override them here). The m_dest attribute would be set and not used, but
1050 that should not be a big deal.
1051
1052 @todo This also indicates deficiency of the current SP-istruction class
1053 hierarchy.
1054 */
1055
1056 void set_destination(uint old_dest, uint new_dest) override {
1057 if (m_cont_dest == old_dest) m_cont_dest = new_dest;
1058 }
1059
1060 void backpatch(uint) override {}
1061
1062 /////////////////////////////////////////////////////////////////////////
1063 // sp_lex_instr implementation.
1064 /////////////////////////////////////////////////////////////////////////
1065
1066 bool exec_core(THD *thd, uint *nextp) override;
1067
1068 bool on_after_expr_parsing(THD *thd) override {
1070 assert(m_expr_item != nullptr);
1071 return false;
1072 }
1073
1074 private:
1075 /// Identifier (index) of the CASE-expression in the runtime context.
1077
1078#ifdef HAVE_PSI_INTERFACE
1079 public:
1081
1083#endif
1084};
1085
1086///////////////////////////////////////////////////////////////////////////
1087
1088/**
1089 sp_instr_jump_case_when instruction is used in the "simple CASE"
1090 implementation. It's a jump instruction with the following condition:
1091 (CASE-expression = WHEN-expression)
1092 CASE-expression is retrieved from sp_rcontext;
1093 WHEN-expression is kept by this instruction.
1094*/
1096 public:
1097 sp_instr_jump_case_when(uint ip, LEX *lex, int case_expr_id,
1098 Item *when_expr_item, LEX_CSTRING when_expr_query)
1099 : sp_lex_branch_instr(ip, lex->get_sp_current_parsing_ctx(), lex,
1100 when_expr_item, when_expr_query),
1101 m_case_expr_id(case_expr_id) {}
1102
1103 /////////////////////////////////////////////////////////////////////////
1104 // sp_printable implementation.
1105 /////////////////////////////////////////////////////////////////////////
1106
1107 void print(const THD *thd, String *str) override;
1108
1109 /////////////////////////////////////////////////////////////////////////
1110 // sp_instr implementation.
1111 /////////////////////////////////////////////////////////////////////////
1112
1113 enum Instr_type type() override {
1114 return Instr_type::INSTR_LEX_BRANCH_CASE_WHEN;
1115 }
1116
1117 /////////////////////////////////////////////////////////////////////////
1118 // sp_lex_instr implementation.
1119 /////////////////////////////////////////////////////////////////////////
1120
1121 bool exec_core(THD *thd, uint *nextp) override;
1122
1123 void invalidate() override {
1124 // Items should be already deleted in lex-keeper.
1125 m_case_expr_item = nullptr;
1126 m_eq_item = nullptr;
1127 m_expr_item = nullptr; // it's a WHEN-expression.
1128 }
1129
1130 /**
1131 Build CASE-expression item tree:
1132 Item_func_eq(case-expression, when-i-expression)
1133
1134 This function is used for the following form of CASE statement:
1135 CASE case-expression
1136 WHEN when-1-expression THEN ...
1137 WHEN when-2-expression THEN ...
1138 ...
1139 WHEN when-n-expression THEN ...
1140 END CASE
1141
1142 The thing is that after the parsing we have an item (item tree) for the
1143 case-expression and for each when-expression. Here we build jump
1144 conditions: expressions like (case-expression = when-i-expression).
1145
1146 @param thd Thread context.
1147
1148 @return Error flag.
1149 */
1150 bool on_after_expr_parsing(THD *thd) override;
1151
1152 private:
1153 /// Identifier (index) of the CASE-expression in the runtime context.
1155
1156 /// Item representing the CASE-expression.
1158
1159 /**
1160 Item corresponding to the main item of the jump-condition-expression:
1161 it's the equal function (=) in the (case-expression = when-i-expression)
1162 expression.
1163 */
1165
1166#ifdef HAVE_PSI_INTERFACE
1167 public:
1169
1171#endif
1172};
1173
1174///////////////////////////////////////////////////////////////////////////
1175// SQL-condition handler instructions.
1176///////////////////////////////////////////////////////////////////////////
1177
1179 public:
1181
1182 ~sp_instr_hpush_jump() override;
1183
1184 void add_condition(sp_condition_value *condition_value);
1185
1187
1188 /////////////////////////////////////////////////////////////////////////
1189 // sp_printable implementation.
1190 /////////////////////////////////////////////////////////////////////////
1191
1192 void print(const THD *thd, String *str) override;
1193
1194 /////////////////////////////////////////////////////////////////////////
1195 // sp_instr implementation.
1196 /////////////////////////////////////////////////////////////////////////
1197
1198 bool execute(THD *thd, uint *nextp) override;
1199
1200 enum Instr_type type() override {
1201 return Instr_type::INSTR_COND_HANDLER_PUSH_JUMP;
1202 }
1203
1204 uint opt_mark(sp_head *sp, List<sp_instr> *leads) override;
1205
1206 /** Override sp_instr_jump's shortcut; we stop here. */
1207 uint opt_shortcut_jump(sp_head *, sp_instr *) override { return get_ip(); }
1208
1209 /////////////////////////////////////////////////////////////////////////
1210 // sp_branch_instr implementation.
1211 /////////////////////////////////////////////////////////////////////////
1212
1213 void backpatch(uint dest) override {
1214 assert(!m_dest || !m_opt_hpop);
1215 if (!m_dest)
1216 m_dest = dest;
1217 else
1218 m_opt_hpop = dest;
1219 }
1220
1221 private:
1222 /// Handler.
1224
1225 /// hpop marking end of handler scope.
1227
1228 // This attribute is needed for SHOW PROCEDURE CODE only (i.e. it's needed in
1229 // debug version only). It's used in print().
1231
1232#ifdef HAVE_PSI_INTERFACE
1233 public:
1235
1237#endif
1238};
1239
1240///////////////////////////////////////////////////////////////////////////
1241
1242class sp_instr_hpop : public sp_instr {
1243 public:
1244 sp_instr_hpop(uint ip, sp_pcontext *ctx) : sp_instr(ip, ctx) {}
1245
1246 /////////////////////////////////////////////////////////////////////////
1247 // sp_printable implementation.
1248 /////////////////////////////////////////////////////////////////////////
1249
1250 void print(const THD *, String *str) override {
1251 str->append(STRING_WITH_LEN("hpop"));
1252 }
1253
1254 /////////////////////////////////////////////////////////////////////////
1255 // sp_instr implementation.
1256 /////////////////////////////////////////////////////////////////////////
1257
1258 bool execute(THD *thd, uint *nextp) override;
1259
1260 enum Instr_type type() override { return Instr_type::INSTR_HPOP; }
1261
1262#ifdef HAVE_PSI_INTERFACE
1263 public:
1265
1267#endif
1268};
1269
1270///////////////////////////////////////////////////////////////////////////
1271
1273 public:
1274 sp_instr_hreturn(uint ip, sp_pcontext *ctx);
1275
1276 /////////////////////////////////////////////////////////////////////////
1277 // sp_printable implementation.
1278 /////////////////////////////////////////////////////////////////////////
1279
1280 void print(const THD *thd, String *str) override;
1281
1282 /////////////////////////////////////////////////////////////////////////
1283 // sp_instr implementation.
1284 /////////////////////////////////////////////////////////////////////////
1285
1286 bool execute(THD *thd, uint *nextp) override;
1287
1288 enum Instr_type type() override {
1289 return Instr_type::INSTR_COND_HANDLER_RETURN;
1290 }
1291
1292 /** Override sp_instr_jump's shortcut; we stop here. */
1293 uint opt_shortcut_jump(sp_head *, sp_instr *) override { return get_ip(); }
1294
1295 uint opt_mark(sp_head *sp, List<sp_instr> *leads) override;
1296
1297 private:
1298 // This attribute is needed for SHOW PROCEDURE CODE only (i.e. it's needed in
1299 // debug version only). It's used in print().
1301
1302#ifdef HAVE_PSI_INTERFACE
1303 public:
1305
1307#endif
1308};
1309
1310///////////////////////////////////////////////////////////////////////////
1311// Cursor implementation.
1312///////////////////////////////////////////////////////////////////////////
1313
1314/**
1315 sp_instr_cpush corresponds to DECLARE CURSOR, implements DECLARE CURSOR and
1316 OPEN.
1317
1318 This is the most important instruction in cursor implementation. It is created
1319 and added to sp_head when DECLARE CURSOR is being parsed. The arena of this
1320 instruction contains LEX-object for the cursor's SELECT-statement.
1321
1322 This instruction is actually used to open the cursor.
1323
1324 execute() operation "implements" DECLARE CURSOR statement -- it merely pushes
1325 a new cursor object into the stack in sp_rcontext object.
1326
1327 exec_core() operation implements OPEN statement. It is important to implement
1328 OPEN statement in this instruction, because OPEN may lead to re-parsing of the
1329 SELECT-statement. So, the original Arena and parsing context must be used.
1330*/
1332 public:
1333 sp_instr_cpush(uint ip, sp_pcontext *ctx, LEX *cursor_lex,
1334 LEX_CSTRING cursor_query, int cursor_idx)
1335 : sp_lex_instr(ip, ctx, cursor_lex, true),
1336 m_cursor_query(cursor_query),
1337 m_valid(true),
1338 m_cursor_idx(cursor_idx) {
1339 /*
1340 Cursors cause queries to depend on external state, so they are
1341 noncacheable.
1342 */
1343 cursor_lex->safe_to_cache_query = false;
1344 }
1345
1346 /////////////////////////////////////////////////////////////////////////
1347 // sp_printable implementation.
1348 /////////////////////////////////////////////////////////////////////////
1349
1350 void print(const THD *thd, String *str) override;
1351
1352 /////////////////////////////////////////////////////////////////////////
1353 // sp_instr implementation.
1354 /////////////////////////////////////////////////////////////////////////
1355
1356 bool execute(THD *thd, uint *nextp) override;
1357
1358 enum Instr_type type() override { return Instr_type::INSTR_LEX_CPUSH; }
1359
1360 /////////////////////////////////////////////////////////////////////////
1361 // sp_lex_instr implementation.
1362 /////////////////////////////////////////////////////////////////////////
1363
1364 bool exec_core(THD *thd, uint *nextp) override;
1365
1366 bool is_invalid() const override { return !m_valid; }
1367
1368 void invalidate() override { m_valid = false; }
1369
1370 void get_query(String *sql_query) const override {
1372 }
1373
1374 bool on_after_expr_parsing(THD *) override {
1375 m_valid = true;
1376 return false;
1377 }
1378
1379 private:
1380 /// This attribute keeps the cursor SELECT statement.
1382
1383 /// Flag if the LEX-object of this instruction is valid or not.
1384 /// The LEX-object is not valid when metadata have changed.
1386
1387 /// Used to identify the cursor in the sp_rcontext.
1389
1390#ifdef HAVE_PSI_INTERFACE
1391 public:
1393
1395#endif
1396};
1397
1398///////////////////////////////////////////////////////////////////////////
1399
1400/**
1401 sp_instr_cpop instruction is added at the end of BEGIN..END block.
1402 It's used to remove declared cursors so that they are not visible any longer.
1403*/
1404class sp_instr_cpop : public sp_instr {
1405 public:
1406 sp_instr_cpop(uint ip, sp_pcontext *ctx, uint count)
1407 : sp_instr(ip, ctx), m_count(count) {}
1408
1409 /////////////////////////////////////////////////////////////////////////
1410 // sp_printable implementation.
1411 /////////////////////////////////////////////////////////////////////////
1412
1413 void print(const THD *thd, String *str) override;
1414
1415 /////////////////////////////////////////////////////////////////////////
1416 // sp_instr implementation.
1417 /////////////////////////////////////////////////////////////////////////
1418
1419 bool execute(THD *thd, uint *nextp) override;
1420
1421 enum Instr_type type() override { return Instr_type::INSTR_CPOP; }
1422
1423 private:
1425
1426#ifdef HAVE_PSI_INTERFACE
1427 public:
1429
1431#endif
1432};
1433
1434///////////////////////////////////////////////////////////////////////////
1435
1436/**
1437 sp_instr_copen represents OPEN statement (opens the cursor).
1438 However, the actual implementation is in sp_instr_cpush::exec_core().
1439*/
1440class sp_instr_copen : public sp_instr {
1441 public:
1442 sp_instr_copen(uint ip, sp_pcontext *ctx, int cursor_idx)
1443 : sp_instr(ip, ctx), m_cursor_idx(cursor_idx) {}
1444
1445 /////////////////////////////////////////////////////////////////////////
1446 // sp_printable implementation.
1447 /////////////////////////////////////////////////////////////////////////
1448
1449 void print(const THD *thd, String *str) override;
1450
1451 /////////////////////////////////////////////////////////////////////////
1452 // sp_instr implementation.
1453 /////////////////////////////////////////////////////////////////////////
1454
1455 bool execute(THD *thd, uint *nextp) override;
1456
1457 enum Instr_type type() override { return Instr_type::INSTR_COPEN; }
1458
1459 private:
1460 /// Used to identify the cursor in the sp_rcontext.
1462
1463#ifdef HAVE_PSI_INTERFACE
1464 public:
1466
1468#endif
1469};
1470
1471///////////////////////////////////////////////////////////////////////////
1472
1473/**
1474 The instruction corresponds to the CLOSE statement.
1475 It just forwards the close-call to the appropriate sp_cursor object in the
1476 sp_rcontext.
1477*/
1479 public:
1480 sp_instr_cclose(uint ip, sp_pcontext *ctx, int cursor_idx)
1481 : sp_instr(ip, ctx), m_cursor_idx(cursor_idx) {}
1482
1483 /////////////////////////////////////////////////////////////////////////
1484 // sp_printable implementation.
1485 /////////////////////////////////////////////////////////////////////////
1486
1487 void print(const THD *thd, String *str) override;
1488
1489 /////////////////////////////////////////////////////////////////////////
1490 // sp_instr implementation.
1491 /////////////////////////////////////////////////////////////////////////
1492
1493 bool execute(THD *thd, uint *nextp) override;
1494
1495 enum Instr_type type() override { return Instr_type::INSTR_CCLOSE; }
1496
1497 private:
1498 /// Used to identify the cursor in the sp_rcontext.
1500
1501#ifdef HAVE_PSI_INTERFACE
1502 public:
1504
1506#endif
1507};
1508
1509///////////////////////////////////////////////////////////////////////////
1510
1511/**
1512 The instruction corresponds to the FETCH statement.
1513 It just forwards the close-call to the appropriate sp_cursor object in the
1514 sp_rcontext.
1515*/
1517 public:
1518 sp_instr_cfetch(uint ip, sp_pcontext *ctx, int cursor_idx)
1519 : sp_instr(ip, ctx), m_cursor_idx(cursor_idx) {}
1520
1521 /////////////////////////////////////////////////////////////////////////
1522 // sp_printable implementation.
1523 /////////////////////////////////////////////////////////////////////////
1524
1525 void print(const THD *thd, String *str) override;
1526
1527 /////////////////////////////////////////////////////////////////////////
1528 // sp_instr implementation.
1529 /////////////////////////////////////////////////////////////////////////
1530
1531 bool execute(THD *thd, uint *nextp) override;
1532
1533 enum Instr_type type() override { return Instr_type::INSTR_CFETCH; }
1534
1535 void add_to_varlist(sp_variable *var) { m_varlist.push_back(var); }
1536
1537 private:
1538 /// List of SP-variables to store fetched values.
1540
1541 /// Used to identify the cursor in the sp_rcontext.
1543
1544#ifdef HAVE_PSI_INTERFACE
1545 public:
1547
1549#endif
1550};
1551
1552///////////////////////////////////////////////////////////////////////////
1553///////////////////////////////////////////////////////////////////////////
1554
1555/**
1556 sp_instr_error just throws an SQL-condition if the execution flow comes to it.
1557 It's used in the CASE implementation to perform runtime-check that the
1558 CASE-expression is handled by some WHEN/ELSE clause.
1559*/
1560class sp_instr_error : public sp_instr {
1561 public:
1562 sp_instr_error(uint ip, sp_pcontext *ctx, int errcode)
1563 : sp_instr(ip, ctx), m_errcode(errcode) {}
1564
1565 /////////////////////////////////////////////////////////////////////////
1566 // sp_printable implementation.
1567 /////////////////////////////////////////////////////////////////////////
1568
1569 void print(const THD *thd, String *str) override;
1570
1571 /////////////////////////////////////////////////////////////////////////
1572 // sp_instr implementation.
1573 /////////////////////////////////////////////////////////////////////////
1574
1575 bool execute(THD *, uint *nextp) override {
1576 my_error(m_errcode, MYF(0));
1577 *nextp = get_ip() + 1;
1578 return true;
1579 }
1580
1581 enum Instr_type type() override { return Instr_type::INSTR_ERROR; }
1582
1583 uint opt_mark(sp_head *, List<sp_instr> *) override {
1584 m_marked = true;
1585 return UINT_MAX;
1586 }
1587
1588 private:
1589 /// The error code, which should be raised by this instruction.
1591
1592#ifdef HAVE_PSI_INTERFACE
1593 public:
1595
1597#endif
1598};
1599
1600///////////////////////////////////////////////////////////////////////////
1601
1602#endif // _SP_INSTR_H_
static app_data_list nextp(app_data_list l)
Return next element in list of app_data.
Definition: app_data.cc:301
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
void reset_condition_info(THD *thd)
Reset the current condition information stored in the Diagnostics Area.
Definition: sql_error.cc:491
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:361
Definition: item.h:4082
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6798
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:928
Definition: sql_list.h:494
Definition: sql_class.h:348
void free_items()
Definition: sql_class.cc:2120
enum_sql_command sql_command
SQL command for this statement.
Definition: sql_lex.h:2773
Simple intrusive linked list.
Definition: sql_list.h:48
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
bool append(const String &s)
Definition: sql_string.cc:419
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
LEX * lex
Definition: sql_class.h:1002
Diagnostics_area * get_stmt_da()
Returns first Diagnostics Area for the current statement.
Definition: sql_class.h:3340
Definition: table.h:2933
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4741
An interface for all SP-instructions with destinations that need to be updated by the SP-optimizer.
Definition: sp_instr.h:78
virtual void backpatch(uint dest)=0
Update all instruction with the given label in the backpatch list to the specified instruction pointe...
virtual ~sp_branch_instr()=default
virtual void set_destination(uint old_dest, uint new_dest)=0
Update the destination; used by the SP-instruction-optimizer.
This class represents condition-value term in DECLARE CONDITION or DECLARE HANDLER statements.
Definition: sp_pcontext.h:133
This class represents 'DECLARE HANDLER' statement.
Definition: sp_pcontext.h:193
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
The instruction corresponds to the CLOSE statement.
Definition: sp_instr.h:1478
static PSI_statement_info psi_info
Definition: sp_instr.h:1505
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1495
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1765
sp_instr_cclose(uint ip, sp_pcontext *ctx, int cursor_idx)
Definition: sp_instr.h:1480
int m_cursor_idx
Used to identify the cursor in the sp_rcontext.
Definition: sp_instr.h:1499
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1776
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1503
The instruction corresponds to the FETCH statement.
Definition: sp_instr.h:1516
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1533
List< sp_variable > m_varlist
List of SP-variables to store fetched values.
Definition: sp_instr.h:1539
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1546
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1802
sp_instr_cfetch(uint ip, sp_pcontext *ctx, int cursor_idx)
Definition: sp_instr.h:1518
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1813
static PSI_statement_info psi_info
Definition: sp_instr.h:1548
void add_to_varlist(sp_variable *var)
Definition: sp_instr.h:1535
int m_cursor_idx
Used to identify the cursor in the sp_rcontext.
Definition: sp_instr.h:1542
sp_instr_copen represents OPEN statement (opens the cursor).
Definition: sp_instr.h:1440
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1698
sp_instr_copen(uint ip, sp_pcontext *ctx, int cursor_idx)
Definition: sp_instr.h:1442
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1739
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1457
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1465
static PSI_statement_info psi_info
Definition: sp_instr.h:1467
int m_cursor_idx
Used to identify the cursor in the sp_rcontext.
Definition: sp_instr.h:1461
sp_instr_cpop instruction is added at the end of BEGIN..END block.
Definition: sp_instr.h:1404
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1421
uint m_count
Definition: sp_instr.h:1424
static PSI_statement_info psi_info
Definition: sp_instr.h:1430
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1428
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1681
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1674
sp_instr_cpop(uint ip, sp_pcontext *ctx, uint count)
Definition: sp_instr.h:1406
sp_instr_cpush corresponds to DECLARE CURSOR, implements DECLARE CURSOR and OPEN.
Definition: sp_instr.h:1331
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1358
bool is_invalid() const override
Definition: sp_instr.h:1366
bool on_after_expr_parsing(THD *) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:1374
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:1368
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1392
static PSI_statement_info psi_info
Definition: sp_instr.h:1394
int m_cursor_idx
Used to identify the cursor in the sp_rcontext.
Definition: sp_instr.h:1388
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1629
void get_query(String *sql_query) const override
Return the query string, which can be passed to the parser.
Definition: sp_instr.h:1370
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1646
LEX_CSTRING m_cursor_query
This attribute keeps the cursor SELECT statement.
Definition: sp_instr.h:1381
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1637
bool m_valid
Flag if the LEX-object of this instruction is valid or not.
Definition: sp_instr.h:1385
sp_instr_cpush(uint ip, sp_pcontext *ctx, LEX *cursor_lex, LEX_CSTRING cursor_query, int cursor_idx)
Definition: sp_instr.h:1333
sp_instr_error just throws an SQL-condition if the execution flow comes to it.
Definition: sp_instr.h:1560
bool execute(THD *, uint *nextp) override
Execute this instruction.
Definition: sp_instr.h:1575
sp_instr_error(uint ip, sp_pcontext *ctx, int errcode)
Definition: sp_instr.h:1562
int m_errcode
The error code, which should be raised by this instruction.
Definition: sp_instr.h:1590
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1581
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1594
uint opt_mark(sp_head *, List< sp_instr > *) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.h:1583
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1848
static PSI_statement_info psi_info
Definition: sp_instr.h:1596
sp_instr_freturn represents RETURN statement in stored functions.
Definition: sp_instr.h:711
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:735
LEX_CSTRING m_expr_query
SQL-query corresponding to the RETURN-expression.
Definition: sp_instr.h:774
static PSI_statement_info psi_info
Definition: sp_instr.h:783
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:745
Item * m_expr_item
RETURN-expression item.
Definition: sp_instr.h:771
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1433
LEX_CSTRING get_expr_query() const override
Definition: sp_instr.h:756
enum enum_field_types m_return_field_type
RETURN-field type code.
Definition: sp_instr.h:777
sp_instr_freturn(uint ip, LEX *lex, Item *expr_item, LEX_CSTRING expr_query, enum enum_field_types return_field_type)
Definition: sp_instr.h:713
Item * get_expr_item() const
Definition: sp_instr.h:767
bool on_after_expr_parsing(THD *thd) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:750
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:781
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1452
bool is_invalid() const override
Definition: sp_instr.h:743
void adjust_sql_command(LEX *lex) override
Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL comman...
Definition: sp_instr.h:758
uint opt_mark(sp_head *, List< sp_instr > *) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.h:730
Definition: sp_instr.h:1242
void print(const THD *, String *str) override
Definition: sp_instr.h:1250
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1260
static PSI_statement_info psi_info
Definition: sp_instr.h:1266
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1264
sp_instr_hpop(uint ip, sp_pcontext *ctx)
Definition: sp_instr.h:1244
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1548
Definition: sp_instr.h:1178
sp_instr_hpush_jump(uint ip, sp_pcontext *ctx, sp_handler *handler)
Definition: sp_instr.cc:1472
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1496
uint opt_shortcut_jump(sp_head *, sp_instr *) override
Override sp_instr_jump's shortcut; we stop here.
Definition: sp_instr.h:1207
uint m_opt_hpop
hpop marking end of handler scope.
Definition: sp_instr.h:1226
sp_handler * m_handler
Handler.
Definition: sp_instr.h:1223
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1200
void backpatch(uint dest) override
Update all instruction with the given label in the backpatch list to the specified instruction pointe...
Definition: sp_instr.h:1213
~sp_instr_hpush_jump() override
Definition: sp_instr.cc:1481
uint m_frame
Definition: sp_instr.h:1230
static PSI_statement_info psi_info
Definition: sp_instr.h:1236
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1490
uint opt_mark(sp_head *sp, List< sp_instr > *leads) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.cc:1508
void add_condition(sp_condition_value *condition_value)
Definition: sp_instr.cc:1486
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1234
sp_handler * get_handler()
Definition: sp_instr.h:1186
Definition: sp_instr.h:1272
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1304
uint m_frame
Definition: sp_instr.h:1300
static PSI_statement_info psi_info
Definition: sp_instr.h:1306
uint opt_shortcut_jump(sp_head *, sp_instr *) override
Override sp_instr_jump's shortcut; we stop here.
Definition: sp_instr.h:1293
uint opt_mark(sp_head *sp, List< sp_instr > *leads) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.cc:1602
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1288
sp_instr_hreturn(uint ip, sp_pcontext *ctx)
Definition: sp_instr.cc:1564
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:1567
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1588
sp_instr_jump_case_when instruction is used in the "simple CASE" implementation.
Definition: sp_instr.h:1095
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1373
int m_case_expr_id
Identifier (index) of the CASE-expression in the runtime context.
Definition: sp_instr.h:1154
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1113
static PSI_statement_info psi_info
Definition: sp_instr.h:1170
Item_case_expr * m_case_expr_item
Item representing the CASE-expression.
Definition: sp_instr.h:1157
bool on_after_expr_parsing(THD *thd) override
Build CASE-expression item tree: Item_func_eq(case-expression, when-i-expression)
Definition: sp_instr.cc:1386
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:1123
Item * m_eq_item
Item corresponding to the main item of the jump-condition-expression: it's the equal function (=) in ...
Definition: sp_instr.h:1164
sp_instr_jump_case_when(uint ip, LEX *lex, int case_expr_id, Item *when_expr_item, LEX_CSTRING when_expr_query)
Definition: sp_instr.h:1097
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1168
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1361
sp_instr_jump_if_not implements SP-instruction, which does the jump if its SQL-expression is false.
Definition: sp_instr.h:959
sp_instr_jump_if_not(uint ip, LEX *lex, Item *expr_item, LEX_CSTRING expr_query)
Definition: sp_instr.h:961
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:981
bool on_after_expr_parsing(THD *thd) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:991
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1290
static PSI_statement_info psi_info
Definition: sp_instr.h:1001
sp_instr_jump_if_not(uint ip, LEX *lex, Item *expr_item, LEX_CSTRING expr_query, uint dest)
Definition: sp_instr.h:966
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:999
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1278
This is base class for all kinds of jump instructions.
Definition: sp_instr.h:799
sp_instr_jump(uint ip, sp_pcontext *ctx)
Definition: sp_instr.h:801
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:853
sp_instr * m_optdest
Definition: sp_instr.h:849
sp_instr_jump(uint ip, sp_pcontext *ctx, uint dest)
Definition: sp_instr.h:804
uint opt_mark(sp_head *sp, List< sp_instr > *leads) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.cc:1237
uint m_dest
Where we will go.
Definition: sp_instr.h:846
void backpatch(uint dest) override
Update all instruction with the given label in the backpatch list to the specified instruction pointe...
Definition: sp_instr.h:838
static PSI_statement_info psi_info
Definition: sp_instr.h:855
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1230
void opt_move(uint dst, List< sp_branch_instr > *ibp) override
Inform the instruction that it has been moved during optimization.
Definition: sp_instr.cc:1260
uint opt_shortcut_jump(sp_head *sp, sp_instr *start) override
Short-cut jumps to jumps during optimization.
Definition: sp_instr.cc:1245
bool execute(THD *, uint *nextp) override
Execute this instruction.
Definition: sp_instr.h:817
void set_destination(uint old_dest, uint new_dest) override
Update the destination; used by the SP-instruction-optimizer.
Definition: sp_instr.h:834
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:822
sp_instr_set_case_expr is used in the "simple CASE" implementation to evaluate and store the CASE-exp...
Definition: sp_instr.h:1013
void set_destination(uint old_dest, uint new_dest) override
Update the destination; used by the SP-instruction-optimizer.
Definition: sp_instr.h:1056
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1888
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:1035
void opt_move(uint dst, List< sp_branch_instr > *ibp) override
Inform the instruction that it has been moved during optimization.
Definition: sp_instr.cc:1914
static PSI_statement_info psi_info
Definition: sp_instr.h:1082
uint m_case_expr_id
Identifier (index) of the CASE-expression in the runtime context.
Definition: sp_instr.h:1076
bool on_after_expr_parsing(THD *thd) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:1068
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:1080
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1865
sp_instr_set_case_expr(uint ip, LEX *lex, uint case_expr_id, Item *case_expr_item, LEX_CSTRING case_expr_query)
Definition: sp_instr.h:1015
uint opt_mark(sp_head *sp, List< sp_instr > *leads) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.cc:1900
void backpatch(uint) override
Update all instruction with the given label in the backpatch list to the specified instruction pointe...
Definition: sp_instr.h:1060
sp_instr_set_trigger_field represents SET-statements, which deal with NEW/OLD trigger pseudo-rows.
Definition: sp_instr.h:644
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:665
sp_instr_set_trigger_field(uint ip, LEX *lex, LEX_CSTRING trigger_field_name, Item_trigger_field *trigger_field, Item *value_item, LEX_CSTRING value_query)
Definition: sp_instr.h:646
bool on_after_expr_parsing(THD *thd) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.cc:1194
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:700
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1168
bool is_invalid() const override
Definition: sp_instr.h:675
static PSI_statement_info psi_info
Definition: sp_instr.h:702
Item_trigger_field * m_trigger_field
Item corresponding to the NEW/OLD trigger field.
Definition: sp_instr.h:690
void cleanup_before_parsing(THD *thd) override
Destroy items in the free list before re-parsing the statement query string (and thus,...
Definition: sp_instr.cc:1214
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1187
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:677
LEX_CSTRING get_expr_query() const override
Definition: sp_instr.h:683
LEX_CSTRING m_trigger_field_name
Trigger field name ("field_name" of the "NEW.field_name").
Definition: sp_instr.h:687
LEX_CSTRING m_value_query
SQL-query corresponding to the value expression.
Definition: sp_instr.h:696
Item * m_value_item
Value expression item of the SET-statement.
Definition: sp_instr.h:693
sp_instr_set represents SET-statements, which deal with SP-variables.
Definition: sp_instr.h:568
LEX_CSTRING get_expr_query() const override
Definition: sp_instr.h:606
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:587
LEX_CSTRING m_value_query
SQL-query corresponding to the value expression.
Definition: sp_instr.h:629
bool on_after_expr_parsing(THD *thd) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:599
void adjust_sql_command(LEX *lex) override
Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL comman...
Definition: sp_instr.h:608
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1123
sp_instr_set(uint ip, LEX *lex, uint offset, Item *value_item, LEX_CSTRING value_query, bool is_lex_owner)
Definition: sp_instr.h:570
Item * get_value_item()
Definition: sp_instr.h:617
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1140
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:597
Item * m_value_item
Value expression item of the SET-statement.
Definition: sp_instr.h:626
uint get_offset()
Definition: sp_instr.h:619
bool is_invalid() const override
Definition: sp_instr.h:595
static PSI_statement_info psi_info
Definition: sp_instr.h:633
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:634
uint m_offset
Frame offset.
Definition: sp_instr.h:623
sp_instr_stmt represents almost all conventional SQL-statements, which are supported outside stored p...
Definition: sp_instr.h:508
enum Instr_type type() override
Get the instruction type of this instruction.
Definition: sp_instr.h:521
bool is_invalid() const override
Definition: sp_instr.h:535
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:537
void print(const THD *thd, String *str) override
Definition: sp_instr.cc:1069
sp_instr_stmt(uint ip, LEX *lex, LEX_CSTRING query)
Definition: sp_instr.h:510
static PSI_statement_info psi_info
Definition: sp_instr.h:559
bool on_after_expr_parsing(THD *) override
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:543
bool exec_core(THD *thd, uint *nextp) override
Execute core function of instruction after all preparations (e.g.
Definition: sp_instr.cc:1093
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.cc:965
PSI_statement_info * get_psi_info() override
Definition: sp_instr.h:557
bool m_valid
Specify if the stored LEX-object is up-to-date.
Definition: sp_instr.h:553
LEX_CSTRING m_query
Complete query of the SQL-statement.
Definition: sp_instr.h:550
void get_query(String *sql_query) const override
Return the query string, which can be passed to the parser.
Definition: sp_instr.h:539
Base class for every SP-instruction.
Definition: sp_instr.h:105
bool m_marked
Show if this instruction is reachable within the SP (used by SP-optimizer).
Definition: sp_instr.h:227
virtual SQL_I_List< Item_trigger_field > * get_instr_trig_field_list()
Definition: sp_instr.h:218
sp_instr(uint ip, sp_pcontext *ctx)
Definition: sp_instr.h:107
sp_pcontext * m_parsing_ctx
Instruction parsing context.
Definition: sp_instr.h:233
void clear_da(THD *thd) const
Clear diagnostics area.
Definition: sp_instr.h:176
virtual uint opt_shortcut_jump(sp_head *, sp_instr *start)
Short-cut jumps to jumps during optimization.
Definition: sp_instr.h:202
bool opt_is_marked() const
Definition: sp_instr.h:216
virtual uint get_cont_dest() const
Get the continuation destination (instruction pointer for the CONTINUE HANDLER) of this instruction.
Definition: sp_instr.h:167
virtual uint opt_mark(sp_head *, List< sp_instr > *leads)
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.h:191
void operator=(sp_instr &)
sp_instr(const sp_instr &)
virtual bool execute(THD *thd, uint *nextp)=0
Execute this instruction.
virtual void opt_move(uint dst, List< sp_branch_instr > *ibp)
Inform the instruction that it has been moved during optimization.
Definition: sp_instr.h:212
uint m_ip
Instruction pointer.
Definition: sp_instr.h:230
virtual enum Instr_type type()=0
Get the instruction type of this instruction.
Query_arena m_arena
Definition: sp_instr.h:222
uint get_ip() const
Definition: sp_instr.h:160
virtual PSI_statement_info * get_psi_info()=0
~sp_instr() override
Definition: sp_instr.h:113
sp_pcontext * get_parsing_ctx() const
Definition: sp_instr.h:169
Instr_type
Definition: sp_instr.h:115
@ INSTR_LEX_FRETURN
Definition: sp_instr.h:127
@ INSTR_UNKNOWN
Definition: sp_instr.h:116
@ INSTR_LEX_BRANCH_SET_CASE_EXPR
Definition: sp_instr.h:133
@ INSTR_COND_HANDLER_RETURN
Definition: sp_instr.h:125
@ INSTR_CCLOSE
Definition: sp_instr.h:118
@ INSTR_LEX_BRANCH_IF_NOT
Definition: sp_instr.h:132
@ INSTR_LEX_CPUSH
Definition: sp_instr.h:126
@ INSTR_COND_HANDLER_PUSH_JUMP
Definition: sp_instr.h:124
@ INSTR_LEX_STMT
Definition: sp_instr.h:130
@ INSTR_COPEN
Definition: sp_instr.h:117
@ INSTR_LEX_SET_TRIGGER_FIELD
Definition: sp_instr.h:129
@ INSTR_LEX_SET
Definition: sp_instr.h:128
@ INSTR_HPOP
Definition: sp_instr.h:121
@ INSTR_JUMP
Definition: sp_instr.h:123
@ INSTR_ERROR
Definition: sp_instr.h:122
@ INSTR_CFETCH
Definition: sp_instr.h:119
@ INSTR_CPOP
Definition: sp_instr.h:120
@ INSTR_LEX_BRANCH_CASE_WHEN
Definition: sp_instr.h:131
sp_lex_branch_instr is a base class for SP-instructions, which might perform conditional jump dependi...
Definition: sp_instr.h:865
sp_instr * m_cont_optdest
Definition: sp_instr.h:944
enum Instr_type type() override=0
Get the instruction type of this instruction.
sp_lex_branch_instr(uint ip, sp_pcontext *ctx, LEX *lex, Item *expr_item, LEX_CSTRING expr_query, uint dest)
Definition: sp_instr.h:877
uint m_dest
Where we will go.
Definition: sp_instr.h:937
void opt_move(uint dst, List< sp_branch_instr > *ibp) override
Inform the instruction that it has been moved during optimization.
Definition: sp_instr.cc:1331
sp_lex_branch_instr(uint ip, sp_pcontext *ctx, LEX *lex, Item *expr_item, LEX_CSTRING expr_query)
Definition: sp_instr.h:867
uint m_cont_dest
Where continue handlers will go.
Definition: sp_instr.h:940
bool is_invalid() const override
Definition: sp_instr.h:906
sp_instr * m_optdest
Definition: sp_instr.h:943
void set_destination(uint old_dest, uint new_dest) override
Update the destination; used by the SP-instruction-optimizer.
Definition: sp_instr.h:918
uint opt_mark(sp_head *sp, List< sp_instr > *leads) override
Mark this instruction as reachable during optimization and return the index to the next instruction.
Definition: sp_instr.cc:1307
LEX_CSTRING m_expr_query
SQL-query corresponding to the expression.
Definition: sp_instr.h:950
void adjust_sql_command(LEX *lex) override
Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL comman...
Definition: sp_instr.h:930
LEX_CSTRING get_expr_query() const override
Definition: sp_instr.h:912
Item * m_expr_item
Expression item.
Definition: sp_instr.h:947
void invalidate() override
Invalidate the object.
Definition: sp_instr.h:908
void backpatch(uint dest) override
Update all instruction with the given label in the backpatch list to the specified instruction pointe...
Definition: sp_instr.h:924
uint get_cont_dest() const override
Get the continuation destination (instruction pointer for the CONTINUE HANDLER) of this instruction.
Definition: sp_instr.h:898
void set_cont_dest(uint cont_dest)
Definition: sp_instr.h:888
sp_lex_instr is a class providing the interface and base implementation for SP-instructions,...
Definition: sp_instr.h:252
bool execute_expression(THD *thd, uint *nextp)
Execute an expression (e.g an IF) that is not a complete SQL statement.
Definition: sp_instr.cc:319
bool reset_lex_and_exec_core(THD *thd, uint *nextp, bool open_tables)
Prepare LEX and thread for execution of instruction, if requested open and lock LEX's tables,...
Definition: sp_instr.cc:388
~sp_lex_instr() override
Definition: sp_instr.h:264
const LEX * get_lex()
Definition: sp_instr.h:378
Table_ref ** m_lex_query_tables_own_last
The value m_lex->query_tables_own_last should be set to this when the statement enters/leaves prelock...
Definition: sp_instr.h:491
void set_lex(LEX *lex, bool is_lex_owner)
Set LEX-object.
Definition: sp_instr.cc:905
virtual LEX_CSTRING get_expr_query() const
Definition: sp_instr.h:427
virtual bool is_invalid() const =0
Table_ref * m_prelocking_tables
List of additional tables this statement needs to lock when it enters/leaves prelocked mode on its ow...
Definition: sp_instr.h:485
enum Instr_type type() override=0
Get the instruction type of this instruction.
LEX * m_lex
LEX-object.
Definition: sp_instr.h:452
virtual void get_query(String *sql_query) const
Return the query string, which can be passed to the parser.
Definition: sp_instr.cc:944
SQL_I_List< Item_trigger_field > * get_instr_trig_field_list() override
Definition: sp_instr.h:295
virtual void adjust_sql_command(LEX *)
Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL comman...
Definition: sp_instr.h:415
SQL_I_List< Item_trigger_field > m_trig_field_list
List of all the Item_trigger_field's of instruction.
Definition: sp_instr.h:496
bool validate_lex_and_execute_core(THD *thd, uint *nextp, bool open_tables)
Make a few attempts to execute the instruction.
Definition: sp_instr.cc:711
void free_lex()
Cleanup and destroy assigned LEX-object if needed.
Definition: sp_instr.cc:915
bool m_is_lex_owner
Indicates whether this sp_lex_instr instance is responsible for LEX-object deletion.
Definition: sp_instr.h:466
bool execute(THD *thd, uint *nextp) override
Execute this instruction.
Definition: sp_instr.h:354
virtual bool exec_core(THD *thd, uint *nextp)=0
Execute core function of instruction after all preparations (e.g.
bool m_first_execution
Indicates whether exec_core() has not been already called on the current LEX-object.
Definition: sp_instr.h:472
virtual bool on_after_expr_parsing(THD *thd)
Callback function which is called after the statement query string is successfully parsed,...
Definition: sp_instr.h:439
virtual void invalidate()=0
Invalidate the object.
virtual void cleanup_before_parsing(THD *thd)
Destroy items in the free list before re-parsing the statement query string (and thus,...
Definition: sp_instr.cc:931
sp_lex_instr(uint ip, sp_pcontext *ctx, LEX *lex, bool is_lex_owner)
Definition: sp_instr.h:254
MEM_ROOT m_lex_mem_root
Mem-root for storing the LEX-tree during reparse.
Definition: sp_instr.h:460
LEX * parse_statement(THD *thd, sp_head *sp)
Parse statement corresponding to this instruction and return a new LEX.
Definition: sp_instr.cc:573
The class represents parse-time context, which keeps track of declared variables/parameters,...
Definition: sp_pcontext.h:252
sp_printable defines an interface which should be implemented if a class wants report some internal i...
Definition: sp_instr.h:67
virtual void print(const THD *thd, String *str)=0
virtual ~sp_printable()=default
This class represents a stored program variable or a parameter (also referenced as 'SP-variable').
Definition: sp_pcontext.h:49
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
bool open_tables(THD *thd, Table_ref **start, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
Open all tables in list.
Definition: sql_base.cc:5886
#define alloc_root_inited(A)
Definition: my_sys.h:802
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:217
Item * single_visible_field() const
Definition: sql_resolver.cc:4938
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
constexpr const LEX_CSTRING EMPTY_CSTR
Definition: lex_string.h:48
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Header for compiler-dependent features.
Some integer typedefs for easier portability.
#define MYF(v)
Definition: my_inttypes.h:97
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
@ SQLCOM_SELECT
Definition: my_sqlcommand.h:47
@ SQLCOM_END
Definition: my_sqlcommand.h:213
@ SQLCOM_SET_OPTION
Definition: my_sqlcommand.h:78
Common header for many mysys elements.
static int count
Definition: myisam_ftdump.cc:45
static char * query
Definition: myisam_ftdump.cc:47
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1078
Performance schema instrumentation interface.
File containing constants that can be used throughout the server.
constexpr const size_t MEM_ROOT_BLOCK_SIZE
Memory allocated when parsing a statement.
Definition: sql_const.h:129
Our own string classes, used pervasively throughout the executor.
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3999
bool safe_to_cache_query
Whether this query will return the same answer every time, given unchanged data.
Definition: sql_lex.h:4414
Query_block * query_block
First query block.
Definition: sql_lex.h:4004
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Statement instrument information.
Definition: psi_statement_bits.h:133
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:44