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