44#include "mysqld_error.h"
79#define SP_PSI_STATEMENT_INFO_COUNT 16
81#ifdef HAVE_PSI_INTERFACE
590 bool need_fix_fields);
719 char *
name(uint *lenp =
nullptr)
const {
744 void set_definer(
const char *definer,
size_t definerlen);
814 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"Dynamic SQL");
820 my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0));
822 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"RESET");
824 my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG,
MYF(0),
"FLUSH");
851 DBUG_PRINT(
"info", (
"lex->get_stmt_unsafe_flags(): 0x%x",
853 DBUG_PRINT(
"info", (
"sp_head(0x%p=%s)->unsafe_flags: 0x%x",
this,
name(),
1017 bool execute(
THD *thd,
bool merge_da_on_success);
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Default_object_creation_ctx – default implementation of Object_creation_ctx.
Definition: table.h:228
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6699
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Definition: sql_lex.h:2618
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:2951
uint32 get_stmt_unsafe_flags() const
Return a binary combination of all unsafe warnings for the statement.
Definition: sql_lex.h:2964
void set_stmt_unsafe_with_mixed_mode()
Definition: sql_lex.h:3192
Simple intrusive linked list.
Definition: sql_list.h:48
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:54
Structure that represents element in the set of stored routines used by statement or routine.
Definition: sp.h:225
Stored_program_creation_ctx – base class for creation context of stored programs (stored routines,...
Definition: sp_head.h:92
const CHARSET_INFO * m_db_cl
db_cl stores the value of the database collation.
Definition: sp_head.h:118
virtual Stored_program_creation_ctx * clone(MEM_ROOT *mem_root)=0
void change_env(THD *thd) const override
Definition: sp_head.cc:3761
Stored_program_creation_ctx(THD *thd)
Definition: sp_head.cc:3757
Stored_program_creation_ctx(const CHARSET_INFO *client_cs, const CHARSET_INFO *connection_cl, const CHARSET_INFO *db_cl)
Definition: sp_head.h:102
const CHARSET_INFO * get_db_cl()
Definition: sp_head.h:94
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class holds all information about triggers of a table.
Definition: table_trigger_dispatcher.h:68
This is an interface to be used from Item_trigger_field to access information about table trigger fie...
Definition: table_trigger_field_support.h:44
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:219
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:157
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:35
An interface for all SP-instructions with destinations that need to be updated by the SP-optimizer.
Definition: sp_instr.h:78
sp_head represents one instance of a stored program.
Definition: sp_head.h:383
void set_creation_ctx(Stored_program_creation_ctx *creation_ctx)
Definition: sp_head.h:578
@ MULTI_RESULTS
Definition: sp_head.h:388
@ HAS_TEMP_TABLE_DDL
Set when a stored program contains sub-statement(s) that creates or drops temporary table(s).
Definition: sp_head.h:418
@ HAS_SQLCOM_RESET
Definition: sp_head.h:397
@ MODIFIES_DATA
Marks routines that directly (i.e.
Definition: sp_head.h:412
@ LOG_GENERAL_LOG
Definition: sp_head.h:396
@ HAS_COMMIT_OR_ROLLBACK
Definition: sp_head.h:394
@ IS_INVOKED
Definition: sp_head.h:390
@ CONTAINS_DYNAMIC_SQL
Definition: sp_head.h:389
@ HAS_SQLCOM_FLUSH
Definition: sp_head.h:398
@ LOG_SLOW_STATEMENTS
Definition: sp_head.h:395
@ HAS_RETURN
Definition: sp_head.h:387
@ HAS_SET_AUTOCOMMIT_STMT
Definition: sp_head.h:391
bool execute_external_routine(THD *thd)
Execute external routine.
Definition: sp_head.cc:2461
bool add_instr(THD *thd, sp_instr *instr)
Add instruction to SP.
Definition: sp_head.cc:3301
bool set_external_program_handle(external_program_handle sp)
Set the external program handle object.
Definition: sp_head.cc:2707
LEX_STRING m_name
Definition: sp_head.h:466
bool execute_function(THD *thd, Item **args, uint argcount, Field *return_fld)
Execute a function.
Definition: sp_head.cc:2737
st_sp_chistics * m_chistics
Stored program characteristics.
Definition: sp_head.h:447
sp_head(MEM_ROOT &&mem_root, enum_sp_type type)
Use sp_start_parsing() to create instances of sp_head.
Definition: sp_head.cc:1703
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:569
void set_definer(const char *definer, size_t definerlen)
Definition: sp_head.cc:3277
void operator=(sp_head &)
LEX_CSTRING m_body
Definition: sp_head.h:468
bool setup_trigger_fields(THD *thd, Table_trigger_field_support *tfs, GRANT_INFO *subject_table_grant, bool need_fix_fields)
Definition: sp_head.cc:1831
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:1883
void init_sp_name(THD *thd, sp_name *spname)
Copy sp name from parser.
Definition: sp_head.cc:1753
bool execute_procedure(THD *thd, mem_root_deque< Item * > *args)
Execute a procedure.
Definition: sp_head.cc:2952
void set_body_end(THD *thd)
Set the statement-definition (body-definition) end position.
Definition: sp_head.cc:1782
void set_info(longlong created, longlong modified, st_sp_chistics *chistics, sql_mode_t sql_mode)
Definition: sp_head.cc:3255
ulong m_recursion_level
Recursion level of the current SP instance.
Definition: sp_head.h:478
longlong m_created
Definition: sp_head.h:473
external_program_handle get_external_program_handle()
Get the external program handle object.
Definition: sp_head.cc:2703
sp_head * m_first_instance
Pointer to the first element of the above list.
Definition: sp_head.h:489
uint instructions()
Definition: sp_head.h:697
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:931
bool execute(THD *thd, bool merge_da_on_success)
Execute the routine.
Definition: sp_head.cc:1998
Security_context m_security_ctx
Definition: sp_head.h:522
Create_field m_return_field_def
Definition of the RETURN-field (from the RETURNS-clause).
Definition: sp_head.h:441
bool is_sql() const
Definition: sp_head.h:560
uint m_flags
Stored program flags.
Definition: sp_head.h:430
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:535
bool init_external_routine(my_service< const mysql_service_external_program_execution_t > *service)
Initialize and parse an external routine.
Definition: sp_head.cc:2715
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:3552
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:2237
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:951
sp_pcontext * m_root_parsing_ctx
Root parsing context (topmost BEGIN..END block) of this SP.
Definition: sp_head.h:917
LEX_STRING m_params
Definition: sp_head.h:467
bool show_routine_code(THD *thd)
Return the routine instructions as a result set.
Definition: sp_head.cc:3406
class Table_trigger_dispatcher * m_trg_list
The Table_trigger_dispatcher instance, where this trigger belongs to.
Definition: sp_head.h:548
malloc_unordered_map< std::string, Sroutine_hash_entry * > m_sroutines
Set containing names of stored routines used by this routine.
Definition: sp_head.h:516
std::vector< SP_TABLE * > m_sptabs_sorted
Definition: sp_head.h:939
LEX_STRING m_db
Definition: sp_head.h:465
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:1937
bool check_show_access(THD *thd, bool *full_access)
Check if a user has access right to a SP.
Definition: sp_head.cc:3625
void set_sp_cache_version(int64 sp_cache_version)
Set the value of the SP cache version.
Definition: sp_head.h:572
bool m_explicit_name
Prepend the db name? */.
Definition: sp_head.h:463
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:812
void mark_used_trigger_fields(TABLE *subject_table)
Definition: sp_head.cc:1853
void returns_type(THD *thd, String *result) const
Definition: sp_head.cc:1971
LEX_CSTRING m_body_utf8
Definition: sp_head.h:469
Mem_root_array< sp_instr * > m_instructions
The SP-instructions.
Definition: sp_head.h:920
uint32 unsafe_flags
Flags of LEX::enum_binlog_stmt_unsafe.
Definition: sp_head.h:957
Stored_program_creation_ctx * m_creation_ctx
Snapshot of several system variables at CREATE-time.
Definition: sp_head.h:954
bool is_invoked() const
Is this routine being executed?
Definition: sp_head.h:554
LEX_STRING m_qname
Fully qualified name (<db name>.<sp name>).
Definition: sp_head.h:461
bool execute_external_routine_core(THD *thd)
Core function for executing the external routine.
Definition: sp_head.cc:2425
LEX_STRING m_definer_host
Definition: sp_head.h:471
sql_mode_t m_sql_mode
The value of sql_mode system variable at the CREATE-time.
Definition: sp_head.h:458
MEM_ROOT * get_persistent_mem_root() const
Definition: sp_head.h:875
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:3462
longlong m_modified
Definition: sp_head.h:474
bool restore_lex(THD *thd)
Restore LEX-object during parsing, after we have parsed a sub statement.
Definition: sp_head.cc:3205
static void destroy(sp_head *sp)
Definition: sp_head.cc:1692
~sp_head()
Use destroy() to destoy instances of sp_head.
Definition: sp_head.cc:1902
sp_instr * last_instruction()
Definition: sp_head.h:699
LEX_STRING m_definer_user
Definition: sp_head.h:470
char * name(uint *lenp=nullptr) const
Definition: sp_head.h:719
void set_body_start(THD *thd, const char *begin_ptr)
Set the body-definition start position.
Definition: sp_head.cc:1776
void add_mark_lead(uint ip, List< sp_instr > *leads)
Helper used during flow analysis during code optimization.
Definition: sp_head.cc:3365
bool has_temp_table_ddl() const
Definition: sp_head.h:695
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:2597
PSI_sp_share * m_sp_share
Instrumentation interface for SP.
Definition: sp_head.h:435
sp_parser_data m_parser_data
Attributes used during the parsing stage only.
Definition: sp_head.h:444
Stored_program_creation_ctx * get_creation_ctx()
Definition: sp_head.h:576
sp_head * m_next_cached_sp
A list of different recursion level instances for the same procedure.
Definition: sp_head.h:486
bool reset_lex(THD *thd)
Reset LEX-object during parsing, before we parse a sub statement.
Definition: sp_head.cc:3181
MEM_ROOT main_mem_root
SP-persistent memory root (for instructions and expressions).
Definition: sp_head.h:914
st_trg_chistics m_trg_chistics
Trigger characteristics.
Definition: sp_head.h:545
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:498
external_program_handle m_language_stored_program
language component related state of this sp.
Definition: sp_head.h:963
void optimize()
Do some minimal optimization of the code:
Definition: sp_head.cc:3332
enum_sp_type m_type
Stored program type.
Definition: sp_head.h:427
bool modifies_data() const
Returns true if any substatement in the routine directly (not through another routine) modifies data/...
Definition: sp_head.h:687
void propagate_attributes(Query_tables_list *prelocking_ctx)
Definition: sp_head.h:844
sp_head * m_last_cached_sp
Pointer to the last element in the list of instances of the SP.
Definition: sp_head.h:504
void opt_mark()
Perform a forward flow analysis in the generated code.
Definition: sp_head.cc:3371
LEX_CSTRING code
Code if language is not SQL.
Definition: sp_head.h:450
sp_pcontext * get_root_parsing_context() const
Definition: sp_head.h:867
sp_instr * get_instr(uint i)
Get SP-instruction at given index.
Definition: sp_head.h:780
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:3639
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:542
Base class for every SP-instruction.
Definition: sp_instr.h:105
This class represents an SQL/PSM label.
Definition: sp_pcontext.h:94
sp_lex_branch_instr is a base class for SP-instructions, which might perform conditional jump dependi...
Definition: sp_instr.h:795
Definition: sp_head.h:123
LEX_STRING m_qname
Definition: sp_head.h:127
bool m_explicit_name
Prepend the db name?
Definition: sp_head.h:128
void init_qname(THD *thd)
Init the qualified name from the db and name.
Definition: sp_head.cc:1678
LEX_STRING m_name
Definition: sp_head.h:126
sp_name(const LEX_CSTRING &db, const LEX_STRING &name, bool use_explicit_name)
Definition: sp_head.h:130
LEX_CSTRING m_db
Definition: sp_head.h:125
sp_parser_data provides a scope for attributes used at the SP-parsing stage only.
Definition: sp_head.h:149
const char * m_current_stmt_start_ptr
Start of the current statement's query string.
Definition: sp_head.h:312
void push_lex(LEX *lex)
Definition: sp_head.h:237
uint m_cont_level
The current continue backpatch level.
Definition: sp_head.h:358
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:3704
void start_parsing_sp_body(THD *thd, sp_head *sp)
Start parsing a stored program body statement.
Definition: sp_head.cc:3671
Item * m_saved_item_list
THD's item list.
Definition: sp_head.h:372
const char * get_option_start_ptr() const
Definition: sp_head.h:213
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:335
void do_cont_backpatch(uint dest)
Backpatch (and pop) the current level to the given instruction pointer.
Definition: sp_head.cc:3729
bool is_parsing_sp_body() const
Definition: sp_head.h:195
MEM_ROOT * m_saved_memroot
THD's memroot.
Definition: sp_head.h:369
sp_parser_data()
Definition: sp_head.h:157
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:328
void process_new_sp_instr(THD *thd, sp_instr *i)
Definition: sp_head.cc:3740
const char * get_parameter_end_ptr() const
Definition: sp_head.h:225
void set_body_start_ptr(const char *ptr)
Definition: sp_head.h:233
void set_parameter_start_ptr(const char *ptr)
Definition: sp_head.h:223
void set_current_stmt_start_ptr(const char *stmt_start_ptr)
Definition: sp_head.h:207
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:341
void set_parameter_end_ptr(const char *ptr)
Definition: sp_head.h:227
List< Backpatch_info > m_backpatch
Instructions needing backpatching.
Definition: sp_head.h:344
LEX * pop_lex()
Definition: sp_head.h:239
bool add_cont_backpatch_entry(sp_lex_branch_instr *i)
Add a SP-instruction to the current level.
Definition: sp_head.cc:3724
List< LEX > m_lex_stack
Stack of LEX-objects.
Definition: sp_head.h:321
const char * m_option_start_ptr
Start of the SET-expression query string.
Definition: sp_head.h:315
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:355
void set_option_start_ptr(const char *option_start_ptr)
Definition: sp_head.h:215
const char * get_body_start_ptr() const
Definition: sp_head.h:231
bool new_cont_backpatch()
Start a new backpatch level for the SP-instruction requiring continue destination.
Definition: sp_head.h:289
void finish_parsing_sp_body(THD *thd)
Finish parsing of a stored program body statement.
Definition: sp_head.cc:3682
const char * get_parameter_start_ptr() const
Definition: sp_head.h:221
const char * get_current_stmt_start_ptr() const
Definition: sp_head.h:203
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:3715
The class represents parse-time context, which keeps track of declared variables/parameters,...
Definition: sp_pcontext.h:252
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
uint64_t sql_mode_t
Definition: dd_event.h:39
enum_sp_type
enum_sp_type defines type codes of stored programs.
Definition: sql_lex.h:225
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:216
void init_sp_psi_keys(void)
Definition: sp_head.cc:1546
struct PSI_sp_share PSI_sp_share
Definition: psi_statement_bits.h:119
struct external_program_handle_imp * external_program_handle
The handle is created by the caller of external_program_execution service.
Definition: language_service.h:37
static int native_strcasecmp(const char *s1, const char *s2)
Definition: m_string.h:207
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:181
Some integer typedefs for easier portability.
int64_t int64
Definition: my_inttypes.h:68
long long int longlong
Definition: my_inttypes.h:55
#define MYF(v)
Definition: my_inttypes.h:97
uint32_t uint32
Definition: my_inttypes.h:67
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
enum_sql_command
Definition: my_sqlcommand.h:46
Common header for many mysys elements.
static char * where
Definition: mysqldump.cc:152
static const char * sql_mode
Definition: mysqlslap.cc:199
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
Performance schema instrumentation interface.
required string type
Definition: replication_group_member_actions.proto:34
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:372
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3844
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Definition: mysql_lex_string.h:35
char * str
Definition: mysql_lex_string.h:36
size_t length
Definition: mysql_lex_string.h:37
Definition: my_bitmap.h:43
SP_TABLE represents all instances of one table in an optimized multi-set of tables used by a stored p...
Definition: sp_head.cc:1572
Definition: sp_head.h:151
sp_label * label
Definition: sp_head.h:152
sp_branch_instr * instr
Definition: sp_head.h:153
Definition: sql_lex.h:2576
LEX_CSTRING language
CREATE|ALTER ... LANGUAGE <language>
Definition: sql_lex.h:2581
Definition: sql_lex.h:2586