40#include "mysqld_error.h"
75#define SP_PSI_STATEMENT_INFO_COUNT 16
77#ifdef HAVE_PSI_INTERFACE
575 bool need_fix_fields);
722 const char *field_name,
TABLE *table)
const;
729 void set_definer(
const char *definer,
size_t definerlen);
799 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"Dynamic SQL");
805 my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0));
807 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"RESET");
809 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"FLUSH");
836 DBUG_PRINT(
"info", (
"lex->get_stmt_unsafe_flags(): 0x%x",
838 DBUG_PRINT(
"info", (
"sp_head(0x%p=%s)->unsafe_flags: 0x%x",
this,
name(),
963 bool execute(
THD *thd,
bool merge_da_on_success);
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:50
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:219
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6486
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
Definition: sql_list.h:433
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
Definition: sql_lex.h:2490
void set_stmt_unsafe_flags(uint32 flags)
Set the bits of binlog_stmt_flags determining the type of unsafeness of the current statement.
Definition: sql_lex.h:2823
uint32 get_stmt_unsafe_flags() const
Return a binary combination of all unsafe warnings for the statement.
Definition: sql_lex.h:2836
void set_stmt_unsafe_with_mixed_mode()
Definition: sql_lex.h:3061
Simple intrusive linked list.
Definition: sql_list.h:45
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:53
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:223
Stored_program_creation_ctx – base class for creation context of stored programs (stored routines,...
Definition: sp_head.h:88
const CHARSET_INFO * m_db_cl
db_cl stores the value of the database collation.
Definition: sp_head.h:114
virtual Stored_program_creation_ctx * clone(MEM_ROOT *mem_root)=0
void change_env(THD *thd) const override
Definition: sp_head.cc:3509
Stored_program_creation_ctx(THD *thd)
Definition: sp_head.cc:3505
Stored_program_creation_ctx(const CHARSET_INFO *client_cs, const CHARSET_INFO *connection_cl, const CHARSET_INFO *db_cl)
Definition: sp_head.h:98
const CHARSET_INFO * get_db_cl()
Definition: sp_head.h:90
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
This class holds all information about triggers of a table.
Definition: table_trigger_dispatcher.h:62
This is an interface to be used from Item_trigger_field to access information about table trigger fie...
Definition: table_trigger_field_support.h:43
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:209
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:147
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
An interface for all SP-instructions with destinations that need to be updated by the SP-optimizer.
Definition: sp_instr.h:77
sp_head represents one instance of a stored program.
Definition: sp_head.h:379
void set_creation_ctx(Stored_program_creation_ctx *creation_ctx)
Definition: sp_head.h:563
bool add_instr(THD *thd, sp_instr *instr)
Add instruction to SP.
Definition: sp_head.cc:3055
LEX_STRING m_name
Definition: sp_head.h:459
bool execute_function(THD *thd, Item **args, uint argcount, Field *return_fld)
Execute a function.
Definition: sp_head.cc:2507
st_sp_chistics * m_chistics
Stored program characteristics.
Definition: sp_head.h:443
sp_head(MEM_ROOT &&mem_root, enum_sp_type type)
Use sp_start_parsing() to create instances of sp_head.
Definition: sp_head.cc:1698
int64 sp_cache_version() const
Get the value of the SP cache version, as remembered when the routine was inserted into the cache.
Definition: sp_head.h:554
void set_definer(const char *definer, size_t definerlen)
Definition: sp_head.cc:3031
void operator=(sp_head &)
LEX_CSTRING m_body
Definition: sp_head.h:461
bool setup_trigger_fields(THD *thd, Table_trigger_field_support *tfs, GRANT_INFO *subject_table_grant, bool need_fix_fields)
Definition: sp_head.cc:1825
bool has_updated_trigger_fields(const MY_BITMAP *used_fields) const
Check whether any table's fields are used in trigger.
Definition: sp_head.cc:1877
void init_sp_name(THD *thd, sp_name *spname)
Copy sp name from parser.
Definition: sp_head.cc:1748
bool execute_procedure(THD *thd, mem_root_deque< Item * > *args)
Execute a procedure.
Definition: sp_head.cc:2720
void set_body_end(THD *thd)
Set the statement-definition (body-definition) end position.
Definition: sp_head.cc:1777
void set_info(longlong created, longlong modified, st_sp_chistics *chistics, sql_mode_t sql_mode)
Definition: sp_head.cc:3017
ulong m_recursion_level
Recursion level of the current SP instance.
Definition: sp_head.h:472
longlong m_created
Definition: sp_head.h:467
sp_head * m_first_instance
Pointer to the first element of the above list.
Definition: sp_head.h:483
uint instructions()
Definition: sp_head.h:682
collation_unordered_map< std::string, SP_TABLE * > m_sptabs
Multi-set representing optimized list of tables to be locked by this routine.
Definition: sp_head.h:916
bool execute(THD *thd, bool merge_da_on_success)
Execute the routine.
Definition: sp_head.cc:1982
Security_context m_security_ctx
Definition: sp_head.h:516
Create_field m_return_field_def
Definition of the RETURN-field (from the RETURNS-clause).
Definition: sp_head.h:437
LEX_STRING m_defstr
Definition: sp_head.h:463
uint m_flags
Stored program flags.
Definition: sp_head.h:426
SQL_I_List< SQL_I_List< Item_trigger_field > > m_list_of_trig_fields_item_lists
List of item (Item_trigger_field objects)'s lists representing fields in old/new version of row in tr...
Definition: sp_head.h:529
void add_used_tables_to_table_list(THD *thd, Table_ref ***query_tables_last_ptr, enum_sql_command sql_command, Table_ref *belong_to_view)
Add tables used by routine to the table list.
Definition: sp_head.cc:3300
friend sp_head * sp_start_parsing(THD *thd, enum_sp_type sp_type, sp_name *sp_name)
Start parsing of a stored program.
Definition: sp.cc:2153
int64 m_sp_cache_version
Version of the stored routine cache at the moment when the routine was added to it.
Definition: sp_head.h:936
sp_pcontext * m_root_parsing_ctx
Root parsing context (topmost BEGIN..END block) of this SP.
Definition: sp_head.h:902
LEX_STRING m_params
Definition: sp_head.h:460
bool show_routine_code(THD *thd)
Return the routine instructions as a result set.
Definition: sp_head.cc:3160
class Table_trigger_dispatcher * m_trg_list
The Table_trigger_dispatcher instance, where this trigger belongs to.
Definition: sp_head.h:542
malloc_unordered_map< std::string, Sroutine_hash_entry * > m_sroutines
Set containing names of stored routines used by this routine.
Definition: sp_head.h:510
std::vector< SP_TABLE * > m_sptabs_sorted
Definition: sp_head.h:924
LEX_STRING m_db
Definition: sp_head.h:458
Field * create_result_field(THD *thd, size_t field_max_length, const char *field_name, TABLE *table) const
Create Field-object corresponding to the RETURN field of a stored function.
Definition: sp_head.cc:1924
bool check_show_access(THD *thd, bool *full_access)
Check if a user has access right to a SP.
Definition: sp_head.cc:3373
void set_sp_cache_version(int64 sp_cache_version)
Set the value of the SP cache version.
Definition: sp_head.h:557
bool m_explicit_name
Prepend the db name? */.
Definition: sp_head.h:456
bool is_not_allowed_in_function(const char *where)
Check if this stored routine contains statements disallowed in a stored function or trigger,...
Definition: sp_head.h:797
void mark_used_trigger_fields(TABLE *subject_table)
Definition: sp_head.cc:1847
void returns_type(THD *thd, String *result) const
Definition: sp_head.cc:1955
LEX_CSTRING m_body_utf8
Definition: sp_head.h:462
Mem_root_array< sp_instr * > m_instructions
The SP-instructions.
Definition: sp_head.h:905
uint32 unsafe_flags
Flags of LEX::enum_binlog_stmt_unsafe.
Definition: sp_head.h:942
Stored_program_creation_ctx * m_creation_ctx
Snapshot of several system variables at CREATE-time.
Definition: sp_head.h:939
bool is_invoked() const
Is this routine being executed?
Definition: sp_head.h:548
LEX_STRING m_qname
Fully qualified name (<db name>.<sp name>).
Definition: sp_head.h:454
LEX_STRING m_definer_host
Definition: sp_head.h:465
sql_mode_t m_sql_mode
The value of sql_mode system variable at the CREATE-time.
Definition: sp_head.h:451
MEM_ROOT * get_persistent_mem_root() const
Definition: sp_head.h:860
bool merge_table_list(THD *thd, Table_ref *table, LEX *lex_for_tmp_check)
Merge the list of tables used by some query into the multi-set of tables used by routine.
Definition: sp_head.cc:3210
longlong m_modified
Definition: sp_head.h:468
bool restore_lex(THD *thd)
Restore LEX-object during parsing, after we have parsed a sub statement.
Definition: sp_head.cc:2967
static void destroy(sp_head *sp)
Definition: sp_head.cc:1687
~sp_head()
Use destroy() to destoy instances of sp_head.
Definition: sp_head.cc:1896
sp_instr * last_instruction()
Definition: sp_head.h:684
LEX_STRING m_definer_user
Definition: sp_head.h:464
char * name(uint *lenp=nullptr) const
Definition: sp_head.h:704
void set_body_start(THD *thd, const char *begin_ptr)
Set the body-definition start position.
Definition: sp_head.cc:1771
void add_mark_lead(uint ip, List< sp_instr > *leads)
Helper used during flow analysis during code optimization.
Definition: sp_head.cc:3119
bool has_temp_table_ddl() const
Definition: sp_head.h:680
bool execute_trigger(THD *thd, const LEX_CSTRING &db_name, const LEX_CSTRING &table_name, GRANT_INFO *grant_info)
Execute trigger stored program.
Definition: sp_head.cc:2401
PSI_sp_share * m_sp_share
Instrumentation interface for SP.
Definition: sp_head.h:431
sp_parser_data m_parser_data
Attributes used during the parsing stage only.
Definition: sp_head.h:440
Stored_program_creation_ctx * get_creation_ctx()
Definition: sp_head.h:561
sp_head * m_next_cached_sp
A list of different recursion level instances for the same procedure.
Definition: sp_head.h:480
bool reset_lex(THD *thd)
Reset LEX-object during parsing, before we parse a sub statement.
Definition: sp_head.cc:2943
MEM_ROOT main_mem_root
SP-persistent memory root (for instructions and expressions).
Definition: sp_head.h:899
st_trg_chistics m_trg_chistics
Trigger characteristics.
Definition: sp_head.h:539
sp_head * m_first_free_instance
Pointer to the first free (non-INVOKED) routine in the list of cached instances for this SP.
Definition: sp_head.h:492
void optimize()
Do some minimal optimization of the code:
Definition: sp_head.cc:3086
enum_sp_type m_type
Stored program type.
Definition: sp_head.h:423
bool modifies_data() const
Returns true if any substatement in the routine directly (not through another routine) modifies data/...
Definition: sp_head.h:672
void propagate_attributes(Query_tables_list *prelocking_ctx)
Definition: sp_head.h:829
sp_head * m_last_cached_sp
Pointer to the last element in the list of instances of the SP.
Definition: sp_head.h:498
void opt_mark()
Perform a forward flow analysis in the generated code.
Definition: sp_head.cc:3125
sp_pcontext * get_root_parsing_context() const
Definition: sp_head.h:852
sp_instr * get_instr(uint i)
Get SP-instruction at given index.
Definition: sp_head.h:765
@ MULTI_RESULTS
Definition: sp_head.h:384
@ HAS_TEMP_TABLE_DDL
Set when a stored program contains sub-statement(s) that creates or drops temporary table(s).
Definition: sp_head.h:414
@ HAS_SQLCOM_RESET
Definition: sp_head.h:393
@ MODIFIES_DATA
Marks routines that directly (i.e.
Definition: sp_head.h:408
@ LOG_GENERAL_LOG
Definition: sp_head.h:392
@ HAS_COMMIT_OR_ROLLBACK
Definition: sp_head.h:390
@ IS_INVOKED
Definition: sp_head.h:386
@ CONTAINS_DYNAMIC_SQL
Definition: sp_head.h:385
@ HAS_SQLCOM_FLUSH
Definition: sp_head.h:394
@ LOG_SLOW_STATEMENTS
Definition: sp_head.h:391
@ HAS_RETURN
Definition: sp_head.h:383
@ HAS_SET_AUTOCOMMIT_STMT
Definition: sp_head.h:387
bool set_security_ctx(THD *thd, Security_context **save_ctx)
Change routine security context, and check if there is an EXECUTE privilege in new context.
Definition: sp_head.cc:3387
SQL_I_List< Item_trigger_field > m_cur_instr_trig_field_items
List of all the Item_trigger_field items created while parsing sp instruction.
Definition: sp_head.h:536
Base class for every SP-instruction.
Definition: sp_instr.h:104
This class represents an SQL/PSM label.
Definition: sp_pcontext.h:93
sp_lex_branch_instr is a base class for SP-instructions, which might perform conditional jump dependi...
Definition: sp_instr.h:788
Definition: sp_head.h:119
LEX_STRING m_qname
Definition: sp_head.h:123
bool m_explicit_name
Prepend the db name?
Definition: sp_head.h:124
void init_qname(THD *thd)
Init the qualified name from the db and name.
Definition: sp_head.cc:1673
LEX_STRING m_name
Definition: sp_head.h:122
sp_name(const LEX_CSTRING &db, const LEX_STRING &name, bool use_explicit_name)
Definition: sp_head.h:126
LEX_CSTRING m_db
Definition: sp_head.h:121
sp_parser_data provides a scope for attributes used at the SP-parsing stage only.
Definition: sp_head.h:145
const char * m_current_stmt_start_ptr
Start of the current statement's query string.
Definition: sp_head.h:308
void push_lex(LEX *lex)
Definition: sp_head.h:233
uint m_cont_level
The current continue backpatch level.
Definition: sp_head.h:354
bool add_backpatch_entry(sp_branch_instr *i, sp_label *label)
Put the instruction on the backpatch list, associated with the label.
Definition: sp_head.cc:3452
void start_parsing_sp_body(THD *thd, sp_head *sp)
Start parsing a stored program body statement.
Definition: sp_head.cc:3419
Item * m_saved_item_list
THD's item list.
Definition: sp_head.h:368
const char * get_option_start_ptr() const
Definition: sp_head.h:209
const char * m_param_end_ptr
Position in the CREATE PROCEDURE- or CREATE FUNCTION-statement's query string corresponding to the en...
Definition: sp_head.h:331
void do_cont_backpatch(uint dest)
Backpatch (and pop) the current level to the given instruction pointer.
Definition: sp_head.cc:3477
bool is_parsing_sp_body() const
Definition: sp_head.h:191
MEM_ROOT * m_saved_memroot
THD's memroot.
Definition: sp_head.h:365
sp_parser_data()
Definition: sp_head.h:153
const char * m_param_start_ptr
Position in the CREATE PROCEDURE- or CREATE FUNCTION-statement's query string corresponding to the st...
Definition: sp_head.h:324
void process_new_sp_instr(THD *thd, sp_instr *i)
Definition: sp_head.cc:3488
const char * get_parameter_end_ptr() const
Definition: sp_head.h:221
void set_body_start_ptr(const char *ptr)
Definition: sp_head.h:229
void set_parameter_start_ptr(const char *ptr)
Definition: sp_head.h:219
void set_current_stmt_start_ptr(const char *stmt_start_ptr)
Definition: sp_head.h:203
const char * m_body_start_ptr
Position in the CREATE-/ALTER-stored-program statement's query string corresponding to the start of t...
Definition: sp_head.h:337
void set_parameter_end_ptr(const char *ptr)
Definition: sp_head.h:223
List< Backpatch_info > m_backpatch
Instructions needing backpatching.
Definition: sp_head.h:340
LEX * pop_lex()
Definition: sp_head.h:235
bool add_cont_backpatch_entry(sp_lex_branch_instr *i)
Add a SP-instruction to the current level.
Definition: sp_head.cc:3472
List< LEX > m_lex_stack
Stack of LEX-objects.
Definition: sp_head.h:317
const char * m_option_start_ptr
Start of the SET-expression query string.
Definition: sp_head.h:311
List< sp_lex_branch_instr > m_cont_backpatch
We need a special list for backpatching of instructions with a continue destination (in the case of a...
Definition: sp_head.h:351
void set_option_start_ptr(const char *option_start_ptr)
Definition: sp_head.h:211
const char * get_body_start_ptr() const
Definition: sp_head.h:227
bool new_cont_backpatch()
Start a new backpatch level for the SP-instruction requiring continue destination.
Definition: sp_head.h:285
void finish_parsing_sp_body(THD *thd)
Finish parsing of a stored program body statement.
Definition: sp_head.cc:3430
const char * get_parameter_start_ptr() const
Definition: sp_head.h:217
const char * get_current_stmt_start_ptr() const
Definition: sp_head.h:199
void do_backpatch(sp_label *label, uint dest)
Update all instruction with the given label in the backpatch list to the given instruction pointer.
Definition: sp_head.cc:3463
The class represents parse-time context, which keeps track of declared variables/parameters,...
Definition: sp_pcontext.h:251
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
ulonglong sql_mode_t
Definition: dd_event.h:36
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
enum_sp_type
enum_sp_type defines type codes of stored programs.
Definition: sql_lex.h:222
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
void init_sp_psi_keys(void)
Definition: sp_head.cc:1541
struct PSI_sp_share PSI_sp_share
Definition: psi_statement_bits.h:110
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:180
Some integer typedefs for easier portability.
int64_t int64
Definition: my_inttypes.h:67
long long int longlong
Definition: my_inttypes.h:54
#define MYF(v)
Definition: my_inttypes.h:96
uint32_t uint32
Definition: my_inttypes.h:66
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
enum_sql_command
Definition: my_sqlcommand.h:45
Common header for many mysys elements.
static char * where
Definition: mysqldump.cc:136
static const char * sql_mode
Definition: mysqlslap.cc:196
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
Performance schema instrumentation interface.
required string type
Definition: replication_group_member_actions.proto:33
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:382
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:356
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3693
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
char * str
Definition: mysql_lex_string.h:35
size_t length
Definition: mysql_lex_string.h:36
Definition: my_bitmap.h:42
SP_TABLE represents all instances of one table in an optimized multi-set of tables used by a stored p...
Definition: sp_head.cc:1567
Definition: sp_head.h:147
sp_label * label
Definition: sp_head.h:148
sp_branch_instr * instr
Definition: sp_head.h:149
Definition: sql_lex.h:2449
Definition: sql_lex.h:2458
#define NULL
Definition: types.h:54
unsigned int uint
Definition: uca-dump.cc:29